How to trigger GPIO with traceTASK_SWITCHED_IN()

dave_see
Posts: 11
Joined: Wed Jan 08, 2020 6:02 pm

How to trigger GPIO with traceTASK_SWITCHED_IN()

Postby dave_see » Thu Apr 16, 2020 1:05 pm

Hello,

I was reading about the FreeRTOS macros traceTASK_SWITCHED_IN() and traceTASK_SWITCHED_OUT() at this link from freertos.org:
https://www.freertos.org/rtos-trace-macros.html

I'd like to use the macros to drive GPIO pins to debug task behavior. I'm able to set a pin for each task with vTaskSetApplicationTaskTag.

To set the trace macros, I try to include "driver/gpio.h" at the end of "FreeRTOSConfig.h". When I try to do that, I get a lot of build errors starting with:

Code: Select all

~/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/sys-include/machine/_default_types.h:41: Error: unknown opcode or format name 'typedef'
It seems I can't include "driver/gpio.h" in "FreeRTOSConfig.h".

Is it possible to use traceTASK_SWITCHED_IN() and traceTASK_SWITCHED_OUT() to drive GPIO pins with ESP-IDF?

Many thanks,
Dave

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: How to trigger GPIO with traceTASK_SWITCHED_IN()

Postby ESP_igrr » Thu Apr 16, 2020 3:58 pm

dave_see wrote:Error: unknown opcode or format name 'typedef'
This happens because FreeRTOSConfig.h is also included from assembly sources (.S). You can add #ifndef __ASSEMBLER__ // #endif around your extra include header.

A more lightweight alternative is to add a forward declaration of the function you require (again, inside ifndef __ASSEMBLER). This way you won't be pulling in the whole gpio.h and other headers it might depend on.

#ifndef __ASSEMBLER__
int32_t gpio_set_level(int, uint32_t);
#endif // __ASSEMBLER__

dave_see
Posts: 11
Joined: Wed Jan 08, 2020 6:02 pm

Re: How to trigger GPIO with traceTASK_SWITCHED_IN()

Postby dave_see » Thu Apr 16, 2020 7:49 pm

Hi ESP_igrr,

Thank you for your suggestion!

I have it working now and my FreeRTOSConfig.h file looks like this:

Code: Select all

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include "sdkconfig.h"

/* ACTUAL FreeRTOSConfig.h THINGS HERE */
/* ACTUAL FreeRTOSConfig.h THINGS HERE */
/* ACTUAL FreeRTOSConfig.h THINGS HERE */

#ifndef __ASSEMBLER__
int32_t gpio_set_level(int, uint32_t);
#endif // __ASSEMBLER__

#define traceTASK_SWITCHED_IN() { \
    if( (int)pxCurrentTCB[ xPortGetCoreID() ]->pxTaskTag > 0 ) \
        gpio_set_level((int)pxCurrentTCB[ xPortGetCoreID() ]->pxTaskTag, 1); \
}

#define traceTASK_SWITCHED_OUT() { \
    if( (int)pxCurrentTCB[ xPortGetCoreID() ]->pxTaskTag > 0 ) \
        gpio_set_level((int)pxCurrentTCB[ xPortGetCoreID() ]->pxTaskTag, 0); \
}

#endif /* FREERTOS_CONFIG_H */
Thanks again!

-Dave

Who is online

Users browsing this forum: Bing [Bot], brushlow18 and 133 guests