How to check thread memory stack in runtime?

Discussions and support about ChibiOS/RT, the free embedded RTOS.
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times
Contact:

How to check thread memory stack in runtime?

Postby kreyl » Sat Jul 22, 2017 2:14 pm

I found same topic in user projects, but it seems that thread workspace has changed since 2011, and mentioned solution outputs something weird.

stm32l151c8, Chibios v 17.6.0

Here is the code I use now (it is definitely something wrong in boundaries). What is wrong?

Code: Select all

uint32_t GetThdFreeStack(void *wsp, uint32_t size) {
    uint32_t n = 0;
#if CH_DBG_FILL_THREADS
    uint8_t *startp = (uint8_t *)wsp + sizeof(thread_t);
    uint8_t *endp = (uint8_t *)wsp + size;
    while (startp < endp)
        if(*startp++ == CH_DBG_STACK_FILL_VALUE) ++n;
#endif
    return n;
}

void PrintThdFreeStack(void *wsp, uint32_t size) {
    Printf("Free stack memory: %u of %u bytes\r",
            GetThdFreeStack(wsp, size) - sizeof(thread_t),
            size - sizeof(thread_t));
}
...
static THD_WORKING_AREA(waEffectsThread, 128);
...
PrintThdFreeStack(waEffectsThread, sizeof(waEffectsThread));

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: How to check thread memory stack in runtime?

Postby Giovanni » Sat Jul 22, 2017 6:02 pm

Hi,

The thread_t is no more placed at base of working area (too vulnerable place) so you have to remove that "+ sizeof(thread_t)" when calculating the base address.

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 7 guests