本文参考代码
https://letanphuc.net/2015/02/stm32f0-tutorial-gpio-blinking-led-cubemx-keil-source-insight/
ide版本信息:
STM32CubeIDE Release Note v1.4.0
CubeMX V6.0.0 integration
-
Additional support for STM32MP1 devices : OpenSTLinux 2.0 SDK & Projects support
-
Additional support for STM32H7 devices
-
itional support for STM32G4 devices
-
OpenOCD support improvements
It uses an enhanced GNU tool chain for STM32, based on GNU Arm Embedded.
It has an integrated version of STM32CubeMX and MCUFinder
ntegrates the command-line version of STM32CubeProgrammer (STM32CubeProg) for Flash memory handling while using the ST-LINK GDB server.
STM32CubeIDE is based on the following technology, with STMicroelectronics-specific enhancements:
-
ECLIPSETM 2019-09 and CDT version 9.9.0(Eclipse foundation)
-
GNU Tools for STM32, based on GNU Tools for Arm Embedded Processors 7-2018-q2-update 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]
-
GNU GDB (GNU Tools for STM32 7-2018-q2-update.20190328-1800) 8.1.0.20180315-git
-
GNU Tools for Arm Embedded Processors 7-2018-q2-update 7.3.1 20180622 (release) [ARM/embedded-7- branch revision 261907]
-
GNU GDB (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 8.1.0.20180315-git
-
AdoptOpenJDK Runtime Environment (build 1.8.0_252, 64-bit)
-
ST-LINK_gdbserver 5.6.0, supporting ST-LINK/V2 and STLINK-V3
-
SEGGER J-Link GDB Server V6.80b
-
Open On-Chip Debugger 0.10.0+dev-g30d1303
启动后提示升级1.4.2
使用必须联网
install anyway
重启
新建项目
打开cubemx后
可能会更新一些文件
然后选择芯片或开发版 比如我这块
整个电路板包括:
- 核心芯片STM32F051R8T6微控制器:64KB Flash和8KB RAM。
- 集成STLINK/V2仿真器
- 四个LED
- 2个按键
- mini-B USB接口
全扩展I/O插座 开发套件还包括了一个万用板,与开发板的尺寸一样(51mm x 88.9mm,间距2.54mm)。这个万用板更方便用来扩展功能,搭建原型平台。可以用来连接各种扩展板卡比如ST自己的传感器模块甚至Arduino的各种兼容扩展板。
开发板上有一个mini-B型USB,作为供电以及调试编程。因为将STM32F051芯片的所有IO脚引出,所以也可以通过引脚接入5V外部电源或者向外输出5V和3V的直流电源。
STM32F0-Discovery 的使用很简单,在出厂时预置了一个Demo的程序。首先确认板上的跳线都已经安装,连接mini-B USB到计算机或者5V电源。这时电源指示灯(LD1)变亮,USB通讯指示灯(LD2)红色闪烁,速度由慢到快,表示USB初始化完成。同时程序执行后绿色的LED(LD3)闪烁。
next
选择语言
开始下载需要的文件
配置各个页面信息
修改代码
下载参考代码
https://www.st.com/en/embedded-software/stm32cubef0.html
修改while循环
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, LD4_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC,LD3_Pin, GPIO_PIN_SET);
}
/* USER CODE END 3 */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, LD4_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
//HAL_GPIO_WritePin(GPIOC,LD3_Pin, GPIO_PIN_SET);
HAL_GPIO_TogglePin(GPIOC, LD3_Pin); //Toggle the state of pin PC9
HAL_Delay(100); //delay 100ms
}
/* USER CODE END 3 */
build
默认点击run会自动build
run debug
第一次使用,提示升级stlink固件
tips--ok
按照提示完成stlink升级
run点击后会下载程序
STMicroelectronics ST-LINK GDB server. Version 5.6.0
Copyright (c) 2020, STMicroelectronics. All rights reserved.
Starting server with the following options:
Persistent Mode : Disabled
Logging Level : 1
Listen Port Number : 61234
Status Refresh Delay : 15s
Verbose Mode : Disabled
SWD Debug : Enabled
InitWhile : Enabled
Waiting for debugger connection...
Debugger connected
-------------------------------------------------------------------
STM32CubeProgrammer v2.5.0-RC1
-------------------------------------------------------------------
ST-LINK SN : 48FF76065185525453150287
ST-LINK FW : V2J37S0
Board : --
Voltage : 2.92V
SWD freq : 4000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x440
Revision ID : Rev 2.0
Device name : STM32F05x/F030x8
Flash size : 64 KBytes
Device type : MCU
Device CPU : Cortex-M0
Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_5wHtk2.srec
File : ST-LINK_GDB_server_5wHtk2.srec
Size : 4896 Bytes
Address : 0x08000000
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 4]
Download in Progress:
File download complete
Time elapsed during download operation: 00:00:00.401
Verifying ...
Download verified successfully
Debugger connection lost.
Shutting down...
debug点击后会打开调试界面
勾选remember my decision switch
STMicroelectronics ST-LINK GDB server. Version 5.6.0
Copyright (c) 2020, STMicroelectronics. All rights reserved.
Starting server with the following options:
Persistent Mode : Disabled
Logging Level : 1
Listen Port Number : 61234
Status Refresh Delay : 15s
Verbose Mode : Disabled
SWD Debug : Enabled
InitWhile : Enabled
Waiting for debugger connection...
Debugger connected
-------------------------------------------------------------------
STM32CubeProgrammer v2.5.0-RC1
-------------------------------------------------------------------
ST-LINK SN : 48FF76065185525453150287
ST-LINK FW : V2J37S0
Board : --
Voltage : 2.93V
SWD freq : 4000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x440
Revision ID : Rev 2.0
Device name : STM32F05x/F030x8
Flash size : 64 KBytes
Device type : MCU
Device CPU : Cortex-M0
Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_5ymeVa.srec
File : ST-LINK_GDB_server_5ymeVa.srec
Size : 4896 Bytes
Address : 0x08000000
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 4]
Download in Progress:
File download complete
Time elapsed during download operation: 00:00:00.405
Verifying ...
Download verified successfully
支持的调试功能
点击step over单步执行
点击Resume恢复程序执行
LED灯开始闪烁 ,测试ok
其他资料:
What is OpenOCD?
The Open On-Chip Debugger (OpenOCD) aims to provide debugging, in-system program- ming and boundary-scan testing for embedded target devices.
It does so with the assistance of a debug adapter, which is a small hardware module which helps provide the right kind of electrical signaling to the target being debugged. These are required since the debug host (on which OpenOCD runs) won’t usually have native support for such signaling, or the connector needed to hook up to the target.
Such debug adapters support one or more transport protocols, each of which involves dif- ferent electrical signaling (and uses different messaging protocols on top of that signaling). There are many types of debug adapter, and little uniformity in what they are called. (There are also product naming differences.)
These adapters are sometimes packaged as discrete dongles, which may generically be called hardware interface dongles. Some development boards also integrate them directly, which may let the development board connect directly to the debug host over USB (and sometimes also to power it over USB).
GDB server start-up options
The GDB server is started up with the following command:
ST-LINK_gdbserver.exe [options]
Most options are available in a short and long form. The set of options, which the GDB server supports, are described below with default modes and configurations in bold:
-
-h, --help
Causes the ST-LINK_gdbserver to display usage information.
-
-q, --debuggers
List connected debuggers, ST-LINK serial numbers. -
-i <ST-LINK S/N>, --serial-number <ST-LINK S/N> Specifies the ST-LINK serial numbers the server shall connect to.
-
--frequency <max freq kHz>
Specifies the ST-LINK communication frequency in kHz, such as 5, 25, 100, 240, 950, 1800, 4000, 8000,24000 kHz.
-
--erase-all
Erases all the memories. -
--memory-map <device id>
Shows the memory map for the given device identifier, such as 0x410. -
--ext-memory-loaders
Provides the list of the available external memory loaders.
-
-cp <path>, --stm32cubeprogrammer-path <path>
Path to the STM32CubeProgrammer (STM32CubeProg) installation. -
--version
Displays version information and exits.
-
Starting the GDB server
The GDB server can be started in a command window in the following way:-
cd C:\ST\STM32CubeIDE_1.0.0.19w12patch\STM32CubeIDE\plugins \com.st.stm32cube.ide.mcu.externaltools.stlink-gdb- server.win32_1.0.0.201903011553\tools\bin\ST-LINK_gdbserver
-
Start the GDB server using –cp with the path to STM32_Programmer_CLI.exe
For instance: ST-LINK_gdbserver.exe -d -v -cp "C:\ST\STM32CubeIDE_1.0.0.19w12patch \STM32CubeIDE\plugins \com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_1.0.0.201903011553\ tools\bin"
-
Then, the GDB server connects to the STM32 device using the ST-LINK JTAG and waits for commands from a GDB debug session.
-
-
Launching GDB
A command-line GDB client is started by the command
>arm-none-eabi-gdb <program.elf>
where <program.elf> is the program to be debugged. -
Connecting to the server
The server can be started in either persistent or non-persistent mode:
-
If the server is started in non-persistent mode, the client must connect to the server using the command
>target remote <ip-address>:<port-number>
When the client connects to the server in non-persistent mode using this command, the debug session cannot be restarted without closing both client and server.
-
If the server is started in persistent mode, the client must connect to the server using the command
>target extended-remote <ip-address>:<port-number>
When the client connects to the server in persistent mode using this command, the user has the facility to restart the debug session without closing the server or client. In this mode of operation for client and server, the debug session can be repeatedly restarted.
-
Loading the program on the target
The executable program is loaded on the target using the GDB command
>load <program.elf>
This command loads the program on the target. If the code segment of the program lies in the Flash ROM, then the respective pages of the Flash are erased before the new code is written.
-
Note: The Flash programming (the code download into the Flash memory) is handled by the GDB server using STM32CubeProgrammer (STM32CubeProg) and is transparent to the user.
-
Running the program
Once the program is loaded, the debugger starts execution through the command>continue
Note: There is no mechanism for specifying command-line parameters to the program.
The user can halt the program by pressing Ctrl-C while it is running. The user can step over a statement by using the next command. The user can also step inside a function by using the step command.
-
-
Monitor commands
The GDB monitor commands are supported and implement target-specific features, especially for performingFlash controller specific commands.
The following commands are the monitor commands supported for the ST-LINK GDB server: -
>monitor help
Prints information about the supported monitor commands.
-
>monitor reset
Resets the target device.
-
>monitor flash mass_erase
Used to erase all the pages of the Flash device. Care needs to be taken when using this command since it causes all data stored in the Flash to be lost.
Troubleshooting
In case the server hangs or fails to start up, follow these steps:
-
Shutdown the GDB server and any client attached to the server.
-
Power off the target board.
-
Disconnect the ST-LINK JTAG USB cable.
-
Re-connect the ST-LINK JTAG USB cable.
-
Power on the target board.
-
Check the debug configuration settings, such as the SWD/JTAG interface
-
Start the GDB server, preferably using a different port number.
UM2576
Troubleshooting
A good practice is to try the debug of another project to eliminate the possibility of a project-specific problem with the project configuration or start-up code.
We also recommend to try and debug with another USB cable, ST-LINK or STM32 hardware to exclude hardware failures as the reason for the debug problems.
It is also advised to try and connect to the target using some other tool from STMicroelectronics, such as the STM32CubeProgrammer (STM32CubeProg). If STM32CubeProgrammer can connect to the target, try to:
-
Erase the Flash with STM32CubeProgrammer.
-
Program a new program with STM32CubeProgrammer.
-
If the programming is successful, erase the Flash again with STM32CubeProgrammer.
-
Disconnect STM32CubeProgrammer from the target.
-
Try and debug the program using ST-LINK_gdbserver.