Setup a Blink Project Using STM32 (CubeMX+Clion)
First open the CubeMX:
Then click sstart my project from MCU:
Choose the corresponding model from the list or frome the saved list (favorite):
Then setup the peripherals:
Setup system through serial wire.
then setup the crystal high speed clock :
Configure clock to 72Mhz or other value.
Setup USUART1 and enable global interrupt.
Setup BLUE LED on pin 15.
Give the project name, tool chain select STM32 Cube IDE.
Then Generate Code.
Open the project using CLION.
Click copy to project and use.
For ST-Link V2-A Version we need to change the .cfg file like this :
# This is an STM32F4 discovery board with a single STM32F407VGT6 chip.
# http://www.st.com/internet/evalboard/product/252419.jsp
;source [find interface/stlink-v2.cfg]
source [find interface/stlink-v2-1.cfg]
transport select hla_swd
# increase working area to 64KB
set WORKAREASIZE 0x10000
source [find target/stm32f4x.cfg]
reset_config srst_only
Build Programm successful.
Upload the program.
This may not successful the first time, if so, we need to press the reset button on the stm32 and press the run button on the clion at the same time.
Blink the LED.
Code :
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, 1);
HAL_Delay(1000);
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, 0);
HAL_Delay(1000);
Result ;
Blinky Again with some new
/* USER CODE BEGIN WHILE */
while (1) {
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */