In the whole ARM Cortex-M4 series, we are going to start with an LED, which means “How to configure the inbuilt LED”.
Before going with a direct Microcontroller part.
Let’s start with a Datasheet and Reference manual. How it’s gonna play a major role in this part.
Datasheet: https://www.alldatasheet.com/datasheet-pdf/pdf/929997/STMICROELECTRONICS/STM32F411RE.html
Reference manual: https://www.st.com/resource/en/reference_manual/rm0383-stm32f411xce-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
Just click that link and download!
We are going to configure the in-build led LED in stm32f411re microcontroller. I Hope you have been downloading the Datasheet, Reference manual and User manual(stm32 nucleo 64 board).
This Led is placed on the outside of the Microcontroller board. You can strongly see the LED so in this case, we are going to open the schematic diagram in the User manual(stm32 nucleo 64 board).
Fig 1 Schematic Diagram for LED 2 connection
If you have already downloaded the User manual just visit the (page no 66). You can see the schematic diagram for a specific LED that is “LED2”. Actually configuring the inbuilt LED can be done with a,
1.Using only special function registers can enable the LED
2. Using a program(embedded c) enables the LED using special function registers.
In this Blog only covered up “How to enable LED using only special function registers”. Let’s go with a step by step procedure and after we get a proper procedure, we gonna implement it by using two methods!
Step 1
For the very first procedure you have to check LD2 has connected with which GPIO port. For every peripheral it’s gonna be suitable, “which GPIO port it has to be connected with”. In this case LD2 is connected with PA5 which tends to GPIO PIN 5. Now we found LED2 connected with a GPIO pin.
Step 2
Now the first task is completed, second thing you can open the datasheet to read the internal architecture of our microcontroller. Open the datasheet page no 15. You can see the block diagram.
We already know that LD2 is connected with GPIO A. Now you have checked that specific GPIO A has a connection with which bus.
BUS
The bus is mainly used to transfer the data from one place to another place. This internal architecture has two buses AHB & APB.
AHB- Advanced High Bus,
APB- Advanced Peripheral Bus,
GPIO A is connected with AHB1 100MHz. Here step 2 has completed.
Step 3
We found GPIO connected with AHB1 buses. Now give the clock access to the AHB1 bus to enable the GPIO port A.
For this case we are going to open the Reference manual. You might be confused why you always open the datasheet, reference manual and user manual?. No need to confuse it. If you want to see the internal block diagram go and visit the datasheet. If you want to read the register go to the Reference manual and if you want the schematics go and visit the user manual that’s it.
Open the Reference manual in the index table.
Have to enable the GPIO A for that to give a clock access to the AHB1 bus before we need an address to enable specific bits in AHB1. In this case go to the RCC register and AHB1ENR bus (page no:117,118)
In that RCC register, go to the AHB1ENR bus register that enables the GPIO A of 0th bit because led is connected with GPIO A
How to enable it? Here
Step 4
The LED has connected with GPIO A and now we are going to implement, ”what will the GPIO A have to perform?”. The name itself is GPIO(General purpose input and output). It is going to perform as an input, output, multiple function etc. In this, go to the Reference manual(page no 157) and go to the moder register. Using the moder register we are going to implement what the function is going to perform.
In this Moder register, As you know LED is connected with port A (5th pin). As same you have to enable the MODER5[1:0]. How to enable it? Before that we know what the function is going to perform. If it is a LED only “ON” & “OFF” so it will act as an output always. So as by the reference manual give “01” in the MODER5[1:0].
We enable it as a Output mode.
Step 5
Store the output data into any one of the registers. So for that case we are going to store the data into the output data register in the same GPIO register.
This specially enables ODR5 as you know GPIO A 5th pin. So Enable as 1 to enable it as 1 using GPIO x BSRR register as given by the procedure.
THIS ALL ABOUT THE PROCEDURE OF TO CONFIGURE INBUILT LED THEN SEE WITH
Using only special function registers can enable the LED
Using only special function registers can enable the LED
The same steps, we are going to implement only a special function register(SFR).
Before that we need software to configure this project. Need install STM32CUBE IDE
Here the link we give step by step procedure to “How to Install it” go check and install.
Step 1
Open the STM32CUBE IDE. create a new project and STM32 Project
Step 2
Select a Board selector and select the board
Step 3
The board is NUCLEO-F411RE select and give next.
Step 4
Create a new project with any name, give it as empty and finish.
Step 5
After create project > go to the src > main.c
We are going to write the code.
First we enable it through a special function register(SFR).
Step 6
Go to windows > show in views > SFR you can see the SFR of all peripherals
Procedure
1) To configure inbuilt LED using only registers
Step 1
RCC register > AHB1ENR register > GPIO A bit enable as 1
RCC > AHB1ENR > GPIO A click that bits are visible just click the bit which you want to enable after click it se as 1. If again you click it will disable as 0
Step 2
GPIO A > MODER register > MODER5 as 01
Led is output set the bit as 01
Step 3
GPIO A > ODR > ODR5
Led Turn ON
Led Turn OFF
After set the ODR5 of 5th bit you can see the led “turns on” in the stm32f411re and set 0 you can led turns off