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];
}
}
网友评论