cancel
Showing results for 
Search instead for 
Did you mean: 

HAL USB host HS in FS with FreeRTOS

vincent2
Associate II
Posted on June 19, 2015 at 10:22

Hi all,

I'am communicating with a 3G modem through USB.

I'am using FreeRTOS (this is important).

The USB is configurated like :

  

/*Set LL Driver parameters */

  hhcd.

Instance

= USB_OTG_HS;

  hhcd.

Init

.

Host_channels

= 11; 

  hhcd.

Init

.

dma_enable

= 1;

  hhcd.

Init

.

low_power_enable

= 0;

  hhcd.

Init

.

phy_itface

= HCD_PHY_EMBEDDED; 

  hhcd.

Init

.

Sof_enable

= 0;

  hhcd.

Init

.

speed

= HCD_SPEED_HIGH;

  hhcd.

Init

.

vbus_sensing_enable

= 0;

  hhcd.

Init

.

use_external_vbus

= 0;

My problem is the following: 

Sending small datas (simple AT command) to the modem is OK.

char

at[] =

''ATE0\r\n''

;

USBH_CDC_Transmit(&hUSB_Host, (

uint8_t

*) at, (

uint32_t

)

strlen

(at));

but sending more bigger data is a problem.

If the data is bigger than 64 (USB frame size) the transmit do not end.

If I add an osDelay(1) in the main USB thread ( USBH_Process_OS() ) the

transmit ends !

If I add a new thread to manage data received by the modem, the transmit ends !

But those workaround hide a bigger problem.

I suspect a FreeRTOS schedule and/or interrupt priority problem. So far I didn't managed to identifie it.

If someone has faced same problems please share your experience and/or fix,

Thanks,

Best Regards,  

4 REPLIES 4
vincent2
Associate II
Posted on June 24, 2015 at 17:13

I'am answering to my own question.

There is a problem (don't know why yet) with USB_OTG_HCCHAR_CHDIS and USB_OTG_HCCHAR_CHENA registers.

Writing in it ''too early'' will overwrite it and crash (?) the USB.

Adding :

while

((USBx_HC(hc->

ch_num

)->

HCCHAR

& USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);in USB_HC_StartXfer before addressing theses register correct the problem.

To me this is only a workaround. The root cause should be addressed. I suspect a concurrence problem between main USB thread and USB interrupt.

I didn't investigate more so far.

Hope that help,

Best regards,
vincent2
Associate II
Posted on June 24, 2015 at 17:13

rodrigo
Associate II
Posted on September 22, 2015 at 19:16

hi, pillet.vincent.

Sorry for my bad english. I'm from Brazil.

I'm also working with 3g modem. I'm not able to switch the modem mode to CDC. The 3g modem always stay in MSC class. How do it?

you could post your code?

Thanks.

Posted on February 01, 2018 at 03:54

This workaround solved my problem of unreliable sends with CDC host. The bug still exists in STMCubeF7 V1.8.0. In addition, the same function also appears to have another bug in that the tmpreg variable is oddly declared static and so the function is NOT thread-safe.