change "mem wipe" / "mem info" to use NG.\nsome more style changes

This commit is contained in:
iceman1001 committed 2025-09-12 22:06:37 +02:00
1 parent af9567a19e
commit 45d869e87a
6 files changed
+101 -73

No files matched your search

+54 -28
View File
@@ -55,15 +55,16 @@ void FlashmemSetSpiBaudrate(uint32_t baudrate) {
// read ID out
bool Flash_ReadID(flash_device_type_t *result, bool read_jedec) {
if (Flash_CheckBusy(BUSY_TIMEOUT)) return false;
if (Flash_CheckBusy(BUSY_TIMEOUT)) {
return false;
}
if (read_jedec) {
// 0x9F JEDEC
FlashSendByte(JEDECID);
result->manufacturer_id = (FlashSendByte(0xFF) & 0xFF);
result->device_id = (FlashSendByte(0xFF) & 0xFF);
result->manufacturer_id = (FlashSendByte(0xFF) & 0xFF);
result->device_id = (FlashSendByte(0xFF) & 0xFF);
result->device_id2 = (FlashSendLastByte(0xFF) & 0xFF);
} else {
// 0x90 Manufacture ID / device ID
@@ -72,7 +73,7 @@ bool Flash_ReadID(flash_device_type_t *result, bool read_jedec) {
FlashSendByte(0x00);
FlashSendByte(0x00);
result->manufacturer_id = (FlashSendByte(0xFF) & 0xFF);
result->manufacturer_id = (FlashSendByte(0xFF) & 0xFF);
result->device_id = (FlashSendLastByte(0xFF) & 0xFF);
}
@@ -81,10 +82,14 @@ bool Flash_ReadID(flash_device_type_t *result, bool read_jedec) {
uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len) {
if (!FlashInit()) return 0;
if (FlashInit() == false) {
return 0;
}
// length should never be zero
if (!len || Flash_CheckBusy(BUSY_TIMEOUT)) return 0;
if ((len == 0) || Flash_CheckBusy(BUSY_TIMEOUT)) {
return 0;
}
uint8_t cmd = (FASTFLASH) ? FASTREAD : READDATA;
@@ -99,6 +104,7 @@ uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len) {
for (; i < (len - 1); i++) {
out[i] = (FlashSendByte(0xFF) & 0xFF);
}
out[i] = (FlashSendLastByte(0xFF) & 0xFF);
FlashStop();
return len;
@@ -114,7 +120,9 @@ void Flash_TransferAdresse(uint32_t address) {
uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len) {
// length should never be zero
if (!len) return 0;
if (len == 0) {
return 0;
}
uint8_t cmd = (FASTFLASH) ? FASTREAD : READDATA;
@@ -129,6 +137,7 @@ uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len) {
for (; i < (len - 1); i++) {
out[i] = (FlashSendByte(0xFF) & 0xFF);
}
out[i] = (FlashSendLastByte(0xFF) & 0xFF);
return len;
}
@@ -139,8 +148,9 @@ uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len) {
uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) {
// length should never be zero
if (!len)
if (len == 0) {
return 0;
}
// Max 256 bytes write
if (((address & 0xFF) + len) > 256) {
@@ -148,8 +158,8 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) {
return 0;
}
if (!FlashInit()) {
if (g_dbglevel > 3) Dbprintf("Flash_WriteData init fail");
if (FlashInit() == false) {
if (g_dbglevel > DBG_DEBUG) Dbprintf("Flash_WriteData init fail");
return 0;
}
@@ -170,8 +180,9 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) {
FlashSendByte((address >> 0) & 0xFF);
uint16_t i = 0;
for (; i < (len - 1); i++)
for (; i < (len - 1); i++) {
FlashSendByte(in[i]);
}
FlashSendLastByte(in[i]);
@@ -203,8 +214,9 @@ uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len) {
FlashSendByte((address >> 0) & 0xFF);
uint16_t i = 0;
for (; i < (len - 1); i++)
for (; i < (len - 1); i++) {
FlashSendByte(in[i]);
}
FlashSendLastByte(in[i]);
return len;
@@ -233,8 +245,9 @@ uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len) {
isok = (res == bytes_in_packet);
if (!isok)
if (isok == false) {
goto out;
}
}
out:
@@ -246,10 +259,12 @@ out:
// they should inform the file system of this change
// e.g., rdv40_spiffs_check()
bool Flash_WipeMemoryPage(uint8_t page) {
if (!FlashInit()) {
if (g_dbglevel > 3) Dbprintf("Flash_WriteData init fail");
if (FlashInit() == false) {
if (g_dbglevel > DBG_DEBUG) Dbprintf("Flash_WriteData init fail");
return false;
}
Flash_ReadStat1();
// Each block is 64Kb. One block erase takes 1s ( 1000ms )
@@ -263,10 +278,12 @@ bool Flash_WipeMemoryPage(uint8_t page) {
}
// Wipes flash memory completely, fills with 0xFF
bool Flash_WipeMemory(void) {
if (!FlashInit()) {
if (g_dbglevel > 3) Dbprintf("Flash_WriteData init fail");
if (FlashInit() == false) {
if (g_dbglevel > DBG_DEBUG) Dbprintf("Flash_WriteData init fail");
return false;
}
Flash_ReadStat1();
// Each block is 64Kb. Four blocks
@@ -284,14 +301,16 @@ bool Flash_WipeMemory(void) {
// enable the flash write
void Flash_WriteEnable(void) {
FlashSendLastByte(WRITEENABLE);
if (g_dbglevel > 3) Dbprintf("Flash Write enabled");
if (g_dbglevel > DBG_DEBUG) Dbprintf("Flash Write enabled");
}
// erase 4K at one time
// execution time: 0.8ms / 800us
bool Flash_Erase4k(uint8_t block, uint8_t sector) {
if (block > spi_flash_pages64k || sector > MAX_SECTORS) return false;
if (block > spi_flash_pages64k || sector > MAX_SECTORS) {
return false;
}
FlashSendByte(SECTORERASE);
FlashSendByte(block);
@@ -326,7 +345,9 @@ bool Flash_Erase32k(uint32_t address) {
// 0x03 00 00 -- 0x 03 FF FF == block 3
bool Flash_Erase64k(uint8_t block) {
if (block > spi_flash_pages64k) return false;
if (block > spi_flash_pages64k) {
return false;
}
FlashSendByte(BLOCK64ERASE);
FlashSendByte(block);
@@ -346,7 +367,7 @@ void Flashmem_print_status(void) {
DbpString(_CYAN_("Flash memory"));
Dbprintf(" Baudrate................ " _GREEN_("%d MHz"), FLASHMEM_SPIBAUDRATE / 1000000);
if (!FlashInit()) {
if (FlashInit() == false) {
DbpString(" Init.................... " _RED_("failed"));
return;
}
@@ -374,7 +395,7 @@ void Flashmem_print_status(void) {
uid[0], uid[1], uid[2], uid[3],
uid[4], uid[5], uid[6], uid[7]
);
if (g_dbglevel > 3) {
if (g_dbglevel > DBG_DEBUG) {
Dbprintf(" Unique ID (le).......... " _YELLOW_("0x%02X%02X%02X%02X%02X%02X%02X%02X"),
uid[7], uid[6], uid[5], uid[4],
uid[3], uid[2], uid[1], uid[0]
@@ -384,6 +405,7 @@ void Flashmem_print_status(void) {
}
bool FlashDetect(void) {
flash_device_type_t flash_data = {0};
bool ret = false;
// read using 0x9F (JEDEC)
@@ -392,8 +414,9 @@ bool FlashDetect(void) {
spi_flash_data.jedec_id = (flash_data.device_id << 8) + flash_data.device_id2;
ret = true;
} else {
if (g_dbglevel > 3) Dbprintf("Flash_ReadID failed reading JEDEC (0x9F)");
if (g_dbglevel > DBG_DEBUG) Dbprintf("Flash_ReadID failed reading JEDEC (0x9F)");
}
// read using 0x90 (Manufacturer / Device ID)
if (Flash_ReadID(&flash_data, false)) {
if (spi_flash_data.manufacturer_id == 0) {
@@ -402,8 +425,9 @@ bool FlashDetect(void) {
spi_flash_data.device_id = flash_data.device_id;
ret = true;
} else {
if (g_dbglevel > 3) Dbprintf("Flash_ReadID failed reading Mfr/Dev (0x90)");
if (g_dbglevel > DBG_DEBUG) Dbprintf("Flash_ReadID failed reading Mfr/Dev (0x90)");
}
// Check JEDEC data is valid, compare the reported device types and then calculate the number of pages
// It is covering the most (known) cases of devices but probably there are vendors with different data
// They will be handled when there is such cases
@@ -434,7 +458,7 @@ bool FlashInit(void) {
#ifndef AS_BOOTROM
if (spi_flash_data.manufacturer_id == 0) {
if (!FlashDetect()) {
if (FlashDetect() == false) {
return false;
}
}
@@ -446,7 +470,9 @@ bool FlashInit(void) {
// read unique id for chip.
void Flash_UniqueID(uint8_t *uid) {
if (Flash_CheckBusy(BUSY_TIMEOUT)) return;
if (Flash_CheckBusy(BUSY_TIMEOUT)) {
return;
}
// reading unique serial number
FlashSendByte(UNIQUE_ID);
@@ -483,7 +509,7 @@ void FlashStop(void) {
AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS;
#ifndef AS_BOOTROM
if (g_dbglevel > 3) Dbprintf("FlashStop");
if (g_dbglevel > DBG_DEBUG) Dbprintf("FlashStop");
#endif // AS_BOOTROM
StopTicks();