Category: Tutorials

How to use scanf with USART 3

How to use scanf with USART

I’ve already posted how to use printf (send data to stream) on STM32Fxxx devices. Recently, I received a comment, how to use scanf function to read strings and convert them from USART. Here is a little bit more to do before it will work correct. When you call scanf function, it calls subfunction fgetc, where you return a character. This function is called until it does not return EOF (-1). And it is called very fast. If you check in this function, if...

Disable peripherals in debug mode on STM32F4xx 0

Disable peripherals in debug mode on STM32F4xx

Have you ever used watchdog in your application? Have you ever debug your application when watchdog was enabled and you hit stop? Watchdog did not stop in this case and when you pressed “continue” in your debugger, your program starts over because WDG has reset your system. One choice is that you remove line where you initialize IWDG, but you then must recompile and redownload and all that stuff. Wasting useful time. To avoid this problem, STM32 devices have possibility...

How to properly enable/disable interrupts in ARM Cortex-M? 9

How to properly enable/disable interrupts in ARM Cortex-M?

Point of this post is not how to use NVIC (Nested Vectored Interrupt Controller) in Cortex-M processors but how to disable/enable interrupts properly for your system to avoid strange behaviours in your code. Let’s assume you have 2 functions, which do some important stuff and they have to make sure that noone interrupts these 2 functions

ARM Cortex-M SCB ICSR register structure. From arm.com 1

Get interrupt execution status on Cortex-M processors

You might come to a situation when you wanna know if current code is executing inside interrupt or not. This might be handy when you do a library and you have one function which you wanna call in interrupt handler for specific event or without interrupt handler, buf wanna execute something specific in function only if you are currently in interrupt. You can create 2 different functions of course, but what if you have one very big function, and for...

CPU load monitor for STM32F4xx 0

CPU load monitor for STM32F4xx

I’ve been searching for a simple CPU load monitor on STM32F4xx device. Today, I’ve managed to get one very, very primitive CPU load monitor for these devices. Check library here. STM32F4xx have built-in DWT (Data Watchpoint and Trace unit) which has several timers there. 2 of them are cycle counter and sleep counter. The first counts number of CPU cycles and the second counts number of cycles where CPU was sleeping. It would be very easy to get CPU load,...

How to properly set clock speed for STM32F4xx devices 71

How to properly set clock speed for STM32F4xx devices

I see that you have problems with your devices when you don’t know even (and you don’t even ask) on which speed your device is actually running. Speed of your device depends on PLL settings or clock source you have selected for system core clock. In most cases system core clock’s source is PLL output. To get proper value, you check ALWAYS first these settings when something is not working. Because I’m tired of questions that something is not working but...