Skip to main content
NorfLoud
Associate II
August 10, 2020
Solved

RTOS. osMailQId bug.

  • August 10, 2020
  • 1 reply
  • 1396 views

I got an interesting bug when working with the queue (STM32CubeMX 5.6.1 + lib 1.25 in STM32F407VGT6):

typedef struct

{

uint8_t* data;

uint16_t len;

} message_t;

uint8_t str[] = "hello\n";

for(;;)

{

message_t* message;

if ((message = osMailAlloc(ComOutputQueue, 0)) == NULL)

{

// no action

}

else

{

message->len = 6;

message->data = malloc(6);

if (message->data == NULL)

{

osMailFree(ComOutputQueue, message);

}

for (uint16_t i = 0; i < 6; i++)

{

message->data[i] = str[i];

}

osMailPut(ComOutputQueue, message);

CDC_Transmit_FS((uint8_t*)str, 6);

osDelay(30);

CDC_Transmit_FS(message->data, message->len);

}

osDelay(30);

}

The ComOutputQueue is declared and initialized.

Result:0693W000003OqkkQAC.jpg

What am I doing wrong?

This topic has been closed for replies.
Best answer by Pavel A.

Note use of malloc in a thread.

Mr. Nadler to the rescue?

-- pa

1 reply

Pavel A.
Pavel A.Best answer
August 10, 2020

Note use of malloc in a thread.

Mr. Nadler to the rescue?

-- pa