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
Led blink
Ref:[3]
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 [4]
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" [5]
- ↑ 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://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