Skip to content

Commit

Permalink
Merge pull request #38 from adafruit/devlocal
Browse files Browse the repository at this point in the history
fix current.uf2 related issue
  • Loading branch information
dhalbert authored Dec 21, 2018
2 parents 5c38bc8 + a316c8b commit 61b4ca3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ pip3 install --user adafruit-nrfutil

This repository depends on the following submodules:

- [tinyusb](https://github.com/hathach/tinyusb/tree/develop)
- [tinyusb](https://github.com/hathach/tinyusb)
- [nrfx](https://github.com/NordicSemiconductor/nrfx)

Note that `tinyusb` also includes `nrfx` as a submodule, so you need
Expand Down
11 changes: 9 additions & 2 deletions src/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void board_init(void)
app_timer_init();

// Configure Systick for led blinky
NVIC_SetPriority(SysTick_IRQn, 7);
extern uint32_t SystemCoreClock;
SysTick_Config(SystemCoreClock/1000);
}
Expand Down Expand Up @@ -346,9 +347,11 @@ void neopixel_init(void)
void neopixel_teardown(void)
{
uint8_t grb[3] = { 0, 0, 0 };
neopixel_write(grb);

NRFX_DELAY_US(100);
NRFX_DELAY_US(50); // wait for previous write is complete

neopixel_write(grb);
NRFX_DELAY_US(50); // wait for this write

pwm_teardown(NRF_PWM2);
}
Expand Down Expand Up @@ -380,6 +383,10 @@ void neopixel_write (uint8_t *pixels)
nrf_pwm_seq_cnt_set(pwm, 0, sizeof(pixels_pattern)/2);
nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
nrf_pwm_task_trigger(pwm, NRF_PWM_TASK_SEQSTART0);

// no need to blocking wait for sequence complete
// while( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {}
// nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
}
#endif

Expand Down
19 changes: 14 additions & 5 deletions src/usb/uf2/ghostfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static struct TextFile const info[] = {
};
#define NUM_INFO (sizeof(info) / sizeof(info[0]))

#define UF2_SIZE (get_flash_size() * 2)
#define UF2_SIZE (current_flash_size() * 2)
#define UF2_SECTORS (UF2_SIZE / 512)
#define UF2_FIRST_SECTOR (NUM_INFO + 1)
#define UF2_LAST_SECTOR (UF2_FIRST_SECTOR + UF2_SECTORS - 1)
Expand Down Expand Up @@ -120,7 +120,9 @@ static FAT_BootBlock const BootBlock = {
#define NRF_LOG_WARNING(...)

static WriteState _wr_state = { 0 };
static uint32_t get_flash_size(void)

// get current.uf2 flash size in bytes, round up to 256 bytes
static uint32_t current_flash_size(void)
{
static uint32_t flash_sz = 0;

Expand All @@ -136,10 +138,17 @@ static uint32_t get_flash_size(void)
bootloader_settings_t const * boot_setting;
bootloader_util_settings_get(&boot_setting);

flash_sz = boot_setting->bank_0_size;

// Copy size must be multiple of 256 bytes
// else we will got an issue copying current.uf2
if (flash_sz & 0xff)
{
flash_sz = (flash_sz & ~0xff) + 256;
}

// if bank0 size is not valid, happens when flashed with jlink
// use maximum application size

flash_sz = boot_setting->bank_0_size;
if ( (flash_sz == 0) || (flash_sz == 0xFFFFFFFFUL) )
{
flash_sz = FLASH_SIZE;
Expand Down Expand Up @@ -217,7 +226,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
bl->magicStart1 = UF2_MAGIC_START1;
bl->magicEnd = UF2_MAGIC_END;
bl->blockNo = sectionIdx;
bl->numBlocks = FLASH_SIZE / 256;
bl->numBlocks = current_flash_size() / 256;
bl->targetAddr = addr;
bl->payloadSize = 256;
bl->flags = UF2_FLAG_FAMILYID;
Expand Down

0 comments on commit 61b4ca3

Please sign in to comment.