-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Hardware:
Board: Adafruit HUZZAH32 Feather
Core Installation/update date: ?11/jul/2017?
IDE name: Arduino IDE
Flash Frequency: 80Mhz
Upload Speed: 115200
Description:
Whenever I try to use Semaphores in my code I get the following error:
`/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/./queue.c:1441 (xQueueGenericReceive)- assert failed!
abort() was called at PC 0x40084701 on core 1
Backtrace: 0x40087360:0x3ffcd070 0x4008745f:0x3ffcd090 0x40084701:0x3ffcd0b0 0x400d0a33:0x3ffcd0f0
`
I tried it in several different cases but I never got semaphores to work on my code. The RepeatTimer example works fine though. I read that this has to do with serial connection, but for me everything works fine except when I insert a semaphore.
Sketch:
/**
* \file sketch_nov23a.ino
*/
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 21
#define TFT_DC 14
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
static boolean myAlarm = false;
byte screen, rotate;
const byte vibratePin = 4;
const int strength = 255;
typedef struct box box;
TaskHandle_t Task1;
hw_timer_t *timer = NULL;
volatile SemaphoreHandle_t timerSemaphore;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
volatile uint32_t isrCounter = 0;
volatile uint32_t lastIsrAt = 0;
void IRAM_ATTR onTimer(){
// Increment the counter and set the time of ISR
portENTER_CRITICAL_ISR(&timerMux);
isrCounter++;
lastIsrAt = millis();
portEXIT_CRITICAL_ISR(&timerMux);
// Give a semaphore that we can check in the loop
xSemaphoreGiveFromISR(timerSemaphore, NULL);
Serial.println("onTimer");
// It is safe to use digitalRead/Write here if you want to toggle an output
}
void DisplayTask(void *pvParameters){
tft.begin();
while (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
}
Serial.println("Capacitive touchscreen started");
showMainScreen();
while(1){
// Create alarm
if (myAlarm){
if(timer){
if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE){
uint32_t isrCount = 0, isrTime = 0;
// Read the interrupt count and time
portENTER_CRITICAL(&timerMux);
isrCount = isrCounter;
isrTime = lastIsrAt;
portEXIT_CRITICAL(&timerMux);
if (isrCount%2==0){
sigmaDeltaWrite(0, 0);
}
else{
sigmaDeltaWrite(0, strength);
}
}
}
else{
// Use 1st timer of 4 (counted from zero).
// Set 80 divider for prescaler (see ESP32 Technical Reference Manual for more
// info).
timer = timerBegin(0, 80, true);
// Attach onTimer function to our timer.
timerAttachInterrupt(timer, &onTimer, true);
// Set alarm to call onTimer function every second (value in microseconds).
// Repeat the alarm (third parameter)
timerAlarmWrite(timer, 1000000, true);
// Start an alarm
timerAlarmEnable(timer);
}
}
else{
if(timer){
timerEnd(timer);
timer = NULL;
}
}
if (! ctp.touched()) {
delay(1);
continue;
}
//analogWrite(vibratePin, strength);
// Retrieve a point
TS_Point p = ctp.getPoint();
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
showMainScreen();
delay(1);
}
}
/**
* \brief Setup starts the serial communication and shows first main screen.
*/
void setup() {
Serial.begin(115200);
xTaskCreatePinnedToCore(
DisplayTask, /* Function to implement the task */
"DisplayTask", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
2, /* Priority of the task */
&Task1, /* Task handle. */
1); /* Core where the task should run */
myAlarm = true;
}
void loop() {
}
/*****************************************************************
* Display screens
*/
void showMainScreen(){
if(myAlarm){
tft.fillScreen(0);
}
else{
tft.fillScreen(255);
}
}
Debug Messages:
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:812
load:0x40078000,len:0
load:0x40078000,len:11392
entry 0x40078a9c
Capacitive touchscreen started
/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/./queue.c:1441 (xQueueGenericReceive)- assert failed!
abort() was called at PC 0x40084701 on core 1
Backtrace: 0x40087360:0x3ffcd070 0x4008745f:0x3ffcd090 0x40084701:0x3ffcd0b0 0x400d0a33:0x3ffcd0f0
Rebooting...