第73行: | 第73行: | ||
Download [https://www.keil.arm.com/devices/stmicroelectronics-stm32f103ze/processors/ stm32f103ze] DFP and install | Download [https://www.keil.arm.com/devices/stmicroelectronics-stm32f103ze/processors/ stm32f103ze] DFP and install | ||
=== MDK4.7 === | |||
MDK 4.72 + keygen (Menu/License manage/CID), generated key only valid to 2020, but still can use | |||
* [https://www.st.com/en/embedded-software/stsw-stm32054.html STM32F10x Standard Peripheral Library (SPL)] | |||
* [https://www.st.com/en/embedded-software/stm32cubef1.html CMSIS (Core Peripheral Access Layer)] | |||
== OpenOCD == | == OpenOCD == |
2025年3月28日 (五) 11:32的版本
STM32 development settings on Mac
ST-Link connection
Ref: [1]
- VCC 3.3v
- GND
- SWDCLK
- SWDIO
Install Stm32CubeIde
- install stm32cubeclt
- install stm32cubeide
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for STM32 13.3.rel1.20240926-1715) 13.3.1 20240614
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ STM32_Programmer_CLI --version
-------------------------------------------------------------------
STM32CubeProgrammer v2.19.0
-------------------------------------------------------------------
STM32CubeProgrammer version: 2.19.0
$ ST-LINK_gdbserver --version
ST-LINK_gdbserver version: 7.10.0
$ cmake --version
cmake version 3.28.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ ninja --version
1.11.1
Install ST Link Driver
brew install stlink
$ st-info --probe
Found 1 stlink programmers
version: V2J17S4
serial: 56FF74066580515144522467
flash: 524288 (pagesize: 2048)
sram: 65536
chipid: 0x414
dev-type: F1xx_HD
Install PlatformIo
Install platformio extension in vscode, and then install stm32 platform:
MDK-ARM
Windows7x64 virtual machine on Mac
- Download and install mdk-arm
- VC_redist.x64.exe
The pack installer seems useless. Just close it, and the install link is somehow disabled.
Download stm32f103ze DFP and install
MDK4.7
MDK 4.72 + keygen (Menu/License manage/CID), generated key only valid to 2020, but still can use
OpenOCD
https://openocd.org/pages/getting-openocd.html
# don't brew install, lacks of stlink support
# brew install openocd
brew install jimtcl libusb
# ./doc/openocd.texi:12874: Unmatched `@end'.
# makeinfo: Removing output file `doc/openocd.info' due to errors; use --force to preserve.
brew install texinfo # need newer version
# configure: error: libusb-1.x is required for adapter "ST-Link Programmer".
export PKG_CONFIG_PATH="/usr/local/opt/libusb/lib/pkgconfig:$PKG_CONFIG_PATH"
git clone https://git.code.sf.net/p/openocd/code openocd-code
cd openocd-code
make -j 4
sudo make install
OpenOCD install path: /usr/local/share/openocd/scripts/
Start debug:
$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg
Open On-Chip Debugger 0.12.0+dev-00910-g72ff2e2d9 (2025-03-28-15:13)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
Info : auto-selecting first available session transport "dapdirect_swd". To override use 'transport select <transport>'.
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.237209
Error: ST-Link version does not support DAP direct transport
STM32CubeMX
stm32-for-vscode
Led blink
Ref:[5]
main.h
#ifndef __MAIN_H_
#define __MAIN_H_
#include "stm32f1xx_hal.h"
void Error_Handler(void);
#endif
main.cpp:
#include "main.h"
#define LED_PIN GPIO_PIN_4
#define LED_GPIO_PORT GPIOD
#define LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
void SystemClock_Config(void);
void LED_Init();
int main(void)
{
HAL_Init();
SystemClock_Config();
LED_Init();
while (1)
{
HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_PIN);
HAL_Delay(200);
}
}
void LED_Init()
{
LED_GPIO_CLK_ENABLE();
GPIO_InitTypeDef gpioConfig = {0};
gpioConfig.Pin = LED_PIN;
gpioConfig.Mode = GPIO_MODE_OUTPUT_PP;
gpioConfig.Pull = GPIO_NOPULL;
gpioConfig.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(LED_GPIO_PORT, &gpioConfig);
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
void Error_Handler(void)
{
__disable_irq();
while (1)
{
}
}
LED not blinking
The led is not blinking, but always on, similar as [6]
Issues
- If "st-info" shows no device, then check if the usb wine is good
- Stm32CubeIde does not work with none-original ST-Link device, error:
- If install old version of stm32cubeide, "“STM32CubeIDE is damaged and can’t be opened" [7]
- ↑ https://www.cnblogs.com/jpeg/p/hello-world-of-cocox-ide.html
- ↑ https://github.com/MaJerle/stm32-cube-cmake-vscode?tab=readme-ov-file
- ↑ https://pfeerick.github.io/InfiniTime/doc/openOCD.html
- ↑ https://rudi-horn.de/Home/7-debugging-the-stmf-with-an-st-linkv-and-openocd
- ↑ https://stm32-base.org/guides/platformio.html
- ↑ https://www.reddit.com/r/embedded/comments/ucohur/new_to_stm_tried_making_an_led_blink_but_it/
- ↑ https://community.st.com/t5/stm32cubeide-mcus/stm32cubeide-is-damaged-and-can-t-be-opened/td-p/256814