Skip to main content
ranran
Senior
Jan 20, 2019 10:08 AM UTC
Solved

Limitation of freeRTOS's stack size from main to maximum ~1480 bytes ?

Hello,

I am trying to overcome some strange issue using IAR when starting freeRTOS thread from main.

I have used the following example for usb

\en.stm32cubeh7\STM32Cube_FW_H7_V1.3.0\Projects\STM32H743I_EVAL\Applications\USB_Host\HID_RTOS

It detects a HID automatically when inserting into board, and display information about it on LCD.

But when I started adding some threads, it suddeny stopped detecting the inserted device.

After some debugging, I've came to conculsion that it is a matter of stack size.

Even if I have only one thread (the usbtest thread) and I give it a large size then it fails:

- osThreadDef(USER_Thread, StartThread, osPriorityNormal, 0,

        128);

+ osThreadDef(USER_Thread, StartThread, osPriorityNormal, 0,

        1480);

I thought that stack size from main is a matter of changing in icf and rebuild :

-define symbol __ICFEDIT_size_cstack__ = 0x400;

+define symbol __ICFEDIT_size_cstack__ = 0x4400;

But surprisingly, it did not help !

Does anyone have any idea ?

Thanks,

ran

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Jan 20, 2019 11:35 AM UTC

Doesn't it allocate these dynamically from its own heap?​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..

4 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Jan 20, 2019 11:35 AM UTC

Doesn't it allocate these dynamically from its own heap?​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Piranha
Principal III
Jan 20, 2019 5:25 PM UTC

Clive is right, it does. Each thread has it's own stack and those are not related to main stack.

ranran
ranranAuthor
Senior
Jan 24, 2019 9:46 AM UTC

Hello,

I am not sure I understand the suggestion how to solve this issue.

Do you mean that I should increase configMINIMAL_STACK_SIZE ? I've tried that.

Please see main here:

int main(void)
{
 MPU_Config();
 
 CPU_CACHE_Enable();
 
 HAL_Init(); 
 
 osThreadDef(EthThread, StartEthThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE*2 );
 osThreadCreate (osThread(EthThread), NULL);
 
 osThreadDef(rxUART, UART_RxThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE);
 osThreadCreate (osThread(rxUART), NULL);
 
 osThreadDef(LOGGER, Logger_Thread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE*3 );
 LoggerThreadHandle = osThreadCreate(osThread(LOGGER), NULL);
 
 osKernelStart();
 /* We should never get here as control is now taken by the scheduler */
 for( ;; );
}

Thank you!

ranran

Piranha
Principal III
Jan 24, 2019 11:01 PM UTC