I am developing bare metal applications over the past years, and I am thinking of switching over to Chibios. Currently I am interested in the Cortex-M architectures and most importantly to Cortex-M3 MCUs.
I have developed my own HAL, startup code and linker scripts and I am using Eclipse with managed makefiles. I am interested in keeping it that way. Note that the code mentioned is tested and is working correctly in bare metal applications.
I created a new project in Eclipse, and placed there only the following (I wanted to keep it minimal, so I can better track things around. I didn't need all those examples etc...)
- the os/rt directory
- the chconf.h file as provided in the templates for my MCU (STM32F103)
- the files cmparams.h, chcore.h, chcore_v7m.h, chcore_v7.c, chcoreasm_v7m.S, chtypes.h
Building went fine, I got no errors or warnings. I flashed my MCU with the binary file, and it started executing code normally. However at some point (while the os has been enabled) I get hardfaults, which I am unable to track down. Obviously I am missing something.
The code I try to build is fairly simple:
Code: Select all
#include "ch.h"
#include "systick.h"
static void thread(void * arg);
static THD_WORKING_AREA(threadWA, 128);
int main(void)
{
SysTick_init(1, NULL);
chSysInit();
chThdCreateStatic(threadWA, sizeof(threadWA), NORMALPRIO, thread, NULL);
while (1)
{
chThdSleepMilliseconds (50);
}
return 0;
}
static void thread(void __attribute__ ((__unused__)) * arg)
{
while(1)
{
volatile int i = 0;
chThdSleepMilliseconds (5000);
}
}
Note that the SysTick function above is provided by my HAL, and it just starts the SysTickTimer with a period of 1ms.
The startup code and the linker scripts I am using are those that I have posted here.
I guess it is something related to the context switch mechanism, or the startup code, or the stacks, or... But I am not sure.
Apart from what I have already done, what other steps have I to do to make my applications usable? Or how may I fix the already taken steps?