3005 views|6 replies

23

Posts

0

Resources
The OP
 

[ST NUCLEO-G071RB Review]_05_System clock configuration and Tetris game implemented on the serial port [Copy link]

This post was last edited by lvxinn2006 on 2019-1-11 08:55
The development board evaluated in this eventST NUCLEO-G071RB is provided by STMicroelectronics. Thanks to STMicroelectronics for its support for EEWorld's evaluation!
【Purpose】
· Master the use of serial port
· Master the configuration of system clock
· Master the implementation logic of Tetris game
【Experimental environment】
· NUCLEO-G071RB development board · Keil MDK-ARM (Keil uVision 5.25.2.0) · Keil.STM32G0xx_DFP.1.0.0.pack · MobaXterm, Putty, SecureCRT, XShell and other hyperterminal software.5pt] 【Experimental Materials】
· NUCLEO-G071RB Development Board Schematic Diagram
· STM32G071x8/xB Data Sheet
·STM32G071 chip user reference manual
[ExperimentAnalysis]
Based on the previousUART serial port experiment, the functional logic of Tetris is added. It contains many C language algorithms and the use of terminal control codes. The content is relatively complicated. The program code is provided here for interested readers to refer to.
In this experiment, two additional processor functions are mainly used
1. Configuration of main system clock increased to 64MHz
2. Use of Systick beat timer
The configuration of 64MHz main clock mainly uses the RCC unit of the chip. The RCC unit is mainly used to control the reset and clock control of each functional unit of the entire chip system. Here, clock control is mainly used.
The basis of clock control mainly depends on the system clock tree. The part related to the system main frequency is shown in the following figure:
[attach]398003 [/attach]
In fact, it is necessary to make SYSCLK The clock frequency reaches 64MHz through various settings. According to the clock diagram and the chip manual, we can know that the system uses the internal 16MHz RC oscillation circuit as the clock by default, that is, HSI16, and after the divider (undivided by default), it becomes HSISYS. The main clock SYSCLK selector selects HSISYS as the main clock source by default, and the default main clock SYSCLK frequency is 16MHz. According to the understanding of the STM32G071 chip, the maximum supported frequency of the SYSCLK master clock is 64MHz. As the main clock of the system, SYSCLK provides the clock source for the CPU core and most peripheral devices. This chip uses the Cortex-M0+ CPU core of the architecture, with HCLK as the working clock, and the maximum main frequency can run to 64MHz. In summary, if we want to maximize the performance of the processor, we need to increase SYSCLK to the maximum supported frequency of 64MHz. In the clock part, there is a PLL component in the system. Its main function is to increase the clock frequency, input a low-frequency clock signal, and output a high-frequency clock signal. As can be seen in the figure, PLL can choose HSE or HSI16 as the clock source. In our development board, only HSI16 can be used, so this part needs to be configured separately. The entire PLL related configuration is in register [ In PLLCFGR: 398004 398005 398006 In this register, we are mainly concerned about several values M, N, P, Q and R. Combined with the clock tree and the register formula description, we can clearly understand the role of each bit segment. The two most important parameters here are M and N. These two determine the frequency of fvco inside the phase-locked loop PLL. The three output clocks are divided based on this frequency, so it is necessary to select reasonable values for M and N. After configuring the PLL parameters, you need to start the PLL, which mainly uses the RCC_CR register.
needs to turn on the 24th bit, and needs to detect whether the PLL is working properly by testing the 25th bit. After everything is normal, you can switch the SYSCLK clock source to PLLRCLK. The selection of the main clock source mainly uses RCC_CFGR398007398008. Set 2:0=010 (0x2) here to select the main clock as PLLRCLK. After the clock is switched successfully, you can verify whether the clock is switched successfully by reading 5:3. /font]
To summarize, the clock configuration function is implemented as follows:
  1. /* Configure 64MHz system clock*/ void SystemClockConfig(void) { //Fvco1 = 16 * 32 / 4 = 128 RCC->PLLCFGR = (0x2<<0) //PLL clock source select HSI16 | (4<<4) //M=4 | (32<<8) //N=32 | (1<<28) //Enable PLLRCLK | (1<<29); //R=1 PLLRCLK division coefficient is 2, then PLLRCLK frequency is 64MHz RCC->CR |= (1<<24); //Enable PLL while(!(RCC->CR & (1<<25))); //Wait for PLL to lock RCC->CFGR |= (0x2<<0); //Switch clock source to PLLRCLK while(!(RCC->CFGR & (0x2<<3))); //Wait for the clock source switching to complete SystemCoreClockUpdate(); //Update the SystemCoreClock global variable }
复制代码
Running this function in the main function can increase the main clock frequency to64MHz, and you can get the currentSYSCLKclock frequency by accessing the global variableSystemCoreClock.
Experimental code]
实验05_俄罗斯方块.rar (836.2 KB, downloads: 3)
[Experimental phenomenon]
· Connect the development board, open the HyperTerminal software, and use the baud rate of115200 to connect to the serial port of the development board (Note: only the HyperTerminal software can be used, the Serial Debug Assistant cannot be used. The Serial Debug Assistant can only see the original terminal control code)
· Start the game after the development board is reset, and use the keyboard keys to control the direction
S ——Left
D ——Down
F ——Right
E ——Switch direction
Space bar pauses/Continue the game
R ——Restart
The terminal displays the following:
This content is originally created by EEWORLD forum user lvxinn2006. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source(RCC->CFGR & (0x2<<3))); //Wait for the clock source switching to complete SystemCoreClockUpdate(); //Update the SystemCoreClock global variable }[/code]
Running this function in the main function can increase the main clock frequency to64MHz, and you can get the currentSYSCLKclock frequency by accessing the global variableSystemCoreClock.
Experimental code]
实验05_俄罗斯方块.rar (836.2 KB, downloads: 3)
[Experimental phenomenon]
· Connect the development board, open the HyperTerminal software, and use the baud rate of115200 to connect to the serial port of the development board (Note: only the HyperTerminal software can be used, the Serial Debug Assistant cannot be used. The Serial Debug Assistant can only see the original terminal control code)
· Start the game after the development board is reset, and use the keyboard keys to control the direction
S ——Left
D ——Down
F ——Right
E ——Switch direction
Space bar pause/Continue the game
R ——Restart
The terminal displays the following:
This content is originally created by EEWORLD forum user lvxinn2006. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

图片18.png (162.57 KB, downloads: 0)

图片18.png

图片19.png (53.6 KB, downloads: 0)

图片19.png

图片20.png (62.18 KB, downloads: 0)

图片20.png

图片22.png (76.09 KB, downloads: 0)

图片22.png

图片23.png (91.6 KB, downloads: 0)

图片23.png
This post is from stm32/stm8

Latest reply

I can't download it either. I want to study. It's embarrassing. I can't download it.  Details Published on 2019-3-25 19:58

赞赏

1

查看全部赞赏

 

424

Posts

8

Resources
2
 
Can this be brushed? Can it remove blocks?
This post is from stm32/stm8
 
 

295

Posts

1

Resources
3
 
Haha, this is very powerful. When using mobaxterm as a serial terminal, does it use the command of full page refresh? If you use the serial assistant, it should not work.
This post is from stm32/stm8
 
Personal signature

我的小站 我的博客

 

23

Posts

0

Resources
4
 
lehuijie posted on 2019-1-13 17:16 Can this be brushed? Can it remove the blocks?
Using VT terminal control codes, you can manipulate the position of characters, foreground and background colors, and of course remove the blocks
This post is from stm32/stm8
 
 
 

23

Posts

0

Resources
5
 
hotsauce1861 posted on 2019-1-14 09:42 Haha, this is very powerful. When using mobaxterm as a serial terminal, does it use the command to refresh the entire page? If you use the serial assistant, it shouldn't work.
The serial assistant does not support VT control codes. If you use the serial assistant, you can see the original control code data
This post is from stm32/stm8
 
 
 

11

Posts

0

Resources
6
 
Why can't I download it? It's embarrassing.
This post is from stm32/stm8
 
 
 

11

Posts

0

Resources
7
 
I can't download it either. I want to study. It's embarrassing. I can't download it.
This post is from stm32/stm8
 
 
 

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