[stm32CubeMX] Based on the STM32F103C8T6 LED blinking and using Keil's software simulation logic analyzer function observation
1. Install STM32CubeMX
Official website download (official website download requires bound email or registration)
can also be linked: Click the link to download using Baidu network disk Extraction
code: 8520
(1) Run the installer as an administrator, click next:
(2) Click "I accept the terms of this license agreement", then select Next:
(3) Just check the first one, and the second option is whether to agree to ST Company collecting your personal usage information, etc.:
(4) Select the installation location, the default location is to install in the C drive (note: Chinese should not appear in the installation location):
(5) Click NEXT directly, and start the installation after other settings are not required:
(6) After the installation is complete, click Done to exit:
2. Install the HAL library
The STM32 HAL firmware library is the abbreviation of Hardware Abstraction Layer, and the Chinese name is: Hardware Abstraction Layer. The HAL library is the latest abstraction layer embedded software launched by ST for the STM32 MCU, in order to achieve the maximum portability across STM32 products more conveniently. With the launch of the HAL library, it can be said that ST has slowly abandoned the original standard firmware library, which also makes many old users dissatisfied. However, when the HAL library was launched, many third-party middleware were added, including RTOS, USB, TCP/IP, graphics, and so on.
Compared with the standard library, the HAL library of STM32 is more abstract. The ultimate goal of ST is to achieve seamless porting between STM32 series MCUs, and even fast porting among other MCUs.
And since 2016, ST company has gradually stopped updating the standard firmware library, and turned to the update of the HAL firmware library and the Low-layer underlying library, stopping the standard library update, which means that the use of STM32CubeMX to configure the HAL/ LL library is the mainstream configuration environment;
(1) Open the installed STMCubeMX
(2) Click HELP->Manage embedded software packages:
(3) A model selection interface will pop up, select the HAL library you want to install, and click "Install Now" until the installation is successful. As shown below:
3. New project
(1) Go back to the main interface of STMCubeMX and create a new project:
(2) Select your own chip in the part name, click the specific chip information in the information column to select it, and click start project:
(3) Click system core, enter SYS, and select serial wire under debug:
(4) Configure the clock, enter the above rcc, there are two clocks, one is hse and lse, we want to use the GPIO interface, and these interfaces are in APB2:
Next, observe the clock architecture. The clock of the APB2 bus is controlled by hse. At the same time, you must select the right side of PLLCLK in this interface:
(5) Set hse to Crystal/Ceramic Resonator:
(6) The next step is to click the corresponding pin to set the output register, which is the output item. There are three selected in total, which are PA5, PB9, and PC15:
(7) Click project manager, configure your own path and project name, and then change the IDE item to MDK-ARM:
(8) Enter the code generate interface, select to generate the initialization .c/.h file, then click generate code, select open project, and then go to KEIL5:
Four, keil simulation debugging
(1) Open the main.c file and slip the part of the main function:
(2) Put the following code into the main function (replace the content inside)
SystemClock_Config();//系统时钟初始化
MX_GPIO_Init();//gpio初始化
while (1)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);//PA4亮灯
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET);//PB9熄灯
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_SET);//PC15熄灯
HAL_Delay(1000);//延时1s
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);//PA4熄灯
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET);//PB9亮灯
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_SET);//PC15熄灯
HAL_Delay(1000);//延时1s
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);//PA4熄灯
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET);//PB9熄灯
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_RESET);//PC15亮灯
HAL_Delay(1000);//延时1s
}
(3) Observe the output waveform of the GPIO port
(1) In the Target interface, select the correct size of the crystal oscillator. I use an 8MHz external crystal oscillator. This option plays a very important role in software simulation. If the wrong choice is made, the waveform must be wrong because the time is not accurate.
(2) Debug page settings:
(3) Click Debug to enter the debugging interface:
(4) Select the logic analyzer:
(5) Select the pin to observe:
①Click Setup Logic Analyzer
②Add the pins to be observed:
directly enter PORTA.1
PORTA.5
PORTA.7
(6) Select bit (each must be selected)
(7) Observe the waveform:
When the pin is low-level, the light is on, and the high-level light is not on.
When using keil alone to write a running light, there are many related sentences to write. It is easier to use the STMCubeMX+keil+hal library to realize lighting.
5. Realization
After editing the file to hex, lower the board and connect the red, yellow and green tri-color lights
QQ video 20221010220746
6. Summary
This process is mainly to understand the principle of realizing flicker and learn to use keil simulation, how to use the functions provided by the HAL library to write programs. For different development boards, the method is basically the same, so the most important thing is to learn to read the development manual.
7. References
[STM32] STM32 CubeMx Tutorial 1 – Installation Tutorial
Use STMCubeMX to generate code (using hal library) to realize the water lamp