I am programming an STM32WB55CGU6 with C and I am accessing the peripheral registers to light up an LED. However, the LED is not lighting up. My guess is that I'm not writing to memory/casting in the right way and it goes into HardFault, but I don't see where that problem is. I also did it in assembly and it worked, so shouldn't be a hardware issue. It compiles and uploads correctly. What's wrong with my code?
#include <stdlib.h>
#define CLOCK_ENABLE_GPIOBC 6
#define PIN_SET_PC15 1<<15
#define MODE_SELECT_PC15 1<<30
static int* RCC = (int*)0x58000000;
static int* GPIOA = (int*)0x48000000;
static int* GPIOB = (int*)0x48000400;
static int* GPIOC = (int*)0x48000800;
static int* GPIOD = (int*)0x48000C00;
static int* GPIOE = (int*)0x48001000;
int main(void)
{
*(int*)((int)RCC + 0x04C) = CLOCK_ENABLE_GPIOBC;
*GPIOC |= MODE_SELECT_PC15;
*(int*)((int)GPIOC + 0x18) = PIN_SET_PC15;
while(1)
{}
}
I've gotten all of the memory addresses and the layouts of the registers from the reference manual.
The problem was
*GPIOC |= MODE_SELECT_PC15
The reference manual shows that the reset value of GPIOC MODER register is 0xFFFF FFFF. When I apply bitwise or with 1<<15 to it, it changes nothing. For a pin to be in output mode, the corresponding bits have to be 01. When it is in reset state, all the of the bits are 1's.