[Linux]学习笔记系列 -- [arm][debug]
文章目录
- arch/arm/include/debug/stm32.S
- addruart 添加debug串口地址
- CONFIG_DEBUG_UART_PHYS 和 CONFIG_DEBUG_UART_VIRT
- waituarttxrdy 等待串口发送准备
- senduart
- busyuart 等待串口发送完成
- compressed/debug.S 通过串口打印信息
- arch/arm/kernel/debug.S
- addruart_current 添加当前debug串口地址
- printascii
https://github.com/wdfk-prog/linux-study
arch/arm/include/debug/stm32.S
addruart 添加debug串口地址
.macro addruart, rp, rv, tmpldr \rp, =CONFIG_DEBUG_UART_PHYS @ physical baseldr \rv, =CONFIG_DEBUG_UART_VIRT @ virt base
.endm
CONFIG_DEBUG_UART_PHYS 和 CONFIG_DEBUG_UART_VIRT
//arch/arm/Kconfig.debug
config DEBUG_UART_VIRTdefault DEBUG_UART_PHYS if !MMU
config DEBUG_UART_PHYSdefault 0x40011000 if STM32F4_DEBUG_UART || STM32F7_DEBUG_UART || \STM32H7_DEBUG_UARTconfig STM32H7_DEBUG_UARTbool "Use STM32H7 UART for low-level debug"depends on MACH_STM32H743select DEBUG_STM32_UARThelp如果需要内核低级调试支持,请在此处说 Y在基于 STM32H7 的平台上,默认 UART 连接USART1 的 UART 实例,但可以通过修改CONFIG_DEBUG_UART_PHYS。
waituarttxrdy 等待串口发送准备
// while(TXE ==1);
.macro waituarttxrdy,rd,rx
1001: ldr \rd, [\rx, #(STM32_USART_SR_OFF)] @ Read Status Registertst \rd, #STM32_USART_TXE @ TXE = 1 = tx emptybeq 1001b
.endm
senduart
.macro senduart,rd,rxstrb \rd, [\rx, #STM32_USART_TDR_OFF]
.endm
busyuart 等待串口发送完成
// while(TC == 1);
.macro busyuart,rd,rx
1001: ldr \rd, [\rx, #(STM32_USART_SR_OFF)] @ Read Status Registertst \rd, #STM32_USART_TC @ TC = 1 = tx completebeq 1001b
.endm
compressed/debug.S 通过串口打印信息
//使用仿真器调试
#ifndef CONFIG_DEBUG_SEMIHOSTING#include CONFIG_DEBUG_LL_INCLUDEENTRY(putc)addruart r1, r2, r3
#ifdef CONFIG_DEBUG_UART_FLOW_CONTROLwaituartcts r3, r1
#endifwaituarttxrdy r3, r1senduart r0, r1busyuart r3, r1mov pc, lr
ENDPROC(putc)#else
#endif
arch/arm/kernel/debug.S
addruart_current 添加当前debug串口地址
.macro addruart_current, rx, tmp1, tmp2addruart \rx, \tmp1, \tmp2.endm
printascii
ENTRY(printascii)//添加debug串口寄存器地址addruart_current r3, r1, r2//检查寄存器 r0 是否为 0,r0 通常存储字符串的起始地址。如果为 0,表示字符串为空
1: teq r0, #0// r0 不为 0 的情况下,从地址 r0 加载一个字节到寄存器 r1,并将 r0 自增 1ldrbne r1, [r0], #1//检查加载的字节是否为字符串的结束符(\0)teqne r1, #0//如果当前字符是结束符,返回到调用者reteq lr
//处理换行符
2: teq r1, #'\n' //检查当前字符是否是换行符(\n)bne 3f //如果不是换行符,跳转到标签 3mov r1, #'\r' //如果是换行符,将其替换为回车符(\r),并通过 UART 发送。
#ifdef CONFIG_DEBUG_UART_FLOW_CONTROLwaituartcts r2, r3
#endifwaituarttxrdy r2, r3senduart r1, r3busyuart r2, r3mov r1, #'\n' //将换行符(\n)加载到 r1,准备发送
//发送其他字符
3:
#ifdef CONFIG_DEBUG_UART_FLOW_CONTROLwaituartcts r2, r3
#endifwaituarttxrdy r2, r3senduart r1, r3busyuart r2, r3b 1b
ENDPROC(printascii)