I am adopting one of my previous application to use the ARM RTX. Now have some questions to seek your help.
Question 1.I have noticed that in the RTX_CM_Lib.h, there is a section of code:
#ifdef __MICROLIB void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); void _main_init (void) { osKernelInitialize(); osThreadCreate(&os_thread_def_main, NULL); osKernelStart(); for (;;); } #else __asm void _platform_post_lib_init (void) { IMPORT os_thread_def_main IMPORT osKernelInitialize IMPORT osKernelStart IMPORT osThreadCreate IMPORT exit ADD SP,#0x10 BL osKernelInitialize LDR R0,=os_thread_def_main MOVS R1,#0 BL osThreadCreate BL osKernelStart BL exit ALIGN } #endif
So it seems the _main_init already has called osKernelStart given the microlib would not be used as in my case. Then is it necessary to call them again in my own main function as suggested in the supplied code template:
int main (void) { osKernelInitialize (); // initialize CMSIS-RTOS // initialize peripherals here // create 'thread' functions that start executing, // example: tid_name = osThreadCreate (osThread(name), NULL); osKernelStart (); // start thread execution }
Question 2 After I have chosen to use the CMSIS RTX via the pack manager, my program runs into the HardFault_Handler after this instruction in the code section mentioned in the question 1:
BL osKernelStart
Because it is well before the main function, I have no hint where the problem occurs. The STACK I assigned in the startup file is 0x4000. And other important RTX relevant setting are as below:
#define OS_TASKCNT 3 #define OS_STKSIZE 200 // this stack size value is in words #define OS_MAINSTKSIZE 250 // this stack size value is in words #define OS_STKCHECK 1
By the way, I don't quite understand what the exact relationship between the stack size in the startup file and the stack size in the RTX Setting file. Are all the RTX stack are included in the stack assigned in the startup file?
My application doesn't reside from the start of the internal Flash(0x8000000 for my CPU, STM32F105), but with a offset. I have modified the vector table in the system_stm32f10x.c:
#define VECT_TAB_OFFSET APP_OFF /*!< Vector Table base offset field. This value must be a multiple of 0x200. */
And in the target setting tab. After a check of the generated hex file, I am sure all the code start from this offset.
The problem only occurs after I choose the CMSIS RTX component. My main function only adds these lines to the previous content:
#ifdef USE_RTX osKernelInitialize (); // initialize CMSIS-RTOS mut_Test = osMutexCreate(osMutex(mut_Test)); tid_phaseA = osThreadCreate(osThread(phaseA), NULL); tid_phaseB = osThreadCreate(osThread(phaseB), NULL); tid_clock = osThreadCreate(osThread(clock), NULL); osSignalSet(tid_phaseA, 0x0001); /* set signal to phaseA thread */ osKernelStart (); // start thread execution osDelay(osWaitForever); #endif
If anyone has some hint about how to debug this HardFault, it would be very helpful. Thanks!
Hi !
I have the same problem. Starting RTX application at address 0x08020000 result in HardFault-Handler. The problem occurs before main() in the module rt_CMSIS.c. The function osKernelStart() calls the function __svcKernelStart(). The HardFault-Handler is called.
If anyone has a solution, please let me know.
regards Marc