STM32 Issues
Moderators: RoccoMarco, lbednarz, tfAteba
STM32 Issues
Hi,
I have been running a version of ChiBios 2.0.4 (Kernel no HAL) on the STM32F207 processor (has the CortexM3 Core). It is very new, and not released. After some driver developement I started to experiance some crashes, which resulted in the svcall interrupt vector. I have upgraded the kernel of the ChiBios to version 2.0.8 but now my threads are not running at all. I no longer see the PendSV interrupt handler in the ChiBios (has it been removed?). And it appears the port_switch function that involked the SVCall interrupt has also changed.
I see systick get called 10 times, svcall never gets called. The systick counter register is still counting.
Do you have any ideas? I have not changed any of my tasks only the Chibios kernel. I removed the drivers I was implementing to make sure that was not interferring.
I am using Code Sourcery EABI GCC compiler.
Thanks!
Brian Spranger
I have been running a version of ChiBios 2.0.4 (Kernel no HAL) on the STM32F207 processor (has the CortexM3 Core). It is very new, and not released. After some driver developement I started to experiance some crashes, which resulted in the svcall interrupt vector. I have upgraded the kernel of the ChiBios to version 2.0.8 but now my threads are not running at all. I no longer see the PendSV interrupt handler in the ChiBios (has it been removed?). And it appears the port_switch function that involked the SVCall interrupt has also changed.
I see systick get called 10 times, svcall never gets called. The systick counter register is still counting.
Do you have any ideas? I have not changed any of my tasks only the Chibios kernel. I removed the drivers I was implementing to make sure that was not interferring.
I am using Code Sourcery EABI GCC compiler.
Thanks!
Brian Spranger
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: STM32 Issues
Hello,
I need more info about the problem, the STM32F207 should work exactly like any other Cortex-M3. Is it possible you are experiencing problems related to the platform? for example:
About the PendSV vector, there are two Cortex-M3 ports in 2.0.x the default one does not use PendSV at all, there is also a "legacy" port from version 1.4.x that uses PendSV and performs the context switch in a different way. Is it possible you were using the legacy port and then switched to the default one? the legacy port is located under ./os/ports/GCC/ARMCMx/old.
There are some things you can try:
Giovanni
I need more info about the problem, the STM32F207 should work exactly like any other Cortex-M3. Is it possible you are experiencing problems related to the platform? for example:
- Clock tree initialization settings, it is different from the normal STM32s.
- Flash related settings (prefetch, wait states), note that the wait states must be assigned considering both the clock frequency and the VCC voltage.
About the PendSV vector, there are two Cortex-M3 ports in 2.0.x the default one does not use PendSV at all, there is also a "legacy" port from version 1.4.x that uses PendSV and performs the context switch in a different way. Is it possible you were using the legacy port and then switched to the default one? the legacy port is located under ./os/ports/GCC/ARMCMx/old.
There are some things you can try:
- Increase stack sizes and see if it makes a difference (including the main and process stacks from withing the linker script).
- Activate the various debug option (stacks, assertions, parameter checks) and then verify if some assertion is triggered, this could give us a hint of what is happening. You can inspect the global variable "panic_msg" after an assertion in order to retrieve the error message.
- Reduce the problem complexity by disabling parts of your application until you have a "naked" application then you can try re-enabling the various parts.
Giovanni
Re: STM32 Issues
Giovanni,
I did some more debugging and looking at the trace, one thread has exited (main), one thread is in the ready state and three threads are sleeping. There isn't any threads running. And that is what we have noticed. It is always sitting in the idle_thread.
What method is used to get the tasks into the next state?
The clocks and flash seem to be initialized fine, our timers, and communications all are at the correct rates.
We have also verified our stacks and they are good.
Thanks!
Brian
I did some more debugging and looking at the trace, one thread has exited (main), one thread is in the ready state and three threads are sleeping. There isn't any threads running. And that is what we have noticed. It is always sitting in the idle_thread.
What method is used to get the tasks into the next state?
The clocks and flash seem to be initialized fine, our timers, and communications all are at the correct rates.
We have also verified our stacks and they are good.
Thanks!
Brian
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: STM32 Issues
Hi Brian,
The thread states are not directly controlled by the application. Something like what you are describing happened to another developer a couple of months ago while developing an ADC driver, the ready list got corrupted.
The problem was caused by an interrupt handler that didn't reset the IRQ source properly so a counting semaphore was signaled continously until it overflowed.
If the application is sitting in the idle thread and no assertions were triggered could mean that the system is running normally, the idle thread is in running state and the other threads are waiting for external events that are not triggered for some reason. Probably the best thing to do is to post some code, especially the interrupt related code.
A hint about debugging, the trace buffer is hard to read without a specific tool, but if you need to see the "current" system state you can scan the registry using the debugger. The registry is a double linked list connecting all the active threads. You have simply to inspect the "rlist" global variable in Eclipse (or any other debugger) and then follow the links r_newer or r_older, with few clicks you can scan all the threads and see their detailed status, the link r_current points directly to the current thread.
A question, is the thread main() exit intentional?
Giovanni
The thread states are not directly controlled by the application. Something like what you are describing happened to another developer a couple of months ago while developing an ADC driver, the ready list got corrupted.
The problem was caused by an interrupt handler that didn't reset the IRQ source properly so a counting semaphore was signaled continously until it overflowed.
If the application is sitting in the idle thread and no assertions were triggered could mean that the system is running normally, the idle thread is in running state and the other threads are waiting for external events that are not triggered for some reason. Probably the best thing to do is to post some code, especially the interrupt related code.
A hint about debugging, the trace buffer is hard to read without a specific tool, but if you need to see the "current" system state you can scan the registry using the debugger. The registry is a double linked list connecting all the active threads. You have simply to inspect the "rlist" global variable in Eclipse (or any other debugger) and then follow the links r_newer or r_older, with few clicks you can scan all the threads and see their detailed status, the link r_current points directly to the current thread.
A question, is the thread main() exit intentional?
Giovanni
Re: STM32 Issues
Giovanni wrote:The thread states are not directly controlled by the application. Something like what you are describing happened to another developer a couple of months ago while developing an ADC driver, the ready list got corrupted.
The problem was caused by an interrupt handler that didn't reset the IRQ source properly so a counting semaphore was signaled continously until it overflowed.
Can you go into more detail about your comment "The problem was caused by an interrupt handler that didn't reset the IRQ source properly"? I'm not sure we are doing anything special for our interrupt exits.
Giovanni wrote:A hint about debugging, the trace buffer is hard to read without a specific tool, but if you need to see the "current" system state you can scan the registry using the debugger. The registry is a double linked list connecting all the active threads. You have simply to inspect the "rlist" global variable in Eclipse (or any other debugger) and then follow the links r_newer or r_older, with few clicks you can scan all the threads and see their detailed status, the link r_current points directly to the current thread.
I have been doing this, but I am never to sure what all the elements of the structure are.
Giovanni wrote:A question, is the thread main() exit intentional?
Yes, were are exiting the main() thread because we started two others. Should we put the main() thread into a while (1) instead?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: STM32 Issues
bspranger wrote:Can you go into more detail about your comment "The problem was caused by an interrupt handler that didn't reset the IRQ source properly"? I'm not sure we are doing anything special for our interrupt exits.
The issue was caused by an interrupt handler that didn't properly reset its source, the handler was invoked repeatedly until it crashed the system by overflowing a semaphore. Are you using the OS macros for interrupt handlers?
About interrupt handlers, another possible error related to IRQs is to use kernel primitives from IRQs having a priority higher than CORTEX_BASEPRI_KERNEL, those would be able to preempt the kernel.
bspranger wrote:Yes, were are exiting the main() thread because we started two others. Should we put the main() thread into a while (1) instead?
Exiting the main() thread is fine but you should not exit by returning but by invoking chThdExit(), returning from main would send the CPU into an infinite loop, this would block all threads with priority lower than NORMALPRIO.
Another minor issue is that exiting the main() thread does not recover the RAM statically allocated to that thread in the linker script (you may want to reduce the amount, the default is 1KB).
Giovanni
Re: STM32 Issues
I should mention that we have relocated the interrupt vector table into RAM. This seems to function fine with our code, but perhaps this is causing an issue with ChiBios?
Can you give an example of the OS macros for interrupt handlers?
Can the kernel NOT be preempted, for instance by an proprietary ADC driver?
We used chThdExit().
Giovanni wrote:Are you using the OS macros for interrupt handlers??
Can you give an example of the OS macros for interrupt handlers?
Giovanni wrote:About interrupt handlers, another possible error related to IRQs is to use kernel primitives from IRQs having a priority higher than CORTEX_BASEPRI_KERNEL, those would be able to preempt the kernel.
Can the kernel NOT be preempted, for instance by an proprietary ADC driver?
Giovanni wrote:Exiting the main() thread is fine but you should not exit by returning but by invoking chThdExit(), returning from main would send the CPU into an infinite loop, this would block all threads with priority lower than NORMALPRIO.
We used chThdExit().
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: STM32 Issues
bspranger wrote:I should mention that we have relocated the interrupt vector table into RAM. This seems to function fine with our code, but perhaps this is causing an issue with ChiBios?
It is not an issue.
bspranger wrote:Can you give an example of the OS macros for interrupt handlers?
Sure, you must write interrupt handler using the OS macros as shown in this article: http://www.chibios.org/dokuwiki/doku.ph ... interrupts
The macros take care of the rescheduling after the handler execution.
bspranger wrote:Can the kernel NOT be preempted, for instance by an proprietary ADC driver?
In ChibiOS/RT there are 2 abstract classes of IRQ: regular and fast.
Regular interrupt cannot preempt the kernel because have a priority less or equal to CORTEX_BASEPRI_KERNEL thus can invoke kernel primitives from ISRs, fast interrupts have an higher priority and can preempt the kernel (zero latency) but cannot invoke kernel primitives from ISRs. A proprietary ADC driver can or cannot preempt the kernel depending on the priority you assign to its interrupt handlers.
Details about this are explained in the "Kernel Concepts" section in the kernel documentation.
You may use the STM32 ADC driver provided in the HAL as example for writing an interrupt handler.
http://chibios.svn.sourceforge.net/view ... iew=markup
Giovanni
Re: STM32 Issues
Giovanni wrote:Sure, you must write interrupt handler using the OS macros as shown in this article: http://www.chibios.org/dokuwiki/doku.ph ... interrupts
The macros take care of the rescheduling after the handler execution.
In ChibiOS/RT there are 2 abstract classes of IRQ: regular and fast.
Regular interrupt cannot preempt the kernel because have a priority less or equal to CORTEX_BASEPRI_KERNEL thus can invoke kernel primitives from ISRs, fast interrupts have an higher priority and can preempt the kernel (zero latency) but cannot invoke kernel primitives from ISRs. A proprietary ADC driver can or cannot preempt the kernel depending on the priority you assign to its interrupt handlers.
Details about this are explained in the "Kernel Concepts" section in the kernel documentation.
You may use the STM32 ADC driver provided in the HAL as example for writing an interrupt handler.
http://chibios.svn.sourceforge.net/view ... iew=markup
Giovanni
When I look through the code for the STM32, it appears to me that the macros CH_IRQ_HANDLER(), CH_IRQ_PROLOGUE(), CH_IRQ_EPILOGUE, CH_FAST_IRQ_HANDLER(), ... all result in basically empty macros. So I don't see the benifit of adding those macros.
Please correct me if I am wrong.
We are not making any ChiBios calls from our interrupt routines so I would assume this means we can make our interrupts CH_FAST_IRQ_HANDLER(). Am I correct in saying this?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: STM32 Issues
Those macro are not Cortex specific, can be not empty on other architectures, it is a ways to write ISRs in a architecture independent way. Note that aren't all empty in the cortex port, the epilogue performs the rescheduling part.
Anyway you are correct, if you don't invoke any ChibiOS/RT function from within an interrupt handler then you do not need to write it that way, you may use CH_FAST_IRQ_HANDLER() but it is not mandatory, it is just abstraction. Such an ISR could not cause problems with the OS either, except for a possible IRQ stack overflow.
BTW, are you using the ChibiOS/RT startup files? if not make sure that the processor is in process/privileged mode before initializing the OS.
Giovanni
Anyway you are correct, if you don't invoke any ChibiOS/RT function from within an interrupt handler then you do not need to write it that way, you may use CH_FAST_IRQ_HANDLER() but it is not mandatory, it is just abstraction. Such an ISR could not cause problems with the OS either, except for a possible IRQ stack overflow.
BTW, are you using the ChibiOS/RT startup files? if not make sure that the processor is in process/privileged mode before initializing the OS.
Giovanni