1. Preparations
Hardware preparation
Development board
first need to prepare a Cubs sent IoT development board and connected to the computer via the USB cable.
Software ready
- Need to install Keil - MDK chip and the corresponding packet so that the compiler generated code and downloading, refer MDK installation tutorial
2. Create Project
One is chosen
Open STM32CubeMX, open MCU Selector:
Search and select chip STM32L431RCT6
:
Clock Source
- If you choose to use external high-speed clock (HSE), you need to configure the RCC in System Core;
- If you use the default internal clock (HSI), you can skip this step;
Here I have to use an external clock:
Configurable GPIO pins
View schematics, determined to control the LED pins, our LED used here is PC13 pin.
So then we select the configuration PC13
pins:
Configuring the Clock Tree
STM32L4 the highest clock speed to 80M, so the configuration PLL, the last HCLK = 80Mhz
to:
Generating project settings
Code generation is provided
The last set generates a separate initialization file:
Generate code
Click GENERATE CODE
to generate MDK-V5 project:
Generate success
3. In the MDK write, compile, download user code
Write user code
STM32CubeMX generated code directory is as follows:
Enter the MDK-ARM文件夹
directory, open the project:
In main.c
the main function simply write user code:
1 while (1) 2 { 3 /* USER CODE END WHILE */ 4 /* USER CODE BEGIN 3 */ 5 HAL_Delay(200); 6 HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); 7 }
Compiled code
Click the button to compile the project as shown
Set Downloader
As shown in Figure Click the button to open the Settings page
Download settings, select "ST-Link Debugger", and click "Settings".
Check the "Reset and Run" option under "Flash Download" menu, after the burning process has reached the MCU automatically reset and run the purpose of the program.
Download run
Click "LOAD" button to burn code into the device.
Burning success
Experimental phenomena
So far, we've learned how to use STM32CubeMX quickly generate MDK engineering, light up a LED, how about the next one to use STM32CubeMX initialize the GPIO key detection.