Hello,
I’m trying to learn / use FreeRTOS with libopencm3 on a STM32 thanks to
Warren
Gay’s book the code examples used in his book are available
here
I have already asked this question on
StackOverflow and on
ve3wwg/stm32f103c8t6 but I did not get an answer that solved my problem.
Hardware
- MCU: STM32F103C8T6 (also known as Blue Pill)
- FT232RL breakout board
- ST-Link V2
Software
- Kubuntu 18.04
- arm-none-eabi-gcc (15:6.3.1+svn253039-1build1) 6.3.1 20170620
- gdb-multiarch – GNU gdb (Ubuntu 8.2-0ubuntu1~18.04) 8.2)
- FreeRTOS 10.2.0
- libopencm3 latest commit 0fd4f74ee301af5de4e9b036f391bf17c5a52f02
The following program creates two tasks and a queue. The queue is filled by the task “SEND” and the task “RECEIVE” receives from the same queue, the Blue Pill LED (GPIOC, GPIO13) is turned on by the “SEND” task every 1100 ms and the “RECEIVE” tasks turns it off when it receives a message (100 ms after it has been turned on).
~~~
include <FreeRTOS.h>
include <libopencm3/stm32/gpio.h>
include <libopencm3/stm32/rcc.h>
include <queue.h>
include <task.h>
static QueueHandle_t queue;
static void
task
receive(void *args attribute((unused)))
{
bool nothing;
while (1)
{
if (xQueueReceive(queue, ¬hing, 10) == pdPASS)
gpioset(GPIOC, GPIO13); // Turn off
}
}
static void
task
send(void *args attribute((unused)))
{
bool nothing = false;
while (1)
{
gpioclear(GPIOC, GPIO13); // Turn on
vTaskDelay(pdMS
TOTICKS(100));
xQueueSendToBack(queue, ¬hing, portMAX
DELAY);
vTaskDelay(pdMSTO_TICKS(1000));
}
}
int
main(void)
{
rcc
clocksetup
inhse
8mhzout_72mhz();
// Blue-Pill led
rcc
periphclock
enable(RCCGPIOC);
gpio
setmode(
GPIOC,
GPIO
MODEOUTPUT
2MHZ,
GPIO
CNFOUTPUT
PUSHPULL,
GPIO13);
gpioset(GPIOC, GPIO13); // Turn off (polarity of the led is inversed!)
queue = xQueueCreate(32, sizeof(bool));
if (queue == 0)
{
while (1)
{
gpio
toggle(GPIOC, GPIO13);
for (uint32t i = 0; i < 80000; ++i)
asm(“nop”);
};
}
xTaskCreate(task
receive, “RECEIVE”, 200, NULL, configMAXPRIORITIES-1, NULL);
xTaskCreate(task
send, “SEND”, 200, NULL, configMAXPRIORITIES-2, NULL);
vTaskStartScheduler();
while(1);
return 0;
}
~~~
This program does not work when I flash it on a Blue Pill, the led stays on and never turns off, I think the execution is blocking at the xQueueSendToBack call (it never exits).
I am using the configuration files from the
rtos/uart2 example of the book.
I have tried debugging this with the ST-Link V2, here is the output of my debug session: (note: the program is named uart.elf because I’m using the rtos/uart2 example files, I replaced the code with the one above)
~~~
gdb-multiarch
layout split
file uart.elf
target extended-remote :4242
load uart.elf
b main
~~~
At that point the everything looks fine from my point of view:
gdb session
Then I set a breakpoint to the xQueueSendToBack call and continue:
~~~
(gdb) b uart.c:30
Breakpoint 2 at 0x8000156: file uart.c, line 30.
(gdb) c
Continuing.
~~~
If I let the code continue and halt it afterwards I get this:
~~~
(gdb) c
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
0x08000e9c in prvIdleTask (pvParameters=
) at rtos/tasks.c:3166
(gdb) bt
0 0x08000e9c in prvIdleTask (pvParameters=) at rtos/tasks.c:3166
1 0x08000462 in uxListRemove (pxItemToRemove=) at rtos/list.c:238
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
~~~
There seems to be something wrong here, however I don’t know how to interpret this corrupt stack error.
Why is this example not working on my Blue-Pill? There must be something wrong in my setup but I can’t find what.
If there is any information missing please ask as I’m willing to provide as much as you need to help me fix this problem. I’m a little desperate here 🙂
Bye