From 43738a26caa2b68e27d4e0171cc365d61113c055 Mon Sep 17 00:00:00 2001 From: Sjoerd Langkemper Date: Mon, 9 Jan 2017 11:04:25 +0100 Subject: [PATCH 1/3] Remove debug statements --- Python/cclib/chip/cc254x.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Python/cclib/chip/cc254x.py b/Python/cclib/chip/cc254x.py index 5e06ac1..8126545 100644 --- a/Python/cclib/chip/cc254x.py +++ b/Python/cclib/chip/cc254x.py @@ -563,10 +563,6 @@ def writeCODE(self, offset, data, erase=False, verify=False, showProgress=False) cLow = fWordOffset & 0xFF self.writeXDATA( 0x6271, [cLow, cHigh] ) - # Debug - #print "[@%04x: p=%i, ofs=%04x, %02x:%02x]" % (fAddr, fPage, fWordOffset, cHigh, cLow), - #sys.stdout.flush() - # Check if we should erase page first if erase: # Select the page to erase using FADDRH[7:1] From bff413aefd66217c64837e88f8eac78daa2a2ad4 Mon Sep 17 00:00:00 2001 From: Sjoerd Langkemper Date: Mon, 9 Jan 2017 11:05:00 +0100 Subject: [PATCH 2/3] Don't overwrite values when erasing When erasing, we would write different values to 0x6271 (flash address) than are needed to write the data. Move the write after the erase so they don't interfere with each other. --- Python/cclib/chip/cc254x.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Python/cclib/chip/cc254x.py b/Python/cclib/chip/cc254x.py index 8126545..f4ab489 100644 --- a/Python/cclib/chip/cc254x.py +++ b/Python/cclib/chip/cc254x.py @@ -556,13 +556,6 @@ def writeCODE(self, offset, data, erase=False, verify=False, showProgress=False) fAddr = offset + iOfs fPage = int( fAddr / self.flashPageSize ) - # Calculate FLASH address High/Low bytes - # for writing (addressable as 32-bit words) - fWordOffset = int(fAddr / 4) - cHigh = (fWordOffset >> 8) & 0xFF - cLow = fWordOffset & 0xFF - self.writeXDATA( 0x6271, [cLow, cHigh] ) - # Check if we should erase page first if erase: # Select the page to erase using FADDRH[7:1] @@ -579,6 +572,13 @@ def writeCODE(self, offset, data, erase=False, verify=False, showProgress=False) while self.isFlashBusy(): time.sleep(0.010) + # Calculate FLASH address High/Low bytes + # for writing (addressable as 32-bit words) + fWordOffset = int(fAddr / 4) + cHigh = (fWordOffset >> 8) & 0xFF + cLow = fWordOffset & 0xFF + self.writeXDATA( 0x6271, [cLow, cHigh] ) + # Upload to FLASH through DMA-1 self.armDMAChannel(1) self.setFlashWrite() From df846d2e9e0cb619e75e46ff00fd9dbebdce5539 Mon Sep 17 00:00:00 2001 From: Sjoerd Langkemper Date: Mon, 9 Jan 2017 11:18:30 +0100 Subject: [PATCH 3/3] Pad data to write anywhere The flash is addressable as 32-bit words, so we can only write on 32-bit boundaries. If the offset parameter to writeCODE is not divisible by 4 (bytes), we will write to the wrong location. Put 0xff on the front of data so that data is still written to the correct location. Also, make sure the size of the data is also divisable by 4, as the documentation states: "note that the block size, LEN in configuration data, must be divisible by 4; otherwise, the last word is not written to the flash". This is not really an ideal solution because we will now also check the 0xff padding when verifying the write. This should not happen. --- Python/cclib/chip/cc254x.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Python/cclib/chip/cc254x.py b/Python/cclib/chip/cc254x.py index f4ab489..3c15a55 100644 --- a/Python/cclib/chip/cc254x.py +++ b/Python/cclib/chip/cc254x.py @@ -512,6 +512,11 @@ def writeCODE(self, offset, data, erase=False, verify=False, showProgress=False) WARNING: This requires DMA operations to be unpaused ( use: self.pauseDMA(False) ) """ + # Pad data so that the start and end address are on 4-byte boundaries. + data = b"\xff" * (offset % 4) + data + data = data + b"\xff" * (-len(data) % 4) + offset -= offset % 4 + # Prepare DMA-0 for DEBUG -> RAM (using DBG_BW trigger) self.configDMAChannel( 0, 0x6260, 0x0000, 0x1F, tlen=self.bulkBlockSize, srcInc=0, dstInc=1, priority=1, interrupt=True ) # Prepare DMA-1 for RAM -> FLASH (using the FLASH trigger)