This post was last edited by Jack Zhang on 2020-1-3 17:04
Test a cost-effective MCU . This MCU is definitely a must-have sword for embedded engineers. The most amazing thing is that ST company gives you the sword and also provides a sword manual to ward off evil spirits (see the picture below)
I have the sword and the sword manual, but I still need to practice.
STM32G071 is a newcomer to the industry. Let me show you how to flip GPIO and print serial port. Please don't laugh at me.
Now it starts
Double-click the icon below to open the STM32CubeMX software
Enter the following interface
Find the ACCESS TO MCU SELECTOR option in this interface as shown below
Click to open the MCU selection interface as shown below
Find the image below and enter STM32G071RB in the Search MCU dialog box.
When the input is completed, the dialog box in the lower right corner will display two options as shown below. We select the chip with LQFP64 package and double-click this option.
Double-click to enter the following interface
At this time, you must pay attention to whether the MCU option at the bottom is as shown below
Enter PA5 in the interface search window . After entering, PA5 will flash or change color.
Click PA5 and select the PGIO_Output option as shown in the figure below. Please also refer to the schematic diagram. PA5 is connected to an external yellow LED light. We use this as an output display. We can use this LED to observe whether the MCU is working and its working status.
The LED related schematic diagram is as follows
Then select LPUART1 in the Commectivity tab , find the Mode tab in LPUART1 Mode and Configuration and select Asynchronous communication , as shown below
After selection, the following figure is shown. At this time, the default interface of LPUART1 is PC0 and PC1. We need to change the communication interface of LPUART1 to the interface that the hardware of Nucleo board has been connected to ( PA2 and PA3 ).
The method to modify the communication interface of LPUART1 is as follows: hold down the CTRL key and drag PC0 to PA3 with the mouse, hold down the CTRL key and drag PC1 to PA2 with the mouse. The modified interface is as shown below
In the Time Configuration tab, find the yellow box in the picture below and fill it with 64 and press Enter. Then check whether the values in the three red boxes are the same as the picture below.
After completing the above settings, return to the Pinout & Configuration tab and find the Parameter settings tab. In Basic Parameters, change Baud Rate to 115200Bits/s , Word Length to 8Bits , Parityn to None , and Stop Bits to 1 , as shown below.
Now, we just need to enter the project name in the project manager and select IDE , as shown below
After completing this step, click GENERATE CODE to generate the code.
After generating the code, open MDK, find the main file and add #include <stdio.h> around line 26 as shown below
Add #define PUTCHAR_PROTOTYPE int fputc (int ch, FILE *f) around line 56 as shown below
Add around line 237
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&hlpuart1,(uint8_t *)&ch,1,0xff);
return ch;
}
Add to the main function
uint32_t countS=0;
Add in the main loop
printf("** Seconds Count %dS** \n\r",countS);
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
HAL_Delay(1000);
countS++;
When everything is complete, compile and download and run
The running results are as follows: the serial port prints the running seconds, and the LED of PA5 flips once per second
This content is originally created by EEWORLD forum user Zhang Jack . If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source