Page 1 of 1

How to trigger GPIO with traceTASK_SWITCHED_IN()

Posted: Thu Apr 16, 2020 1:05 pm
by dave_see
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

Re: How to trigger GPIO with traceTASK_SWITCHED_IN()

Posted: Thu Apr 16, 2020 3:58 pm
by ESP_igrr
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__

Re: How to trigger GPIO with traceTASK_SWITCHED_IN()

Posted: Thu Apr 16, 2020 7:49 pm
by dave_see
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