[Linux]学习笔记系列 -- [arm][debug]

文章目录

  • 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)
相关推荐
阿里云大数据AI技术1 天前
阿里云 EMR AI 助手正式发布:从问答工具到全栈智能运维助手
运维·人工智能
orion572 天前
Missing Semester Class1:course overview and introduction of shell
linux
SkyWalking中文站2 天前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户120487221612 天前
Linux驱动编译与加载
linux·嵌入式
火车叼位2 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
用户805533698032 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698032 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
小猿姐3 天前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
七歌杜金房3 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
SkyWalking中文站3 天前
认识 Horizon UI · 5/17:3D 基础设施地图
运维·监控·自动化运维