I am trying to turn the led (LD2 in schematic) inside the nucleo board on using only registers with the STM32CubeIDE.
The user manual states the following addresses for the clock, mode and data registers:
Led pin: PA5
Address of the Clock control register: RCC_AHBENR
[base address] + [offset] ===> [Result]
0x4002 1000 + 0x14 ===> 0x40021014
Address of the GPIOA mode register
0x4800 0000 + 0x00 ===> 0x48000000
Address of the GPIOA output data register
0x4800 0000 + 0x14 ===> 0x48000014
I am using the following code to set/clear the registers in the board:
#include <stdint.h>
int main(void)
{
uint32_t *pClkCtrlReg = (uint32_t*)0x40021014;
uint32_t *pPortAModeReg = (uint32_t*)0x48000000;
uint32_t *pPortAOutReg = (uint32_t*)0x48000014;
//1. enable the clock for GPIOA peripheral in the AHBENR
*pClkCtrlReg |= 0x00020000;
//2. configure the mode of the IO pin as output
//a. clear the 24th and 25th bit positions
*pPortAModeReg &= 0xFCFFFFFF;
//b set 24th bit position as 1
*pPortAModeReg |= 0x01000000;
//3. SET 12th bit of the output data register to make I/O pin-12 as HIGH
*pPortAOutReg |= 0x20;
while(1);
}
Using the register viewer from the IDE, I can see that the PA5 is set as output, but physically, my led is not turning on.
I do not know what I am doing wrong. I am suspecting that the pin PA5 is wrong, but i tried PA12 too and it does not work. Can someone please help me out here?