SMT32打印固件版本信息

    技术2022-07-16  70

    SMT32打印固件版本信息

    文章目录

    SMT32打印固件版本信息源码举例手动添加头文件absacc.h(选)测试结果总结宏定义__attribute__分析

    源码

    //----------------------------------------------------------------------------- //#include<absacc.h>//没用上,我的keil版本V5.27不需要 //------------------------------------------------------------------------------ #define VERINFO_ADDR_BASE (0x8009F00) // 版本信息在FLASH中的存放地址,自定义 const char Hardware_Ver[] __attribute__((at(VERINFO_ADDR_BASE + 0x00))) = "Hardware: 1.0.0"; const char Firmware_Ver[] __attribute__((at(VERINFO_ADDR_BASE + 0x20))) = "Firmware: 1.0.0"; const char Compiler_Date[] __attribute__((at(VERINFO_ADDR_BASE + 0x40))) = "Date: "__DATE__; const char Compiler_Time[] __attribute__((at(VERINFO_ADDR_BASE + 0x60))) = "Time: "__TIME__;

    举例

    法一

    printf("Hardware_Ver=%s\r\nFirmware_Ver=%s\r\nCompiler_Date=%s\r\n Compiler_Time=%s\r\n",Hardware_Ver,Firmware_Ver,Compiler_Date,Compiler_Time);

    法二

    unsigned char Verision_info[40]; /*...... */ sprintf(Verision_info,"Hardware_Ver=%s\r\nFirmware_Ver=%s\r\nCompiler_Date=%s\r\nCompiler_Time=%s\r\n",Hardware_Ver,Firmware_Ver,Compiler_Date,Compiler_Time);//格式化字符串 printf(Verision_info);//串口打印输出 LCD_ShowString( ....参数... , Verision_info)//显示屏输出

    手动添加头文件absacc.h(选)

    /* absacc.h: header file that allows absolute variable location at C level */ /* Copyright 2006-2007 ARM Limited. All rights reserved. */ /* version 1.01 */ #ifndef __at #define __at(_addr) __attribute__ ((at(_addr))) #endif #ifndef __section #define __section(_name) __attribute__ ((section(_name))) #endif

    测试结果

    debug页面

    实物调试

    总结

    宏定义

    __FILE__**:记录文件的路径加名称 __LINE__:记录文件已经被编译的行数 __DATE__:记录文件的编译日期 __TIME__:记录文件的编译时间

    __attribute__分析

    STM32学习笔记之__attribute__ ((at())绝对定位分析_一颗偏执的心-博客

    Processed: 0.008, SQL: 9