FreeRTOS tutorial on STM32

A High-density line of STM32 microcontrollers has quite many features that can be used in your programs. However, the more features you add to the source, the more complicated the program becomes, and it may become challenging to keep up with all things. Relying on the main loop and interrupts becomes a time-consuming task to manage. If you do not want to struggle while tuning things up manually, you can use one of the best free real-time operating systems (RTOS). It is handy when you need many separate functions to run in parallel without missing a task. RTOS scheduler takes care of giving each task a required period to perform. There are many great RTOS systems around. Many of them are free and open source. Follow the FreeRTOS tutorial to see how easy it is to run complex tasks. I love using FreeRTOS, which has a long successful history and is flexible to fit multiple hardware types. You can check out my demo FreeRTOS tutorial on Atmega128. I also encourage you to give it a try for other RTOS systems like ChibiOS, BeRTOS, and others. FreeRTOS is quite simple and easy to use. It has practically all of the features…

Continue reading

Flashing programs to STM32. Embedded Bootloader

Post updated with new screens and up-to-date information (2020)! There have been several requests from users to explain more about loading programs into the flash memory of STM32 microcontrollers. There are several ways how to perform stm32 flash programming. You may enter the STM32 bootloader directly via USART interface and upload the binaries. The more advanced and flexible method is to use an ST-LINK utility – an ST-based adapter, which connects to STM32 board through JTAG interface. Many ST development boards already have this feature included. Otherwise, you can jump-wires from one to another, or get a dedicated portable ST-Link adapter. Also, you can use standard third-party JTAG tools such as J-Link. Finally, you can flash your bootloader that works with any interface (USART, USB, SPI, etc.) The STM32F103RB board Any of these methods are great if they get the job done. In this topic, let us focus on how to perform STM32 flashing by using a bootloader. Today probably, no manufacturer is producing boards with an RS232 interface. Nevertheless, you like me, probably have a dozen older boards with a serial port. They are great boards still to use in many projects.

Continue reading

Pushing prototyping with STM32F4Discovery to new level

STM32F4Discovery board is already quite powerful and stacked with many handy features. You can find a three-axis accelerometer, MEMS microphone, DAC with D class amplifier that can output sound through the built-in audio jack on a single board. Also, there are a couple of LEDs and a button for fast access. Of course, this board’s core is the STM32F407VGT6 ARM Cortex-M4 microcontroller that packs a series of great features, including DSP instructions and a floating-point unit. But eventually, with such power, you will miss several other handy features that could be used in your project. Think of LCD, Ethernet, RS232 interface, and even camera. You could start making your extension boards that include additional features, but why bother since several extension boards are available for it. Let us go through them and see the features you could get without a heating soldering iron.

Continue reading

Setting up CoIDE with GNU tools

For some time, I’ve been using Codebench ARM GCC tools for developing software for ARM microcontrollers. As IDE, I used plain Eclipse, which I had to configure by myself. It worked pretty well, and there is nothing wrong with this. Anyway, sometimes it gets a little annoying to keep an eye on configurations and manual settings. So I decided to give a try CooCox IDE which claims to be free and open. It seems that it already supports all the microcontrollers I like to use. Along with this change, I am also moving to a different GCC tool collection. Codebench free tools are great, but on the other hand, there are some limitations. One of them is release times. They release their free tools twice a year, so updates and other improvements cannot reach as fast as you’d expect.Another thing I am concerned – disabled hard float functionality. If you would like to ta take advantage of the floating-point unit in Cortex-M4, then you get stuck. If you are not using a hardware floating-point module, this tool works fine, and you can stick with it. Anyway, I wouldn’t say I like limitations, especially with free tools, so I switch to…

Continue reading

You know basics of ARM. Whats next?

You’ve probably noticed that day by day, and more complex hardware gets closer to a user. Of course, I am talking about microcontrollers and processors. Several years ago, it was a challenge to have running Linux on board. Now almost everyone has Raspberry Pi and doing crazy things. As I have noticed, not many hobbyists are building their boards to get things done. There is a wide variety of ready-made developing boards depending on size, speed, price that it looks not worth spending time on what’s already done. Everyone seems to be grabbing Arduino and building amazing projects. In a couple of years, enthusiasts used to crunch ARM projects like cookies. This is thanks to the choice of cheap development boards and improving free software tools. But the most critical role in this is the manufacturers. They finally noticed that the hobby market could be a powerful driving mechanism. Ignoring it means losing the game. Now almost every hardware company is trying to get their development board closer to the maker and hacker community because they like to build stuff and spread the word about it.

Continue reading

Bit Band operations with ARM Cortex microcontrollers

I got few questions from our readers about the bit-band feature in ARM Cortex microcontrollers. It may seem to be a prominent topic, still may lead to come confusion while using bit-banding. So let’s look at this feature a little bit closer. Why use bit band? Simply speaking Bit banding method allows performing atomic bitwise operations to memory areas. Why use bit banding? The most straightforward answer is because ARM Cortex doesn’t have something like BIT CSET or BIT CLEAR commands like most of the 8-bit microcontrollers do. So this is somewhat a workaround solution. Another question may rise – Why not using the read-modify-write method? Again this method is not reliable in some cases. For instance, f there is an interrupt during this operation; it can cause data corruption. Other situation may occur in embedded OS when different tasks may modify the same memory location. So we want a method that allows setting or clear individual bits with a single instruction. This is where the bit band method helps.

Continue reading

Basic touch screen routines up and running

STm32 touch screen

STM32103ZET6 prototyping board comes with LCD having touch screen capability. It is a great way to interact with the device. Practically speaking Touch screen is a resistive film that can be accessed as a regular potentiometer which value depends on the touchpoint. Depending on voltage drop, it is possible to calculate the coordinates. There is a touch screen controller that takes most of the hard work – it has an internal ADC that measures the voltage and sends a value to the microcontroller using one of the selected interfaces (I2C or SPI). There is a typical ADS7843 controller used in the board, which talks to the microcontroller using SPI. After playing around, I’ve put a messy code that reads touch screen coordinates. It is a glued code from various sources, so it is only to fix some results. Currently, the code reads many values, then averages to get rid of most garbage, and then calculates screen matching coordinates. This is the trickiest part to do. You can do this empirically by reading min and max ADC values for each axis and then calculate coordinates using formulas:

Continue reading

Updating STM32 C template with CMSIS V3

So far, we’ve been using an old template with CMSIS version 1.30. Since then, it was updated several times by adding new Cortex processor families, fixing several bugs, and adding new features. They also changed the folder structure of CMSIS to be more generic. And there is a CMSIS DSP library integrated. With it, you can do complex math tasks using only a few lines of code. So why not upgrading our software template for Sourcery Codebench G++ toolchain with new CMSIS. First of all, download the latest CMSIS package from arm.com/cmsis. You will have to register to access download files—package with CMSIS, DSP library, and documentation weights about 45MB. Since we are working with ST32 microcontrollers, you also need to download STM32F10x Standard Peripheral Library from STMicroelectronics.

Continue reading

Downloading binaries using STM32 ST-Link Utility

As you may know, ST also produces its own debugger/programmer called ST-Link. It supports JTAG and SWD interfaces. You can purchase an ST-Link USB adapter, but there is a better option if you are into STM32 microcontrollers and probably own one of the ST32 Discovery boards. Since I have STM32VLDiscovery nearby, this is how to program another STM32F103RBT6 board using only four wires. On the discovery board, locate CN3 jumpers and disconnect them as they connect the discovery board to a debugger.

Continue reading

Flashing STM32 using J-Flash ARM

Last time, we covered the topic of flashing STM32 microcontrollers using the bootloader, which is the most comfortable and cheapest way of loading programs into MCU memory. But this isn’t the only way of doing this. The firmware can also be downloaded using the JTAG adapter, which is also used for debugging. This time we are not digging into debugging but staying only with programming. J-Link software You can download the latest J-Link software from the Segger Download page. You will be asked for an adapter serial number which can be found on the backside of the J-Link adapter.

Continue reading