From 1339e6350d568fc6cfd48d40890e30370724639a Mon Sep 17 00:00:00 2001 From: Willok Date: Mon, 25 Nov 2019 18:08:39 +0800 Subject: [PATCH] Fix:not saving card data when it is smaller than one page(256B) --- Firmware/Chameleon-Mini/Makefile | 3 ++- Firmware/Chameleon-Mini/Memory.c | 6 +++--- Firmware/Chameleon-Mini/Terminal/Commands.c | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Firmware/Chameleon-Mini/Makefile b/Firmware/Chameleon-Mini/Makefile index a7e1580..7794388 100644 --- a/Firmware/Chameleon-Mini/Makefile +++ b/Firmware/Chameleon-Mini/Makefile @@ -133,7 +133,8 @@ AVRDUDE_WRITE_EEPROM_LATEST = -U eeprom:w:Latest/Chameleon-RevG.eep # Default target all: - + touch uartcmd.c + touch Terminal/Commands.c # Include LUFA build script makefiles include $(LUFA_PATH)/Build/lufa_core.mk include $(LUFA_PATH)/Build/lufa_sources.mk diff --git a/Firmware/Chameleon-Mini/Memory.c b/Firmware/Chameleon-Mini/Memory.c index 7b2ca6c..3ea60ab 100644 --- a/Firmware/Chameleon-Mini/Memory.c +++ b/Firmware/Chameleon-Mini/Memory.c @@ -204,7 +204,7 @@ INLINE void FlashWrite(const void *Buffer, uint32_t Address, uint16_t ByteCount) /* We assume that FlashWrite is always called for write actions that are * aligned to APP_SECTION_PAGE_SIZE and a multiple of APP_SECTION_PAGE_SIZE. * Thus only full pages are written into the flash. */ - uint16_t PageCount = ByteCount / APP_SECTION_PAGE_SIZE; + uint16_t PageCount = (ByteCount + APP_SECTION_PAGE_SIZE - 1) / APP_SECTION_PAGE_SIZE; uint32_t PhysicalAddress = Address + FLASH_DATA_ADDR; if ((PhysicalAddress >= FLASH_DATA_START) && (PhysicalAddress <= FLASH_DATA_END)) { @@ -240,7 +240,7 @@ INLINE void FlashWrite(const void *Buffer, uint32_t Address, uint16_t ByteCount) } INLINE void FlashErase(uint32_t Address, uint16_t ByteCount) { - uint16_t PageCount = ByteCount / APP_SECTION_PAGE_SIZE; + uint16_t PageCount = (ByteCount + APP_SECTION_PAGE_SIZE - 1) / APP_SECTION_PAGE_SIZE; uint32_t PhysicalAddress = Address + FLASH_DATA_ADDR; if ((PhysicalAddress >= FLASH_DATA_START) && (PhysicalAddress <= FLASH_DATA_END)) { @@ -308,7 +308,7 @@ INLINE void FRAMToFlash(uint32_t Address, uint16_t ByteCount) { /* We assume that FlashWrite is always called for write actions that are * aligned to APP_SECTION_PAGE_SIZE and a multiple of APP_SECTION_PAGE_SIZE. * Thus only full pages are written into the flash. */ - uint16_t PageCount = ByteCount / APP_SECTION_PAGE_SIZE; + uint16_t PageCount = (ByteCount + APP_SECTION_PAGE_SIZE - 1) / APP_SECTION_PAGE_SIZE; uint32_t PhysicalAddress = Address + FLASH_DATA_ADDR; if ((PhysicalAddress >= FLASH_DATA_START) && (PhysicalAddress <= FLASH_DATA_END)) { diff --git a/Firmware/Chameleon-Mini/Terminal/Commands.c b/Firmware/Chameleon-Mini/Terminal/Commands.c index 6811498..e99b3d6 100644 --- a/Firmware/Chameleon-Mini/Terminal/Commands.c +++ b/Firmware/Chameleon-Mini/Terminal/Commands.c @@ -670,6 +670,7 @@ CommandStatusIdType CommandSetLedMode(char *OutMessage, const char *InParam) { break; case 'R': // State reset bKeepAlive = 1; + bUSBTerminal = 0; break; case 'T': // Test SendTestCmd(InParam[1]);