summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/device/cdc_msc_hid/src/main.c39
-rw-r--r--examples/device/cdc_msc_hid_freertos/ses/nrf5x/nrf5x.emProject3
-rw-r--r--examples/device/cdc_msc_hid_freertos/src/main.c65
-rw-r--r--examples/device/cdc_msc_hid_freertos/src/tusb_config.h8
-rw-r--r--examples/host/cdc_msc_hid/src/tusb_config.h14
-rw-r--r--examples/obsolete/device/src/tusb_config.h3
6 files changed, 45 insertions, 87 deletions
diff --git a/examples/device/cdc_msc_hid/src/main.c b/examples/device/cdc_msc_hid/src/main.c
index bc260fdfa..178609e1e 100644
--- a/examples/device/cdc_msc_hid/src/main.c
+++ b/examples/device/cdc_msc_hid/src/main.c
@@ -46,7 +46,6 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
-void print_greeting(void);
void led_blinking_task(void);
extern void virtual_com_task(void);
@@ -56,7 +55,6 @@ extern void usb_hid_task(void);
int main(void)
{
board_init();
- print_greeting();
tusb_init();
@@ -84,9 +82,9 @@ int main(void)
#if CFG_TUD_CDC
void virtual_com_task(void)
{
- // connected and there are data available
if ( tud_cdc_connected() )
{
+ // connected and there are data available
if ( tud_cdc_available() )
{
uint8_t buf[64];
@@ -98,11 +96,7 @@ void virtual_com_task(void)
{
tud_cdc_write_char(buf[i]);
- if ( buf[i] == '\r' )
- {
- tud_cdc_write_char('\n');
- tud_cdc_write_str("tinyusb cdc: ");
- }
+ if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
}
tud_cdc_write_flush();
@@ -117,8 +111,8 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
// connected
if ( dtr && rts )
{
- // print greeting
- tud_cdc_write_str("tinyusb cdc: ");
+ // print initial message when connected
+ tud_cdc_write_str("\r\nTinyUSB CDC MSC HID device example\r\n");
}
}
#endif
@@ -213,28 +207,3 @@ void led_blinking_task(void)
board_led_control(led_state);
led_state = 1 - led_state; // toggle
}
-
-//--------------------------------------------------------------------+
-// HELPER FUNCTION
-//--------------------------------------------------------------------+
-void print_greeting(void)
-{
- char const * const rtos_name[] =
- {
- [OPT_OS_NONE] = "None",
- [OPT_OS_FREERTOS] = "FreeRTOS",
- };
-
- printf("\n--------------------------------------------------------------------\n");
- printf("- Device Demo (a tinyusb example)\n");
- printf("- if you find any bugs or get any questions, feel free to file an\n");
- printf("- issue at https://github.com/hathach/tinyusb\n");
- printf("--------------------------------------------------------------------\n\n");
-
- printf("This DEVICE demo is configured to support:");
- printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
- if (CFG_TUD_CDC ) puts(" - Communication Device Class");
- if (CFG_TUD_MSC ) puts(" - Mass Storage");
- if (CFG_TUD_HID_KEYBOARD ) puts(" - HID Keyboard");
- if (CFG_TUD_HID_MOUSE ) puts(" - HID Mouse");
-}
diff --git a/examples/device/cdc_msc_hid_freertos/ses/nrf5x/nrf5x.emProject b/examples/device/cdc_msc_hid_freertos/ses/nrf5x/nrf5x.emProject
index 76615bf5b..ea4950682 100644
--- a/examples/device/cdc_msc_hid_freertos/ses/nrf5x/nrf5x.emProject
+++ b/examples/device/cdc_msc_hid_freertos/ses/nrf5x/nrf5x.emProject
@@ -18,11 +18,12 @@
arm_target_debug_interface_type="ADIv5"
arm_target_device_name="nRF52840_xxAA"
arm_target_interface_type="SWD"
- build_treat_warnings_as_errors="Yes"
+ build_treat_warnings_as_errors="No"
c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_PCA10056;CFG_TUSB_MCU=OPT_MCU_NRF5X"
c_user_include_directories="./;../../src;$(rootDir)/hw/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(nrfxDir)/..;$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(freertosDir)/Source/include;$(freertosDir)/Source/portable/GCC/ARM_CM4F"
debug_register_definition_file="nrf52840_Registers.xml"
debug_target_connection="J-Link"
+ gcc_enable_all_warnings="Yes"
gcc_entry_point="Reset_Handler"
link_use_linker_script_file="No"
linker_memory_map_file="nRF52840_xxAA_MemoryMap.xml"
diff --git a/examples/device/cdc_msc_hid_freertos/src/main.c b/examples/device/cdc_msc_hid_freertos/src/main.c
index fbe1ec93e..843b2b077 100644
--- a/examples/device/cdc_msc_hid_freertos/src/main.c
+++ b/examples/device/cdc_msc_hid_freertos/src/main.c
@@ -59,14 +59,13 @@
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-void print_greeting(void);
void led_blinky_cb(TimerHandle_t xTimer);
+void usb_device_task(void* param);
/*------------- MAIN -------------*/
int main(void)
{
board_init();
- print_greeting();
// soft timer for blinky
TimerHandle_t tm_hdl = xTimerCreate(NULL, pdMS_TO_TICKS(1000), true, NULL, led_blinky_cb);
@@ -74,10 +73,13 @@ int main(void)
tusb_init();
+ // Create a task for tinyusb device stack
+ xTaskCreate( usb_device_task, "usbd", 150, NULL, configMAX_PRIORITIES-1, NULL);
+
// Create task
#if CFG_TUD_CDC
extern void cdc_task(void* params);
- xTaskCreate( cdc_task, "cdc", 256, NULL, 2, NULL);
+ xTaskCreate( cdc_task, "cdc", 256, NULL, configMAX_PRIORITIES-2, NULL);
#endif
#if CFG_TUD_HID
@@ -90,6 +92,19 @@ int main(void)
return 0;
}
+// USB Device Driver task
+// This top level thread process all usb events and invoke callbacks
+void usb_device_task(void* param)
+{
+ (void) param;
+
+ // RTOS forever loop
+ while (1)
+ {
+ tusb_task();
+ }
+}
+
//--------------------------------------------------------------------+
// USB CDC
//--------------------------------------------------------------------+
@@ -98,11 +113,12 @@ void cdc_task(void* params)
{
(void) params;
+ // RTOS forever loop
while ( 1 )
{
- // connected and there are data available
if ( tud_cdc_connected() )
{
+ // connected and there are data available
if ( tud_cdc_available() )
{
uint8_t buf[64];
@@ -110,10 +126,15 @@ void cdc_task(void* params)
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
- tud_cdc_write(buf, count);
- }
+ for(uint32_t i=0; i<count; i++)
+ {
+ tud_cdc_write_char(buf[i]);
- tud_cdc_write_flush();
+ if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
+ }
+
+ tud_cdc_write_flush();
+ }
}
}
}
@@ -125,8 +146,8 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
// connected
if ( dtr && rts )
{
- // print greeting
- tud_cdc_write_str("tinyusb usb cdc\n");
+ // print initial message when connected
+ tud_cdc_write_str("\r\nTinyUSB CDC MSC HID device with FreeRTOS example\r\n");
}
}
#endif
@@ -206,6 +227,7 @@ void tud_umount_cb(void)
void tud_cdc_rx_cb(uint8_t itf)
{
+ (void) itf;
}
//--------------------------------------------------------------------+
@@ -219,28 +241,3 @@ void led_blinky_cb(TimerHandle_t xTimer)
board_led_control(led_state);
led_state = 1 - led_state; // toggle
}
-
-//--------------------------------------------------------------------+
-// HELPER FUNCTION
-//--------------------------------------------------------------------+
-void print_greeting(void)
-{
- char const * const rtos_name[] =
- {
- [OPT_OS_NONE] = "None",
- [OPT_OS_FREERTOS] = "FreeRTOS",
- };
-
- printf("\n--------------------------------------------------------------------\n");
- printf("- Device Demo (a tinyusb example)\n");
- printf("- if you find any bugs or get any questions, feel free to file an\n");
- printf("- issue at https://github.com/hathach/tinyusb\n");
- printf("--------------------------------------------------------------------\n\n");
-
- printf("This DEVICE demo is configured to support:");
- printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
- if (CFG_TUD_CDC ) puts(" - Communication Device Class");
- if (CFG_TUD_MSC ) puts(" - Mass Storage");
- if (CFG_TUD_HID_KEYBOARD ) puts(" - HID Keyboard");
- if (CFG_TUD_HID_MOUSE ) puts(" - HID Mouse");
-}
diff --git a/examples/device/cdc_msc_hid_freertos/src/tusb_config.h b/examples/device/cdc_msc_hid_freertos/src/tusb_config.h
index e45c667b3..c35526d7e 100644
--- a/examples/device/cdc_msc_hid_freertos/src/tusb_config.h
+++ b/examples/device/cdc_msc_hid_freertos/src/tusb_config.h
@@ -53,14 +53,8 @@
#endif
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
-
-#define CFG_TUSB_DEBUG 2
-
-/*------------- RTOS -------------*/
#define CFG_TUSB_OS OPT_OS_FREERTOS
-#define CFG_TUD_TASK_PRIO (configMAX_PRIORITIES-1)
-//#define CFG_TUD_TASK_QUEUE_SZ 16
-//#define CFG_TUD_TASK_STACK_SZ 150
+#define CFG_TUSB_DEBUG 2
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
* Tinyusb use follows macros to declare transferring memory so that they can be put
diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h
index cc06ae93d..e3439f88f 100644
--- a/examples/host/cdc_msc_hid/src/tusb_config.h
+++ b/examples/host/cdc_msc_hid/src/tusb_config.h
@@ -80,14 +80,14 @@
// DEVICE CONFIGURATION
//--------------------------------------------------------------------
-#define CFG_TUH_HUB 1
-#define CFG_TUH_CDC 1
-#define CFG_TUH_HID_KEYBOARD 0
-#define CFG_TUH_HID_MOUSE 0
-#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported)
-#define CFG_TUH_MSC 0
+#define CFG_TUH_HUB 1
+#define CFG_TUH_CDC 1
+#define CFG_TUH_HID_KEYBOARD 0
+#define CFG_TUH_HID_MOUSE 0
+#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported)
+#define CFG_TUH_MSC 0
-#define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports
+#define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports
//------------- CLASS -------------//
#define CFG_TUD_CDC 0
diff --git a/examples/obsolete/device/src/tusb_config.h b/examples/obsolete/device/src/tusb_config.h
index bc9ff27fe..2fd35102f 100644
--- a/examples/obsolete/device/src/tusb_config.h
+++ b/examples/obsolete/device/src/tusb_config.h
@@ -55,9 +55,6 @@
/*------------- RTOS -------------*/
//#define CFG_TUSB_OS OPT_OS_NONE // be passed from IDE/command line for easy project switching
-//#define CFG_TUD_TASK_PRIO 0
-//#define CFG_TUD_TASK_QUEUE_SZ 16
-//#define CFG_TUD_TASK_STACK_SZ 150
//--------------------------------------------------------------------+
// DEVICE CONFIGURATION