Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


LED toggle

I am trying to toggle the user LEDs in every 1sec. When I use the HSI alone for 16MHz the output is perfect. When I try to set up my clock as 32MHz using PLL the LEDs doesn’t blink. I am using STM32L152RBT6 discovery board. Can anyone please explain to me as to where I am making the mistake?

void clock_set(void);
void delay(uint32_t delay);
uint32_t SYC=32000000;
uint32_t a;
int main(void)
{
clock_set();
GPIO_init();

while (1)
{
GPIOB->BSRRH |= 0x80;
GPIOB->BSRRL |= 0x40;
delay(1000);
GPIOB->BSRRH |= 0x40;
GPIOB->BSRRL |= 0x80;
delay(1000);
}
}

void SysTick_Handler(void)
{
tick--;
}

void delay(uint32_t delay)
{
tick=delay-1;
while(tick);
}

void GPIO_init(void)
{
RCC->AHBENR |= 0x00000002;
GPIOB->MODER |= 0x00005000;
GPIOB->OTYPER |= 0x00000000;
GPIOB->OSPEEDR |= 0x0000F000;
GPIOB->PUPDR |= 0x00000000;
GPIOB->BSRRL |= 0x80;
}
void clock_set(void)
{
FLASH->ACR&=~FLASH_ACR_LATENCY;
FLASH->ACR|= 0x1; /*Latency waiting state*/

RCC->CR|=RCC_CR_HSION; /*HSI ON*/
while((RCC->CR & RCC_CR_HSIRDY)==0); /*Wait for HSI on*/

RCC->ICSCR&=~RCC_ICSCR_HSITRIM;
RCC->ICSCR|=16CR & RCC_CR_PLLRDY)==RCC_CR_PLLRDY); /*Turnoff PLL and wait*/

RCC->CFGR &= ~RCC_CFGR_PLLSRC;
RCC->CFGR |= RCC_CFGR_PLLSRC_HSI; /*Set HSI as PLL source*/

RCC->CFGR |= 0x00440000; /*4Mul 2Div 32Mhz*/

RCC->CR|=RCC_CR_PLLON;
while((RCC->CR&RCC_CR_PLLRDY)==0); /*Turn on pll and wait*/

RCC->CFGR &= ~RCC_CFGR_SW;
RCC->CFGR |= RCC_CFGR_SW_PLL;
while((RCC->CFGR&RCC_CFGR_SWS)!=RCC_CFGR_SWS_PLL); /*PLL as Core clock*/

SYC=32000000;
SysTick_Config(SYC/1000);

}