Skip to content

Commit 61b4ca3

Browse files
authored
Merge pull request #38 from adafruit/devlocal
fix current.uf2 related issue
2 parents 5c38bc8 + a316c8b commit 61b4ca3

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $ pip3 install --user adafruit-nrfutil
2626

2727
This repository depends on the following submodules:
2828

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

3232
Note that `tinyusb` also includes `nrfx` as a submodule, so you need

src/boards.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void board_init(void)
8282
app_timer_init();
8383

8484
// Configure Systick for led blinky
85+
NVIC_SetPriority(SysTick_IRQn, 7);
8586
extern uint32_t SystemCoreClock;
8687
SysTick_Config(SystemCoreClock/1000);
8788
}
@@ -346,9 +347,11 @@ void neopixel_init(void)
346347
void neopixel_teardown(void)
347348
{
348349
uint8_t grb[3] = { 0, 0, 0 };
349-
neopixel_write(grb);
350350

351-
NRFX_DELAY_US(100);
351+
NRFX_DELAY_US(50); // wait for previous write is complete
352+
353+
neopixel_write(grb);
354+
NRFX_DELAY_US(50); // wait for this write
352355

353356
pwm_teardown(NRF_PWM2);
354357
}
@@ -380,6 +383,10 @@ void neopixel_write (uint8_t *pixels)
380383
nrf_pwm_seq_cnt_set(pwm, 0, sizeof(pixels_pattern)/2);
381384
nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
382385
nrf_pwm_task_trigger(pwm, NRF_PWM_TASK_SEQSTART0);
386+
387+
// no need to blocking wait for sequence complete
388+
// while( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {}
389+
// nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
383390
}
384391
#endif
385392

src/usb/uf2/ghostfat.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static struct TextFile const info[] = {
8383
};
8484
#define NUM_INFO (sizeof(info) / sizeof(info[0]))
8585

86-
#define UF2_SIZE (get_flash_size() * 2)
86+
#define UF2_SIZE (current_flash_size() * 2)
8787
#define UF2_SECTORS (UF2_SIZE / 512)
8888
#define UF2_FIRST_SECTOR (NUM_INFO + 1)
8989
#define UF2_LAST_SECTOR (UF2_FIRST_SECTOR + UF2_SECTORS - 1)
@@ -120,7 +120,9 @@ static FAT_BootBlock const BootBlock = {
120120
#define NRF_LOG_WARNING(...)
121121

122122
static WriteState _wr_state = { 0 };
123-
static uint32_t get_flash_size(void)
123+
124+
// get current.uf2 flash size in bytes, round up to 256 bytes
125+
static uint32_t current_flash_size(void)
124126
{
125127
static uint32_t flash_sz = 0;
126128

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

141+
flash_sz = boot_setting->bank_0_size;
142+
143+
// Copy size must be multiple of 256 bytes
144+
// else we will got an issue copying current.uf2
145+
if (flash_sz & 0xff)
146+
{
147+
flash_sz = (flash_sz & ~0xff) + 256;
148+
}
149+
139150
// if bank0 size is not valid, happens when flashed with jlink
140151
// use maximum application size
141-
142-
flash_sz = boot_setting->bank_0_size;
143152
if ( (flash_sz == 0) || (flash_sz == 0xFFFFFFFFUL) )
144153
{
145154
flash_sz = FLASH_SIZE;
@@ -217,7 +226,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
217226
bl->magicStart1 = UF2_MAGIC_START1;
218227
bl->magicEnd = UF2_MAGIC_END;
219228
bl->blockNo = sectionIdx;
220-
bl->numBlocks = FLASH_SIZE / 256;
229+
bl->numBlocks = current_flash_size() / 256;
221230
bl->targetAddr = addr;
222231
bl->payloadSize = 256;
223232
bl->flags = UF2_FLAG_FAMILYID;

0 commit comments

Comments
 (0)