Skip to main content
vshah
Associate II
June 13, 2021
Question

Hi All, I am new to STM8L controller, Could you help me out with the clock configuration part? I am using STM8L152R8T6 controller Eval Kit along with Cosmic Compiler. Trying to do simple LED toggling on this board but unable to perform it.

  • June 13, 2021
  • 1 reply
  • 1278 views
void main()
{
	uint32_t clockFrequency = 0x0000;
	
	//clock enable for MCU
	/* Select HSE as system clock source */
 CLK_HSICmd(ENABLE);
 CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
 /* system clock prescaler: 1*/
 CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
 while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSI);
	
	clockFrequency = CLK_GetClockFreq();
 
	GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	GPIO_Init(GPIOG, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	GPIO_Init(GPIOH, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	GPIO_Init(GPIOI, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
	
	while (1)
	{
		GPIO_Write(GPIOA, 0xff);
		GPIO_Write(GPIOB, 0xff);
		GPIO_Write(GPIOC, 0xff);
		GPIO_Write(GPIOD, 0xff);
		GPIO_Write(GPIOE, 0xff);
		GPIO_Write(GPIOF, 0xff);
		GPIO_Write(GPIOG, 0xff);
		GPIO_Write(GPIOH, 0xff);
		GPIO_Write(GPIOI, 0xff);
		
		Delay(1000);Delay(1000);
		
		GPIO_Write(GPIOA, 0x00);
		GPIO_Write(GPIOB, 0x00);
		GPIO_Write(GPIOC, 0x00);
		GPIO_Write(GPIOD, 0x00);
		GPIO_Write(GPIOE, 0x00);
		GPIO_Write(GPIOF, 0x00);
		GPIO_Write(GPIOG, 0x00);
		GPIO_Write(GPIOH, 0x00);
		GPIO_Write(GPIOI, 0x00);
		
		Delay(1000);Delay(1000);
	}
}

Above is the code I am working on. One more interesting point, even clockFrequency set to zero it is always showing some random value after initialization and after clockFrequency = CLK_GetClockFreq() line.

Could anyone help me out? Where I am doing wrong?

Thanks!!!

    This topic has been closed for replies.

    1 reply

    Amira
    Visitor II
    July 7, 2021

    Hello @vshah​ 

    you can refer to STM8L package available on st.com:

    https://my.st.com/content/my_st_com/en/products/embedded-software/mcu-mpu-embedded-software/stm8-embedded-software/stsw-stm8016.html

    where you can find examples (GPIO Toggle) on STM8L Eval board.

    Hope this would help you!

    Regards,

    Amira

    vshah
    vshahAuthor
    Associate II
    July 17, 2021

    Hi Amira,

    Actually I had already gone through it and it was not working for me. The above code is written with help of "standard peripheral library" package only.

    Regards,

    Viren