Cmake笔记

最简单的,只有一个源文件的 CMakeList.txt: cmake_minimum_required (VERSION 2.8) project (learn_cmake) add_executable(hello hello.cpp) $ mkdir build $ cd build/ $ cmake .. $ make 定义变量 set(SRC_LIST 1.c 2.c 3.c) add_executable(app ${SRC_LIST}) 通过EXECUTABLE_PUTPUT_PATH可以指定输出路径: set(HOME /home/xyc) set(EXECUTABLE_OUTPUT_PATH ${HOME}/bin) 搜索文件 方式 1:aux_source_directory 方式 2:file file(GLOB/GLOB_RECURSE 变量名 要搜索的文件路径和文件类型) file(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) GLOB: 将指定目录下搜索到的满足条件的所有文件名生成一个列表,并将其存储到变量中。 GLOB_RECURSE:递归搜索指定目录,将搜索到的满足条件的文件名生成一个列表,并将其存储到变量中。 包含头文件 include_directories(path) 动态库/静态库 制作静态库 add_library(库名称 STATIC 源文件1 [源文件2] ...) # 指定静态库输出路径 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) 制作动态库 add_library(库名称 SHARED 源文件1 [源文件2] ...) # 指定动态库输出路径 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) # 动态库默认是有执行权限的,可以通过这种方式。 链接静态库 # 指明库路径 link_directories(${PROJECT_SOURCE_DIR}/lib) # 链接库 link_libraries(calc) # 可以是全名libxxx....

2024-08-12 · 1 min

USB_Reset_Suspend_Resume

Reset 整个reset过程,host需要拉低D+的时间\(T_{DRST}\) 至少 > 10ms。 High-speed capable hubs and devices在reset过程中还会执行一套reset protocol: Hub确认接的设备不是Low-speed, 如果是low-speed,不会有下面的reset握手协议。 Hub把D+拉低,进入SE0状态。 Device检测到SE0: 如果device是从suspend状态进入reset,那么device在不少于2.5us后进行high-speed detection handshake。 如果device是从non-suspend full-speed状态进入reset,那么device需要在2.5us~3ms之间进入handshake。 如果device是从non-suspend high-speed状态进入reset,那么device必须在3ms~3.125ms之间恢复full-spped,通过断开高速终端电阻以及重新接上D+的上拉电阻。接着在100us-875us内开始检测SE0状态,进入handshake。 Device往D-灌电流,形成一个800mv左右的ChripK信号, 该信号保持1~7ms。 Hub检测到ChripK信号后,100us内需要发送三对KJ(k-J-K-J-K-J)。每个单独的J或K都要保持40~60us。KJ对打完之后,在500us内断开D+上拉电阻,使能高速终端电阻,进入高速状态。 Suspend Device有两种进入suspend的方式: 如果连续3帧没有收到SOF包(1ms一帧),device会进入suspend状态。 host driver发送SET_PORT_FEATURE(PORT_SUSPEND)给hub,hub再发送给指定的device。 Resume 从suspend状态resume起来需要保持ChripK状态20ms以上,也有两种方式: Device remote wakeup,device drive K-state 1~15ms。Hub会在1ms内,接管D+, D-,继续产生resume信号直到20ms。 host发送CLEAR_PORT_FEATURE( PORT_SUSPSEND)给hub,hub drive K-state 20ms。 Reference Reset, Suspend, and Resume Commands USB全速设备的挂起、唤醒Resume USB2.0设备从全速模式到高速模式的识别过程及速率协商 USB spec 7.1.7.5~7.1.7.7, 11.9

2024-03-29 · 1 min

Vim, Tmux, and Vim plugins

Basic Command-line :e {name of file} open file for editing :ls show open buffers :help {topic} open help :help :w opens help for the :w command :help w opens help for the w movement Movement Movements in Vim are also called “nouns”. Basic movement: hjkl (left, down, up, right) Words: w (next word), b (beginning of word), e (end of word) Lines: 0 (beginning of line), ^ (first non-blank character), $ (end of line) Screen: H (top of screen), M (middle of screen), L (bottom of screen) Scroll: Ctrl-u (up), Ctrl-d (down) File: gg (beginning of file), G (end of file) Line numbers: :{number}<CR> or {number}G (line {number}) Misc: % (corresponding item) Find: f{character}, t{character}, F{character}, T{character} find/to forward/backward {character} on the current line , / ; for navigating matches Search: /{regex}, n / N for navigating matches Edits Vim’s editing commands are also called “verbs”...

2023-12-13 · 5 min

DFU(Device Firmware Upgrade)

2. Overview 四个阶段: Enumeration device告知host具备的能力。通过Run-Time Descriptor中增加的DFU class-interface descriptor和functional descriptor实现。 Reconfiguration host和device同意初始固件升级。host会发送一次USB reset,设备会exports DFU descriptors出来。 Transfer Manifestation device告知设备完成升级,host会再次发送USB reset, 重新枚举设备,运行新固件。 总体流程: 3. Requests bRequest分别从DFU_DETACH: 0 ~ DFU_ABORT: 6 4. Enumeration Phase 4.1 Run-Time Descriptor Set 支持DFU的设备,在run-time时需要额外增加两个描述符: A single DFU class interface descriptor A single functional descriptor 因此Configuration descriptor的bNumInterfaces域需要加1。 Run-time DFU Interface Descriptor DFU Functional Descriptor static void PrepareDFUFunDesc(DFUFunDesc_t *pDFUFunDesc) { pDFUFunDesc->bLength = sizeof(DFUFunDesc_t); pDFUFunDesc->bDescriptorType = 0x21; pDFUFunDesc->bmAttributes = g_DFUVar.bmAttributes; /// BIT0 | BIT1 | BIT2 | BIT3 pDFUFunDesc->wDetachTimeOut = 200; pDFUFunDesc->wTransferSize = g_DFUVar....

2023-08-15 · 2 min

linux usb driver

USB function driver f_loopback.c USB composite driver zero.c usb_composite_driver struct usb_composite_driver { const char *name; // "zero" const struct usb_device_descriptor *dev; // device_desc struct usb_gadget_strings **strings; // dev_strings enum usb_device_speed max_speed; // USB_SPEED_SUPER unsigned needs_serial:1; int (*bind)(struct usb_composite_dev *cdev); // zero_bind int (*unbind)(struct usb_composite_dev *); // zero_unbind void (*disconnect)(struct usb_composite_dev *); /* global suspend hooks */ void (*suspend)(struct usb_composite_dev *); // zero_suspend void (*resume)(struct usb_composite_dev *); // zero_resume struct usb_gadget_driver gadget_driver; // composite_driver_template }; 提供usb_configuration usb_device_descriptor...

2023-06-15 · 2 min

usb spec

Questions USB-IF Others USB标准名称变更: USB 1.0 -> USB 2.0 Low-Speed USB 1.1 -> USB 2.0 Full-Speed USB 2.0 -> USB 2.0 High-Speed USB 3.0 -> USB 3.1 Gen1 -> USB 3.2 Gen1 USB 3.1 -> USB 3.1 Gen2 -> USB 3.2 Gen2 × 1 USB 3.2 -> USB 3.2 Gen2 × 2 USB OTG中增加了一种MINI USB接头,使用5条线,比标准USB多一条身份识别线。 USB协议规定,设备在未配置前,可以从Vbus最多获取100mA电流,配置之后,最多可以获得500mA电流。Vbus是5V的电压。 枚举就是从设备读取各种描述符信息。 Control transfer:低速8字节,高速64字节,全速8/16/32/64字节。 Isochronous Transfer:全速1023字节,高速1024字节,低速不支持。 Interrupt Transfer:低速上限8字节,全速上限64字节,高速上限1024字节。 Bulk transfer:高速512字节,全速8/16/32/64字节,低速不支持。 Chapter3 Background USB 接口可用于连接多达 127 种外设。...

2023-06-15 · 3 min

GDB

Stepping step(s)/stepi(si) + <n>: 执行n行c/assembly 代码, 会跳进函数。 next(n)/nexti(ni) + <n>: 执行n行c/assembly 代码,不会跳进函数。 Running run/r: run code 直到遇到breakpoint。程序跑完接着run会restart程序。 continue/c: 继续执行。 finish: run code直到当前函数return。 advance <location>: run code直到指令到达。和设置breakpoint然后 Breakpoints break <location>: 设置断点,location可以是内存地址"*0x7c00"或者名称"mon_backtrace", "monitor.c:71" break <location> if <condition>: 只有condition满足的时候才会break。 cond <number> <condition>: 给某个断点增加condition。 Watchpoints watch <expression>: 表达式值发生改变时,会停止执行指令。 watch -l <address>: 内存地址的值发生改变时,会停止执行指令。 rwatch [-l] <expression>: 表达式值被read后,会停止执行指令。 Examining x: 打印内存的原始数据,x/x十六进制,x/i汇编。 print/p: 打印C expression。 x/s <内存地址>或p (char*)<内存地址>: 打印字符串。 p $rax: 打印某个寄存器值。 info registers: 打印所有寄存器。 info frame: 打印当前栈帧。...

2023-05-08 · 2 min

Buildroot

Notes ./lanuch 最终的操作是 cd sdk_3921/buildroot-dist # 进入buildroot目录 make BR2_EXTERNAL=sdk_3921/platform/ O=sdk3921/out/rts3923_fpga/ rts3923_fpga_defconfig local.mk # BR2_PACKAGE_OVERRIDE_FILE 在platform/configs中定义 external.mk include common.mk include package/*/*/*.mk include package/*/*.mk include package/*/*/src.mki include package/*/*/gen.mki include post_pkg.mk platform/local.mk: 指定自定义源码位置 在local.mk中还定义了: make rr: Reconstruct rootfs make rp: Rebuild external packages Managing the build and the configuration Out of tree build 在buildroot Makefile中有 ifeq ($(O),$(CURDIR)/output) CONFIG_DIR := $(CURDIR) NEED_WRAPPER = else CONFIG_DIR := $(O) NEED_WRAPPER = y endif 可以看出,如果O != buildroot_dist/output, CONFIG_DIR = sdk3921/out/rts3923_fpga/ 在CONFIG_DIR目录下,保存着....

2023-04-13 · 3 min

正则表达式

References RegexOne github正则表达式 需要转义的特殊字符: * . ? + $ ^ [ ] ( ) { } | \ / Tutorials Lesson 1 The 123s \d any single digit character \D any single non-digit character Lesson 2: The Dot . any single character \. period Lesson 3: Matching specific characters [abc] only a, b, c single character Lesson 4: Excluding specific characters [^abc] not a, b or c Lesson 5: Character ranges [a-z] characters a to z...

2023-01-12 · 2 min

Git 常用指令

GIT Git push # git push [远程主机名][本地分支名]:[远程分支名] $ git push origin HEAD:master # HEAD是当前指向的分支,可以用git show HEAD 查看 $ git show HEAD $ git branch -a # 需要code view 时要加/refs/for $ git push origin HEAD:refs/for/master # 不加远程分支名 $ git push origin dev # 相当于,如果远程分支不存在则会自动创建, 并创建联系 $ git push origin dev:dev $ git branch --set-upstream-to=origin/dev # 删除远程分支,直接推送空分支到远程分支 $ git push origin :dev git diff # 查看unstaged的改动(还没git add) $ git diff # 查看staged的改动(git add过的) $ git diff --staged # 显示出branch1和branch2中差异的部分 $ git diff branch1 branch2 --stat # 显示指定文件的详细差异 $ git diff branch1 branch2 具体文件路径 # 显示出所有有差异的文件的详细差异 $ git diff branch1 branch2 # 显示本地master分支与远程master分支的区别 $ git diff master origin/master # 比较两个commit git diff commit id1 commit id2 git log # 查看前两个commit的修改 $ git log -p -2 # 查看改动了哪些文件 $ git log --stat # 每个commit一行展示 $ git log --pretty=oneline # 展示合并历史 $ git log --graph # 从一定时间开始的commit $ git log --since=2....

2023-01-04 · 4 min