文章目录
- arch/arm/include/debug/stm32.S
-
- [addruart 添加debug串口地址](#addruart 添加debug串口地址)
-
- [CONFIG_DEBUG_UART_PHYS 和 CONFIG_DEBUG_UART_VIRT](#CONFIG_DEBUG_UART_PHYS 和 CONFIG_DEBUG_UART_VIRT)
- [waituarttxrdy 等待串口发送准备](#waituarttxrdy 等待串口发送准备)
- senduart
- [busyuart 等待串口发送完成](#busyuart 等待串口发送完成)
- [compressed/debug.S 通过串口打印信息](#compressed/debug.S 通过串口打印信息)
- arch/arm/kernel/debug.S
-
- [addruart_current 添加当前debug串口地址](#addruart_current 添加当前debug串口地址)
- printascii
https://github.com/wdfk-prog/linux-study

arch/arm/include/debug/stm32.S
addruart 添加debug串口地址
asm
复制代码
.macro addruart, rp, rv, tmp
ldr \rp, =CONFIG_DEBUG_UART_PHYS @ physical base
ldr \rv, =CONFIG_DEBUG_UART_VIRT @ virt base
.endm
CONFIG_DEBUG_UART_PHYS 和 CONFIG_DEBUG_UART_VIRT
c
复制代码
//arch/arm/Kconfig.debug
config DEBUG_UART_VIRT
default DEBUG_UART_PHYS if !MMU
config DEBUG_UART_PHYS
default 0x40011000 if STM32F4_DEBUG_UART || STM32F7_DEBUG_UART || \
STM32H7_DEBUG_UART
config STM32H7_DEBUG_UART
bool "Use STM32H7 UART for low-level debug"
depends on MACH_STM32H743
select DEBUG_STM32_UART
help
如果需要内核低级调试支持,请在此处说 Y
在基于 STM32H7 的平台上,默认 UART 连接
USART1 的 UART 实例,但可以通过修改
CONFIG_DEBUG_UART_PHYS。
waituarttxrdy 等待串口发送准备
asm
复制代码
// while(TXE ==1);
.macro waituarttxrdy,rd,rx
1001: ldr \rd, [\rx, #(STM32_USART_SR_OFF)] @ Read Status Register
tst \rd, #STM32_USART_TXE @ TXE = 1 = tx empty
beq 1001b
.endm
senduart
asm
复制代码
.macro senduart,rd,rx
strb \rd, [\rx, #STM32_USART_TDR_OFF]
.endm
busyuart 等待串口发送完成
asm
复制代码
// while(TC == 1);
.macro busyuart,rd,rx
1001: ldr \rd, [\rx, #(STM32_USART_SR_OFF)] @ Read Status Register
tst \rd, #STM32_USART_TC @ TC = 1 = tx complete
beq 1001b
.endm
compressed/debug.S 通过串口打印信息
asm
复制代码
//使用仿真器调试
#ifndef CONFIG_DEBUG_SEMIHOSTING
#include CONFIG_DEBUG_LL_INCLUDE
ENTRY(putc)
addruart r1, r2, r3
#ifdef CONFIG_DEBUG_UART_FLOW_CONTROL
waituartcts r3, r1
#endif
waituarttxrdy r3, r1
senduart r0, r1
busyuart r3, r1
mov pc, lr
ENDPROC(putc)
#else
#endif
arch/arm/kernel/debug.S
addruart_current 添加当前debug串口地址
asm
复制代码
.macro addruart_current, rx, tmp1, tmp2
addruart \rx, \tmp1, \tmp2
.endm
printascii
asm
复制代码
ENTRY(printascii)
//添加debug串口寄存器地址
addruart_current r3, r1, r2
//检查寄存器 r0 是否为 0,r0 通常存储字符串的起始地址。如果为 0,表示字符串为空
1: teq r0, #0
// r0 不为 0 的情况下,从地址 r0 加载一个字节到寄存器 r1,并将 r0 自增 1
ldrbne r1, [r0], #1
//检查加载的字节是否为字符串的结束符(\0)
teqne r1, #0
//如果当前字符是结束符,返回到调用者
reteq lr
//处理换行符
2: teq r1, #'\n' //检查当前字符是否是换行符(\n)
bne 3f //如果不是换行符,跳转到标签 3
mov r1, #'\r' //如果是换行符,将其替换为回车符(\r),并通过 UART 发送。
#ifdef CONFIG_DEBUG_UART_FLOW_CONTROL
waituartcts r2, r3
#endif
waituarttxrdy r2, r3
senduart r1, r3
busyuart r2, r3
mov r1, #'\n' //将换行符(\n)加载到 r1,准备发送
//发送其他字符
3:
#ifdef CONFIG_DEBUG_UART_FLOW_CONTROL
waituartcts r2, r3
#endif
waituarttxrdy r2, r3
senduart r1, r3
busyuart r2, r3
b 1b
ENDPROC(printascii)