STM32 Barrier Instructions.

STM32 Barrier Instructions.
STM32

If you have never looked into how a microcontroller works, you probably think it executes instructions sequentially, one after another. That is exactly how the first MCUs worked, but over time their architecture became more complex to increase performance. It is important to note that executing an instruction itself consists of stages. In general terms, from the MCU's point of view it looks like this: fetch the instruction from memory, execute it...

STM32 USB: GETTING STARTED.

STM32 USB: GETTING STARTED.
STM32

Today even the cheapest MCUs have hardware USB, and at the same time this interface is the standard for connecting peripherals to a PC. I realized this long ago, but USB is quite complex and for a long time I didn't know how to approach it...

OTM8009A TFT Display Initialization.

OTM8009A TFT Display Initialization.
Дисплеи

Exactly five years have passed since the first article describing display initialization appeared on this site. I used that display in my projects for years, and over that time displays with better specifications have become available. For example, a 3.97-inch IPS display with a resolution of 800x480 pixels...

STM32: How to Write a float to a Backup Register.

STM32: How to Write a float to a Backup Register.
STM32

I have been asked several times how to write a float variable to external EEPROM or to backup registers. I found this question interesting, so I decided to answer it in an article. As you know, one backup register holds 16 bits, while a float variable contains 32 bits. So to store one float variable, we need 2 backup registers. The first...

STM32 DAC.

STM32 DAC.
STM32

The key difference between digital and analog electronics is that digital electronics operates with only two signal levels, logic zero and logic one. This doesn't mean that if we connect a multimeter to a microcontroller pin, it will show 0 or 1 V. Figuratively speaking, zero can be thought of as the absence of a signal and one as the presence of a signal, while the magnitude of the signal itself depends on...

STM32 SDIO.

STM32 SDIO.
STM32

There are already several articles on this site about working with an SD card connected via SPI. But SPI has one drawback: it is not "native" for the card and, as a result, it doesn't support some commands and doesn't provide the maximum data transfer speed. As for command support, I'm not very interested in that for now, but I would like to increase the data transfer speed...

STM32 ONE PULSE MODE.

STM32 ONE PULSE MODE.
STM32

In one of my projects I used the following mechanism to control a buzzer: I turned it on manually, started a timer and turned it off in the interrupt triggered by the timer overflow. Over time the number of interrupts in the project grew, and other interrupts often prevented the one that turned off the buzzer from firing. As a result, the buzzer always produced a beep of varying length...

STM32 I2S.

STM32 I2S.
STM32

The I2S protocol, not to be confused with I2C, is designed for transmitting an audio stream. In my device this protocol is used to transfer the audio stream between a codec and the MCU. I'd like to note right away that STM32 has no separate I2S module as such; the one it has is implemented on the basis of the SPI module, and they share the same DR[0:15] register...

STM32 I2C.

STM32 I2C.
STM32

Lately I keep coming across negative reviews of the I2C bus on STM32, saying that working with it is like performing a ritual dance and so on. Over the past month I managed to get two I2C chips working without any dancing, just careful reading of the datasheet...

STM32 FLASH.

STM32 FLASH.
STM32

I think regular visitors to the site have noticed that I prefer to do everything with registers, but sometimes I still use SPL. For example, the article about a custom bootloader used library functions to work with flash memory. Once again connecting this library, I decided that it takes up too much space and decided to implement the necessary functions myself. To work with flash memory...

STM32 RTC, Calendar.

STM32 RTC, Calendar.
STM32

Let's start with the fact that RTC is an abbreviation that stands for Real-time clock. In the old days, when I used AVR MCUs, I used a separate chip as the RTC and communicated with it over a specific protocol. On STM32, however, the RTC is a module implemented inside the MCU. On STM32 the RTC has the following...

STM32: Problems Connecting a Display via LTDC.

STM32: Problems Connecting a Display via LTDC.
STM32

In one of my previous articles I described how to connect a display to an STM32 microcontroller using the LTDC interface. The article ended with a video showing an image on the display built into the DISCOVERY board. Naturally, my next wish was to run something bigger and connect it myself, so that I'd have a complete picture in my head. I ordered a 7-inch display from China...

STM32F3 and STM32F4 SPI Problems.

STM32F3 and STM32F4 SPI Problems.
STM32

When porting one of my projects from the F1 series to the F3 series, I ran into a problem: SPI frames were always 16 bits long, but I needed 8. Interestingly, the F1 series has a single DFF (Data frame format) bit for setting the SPI frame length: when it is cleared the frame is 8 bits, when set, 16. In the F3 series a 4-bit field was allocated for this, and the frame length can...

STM32: How LTDC Works.

STM32: How LTDC Works.
STM32

About six months ago, one of the site's regular visitors sent me an STM32F429I DISCO development board. When I told him I didn't need it, he replied that it was a gift and I should accept it. He had also read somewhere that the RAM on the board is needed for the display and asked me what exactly for, but I didn't have an answer to that question. It was clear that the RAM acts...

STM32 DMA MEM2MEM.

STM32 DMA MEM2MEM.
STM32

In one of my previous articles I already described what DMA is and gave an example of it working together with an ADC. In that example, the ADC conversion results were written to a buffer without involving the core. This time I needed to move a buffer from one memory area to another, and I knew for sure that this can be done with DMA using MEM2MEM mode...

STM32 Frequency Measurement.

STM32 Frequency Measurement.
STM32

In one of my previous articles I talked about the STM32 capture mode and gave an example of how to use it to measure a signal's period. But this method can't ACCURATELY measure the period of a high-frequency signal (it will become clear below which signal counts as high-frequency). Suppose the frequency of the signal under test is 1MHz and our timer counts 72 million per second. Let's convert the frequency to a period...

Writing Your Own Bootloader for STM32, Part 2.

Writing Your Own Bootloader for STM32, Part 2.
STM32

While I was finishing the previous article, I came across a thread on Radiokot discussing what format to use for sending firmware to a bootloader. I had the same question, and at the end of the previous article I described why it is more convenient to send firmware as a hex file than as a binary; those interested can read it here. So, we need to look at the record types in a hex file and extend the code from the previous article. Everything...

Writing Your Own Bootloader for STM32.

Writing Your Own Bootloader for STM32.
STM32

In one of my previous articles I described how to flash an STM32 using the bootloader and explained how it works. For those who haven't read it, let me remind you that a bootloader is essentially a program that lives in the MCU and can rewrite its memory, i.e. update the firmware. I think someone may wonder why write a bootloader yourself if you can use the built-in one. The answer to this question is very simple...

How to Flash an STM32 Using KEIL UVISION.

How to Flash an STM32 Using KEIL UVISION.
STM32

Once a friend scolded me because I sent him a hex file instead of a project, and he couldn't manage to load it into the microcontroller. Honestly, I never understood why he was scolding me, since he was the one who couldn't do it))) This situation prompted me to write this article. So, we have firmware that we want to load into the MCU. First, we need to create an empty project, selecting the MCU...

How to Detect Stack Overflow in KEIL UVISION.

How to Detect Stack Overflow in KEIL UVISION.
STM32

There is plenty of information about the stack on the internet, so I probably can't tell you anything new. If someone still doesn't know, the stack is an area of RAM that works like a stack of plates. What kind of principle is that? The principle is that if there is a stack of identical plates in front of us and we need to take one, we take the top one, since it's the easiest to take. The same...