move usb hardware init and tud_init into usb device thread

help to prevent USB IRQ when scheduler is not started yet
This commit is contained in:
hathach committed 2020-07-23 07:45:09 +07:00
1 parent ca4f2bcbb4
commit cb6d216c9c
2 files changed
+29 -29

No files matched your search

+25 -25
View File
@@ -30,6 +30,16 @@
#include "Arduino.h"
#include "Adafruit_TinyUSB_Core.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
#define USBD_STACK_SZ (200)
// tinyusb function that handles power event (detected, ready, removed)
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
extern "C" void tusb_hal_nrf_power_event(uint32_t event);
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
@@ -46,30 +56,6 @@ extern "C" void USBD_IRQHandler(void)
#endif
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
#define USBD_STACK_SZ (200)
// tinyusb function that handles power event (detected, ready, removed)
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
extern "C" void tusb_hal_nrf_power_event(uint32_t event);
// USB Device Driver task
// This top level thread process all usb events and invoke callbacks
static void usb_device_task(void* param)
{
(void) param;
// RTOS forever loop
while (1)
{
// tinyusb device task
tud_task();
}
}
//--------------------------------------------------------------------+
// Core Init & Touch1200
//--------------------------------------------------------------------+
@@ -99,8 +85,12 @@ static void usb_hardware_init(void)
if ( usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
}
void Adafruit_TinyUSB_Core_init(void)
// USB Device Driver task
// This top level thread process all usb events and invoke callbacks
static void usb_device_task(void* param)
{
(void) param;
USBDevice.addInterface( (Adafruit_USBD_Interface&) Serial);
USBDevice.setID(USB_VID, USB_PID);
USBDevice.begin();
@@ -110,6 +100,16 @@ void Adafruit_TinyUSB_Core_init(void)
// Init tinyusb stack
tusb_init();
// RTOS forever loop
while (1)
{
// tinyusb device task
tud_task();
}
}
void Adafruit_TinyUSB_Core_init(void)
{
// Create a task for tinyusb device stack
xTaskCreate( usb_device_task, "usbd", USBD_STACK_SZ, NULL, TASK_PRIO_HIGH, NULL);
}
+4 -4
View File
@@ -44,10 +44,6 @@ static void loop_task(void* arg)
{
(void) arg;
#ifdef USE_TINYUSB
Adafruit_TinyUSB_Core_init();
#endif
#if CFG_DEBUG
// If Serial is not begin(), call it to avoid hard fault
if(!Serial) Serial.begin(115200);
@@ -80,6 +76,10 @@ int main( void )
SEGGER_SYSVIEW_Conf();
#endif
#ifdef USE_TINYUSB
Adafruit_TinyUSB_Core_init();
#endif
// Create a task for loop()
xTaskCreate( loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);