standardize flash uniqueID to big-endian

This commit is contained in:
Henry Gabryjelski 2023-02-18 12:16:50 -08:00
commit 229454963b
3 changed files with 34 additions and 31 deletions

View file

@ -49,9 +49,9 @@ void FlashmemSetSpiBaudrate(uint32_t baudrate) {
} }
// read ID out // read ID out
uint8_t Flash_ReadID(void) { bool Flash_ReadID_90(flash_device_type_90_t* result) {
if (Flash_CheckBusy(BUSY_TIMEOUT)) return 0; if (Flash_CheckBusy(BUSY_TIMEOUT)) return false;
// Manufacture ID / device ID // Manufacture ID / device ID
FlashSendByte(ID); FlashSendByte(ID);
@ -59,15 +59,10 @@ uint8_t Flash_ReadID(void) {
FlashSendByte(0x00); FlashSendByte(0x00);
FlashSendByte(0x00); FlashSendByte(0x00);
uint8_t man_id = FlashSendByte(0xFF); result->manufacturer_id = FlashSendByte(0xFF);
uint8_t dev_id = FlashSendLastByte(0xFF); result->device_id = FlashSendLastByte(0xFF);
if (g_dbglevel > 3) Dbprintf("Flash ReadID | Man ID %02x | Device ID %02x", man_id, dev_id); return true;
if ((man_id == WINBOND_MANID) && (dev_id == WINBOND_DEVID))
return dev_id;
return 0;
} }
uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len) { uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len) {
@ -349,29 +344,32 @@ void Flashmem_print_status(void) {
} }
DbpString(" Init.................... " _GREEN_("OK")); DbpString(" Init.................... " _GREEN_("OK"));
uint8_t dev_id = Flash_ReadID(); // NOTE: It would likely be more useful to use JDEC ID command 9F,
switch (dev_id) { // as it provides a third byte indicative of capacity.
case 0x11 : flash_device_type_90_t device_type = {0};
DbpString(" Memory size............. " _YELLOW_("2 mbits / 256 kb")); if (!Flash_ReadID_90(&device_type)) {
break; DbpString(" Device ID............... " _RED_(" --> Not Found <--"));
case 0x10 : } else {
DbpString(" Memory size..... ....... " _YELLOW_("1 mbits / 128 kb")); if ((device_type.manufacturer_id == WINBOND_MANID) && (device_type.device_id == WINBOND_DEVID)) {
break; DbpString(" Memory size............. " _GREEN_("2 mbits / 256 kb"));
case 0x05 : } else {
DbpString(" Memory size............. " _YELLOW_("512 kbits / 64 kb")); Dbprintf(" Device ID............... " _YELLOW_("%02X / %02X (unknown)"),
break; device_type.manufacturer_id, device_type.device_id );
default : }
DbpString(" Device ID............... " _YELLOW_(" --> Unknown <--"));
break;
} }
uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0}; uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0};
Flash_UniqueID(uid); Flash_UniqueID(uid);
Dbprintf(" Unique ID............... " _YELLOW_("0x%02X%02X%02X%02X%02X%02X%02X%02X"), Dbprintf(" Unique ID (be).......... " _YELLOW_("0x%02X%02X%02X%02X%02X%02X%02X%02X" ),
uid[0], uid[1], uid[2], uid[3],
uid[4], uid[5], uid[6], uid[7]
);
if (g_dbglevel > 3) {
Dbprintf(" Unique ID (le).......... " _YELLOW_("0x%02X%02X%02X%02X%02X%02X%02X%02X" ),
uid[7], uid[6], uid[5], uid[4], uid[7], uid[6], uid[5], uid[4],
uid[3], uid[2], uid[1], uid[0] uid[3], uid[2], uid[1], uid[0]
); );
}
FlashStop(); FlashStop();
} }

View file

@ -123,7 +123,12 @@ bool Flash_Erase4k(uint8_t block, uint8_t sector);
//bool Flash_Erase32k(uint32_t address); //bool Flash_Erase32k(uint32_t address);
bool Flash_Erase64k(uint8_t block); bool Flash_Erase64k(uint8_t block);
uint8_t Flash_ReadID(void); typedef struct {
uint8_t manufacturer_id;
uint8_t device_id;
} flash_device_type_90_t; // to differentiate from JDEC ID via cmd 9F
bool Flash_ReadID_90(flash_device_type_90_t* result);
uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len); uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len);
uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len); uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len);
uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len); uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len);

View file

@ -413,8 +413,8 @@ void usb_update_serial(uint64_t newSerialNumber) {
uint8_t nibble2 = (newSerialNumber >> ((8 * i) + 0)) & 0xFu; // bitmasks [0x0F, 0x0F00, 0x0F0000, ... 0x0F00000000000000] uint8_t nibble2 = (newSerialNumber >> ((8 * i) + 0)) & 0xFu; // bitmasks [0x0F, 0x0F00, 0x0F0000, ... 0x0F00000000000000]
char c1 = nibble1 < 10 ? '0' + nibble1 : 'A' + (nibble1 - 10); char c1 = nibble1 < 10 ? '0' + nibble1 : 'A' + (nibble1 - 10);
char c2 = nibble2 < 10 ? '0' + nibble2 : 'A' + (nibble2 - 10); char c2 = nibble2 < 10 ? '0' + nibble2 : 'A' + (nibble2 - 10);
StrSerialNumber[46 - (4 * i)] = c1; // [ 46, 42, .., 22, 18 ] StrSerialNumber[18 + (4*i) + 0] = c1; // [ 18, 22, .., 42, 46 ]
StrSerialNumber[48 - (4 * i)] = c2; // [ 48, 44, .., 24, 20 ] StrSerialNumber[18 + (4*i) + 2] = c2; // [ 20, 24, .., 44, 48 ]
} }
StrSerialNumber[0] = USB_STRING_DESCRIPTOR_SERIAL_NUMBER_LENGTH; StrSerialNumber[0] = USB_STRING_DESCRIPTOR_SERIAL_NUMBER_LENGTH;
} }