Posts

Watch out! Scammers in the town.

Image
T oday's post is not about microcontrollers. It's about scammers. I will go through an (unsuccessful) attempt to steal my money. I was selling my old Macbook on Facebook Marketplace. I used marketplace a few times before and it was always rather positive experience. But not this time. Here is the conversation with one of the "buyers" with my comments. The "buyer's" name is Klaudia. I'm pretty sure that its a real person account that has been hacked, so I won't blame the real Klaudia for that :)  Klaudia Available? Me: Yes Klaudia: What are the recent conditions Where are you located? Me: It’s in very good condition. I’m at Taringa So far looks legit. Someone who wanted to buy would ask these questions. Keep talking... Klaudia: Okay sounds good, I won't be able to pick up myself today because of my working hours but I can send one of my truck driver along with my son to come pick it up and Do you have paypal or bank transfer? Now things diverg...

STM32 general purpose timer as a trigger for multiple time dependant events

Image
 Imagine, you're building a TDMA application with an STM32 controller and you're solving the problem of precise timing for multiple events. TDMA stands for Time Division Multiple Access. It is a channel access method that allows multiple users to share a common data channel (e.g. the same frequency) by dividing the signal into different time slots.  In the followong playground TDMA system with three time slots, the master transmits in slot #0 and it receives from three other users in slots #1, #2. The transmit function is called at time T0=0, and the receive functions are called at times T1, and T2, respectively. The later times are all based on the master clock T0, but they may be slightly adjusted to compensate for the delays of the remote devices. A neat way to solve this timing issue is to use a timer (e.g., TIM2) with multiple channels to generate all the required times. The timer overflow event can be used as the master clock, which triggers the transmit function. Two ou...

STM32 built-in bootloader

Image
O nce we have finished our main working horse algorithm (well, I know it never finished), the next thing we facing is future support. All software has bugs, and importantly we want to be able to update our device every time when some of the bugs has been fixed.  STM did arguably good job providing built-in bootloader that can use multiple interfaces. Here I describe how to use the USB-based update mechanism dubbed DFU. DFU is an open prototcol that is well supported by many IDEs including STM32CubeProgrammer. Furthermore literally every programming language has DFU libraries, so it is fairly easy to write your own uploader if needed. I start with STM32H7 series and I use the NUCLEO-H743ZI2 board for concreteness.  To run the built-in bootloader, we need to do two things. First, we need to set the stack pointer to the area of RAM that bootloader expected to see. Secong, we need to change the PC register value to the entry address of the bootloader. Sounds easy, right? It worth ...

As simple as the timer TIM1 (not really)

Image
 L ets start with something "simple" yet still widely misundersood:  standard timers in STM32. STM32 microcontrollers have a unified timer periphery called "TIMx". This means that all timers with the same name, such as TIM2, will have the same functionality and registers, regardless of the MCU series. For example, TIM2 in STM32G474 will be functionally equivalent to TIM2 in STM32L052. That's cool, isn't it? The most important timer parameters are the clock divider and the number it counts up to before it resets to zero. The clock divider is called the "Prescaler", and the number it counts up to is called the "Counter Period" or "Auto-reload Register". There is also a "Repetition Counter", but we will ignore it for now. The value you enter in STM32CubeIDE is not quite what it sounds. Let's look at the formula from [1], page 11:   Update_event = TIM_CLK/((Prescaller + 1)*(Autoreload + 1)*(Repetition + 1)) As you can ...

Why this blog?

Image
Anyone who designs firmware for microcontrollers knows the feeling of wasting days on a "trivial" problem. Whether it's due to a lack of documentation, bugs in the MCU's HAL, or simply a misunderstanding of the MCU's capabilities, these problems can be incredibly frustrating.  This blog is a collection of tips and tricks that I've personally discovered while programming STM32 MCUs. I hope that these tips will give you a fresh look on both typical and non-trivial problems, and help you avoid some pitfalls.