Professional Documents
Culture Documents
Microprocessor System
Assembly language programming and simple I/O
Programming
What we will learn in this section:
The STM32F446_Nucleo
board used the
STM32F446RE T6 chip
that has 64 pins and
512kB size of on-chip
Flash Memory
https://doc.riot-os.org/group__boards__nucleo-f446re.html#details
Nucleo-F446RE
The Nucleo-F446RE is a
board from ST's Nucleo
family supporting a ARM
Cortex-M4 STM32F446RE
microcontroller with
128Kb of RAM and 512Kb
of ROM Flash.
Specific and optimize Cross platform and Access to various Assembly and
for STM32 chips support multiple Arduino library debugging capability
vendors
Hardware Abstraction C C Assembly and C
Layer (HAL)
programming
What we will learn in this section:
Notes:
1. PB11 is not brought out to a board pin.
2. PA13 and PA14 are shared with the debug
circuitry and should be avoided if possible.
3. A User LED (green) is connected to PA5 and is
on when the pin is high.
4. A User push-button is connected to PC13.
GPIO Registers
STM32F4xx microcontroller on the Nucleo board has several general purpose
input/output (GPIO) ports named Port A,B,C,D,E,F,G & H.
Each of the GPIO ports on the ARM Cortex M4 processor has ten 32-bit registers that
are used to configure the port and get information in and out and Table 3 defines
these registers.
Note: alternate function include timers, UARTs, CAN, Ethernet, I2C, and SPI to be attached to a port pin.
GPIO Registers Address
Each GPIO has:
Four 32-bit configuration registers
GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR and GPIOx_PUPDR
Two 32-bit data registers
GPIOx_IDR and GPIOx_ODR
A 32-bit set/reset register
GPIOx_BSRR
A 32-bit locking register
GPIOx_LCKR
Two 32-bit alternate function selection register
GPIOx_AFRH and GPIOx_AFRL
GPIO Registers Address
Address ranges assigned to ports of STM32F4xx chips:
A GPIO pin is a
generic pin
controllable by
the user at run
time and
configurable to
be input or
output.
Basic structure of a 5 V tolerant I/O port bit(Refer page 177 in STM32F446RE Reff Manual)
GPIO Port Input Register (GPIOx_IDR)
Refer page 189 in STM32F446RE Reff Manual)
GPIO Port Output Register
(GPIOx_ODR) Refer page 190 in STM32F446RE Reff Manual)
GPIO Port Bit/Set Register (GPIOx_BSRR)
Configure PA5 as
output
Turn on LED
Step1 : Enable GPIO clock RCC_AHB1ENR
Find out the address of register RCC_AHB1ENR. This register is part of the RCC registers (Reset and
Clock control). The offset of this register is 0x30 as described in section 6.3.10 of reference manual.
The memory map shows the RCC boundary address range as 0x40023800 to 0x40023BFF. Therefore
the address of RCC_AHB1ENR register is 0x40023800 + address offset (0x30) = 0x40023830
Step1 :Enable GPIO clock RCC_AHB1ENR : Clock Setting for
GPIOx
RCC AHB1 peripheral clock enable register (RCC_AHB1ENR)
Refer Section 6.3.10
Loading 0000 0000 0000 0001
Enable GPIOA
0 0 0 1
Step1 : Enable GPIO clock RCC_AHB1ENR
Program segment:
RCC_AHB1ENR equ 0x40023830 ;Define address of RCC_AHB1ENR
LDR R4, =RCC_AHB1ENR ;R4 <- RCC_AHB1ENR
LDR R5, [R4] ;R5 <- contents of RCC_AHB1ENR
ORR R5, #1 ;set bit0 (GPIOAEN = 1 )
STR R5, [R4] ;RCC_AHB1ENR <- R5
Step 2 : Configure the desired I/O as OUTPUT or INPUT in the
GPIOx_MODER register
0 1
0 0 1 0
START
Enable GPIOA
0 0 0 1
Step 2 : Configure the desired I/O as OUTPUT or INPUT in the
GPIOx_MODER register
0 1 0 0
0 0 1 0
0 0 1 0
BR5=1
START
Delay 0.5s
Sample Coding in Assembly Program for blinking LEDs
Assembly program to toggle the green LED (LD2) on STM32F446RE Nucleo64 board at 16Hz
Depending on how the external SW is connected , we need to enable the internal pull-up
or pull-down Resistor for the pin.
If the SW connected to the ground, the internal Pull-up Resistor is enabled.
If the SW connected to the power, the internal Pull-down Resistor is enabled.
Input and Output Data
Step1 : Enable GPIO clock RCC_AHB1ENR :
Clock Setting for GPIOA and
GPIOC
0 1 0 1
Enable both GPIOA & GPIOC
Step 2 : Configure the desired I/O as OUTPUT or INPUT in the
GPIOx_MODER register
See Table 1 in
pg 57 in
STM32F446RE
Reff manual
0 0
STEP 3:GPIO port INPUT Data
Register (GPIOx _IDR)
0 0 1 0 PC13 is high
0 0 1 0
0 0 1 0
BR5=1
Flowchart
L1 LDR R4, =GPIOC_IDR;
LDR R3, [r4] ; Copy PA13 to r3
AND R3, #0x2000 ; Mask bit13 (i.e PA13
CMP R3, #0 ; Is it zero?
Read the status of BEQ turnon ; branch to turnon
the switch
START
See Table 1 in
pg 57 in
STM32F446RE
Reff manual
APPENDICES
APPENDICES