cancel
Showing results for 
Search instead for 
Did you mean: 

[FreeRTOS] [STM32F429-DISCO] Observing task priority via GPIO & oscilloscope

f239955
Associate
Posted on January 08, 2016 at 14:50

Hi,

in a realtime programming lab we observed the task priorities via GPIO and an oscilloscope. We used a stm32f4xg-eval board, and I want to replicate this on a stm32f429-disco board.

This code was used:

// initialize PORT I as output for CPU watch GPIO_InitTypeDef GPIO_InitStructure; __HAL_RCC_GPIOI_CLK_ENABLE(); /* Configure Port 'I' 4567 for poor man's DAC */ GPIO_InitStructure.Pin = 0xf0; GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Speed = GPIO_SPEED_FAST; HAL_GPIO_Init(GPIOI, &GPIO_InitStructure); __HAL_RCC_GPIOE_CLK_ENABLE();

I'm not sure if FreeRTOS has to be configured to expose this info via GPIO and the f429 manual didn't relly help me.

Has anybody done something similar and/or can point me in the right direction.

Thanks
3 REPLIES 3
jpeacock
Associate III
Posted on January 08, 2016 at 15:12

FreeRTOS has macros to track task context.  Look at:

vTraceTaskSwitchedIn()

vTraceTaskSwitchedOut()

You can get the current task TCB through pcCurrentTCB (but check to make sure it isn't null).  Get the task number from pxCurrentTCB->uxTCBNumber.

My guess is you never use more than 15 tasks (plus idle) so you can output the task number on the GPIO pins.

I use this for my own task profiling routines.  Each time a task switches in I start TIM7, and when it switches out I add the TIM7 count to an execution time array entry indexed by task number.  Not very precise, interrupts throw it off, but it is useful to spot something taking way too much CPU time, or if a task becomes permanently blocked (time doesn't increase).

  Jack Peacock
Posted on January 08, 2016 at 15:16

Clearly there's some complementary code here that actually outputs to the pins.

The STM32F429I-DISCO manual should enumerate all the pins, and if they are free for user applications, although the pins are heavily utilized with the SDRAM, LCD, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
f239955
Associate
Posted on January 08, 2016 at 15:34

Thanks, that looks good. We measured the time spent in ISRs and didn't add macros to the tasks, but maybe it's precise enough.

Edit: just noticed that one only needs to modify the tasks if one doesn't use the uxTCBNumber. I guess that's exactly how it was done, since we had only 16 different output values, too.

Edit 2: I found out how it was originally done:

#define traceTASK_SWITCHED_IN() \

    { unsigned priority=pxCurrentTCB->uxPriority; *(volatile unsigned *)0x4002201a=0xf0; *(volatile unsigned *)0x40022018 = priority << 4; }

#define ENTER_ISR \

unsigned old_prio =*(volatile unsigned*)0x40022014 >> 4;   *(volatile unsigned*)0x40022018 = 0xf0;

#define LEAVE_ISR  *(volatile unsigned*)0x4002201a = 0xf0; *(volatile unsigned*)0x40022018 = old_prio << 4;

#define ENTER_RTOS *(volatile unsigned*)0x40022018 = 0xe0; *(volatile unsigned*)0x4002201a = 0x10;

#define ENTER_IDLE *(volatile unsigned*)0x4002201a = 0xf0;

#define SWITCH_HOOK()

#define IDLE_HOOK()