cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 new project.

arganasss
Associate II
Posted on December 11, 2013 at 14:33

Hello everyone. I'm new to programming, just got this stm32f3 board. I tried to run TIM_PWM_Input example ant it seems to work just fine. That's what i want to do now - measure external signal frequency. However, when i created new project, and copied absolutely everything from TIM_PWM_Input example, with all libs and directories, the code doesn't work. When i connect external signal and run the code, it jumps to HardFault_handler. So i want to ask is there a way to fix it and why it happens? i mean i just coppied example project and it doesn't work. Will appreciate any help. Thanks in advance.

24 REPLIES 24
arganasss
Associate II
Posted on December 11, 2013 at 15:15

I also did some research about HardFault_handler and did stack ussage analysis : „Warning[Lo008]: [stack usage analysis] at least one function appears to be uncalled. Example: ''BusFault_Handler''. A complete list of uncalled functions is in the map file. “ I know where the map file is and how to open it, but i can't find and explanation how to read it. I mean what information can i get from that file?

frankmeyer9
Associate II
Posted on December 11, 2013 at 15:39

„Warning[Lo008]: [stack usage analysis] at least one function appears to be uncalled. Example: ''BusFault_Handler''.

 

Not sure if the helps in this regard.

Async event handlers like interrupt/fault/exception handler are generally not ''called'' per se, and require a meta-knowledge of the MCU for a proper automatic analysis.

But indeed, your stack might be too small, and cause spurious crashes at runtime. One often tends to forget those project setting items when cloning a project.

Have you tried to single-step with a debugger, and locate the position of the crash ?

Or, to tackle the issue from the other side, you can use a debugger to halt the code in the hardfault handler, and inspect the SCB register flags, which should give some indication of the reason. You will find several thread to this topic in this forum ...

Posted on December 11, 2013 at 17:13

Check also pre-processor defines and include search paths buried in the project options meta-data.

Become more familiar with the tool chain (IAR?) that you have purchased, read the documentation, get some paid training on it, review YouTube videos, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arganasss
Associate II
Posted on December 11, 2013 at 17:21

Thanks for your replay fm. I fixes this problem. However, now i got some more. I would be very grateful if you helped me to solve them out. I managed to get my code working. Now i want to print the value of external signal frequency and duty cycle in the terminal. Im using IAR btw. I can see through registers that code is working and duty cycle and frequency are measured correctly, but when i debug the code, this warning comes:„Warning[Lo007]: [stack usage analysis] at least one function does not have stack usage information. Example: ''Reset_Handler''. A complete list of such functions is in the map file. “ However, the code works. When i break the code while its running, i always see that it stops in TIM2_IRQHandler. So whats the idea of that? If i want to printf those values on the terminal, i have to stop Timer making interrupts or what?

BTW still dont know, what .map file can say to me about my code. Thank you for your answers and help in advance.

Posted on December 11, 2013 at 17:36

For printf() to work you'd need to bring up a suitable interface, and have code to direct STDIO output to it. That presumably could be a USART or SWV connection.

If you are just taking the measurements in the TIM IRQ there is no need to stop it, just don't use things like printf()/puts() in the interrupt handler, but rather in your main loop.

Your ''STM32F3 board'' is a bit generic to give specific advice on, what exactly do you have?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
frankmeyer9
Associate II
Posted on December 12, 2013 at 09:25

If you are just taking the measurements in the TIM IRQ there is no need to stop it, just don't use things like printf()/puts() in the interrupt handler, but rather in your main loop.

 

In addition, you need to take care that your output routine (e.g. printf()) does keep up with the data generation rate. Otherwise you may experience data loss/corruption, or crashes.

To the map file: this is basically a list all program objects, i.e. functions (code) and variables (data), and the actual physical addresses they are mapped to. Hence the name map file.

arganasss
Associate II
Posted on December 12, 2013 at 17:13

Thanks for your replay's fm and clive1. Im using stm32f3 discovery board. So your idea is that if i want to print the frequency vaule in IAR I/O Terminal, i have to do a delay after signal is measured, so it can be physically written to the register? And one more question: i have noticed, that then measuring high frequencies ( 80-120kHz), it is measured with  0.3-0.6kHz bias. From board schematics i found out that i can put external quartz on it. Would that fix the problem? I mean with that quartz, maybe the measurement bias would be smaller? And if so, how should i say to processor that there is an external quartz? Many thanks for you attention and help.

arganasss
Associate II
Posted on December 12, 2013 at 17:15

And also, do you have any idea why, then i run my code and i stop it, it always stops in TIM2_IRQHandler? Thanks again.

Posted on December 12, 2013 at 19:12

The STM32F3-Discovery derives it's 8 MHz HSE clock from the oscillator used by the ST-LINK's F103 part via it's MCO pin and the the HSE_IN pin.

Sitting in long blocking loops in interrupt handlers is something to be avoided, for reasons that should be obvious.

Measuring frequency can be done two ways, for low frequencies you can time stamp the edge(s) using a high frequency reference and compute period/duty, for higher frequencies you want to count pulses, and integrate over a fixed period, 1 ms, a second, whatever is appropriate for the bit width of the counter, modulation and range being measured.

Having not seen your code I'd guess a) you don't clear the interrupt, or b) you are incessantly interrupting and saturating the processor?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..