nordic 有提供非易失性寄存器
FICR 暂未了解。
主要了解UICR,全名 User information configuration。
程序中 UICR 的结构体和定义:
typedef struct { /*!< (@ 0x10001000) UICR Structure */
__IOM uint32_t UNUSED0; /*!< (@ 0x00000000) Unspecified */
__IOM uint32_t UNUSED1; /*!< (@ 0x00000004) Unspecified */
__IOM uint32_t UNUSED2; /*!< (@ 0x00000008) Unspecified */
__IM uint32_t RESERVED;
__IOM uint32_t UNUSED3; /*!< (@ 0x00000010) Unspecified */
__IOM uint32_t NRFFW[15]; /*!< (@ 0x00000014) Description collection[n]: Reserved for Nordic
firmware design */
__IOM uint32_t NRFHW[12]; /*!< (@ 0x00000050) Description collection[n]: Reserved for Nordic
hardware design */
__IOM uint32_t CUSTOMER[32]; /*!< (@ 0x00000080) Description collection[n]: Reserved for customer */
__IM uint32_t RESERVED1[64];
__IOM uint32_t PSELRESET[2]; /*!< (@ 0x00000200) Description collection[n]: Mapping of the nRESET
function */
__IOM uint32_t APPROTECT; /*!< (@ 0x00000208) Access port protection */
__IOM uint32_t NFCPINS; /*!< (@ 0x0000020C) Setting of pins dedicated to NFC functionality:
NFC antenna or GPIO */
__IOM uint32_t DEBUGCTRL; /*!< (@ 0x00000210) Processor debug control */
__IM uint32_t RESERVED2[60];
__IOM uint32_t REGOUT0; /*!< (@ 0x00000304) GPIO reference voltage / external output supply
voltage in high voltage mode */
} NRF_UICR_Type; /*!< Size = 776 (0x308) */
#define NRF_UICR ((NRF_UICR_Type*) NRF_UICR_BASE)
nordic 预留给我们使用的是成员 CUSTOMER。
更改 UICR 需要配合 NVMC 使用,擦除写入操作后需要复位程序,因为有一些系统配置是储存在这个结构体的,给我们使用的只有成员 CUSTOMER,复位后启动程序会检查重新写入系统配置。
程序中 NVMC 的结构体和定义:
typedef struct { /*!< (@ 0x4001E000) NVMC Structure */
__IM uint32_t RESERVED[256];
__IM uint32_t READY; /*!< (@ 0x00000400) Ready flag */
__IM uint32_t RESERVED1;
__IM uint32_t READYNEXT; /*!< (@ 0x00000408) Ready flag */
__IM uint32_t RESERVED2[62];
__IOM uint32_t CONFIG; /*!< (@ 0x00000504) Configuration register */
union {
__IOM uint32_t ERASEPAGE; /*!< (@ 0x00000508) Register for erasing a page in code area */
__IOM uint32_t ERASEPCR1; /*!< (@ 0x00000508) Deprecated register - Register for erasing a
page in code area. Equivalent to ERASEPAGE. */
};
__IOM uint32_t ERASEALL; /*!< (@ 0x0000050C) Register for erasing all non-volatile user memory */
__IOM uint32_t ERASEPCR0; /*!< (@ 0x00000510) Deprecated register - Register for erasing a
page in code area. Equivalent to ERASEPAGE. */
__IOM uint32_t ERASEUICR; /*!< (@ 0x00000514) Register for erasing user information configuration
registers */
__IOM uint32_t ERASEPAGEPARTIAL; /*!< (@ 0x00000518) Register for partial erase of a page in code
area */
__IOM uint32_t ERASEPAGEPARTIALCFG; /*!< (@ 0x0000051C) Register for partial erase configuration */
__IM uint32_t RESERVED3[8];
__IOM uint32_t ICACHECNF; /*!< (@ 0x00000540) I-code cache configuration register. */
__IM uint32_t RESERVED4;
__IOM uint32_t IHIT; /*!< (@ 0x00000548) I-code cache hit counter. */
__IOM uint32_t IMISS; /*!< (@ 0x0000054C) I-code cache miss counter. */
} NRF_NVMC_Type; /*!< Size = 1360 (0x550) */
#define NRF_NVMC ((NRF_NVMC_Type*) NRF_NVMC_BASE)
一个简单的擦除UICR操作:
NRF_NVMC->CONFIG = 2; //Erase enabled
while(NRF_NVMC->READY == 0)
{
}
NRF_NVMC->ERASEUICR = 1; //Start erase of UICR
while(NRF_NVMC->READY == 0)
{
}
NRF_NVMC->CONFIG = 0; //Read only access
while(NRF_NVMC->READY == 0)
{
}
//可写入新数据后复位
NVIC_SystemReset();
正常擦除UICR操作:
//开始使能
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
//开始擦除
NRF_NVMC->CONFIG = NVMC_ERASEUICR_ERASEUICR_Erase << NVMC_ERASEUICR_ERASEUICR_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
//恢复仅读
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
//可写入新数据后复位
NVIC_SystemReset();
NVMC的一些寄存器说明:
简单的写操作:
NRF_NVMC->CONFIG = 1; //write enabled
while(NRF_NVMC->READY == 0)
{
}
NRF_UICR->CUSTOMER[0] = 22;
while(NRF_NVMC->READY == 0)
{
}
NRF_NVMC->CONFIG = 0; //Read only access
while(NRF_NVMC->READY == 0)
{
}
简单的读操作:
不要问我怎么读,问了就乱棍打死。
nordic 还提供了软件nrfjprog,可通过jlink工具直接写入数据到这些地址,写入位置不是0xFFFFFFF将会无法写入,需要擦除。
如编辑一个bat脚本:
@echo off
set num1=5456
set num2=66
set num3=123456
nrfjprog --memwr 0x10001080 -f nrf52 --val %num1%
nrfjprog --memwr 0x10001084 -f nrf52 --val %num2%
nrfjprog --memwr 0x10001088 -f nrf52 --val %num3%
pause
windows上直接双击运行就能写入了,写入不了那就是环境没搭好。
有了这样的东西就能实现很多操作了,如烧录程序时更改地址。
追加编辑:
UICR擦除需要注意的东西, UICR结构体中包含了一些nfc引脚等的配置, 如果用到了这些配置的话要注意擦除前后读出来重新写回去。