This commit is contained in:
hathach 2018-06-20 13:18:14 +07:00
parent 3f8fba843c
commit 4560d69010
2 changed files with 28 additions and 6 deletions

View File

@ -1,12 +1,8 @@
#include "uf2.h" #include "uf2.h"
#include "nrf_log.h"
#include "nrf_nvmc.h" #include "nrf_nvmc.h"
#include "nrf_sdh.h"
#include "nrf_dfu_settings.h"
#include <string.h> #include <string.h>
#include "tusb.h"
typedef struct { typedef struct {
uint8_t JumpInstruction[3]; uint8_t JumpInstruction[3];
@ -115,11 +111,14 @@ static const FAT_BootBlock BootBlock = {
#define NO_CACHE 0xffffffff #define NO_CACHE 0xffffffff
#define NRF_LOG_DEBUG(...)
uint32_t flashAddr = NO_CACHE; uint32_t flashAddr = NO_CACHE;
uint8_t flashBuf[FLASH_PAGE_SIZE] __attribute__((aligned(4))); uint8_t flashBuf[FLASH_PAGE_SIZE] __attribute__((aligned(4)));
bool firstFlush = true; bool firstFlush = true;
bool hadWrite = false; bool hadWrite = false;
#if 0
void flushFlash() { void flushFlash() {
if (flashAddr == NO_CACHE) if (flashAddr == NO_CACHE)
return; return;
@ -186,6 +185,7 @@ void uf2_timer(void *p_context) {
} }
void uf2_timer_start(int ms); void uf2_timer_start(int ms);
#endif
void padded_memcpy(char *dst, const char *src, int len) { void padded_memcpy(char *dst, const char *src, int len) {
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
@ -197,6 +197,7 @@ void padded_memcpy(char *dst, const char *src, int len) {
} }
} }
void read_block(uint32_t block_no, uint8_t *data) { void read_block(uint32_t block_no, uint8_t *data) {
memset(data, 0, 512); memset(data, 0, 512);
uint32_t sectionIdx = block_no; uint32_t sectionIdx = block_no;
@ -258,6 +259,27 @@ 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)
{
(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;

View File

@ -8,7 +8,7 @@
#include "app_util.h" #include "app_util.h"
#include "nrf_bootloader_info.h" #include "dfu_types.h"
#define SD_MAGIC_NUMBER 0x51b1e5db #define SD_MAGIC_NUMBER 0x51b1e5db
#define SD_MAGIC_OK() (*((uint32_t*)(SOFTDEVICE_INFO_STRUCT_ADDRESS+4)) == 0x51b1e5db) #define SD_MAGIC_OK() (*((uint32_t*)(SOFTDEVICE_INFO_STRUCT_ADDRESS+4)) == 0x51b1e5db)