cdc work with test code

This commit is contained in:
hathach 2018-04-04 20:03:56 +07:00
parent a80e029ae1
commit f18643ae10
4 changed files with 36 additions and 21 deletions

@ -1 +1 @@
Subproject commit 7a77aed8fa67cf6740943cf25a00485d4f288cfb Subproject commit b6accc622b3a307e8fd5559a215401f1d704a5f4

View File

@ -34,22 +34,6 @@
#define bit(b) (1UL << (b)) #define bit(b) (1UL << (b))
static inline uint32_t bit_set(uint32_t value, uint8_t n)
{
return value | bit(n);
}
static inline uint32_t bit_clear(uint32_t value, uint8_t n)
{
return value & (~bit(n));
}
static inline bool bit_test(uint32_t value, uint8_t n)
{
return (value & bit(n)) ? true : false;
}
void led_control(uint32_t pin, bool state); void led_control(uint32_t pin, bool state);
static inline void led_on(uint32_t pin) static inline void led_on(uint32_t pin)

View File

@ -57,6 +57,8 @@
#include "nrf_delay.h" #include "nrf_delay.h"
#include "pstorage.h" #include "pstorage.h"
#include "tusb.h"
#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0] #define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
@ -334,7 +336,6 @@ int main(void)
/* Initialize a blinky timer to show that we're in bootloader */ /* Initialize a blinky timer to show that we're in bootloader */
(void) app_timer_create(&blinky_timer_id, APP_TIMER_MODE_REPEATED, blinky_handler); (void) app_timer_create(&blinky_timer_id, APP_TIMER_MODE_REPEATED, blinky_handler);
app_timer_start(blinky_timer_id, APP_TIMER_TICKS(LED_BLINK_INTERVAL), NULL);
// Init bootloader and SD // Init bootloader and SD
(void) bootloader_init(); (void) bootloader_init();
@ -345,6 +346,7 @@ int main(void)
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
ble_stack_init(!sd_inited); ble_stack_init(!sd_inited);
app_timer_start(blinky_timer_id, APP_TIMER_TICKS(LED_BLINK_INTERVAL), NULL);
err_code = bootloader_dfu_sd_update_finalize(); err_code = bootloader_dfu_sd_update_finalize();
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
@ -352,6 +354,30 @@ int main(void)
else else
{ {
ble_stack_init(!sd_inited); ble_stack_init(!sd_inited);
app_timer_start(blinky_timer_id, APP_TIMER_TICKS(LED_BLINK_INTERVAL), NULL);
}
// Init usb stack
tusb_init();
// TODO temporarily code to test usb cdc
while( true )
{
sd_app_evt_wait();
app_sched_execute();
tusb_task();
// connected and there are data available -> echo back
if ( tud_mounted() && tud_cdc_available() )
{
uint8_t buf[64];
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
tud_cdc_write(buf, count);
}
} }
/*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/ /*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/
@ -480,7 +506,7 @@ void adafruit_factory_reset(void)
} }
static inline void verify_breakpoint(void) static inline void halt_breakpoint(void)
{ {
// Cortex M CoreDebug->DHCSR // Cortex M CoreDebug->DHCSR
volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL);
@ -491,7 +517,7 @@ static inline void verify_breakpoint(void)
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{ {
verify_breakpoint(); halt_breakpoint();
NVIC_SystemReset(); NVIC_SystemReset();
} }
@ -586,8 +612,10 @@ void ada_soc_task(void* evt_data, uint16_t evt_size)
if (NRF_SUCCESS == err) if (NRF_SUCCESS == err)
{ {
// Flash is the only soc event extern void power_usb_event_handler(uint32_t evt);
pstorage_sys_event_handler(soc_evt); pstorage_sys_event_handler(soc_evt);
power_usb_event_handler(soc_evt);
} }
} }
} }

View File

@ -273,6 +273,9 @@
<file file_name="../metro52.h" /> <file file_name="../metro52.h" />
<file file_name="../pstorage_platform.h" /> <file file_name="../pstorage_platform.h" />
<file file_name="../sdk_config.h" /> <file file_name="../sdk_config.h" />
<file file_name="../tusb_config.h" />
<file file_name="../tusb_descriptors.c" />
<file file_name="../tusb_descriptors.h" />
</folder> </folder>
<configuration <configuration
Name="Debug" Name="Debug"