Page 1 of 1

NIL without HAL / wrong PSP value

Posted: Sun Feb 03, 2019 11:57 am
by PeterAwsmtek
Hello!
I have the baremetal project in which I want to add ChibiOS.
For test I created empty project with same MCU, startup, vector table and ldscript.
As well I use LL library provided by manufacturer.
Startup used is CMSIS startup.
Ldscripts and early init used are provided my GNU ARM Embedded project.
MCU is STM32F103

OSless test project has been built and runned successfully.
Then I added ChibiOS/NIL, looking at NIL-ARMCM0-GENERIC demo.
I know that my MCU is CM3, but I think thereis no difference in project itself.
Steps to add RTOS:
1 - Ensure I have the same initializing code for SysTick Timer;
2 - Added ch.h headers and copied chconf.h to project;
3 - Added ChibiOS handling code to SysTick ISR Handler;
4 - Added chSysInit() as last step in program init section (in main());
5 - Implemented 2 tasks, added it ot THD_TABLE and set CH_CFG_NUM_THREADS to 2
6 - Changed variable name for defining heap in ldscript

After that I could build project and run debug session on target.
The issue I have is I have wrong (as I thing) PSP value at start of program. The value is 0x0.
So this value is used to switch context in epilog of systick ISR and causes HardFault exception.

Should I make some changes in ldscript or/and startup code to make ChibiOS working?

Re: NIL without HAL / wrong PSP value

Posted: Sun Feb 03, 2019 2:37 pm
by Giovanni
Hi,

ChibiOS requires the dual stacks mode of the Cortex-M (both PSP and MSP are used), are your startup files initializing this mode? look at ChibiOS startup files for an example.

Giovanni

Re: NIL without HAL / wrong PSP value

Posted: Mon Feb 04, 2019 10:27 pm
by PeterAwsmtek
Thanks! I am starting to move from my startup to chibios startup.
In the file crt1.c there are lots of extern variables from linker. ram0, ram1 etc.
That is purpose of this? can these regions be merged, resized of rearranged? How it used in os?

Re: NIL without HAL / wrong PSP value

Posted: Tue Feb 05, 2019 8:18 am
by Giovanni
Hi,

Our linker script defines several generic regions, flash0..7, ram0..7, the startup file initialize those regions. The OS itself does not touch those directly.

If you want to adopt the startup files then you need also to use our .ld files structure (which is quite flexible).

Giovanni

Re: NIL without HAL / wrong PSP value

Posted: Tue Feb 05, 2019 8:37 pm
by PeterAwsmtek
I've started adopting it and I found definition of double stack. Now I need some time to understand all relations between ld and startup.
Thank you for support!