Merge pull request #36 from adafruit/devlocal

fixed the incosnsitent led pattern by using systick to call led_tick()
This commit is contained in:
hathach 2018-12-19 18:43:40 +07:00 committed by GitHub
commit fd924b4c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 39 deletions

View File

@ -7,31 +7,28 @@
# - SD_VER1, SD_VER2, SD_VER3: SoftDevice version e.g 6.0.0
# - SD_HEX : to bootloader hex binary
#******************************************************************************
SRC_PATH = src
SRC_PATH = src
SDK_PATH = lib/sdk/components
SDK11_PATH = lib/sdk11/components
SD_PATH = lib/softdevice/$(SD_FILENAME)
SDK_PATH = lib/sdk/components
SDK11_PATH = lib/sdk11/components
SD_PATH = lib/softdevice/$(SD_FILENAME)
TUSB_PATH = lib/tinyusb/src
NRFX_PATH = lib/nrfx
TUSB_PATH = lib/tinyusb/src
NRFX_PATH = lib/nrfx
SD_VER1 = 6
SD_VER2 = 1
SD_VER3 = 1
SD_VER1 = 6
SD_VER2 = 1
SD_VER3 = 1
SD_VERSION = $(SD_VER1).$(SD_VER2).$(SD_VER3)
SD_VERSION_FULL = $(SD_VERSION)
SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION)
SD_VERSION = $(SD_VER1).$(SD_VER2).$(SD_VER3)
SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION)
SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API
SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(SD_VER1).ld
SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API
SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(SD_VER1).ld
MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION_FULL)
RELEASE_DIR = bin/$(BOARD)/$(SD_VERSION_FULL)
MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION)
RELEASE_DIR = bin/$(BOARD)/$(SD_VERSION)
MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION)"
@ -45,7 +42,6 @@ OUTPUT_FILENAME = $(BOARD)_bootloader-$(GIT_VERSION)
#******************************************************************************
NRFUTIL = adafruit-nrfutil
ifneq ($(JLINK),)
NRFJPROG = nrfjprog -s $(JLINK)
else
@ -475,7 +471,6 @@ $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out
@echo CR $(OUTPUT_FILENAME)-nosd.hex
$(QUIET)$(OBJCOPY) -O ihex $< $@
# merge bootloader and sd hex together
combinehex: $(BUILD)/$(MERGED_FNAME).hex

View File

@ -3,7 +3,7 @@
This is a CDC/DFU/UF2 bootloader for nRF52 boards.
- [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406)
- Adafruit Feather nRF52840 Express
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
- Nordic nRF52840DK PCA10056
- Nordic nRF52840DK PCA10059 ("Dongle")
- Particle Argon

View File

@ -136,8 +136,6 @@ static void wait_for_events(void)
}
#endif
led_tick();
if ((m_update_status == BOOTLOADER_COMPLETE) ||
(m_update_status == BOOTLOADER_TIMEOUT) ||
(m_update_status == BOOTLOADER_RESET) )

View File

@ -80,10 +80,17 @@ void board_init(void)
// Init app timer (use RTC1)
app_timer_init();
// Configure Systick for led blinky
extern uint32_t SystemCoreClock;
SysTick_Config(SystemCoreClock/1000);
}
void board_teardown(void)
{
// Disable systick, turn off LEDs
SysTick->CTRL = 0;
// Disable and reset PWM for LEDs
led_pwm_teardown();
@ -104,12 +111,20 @@ void board_teardown(void)
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
}
static uint32_t _systick_count = 0;
void SysTick_Handler(void)
{
_systick_count++;
led_tick();
}
uint32_t tusb_hal_millis(void)
{
return ( ( ((uint64_t)app_timer_cnt_get())*1000*(APP_TIMER_CONFIG_RTC_FREQUENCY+1)) / APP_TIMER_CLOCK_FREQ );
}
void pwm_teardown(NRF_PWM_Type* pwm )
{
pwm->TASKS_SEQSTART[0] = 0;
@ -126,7 +141,7 @@ void pwm_teardown(NRF_PWM_Type* pwm )
pwm->SEQ[0].CNT = 0;
}
static uint16_t led_duty_cycles[PWM0_CH_NUM];
static uint16_t led_duty_cycles[PWM0_CH_NUM] = { 0 };
#if LEDS_NUMBER > PWM0_CH_NUM
#error "Only " PWM0_CH_NUM " concurrent status LEDs are supported."
@ -136,10 +151,13 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin)
{
NRF_PWM_Type* pwm = NRF_PWM0;
pwm->ENABLE = 0;
nrf_gpio_cfg_output(led_pin);
nrf_gpio_pin_write(led_pin, 1 - LED_STATE_ON);
pwm->PSEL.OUT[led_index] = led_pin;
pwm->ENABLE = 1;
pwm->MODE = PWM_MODE_UPDOWN_Up;
pwm->COUNTERTOP = 0xff;
pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_16;
@ -150,8 +168,11 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin)
pwm->SEQ[0].CNT = 4; // default mode is Individual --> count must be 4
pwm->SEQ[0].REFRESH = 0;
pwm->SEQ[0].ENDDELAY = 0;
pwm->LOOP = 0;
pwm->TASKS_SEQSTART[0] = 1;
pwm->ENABLE = 1;
pwm->EVENTS_SEQEND[0] = 0;
// pwm->TASKS_SEQSTART[0] = 1;
}
void led_pwm_teardown(void)
@ -171,7 +192,7 @@ static uint32_t primary_cycle_length;
static uint32_t secondary_cycle_length;
#endif
void led_tick() {
uint32_t millis = tusb_hal_millis();
uint32_t millis = _systick_count;
uint32_t cycle = millis % primary_cycle_length;
uint32_t half_cycle = primary_cycle_length / 2;
@ -207,19 +228,25 @@ void led_state(uint32_t state)
switch (state) {
case STATE_USB_MOUNTED:
new_rgb_color = 0x00ff00;
primary_cycle_length = 4000;
primary_cycle_length = 3000;
break;
case STATE_BOOTLOADER_STARTED:
case STATE_USB_UNMOUNTED:
new_rgb_color = 0xff0000;
primary_cycle_length = 300;
break;
case STATE_WRITING_STARTED:
temp_color = 0xff0000;
primary_cycle_length = 100;
break;
case STATE_WRITING_FINISHED:
// Empty means to unset any temp colors.
primary_cycle_length = 3000;
break;
case STATE_BLE_CONNECTED:
new_rgb_color = 0x0000ff;
#ifdef LED_SECONDARY_PIN
@ -228,6 +255,7 @@ void led_state(uint32_t state)
primary_cycle_length = 500;
#endif
break;
case STATE_BLE_DISCONNECTED:
new_rgb_color = 0xff00ff;
#ifdef LED_SECONDARY_PIN
@ -236,6 +264,7 @@ void led_state(uint32_t state)
primary_cycle_length = 300;
#endif
break;
default:
break;
}
@ -260,7 +289,7 @@ void led_state(uint32_t state)
#endif
}
#if LED_NEOPIXEL
#ifdef LED_NEOPIXEL
// WS2812B (rev B) timing is 0.4 and 0.8 us
#define MAGIC_T0H 6UL | (0x8000) // 0.375us

View File

@ -108,8 +108,6 @@ static inline bool button_pressed(uint32_t pin)
return (nrf_gpio_pin_read(pin) == 0) ? true : false;
}
bool is_ota(void);
#endif

View File

@ -71,7 +71,7 @@ void usb_teardown(void);
#else
#define usb_init(x)
#define usb_init(x) led_state(STATE_USB_MOUNTED) // mark nrf52832 as mounted
#define usb_teardown()
#endif
@ -167,6 +167,8 @@ int main(void)
board_init();
bootloader_init();
led_state(STATE_BOOTLOADER_STARTED);
// When updating SoftDevice, bootloader will reset before swapping SD
if (bootloader_dfu_sd_in_progress())
{
@ -209,8 +211,6 @@ int main(void)
(*dbl_reset_mem) = 0;
led_state(STATE_BOOTLOADER_STARTED);
if ( dfu_start || !valid_app )
{
if ( _ota_dfu )
@ -222,7 +222,6 @@ int main(void)
else
{
led_state(STATE_USB_UNMOUNTED);
// otherwise USB for Serial & UF2
usb_init(serial_only_dfu);
}

View File

@ -18,7 +18,7 @@
arm_target_debug_interface_type="ADIv5"
arm_target_device_name="nRF52840_xxAA"
arm_target_interface_type="SWD"
c_preprocessor_definitions="__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;MK_BOOTLOADER_VERSION=0x06010000;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD;CFG_TUSB_DEBUG=2"
c_preprocessor_definitions="__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;MK_BOOTLOADER_VERSION=0x06010000;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD;CFG_TUSB_DEBUG=2;UF2_VERSION=&quot;Segger&quot;"
c_user_include_directories="../;../usb;../cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(sdDir)/include;$(sdDir)/include/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj"
debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml"
debug_target_connection="J-Link"