Setting REGOUT0 in merged.hex

Hi there,

Our firmware is built on NCS 2.6.1 (soon to be ported to 2.7.0) and uses MCUboot.

I want to set REGOUT0 to 5 (which corresponds to 3.3V) and the `nrfjprog --memwr 0x10001304 --val 5` command works for this purpose.

However, I want this REGOUT0 value to be put into merged.hex during the build procedure. I've read numerous related forum threads, but none explains exactly how to achieve this. To the best of my knowledge, a linker script is the solution.

Please provide exact instructions.

Thanks in advance!

- Laci

  • There should be one way that I think you can try using linked script 

    add a linker script in your project folder for example my_regout0_settings.ld like this

    SECTIONS
    {
        .uicr_regout0 (0x10001304) :
        {
            KEEP(*(.uicr_regout0))
        } >UICR
    }
    

    In your CMakeLists.txt: Include the custom linker script in the build process:

    set_property(GLOBAL APPEND PROPERTY linker_script custom_uicr.ld)
    If set_property does not work, then just use set

    In your application somewhere, set the REGOUT0 value like this

    __attribute__((section(".uicr_regout0")))
    const uint32_t regout0 = 0xFFFFFF05; // 3.3V

  • Thanks for your help, Susheel!

    Unfortunately, the suggested solution didn't make a difference. I used claude.ai to get closer to the solution.

    Instead of using set_property or set, I used:

    zephyr_linker_sources(SECTIONS my_regout0_settings.ld)
     
    Which included the my_regout0_settings.ld
    But then the build failed because the UICR memory section wasn't present, so I included it:
    MEMORY
    {
        UICR (rw) : ORIGIN = 0x10001000, LENGTH = 0x1000
    }
    The build failed due to multiple memory sections, so I included the following in the device tree:
    soc {
        uicr: uicr@10001000 {
            compatible = "zephyr,memory-region";
            reg = <0x10001000 0x1000>;
            zephyr,memory-region = "UICR";
            status = "okay";
        };
    };
     
    The above devicetree fragment created the memory section in linker.cmd.
    Then I added the following to my_regout0_settings.ld:
    SECTIONS
    {
        .uicr_regout0 (0x10001304) :
        {
            KEEP(*(.uicr_regout0))
        } >UICR
    }
    The build failed, presumably because of multiple sections. I added the following devicetree fragment which doesn't make a difference:
    regout0_partition: partition@10001304 {
        compatible = "zephyr,code-partition";
        reg = <0x10001304 0x4>;
        zephyr,memory-region = "UICR";
        zephyr,section-name = "uicr_regout0";
    };
    I'm stuck at this point.
    Do any of you at Nordic have further suggestions?
  • Laszlo,

    I think it is getting complicated with the changes going the route of having it in linker file. I think simpler would be just add it to the merged.hex in a different way. 

    I had another thought

    create a regout0.hex with this content

    :020000041000EA
    :0403040050000005E3
    :00000001FF

    and add custom merge in CMakeLists.txt

    # Path to the custom HEX file
    set(REGOUT0_HEX ${CMAKE_CURRENT_SOURCE_DIR}/regout0.hex)
    
    # Append REGOUT0_HEX to the final merged.hex
    add_custom_command(
        TARGET ${APPLICATION}
        POST_BUILD
        COMMAND mergehex --merge ${CMAKE_BINARY_DIR}/zephyr/merged.hex ${REGOUT0_HEX} --output ${CMAKE_BINARY_DIR}/zephyr/merged_with_regout.hex
        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/zephyr/merged_with_regout.hex ${CMAKE_BINARY_DIR}/zephyr/merged.hex
    )
     

    verify through nrfjprog after you flash this new merged.hex

    nrfjprog --readcode output.hex
    grep "10001304" output.hex
    

  • Hi Susheel,

    `mergehex --merge dongle-merged-3ba9eec.hex regout0.hex --output dongle-merged-3ba9eec-regout0.hex` yields:

    Failed to parse line 1 : ":0403040050000005E3"ERROR: One of the files to merge is not a valid hex file.

    dongle-merged-3ba9eec.hex

    regout0.hex

    Can you help with this error?

  • I am sorry, missed to see this ticket. I think I created a wrong hex file, but my intention was to show you how it is done.

    There are so many ways to create an intel HEX one I could think of is using objcopy

    printf "\x05\x00\x00\x00" > regout0.bin
    arm-none-eabi-objcopy --adjust-vma=0x10001304 -I binary -O ihex regout0.bin regout0.hex
    mergehex -m app.hex regout0.hex -o merged.hex
    nrfjprog --program merged.hex --verify
    nrfjprog --memrd 0x10001304 --n 4

    I think that should work. 


Related