This commit is contained in:
hathach 2018-06-21 11:28:04 +07:00
parent 19eb8652e7
commit 2ce43e643b
2 changed files with 10 additions and 24 deletions

View File

@ -4,6 +4,7 @@
#include <string.h> #include <string.h>
#include "tusb.h" #include "tusb.h"
#if 1
typedef struct { typedef struct {
uint8_t JumpInstruction[3]; uint8_t JumpInstruction[3];
uint8_t OEMInfo[8]; uint8_t OEMInfo[8];
@ -157,6 +158,8 @@ void flushFlash() {
flashAddr = NO_CACHE; flashAddr = NO_CACHE;
} }
void flash_write(uint32_t dst, const uint8_t *src, int len) { void flash_write(uint32_t dst, const uint8_t *src, int len) {
uint32_t newAddr = dst & ~(FLASH_PAGE_SIZE - 1); uint32_t newAddr = dst & ~(FLASH_PAGE_SIZE - 1);
@ -243,7 +246,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
memcpy(data, info[sectionIdx].content, strlen(info[sectionIdx].content)); memcpy(data, info[sectionIdx].content, strlen(info[sectionIdx].content));
} else { } else {
sectionIdx -= NUM_INFO - 1; sectionIdx -= NUM_INFO - 1;
uint32_t addr = sectionIdx * 256; uint32_t addr = USER_FLASH_START + sectionIdx * 256;
if (addr < FLASH_SIZE) { if (addr < FLASH_SIZE) {
UF2_Block *bl = (void *)data; UF2_Block *bl = (void *)data;
bl->magicStart0 = UF2_MAGIC_START0; bl->magicStart0 = UF2_MAGIC_START0;
@ -259,27 +262,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
} }
} }
int32_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) #if 0
{
(void) rhport; (void) lun;
// since we return block size each, offset should always be zero
TU_ASSERT(offset == 0, -1);
uint32_t count = 0;
while ( count < bufsize )
{
read_block(lba, buffer);
lba++;
buffer += 512;
count += 512;
}
return count;
}
void write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state) { void write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state) {
UF2_Block *bl = (void *)data; UF2_Block *bl = (void *)data;
@ -337,3 +320,6 @@ void write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state
// uf2_timer_start(500); // uf2_timer_start(500);
} }
} }
#endif
#endif

View File

@ -3,8 +3,8 @@
#define BOARD_ID "NRF52-Bluefruit-v0" #define BOARD_ID "NRF52-Bluefruit-v0"
#define INDEX_URL "https://www.adafruit.com/product/0000" #define INDEX_URL "https://www.adafruit.com/product/0000"
#define UF2_NUM_BLOCKS 8000 #define UF2_NUM_BLOCKS 8000
#define VOLUME_LABEL "NRFBOOT" #define VOLUME_LABEL "NRF52BOOT"
#define FLASH_SIZE (1024*1024) #define FLASH_SIZE (BOOTLOADER_REGION_START-USER_FLASH_START)
// Only allow to write application // Only allow to write application
#define USER_FLASH_START 0x26000 #define USER_FLASH_START 0x26000