I am working on a median filter on the ESP32 board. This median filter is based on a circular buffer. I implemented the filter into the main.c and it worked just fine. However as I created a custom library and called the function from the main.c the ESP32 just reboots and prints the given error message. I am working with PlatformIO and FreeRTOS.
#define FILTER_SIZE_IN_BITS (10)
#define FILTER_SIZE (1 << (FILTER_SIZE_IN_BITS))
uint16_t LO_filter_buffer[FILTER_SIZE];
uint32_t LO_filter_sum;
uint16_t *LO_filter_position;
static void analogRead(void *args)
{
    register int i;
    LO_filter_sum = 0;
    LO_filter_position = LO_filter_buffer;
    for (i = 0; i < FILTER_SIZE; i++)
        LO_filter_buffer[i] = 0;
    while (1)
    {
        LO_filter_sum -= *LO_filter_position;
        LO = adc1_get_raw(ADC1_CHANNEL_4);
        *LO_filter_position = LO;
        LO_filter_sum += LO;
        if (++LO_filter_position >= LO_filter_buffer + FILTER_SIZE)
        {
            LO_filter_position = LO_filter_buffer;
        }
        finallo = (uint32_t)(LO_filter_sum >> FILTER_SIZE_IN_BITS);
        vTaskDelay(20 / portTICK_PERIOD_MS);
    }
    vTaskDelete(NULL);
}
This is the implementation in the library:
#include "median.h"
#define FILTER_SIZE_IN_BITS (3)
#define FILTER_SIZE (1 << (FILTER_SIZE_IN_BITS))
static uint32_t filter_sum = 0;
static uint16_t filter_buffer[FILTER_SIZE] = {0};
static uint16_t *filter_position;
median_t Mittelwert(median_t new_value)
{
  if (++filter_position >= filter_buffer + FILTER_SIZE)
  {
    filter_position = filter_buffer;
  }
  filter_sum -= *filter_position;
  *filter_position = (uint16_t)new_value;
  filter_sum += (uint16_t)new_value;
  return (median_t)(filter_sum >> FILTER_SIZE_IN_BITS);
}
#ifndef __median__
#define __median__ 
#include "stdint.h"
#include <stdbool.h>
#include "stdio.h"
typedef int32_t median_t;
median_t Mittelwert(median_t new_value);
#endif
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core  0 register dump:
PC      : 0x400d1065  PS      : 0x00060d30  A0      : 0x800d0e3c  A1      : 0x3ffba060  
A2      : 0x00000000  A3      : 0x3ffb0034  A4      : 0x00060021  A5      : 0x00060023  
A6      : 0x00000001  A7      : 0x00000000  A8      : 0x3ffb4148  A9      : 0x3ffb415c  
A10     : 0x00000002  A11     : 0x81070000  A12     : 0x3ffba050  A13     : 0x3ffb67f0  
A14     : 0x00000800  A15     : 0x7fffffff  SAR     : 0x0000001b  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000002  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  
Backtrace:0x400d1062:0x3ffba060 0x400d0e39:0x3ffba080 0x400846a9:0x3ffba0d0
ELF file SHA256: dd5498559aa03c7d
Does anyone know what the problem is by calling is filter from a library?
User contributions licensed under CC BY-SA 3.0