T5D68 000:004.749 SEGGER J-Link V6.86a Log File
T5D68 000:004.849 DLL Compiled: Sep 28 2020 15:02:50
T5D68 000:004.857 Logging started @ 2024-03-13 08:00
T5D68 000:004.865 - 4.869ms
T5D68 000:004.878 JLINK_SetWarnOutHandler(...)
T5D68 000:004.886 - 0.012ms
T5D68 000:004.895 JLINK_OpenEx(...)
T5D68 000:005.972 Firmware: J-Link V11 compiled Sep 21 2020 17:00:29
T5D68 000:006.105 Decompressing FW timestamp took 100 us
T5D68 000:008.472 Hardware: V11.00
T5D68 000:008.489 S/N: 50120677
T5D68 000:008.500 OEM: SEGGER
T5D68 000:008.511 Feature(s): GDB, JFlash, FlashDL, RDI, FlashBP
T5D68 000:009.899 TELNET listener socket opened on port 19021
T5D68 000:009.958 WEBSRV Starting webserver
T5D68 000:010.036 WEBSRV Webserver running on local port 19080
T5D68 000:010.049 - 5.158ms returns "O.K."
T5D68 000:010.062 JLINK_GetEmuCaps()
T5D68 000:010.070 - 0.011ms returns 0xB9FF7BBF
T5D68 000:010.081 JLINK_TIF_GetAvailable(...)
T5D68 000:010.151 - 0.075ms
T5D68 000:010.163 JLINK_SetErrorOutHandler(...)
T5D68 000:010.170 - 0.011ms
T5D68 000:010.192 JLINK_ExecCommand("ProjectFile = "M:\STM32\F4\HAL_Demo\UART_TEST\Uart_demo\MDK-ARM\JLinkSettings.ini"", ...).
T5D68 000:015.221 Ref file found at: D:\Keil_v5\ARM\Segger\JLinkDevices.ref
T5D68 000:015.387 XML referenced by ref file: C:\Program Files (x86)\SEGGER\JLink\JLinkDevices.xml
T5D68 000:016.002 C:\Program Files (x86)\SEGGER\JLink\JLinkDevices.xml evaluated successfully.
T5D68 000:098.165 - 87.986ms returns 0x00
T5D68 000:103.023 JLINK_ExecCommand("Device = STM32F407ZGTx", ...).
T5D68 000:107.057 Device "STM32F407ZG" selected.
T5D68 000:107.336 - 4.303ms returns 0x00
T5D68 000:107.354 JLINK_GetHardwareVersion()
T5D68 000:107.362 - 0.012ms returns 110000
T5D68 000:107.377 JLINK_GetDLLVersion()
T5D68 000:107.385 - 0.011ms returns 68601
T5D68 000:107.393 JLINK_GetOEMString(...)
T5D68 000:107.402 JLINK_GetFirmwareString(...)
T5D68 000:107.410 - 0.011ms
T5D68 000:119.012 JLINK_GetDLLVersion()
T5D68 000:119.026 - 0.018ms returns 68601
T5D68 000:119.036 JLINK_GetCompileDateTime()
T5D68 000:119.043 - 0.011ms
T5D68 000:122.766 JLINK_GetFirmwareString(...)
T5D68 000:122.780 - 0.018ms
T5D68 000:126.498 JLINK_GetHardwareVersion()
T5D68 000:126.512 - 0.018ms returns 110000
T5D68 000:130.399 JLINK_GetSN()
T5D68 000:130.413 - 0.018ms returns 50120677
T5D68 000:134.367 JLINK_GetOEMString(...)
T5D68 000:142.328 JLINK_TIF_Select(JLINKARM_TIF_JTAG)
T5D68 000:143.219 - 0.898ms returns 0x00
T5D68 000:143.233 JLINK_HasError()
T5D68 000:143.250 JLINK_SetSpeed(5000)
T5D68 000:143.357 - 0.113ms
T5D68 000:143.369 JLINK_GetIdData(pIdData)
T5D68 000:148.815 TotalIRLen = 9, IRPrint = 0x0011
T5D68 000:152.920 JTAG chain detection found 2 devices:
T5D68 000:156.723 #0 Id: 0x4BA00477, IRLen: 04, CoreSight JTAG-DP
T5D68 000:160.364 #1 Id: 0x06413041, IRLen: 05, STM32 Boundary Scan
T5D68 000:172.466 TotalIRLen = 9, IRPrint = 0x0011
T5D68 000:176.459 JTAG chain detection found 2 devices:
T5D68 000:180.802 #0 Id: 0x4BA00477, IRLen: 04, CoreSight JTAG-DP
T5D68 000:184.850 #1 Id: 0x06413041, IRLen: 05, STM32 Boundary Scan
T5D68 000:189.380 Cannot determine DP version. Assuming DPv0
T5D68 000:193.258 Scanning AP map to find all available APs
T5D68 000:197.381 AP[1]: Stopped AP scan as end of AP map has been reached
T5D68 000:201.092 AP[0]: AHB-AP (IDR: 0x24770011)
T5D68 000:204.676 Iterating through AP map to find AHB-AP to use
T5D68 000:208.835 AP[0]: Core found
T5D68 000:212.734 AP[0]: AHB-AP ROM base: 0xE00FF000
T5D68 000:216.707 CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
T5D68 000:221.038 Found Cortex-M4 r0p1, Little endian.
T5D68 000:221.348 -- Max. mem block: 0x000045B0
T5D68 000:221.373 CPU_ReadMem(4 bytes @ 0xE000EDF0)
T5D68 000:222.338 CPU_ReadMem(4 bytes @ 0xE0002000)
T5D68 000:227.045 FPUnit: 6 code (BP) slots and 2 literal slots
T5D68 000:227.065 CPU_ReadMem(4 bytes @ 0xE000EDFC)
T5D68 000:227.285 CPU_WriteMem(4 bytes @ 0xE000EDFC)
T5D68 000:227.470 CPU_ReadMem(4 bytes @ 0xE0001000)
T5D68 000:227.730 CPU_WriteMem(4 bytes @ 0xE0001000)
T5D68 000:227.953 CPU_ReadMem(4 bytes @ 0xE000ED88)
T5D68 000:228.230 CPU_WriteMem(4 bytes @ 0xE000ED88)
T5D68 000:228.452 CPU_ReadMem(4 bytes @ 0xE000ED88)
T5D68 000:228.730 CPU_WriteMem(4 bytes @ 0xE000ED88)
T5D68 000:232.910 CoreSight components:
T5D68 000:236.600 ROMTbl[0] @ E00FF000
T5D68 000:236.619 CPU_ReadMem(64 bytes @ 0xE00FF000)
T5D68 000:237.021 CPU_ReadMem(32 bytes @ 0xE000EFE0)
T5D68 000:241.472 ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
T5D68 000:241.494 CPU_ReadMem(32 bytes @ 0xE0001FE0)
T5D68 000:245.873 ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
T5D68 000:245.897 CPU_ReadMem(32 bytes @ 0xE0002FE0)
T5D68 000:249.833 ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
T5D68 000:249.852 CPU_ReadMem(32 bytes @ 0xE0000FE0)
T5D68 000:253.857 ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
T5D68 000:253.876 CPU_ReadMem(32 bytes @ 0xE0040FE0)
T5D68 000:258.162 ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
T5D68 000:258.180 CPU_ReadMem(32 bytes @ 0xE0041FE0)
T5D68 000:262.277 ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
T5D68 000:262.321 pIdData->ScanLen=9
T5D68 000:262.334
T5D68 000:262.341 pIdData->NumDevices=2
T5D68 000:262.352
T5D68 000:262.360 pIdData->aId[0]=0x4BA00477
T5D68 000:262.370
T5D68 000:262.378 pIdData->aIrRead[0]=0
T5D68 000:262.388
T5D68 000:262.395 pIdData->aScanLen[0]=0
T5D68 000:262.406
T5D68 000:262.413 pIdData->aScanRead[0]=0
T5D68 000:262.424
T5D68 000:262.432 - 119.066ms
T5D68 000:262.445 JLINK_JTAG_GetDeviceID(DeviceIndex = 0)
T5D68 000:262.454 - 0.013ms returns 1268778103
T5D68 000:262.490 JLINK_JTAG_GetDeviceInfo(DeviceIndex = 0)
T5D68 000:262.499 - 0.013ms returns 0
T5D68 000:262.508 JLINK_JTAG_GetDeviceID(DeviceIndex = 1)
T5D68 000:262.515 - 0.011ms returns 104935489
T5D68 000:262.524 JLINK_JTAG_GetDeviceInfo(DeviceIndex = 1)
T5D68 000:262.531 - 0.011ms returns 0
T5D68 000:262.541 JLINK_GetDLLVersion()
T5D68 000:262.548 - 0.011ms returns 68601
T5D68 000:262.557 JLINK_CORE_GetFound()
T5D68 000:262.564 - 0.011ms returns 0xE0000FF
T5D68 000:262.573 JLINK_GetDebugInfo(0x100 = JLINKARM_ROM_TABLE_ADDR_INDEX)
T5D68 000:262.582 Value=0xE00FF000
T5D68 000:262.592 - 0.023ms returns 0
T5D68 000:266.400 JLINK_GetDebugInfo(0x100 = JLINKARM_ROM_TABLE_ADDR_INDEX)
T5D68 000:266.415 Value=0xE00FF000
T5D68 000:266.426 - 0.030ms returns 0
T5D68 000:266.435 JLINK_GetDebugInfo(0x101 = JLINKARM_DEBUG_INFO_ETM_ADDR_INDEX)
T5D68 000:266.443 Value=0xE0041000
T5D68 000:266.453 - 0.022ms returns 0
T5D68 000:266.468 JLINK_ReadMemEx(0xE0041FD0, 0x20 Bytes, Flags = 0x02000004)
T5D68 000:266.495 CPU_ReadMem(32 bytes @ 0xE0041FD0)
T5D68 000:266.817 Data: 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...
T5D68 000:266.830 - 0.366ms returns 32 (0x20)
T5D68 000:266.840 JLINK_GetDebugInfo(0x102 = JLINKARM_DEBUG_INFO_MTB_ADDR_INDEX)
T5D68 000:266.848 Value=0x00000000
T5D68 000:266.859 - 0.022ms returns 0
T5D68 000:266.867 JLINK_GetDebugInfo(0x103 = JLINKARM_DEBUG_INFO_TPIU_ADDR_INDEX)
T5D68 000:266.875 Value=0xE0040000
T5D68 000:266.886 - 0.022ms returns 0
T5D68 000:266.894 JLINK_GetDebugInfo(0x104 = JLINKARM_DEBUG_INFO_ITM_ADDR_INDEX)
T5D68 000:266.901 Value=0xE0000000
T5D68 000:266.912 - 0.022ms returns 0
T5D68 000:266.920 JLINK_GetDebugInfo(0x105 = JLINKARM_DEBUG_INFO_DWT_ADDR_INDEX)
T5D68 000:266.928 Value=0xE0001000
T5D68 000:266.939 - 0.021ms returns 0
T5D68 000:266.947 JLINK_GetDebugInfo(0x106 = JLINKARM_DEBUG_INFO_FPB_ADDR_INDEX)
T5D68 000:266.954 Value=0xE0002000
T5D68 000:266.965 - 0.021ms returns 0
T5D68 000:266.973 JLINK_GetDebugInfo(0x107 = JLINKARM_DEBUG_INFO_NVIC_ADDR_INDEX)
T5D68 000:266.981 Value=0x
HM STM32F407 HAL库 printf 重定向到串口1
需积分: 0 192 浏览量
更新于2024-03-15
1
收藏 7.39MB RAR 举报
在嵌入式开发领域,STM32F407是一款广泛应用的微控制器,以其高性能、低功耗的特点受到青睐。HAL库(Hardware Abstraction Layer,硬件抽象层)是ST公司提供的一个高级API库,用于简化STM32的编程,使得开发者能够更高效地利用其丰富的功能。本教程将详细讲解如何在STM32F407上使用HAL库将`printf`函数的输出重定向到串口1,以便通过UART(通用异步收发传输器)进行调试或通信。
我们需要了解`printf`函数。`printf`是C语言中的一个标准输出函数,通常用于向控制台输出格式化的文本。在嵌入式系统中,没有标准控制台,因此我们需要将它的输出重定向到一个可用的硬件接口,如串口。
在STM32中,串口1(USART1)是一个常用的通信接口,可以实现与PC或其他设备的数据交换。配置串口1主要包括以下几个步骤:
1. **初始化HAL库**:在项目开始时,需要包含必要的HAL库头文件,并初始化HAL库。这通常在`main()`函数之前完成,通过调用`HAL_Init()`函数。
2. **配置系统时钟**:STM32F407的串口工作需要系统时钟支持,使用`SystemClock_Config()`函数设置适当的时钟源和分频因子。
3. **配置串口1**:使用`HAL_UART_Init()`函数初始化串口1。这包括设置波特率、数据位、停止位、校验位等参数。例如,可以这样定义:
```c
UART_HandleTypeDef huart1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK) {
// 错误处理
}
```
4. **重定向`printf`**:要将`printf`输出重定向到串口1,我们需要替换默认的`stdio`流。这通常涉及以下步骤:
- 包含`<stdio.h>`和`<stdarg.h>`头文件。
- 定义自定义的`putchar`函数,该函数将字符发送到串口1。
- 使用`_setvbuf`函数关闭标准输出的缓冲区,因为串口通常是无缓冲的。
- 使用`freopen`函数将`stdout`和`stderr`重定向到`putchar`函数。
示例代码如下:
```c
int my_putchar(char c, FILE *stream) {
if (c == '\n') {
HAL_UART_Transmit(&huart1, (uint8_t*)"\\r\\n", 3, HAL_MAX_DELAY);
} else {
HAL_UART_Transmit(&huart1, (uint8_t*)&c, 1, HAL_MAX_DELAY);
}
return c;
}
int main(void) {
// 初始化和配置串口1...
_setvbuf(stdout, NULL, _IONBF, 0); // 关闭标准输出的缓冲
_setvbuf(stderr, NULL, _IONBF, 0); // 关闭标准错误的缓冲
freopen("NUL", "w", stdout); // Windows
// 或者
freopen("/dev/null", "w", stdout); // Linux/MacOS
stdout = stderr = (FILE*)my_putchar; // 重定向printf输出
// 正常的程序逻辑...
}
```
5. **UART测试**:在项目中,你可以创建一个名为`UART_TEST`的文件或函数,用于测试串口1的通信。例如,你可以使用`printf`发送一些字符串和变量值,然后在串口终端查看输出结果,确认重定向是否成功。
以上就是使用STM32F407 HAL库将`printf`重定向到串口1的基本过程。通过这个方法,你可以方便地在嵌入式系统中进行调试,将运行时信息实时传送到PC或其他设备,从而提升开发效率。在实际应用中,可能还需要考虑中断处理、多线程环境下的同步问题以及错误处理等复杂情况,确保串口通信的稳定性和可靠性。
HarmonyCat
- 粉丝: 180
- 资源: 15
最新资源
- 自动化应用驱动的容器弹性管理平台解决方案
- 各种排序算法 Python 实现的源代码
- BlurAdmin 是一款使用 AngularJs + Bootstrap实现的单页管理端模版,视觉冲击极强的管理后台,各种动画效果
- 基于JSP+Servlet的网上书店系统源代码项目包含全套技术资料.zip
- GGJGJGJGGDGGDGG
- 基于SpringBoot的毕业设计选题系统源代码项目包含全套技术资料.zip
- Springboot + mybatis-plus + layui 实现的博客系统源代码全套技术资料.zip
- 智慧农场小程序源代码全套技术资料.zip
- 大数据技术毕业设计源代码全套技术资料.zip
- renren-ui-nodejs安装及环境配置