For a pretty long time I have been wanting to lay my hands on some sort of ARM based microcontrollers. There were too many options out there and never knew how to get started with it. Recently I came across ST Microelectronics. They have an awesome collection of low cost ARM based evaluation boards. Then I came across their Nucleo series and I decided to get one at the top of the series, the NUCLEO F411RE. What excited me is that it is cheaper than an Arduino Uno. ST has a number of low cost ARM evaluation boards.
Now coming to the point, the NUCLEO F411RE is based on the STM32F411RET6 32 bit microcontroller which has an ARM Cortex M4 architecture at its heart with a maximum clock speed of 100 MHz. That is roughly 6.25X the speed of your Arduino Uno. The best part is that the evaluation board is supported by mbed.
Mbed is an venture from ARM holdings and its numerous technology partners including Atmel, FreeScale, IBM. It is basically a free online compiler platform for ARM-M series microcontrollers where you can type in your code, compile and download the bin file for flashing onto your device. I would call mbed as an Arduino equivalent when it comes to the compiler part. There are numerous libraries available to take care of your digital I/Os, timers, PWM etc. So this is a good starting point even if you haven’t gone beyond the 8bit devices. Importing of libraries is pretty easy and there is an awesome forum to resolve all your issues. It also relieves you of finding a good compiler and IDE for ARM development. It also offers good code portability since the library functions are the same for different microcontrollers. But making use of the pre-built libraries robs you of the knowledge of what’s really happening inside and often keeps you away from exploring the full potential of your device. So this post is going to be about register level programming of NUCLEOF411RE.
First logon to developer.mbed.org. Instructions to get everything up and running is provided there. Now for the hardware part, you can follow this link to configure any NUCLEO board:
Once you have setup your Nucleo board and mbed account, it’s time to get some code running on that 32 bit device.
I won’t be walking you through the code. But I’ll be telling you the basics needed to get an led to blink. I chose to connect my led to the first bit(LSB) of GPIOA of STM32F411RET6.
At the start of the code you’ll have to include mbed.h. This will take care of a few memory related setup you’ll have to do otherwise.
First of all you need to turn on the clock supply to whatever peripheral you are planning to use. In this case it is GPIOA. If you refer the datasheet, the clock supply to GPIOA can be turned on by setting the LSB of RCC_AHB1ENR.
Next register is the GPIOx_MODER. This is the register where you decide whether a GPIO pin is going to be an input or an output. X is the GPIO port eg. A,B,H etc.
The next one is GPIOx_OTYPER. The microcontroller offers different types of output configuration. You can chose either push-pull, open drain configuration using this register. GPIOx_ODR is the register whose contents will be reflected at the GPIO pin i.e a set bit will set the corresponding pin to a logic high and a reset bit will set it to logic low(0 V, almost).
For the time being you’ll need to use only the above mentioned registers. But there are four other registers worth mentioning. GPIOX_BSRR which can be used to set or reset individual bits. GPIOx_LCKR which can be used to lock other registers associated with GPIO to ensure that they are not modified accidentally. GPIO_AFRH and GPIO_AFRL are used to configure the IOs having dual functionalities.
The code for blinking an LED on PA_0 has been uploaded on GitHub.
All the best with your foray into the ARM world.