Skip to content

pico_get_unique_board_id_string endianness is big-endian #2291

@Poofjunior

Description

@Poofjunior

It looks like the RP2040 is little-endian, but the unique id retrieved from the Winbond flash as printed in pico_get_unique_board_id_string populates the USB descriptor field as big-endian.

From the source, it looks like flash_get_unique_id retrieves the data as little-endian (since the system is little-endian) with:

    flash_do_cmd(txbuf, rxbuf, FLASH_RUID_TOTAL_BYTES);
    for (int i = 0; i < FLASH_RUID_DATA_BYTES; i++)
        id_out[i] = rxbuf[i + 1 + FLASH_RUID_DUMMY_BYTES];  // Copy direction is consistently increasing.

If I dump the data with memcpy like so:

uint8_t uuid[8];  
memcpy((void*)(&uuid[]), (void*)&(unique_id.id), sizeof(unique_id.id));

and then print the resulting array, I get (as expected):
Image

But reading the device descriptor field (populated by pico_get_unique_board_id_string), we get:
Image

But we should get: 2B686B83C25C63E6 where 0xE6 is the least significant byte.

The mistake is in pico_get_unique_board_id_string. Here, bytes are populated least-significant to most-significant, but the string will be printed and read with the least significant byte starting at index 0, making the string read most-significant-to-leas-significant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions