Using FreeRTOS 9.0
CMSIS-RTOS API 1.2
Chip STM32L162RET
Problem: I have two tasks and one message queue, one task sends a data struct the other task receives it, everything works as expected, but when
I add a uint8_t data[DATA_SIZE] and increase the DATA_SIZE from 5-Bytes upwards (4-Bytes works) the program hangs! I set the task stack size to 512 Bytes (nothing!),
I have no idea where else to look? I stepped through the code and the code hangs during osPoolFree (block < pool_id->pool) a HardFault_Handler is generated.
Is there a bug with CMSIS RTOS 1.0 ?
osThreadId tid_thread1; // ID for thread 1
osThreadId tid_thread2; // for thread 2
typedef struct { // Message object structure
float voltage; // AD result of measured voltage
float current; // AD result of measured current
int counter; // A counter value
uint8_t data[20];
} T_MEAS;
osPoolDef(mpool, 16, T_MEAS); // Define memory pool
osPoolId mpool;
osMessageQDef(MsgBox, 16, T_MEAS); // Define message queue
osMessageQId MsgBox;
void send_thread (void const *argument); // forward reference
void recv_thread (void const *argument); // forward reference
//
// Thread 1: Send thread
//
void send_thread (void const *argument) {
for(;;)
{
HAL_GPIO_TogglePin(GPIOC, LED_1_Pin);
T_MEAS *mptr;
mptr = osPoolAlloc(mpool); // Allocate memory for the message
mptr->voltage = 223.72; // Set the message content
mptr->current = 17.54;
mptr->counter = 120786;
memcpy(mptr->data, data_arr, sizeof(mptr->data));
osMessagePut(MsgBox, (uint32_t)mptr, osWaitForever); // Send Message
osDelay(100);
mptr = osPoolAlloc(mpool); // Allocate memory for the message
mptr->voltage = 227.23; // Prepare a 2nd message
mptr->current = 12.41;
mptr->counter = 170823;
osMessagePut(MsgBox, (uint32_t)mptr, osWaitForever); // Send Message
osThreadYield(); // Cooperative multitasking
// We are done here, exit this thread
}
}
//
// Thread 2: Receive thread
//
void recv_thread (void const *argument) {
T_MEAS *rptr;
osEvent evt;
for (;;) {
evt = osMessageGet(MsgBox, osWaitForever); // wait for message
if (evt.status == osEventMessage) {
HAL_GPIO_TogglePin(GPIOC, LED_3_Pin);
rptr = evt.value.p;
printf ("\nVoltage: %.2f V\n", rptr->voltage);
printf ("Current: %.2f A\n", rptr->current);
// printf ("Number of cycles: %d\n", rptr->counter);
osPoolFree(mpool, evt.value); // free memory allocated for message
}
}
}
void StartApplication (void) {
mpool = osPoolCreate(osPool(mpool)); // create memory pool
MsgBox = osMessageCreate(osMessageQ(MsgBox), NULL); // create msg queue
osThreadDef( send_threadTask, send_thread, osPriorityNormal, NULL, 512 );
osThreadDef( recv_threadTask, recv_thread, osPriorityNormal, NULL, 512 );
tid_thread1 = osThreadCreate(osThread(send_threadTask), NULL);
tid_thread2 = osThreadCreate(osThread(recv_threadTask), NULL);
}