nicefy
This commit is contained in:
parent
0b13607efd
commit
26f6bda49e
|
@ -50,8 +50,8 @@ static bool isInVirtualPageBuffer(uint32_t addr) {
|
||||||
|
|
||||||
// read 32-bit address and 8-bit checksum
|
// read 32-bit address and 8-bit checksum
|
||||||
static bool readAddress(uint32_t *addr) {
|
static bool readAddress(uint32_t *addr) {
|
||||||
uint8_t buf[5]; // 4 bytes
|
uint8_t buf[5]; // 4 bytes+checksum
|
||||||
if (sr5ReadData(&blTsChannel, buf, 5) != 5)
|
if (sr5ReadDataTimeout(&blTsChannel, buf, 5, sr5Timeout) != 5)
|
||||||
return false;
|
return false;
|
||||||
if (dfuCalcChecksum(buf, 4) != buf[4])
|
if (dfuCalcChecksum(buf, 4) != buf[4])
|
||||||
return false;
|
return false;
|
||||||
|
@ -105,6 +105,8 @@ bool dfuStartLoop(void) {
|
||||||
uint8_t command, complement;
|
uint8_t command, complement;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
|
|
||||||
|
sr5Timeout = DFU_SR5_TIMEOUT_FIRST;
|
||||||
|
|
||||||
// We cannot afford waiting for the first handshake byte, so we have to send an answer in advance!
|
// We cannot afford waiting for the first handshake byte, so we have to send an answer in advance!
|
||||||
sendByte(DFU_ACK_BYTE);
|
sendByte(DFU_ACK_BYTE);
|
||||||
|
|
||||||
|
@ -203,7 +205,6 @@ bool dfuStartLoop(void) {
|
||||||
|
|
||||||
// transmit data
|
// transmit data
|
||||||
sr5WriteData(&blTsChannel, (uint8_t *)buffer, numBytes);
|
sr5WriteData(&blTsChannel, (uint8_t *)buffer, numBytes);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DFU_WRITE_CMD: {
|
case DFU_WRITE_CMD: {
|
||||||
|
@ -217,7 +218,7 @@ bool dfuStartLoop(void) {
|
||||||
int numBytes = buffer[0] + 1;
|
int numBytes = buffer[0] + 1;
|
||||||
int numBytesAndChecksum = numBytes + 1; // +1 byte of checkSum
|
int numBytesAndChecksum = numBytes + 1; // +1 byte of checkSum
|
||||||
// receive data
|
// receive data
|
||||||
if (sr5ReadData(&blTsChannel, buffer + 1, numBytesAndChecksum) != numBytesAndChecksum)
|
if (sr5ReadDataTimeout(&blTsChannel, buffer + 1, numBytesAndChecksum, sr5Timeout) != numBytesAndChecksum)
|
||||||
break;
|
break;
|
||||||
// don't write corrupted data!
|
// don't write corrupted data!
|
||||||
if (dfuCalcChecksum(buffer, numBytesAndChecksum) != buffer[numBytesAndChecksum]) {
|
if (dfuCalcChecksum(buffer, numBytesAndChecksum) != buffer[numBytesAndChecksum]) {
|
||||||
|
@ -250,7 +251,7 @@ bool dfuStartLoop(void) {
|
||||||
numSectorData = (numSectors + 1) * 2 + 1;
|
numSectorData = (numSectors + 1) * 2 + 1;
|
||||||
uint8_t *sectorList = buffer + 2;
|
uint8_t *sectorList = buffer + 2;
|
||||||
// read sector data & checksum
|
// read sector data & checksum
|
||||||
if (sr5ReadData(&blTsChannel, sectorList, numSectorData) != numSectorData)
|
if (sr5ReadDataTimeout(&blTsChannel, sectorList, numSectorData, sr5Timeout) != numSectorData)
|
||||||
break;
|
break;
|
||||||
// verify checksum
|
// verify checksum
|
||||||
if (dfuCalcChecksum(buffer, 2 + numSectorData - 1) != buffer[2 + numSectorData - 1]) {
|
if (dfuCalcChecksum(buffer, 2 + numSectorData - 1) != buffer[2 + numSectorData - 1]) {
|
||||||
|
@ -260,7 +261,8 @@ bool dfuStartLoop(void) {
|
||||||
// Erase the chosen sectors, sector by sector
|
// Erase the chosen sectors, sector by sector
|
||||||
for (int i = 0; i < numSectorData - 1; i += 2) {
|
for (int i = 0; i < numSectorData - 1; i += 2) {
|
||||||
int sectorIdx = bufToInt16(sectorList + i);
|
int sectorIdx = bufToInt16(sectorList + i);
|
||||||
if (sectorIdx == 0) { // skip zero sector where our bootloader is
|
if (sectorIdx < BOOTLOADER_NUM_SECTORS) { // skip first sectors where our bootloader is
|
||||||
|
// imitate flash erase by writing '0xff'
|
||||||
memset(bootloaderVirtualPageBuffer, 0xff, BOOTLOADER_SIZE);
|
memset(bootloaderVirtualPageBuffer, 0xff, BOOTLOADER_SIZE);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#define BOOTLOADER_ADDR 0x08000000
|
#define BOOTLOADER_ADDR 0x08000000
|
||||||
// Bootloader code max. size, in bytes
|
// Bootloader code max. size, in bytes
|
||||||
#define BOOTLOADER_SIZE 0x4000
|
#define BOOTLOADER_SIZE 0x4000
|
||||||
|
// Number of sectors for the bootloader
|
||||||
|
#define BOOTLOADER_NUM_SECTORS (BOOTLOADER_SIZE/0x4000)
|
||||||
|
|
||||||
// This is where the application starts
|
// This is where the application starts
|
||||||
#define APPLICATION_ADDR 0x08008000
|
#define APPLICATION_ADDR 0x08008000
|
||||||
|
|
Loading…
Reference in New Issue