1602 views|6 replies

410

Posts

3

Resources
The OP
 

【CW32L052 Review】 Sysclk Delay Test [Copy link]

 

In this article, we will learn how to configure and use the sysclk clock of the CW32L052 chip.

1. Clock Block Diagram

The maximum clock that the chip can operate at is 48MHz. Here, the internal 48MHz HSI clock is used to configure sysclk.

2. Procedure

2.1 Clock Configuration

The clock configuration is a bit strange. If you directly enable HSI at 48MHz, the program will not start. If the clock is switched to HSE or LSI and then back to HSI, it can start and run normally.

void rcc_config(void)
{
	uint8_t res = 0U;
	RCC_AHBPeriphClk_Enable(RCC_AHB_PERIPH_FLASH, ENABLE);
	RCC_LSI_Enable( );                                                   //开启外部高速时钟LSI
	res = RCC_SysClk_Switch( RCC_SYSCLKSRC_LSI );                        //切换系统时钟到LSI
	if( res == 0x00 )                                                    //系统时钟切换成功
	{
			RCC_HSI_Disable();                                               //切换时钟到PLL后关闭源时钟HSI
			FirmwareDelay( 400 );   //about 100mS
	}
	
	RCC_HSI_Enable( RCC_HSIOSC_DIV1 );                                   //开启内部高速时钟HSI = HSIOSC / 2
	FLASH_SetLatency(FLASH_Latency_3); 
	res = RCC_SysClk_Switch( RCC_SYSCLKSRC_HSI );                        //切换系统时钟到HSI
	if( res == 0x00 )                                                    //系统时钟切换成功
	{
			RCC_LSI_Disable();                                               //切换时钟到HSI后关闭LSI时钟
			FirmwareDelay( 275000 );  //about 100mS
	}
	
	RCC_HCLKPRS_Config(RCC_HCLK_DIV1);
	
	RCC_HCLK_OUT();                           //通过PA04观察HCLK频率
}

2.2 Main Program

Configure the sysclk clock to 48M

InitTick( 48000000 ); //Initialize SysTick

int32_t main(void)
{
		GPIO_InitTypeDef GPIO_InitStruct = {0};
		rcc_config();
		init_uart();
	
    InitTick( 48000000 );                  //初始化SysTick

    __RCC_GPIOC_CLK_ENABLE();

    GPIO_InitStruct.IT = GPIO_IT_NONE;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pins = LED_GPIO_PINS;

    GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);

    while (1)
    {
        GPIO_TogglePin(LED_GPIO_PORT, LED_GPIO_PINS);
       // Delay(0xFFFF);
				SysTickDelay(100);
    }
}

3. Program running

The oscilloscope tests LED2 port PC10, the waveform is as follows

The delay is 100ms, and the test delay time is 102ms. There is a certain deviation when using the internal clock.

This post is from Domestic Chip Exchange

Latest reply

The quality is worrying, haha   Details Published on 2023-7-27 16:19
 
 

1663

Posts

0

Resources
2
 

Sysclk delay is the basic skill of programming, test it well, and the main thing is configuration

This post is from Domestic Chip Exchange

Comments

Yes, the heartbeat of the operating system  Details Published on 2023-7-20 06:35
 
 
 

410

Posts

3

Resources
3
 
Hot Ximi Show posted on 2023-7-19 23:05 Sysclk delay is the basic skill of programming. Test it well, and the main thing is configuration

Yes, the heartbeat of the operating system

This post is from Domestic Chip Exchange
 
 
 

2

Posts

0

Resources
4
 
Before SYSCLK switches to HSI 48MHz, FLASH needs to configure the read wait cycle. FLASH_SetLatency(FLASH_Latency_2);
This post is from Domestic Chip Exchange
 
 
 

7422

Posts

2

Resources
5
 

Did you use the official generated code?

This post is from Domestic Chip Exchange

Comments

Well, the library is official.  Details Published on 2023-7-26 20:11
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

410

Posts

3

Resources
6
 
freebsder posted on 2023-7-26 19:15 Is the official generated code used?

Well, the library is official.

This post is from Domestic Chip Exchange

Comments

The quality is worrying, haha  Details Published on 2023-7-27 16:19
 
 
 

7422

Posts

2

Resources
7
 
TL-LED posted on 2023-7-26 20:11 Well, the library is official

The quality is worrying, haha

This post is from Domestic Chip Exchange
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list