Hello,
I am new to freeRTOS and tried running it on an STM32F405 chip. For that, I used the port files
from /portable/GCC/ARM_CM4F
and for the config file I used the file from the github-repo
(not allowed to post links) AndColla/stm32f4discovery-freertos-makefile
because it also uses libopencm3.
My code can be found on the github-repo: (not allowed to post links) Hackertreff-Reutte/RT3s_Firmware branch: freertos
main.c
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include "FreeRTOS.h"
#include "task.h"
/*
* Handler in case our application overflows the stack
*/
void vApplicationStackOverflowHook(
TaskHandle_t xTask __attribute__((unused)),
char *pcTaskName __attribute__((unused))) {
for (;;);
}
static void task1(void *args __attribute__((unused))) {
for (;;) {
gpio_toggle(GPIOE, GPIO0);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
static void task2(void *args __attribute__((unused))) {
for (;;) {
gpio_set(GPIOE, GPIO1);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
int main(){
rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
//LED
rcc_periph_clock_enable(RCC_GPIOE);
gpio_mode_setup(GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO0);
gpio_mode_setup(GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO1);
xTaskCreate(task1, "LED1", 100, NULL, 2, NULL);
xTaskCreate(task2, "LED2", 100, NULL, 2, NULL);
/* Start the scheduler. */
vTaskStartScheduler();
for(;;) {}
return 0;
}
What does not work: Task execution
What I have found out so far:
If xTaskCreate()
is called it returns pdPASS
If vTaskStartScheduler()
is called it runs until it executes the arm instruction svc 0
in the function prvPortStartFirstTask()
[located in port.c] after that it never returns and that should be the intended behaviour as far as I understood it.
What is different to a normal STM32:
- There is a bootloader on the chip, hence it has a different memory layout
- The stack pointer is set to -4 from the usual location due to a bug in the bootloader (off by one error while sanity checking)
Memory Layout
{
sram (rwx) : ORIGIN = 0x20000200, LENGTH = 128k - 0x200 /* 0x200 some space for the bootloader? */
flash (rx) : ORIGIN = 0x0800C000, LENGTH = 1M - 48K
ccm (rwx) : ORIGIN = 0x10000000, LENGTH = 64K
}
Stack Pointer
PROVIDE(_stack = ORIGIN(sram) + LENGTH(sram) - 4);
Sadly I can’t debug the chip directly, because it is built into a radio and therefore I don’t have easy access.
Ideas on the next steps of debugging would be appreciated. Or maybe I did something wrong?