ThinkNotes

Simple is not easy | 化繁为简,知易行难

0%

STM32–Firmware Architecture part2:业务代码分析–o2link FWs

o2link FWs的架构区别

o2link FWs指三类:

  • o2link original FW(gen2): 用于老项目的对外发布版FW
  • o2link JEV323 FW: 在o2link original FW上,针对JEV323做了功能改动和架构改动
  • o2link Skyways FW: 在o2link original FW上,针对Skyways做了功能改动

Bootloader和Firmware结构

bootloader和Firmware在Flash的分布

  1. o2link original FW和o2link Skyways FW是分为bootloader和Firmware两部分,两者共同构成烧录的bin文件
  • bootloader:放在Flash的0x0800_0000 ~ 0x0x0800_8000空间,空间32KB;用作USB上位机烧录Firmware到Flash功能。

    image-20240517103655180

  • Firmware: 放在Flash的0x0800_8000~ 0x0801_0000空间,空间32KB;用作处理USB上位机下发的各种控制、读写请求。

    image-20240517103700830

    bootloader和Firmware所有代码在Flash的分布如下:

image-20240517111755697

注意:ROM/RAM空间分布对应到.sct的配置内容需要特别小心:

阅读全文 »

STM32–从0创建项目和设计架构

野火STM32 F4创建项目:

https://doc.embedfire.com/mcu/stm32/f4/hal_general/zh/latest/doc/chapter10/chapter10.html

STMF0创建项目:

(1)芯片型号启动创建

image-20240722151016542

(2)配置时钟和各外设

这里参考已有的其他stm32f0项目,用CubeMX打开两个项目,在GUI对照配置新项目自动生成代码。要特别注意时钟的配置,如果使用外接晶振,和具体开发板环境有关。

image-20240722151602583

配置外设和GPIO有技巧:先配置外设(connectivity项,SPI,UART,I2C…),配好后会自动配置外设占用的GPIO;而独立的GPIO功能(一般作为debug pin)在外设配完后再补充。

阅读全文 »

STM32–搭建VSCode+STMCubeIDE开发环境

用STM32CubeIDE创建工程

用VSCode编辑代码

配置.vscode使能tab补全

Stm32的HAL库默认是没有被VSCode的C/C++ intelligence检测到,自动补全功能不完整,例如HAL_UART_XXX不能tab补全到HAL_UART_Transmit,这个API定义在Drivers/Drivers/STM32FXXX_HAL_Driver/Inc里,C/C++ intelligence没有检测到这个路径,因此需要配置C/C++ intelligence的c_cpp_properties.json, 添加include和defines。

(1)打开STM32项目

注意:要配置哪个STM32项目就VSCode打开哪个目录,不要打开包括多个STM32项目的workspace,不然配置的.vscode是针对workspace目录的,不会对各项目生效。

比如以下workspace有几个STM32CubeIDE创建的项目,VSCode应该打开具体的项目serial-test-isr再配置该项目的.vscode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
PS C:\Users\cursorhu\STM32CubeIDE\workspace_1.15.0> ls

目录: C:\Users\cursorhu\STM32CubeIDE\workspace_1.15.0

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2024/4/29 10:03 .metadata
d----- 2024/4/29 10:34 .vscode
d----- 2024/4/24 19:45 led-test
d----- 2024/4/25 11:25 serial-test
d----- 2024/4/29 10:06 serial-test-isr


PS C:\Users\cursorhu\STM32CubeIDE\workspace_1.15.0> cd .\serial-test-isr\
PS C:\Users\cursorhu\STM32CubeIDE\workspace_1.15.0\serial-test-isr> ls

目录: C:\Users\cursorhu\STM32CubeIDE\workspace_1.15.0\serial-test-isr

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2024/4/28 22:33 .settings
d----- 2024/4/29 10:06 .vscode
d----- 2024/4/28 16:26 Core
d----- 2024/4/28 17:51 Debug
d----- 2024/4/28 16:26 Drivers
-a---- 2024/4/28 16:39 25210 .cproject
-a---- 2024/4/28 16:39 8275 .mxproject
-a---- 2024/4/28 16:30 1221 .project
-a---- 2024/4/28 17:56 10224 serial-test-isr Debug.launch
-a---- 2024/4/28 16:39 2975 serial-test-isr.ioc
-a---- 2024/4/28 16:39 5306 STM32F072C8TX_FLASH.ld

(2)配置.vscode

阅读全文 »

STM32–Firmware Architecture part1:开发环境和HAL API应用

STM32–开发环境

当前主流的几种方案:(软件免费,无法律风险):

1.STM32CubeMX + Keil(社区版)+ VSCode:使用CubeMX快速创建工程并导出为MDK-ARM项目文件,使用Keil编译调试MDK-ARM项目包,使用VSCode编辑代码和版本管理。

优势:兼容老项目,资料最多;Keil的调试经验可以复用到其他非STM32 ARM芯片;

https://www.keil.arm.com/mdk-community/

https://www.st.com/en/development-tools/stm32cubemx.html

2.STM32CubeIDE:ST主推的方式,专用于ST32芯片的IDE,本质是STM32CubeMX + Eclipse IDE + ST的编译调试工具链。

优势:集成度最高;缺陷:只用于STM32

https://www.st.com/en/development-tools/stm32cubeide.html#overview

阅读全文 »

UEFI开发(二)

Library库

https://blog.csdn.net/weixin_45279063/article/details/115324601

以后面要用到的DEBUG库为例:

库的调用方是MdeModulePkg下的某个INF模块,被调用方是MdePkg库(这个属于基础库很常用)

  1. 调用方的INF中要导入库模块的dec和要用到的LibraryClasses
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Packages]
MdePkg/MdePkg.dec #这里包含了库模块MdePkg的dec声明,获取到MdePkg所有对外开放的库接口
MdeModulePkg/MdeModulePkg.dec #这是调用方模块

[LibraryClasses]
DevicePathLib
UefiBootServicesTableLib
UefiRuntimeServicesTableLib
MemoryAllocationLib
BaseMemoryLib
UefiLib
BaseLib
UefiDriverEntryPoint
DebugLib #这里导入了MdePkg库的DebugLib类(头文件),类似其他语言的import或者include namespace
PcdLib
  1. 调用方的c代码中可以直接include库的头文件(不需要用相对地址包含头文件)
1
#include <Library/DebugLib.h>
  1. 调用方使用库的函数体DEBUG();
阅读全文 »

UEFI开发(一)EDK2环境搭建

官方文档:

https://github.com/tianocore/tianocore.github.io/wiki/Getting-Started-with-EDK-II

https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-User-Documentation

下载代码

参考:edk2/Submodules

在C盘根目录用git命令下载edk2并下载submodule:

1
2
3
git clone https://github.com/tianocore/edk2.git
cd edk2
git submodule update --init

如果要切换到stable tag版本:

1
2
3
git tag -l #列出tag, -l: list
git checkout edk2-stable202X0X #切table tag
git submodule update #更新submodule(对应stable tag)
阅读全文 »

Windows Driver – INF Verifier使用笔记

WDK有INF verifier用于检测Driver安装包的INF信息文件的内容是否符合要求:如果INF不符合要求,可能在安装Driver报错或者Driver运行时功能报错。

INF verifier使用

1
.\infverif.exe /w /v C:\path\driver.inf

https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/running-infverif-from-the-command-line

排错示例

新建WDF驱动项目时产生默认的INF,但其中一些符号需要替换,否则安装driver时会直接报错安装失败

  1. DIRID 13问题

driver.sys一般的路径符号 DIRID是12,较新的OS WDK要求DIRID使用13,用于实现driver package isolation:

参考:https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/porting-inf-to-windows-driver

阅读全文 »

Windows Driver - Visual Studio配置

安装VisualStudio+SDK+WDK环境

全部流程:https://learn.microsoft.com/zh-cn/windows-hardware/drivers/download-the-wdk

注意:WDK安装前要求先安装适配版本的SDK:

https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/

推荐按以上链接在VS安装程序中安装Windows 11 SDK (10.0.26100.0),注意默认选中的不是这个版本,需要手动选择这个版本:

image-20240812164012107

正常安装完SDK和WDK后,创建一个KMDF项目是像这样:如果缺少SDK和Driver Setting这些,说明SDK版本不匹配

image-20240812164731134

注意:如果在有问题的环境创建了项目编译会报错,在环境配好后该项目也不能用还是会编译报错,应该删除重新建。

阅读全文 »

Windows WDF PCIe-SD Host Controller Driver Analysis

Current Status Analysis

Based on the dumpfile information:

1. Driver Stack Structure - Correct

  • Device stack is properly established: partmgr → disk → sdhcstor

  • Upper layer device (disk.sys) successfully starts and attaches to your driver

  • ServiceName is “disk”, DeviceInst shows correct device path

2. Critical Issue: ExtensionFlags Inconsistency

Device object ffffc701663ddc80 (Upper device):

  • ⚠️ ExtensionFlags = 0x0000000000 (Highlighted in orange - THIS IS THE PROBLEM)

  • This device object is missing necessary extension flags

Device object ffffc70162a1aa0 (Driver object):

  • ✓ ExtensionFlags = 0x00000800 (DOE_DEFAULT_SD_PRESENT)

  • This flag indicates SD card present - this is correct

阅读全文 »

Windows Driver – Windbg联调环境配置

参考:https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-a-network-debugging-connection-automatically

Target PC配置

注意:

Target PC要先开测试模式,且关闭系统所有网络防火墙。

Target PC要能Ping通Host PC,即Host PC和Target PC可以用同一局域网的路由器(Router)或交换机(Hub)的网口相连。

Target PC的kdnet创建一次以后再创建也不会变。

Kdnet配置完成后,设备管理器的网络设备会有Kernel Debug Network设备(KDNET),且网口设备(例如下面的Intel Ethernet)会有感叹号Code53是正常的,表示此网口正作为KDNET debug端口。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
C:\Windows\System32>
C:\Windows\System32>cd c:\kdnet

c:\kdnet>kdnet.exe

Network debugging is supported on the following NICs:
busparams=0.31.6, Intel(R) Ethernet Connection (7) I219-V, KDNET is running on this NIC.

Network debugging is supported on the following USB controllers:
busparams=0.20.0, Intel(R) USB 3.1 eXtensible Host Controller - 1.10 (Microsoft)

This Microsoft hypervisor supports using KDNET in guest VMs.

c:\kdnet>
c:\kdnet>kdnet.exe 10.52.4.41 50000

Enabling network debugging on Intel(R) Ethernet Connection (7) I219-V.

To debug this machine, run the following command on your debugger host machine.
windbg -k net:port=50000,key=3s1m4bjm7ihi7.3b8dig9hl019g.2fyvva9v1ie3a.38mfaw4eweiuo

Then reboot this machine by running shutdown -r -t 0 from this command prompt.

c:\kdnet>ping 10.52.4.41

Pinging 10.52.4.41 with 32 bytes of data:
Reply from 10.52.4.41: bytes=32 time=4ms TTL=128
Reply from 10.52.4.41: bytes=32 time=1ms TTL=128
Reply from 10.52.4.41: bytes=32 time=1ms TTL=128
Reply from 10.52.4.41: bytes=32 time=1ms TTL=128

Ping statistics for 10.52.4.41:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 4ms, Average = 1ms

Host PC配置

阅读全文 »