The following code is for blinking of the on-board LED on an STM32F401RE board. I am trying to do it without using HAL. When I flash it on to the board, it blinks once and then stays on. How can I fix this? Thank you in advance.
#include "stm32f401xe.h"
#define PLL_M 4
#define PLL_N 84
#define PLL_P 0
void sys_clk_cfg(void) {
//1. enable HSE and wait for HSE to become ready
RCC->CR |= RCC_CR_HSEON;
while(!(RCC->CR & RCC_CR_HSERDY));
//2. Set the power enable clock and voltage regulator
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
PWR->CR |= PWR_CR_VOS;
//configure the flash access
FLASH->ACR |= FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_LATENCY_5WS;
//configure the prescaler for clocks
//AHB PR
RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
//APB1 PR
RCC->CFGR |= RCC_CFGR_PPRE1_DIV2;
//APB2 PR
RCC->CFGR |= RCC_CFGR_PPRE2_DIV1;
//configure the PLL
RCC->PLLCFGR = (PLL_M <<0) | (PLL_N << 6) | (PLL_P << 16) | (RCC_PLLCFGR_PLLSRC_HSE);
//enable the PLL
RCC->CR |= RCC_CR_PLLON;
while(!(RCC->CR & RCC_CR_PLLRDY));
//set the clock source
RCC->CFGR |= RCC_CFGR_SW_PLL;
while((RCC->CFGR & RCC_CFGR_SW) != RCC_CFGR_SW_PLL);
}
void GPIO_Config(void)
{
//enable the gpio clock
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
//2. SET THE PIN PA5 AS OUTPUT
GPIOA->MODER |= (1<<10);
//3. CONFIGURE THE OUTPUT MODE
GPIOA->OTYPER = 0;
GPIOA->OSPEEDR = 0;
}
void delay(uint32_t time)
{
while(time--);
}
int main()
{
sys_clk_cfg();
GPIO_Config();
while(1) {
GPIOA->BSRR |= (1 << 5);
delay(100000);
GPIOA->BSRR |= ((1 << 5) << 16);
delay(100000);
}
}
I expected the LED to Blink, but it's not blinking and just stays on the whole time.
GPIOA->BSRR |= GPIO_BSRR_BS5 ;/GPIOA->BSRR |= GPIO_BSRR_BR5 ;TheGPIO_BSRR_BS5/GPIO_BSRR_BR5macros are defined in the stm32f401xe.h you have already included and is not part of the HAL.