Esp32-(xQueueGenericReceive)- assert failed

Hypnoz
Posts: 2
Joined: Sun Jun 27, 2021 8:54 am

Esp32-(xQueueGenericReceive)- assert failed

Postby Hypnoz » Sun Jun 27, 2021 9:05 am

ImageHey guys i have been working on a project in which the analog values sampled at a particular frequency and stored in array. Then the value will be sent to user application ESP32 BLE. But I got stuck in this error
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:1443 (xQueueGenericReceive)- assert failed! abort() was called at PC 0x4008e1d5 on core 1
Backtrace: 0x40091b38:0x3ffe0b20 0x40091d69:0x3ffe0b40 0x4008e1d5:0x3ffe0b60 0x400d1a2d:0x3ffe0ba0 0x4008e525:0x3ffe0be0

Rebooting... ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:8896 load:0x40080400,len:5816 entry 0x400806ac
I am Using Esp32arduino and Free Rtos for programming i error is in the semaphore from the interrupt but i couldn't able to find out exact solution. Please help me out guys
  1. #include <ArduinoJson.h>
  2. #include <BLEDevice.h>
  3. #include <BLEServer.h>
  4. #include <BLEUtils.h>
  5. #include <BLE2902.h>
  6.  
  7. /*#if CONFIG_FREERTOS_UNICORE
  8.   static const BaseType_t app_cpu = 0;
  9. #else
  10.   static const BaseType_t app_cpu = 1;
  11. #endif*/
  12.  
  13. static const BaseType_t pro_cpu = 0;
  14. static const BaseType_t app_cpu = 1;
  15.  
  16. //ADC Related Global Variables
  17. static const uint16_t timer_divider =80;
  18. static const uint64_t timer_max_count=1000;
  19.  
  20. static const int adc_pin=A0;
  21.  
  22. static const int BUF_SIZE=1000;
  23.  
  24. static int buf[BUF_SIZE];
  25. int Buff_Len=0;
  26. static int Read=0;
  27. static int Write=0;
  28. static int count=0;
  29. static float avg=0;
  30. int i=0;
  31. int BLE_flag=0;
  32. String cmd;
  33.  
  34. static hw_timer_t *timer=NULL;
  35. static uint16_t val;
  36. static int count1=0;
  37.  
  38. static SemaphoreHandle_t bin_sem=NULL;
  39. static SemaphoreHandle_t bin_sem2=NULL;
  40. static portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED;
  41. //ADC Related Global Variables
  42.  
  43. //BLE Global Variable
  44. char Reading[4];
  45. BLEServer *pServer = NULL;
  46. BLECharacteristic * pTxCharacteristic;
  47. bool deviceConnected = false;
  48. bool oldDeviceConnected = false;
  49.  
  50. //Declaration BLE necessary Classes
  51. #define SERVICE_UUID           "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
  52. #define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
  53.  
  54. class MyServerCallbacks: public BLEServerCallbacks {
  55.     void onConnect(BLEServer* pServer) {
  56.       deviceConnected = true;
  57.     };
  58.  
  59.     void onDisconnect(BLEServer* pServer) {
  60.       deviceConnected = false;
  61.     }
  62. };
  63. //BLE Global Variables
  64.  
  65. //Task Section
  66. void IRAM_ATTR onTimer()
  67. {
  68.   BaseType_t task_woken=pdFALSE;
  69.  
  70.   val=analogRead(adc_pin);
  71.   count1++;
  72.  
  73.   xSemaphoreGiveFromISR(bin_sem2,&task_woken);
  74.  
  75.   if (task_woken) {
  76.     portYIELD_FROM_ISR();
  77.   }
  78. }
  79.  
  80. void move_to_Queue (void *parameters)
  81. {
  82.   while(1)
  83.   {
  84.    xSemaphoreTake(bin_sem2,portMAX_DELAY);
  85.    
  86.     if(Buff_Len==BUF_SIZE||count1>2000)
  87.     {
  88.       Serial.println("Buffer is full");
  89.       xSemaphoreGive(bin_sem);
  90.       //BLE_flag=1;
  91.       Buff_Len=0;
  92.       count1=0;    
  93.     }
  94.     else
  95.     {
  96.       buf[Write]=val;
  97.       Write = (Write + 1) % BUF_SIZE;
  98.       Buff_Len++;
  99.     }
  100.   }
  101. }
  102.  
  103. void BLE_Task(void *parameters)
  104. {
  105.    while(1)
  106.   {
  107.  
  108.     xSemaphoreTake(bin_sem,portMAX_DELAY);
  109.     Serial.println("BLE");
  110.     for (i=0;i<BUF_SIZE;i++)
  111.   {
  112.    if(i==0)
  113.   {
  114.     sprintf(Reading,"[%d",buf[i]);
  115.   }
  116.   else if(i==BUF_SIZE-1)
  117.   {
  118.     sprintf(Reading,",%d]",buf[i]);
  119.   }
  120.   else{
  121.   sprintf(Reading,",%d",buf[i]);
  122.   }
  123.    Serial.print(Reading);
  124.     if (deviceConnected) {
  125.         pTxCharacteristic->setValue(Reading);
  126.         pTxCharacteristic->notify();
  127.     delay(10); // bluetooth stack will go into congestion, if too many packets are sent
  128.   }  
  129.  }
  130.  Serial.println();
  131.  
  132.  }
  133. }
  134.  
  135.  
  136. void setup()
  137. {
  138.   // put your setup code here, to run once:
  139.   Serial.begin(115200);
  140.   vTaskDelay(1000/portTICK_PERIOD_MS);
  141.  
  142.   //BLE Declarations
  143.   BLEDevice::init("UART Service");
  144.   pServer = BLEDevice::createServer();
  145.   pServer->setCallbacks(new MyServerCallbacks());
  146.   BLEService *pService = pServer->createService(SERVICE_UUID);
  147.   pTxCharacteristic = pService->createCharacteristic(
  148.                     CHARACTERISTIC_UUID_TX,
  149.                     BLECharacteristic::PROPERTY_NOTIFY
  150.                   );
  151.      
  152.   pTxCharacteristic->addDescriptor(new BLE2902());
  153.   pService->start();
  154.   pServer->getAdvertising()->start();
  155.   Serial.println("Waiting a client connection to notify...");
  156.   //BLE Declaration
  157.  
  158.  
  159.   //ADC Semaphore and Timer Declarations
  160.   bin_sem = xSemaphoreCreateBinary();
  161.   bin_sem2 = xSemaphoreCreateBinary();
  162.  
  163.  
  164.   if(bin_sem==NULL||bin_sem2==NULL)
  165.   {
  166.     Serial.println("Could not create semaphore");
  167.     ESP.restart();
  168.   }
  169.     xTaskCreatePinnedToCore(move_to_Queue,
  170.                           "move_to_Queue",
  171.                           1024,
  172.                           NULL,
  173.                           2,
  174.                           NULL,
  175.                           app_cpu);
  176.      xTaskCreatePinnedToCore(BLE_Task,
  177.                           "BLE_Task",
  178.                           2048,
  179.                           NULL,
  180.                           2,
  181.                           NULL,
  182.                           app_cpu);
  183.                  
  184.      timer = timerBegin(0, timer_divider, true);
  185.  
  186.   // Provide ISR to timer (timer, function, edge)
  187.      timerAttachInterrupt(timer, &onTimer, true);
  188.  
  189.   // At what count should ISR trigger (timer, count, autoreload)
  190.      timerAlarmWrite(timer, timer_max_count, true);
  191.  
  192.   // Allow ISR to trigger
  193.      timerAlarmEnable(timer);
  194.       vTaskDelete(NULL);
  195. }
  196.  
  197. void loop() {
  198.   // put your main code here, to run repeatedly:
  199.  
  200.  
  201. }
Whole Code:https://pastebin.com/K8ppkG28

Thanks in advance guys

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Esp32-(xQueueGenericReceive)- assert failed

Postby ESP_Sprite » Mon Jun 28, 2021 3:32 am

Can you decode that backtrace?

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Esp32-(xQueueGenericReceive)- assert failed

Postby chegewara » Mon Jun 28, 2021 4:09 am


Hypnoz
Posts: 2
Joined: Sun Jun 27, 2021 8:54 am

Re: Esp32-(xQueueGenericReceive)- assert failed

Postby Hypnoz » Mon Jun 28, 2021 6:48 am

ESP_Sprite wrote:
Mon Jun 28, 2021 3:32 am
Can you decode that backtrace?
I appreciate your interest pal. But a buddy from github has already let me know the fix .It was an memory issue .I just have increase char array size

Who is online

Users browsing this forum: Google [Bot] and 50 guests