From bf583bf65b38145a5ea1b4d80bbeb2df6faabb73 Mon Sep 17 00:00:00 2001 From: Doug Brown Date: Tue, 16 Oct 2012 21:25:15 -0700 Subject: [PATCH] Fixed a couple of bugs -- first, I was reading the wrong datasheet. Second, I was doing a bitwise AND when I was trying to do a modulo. The firmware is now tested for erasing only a portion of the SIMM. --- external_mem.c | 12 ++++++------ usb_serial/usb_serial.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/external_mem.c b/external_mem.c index d3a9241..94a4aef 100644 --- a/external_mem.c +++ b/external_mem.c @@ -263,9 +263,9 @@ bool ExternalMem_EraseSectors(uint32_t address, uint32_t length, uint8_t chipsMa // Make sure the area requested to be erased is on 64 KB boundaries. // True, the 2 MB SIMM doesn't require 64 KB boundaries, but I'm going to // keep it to 2 MB boundaries to simplify everything. -#define ERASABLE_SECTOR_SIZE (64*1024UL*1024UL) - if ((address & ERASABLE_SECTOR_SIZE) || - (length & ERASABLE_SECTOR_SIZE)) +#define ERASABLE_SECTOR_SIZE (64*1024UL) + if ((address % ERASABLE_SECTOR_SIZE) || + (length % ERASABLE_SECTOR_SIZE)) { return false; } @@ -274,7 +274,7 @@ bool ExternalMem_EraseSectors(uint32_t address, uint32_t length, uint8_t chipsMa if (curChipType == ChipType8BitData_4MBitSize) { -#define SECTOR_SIZE_4MBIT (128) +#define SECTOR_SIZE_4MBIT (4096) // This chip sucks because you have to erase each sector with its own // complete erase unlock command, which can take a while. At least // individual erase operations are much faster on this chip... @@ -287,7 +287,7 @@ bool ExternalMem_EraseSectors(uint32_t address, uint32_t length, uint8_t chipsMa // Now provide a sector address, but only one. Then the whole // unlock sequence has to be done again after this sector is done. - ExternalMem_WriteCycle(address, 0x20202020UL); + ExternalMem_WriteCycle(address, 0x30303030UL); address += SECTOR_SIZE_4MBIT; length -= SECTOR_SIZE_4MBIT; @@ -301,7 +301,7 @@ bool ExternalMem_EraseSectors(uint32_t address, uint32_t length, uint8_t chipsMa } else if (curChipType == ChipType8Bit16BitData_16MBitSize) { -#define SECTOR_SIZE_16MBIT (64*1024UL*1024UL) +#define SECTOR_SIZE_16MBIT (64*1024UL) // This chip is nicer because it can take all the sector addresses at // once and then do the final erase operation in one fell swoop. diff --git a/usb_serial/usb_serial.c b/usb_serial/usb_serial.c index fbc6933..b6bf903 100644 --- a/usb_serial/usb_serial.c +++ b/usb_serial/usb_serial.c @@ -450,8 +450,8 @@ void USBSerial_HandleErasePortionReadPosLengthByte(uint8_t byte) bool eraseSuccess = false; // Ensure they are both within limits of sector size erasure - if (((erasePosition & ERASE_SECTOR_SIZE_BYTES) == 0) && - ((eraseLength & ERASE_SECTOR_SIZE_BYTES) == 0)) + if (((erasePosition % ERASE_SECTOR_SIZE_BYTES) == 0) && + ((eraseLength % ERASE_SECTOR_SIZE_BYTES) == 0)) { uint32_t boundary = eraseLength + erasePosition;