How to get BD address from OTP ROM

hi Dialog

   if my code stored in QSPI flash, but I writed a BD address in OTP ROM by PLT, how to make ble stack use BD address in OTP ROM instead of the one in NVMS or defaultBLE_STATIC_ADDRESS?   Moreover, how to read the BD address from OTP ROM?  Is there any example code anout this case?

  thanks

  Nigel  

Parents
  • Hi Nigel,

    The BD Address in placed in specific address (0x07F8EA58) in the OPT header. Please try to read the OPT Header with the OTP tool from the SmartSnippets toolbox. In order to read the BD Address from the OTP Header you should follow the procedure below:

    1. Add the LLD (low level drivers) of the OTP controller

    #include "hw_otpc.h"

    2. Add the function which reads from the OTP memory, named read_bd_address_from_otp(). The source code is below:

    static bool read_bd_address_from_otp(uint32_t otp_cell_offset, uint8_t *bd_address, uint32_t *phy_otp_address)
    {
    
        uint32_t r_buf[2]; 
        uint32_t num_words = 3;
        uint32_t *physical_otp_address; 
    
        static uint8_t bd_address_otp_final[8]; 
    
        bool is_correct = 0; 
    
        physical_otp_address = hw_otpc_cell_to_mem(otp_cell_offset);
        phy_otp_address = physical_otp_address;
    
        hw_otpc_init();
    
        is_correct = hw_otpc_fifo_read( (uint32_t *) r_buf, otp_cell_offset ,HW_OTPC_WORD_LOW, num_words, false );
    
        hw_otpc_disable();
    
        bd_address_otp_final[0] = (r_buf[0] >> 0  );
        bd_address_otp_final[1] = (r_buf[0] >> 8  );
        bd_address_otp_final[2] = (r_buf[0] >> 16 );
        bd_address_otp_final[3] = (r_buf[0] >> 24 );
    
        bd_address_otp_final[4] = (r_buf[1] >> 0  );
        bd_address_otp_final[5] = (r_buf[1] >> 8  );
        bd_address_otp_final[6] = (r_buf[1] >> 16 );
        bd_address_otp_final[7] = (r_buf[1] >> 24 );
    
        memcpy(bd_address, bd_address_otp_final, 8);
    
        return is_correct;
    }

    3. Retrieve the BD address from the OTP memory

    uint32_t *physical_otp_memory_cell;
    uint32_t cell_offset = 0x1D4B;
    
    static uint8_t bd_address_final[8];
    
    bool read_success;
    
    /* Retrieve the BD address from the OTP memory */
    read_success = read_bd_address_from_otp(cell_offset, bd_address_final, physical_otp_memory_cell);
    OS_ASSERT(read_success);
    
    
    static own_address_t user_bd_address = {
        .addr_type = PRIVATE_STATIC_ADDRESS,
    };
    
    memcpy(user_bd_address.addr, bd_address_final, 6);
    
    
    // Set BD address to the preffered value. This function sets the BD address in inverse order.
    ble_gap_address_set(&user_bd_address, 0x00FF);

    Thanks, PM_Dialog

Reply
  • Hi Nigel,

    The BD Address in placed in specific address (0x07F8EA58) in the OPT header. Please try to read the OPT Header with the OTP tool from the SmartSnippets toolbox. In order to read the BD Address from the OTP Header you should follow the procedure below:

    1. Add the LLD (low level drivers) of the OTP controller

    #include "hw_otpc.h"

    2. Add the function which reads from the OTP memory, named read_bd_address_from_otp(). The source code is below:

    static bool read_bd_address_from_otp(uint32_t otp_cell_offset, uint8_t *bd_address, uint32_t *phy_otp_address)
    {
    
        uint32_t r_buf[2]; 
        uint32_t num_words = 3;
        uint32_t *physical_otp_address; 
    
        static uint8_t bd_address_otp_final[8]; 
    
        bool is_correct = 0; 
    
        physical_otp_address = hw_otpc_cell_to_mem(otp_cell_offset);
        phy_otp_address = physical_otp_address;
    
        hw_otpc_init();
    
        is_correct = hw_otpc_fifo_read( (uint32_t *) r_buf, otp_cell_offset ,HW_OTPC_WORD_LOW, num_words, false );
    
        hw_otpc_disable();
    
        bd_address_otp_final[0] = (r_buf[0] >> 0  );
        bd_address_otp_final[1] = (r_buf[0] >> 8  );
        bd_address_otp_final[2] = (r_buf[0] >> 16 );
        bd_address_otp_final[3] = (r_buf[0] >> 24 );
    
        bd_address_otp_final[4] = (r_buf[1] >> 0  );
        bd_address_otp_final[5] = (r_buf[1] >> 8  );
        bd_address_otp_final[6] = (r_buf[1] >> 16 );
        bd_address_otp_final[7] = (r_buf[1] >> 24 );
    
        memcpy(bd_address, bd_address_otp_final, 8);
    
        return is_correct;
    }

    3. Retrieve the BD address from the OTP memory

    uint32_t *physical_otp_memory_cell;
    uint32_t cell_offset = 0x1D4B;
    
    static uint8_t bd_address_final[8];
    
    bool read_success;
    
    /* Retrieve the BD address from the OTP memory */
    read_success = read_bd_address_from_otp(cell_offset, bd_address_final, physical_otp_memory_cell);
    OS_ASSERT(read_success);
    
    
    static own_address_t user_bd_address = {
        .addr_type = PRIVATE_STATIC_ADDRESS,
    };
    
    memcpy(user_bd_address.addr, bd_address_final, 6);
    
    
    // Set BD address to the preffered value. This function sets the BD address in inverse order.
    ble_gap_address_set(&user_bd_address, 0x00FF);

    Thanks, PM_Dialog

Children
No Data