首页
随机
最近更改
特殊页面
社群首页
参数设置
关于WHY42
免责声明
WHY42
搜索
用户菜单
登录
欢迎来到Riguz的小站!这是一个私人wiki,用来记录一些我的笔记。
查看“︁Stm32 led blink”︁的源代码
←
Stm32 led blink
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
= ST tools= == STM32CubeProgrammer== [[Image:STM32CubeProgrammer.png|600px]] = STM32 development settings on Mac = == ST-Link connection == Ref: <ref>https://www.cnblogs.com/jpeg/p/hello-world-of-cocox-ide.html</ref> * VCC 3.3v * GND * SWDCLK * SWDIO == Install Stm32CubeIde== * install [https://www.st.com/en/development-tools/stm32cubeclt.html stm32cubeclt] * install [https://www.st.com/en/development-tools/stm32cubeide.html stm32cubeide] <syntaxhighlight lang="bash"> $ 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 </syntaxhighlight> <ref>https://github.com/MaJerle/stm32-cube-cmake-vscode?tab=readme-ov-file</ref> However, could not use with my SD_link: <syntaxhighlight lang="python"> STM32_Programmer_CLI -c port=SWD freq=4000 -e all ------------------------------------------------------------------- STM32CubeProgrammer v2.19.0 ------------------------------------------------------------------- Error: Old ST-LINK firmware version. Upgrade ST-LINK firmware Error: Old ST-LINK firmware!Please upgrade it. </syntaxhighlight> == Install ST Link Driver == <syntaxhighlight lang="bash"> brew install stlink </syntaxhighlight> <syntaxhighlight lang="bash"> $ st-info --probe Found 1 stlink programmers version: V2J17S4 serial: 56FF74066580515144522467 flash: 524288 (pagesize: 2048) sram: 65536 chipid: 0x414 dev-type: F1xx_HD </syntaxhighlight> == Install PlatformIo == Install platformio extension in vscode, and then install stm32 platform: [[Image:platformio.png|600px]] == MDK-ARM == Windows7x64 virtual machine on Mac * Download and install [https://www.keil.com/demo/eval/arm.htm mdk-arm] * [https://aka.ms/vs/17/release/vc_redist.x64.exe VC_redist.x64.exe] The pack installer seems useless. Just close it, and the install link is somehow disabled. 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/development-tools/stsw-link009.html ST-link Driver] * [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)] Project structure(https://github.com/drriguz/stm32-examples/tree/master/stm32-led): [[Image:mdk-led-structure.png|600px]] Set c++ options: [[Image:mdk-led-options.png|600px]] Set debuger to use ST-link+SW: [[Image:mdk-led-debugger1.png|600px]] [[Image:mdk-led-debugger2.png|600px]] [[Image:mdk-led-debugger3.png|600px]] Note: * Don't use startup_stm32f10x_hd.s by Mdk, use the library one * Don't call SystemInit in main.c, it's already called in startup_stm32f10x_hd.s <ref>https://static.assets-stash.eet-china.com/original/3X/2/b/2b319d51f9e583c6c76b6ac42bb2181c11102cb8.pdf</ref> == OpenOCD == https://openocd.org/pages/getting-openocd.html <ref>https://pfeerick.github.io/InfiniTime/doc/openOCD.html</ref> <ref>https://rudi-horn.de/Home/7-debugging-the-stmf-with-an-st-linkv-and-openocd</ref> <syntaxhighlight lang="bash"> # 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 # 12.0 Error: ST-Link version does not support DAP direct transport git checkout v0.10.0 ./bootstrap ./configure --enable-stlink --enable-ftdi --disable-werror make -j 8 sudo make install </syntaxhighlight> OpenOCD install path: /usr/local/share/openocd/scripts/ Start debug: <syntaxhighlight lang="bash"> $ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg Open On-Chip Debugger 0.10.0 (2025-04-04-01:17) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'. Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD adapter speed: 1000 kHz adapter_nsrst_delay: 100 none separate Info : Unable to match requested speed 1000 kHz, using 950 kHz Info : Unable to match requested speed 1000 kHz, using 950 kHz Info : clock speed 950 kHz Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748 Info : using stlink api v2 Info : Target voltage: 3.316364 Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints </syntaxhighlight> == STM32CubeMX == [https://www.st.com/en/development-tools/stm32cubemx.html stm32cubemx] Select STM32F103ZET6: [[Image:CubdeMx-choose-chip.png|600px]] Then config to use cmake, and click "Generate": [[Image:CubdeMx-config.png|600px]] Make the project: <syntaxhighlight lang="bash"> $ cd stm32-hello $ mkdir build $ cd build $ make [100%] Linking C executable stm32-hello.elf Memory region Used Size Region Size %age Used RAM: 1584 B 64 KB 2.42% FLASH: 3772 B 512 KB 0.72% [100%] Built target stm32-hello </syntaxhighlight> == stm32-for-vscode == = Led blink = Ref:<ref>https://stm32-base.org/guides/platformio.html</ref> main.h <syntaxhighlight lang="cpp"> #ifndef __MAIN_H_ #define __MAIN_H_ #include "stm32f1xx_hal.h" void Error_Handler(void); #endif </syntaxhighlight> main.cpp: <syntaxhighlight lang="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) { } } </syntaxhighlight> == LED not blinking== The led is not blinking, but always on, similar as <ref>https://www.reddit.com/r/embedded/comments/ucohur/new_to_stm_tried_making_an_led_blink_but_it/</ref> = 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: [[Image:stm32cubeide-error.png|600px]] * If install old version of stm32cubeide, "“STM32CubeIDE is damaged and can’t be opened" <ref>https://community.st.com/t5/stm32cubeide-mcus/stm32cubeide-is-damaged-and-can-t-be-opened/td-p/256814</ref> [[Category:ARM]] [[Category:STM32]] [[Category:Embedded]]
返回
Stm32 led blink
。