SOLVED: Requirements to run CMSIS RTX RTOS - Page 1
Forum section: electronics / general

author: bernroth
author_rank: Regular Contributor
timestamp: November 23, 2014, 04:12:18 pm
content: Hello all!What are the basic requirements to successfully run and operate CMSIS RTX RTOS on an ARM CM0 processor?More details:I have been working today to implement the CMSIS RTOS in my project on an LPC122x MCU. I am using make, gcc and vim as "IDE".The linker scripts and startup files have been auto-generated in LPCxpresso. CMSIS header files are used.I added all source code files from RTOS to the Makefile and everything all-together compiles without error.As soon following code is run, the MCU hangs and does not make anything else.osKernelInitialize();osKernelStart(); <-- causes the system to hangI have no debugger connected to the target so my insights in the processor are a bit limited.I am quite sure that some requirement is not met so the operating system can not run and causes an exception.In my linker script I do not have a section which initialises or defines the heap section in the processor memory space.This could be an issue but I am not sure.Has anyone successfully implemented CMSIS RTX RTOS in your own project using GCC? What are the basic requirements, do's and dont's?Best regards,Bernhard

author: mikerj
author_rank: Super Contributor
timestamp: November 23, 2014, 08:20:04 pm
content: You say the start-up files have been auto-generated; have you checked that the relevant interrupt vectors are pointing to the RTOS functions rather than an empty handler? SVC, PendSV and SysTick are all likely to be used for an RTOS.

author: bernroth
author_rank: Regular Contributor
timestamp: November 23, 2014, 09:25:26 pm
content: Quote from: mikerj on November 23, 2014, 08:20:04 pmThanks for your feedback, the interrupt handlers are declared as weak in the startup_lpc12xx.c which means that another definition somewhere in the code will overwrite/replace them.In RTX this is done in HAL_CM0.SPreviously the linker complained about my own SysTick_Handler having been still in the code (I removed it now) so IMHO the pointers are correctly set.In the meantime I have discovered something which might be the cause of the "hang":The initialisation code has set the priority of EINT1_IRQn to zero, so highest priority:NVIC_SetPriority(EINT1_IRQn, 0);In the documentation of FreeRTOS I remember having seen that no interrupt must be declared with an higher priority as the RTOS interrupts.Maybe this is applicable to CMSIS RTX RTOS as well.I will try and see what happens tomorrow in the office.

author: andyturk
author_rank: Frequent Contributor
timestamp: November 23, 2014, 09:49:18 pm
content: Quote from: bernroth on November 23, 2014, 04:12:18 pmYep.First off, consider using ChibiOS instead. ;-)Second, get JTAG/SWD working. You can guess at problems for weeks, but a debugger will tell you right away which exception handler you're in.Third, pay particular attention to how your startup code sets up the stack pointer(s). Also, since RTX wants to dynamically allocate stack space at runtime, make sure that it's able to allocate memory correctly.osKernelStart is where your thread code will be run, so if it's failing there, it could either be a problem with the kernel itself or something that happened in your code. I'd start looking at whether it's able to make the first context switch correctly. I.e., does it run any of your code or die before?

author: bernroth
author_rank: Regular Contributor
timestamp: November 24, 2014, 06:31:04 am
content: Quote from: andyturk on November 23, 2014, 09:49:18 pmI am using ChibiOS in other projects with STM32 and it works very well. For this specific project I would like to use CMSIS RTOS (among other reasons are licensing restrictions).Quote from: andyturk on November 23, 2014, 09:49:18 pmDone. The CPU happend to be stuck in "SVCall_Handler" which is spelled wrong in the startup file and should be "SVC_Handler"After fixing this issue the processor stays in HardFault_Handler - great(gdb) bt#0 0x000000de in HardFault_Handler () at startup/startup_lpc12xx.c:267#1 <signal handler called>#2 SVC_Handler () at HAL_CM0.S:230#3 0x00000250 in SVC_Handler () at HAL_CM0.S:222Backtrace stopped: previous frame identical to this frame (corrupt stack?)Quote from: andyturk on November 23, 2014, 09:49:18 pmThis is what I am trying to find out. How does the startup code need to get modified to make the dynamic stack allocation work?I have been using the supplied linker files of the RTOS package from the Templates directory, adjusting the ISR names for my CPUThen GCC sample startup assembler code and supplied linker script. All not workingMaybe someone whats to share a known working linker file and startup script for ARM CMx so that I can find out the key differences.

author: andersm
author_rank: Super Contributor
timestamp: November 24, 2014, 03:41:38 pm
content: I've used CMSIS-RTX on one project, running on an STM32F103. Setting up the project was quite painless using theGNU ARM Eclipseplugin, I don't really remember doing anything except editing the RTX_Conf_CM.c file. My main function calls osKernelInitialize(), then initializes the hardware and creates all threads and other OS objects, and then calls osKernelStart(). Note that osKernelStart() returns, the thread that calls osKernelInitialize() is transformed into the idle task.QuoteIt doesn't. You edit the OS_PRIVSTKSIZE macro in RTX_Conf_CM.c, the memory pool is allocated as a static array in RTX_CM_lib.h (a bit bass-ackwards, but there you go).

author: andyturk
author_rank: Frequent Contributor
timestamp: November 25, 2014, 03:06:41 pm
content: Quote from: bernroth on November 24, 2014, 06:31:04 amIf your release is the same as mine, HAL_CM0.S:230 is an LDMIA instruction that's reloading registers from a saved thread context. If that's crashing, it's probably due to a stack pointer being screwed up in an early context switch.

author: bernroth
author_rank: Regular Contributor
timestamp: November 26, 2014, 10:36:03 am
content: Just a short update:The RTOS works fine now. The reason for it to enter HardFault_Handler was that I must have mixed up the RTOS source 4.70 with HAL_CM0.S of 4.75Shame on meAnother issue was the "SVCall_Handler" is spelled different in LPCxpresso startup files. The "standard" spelling shall be "SVC_Handler" to work with RTX.It is indeed not required to setup the linker script or the startup file in any way. The memories like thread stack are setup in RTX_Conf_CM.c and then reserved in the .bss region.So my final recap:- Check your interrupt handlers in your startup_xxx.c file and match them with the names in HAL_CM0.S- Heap memory does not need to be declared in linker scripts, memory is declared only in RTX_Conf_CM.c- Use all files from the same RTX ZIP archive- To help bug hunting: Put some LED blink code in the while(1) loop of the exception handlersThanks to all for your help and support!