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

共1条 1/1 1 跳转至

【STM32H747I-DISCO|Zephyr】驱动LCD屏

高工
2025-12-25 13:50:27     打赏

【前言】

Zephyr已经支持STM32H747的官方开发板。本篇将分享如何快速体验驱动LCD屏。

【开发环境】

1、wsl2

2、west

【实现步骤】

1、复制hello world工程

cp -r ~/zephyrproject\zephyr\samples\drivers\display ~/zephyrproject/app/stm32h747/H747_display

2、加载虚拟环境:

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

3、进入lcd工程

lugl@lugl:~/zephyrproject/app/stm32h747/h747_display$ ls
CMakeLists.txt  README.rst  boards  build  prj.conf  src

4、在stm32h747的网页中,如果使用lcd屏,必须指定设备树:

image.png

经查看屏的型号为MB1166-A09,因此在编译时需要指定参数如下:

--shield st_b_lcd40_dsi1_mb1166_a09

5、程序修改

由于例程用到了malloc,然而好象现在版本的不支持动态申请内存,因此我指定一个内存给buf

#define DISPLAY_BUFFER_SIZE (384U * 1024U)  /* 384 KB */
static uint8_t __aligned(4) display_buffer[DISPLAY_BUFFER_SIZE];

6、编译

 west build -p auto -b stm32h747i_disco/stm32h747xx/m7 --shield st_b_lcd40_dsi1_mb1166_a09
 [9/9] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       42264 B         1 MB      4.03%
             RAM:      465984 B       512 KB     88.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:       1500 KB        32 MB      4.58%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from /home/lugl/zephyrproject/app/stm32h747/h747_display/build/zephyr/zephyr.elf for board: stm32h747i_disco

7、下载

加载st-link到wsl中

PS C:WINDOWSsystem32> 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

屏已经顺利点亮:

image.png

【总结】

stm32H747已经完美的适配好zephyr生态,可以非常快速的创建开发环境。点亮LCD屏也相当容易。






关键词: STM32H747I-DISCO     Zephyr     L    

共1条 1/1 1 跳转至

回复

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