rename FLASH_SIZE to CFG_UF2_FLASH_SIZE, make it whole flash = 1MB

also rename UF2_NUM_BLOCKS to CFG_UF2_NUM_BLOCKS
This commit is contained in:
hathach
2020-03-27 17:36:51 +07:00
parent 3ee1955e1b
commit 632e4611bf
4 changed files with 18 additions and 8 deletions
+1 -1
View File
@@ -194,7 +194,7 @@ void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_siz
{
(void) lun;
*block_count = UF2_NUM_BLOCKS;
*block_count = CFG_UF2_NUM_BLOCKS;
*block_size = 512;
}
+14 -4
View File
@@ -61,7 +61,7 @@ struct TextFile {
//
//--------------------------------------------------------------------+
#define NUM_FAT_BLOCKS UF2_NUM_BLOCKS
#define NUM_FAT_BLOCKS CFG_UF2_NUM_BLOCKS
#define STR0(x) #x
#define STR(x) STR0(x)
@@ -200,7 +200,7 @@ static uint32_t current_flash_size(void)
// use maximum application size
if ( (flash_sz == 0) || (flash_sz == 0xFFFFFFFFUL) )
{
flash_sz = FLASH_SIZE;
flash_sz = (USER_FLASH_END-USER_FLASH_START);
}
}
@@ -299,7 +299,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
} else { // generate the UF2 file data on-the-fly
sectionIdx -= NUM_FILES - 1;
uint32_t addr = USER_FLASH_START + sectionIdx * 256;
if (addr < USER_FLASH_START+FLASH_SIZE) {
if (addr < CFG_UF2_FLASH_SIZE) {
UF2_Block *bl = (void *)data;
bl->magicStart0 = UF2_MAGIC_START0;
bl->magicStart1 = UF2_MAGIC_START1;
@@ -320,7 +320,14 @@ void read_block(uint32_t block_no, uint8_t *data) {
/* Write UF2
*------------------------------------------------------------------*/
/** Write an block
/**
* Write an uf2 block wrapped by 512 sector. Writing behavior is different when upgrading:
* - Application
* - current App is erased and flash with new firmware with same starting address
*
* - SoftDevice + Bootloader
* - Current App is erased, contents of SD + bootloader is written to App starting address
* - Trigger the SD + Bootloader migration
*
* @return number of bytes processed, only 3 following values
* -1 : if not an uf2 block
@@ -341,6 +348,9 @@ int write_block (uint32_t block_no, uint8_t *data, WriteState *state)
return -1;
}
// if ( (bl->familyID == CFG_UF2_FAMILY_ID) && in_app_space(bl->targetAddr) )
if ( (bl->targetAddr < USER_FLASH_START) || (bl->targetAddr + bl->payloadSize > USER_FLASH_END) )
{
+1 -1
View File
@@ -51,7 +51,7 @@ SOFTWARE.
#define UF2_FLAG_NOFLASH 0x00000001
#define UF2_FLAG_FAMILYID 0x00002000
#define MAX_BLOCKS (FLASH_SIZE / 256 + 100)
#define MAX_BLOCKS (CFG_UF2_FLASH_SIZE / 256 + 100)
typedef struct {
uint32_t numBlocks;
uint32_t numWritten;
+2 -2
View File
@@ -1,7 +1,7 @@
#include "boards.h"
#define UF2_NUM_BLOCKS 8000 // at least 4,1 MB for FAT16
#define FLASH_SIZE (USER_FLASH_END-USER_FLASH_START) // Max flash size
#define CFG_UF2_NUM_BLOCKS 8000 // at least 4,1 MB for FAT16
#define CFG_UF2_FLASH_SIZE (1024*1024) // 1 MB
// Only allow to write application TODO dynamic depending on SD size
#define USER_FLASH_START (SD_FLASH_SIZE + MBR_SIZE)