Sysprogs forums › Forums › VisualGDB › STM32 Detailed ADC tutorial issue
Tagged: ADC tutorial, Discovery, STM32F4
- This topic has 5 replies, 2 voices, and was last updated 8 years ago by parsec67.
-
AuthorPosts
-
November 24, 2016 at 13:03 #9579parsec67Participant
Hi, new user question;
I’m considering buying VisualGDB Embedded and just installed 5.2 r3 trial version. Following the ADC tutorial using an F4 Disco board I cannot get it to work properly. Everything is peachy up to step 13; ADC captures trim pot changes via polling and live variables/graph plot are reflecting this accurately.
But then following step 14-15, the LED4 brightness change doesn’t happen after switching to interrupts instead of polling. LED just stays off. I have verified that the conversion complete handler is called and this is also obvious from the fact that the live variable/graph still changes as expected.
Using a breakpoint in the main function for(;;) loop shows that it is hit once at startup but never again after that.
The code is basically copy-paste from the tutorial page so ADC/GPIO configurations should all be correct, which I have also double-checked a few times. It feels like conversions happen too fast despite 480 cycle sample time? Any ideas what else I should look into to get this working?
- This topic was modified 8 years, 1 month ago by parsec67.
November 24, 2016 at 21:11 #9585supportKeymasterHi,
Please try the Debug->Break All command and see what code is running. Perhaps you have missed one of the interrupt handlers and the program is stuck in DefaultHandler()?
If no other interrupt occurs, please try stepping through the ADC interrupt handler provided by HAL and check that it clears the ‘conversion complete’ flag in the ADC peripheral so that the interrupt is not raised immediately after.
Another reason for this could be that the ADC is configured to fire the interrupts too fast and the main loop never gets a chance to run. In this case lowering the ADC frequency or raising the CPU clock frequency should help.
November 24, 2016 at 23:46 #9591parsec67ParticipantThanks, yes it is stuck looping in Default_Handler(). I’m really not sure what I am missing, checked my code for the Nth time against the example and I can’t see anything that differs.
In the default handler there is a comment;
//If you get stuck here, your code is missing a handler for some interrupt.
//Define a ‘DEBUG_DEFAULT_INTERRUPT_HANDLERS’ macro via VisualGDB Project Properties and rebuild your project.
//This will pinpoint a specific missing vector.Where exactly in properties should I define this?
November 25, 2016 at 11:10 #9592parsec67ParticipantFigured it out eventually, yay!
DEBUG_DEFAULT_INTERRUPT_HANDLERS goes into Project properties->Makefile settings->Preprocessor macros
Building+running with this macro pointed me to a missing SysTick_Handler() interrupt. I had this function already in my code but it was not explicitly declared as extern “C”.
When adding ADC interrupt handler and callback (step 13 in tutorial), which are wrapped in an extern “C” declaration I got several build errors. To get rid of these I had to remove the “#ifdef __cplusplus/extern “C”/#endif” section at the beginning of the main source file. This definition is put there automatically when creating a LEDBlink sample project, which the ADC tutorial is built upon. The example code with added ADC interrupt handlers will not compile unless ‘#ifdef…’ is removed but in doing so the SysTick_Handler() is no longer valid unless explicitly declared as ‘extern “C”. I think this should be mentioned somewhere to avoid confusion.
November 26, 2016 at 04:17 #9596supportKeymasterHi,
Thanks for clarifying this. When we made the tutorial, we could not get any errors with the original extern “C” block.
Please feel free to post the errors you got so that we could check what could be causing this.
November 26, 2016 at 10:21 #9598parsec67ParticipantThere is a little bit more to this story. I started from scratch with a new LEDBlink template, added code from the tutorial, and could not reproduce the build errors. Long story short, there is nothing wrong with the tutorial.
In the process I found what my problem was all along. The ‘#ifdef __cplusplus extern “C” #endif’ at the beginning actually belongs to the SysTick_Handler. I got confused and thought the #ifdef was for the entire source file because there are no curly braces that wraps this specific function.
So, when moving all global variable declarations to the top of the source file, which I normally do to have them collected in one place, I placed them between the #ifdef segment and SysTick_Handler. This generated an undefined reference error for the first variable declared after the #ifdef segment due to it now being declared extern “C”.
-
AuthorPosts
- You must be logged in to reply to this topic.