Issue in task creation and stack overflow
Posted: Fri Oct 29, 2021 9:56 am
- ESP32 wrover-b(8mb flash 8mb psram)
- Ported code from esp-idf v3.3.3 to v4.3 stable
- For FFT using esp-dsp lib
- Following are the errors I am facing
- 1) ***ERROR*** A stack overflow in task procc_data has been detected.
- 2) Task creation failed due to memory allocation failure, but
- I (13860) Start memory size : 4147695
- I (13860) Consumed memory size : 16.000000
- I (13860) Consumed memory size in percent : 0 %
- #define MAXSIZE (1024*5)
- #define SAMPLE_FRQ 1344
- #define N_SAMPLES 4096
- #define FFT_SAMP (N_SAMPLES)
- #define FFT_TEST_COMP_SAMPLES_LEN FFT_SAMP
- #define FFT_TEST_OUT_MAG_SAMPLE_LEN (FFT_SAMP/2)
- int16_t x_value[MAXSIZE] = {0};
- int16_t y_value[MAXSIZE] = {0};
- int16_t z_value[MAXSIZE] = {0};
- __attribute__((aligned(16)))
- float x_1[N_SAMPLES] ;
- __attribute__((aligned(16)))
- float y_1[N_SAMPLES] ;
- __attribute__((aligned(16)))
- float z_1[N_SAMPLES];
- float xyz_abs [N_SAMPLES]={0};
- void runn_fft_on_raw(float *in_buff, float *out_buff)
- {
- float y_cf[FFT_SAMP*2];
- for (int i=0 ; i < FFT_SAMP ; i++) {
- y_cf[i*2 + 0] = in_buff[i] *make_wind_sample(i) ;
- y_cf[i*2 + 1] = 0.0;
- }
- dsps_fft2r_fc32(y_cf, FFT_SAMP);
- dsps_bit_rev_fc32(y_cf, FFT_SAMP);
- dsps_cplx2reC_fc32(y_cf, FFT_SAMP);
- for (int i = 0 ; i < FFT_TEST_OUT_MAG_SAMPLE_LEN ; i++) {
- out_buff[i] = ( sqrt(((y_cf[i * 2 + 0] * y_cf[i * 2 + 0] + y_cf[i * 2 + 1] * y_cf[i * 2 + 1] )))/(float)FFT_SAMP );
- }
- }
- void procc_data (void *pvParameters) {
- int16_t x_value[MAXSIZE] = {0};
- int16_t y_value[MAXSIZE] = {0};
- int16_t z_value[MAXSIZE] = {0};
- while(1) {
- //add accl data;
- int16_t x_value[MAXSIZE] = add(x);
- int16_t y_value[MAXSIZE] = add(y);
- int16_t z_value[MAXSIZE] = add(z);
- }
- }
- void procc_data (void *pvParameters)
- {
- esp_task_wdt_add(NULL);
- float x_fft_data[FFT_TEST_OUT_MAG_SAMPLE_LEN] = {0.0};
- float y_fft_data[FFT_TEST_OUT_MAG_SAMPLE_LEN] = {0.0};
- float z_fft_data[FFT_TEST_OUT_MAG_SAMPLE_LEN] = {0.0};
- while(1){
- memset(x_value, 0, sizeof(x_value));
- memset(y_value, 0, sizeof(y_value));
- memset(z_value, 0, sizeof(z_value));
- memset(x_fft_data, 0, sizeof(x_fft_data));
- memset(y_fft_data, 0, sizeof(y_fft_data));
- memset(z_fft_data, 0, sizeof(z_fft_data));
- memset(x_1, 0, sizeof(x_1));
- memset(y_1, 0, sizeof(y_1));
- memset(z_1, 0, sizeof(z_1));
- get_sample(x_value, y_value, z_value);
- cov_sample_in_flt(x_1, y_1, z_1);
- runn_fft_on_raw(x_1, x_fft_data);
- runn_fft_on_raw(y_1, y_fft_data);
- runn_fft_on_raw(z_1, z_fft_data);
- // process data
- // post process data to sever
- }
- }
- void creatTask ()
- {
- isMaster = xTaskCreate(master_Task, "master_Task", 1024*8, NULL, configMAX_PRIORITIES, &master_t);
- isLed = xTaskCreate(led_Task, "led_Task", 1024*2, NULL, 20, &led_t);
- uint8_t istaskCreated = 0;
- while ( iswebsever != pdPASS) { // wait till task is created properly
- iswebsever = xTaskCreate(websever, "websever", 1024*8, NULL, 20, &websever_t, CORE_ONE);
- if (istaskCreated > 3 && iswebsever != pdPASS ) {
- esp_restart();
- }
- istaskCreated++;
- msDelay(1000);
- }
- istaskCreated = 0;
- while ( isadd_raw_data != pdPASS) { // wait till task is created properly
- isadd_raw_data = xTaskCreatePinnedToCore(add_raw_data, "add_raw_data", 1024*2, NULL, 23, &add_raw_data_t, CORE_ONE);
- if (istaskCreated > 3 && isadd_raw_data != pdPASS ) {
- esp_restart();
- }
- istaskCreated++;
- msDelay(1000);
- }
- istaskCreated = 0;
- while ( isprocc_data != pdPASS) { // wait till task is created properly
- isprocc_data = xTaskCreatePinnedToCore(procc_data, "procc_data", 1024*25, NULL, 22, &procc_data_t, CORE_ONE);
- if (istaskCreated > 3 && isprocc_data != pdPASS ) {
- esp_restart();
- }
- istaskCreated++;
- msDelay(1000);
- }
- istaskCreated = 0;
- }
- void app_main(void)
- {
- esp_err_t err = ESP_FAIL;
- err = nvs_flash_init();
- if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
- ESP_ERROR_CHECK(nvs_flash_erase());
- ESP_ERROR_CHECK( nvs_flash_init());
- }
- init_accel();
- ret = dsps_fft2r_init_fc32( NULL, 4096 );
- if (ret != ESP_OK)
- {
- printf( "Not possible to initialize FFT. Error = %i\n", ret);
- return;
- }
- creatTask();
- }