osthreadDef problem on STM32

Hi, I use the FREERTOS by first time with STM32F429
I used the osthreadDef to run many function, but it always break loop.
I looked some forum, it is the memory problem

256KB SRAM with STM32F429
How can I set my FREERTOS?

osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 1024);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

#define configUSE_PREEMPTION 1
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 7 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)30720)
//#define configTOTAL_HEAP_SIZE ((size_t)17*1024)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1

The task creation code looks okay. Does the task start and then the loop breaks or does the scheduler never start? Would you please step into the osKernelStart and see if the scheduler starts successfully?

Also, do the following:

Thanks.

I’m afraid that is not one of our functions so I don’t know how it is implemented. From your code it looks like it is populating a structure that is passed to osThreadCreate() - is the 1024 the stack size? If so, is it specified in bytes or words? Either way it looks quite large unless you are allocating a lot on the task’s stack.

Grateful if you could be more specific. Are you running out of heap memory? If so, how do you know? What value does xTaskCreate() return (xTaskCreate() is the FreeRTOS API function that will get called in osThreadCreate())? Do you have a malloc failed hook defined?

I’m not sure if you are talking about heap though. You might be talking about stack.

If you are running out of heap then this looks like you are allocating quite a lot as this is 30720 words, not bytes, so 30720*4 bytes on an STM32.

It is start successfully, but do it in other function, it will break loop.
I try to change the “configTOTAL_HEAP_SIZE”, but it is also break at same place

Sorry I didn’t understand.
Is that means i don’t have enough memory?

How do you verify that the loop is breaking? What is your task definition?

To narrow down the problem, would you please only create one task and do nothing in the loop (i.e. the default generated code):

void StartDefaultTask(void const * argument)
{
  /* USER CODE BEGIN 5 */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END 5 */ 
}

Also, did you define configASSERT and other checks as I suggested before?

Thanks.

void StartDefaultTask(void const * argument)
{
/* init code for LWIP /
MX_LWIP_Init();
tcp_server_init();
Tcp_Client_Init();
/
init code for USB_DEVICE /
MX_USB_DEVICE_Init();
/
USER CODE BEGIN 5 /
/
Infinite loop */
while (1)
{
osDelay(100);
}

This is the function that I can run. And also can connect the TCP server.
but I just put the function in the while

while (1)
{
osDelay(100);
main_GW();
}

if main_GW function, put in the main() is run successfully.

I am still unable to understand the problem but it seems like the call to the function main_GW(); is problematic. What is the definition of that function?

Please do the following:

Thanks.

Sorry, I need to try that more check, I can’t compile the program smoothly.

Main_GW is more about GPIO & SPI used. I try to move TCP out of thread, but TCP didn’t work.

osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 1024);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* Start scheduler /
osKernelStart();
while (1)
{
HAL_GPIO_WritePin(GPIOG, RESET_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOG, RESET_Pin, GPIO_PIN_RESET);
Main_GW();
}
/
USER CODE END 3 */
}

1 Like