-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
use all spi flash v0.1 #2638
Merged
Merged
use all spi flash v0.1 #2638
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48ec109
use all spi flash v0.1
ANTodorov 34e317a
address review comments
ANTodorov 861c7ef
fix missing offsets
ANTodorov d49e1f6
remove unused definition
ANTodorov 597bfd6
fix signature offset in a log message too
ANTodorov 51a94d6
restore config page (the last page) protection from wiping
ANTodorov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,8 @@ static uint32_t FLASHMEM_SPIBAUDRATE = FLASH_BAUD; | |
|
||
#ifndef AS_BOOTROM | ||
|
||
uint8_t spi_flash_p64k = 0; | ||
|
||
void FlashmemSetSpiBaudrate(uint32_t baudrate) { | ||
FLASHMEM_SPIBAUDRATE = baudrate; | ||
Dbprintf("Spi Baudrate : %dMHz", FLASHMEM_SPIBAUDRATE / 1000000); | ||
|
@@ -144,14 +146,15 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) { | |
return 0; | ||
} | ||
|
||
// out-of-range | ||
if (((address >> 16) & 0xFF) > MAX_BLOCKS) { | ||
Dbprintf("Flash_WriteData, block out-of-range"); | ||
if (!FlashInit()) { | ||
if (g_dbglevel > 3) Dbprintf("Flash_WriteData init fail"); | ||
return 0; | ||
} | ||
|
||
if (!FlashInit()) { | ||
if (g_dbglevel > 3) Dbprintf("Flash_WriteData init fail"); | ||
// out-of-range | ||
if (((address >> 16) & 0xFF) > spi_flash_p64k) { | ||
Dbprintf("Flash_WriteData, block out-of-range %02x > %02x", (address >> 16) & 0xFF, spi_flash_p64k); | ||
FlashStop(); | ||
return 0; | ||
} | ||
|
||
|
@@ -187,8 +190,8 @@ uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len) { | |
return 0; | ||
} | ||
|
||
if (((address >> 16) & 0xFF) > MAX_BLOCKS) { | ||
Dbprintf("Flash_WriteDataCont, block out-of-range"); | ||
if (((address >> 16) & 0xFF) > spi_flash_p64k) { | ||
Dbprintf("Flash_WriteDataCont, block out-of-range %02x > %02x", (address >> 16) & 0xFF, spi_flash_p64k); | ||
return 0; | ||
} | ||
|
||
|
@@ -266,18 +269,11 @@ bool Flash_WipeMemory(void) { | |
|
||
// Each block is 64Kb. Four blocks | ||
// one block erase takes 1s ( 1000ms ) | ||
Flash_WriteEnable(); | ||
Flash_Erase64k(0); | ||
Flash_CheckBusy(BUSY_TIMEOUT); | ||
Flash_WriteEnable(); | ||
Flash_Erase64k(1); | ||
Flash_CheckBusy(BUSY_TIMEOUT); | ||
Flash_WriteEnable(); | ||
Flash_Erase64k(2); | ||
Flash_CheckBusy(BUSY_TIMEOUT); | ||
Flash_WriteEnable(); | ||
Flash_Erase64k(3); | ||
Flash_CheckBusy(BUSY_TIMEOUT); | ||
for (uint8_t i=0; i < spi_flash_p64k; i++) { | ||
Flash_WriteEnable(); | ||
Flash_Erase64k(i); | ||
Flash_CheckBusy(BUSY_TIMEOUT); | ||
} | ||
|
||
FlashStop(); | ||
return true; | ||
|
@@ -293,7 +289,7 @@ void Flash_WriteEnable(void) { | |
// execution time: 0.8ms / 800us | ||
bool Flash_Erase4k(uint8_t block, uint8_t sector) { | ||
|
||
if (block > MAX_BLOCKS || sector > MAX_SECTORS) return false; | ||
if (block > spi_flash_p64k || sector > MAX_SECTORS) return false; | ||
|
||
FlashSendByte(SECTORERASE); | ||
FlashSendByte(block); | ||
|
@@ -328,7 +324,7 @@ bool Flash_Erase32k(uint32_t address) { | |
// 0x03 00 00 -- 0x 03 FF FF == block 3 | ||
bool Flash_Erase64k(uint8_t block) { | ||
|
||
if (block > MAX_BLOCKS) return false; | ||
if (block > spi_flash_p64k) return false; | ||
|
||
FlashSendByte(BLOCK64ERASE); | ||
FlashSendByte(block); | ||
|
@@ -404,6 +400,7 @@ void Flashmem_print_status(void) { | |
); | ||
} | ||
} | ||
Dbprintf(" Flash pages (64k)....... " _YELLOW_("0x%02x (%u)"), spi_flash_p64k, spi_flash_p64k); | ||
|
||
uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0}; | ||
Flash_UniqueID(uid); | ||
|
@@ -457,6 +454,38 @@ void Flashmem_print_info(void) { | |
FlashStop(); | ||
} | ||
|
||
//read spi flash JEDEC ID and fill the global variable spi_flash_p64k | ||
bool FlashDetect(bool flash_init) { | ||
flash_device_type_t flash_device = {0}; | ||
|
||
if (flash_init) { | ||
if (!FlashInit()) { | ||
if (g_dbglevel > 3) Dbprintf("FlashDetect() FlashInit fail"); | ||
return 0; | ||
} | ||
} | ||
|
||
if (!Flash_ReadID(&flash_device, true)) { | ||
if (g_dbglevel > 3) Dbprintf("Flash_ReadID failed"); | ||
return false; | ||
} | ||
|
||
uint32_t identifier = (flash_device.manufacturer_id <<16) + (flash_device.device_id <<8) + flash_device.device_id2; | ||
int i = 0; | ||
for (; i < ARRAYLEN(SpiFlashTable); i++) { | ||
if (SpiFlashTable[i].identifier == identifier) { | ||
break; | ||
} | ||
} | ||
|
||
spi_flash_p64k = SpiFlashTable[i].pages64; | ||
|
||
if (flash_init) { | ||
FlashStop(); | ||
} | ||
return true; | ||
} | ||
|
||
#endif // #ifndef AS_BOOTROM | ||
|
||
|
||
|
@@ -471,6 +500,12 @@ bool FlashInit(void) { | |
return false; | ||
} | ||
|
||
#ifndef AS_BOOTROM | ||
if (spi_flash_p64k == 0){ | ||
if (!FlashDetect(false)) return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use same style with Curly Brackets |
||
} | ||
#endif // #ifndef AS_BOOTROM | ||
|
||
return true; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't mix return codes.