系统内存--读代码

STM32L471内部flash如图page0----page255  

一共256页每页2K 一共是512K的内存

选择最后的几个页 放置信息:

syscfg.h

#define     DSYS_ABTAG_ADDR      0x0807E000//page252我自己设计的 放置安装工发过来的地址信息
#define     DSYS_CFG_ADDR           0x0807E800//page253放置
#define     DSYS_INFO_ADDR          0x0807F000//page254放置

+++++++++++++++++++++++

顶层:freertos.c    
    第一步sys_info_init();            //系统基础信息初始化
    看函数:
    void sys_info_init( void )
{
读全局变量info:
    失败:
    if( sys_info_read(&info) == FALSE) //也就是读页!(chip_flash_read( DSYS_INFO_ADDR , (uint8_t *)data , sizeof(SystemInfoType) ));
    {
        log(DEBUG,"FLASE读取失败,重启\n");
        soft_system_resert(__func__);
    }
    
    校验失败:
    calcCrc =  crc16_ccitt((uint8_t *)&info , sizeof(SystemInfoType));  
    if( crc != calcCrc)
    {
        log(WARN,"读取INFO文件错误,复位重新读取,get crc = %d  ,calc crc = %d\n" , crc , calcCrc);
        sysInfo_set_default();
        soft_system_resert(__func__);
    }
}

所以第一次上电应该是:sysInfo_set_default();  以后设备出厂以后自己维护了。

回答:复位做了什么?
1蓝牙密码复位了
2小区地址信息清空了
3载入设备信息
所以没有搞到黑白名单

-DDEFAULT_PAIR_PWD="{0X12,0x34,0x56}"
-DDEFAULT_OPEN_PWD="{0X12,0x34,0x56}
void sysInfo_set_default( void )
{
    memset((uint8_t *)&info , 0x00 , sizeof(SystemInfoType)); 
    memcpy(info.user_pwd , bleDeafultUserPwd , BLE_PASSWORD_LENGTH);
    memcpy(info.pair_pwd , bleDeafultPairPwd , BLE_PASSWORD_LENGTH);  
    
    log(INFO,"清空设备小区,楼栋,单元ID\n");
    memset(&info.commun , 0x00 , sizeof(SystemCommunitiesType));
    memset(&info.fkcommun , 0x00 , sizeof(SystemFKCommunitiesType));
    
    sys_info_read_device_module();    
    sysInfo_save();
}

void sys_info_read_device_module( void )
{
    读板子拿到GPRS WIFI ETH BM77 ST25 等等
    log(DEBUG,"设备运行模式=%d .\n" , info.runModule);
}
    
void sysInfo_save( void )
{
就是把自己维护的保存起来。
    sys_info_clear();
    
    info.crc = 0;

    info.crc =  crc16_ccitt((uint8_t *)&info , sizeof(SystemInfoType));

    sys_info_write(&info);
}

下面就是info
typedef struct
{
    uint8_t                 pair_pwd[BLE_PASSWORD_LENGTH];
    uint8_t                 user_pwd[BLE_PASSWORD_LENGTH];
    SystemCommunitiesType   commun;
    SystemFKCommunitiesType fkcommun; 
    uint32_t                 runModule;
    uint16_t                crc;
}SystemInfoType;

static SystemInfoType     info;

++++++++++++++++++++++++++++

猜你喜欢

转载自blog.csdn.net/weixin_42381351/article/details/83006818