aboutsummaryrefslogtreecommitdiffstats
path: root/Bootloaders
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2013-03-09 10:32:17 +0000
committerDean Camera <dean@fourwalledcubicle.com>2013-03-09 10:32:17 +0000
commitbb8754e2b8f1f8e6d027da98f76ed66de4a361cc (patch)
treecea1f9ee5e37bbfd179454748f05c019af9ab74e /Bootloaders
parent63e1fc6e6c435dcdaa0ebc465c00b1df05f69ed4 (diff)
downloadlufa-bb8754e2b8f1f8e6d027da98f76ed66de4a361cc.tar.gz
lufa-bb8754e2b8f1f8e6d027da98f76ed66de4a361cc.tar.bz2
lufa-bb8754e2b8f1f8e6d027da98f76ed66de4a361cc.zip
Add FLASH writing routine to the VirtualFAT layer of the incomplete Mass Storage class bootloader.
Diffstat (limited to 'Bootloaders')
-rw-r--r--Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c34
-rw-r--r--Bootloaders/Incomplete/MassStorage/makefile2
2 files changed, 32 insertions, 4 deletions
diff --git a/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c b/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c
index f5e5f840d..5d91cefaf 100644
--- a/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c
+++ b/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c
@@ -92,7 +92,7 @@ static void UpdateFAT12ClusterEntry(uint8_t* FATTable,
static void WriteBlock(const uint16_t BlockNumber)
{
- uint8_t BlockBuffer[512];
+ uint8_t BlockBuffer[SECTOR_SIZE_BYTES];
/* Wait until endpoint is ready before continuing */
if (Endpoint_WaitUntilReady())
@@ -101,12 +101,40 @@ static void WriteBlock(const uint16_t BlockNumber)
Endpoint_Read_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL);
Endpoint_ClearOUT();
- // TODO: Write to FLASH
+ if ((BlockNumber >= 4) && (BlockNumber < (4 + (FIRMWARE_FILE_SIZE / SECTOR_SIZE_BYTES))))
+ {
+ uint32_t WriteFlashAddress = (uint32_t)(BlockNumber - 4) * SECTOR_SIZE_BYTES;
+
+ for (uint16_t i = 0; i < SECTOR_SIZE_BYTES; i += 2)
+ {
+ /* Disallow writing to the bootloader section */
+ if (WriteFlashAddress > BOOT_START_ADDR)
+ continue;
+
+ if ((WriteFlashAddress % SPM_PAGESIZE) == 0)
+ {
+ /* Erase the given FLASH page, ready to be programmed */
+ boot_page_erase(WriteFlashAddress);
+ boot_spm_busy_wait();
+ }
+
+ /* Write the next data word to the FLASH page */
+ boot_page_fill(WriteFlashAddress, (BlockBuffer[i + 1] << 8) | BlockBuffer[i]);
+ WriteFlashAddress += 2;
+
+ if ((WriteFlashAddress % SPM_PAGESIZE) == 0)
+ {
+ /* Write the filled FLASH page to memory */
+ boot_page_write(WriteFlashAddress - SPM_PAGESIZE);
+ boot_spm_busy_wait();
+ }
+ }
+ }
}
static void ReadBlock(const uint16_t BlockNumber)
{
- uint8_t BlockBuffer[512];
+ uint8_t BlockBuffer[SECTOR_SIZE_BYTES];
memset(BlockBuffer, 0x00, sizeof(BlockBuffer));
switch (BlockNumber)
diff --git a/Bootloaders/Incomplete/MassStorage/makefile b/Bootloaders/Incomplete/MassStorage/makefile
index 532f9f24f..c922b9d7b 100644
--- a/Bootloaders/Incomplete/MassStorage/makefile
+++ b/Bootloaders/Incomplete/MassStorage/makefile
@@ -14,7 +14,7 @@
MCU = at90usb1287
ARCH = AVR8
BOARD = USBKEY
-F_CPU = 16000000
+F_CPU = 8000000
F_USB = $(F_CPU)
OPTIMIZATION = s
TARGET = BootloaderMassStorage