Skip to content

Commit

Permalink
Merge pull request #1 from Sjord/write-anywhere
Browse files Browse the repository at this point in the history
Write anywhere
  • Loading branch information
kirovilya committed May 3, 2018
2 parents 17390d9 + df846d2 commit ca0186f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Python/cclib/chip/cc254x.py
Expand Up @@ -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)
Expand Down Expand Up @@ -556,17 +561,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] )

# 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]
Expand All @@ -583,6 +577,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()
Expand Down

0 comments on commit ca0186f

Please sign in to comment.