Hello Kind folks,
A newbie to freeRTOS here. I am wanting to get my hands dirty with freeRTOS and I have some experience with libopenCM3. I am trying to work on a custom STM32 board with the STM32F103RCT6 processor, not the bluepill board. minor difference but a difference nevertheless. I am using a arm-none-eabi-gcc toolshain which is present in my system path. I am using a MBP running 11.4 Big Sur for sake of completeness.
I have gone through various posts… googled for answers… tried incorporating some of the suggestions but still fail to get a simple blinky working. I come here to seeking knowledge and information, not to inconvenience other folks. Please bear with me.
First , my directory structure.
.
├── freertos_test
├── libopencm3
│ ├── doc
│ ├── include
│ ├── ld
│ ├── lib
│ ├── mk
│ ├── scripts
│ └── tests
└── shared_libs
├── FreeRTOS
├── cryptoauthlib
├── hd44780_v2
├── littlefs
└── mhz19b
My projects working directory is freertos_test
(surprise! surprise! ) . I have unzipped the freertos into the shared_libs/FreeRTOS
directory. I have modified the makefile to include the necessary ( I hope) source files from freertos and also added the include directories.
I have used the FreeRTOSConfig.h file from CORTEX_STM32F103_GCC_Rowley
as a starting point.
These are the contents of my makefile.
PROJECT = freeRTOS_test
BUILD_DIR = bin
SHARED_DIR = ../shared_libs
FREERTOS_SRC = ../shared_libs/FreeRTOS/FreeRTOS/Source
FREERTOS_HEADERS = ../shared_libs/FreeRTOS/FreeRTOS/Source/include
INCLUDES += -I$(FREERTOS_HEADERS)
INCLUDES += -I$(FREERTOS_SRC)/portable/GCC/ARM_CM3
TGT_CFLAGS += -I$(FREERTOS_HEADERS)
TGT_CXXFLAGS += -I$(FREERTOS_HEADERS)
CFILES = main.c
CFILES +=$(FREERTOS_SRC)/portable/GCC/ARM_CM3/port.c $(FREERTOS_SRC)/tasks.c $(FREERTOS_SRC)/list.c $(FREERTOS_SRC)/queue.c $(FREERTOS_SRC)/portable/MemMang/heap_2.c
# TODO - you will need to edit these two lines!
DEVICE=stm32f103rct6
# ST-FLASH = st-flash
# OOCD_INTERFACE = stlink-v2-1
# OOCD_TARGET = stm32l1
# OOCD_FILE = board/stm32ldiscovery.cfg
# You shouldn't have to edit anything below here.
VPATH += $(SHARED_DIR)
INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR))
OPENCM3_DIR=../libopencm3
include $(OPENCM3_DIR)/mk/genlink-config.mk
include ../rules.mk
include $(OPENCM3_DIR)/mk/genlink-rules.mk
size: all
$(SIZE) $(PROJECT).elf
write: $(PROJECT).bin
$(ST-FLASH) write $(PROJECT).bin 0x8000000
erase:
$(ST-FLASH) erase
And this is the content of my main.c file. As I have said before, this is on a custom board that I have made and am wanting to start learning freertos on. As such, the leds are on PORTB GPIO0 and GPIO1.
#include "FreeRTOS.h"
#include "task.h"
#include "libopencm3/stm32/gpio.h"
#include "libopencm3/stm32/rcc.h"
void BlinkLED1(void *parameters) {
(void)parameters;
for (;;) {
gpio_toggle(GPIOB, GPIO0);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void BlinkLED2(void *parameters) {
(void)parameters;
for (;;) {
gpio_toggle(GPIOB, GPIO1);
vTaskDelay(700 / portTICK_PERIOD_MS);
}
}
int main(void) {
// Set GPIO8 and clear GPIO9 to see toggle
rcc_clock_setup_in_hsi_out_64mhz();
// rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_HSI_64MHZ]);
rcc_periph_clock_enable(RCC_GPIOB);
// Output mode, no pull ups or pull down
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,
GPIO0 | GPIO1);
xTaskCreate(BlinkLED1, "LED1 Blink", configMINIMAL_STACK_SIZE + 500, NULL, 2,
NULL);
xTaskCreate(BlinkLED2, "LED2 Blink", configMINIMAL_STACK_SIZE + 500, NULL, 2,
NULL);
vTaskStartScheduler();
while (1) {
}
return 0;
}
Now when I try to run make, I got this error.
main.c:7:6: warning: no previous prototype for 'BlinkLED1' [-Wmissing-prototypes]
7 | void BlinkLED1(void *parameters) {
| ^~~~~~~~~
main.c:16:6: warning: no previous prototype for 'BlinkLED2' [-Wmissing-prototypes]
16 | void BlinkLED2(void *parameters) {
| ^~~~~~~~~
main.c: In function 'main':
main.c:41:3: warning: 'rcc_clock_setup_in_hsi_out_64mhz' is deprecated: use rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_HSI_64MHZ]) [-Wdeprecated-declarations]
41 | rcc_clock_setup_in_hsi_out_64mhz();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../libopencm3/include/libopencm3/stm32/rcc.h:26,
from main.c:5:
../libopencm3/include/libopencm3/stm32/f1/rcc.h:776:6: note: declared here
776 | void rcc_clock_setup_in_hsi_out_64mhz(void) LIBOPENCM3_DEPRECATED("use rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_HSI_64MHZ])");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/tasks.c
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/list.c
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/queue.c
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/portable/MemMang/heap_2.c
GENLNK stm32f103rct6
LD freeRTOS_test.elf
/Users/srikrishnachaitanyanarumanchi/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: bin/../shared_libs/FreeRTOS/FreeRTOS/Source/tasks.o: in function `vTaskSwitchContext':
/Users/srikrishnachaitanyanarumanchi/Workspace/libopencm3/test/freertos_test/../shared_libs/FreeRTOS/FreeRTOS/Source/tasks.c:3052: undefined reference to `vApplicationStackOverflowHook'
collect2: error: ld returned 1 exit status
make: *** [freeRTOS_test.elf] Error 1
Which, from my limited understanding and reading on the forums around needs to defined somewhere in case the application stackoverflows or to disable it in the freertosconfig.h file by settings this #define configCHECK_FOR_STACK_OVERFLOW 2
to 0
I did that and reran the make command again, and it compiles fine this time…
make
CC main.c
main.c:7:6: warning: no previous prototype for 'BlinkLED1' [-Wmissing-prototypes]
7 | void BlinkLED1(void *parameters) {
| ^~~~~~~~~
main.c:16:6: warning: no previous prototype for 'BlinkLED2' [-Wmissing-prototypes]
16 | void BlinkLED2(void *parameters) {
| ^~~~~~~~~
main.c: In function 'main':
main.c:41:3: warning: 'rcc_clock_setup_in_hsi_out_64mhz' is deprecated: use rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_HSI_64MHZ]) [-Wdeprecated-declarations]
41 | rcc_clock_setup_in_hsi_out_64mhz();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../libopencm3/include/libopencm3/stm32/rcc.h:26,
from main.c:5:
../libopencm3/include/libopencm3/stm32/f1/rcc.h:776:6: note: declared here
776 | void rcc_clock_setup_in_hsi_out_64mhz(void) LIBOPENCM3_DEPRECATED("use rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_HSI_64MHZ])");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/tasks.c
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/list.c
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/queue.c
CC ../shared_libs/FreeRTOS/FreeRTOS/Source/portable/MemMang/heap_2.c
GENLNK stm32f103rct6
LD freeRTOS_test.elf
OBJCOPY freeRTOS_test.bin
arm-none-eabi-size freeRTOS_test.elf
text data bss dec hex filename
16624 24 18712 35360 8a20 freeRTOS_test.elf
except… nothing happens… the program literally does nothing… I expect to see two blinking LEDS… and there is literally no activity…
SO, I fired up the debugger to find that the program was ending up in the blocking_handler
, when it entered the vTaskStartScheduler function.
The exact call stack is as follows.
vTaskStartScheduler -> xPortStartScheduler -> prvPortStartFirstTask -> <HardFault_Exception>
From a little more googling around, I understand that this is due to this
FreeRTOS FAQ - My application does not run ( Apparently new users cannot post a link.)
about a wrong interrupt vector table. I tried copy pasting the following three #defines
to my FreeRTOSConfig.h file but the behavior is still the same. blocking handler.
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
I suspected that this might also be caused if the handler functions in libopenCM3 are not defined as they are in the FAQ and looked around in the source of libopenCM3 to get the exact handler names, and used those in the #defines, like so.
/* Redirect FreeRTOS port interrupts. */
#define vPortSVCHandler sv_call_handler
#define xPortPendSVHandler pend_sv_handler
#define xPortSysTickHandler sys_tick_handler
Unfortunately, the same behavior persists.
I would be extremely grateful if someone more knowledgeable than me can point out what I am doing wrong and how to correct it. Again, I am a newbie with freeRTOS andI suspect this setup trouble are few and far inbetween.
I do apologize for the rather long post but I figured it would better to be verbose, in order to not waste your time and to help you folks, help me…
Thank you again folks, in advance and I do apologize if I have broken any of the forums rules. Please excuse me on the account of a noob.