这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » STM32 » 【STM32H747I-DISCO|Zephyr】体验点灯

共1条 1/1 1 跳转至

【STM32H747I-DISCO|Zephyr】体验点灯

高工
2025-12-25 07:25:09     打赏

【前言】

Zephyr已经支持STM32H747的官方开发板,可以快速的实现入门。本篇将分享如何快速体验点亮LED灯。

【开发环境】

1、wsl2

2、west

【实现步骤】

1、复制hello world工程

cp -r ~/zephyrproject/zephyr/samples/basic/blinky ~/zephyrproject/app/stm32h747/

2、加载虚拟环境:

~/zephyrproject/app/stm32h747/hello_world$ source ~/zephyrproject/zephyr/zephyr-env.sh

3、进入hello world工程

lugl@lugl:~$ cd ~/zephyrproject/app/stm32h747/blinky/
lugl@lugl:~/zephyrproject/app/stm32h747/blinky$ ls
CMakeLists.txt  README.rst  boards  prj.conf  sample.yaml  src

4、查看代码中led的定义:

/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)

5、查看设备树是否对led0进行了定义:

找到文件夹zephyrproject\zephyr\boards\st\stm32h747i_disco

查看设备树stm32h747i_disco_stm32h747xx_m7.dts

	aliases {
		led0 = &green_led_1;
		led1 = &orange_led_2;
		sw0 = &wake_up;
	};

说明可以直接使用led0或者led1

6、编译

west build -p always -b stm32h747i_disco/stm32h747xx/m7
-- Zephyr version: 4.3.0 (/home/lugl/zephyrproject/zephyr), build: v4.3.0
[153/153] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       20160 B         1 MB      1.92%
             RAM:        4608 B       512 KB      0.88%
          EXTMEM:          0 GB        64 MB      0.00%
           SRAM0:          0 GB       512 KB      0.00%
           SRAM1:          0 GB       128 KB      0.00%
           SRAM2:          0 GB       128 KB      0.00%
           SRAM3:         16 KB        32 KB     50.00%
           SRAM4:          0 GB        64 KB      0.00%
          SDRAM2:          0 GB        32 MB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from /home/lugl/zephyrproject/app/stm32h747/blinky/build/zephyr/zephyr.elf

7、下载

加载st-link到wsl中

PS C:\WINDOWS\system32> usbipd attach --wsl --busid 2-2
usbipd: info: Using WSL distribution 'Ubuntu-22.04' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Detected networking mode 'nat'.
usbipd: info: Using IP address 172.29.112.1 to reach the host.

然后执行下载:

lugl@lugl:~/zephyrproject/app/stm32h747/blinky$ west flash --runner openocd
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner openocd
-- runners.openocd: Flashing file: /home/lugl/zephyrproject/app/stm32h747/blinky/build/zephyr/zephyr.hex
Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
init
Info : STLINK V3J16M8 (API v3) VID:PID 0483:374E
Info : Target voltage: 3.283124
Info : Unable to match requested speed 1800 kHz, using 1000 kHz
Info : Unable to match requested speed 1800 kHz, using 1000 kHz
Info : clock speed 1000 kHz
Info : stlink_dap_op_connect(connect)
Info : SWD DPIDR 0x6ba02477
Info : stm32h7x.cpu0: hardware has 8 breakpoints, 4 watchpoints
Info : stm32h7x.cpu0: external reset detected
Info : starting gdb server for stm32h7x.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000c58 msp: 0x240011c0
    TargetName         Type       Endian TapName            State
--  ------------------ ---------- ------ ------------------ ------------
 0  stm32h7x.ap2       mem_ap     little stm32h7x.cpu       halted
 1* stm32h7x.cpu0      cortex_m   little stm32h7x.cpu       halted

target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000c58 msp: 0x240011c0
Info : Unable to match requested speed 4000 kHz, using 3300 kHz
Info : Unable to match requested speed 4000 kHz, using 3300 kHz
Info : Device: STM32H74x/75x
Info : flash size probed value 2048
Info : STM32H7 flash has dual banks
Info : Bank (0) size is 1024 kb, base address is 0x08000000
Warn : Adding extra erase range, 0x08004ec0 .. 0x0801ffff
auto erase enabled
wrote 20160 bytes from file /home/lugl/zephyrproject/app/stm32h747/blinky/build/zephyr/zephyr.hex in 4.200407s (4.687 KiB/s)

Error: stm32h7x.cpu0 -- clearing lockup after double fault
target halted due to debug-request, current mode: Handler Reset
xPSR: 0xa05f0001 pc: 0xa05f0001 msp: 0xa05f0001
Polling target stm32h7x.cpu0 failed, trying to reexamine
Info : stm32h7x.cpu0: hardware has 0 breakpoints, 10 watchpoints
Info : stm32h7x.cpu0: external reset detected
shutdown command invoked

观察板载的LED灯,看到顺利的闪烁起来了。

打开串口终端,看到打印出LED灯状态:

image.png

【总结】

stm32H747已经完美的适配好zephyr生态,可以非常快速的创建开发环境。






关键词: STM32H747I-DISCO     Zephyr         

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]