Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pico_get_unique_board_id_string endianness is big-endian #2291

Open
Poofjunior opened this issue Feb 18, 2025 · 0 comments
Open

pico_get_unique_board_id_string endianness is big-endian #2291

Poofjunior opened this issue Feb 18, 2025 · 0 comments

Comments

@Poofjunior
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant