]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Fixing bugs in mk20dx128vlf5 support
authorJacob Alexander <haata@kiibohd.com>
Tue, 26 May 2015 00:50:32 +0000 (17:50 -0700)
committerJacob Alexander <haata@kiibohd.com>
Sun, 14 Jun 2015 21:33:40 +0000 (14:33 -0700)
Bootloader/CMakeLists.txt
Bootloader/flash.c
Bootloader/main.c

index 7a938d93f1bfcc5818b15bf17f9ba50f1d456ba7..41c2bccb1ffcc790cffc0125a1b01e0d8ffcf091 100644 (file)
@@ -60,7 +60,6 @@ include( initialize )
 #
 set( SRCS
        main.c
-       debug.c # TODO only compile in if necessary
        dfu.c
        dfu.desc.c
        flash.c
@@ -68,6 +67,14 @@ set( SRCS
        usb.c
 )
 
+# Only compile in if necessary
+if( CHIP STREQUAL "mk20dx256vlh7" )
+       set( SRCS ${SRCS}
+               debug.c
+       )
+endif()
+
+
 message( STATUS "Bootloader Source Files:" )
 message( "${SRCS}" )
 
index 349a44e3a052160bb24c3684b0a04afb45a323ab..d04cf382947d321ff550fa846d86b65c622f5af0 100644 (file)
@@ -101,15 +101,20 @@ int flash_program_section_phrases( uintptr_t addr, size_t num_phrases )
 
 int flash_program_sector( uintptr_t addr, size_t len )
 {
-#if defined(_mk20dx128vlf5_)
-       return (len != FLASH_SECTOR_SIZE
-               || (addr & (FLASH_SECTOR_SIZE - 1)) != 0
-               || flash_erase_sector( addr )
-               || flash_program_section_longwords( addr, FLASH_SECTOR_SIZE / 4 ));
-#elif defined(_mk20dx256vlh7_)
        if ( len != FLASH_SECTOR_SIZE )
                return 1;
 
+#if defined(_mk20dx128vlf5_)
+       // Check if this is the beginning of a sector
+       // Only erase if necessary
+       if ( (addr & (FLASH_SECTOR_SIZE - 1)) == 0
+               && flash_read_1s_sector( addr, FLASH_SECTOR_SIZE / 4 )
+               && flash_erase_sector( addr ) )
+                       return 1;
+
+       // Program sector
+       return flash_program_section_longwords( addr, FLASH_SECTOR_SIZE / 4 );
+#elif defined(_mk20dx256vlh7_)
        // Check if beginning of sector and erase if not empty
        // Each sector is 2 kB in length, but we can only write to half a sector at a time
        // We can only erase an entire sector at a time
index 303ea35576941c54f81d0c35bf4f15d7f1402eec..8ca8d28fce626306d2a0ba8c7120d3a9bbc4588e 100644 (file)
@@ -36,7 +36,7 @@ static char staging[ USB_DFU_TRANSFER_SIZE ];
 
 // ----- Functions -----
 
-void sector_print( void* buf, size_t sector, size_t chunks )
+int sector_print( void* buf, size_t sector, size_t chunks )
 {
        uint8_t* start = (uint8_t*)buf + sector * USB_DFU_TRANSFER_SIZE;
        uint8_t* end = (uint8_t*)buf + (sector + 1) * USB_DFU_TRANSFER_SIZE;
@@ -79,6 +79,8 @@ void sector_print( void* buf, size_t sector, size_t chunks )
 
                print( NL );
        }
+
+       return retval;
 }
 
 static enum dfu_status setup_read( size_t off, size_t *len, void **buf )
@@ -133,9 +135,6 @@ static enum dfu_status finish_write( void *buf, size_t off, size_t len )
        if ( !target )
                return (DFU_STATUS_errADDRESS);
        memcpy( target, buf, len );
-       print("BUF: ");
-       printHex( off );
-       sector_print( target, 0, 16 );
 
        // Depending on the error return a different status
        switch ( flash_program_sector(off + (uintptr_t)&_app_rom, FLASH_SECTOR_SIZE) )