From 95f247a25ebb7b68144ae883fc3531362a01323a Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Tue, 21 Apr 2020 09:02:48 +0200 Subject: [PATCH] spiFlash: read extented ID only when len != 0 --- src/spiFlash.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/spiFlash.cpp b/src/spiFlash.cpp index d2b3e91..9a1a30d 100644 --- a/src/spiFlash.cpp +++ b/src/spiFlash.cpp @@ -157,6 +157,7 @@ void SPIFlash::read_id() { int len = 4; uint8_t rx[512]; + bool has_edid = false; _spi->spi_put(0x9F, NULL, rx, 4); int d = 0; @@ -169,10 +170,13 @@ void SPIFlash::read_id() if (_verbose) printf("read %x\n", d); - /* read extented */ - len += (d & 0x0ff); - _spi->spi_put(0x9F, NULL, rx, len); + /* read extented */ + if ((d & 0xff) != 0) { + has_edid = true; + len += (d & 0x0ff); + _spi->spi_put(0x9F, NULL, rx, len); + } /* must be 0x20BA1810 ... */ @@ -180,13 +184,17 @@ void SPIFlash::read_id() printf("Jedec ID : %02x\n", rx[0]); printf("memory type : %02x\n", rx[1]); printf("memory capacity : %02x\n", rx[2]); - printf("EDID + CFD length : %02x\n", rx[3]); - printf("EDID : %02x%02x\n", rx[5], rx[4]); - printf("CFD : "); - if (_verbose) { - for (int i = 6; i < len; i++) - printf("%02x ", rx[i]); - printf("\n"); + if (has_edid) { + printf("EDID + CFD length : %02x\n", rx[3]); + printf("EDID : %02x%02x\n", rx[5], rx[4]); + printf("CFD : "); + if (_verbose) { + for (int i = 6; i < len; i++) + printf("%02x ", rx[i]); + printf("\n"); + } else { + printf("\n"); + } } }