This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf connect sdk add custom section(UICR)

Hello

I want to add a UICR section. but I don't know how to add a custom section in ncs(also zephyr).

I have researched about this for days and I've found zephyr code realocation, but I don't want realocate the code. (SRAM, SRAM2, TEXT ...)

All I want is add a UICR section without realocate the other things.

Also I want to know how to change UICR REGOUT0 register value in ncs(also zephyr).

Thanks.

Parents
  • I want to add a UICR section. but I don't know how to add a custom section in ncs(also zephyr).

     You need to have a linker script (*.ld for gcc)Where you create a MEMORY section and define that section in SECTIONS of the linker script. Once you have that linker script you can include your custom linker scripts using this define. 

    Also I want to know how to change UICR REGOUT0 register value in ncs(also zephyr).

     UICR registers are not designed to be edited/changed after writing one value to the register. You need to erase the whole flash to be able to rewrite to UICR registers.

  • Is there an any example?

    I don't know how to write a linker script.

    Also in my research, add a custom linker script should rewrite the whole sections. and I dont want to do that.

    * All I want is change REGOUT0 value to change the gpip reference voltage. and I dont care about the method.

  • If writing to UICR is the thing you are trying to achieve then probably SOC_FLASH_NRF_UICR is your helper feature. You do not need any additional linker scripts when you enable this feature. You can write to this register as a normal flash write.

  • Finally I have wrote this code.

    It works very well.

        // Write UICR's REGOUT0 register to given value
        #if ( CONFIG_NRF52_ENABLE_DCDC == 1 )  
            if ( NRF_UICR->REGOUT0 != (uint32_t)CONFIG_NRF52_DCDC_REGOUT_VALUE ) {
            
                nrfx_err_t err = NRFX_SUCCESS;
            
                NRF_UICR_Type tmp;
                memcpy( &tmp, NRF_UICR, sizeof(NRF_UICR_Type) );
                
                tmp.REGOUT0 = (uint32_t)CONFIG_NRF52_DCDC_REGOUT_VALUE;
                
                err = nrfx_nvmc_uicr_erase( );
                __ASSERT( (err == NRFX_SUCCESS), "NVMC erase UICR failed" );
                
                nrfx_nvmc_bytes_write( NRF_UICR_BASE, &tmp, sizeof(NRF_UICR_Type) );
                while ( nrfx_nvmc_write_done_check() != true );
                
                LOG_INF( "REGOUT0 writed to %u", CONFIG_NRF52_DCDC_REGOUT_VALUE );
            
            }    
        #endif
Reply
  • Finally I have wrote this code.

    It works very well.

        // Write UICR's REGOUT0 register to given value
        #if ( CONFIG_NRF52_ENABLE_DCDC == 1 )  
            if ( NRF_UICR->REGOUT0 != (uint32_t)CONFIG_NRF52_DCDC_REGOUT_VALUE ) {
            
                nrfx_err_t err = NRFX_SUCCESS;
            
                NRF_UICR_Type tmp;
                memcpy( &tmp, NRF_UICR, sizeof(NRF_UICR_Type) );
                
                tmp.REGOUT0 = (uint32_t)CONFIG_NRF52_DCDC_REGOUT_VALUE;
                
                err = nrfx_nvmc_uicr_erase( );
                __ASSERT( (err == NRFX_SUCCESS), "NVMC erase UICR failed" );
                
                nrfx_nvmc_bytes_write( NRF_UICR_BASE, &tmp, sizeof(NRF_UICR_Type) );
                while ( nrfx_nvmc_write_done_check() != true );
                
                LOG_INF( "REGOUT0 writed to %u", CONFIG_NRF52_DCDC_REGOUT_VALUE );
            
            }    
        #endif
Children
No Data
Related