static assert to check OSAL_QUEUE_DEF's queue_depth parameter < 256
enable HOST_HCD_XFER_INTERRUPT by default (previously only enabled with HID), as it is widely used implement tusbh_cdc_is_busy add compilation switch in usbh enumeration for hub rewrite CDC serial application to address usb-serial race condition
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,125 +1,134 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>host_freertos</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>?name?</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
|
||||
<value>all</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||
<value>make</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildLocation</key>
|
||||
<value>${workspace_loc:/host/Debug}</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
|
||||
<value>clean</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.contents</key>
|
||||
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
|
||||
<value>all</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>bsp</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/bsp</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>fatfs</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/vendor/fatfs</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>freertos</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/vendor/freertos</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>lwip</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/vendor/lwip</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>src</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-1-PROJECT_LOC/src</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>tinyusb</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/tinyusb</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1366799906386</id>
|
||||
<name></name>
|
||||
<type>26</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-startup_keil</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>host_freertos</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>?name?</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
|
||||
<value>all</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||
<value>make</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildLocation</key>
|
||||
<value>${workspace_loc:/host/Debug}</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
|
||||
<value>clean</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.contents</key>
|
||||
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
|
||||
<value>all</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>bsp</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/bsp</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>fatfs</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/vendor/fatfs</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>freertos</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/vendor/freertos</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>lwip</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/vendor/lwip</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>src</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-1-PROJECT_LOC/src</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>tinyusb</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/tinyusb</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1382869902141</id>
|
||||
<name></name>
|
||||
<type>26</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-startup_keil</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<id>1382869902149</id>
|
||||
<name></name>
|
||||
<type>26</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-startup_iar</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -53,24 +53,22 @@ OSAL_TASK_DEF(cdc_serial_app_task, 128, CDC_SERIAL_APP_TASK_PRIO);
|
||||
OSAL_QUEUE_DEF(queue_def, QUEUE_SERIAL_DEPTH, uint8_t);
|
||||
|
||||
static osal_queue_handle_t queue_hdl;
|
||||
static uint8_t buffer_in[64] TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
static uint8_t serial_in_buffer[32] TUSB_CFG_ATTR_USBRAM;
|
||||
static uint8_t serial_out_buffer[32] TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// tinyusb Callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
void tusbh_cdc_mounted_cb(uint8_t dev_addr)
|
||||
{
|
||||
// application set-up
|
||||
|
||||
{ // application set-up
|
||||
printf("\na CDC device is mounted\n");
|
||||
|
||||
osal_queue_flush(queue_hdl);
|
||||
tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true); // first report
|
||||
}
|
||||
|
||||
void tusbh_cdc_unmounted_cb(uint8_t dev_addr)
|
||||
{
|
||||
// application tear-down
|
||||
{ // application tear-down
|
||||
printf("\na CDC device is unmounted\n");
|
||||
}
|
||||
|
||||
@@ -83,27 +81,20 @@ void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_
|
||||
case TUSB_EVENT_XFER_COMPLETE:
|
||||
for(uint32_t i=0; i<xferred_bytes; i++)
|
||||
{
|
||||
osal_queue_send(queue_hdl, buffer_in+i);
|
||||
osal_queue_send(queue_hdl, serial_in_buffer+i);
|
||||
}
|
||||
tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true);
|
||||
break;
|
||||
break;
|
||||
|
||||
case TUSB_EVENT_XFER_ERROR:
|
||||
tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true); // ignore & continue
|
||||
break;
|
||||
case TUSB_EVENT_XFER_ERROR: break; // ignore
|
||||
|
||||
case TUSB_EVENT_XFER_STALLED:
|
||||
default :
|
||||
ASSERT(false, VOID_RETURN); // error
|
||||
break;
|
||||
ASSERT(false, VOID_RETURN);
|
||||
break;
|
||||
}
|
||||
}else if (pipe_id == CDC_PIPE_DATA_OUT)
|
||||
{
|
||||
|
||||
}else if (pipe_id == CDC_PIPE_NOTIFICATION)
|
||||
{
|
||||
|
||||
}
|
||||
else if (pipe_id == CDC_PIPE_DATA_OUT) { }
|
||||
else if (pipe_id == CDC_PIPE_NOTIFICATION) { }
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -111,7 +102,7 @@ void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_
|
||||
//--------------------------------------------------------------------+
|
||||
void cdc_serial_app_init(void)
|
||||
{
|
||||
memclr_(buffer_in, sizeof(buffer_in));
|
||||
memclr_(serial_in_buffer, sizeof(serial_in_buffer));
|
||||
|
||||
queue_hdl = osal_queue_create( OSAL_QUEUE_REF(queue_def) );
|
||||
ASSERT_PTR( queue_hdl, VOID_RETURN);
|
||||
@@ -122,16 +113,39 @@ void cdc_serial_app_init(void)
|
||||
//------------- main task -------------//
|
||||
OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
||||
{
|
||||
tusb_error_t error;
|
||||
uint8_t c = 0;
|
||||
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
osal_queue_receive(queue_hdl, &c, OSAL_TIMEOUT_WAIT_FOREVER, &error);
|
||||
|
||||
if (c)
|
||||
for(uint8_t dev_addr=0; dev_addr< TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)
|
||||
{
|
||||
printf("%c", c);
|
||||
if ( tusbh_cdc_serial_is_mounted(dev_addr) )
|
||||
{
|
||||
//------------- send characters got from uart terminal -------------//
|
||||
int ch_tx = getchar();
|
||||
if ( ch_tx > 0 )
|
||||
{ // USB is much faster than serial, here we assume usb is always complete. There could be some characters missing
|
||||
serial_out_buffer[0] = (uint8_t) ch_tx;
|
||||
|
||||
if ( !tusbh_cdc_is_busy(dev_addr, CDC_PIPE_DATA_OUT) )
|
||||
{
|
||||
tusbh_cdc_send(dev_addr, serial_out_buffer, 1, false); // no need for interrupt on serial out pipe
|
||||
}
|
||||
}
|
||||
|
||||
//------------- print out received characters -------------//
|
||||
tusb_error_t error;
|
||||
do{
|
||||
uint8_t ch_rx = 0;
|
||||
osal_queue_receive(queue_hdl, &ch_rx, OSAL_TIMEOUT_NOTIMEOUT, &error); // instant return
|
||||
if (error == TUSB_ERROR_NONE && ch_rx) printf("%c", ch_rx);
|
||||
}while (error == TUSB_ERROR_NONE);
|
||||
|
||||
if ( !tusbh_cdc_is_busy(dev_addr, CDC_PIPE_DATA_IN) )
|
||||
{
|
||||
tusbh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true);
|
||||
}
|
||||
|
||||
break; // demo app only communicate with the first CDC-capable device
|
||||
}
|
||||
}
|
||||
|
||||
OSAL_TASK_LOOP_END
|
||||
|
||||
Reference in New Issue
Block a user