nrf51822 uicr

UICR: 用户信息配置寄存器(User Information ConfigurationRegisters)
UICR->CLENR0寄存器:很重要 CLENR0存放了Region0的大小,对于softdevice6.0需要设置为0×14000,对于softdevice 7.0要设置为0×15000。换句话说这个寄存器存放了用户APP的起始地址。(Region0存放softdevice,Region1存放APP、Bootloader)
UICR->RBCONF: read back protection,回读保护。保护的是region0的。
还有两个XTALFREQ寄存器和FWID寄存器不常用,见手册。

typedef struct {                                    /*!< UICR Structure                                                        */
    volatile uint32_t  CLENR0;                            /*!< Length of code region 0.                                              */
    volatile uint32_t  RBPCONF;                           /*!< Readback protection configuration.                                    */
    volatile uint32_t  XTALFREQ;                          /*!< Reset value for CLOCK XTALFREQ register.                              */
    volatile const  uint32_t  RESERVED0;
    volatile const  uint32_t  FWID;                              /*!< Firmware ID.                                                          */
    volatile uint32_t  BOOTLOADERADDR;                  /*!< Bootloader start address.  */    
    volatile uint32_t  NRFFW[14];                       /*!< Reserved for Nordic firmware design. */          
    volatile uint32_t  NRFHW[12];                         /*!< Reserved for Nordic hardware design.                                  */
    volatile uint32_t  CUSTOMER[32];                      /*!< Reserved for customer.                                                */
} m_uicr_type;

需要正片擦除才能写

static void write_uicr(uint32_t *address, uint32_t value)
{
    // Turn on flash write enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
    *address = value;
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
    // Turn off flash write enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
}


void app_write_uicr(uint8_t *datain,uint8_t len)
{
    uint8_t i;
    uint32_t buf[32];
    volatile uint32_t *p_addr = NULL;
    
    if (len>=32*4)
    {
        len = 32*4;
    }
    memset(buf,0xff,32*4);
    memcpy((uint8_t*)&buf[0],datain,len);

    p_addr = &(m_uicr->CUSTOMER[0]);
    
    for (i=0; i<32; i++)
    {
        write_uicr((uint32_t*)p_addr,buf[i]);
        p_addr++;
    }

}
void app_read_uicr(uint8_t *buf,uint16_t len)
{
    uint16_t i=0;
    const uint8_t *pdata=NULL;
    volatile uint32_t *p_addr32 = NULL;
    
    
    p_addr32 = &(m_uicr->CUSTOMER[0]);
    pdata=(uint8_t*)p_addr32;
    if (len>=32*4)
    {
        len = 32*4;
    }
    for(i=0; i<len; i++)
    {
        buf[i]=pdata[i];
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值