ThinkNotes

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

0%

飞腾派Linux调试环境:串口调试,交叉编译,uboot配置

串口调试环境

串口硬件连接

串口线的颜色和功能是对应的,4根线如下:

1
2
3
4
5
功能    	   线的颜色
TX 绿色
RX 白色
GND 黑色
VCC 红色

串口的接口类型取决于开发板接口,飞腾Pi是使用USB转TTL接口,有的开发板是板载串口转USB芯片,外部是USB直连PC,还有的是RS232接口。不管接口类型如何,串口转接芯片一般是CH340/FT232。

image-20240424142615021

飞腾派接线只用了3根线,没用VCC。注意RX是接到TX, TX是接到RX。

image-20240424142831480

验证串口连接正常:查找到ttyUSB设备即USB转串口设备连接正常。

阅读全文 »

如何使用CubeMX生成STM32代码

示例:

STM32F0的firmware工程文件.ioc用CubeMX打开,如下:

image-20240529202815926

现在要移植一些外设配置到STM32F4,使用UART2为示例:

1.对照F0的工程界面,打开F4的工程界面,搜索要配置的Pin,设置Pin模式和F0一致,为UART2_TX

image-202405292030133902.对照F0的工程界面,打开F4的工程界面,配置UART2_TX的详细工作模式,例如波特率,中断…

image-20240529203142664

3.配置完毕后,点generate code生成代码

4.理解代码和工程配置的对应关系:

阅读全文 »

Keil ARM配置笔记

Keil community版本

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

Keil community安装ARM compiler v5

Keil community 5.37默认只包含ARM compile v6,编译v5的项目通常会报错(报错通常和v6要求C99相关),可以有两种方式解决:

(1)基于v6报错,更新代码,符合v6的规则要求

(2)安装v5 compiler,适配原项目

如何在Keil community >= 5.37版本上安装ARM compiler v5:

参考:https://community.arm.com/support-forums/f/keil-forum/52719/how-can-i-install-compiler-version-5-for-keil-vision-5

1.下载ARM compiler v5

阅读全文 »

本文记录用LeCroy PCIe协议分析仪debug SD host controller issue的方法。具体背景是该issue使用windbg或者打开driver debug log后无法复现,只能用PCIe协议分析仪分析。

PCIe包解析的配置

使用spread view模式:

image-20231122144912104

数据解析方式使用小端(Little-endian)+ MSB(高bit解析)

寻找目标PCIe设备

本文的PCIe设备为SD host controller。

以下PCIe trace包含一次Memory read和Config read操作,以Memory read为例,一次通信流程是:

MRd 指定Address -> MRd ACK -> CpID包含设备返回的数据(98601217)-> CpID的ACK

image-20231122144334835

阅读全文 »

pip install换源

pip install,有的包一直timeout无法安装

1
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out

解决办法参考:https://www.runoob.com/w3cnote/pip-cn-mirror.html

单次换源

使用 -i 指定国内源

1
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple 

常用国内源:

1
2
3
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple
豆瓣:http://pypi.douban.com/simple

设为默认

阅读全文 »

多种代码可视化分析工具What are the best code visualization and analysis tools?

Sourcetrail

官方文档:Sourcetrail/getting-started

使用方式:

(1) Linux kernel生成代码调用图

需要用bear编译kernel生成compile_commands.json作为索引数据库

1
bear -- make -j4

sourcetrail导入compile_commands.json之后即可索引源码,生成调用链图

Screenshot from 2023-09-18 16-19-29

(2) C++项目生成代码调用图

阅读全文 »

linux驱动 – PCI访问硬件分析与SD express调试记录

系统侧调试PCI设备

PCI tree结构

关于PCIe tree的bus/device的详细architecture,参考LDD3和Mastering Linux Device Driver Development - John Madieu

image-20230829111444515

image-20230829111727760

Root complex (RC): This refers to the PCIe host controller in the SoC. It can access the main memory without CPU intervening, which is a feature used by other devices to access the main memory. They are also known as Host-to-PCI bridges.

Bridges: These provide an interface to other buses, such as PCI or PCI X, or even another PCIe bus. A bridge can also provide an interface to the same bus

Endpoint (EP): Endpoints are PCIe devices, and are represented by type 00h configuration space headers. They never appear on a switch’s internal bus and have no downstream port

lspci使用示例

下面介绍如何找到一个PCI(e)设备的信息,及其上游端口信息,以及设备的register space内容

(1)查看所有pci设备:

阅读全文 »

设置sudo

普通用户(以username为例)并没有被加入sudo用户组,不能使用sudo命令

1
2
username@debian:~$ sudo apt install xxx
username is not in the sudoers file.

有两种方式:

  1. 在su下用visudo(nano也可以)编辑/etc/sudoers文件,新增username使sudo能获取root权限。

    1
    2
    3
    # User privilege specification
    root ALL=(ALL:ALL) ALL
    username ALL=(ALL:ALL) ALL
  2. 在su下用usermod -aG sudo username,将username添加到sudo组,由于/etc/sudoers的如下设置已经将sudo组设为root权限,所以这个操作等效于使username能用sudo获取root权限。

    1
    %sudo ALL=(ALL:ALL) ALL
  • sbin的命令not found问题:执行visudo或usermod时,发现command not found. Debug过程如下:

​ 使用whereis visudo查看路径是/usr/sbin;echo $PATH没有/usr/sbin,因此是环境变量问题。

方式一:在username的~/.bashrc下添加sbin到PATH,生效之后sbin目录的命 令才可执行:

1
2
3
4
nano .bashrc
export PATH=$PATH:/usr/sbin
source ~/.bashrc
echo $PATH

方式二:另外一种方式是加软链接,需要一个个添加

阅读全文 »

Linux驱动常用调试技术

Printk详解

printk参考Kernel document: 使用printk记录消息

其中printk是一组4个值,分别是:current, default, minimumboot-time-default. 调试打印一般只配置current和boot-time-default = 7 (支持< pr_debug的打印)或者8 (支持= pr_debug的打印).

printk的基础用法

常用示例如下,一般是手动添加打印代码时使用:

1
2
step1: 例如要打印当前函数被调用,添加pr_info("%s\n", __FUNCTION__)
step2: echo 7 > /proc/sys/kernel/printk

Tips1: 非root用户不能成功执行sudo echo 7 > /proc/sys/kernel/printk,显示permission denied

原因:因为sudo仅让echo按root权限执行,没有让>按root权限执行

解决办法一:sudo su进入root用户

阅读全文 »