How can I read the UICR register of 9160?

The current project needs to save the ID in the programmable register and use the ID in the application image.

So I save the ID number in the URCI->OTP[0] register. When I read the ID in URCI->OTP[0] in the main function of the application image, a fatal error occurred.

uint32_t get_id_from_uicr(){
        uint32_t id;
        id = (NRF_UICR_S->OTP[0]);
        return id;
}

As far as I know, UICR can only be read in secure code.

So I execute this code in the main function of spm and get the ID normally. How can I pass the ID to the application image(not via flash)?

Or is there any other better way to store this ID?

spm.c:

uint32_t get_id_from_uicr(){
        uint32_t id;
        id = (NRF_UICR_S->OTP[0]);
        return id;
}

void main(void)
{
    uint32_t id;
    id = get_imei_from_uicr();
	spm_config();
	spm_jump();
}

Parents Reply
  • I imitated the method of reading the FICR register in secure services to read the UICR register. The spm_request_read() function returns error code -1. How can I solve this problem?

    static int read_uicr_word(uint32_t *result, const volatile uint32_t *addr)
    {
    	printk("Read UICR (address 0x%08x):\n", (uint32_t)addr);
    	int ret = spm_request_read(result, (uint32_t)addr, sizeof(uint32_t));
    
    	if (ret != 0) {
    		printk("Could not read UICR (err: %d)\n", ret);
    	}
    	return ret;
    }
    void main(void)
    {
        uint32_t uicr_info;
        if(read_uicr_word(&ficr_info, &NRF_UICR_S->OTP[0]) == 0) {
    	    printk("UICR = 0x%08X\n\n", uicr_info);        
        }
        
    	printk("Reboot in %d seconds.\n", sleep_time_s);
    	k_sleep(K_SECONDS(5));
    
    	sys_reboot(0); /* Argument is ignored. */    
    }

    Log:

    Read UICR (address 0x00ff8108):
    Could not read UICR (err: -1)
    Reboot in 5 seconds.

Children
Related