Skip to content

Commit

Permalink
stm32device: do not send more than CMD_EXTENDED_ERASE_MAX_PAGES pages…
Browse files Browse the repository at this point in the history
… per extended erase cmd

Some bootloaders apparently do not like massive page list, and just ACK without erasing : limit size of extended erase cmd page param to a CMD_EXTENDED_ERASE_MAX_PAGES.
  • Loading branch information
Guillaume Revaillot committed Sep 12, 2019
1 parent 2591ad4 commit 9241d9e
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/main/java/org/stm32flash/STM32Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class STM32Device {

private static final int CMD_READ_MAX_SIZE = 256;
private static final int CMD_WRITE_MAX_SIZE = 256;
private static final int CMD_EXTENDED_ERASE_MAX_PAGES = 512;


private static final int READ_TIMEOUT_DEFAULT = 1 * 1000;
private static final int ACK_TIMEOUT_DEFAULT = 1 * 1000;
Expand Down Expand Up @@ -251,19 +253,27 @@ public boolean eraseFlash(int startAddress, int len) throws IOException, Timeout
System.out.println("eraseFlash 0x"+ Integer.toHexString(startAddress) + ":0x" + Integer.toHexString(endAddress) + " : " + pageCount + " pages to erase. (" + startPage + ":" + endPage + ").");

if (mUseExtendedErase) {
int pagesToErase = pageCount;
while (pagesToErase > 0) {
// we need limit number of erased pages per extended erase command
// because some boots apparently do not like massive page list..
pageCount = Math.min(pagesToErase, CMD_EXTENDED_ERASE_MAX_PAGES);

byte[][] pageList = new byte[pageCount][2];
for (int i = 0; i < pageCount; i++) {
int page = (startPage + i);
if (mDebug)
System.out.println("adding page " + page + " to list.");
pageList[i][0] = (byte) (page >> 8);
pageList[i][1] = (byte) (page & 0xff);
}
if (!cmdExtendedErase(pageCount - 1, pageList))
return false;

byte[][] pageList = new byte[pageCount][2];
for (int i = 0; i < pageCount; i++) {
int page = (startPage + i);

if (mDebug)
System.out.println("adding page " + page + " to list.");

pageList[i][0] = (byte) (page >> 8);
pageList[i][1] = (byte) (page & 0xff);
startPage += pageCount;
pagesToErase -= pageCount;
}

return cmdExtendedErase(pageCount - 1, pageList);
return true;
} else {
byte[] pageList = new byte[pageCount];
for (int i = startPage; i < endPage; i++) {
Expand Down

0 comments on commit 9241d9e

Please sign in to comment.