cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 USB On-The-Go Host and Device Library: structure?

turboscrew
Senior III
Posted on December 29, 2013 at 17:48

I'm in a process of trying to write an USB Host CDC program (Full Speed only).

This is my first encounter with USB-internals and STM32-chips.

I still haven't figured out what should go into which file / directory or what interrupt to use for waking the end point data transfer code to check whether there is something to move or not.

It's hard to follow the examples without knowing where the actions get initiated.

I don't have much time, and the right stuff is hard to find in the documents (the library and chip).

The files whose contents I'm wondering especially about, are:

...\STM32_USB_HOST_Library\Class\CDC\inc\usbh_cdc_core.h

...\STM32_USB_HOST_Library\Class\CDC\src\usbh_cdc_core.c

...\USB_Host_Examples\CDC\inc\usbh_usr.h

...\USB_Host_Examples\CDC\src\usbh_usr.c

(maybe some other VCP-files?)

I have been trying to put the SW together by editing the MSC example looking into VCP-device example on the side.

I understand that in the device example it's periodic transfer interrupt that is used for triggering the ''situation check'' for USB EP transfers, while RS-side minds its own business using rx/tx interrupts?

That is: what is supposed to be the interface to the library, and what should be left in the application side. The catch is that I shoud add a protocol (in between the USB and Serial) later when I get the raw bytes flowing through. I'm using STM3240G-EVAL.

At the moment I'm using Eclipse, but the stuff should eventually be brought into a commercial IDE.

(Quite a lot of work putting together an Eclipse project...)

#usb #fs
28 REPLIES 28
turboscrew
Senior III
Posted on January 13, 2014 at 16:45

Maybe this is stupid, but I thought it would be nice to notify about any progress...

REMOTE_NDIS_INITIALIZE_MSG 

is sent and a sensible response received.

80000002

00000034

00000000

00000000

00000001

00000000

00000001

00000000

00000001

0000062c

00000000

00000000

00000000

turboscrew
Senior III
Posted on January 14, 2014 at 10:32

Now I send the init-message until I get OK and then start requesting the response (until OK),

Is that the way with control messages?

How about the data?

And where does the interrupt transfers come into play?

Then there are the status polling and alive. How?

(Control messages, I think.)

Anything else I should be taken into account?

[edit]

I started a new thread about receiving data:

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32_USB-Host-Device_Lib%20-%20receiving&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=1]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fSTM32_USB-Host-Device_Lib%20-%20receiving&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=1

I guess this thread is quite long - especially when it's title has become somewhat misleading.

tsuneo
Senior
Posted on January 14, 2014 at 15:36

> Now I send the init-message until I get OK and then start requesting the response (until OK),

 

> Is that the way with control messages?

 

> And where does the interrupt transfers come into play?

The sequence of ''control'' message exchange (for example, REMOTE_NDIS_INITIALIZE_MSG - REMOTE_NDIS_INITIALIZE_CMPLT) is as follows,

1) Above USBH_RNDIS_Send_Encapsulated_Commnad() should be repeatedly called, with REMOTE_NDIS_INITIALIZE_MSG block on the buffer, until it returns USBH_OK.

The first call of USBH_RNDIS_Send_Encapsulated_Commnad() (ie. USBH_CtlReq()) registers SETUP transaction of the Control transfer to the stack. The second and latter calls wait for completion of this Control transfer. The stack supposes repeated calls, though it isn't smart.

2) When USBH_RNDIS_Send_Encapsulated_Commnad() completes, interrupt IN transfer starts to get 8 bytes RESPONSE_AVAILABLE notification.

3) After receiving RESPONSE_AVAILABLE, USBH_RNDIS_Get_Encapsulated_Response() is also repeatedly called for USBH_OK, like USBH_RNDIS_Send_Encapsulated_Commnad().

USB RNDIS Control Channel Characteristics

http://msdn.microsoft.com/en-us/library/ff546124%28v=vs.85%29.aspx

> Anything else I should be taken into account?

After the ST host stack finishes enumeration (until Set_Config), the stack (ie. USBH_Process() in the main loop) repeatedly calls ''Requests'' callback of the class object (USBH_MSC_ClassRequest() of MSC host). ''Requests'' callback initializes the target device. Until the initialization finishes, the callback returns USBH_BUSY, to get another call from the stack. When the initialization finishes, the callback returns USBH_OK.

And then, the stack moves to ''Machine'' (USBH_MSC_Handle() of MSC host) callback. In this callback, the body of the class-specific behavior comes.

For RNDIS implementation,

''Requests'' callback

Exchange these least set of messages

- REMOTE_NDIS_INITIALIZE_MSG : initialize RNDIS interface

- REMOTE_NDIS_QUERY_MSG - OID_GEN_SUPPORTED_LIST : check supported OIDs

- REMOTE_NDIS_QUERY_MSG - OID_GEN_MAXIMUM_FRAME_SIZE : get max Ethernet frame size

- REMOTE_NDIS_QUERY_MSG - OID_802_3_CURRENT_ADDRESS : get current MAC address

- REMOTE_NDIS_QUERY_MSG - OID_GEN_MEDIA_CONNECT_STATUS : confirm connected

- REMOTE_NDIS_SET_MSG - OID_GEN_CURRENT_PACKET_FILTER : set up packet filter

''Machine'' callback

- exchange Ethernet frames (without preemble) over the bulk IN/OUT endpoint, with REMOTE_NDIS_PACKET_MSG header

- Poll the status of the link periodically using,

- - REMOTE_NDIS_QUERY_MSG - OID_GEN_LINK_SPEED

- - REMOTE_NDIS_QUERY_MSG - OID_GEN_MEDIA_CONNECT_STATUS

Tsuneo

tsuneo
Senior
Posted on January 14, 2014 at 15:51

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6dd&d=%2Fa%2F0X0000000bsG%2FrFWosYL_DlexBoqELvUD7x4ov7N340v6.YtkMQvKlU4&asPdf=false
turboscrew
Senior III
Posted on January 14, 2014 at 16:26

A-ha. With the response in the other thread, I guess most of the stuff got quite clear.

(except the data/bulk IN, but I suppose it's done pretty much in the similar way - polling a state. That I'll probably find in the example codes.)

Another trainload of thanks. I think I got it, and if not, I'll ask.

Do you close these threads in any way? Or do I just add ''[SOLVED]'' in the title?

novikov
Associate II
Posted on October 19, 2015 at 14:59

Hi all.

I need

RNDIS

driver for

host

-

STM32F407

/429

for connection to

radios

Motorola

.

I'm trying

the example

USB-host

\

CDC

-Standalone

(

STM32Cube_FW_F4_V1

.

3

.

0

).

I added

log

in function:

USB_WritePacket and

USB_ReadPacket.

In

GetLineCoding

function (

it

is called from

USBH_CDC_ClassRequest

)

I am trying to send

CDC_SEND_ENCAPSULATED_COMMAND

.

In

the write data buffer

REMOTE_NDIS_INITIALIZE_MSG

.

static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecoding)
{
static uint8_t buf[24] = { 0x02, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00 };
// phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | \
// USB_REQ_RECIPIENT_INTERFACE;
// 
// phost->Control.setup.b.bRequest = CDC_GET_LINE_CODING;
// phost->Control.setup.b.wValue.w = 0;
// phost->Control.setup.b.wIndex.w = 0;
// phost->Control.setup.b.wLength.w = LINE_CODING_STRUCTURE_SIZE; 
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS | \
USB_REQ_RECIPIENT_INTERFACE;
phost->Control.setup.b.bRequest = CDC_SEND_ENCAPSULATED_COMMAND;
phost->Control.setup.b.wValue.w = 0;
phost->Control.setup.b.wIndex.w = 0;
phost->Control.setup.b.wLength.w = 0x18; 
return USBH_CtlReq(phost, buf, sizeof(buf));
}

In my log,

one package

length of

24 bytes

,

instead of the expected

three

parcels

on

8 bytes

.

As a result

in the function

USBH_HandleControl

variable

phost

-

>Control

.

state

takes the value

CTRL_STALLED.

How to make

that

function

USBH_CtlSendData

sent packages

to 8

bytes

?

Help me please. My log:

USB Device Attached
Tx ( 8):>> 80 06 00 01 00 00 08 00
Rx ( 8): 12 01 00 02 02 02 00 08
Tx ( 8):>> 80 06 00 01 00 00 12 00
Rx ( 8): 12 01 00 02 02 02 00 08
Rx ( 8): AD 0C 21 10 00 01 01 02
Rx ( 2): 03 01
PID: 1021h
VID: cadh
Tx ( 8):>> 00 05 01 00 00 00 00 00
Address (#1) assigned.
Tx ( 8):>> 80 06 00 02 00 00 09 00
Rx ( 8): 09 02 43 00 02 01 00 C0
Rx ( 1): 02
Tx ( 8):>> 80 06 00 02 00 00 43 00
Rx ( 8): 09 02 43 00 02 01 00 C0
Rx ( 8): 02 09 04 00 00 01 02 02
Rx ( 8): FF 00 05 24 00 10 01 05
Rx ( 8): 24 01 00 00 04 24 02 00
Rx ( 8): 05 24 06 00 01 07 05 81
Rx ( 8): 03 08 00 01 09 04 01 00
Rx ( 8): 02 0A 00 00 00 07 05 03
Rx ( 8): 02 40 00 00 07 05 82 02
Rx ( 3): 40 00 00
Tx ( 8):>> 80 06 01 03 09 04 FF 00
Rx ( 8): 3E 03 4D 00 6F 00 74 00
Rx ( 8): 6F 00 72 00 6F 00 6C 00
Rx ( 8): 61 00 20 00 53 00 6F 00
Rx ( 8): 6C 00 75 00 74 00 69 00
Rx ( 8): 6F 00 6E 00 73 00 20 00
Rx ( 8): 43 00 6F 00 72 00 70 00
Rx ( 8): 6F 00 72 00 61 00 74 00
Rx ( 6): 69 00 6F 00 6E 00
Manufacturer : Motorola Solutions Corporation
Tx ( 8):>> 80 06 02 03 09 04 FF 00
Rx ( 8): 3C 03 4D 00 6F 00 74 00
Rx ( 8): 6F 00 72 00 6F 00 6C 00
Rx ( 8): 61 00 20 00 53 00 6F 00
Rx ( 8): 6C 00 75 00 74 00 69 00
Rx ( 8): 6F 00 6E 00 73 00 20 00
Rx ( 8): 4C 00 54 00 44 00 20 00
Rx ( 8): 44 00 65 00 76 00 69 00
Rx ( 4): 63 00 65 00
Product : Motorola Solutions LTD Device
Tx ( 8):>> 80 06 03 03 09 04 FF 00
Rx ( 8): 16 03 30 00 33 00 38 00
Rx ( 8): 54 00 4E 00 41 00 39 00
Rx ( 6): 34 00 32 00 34 00
Serial Number : 038TNA9424
Enumeration done.
This device has only 1 configuration.
Tx ( 8):>> 00 09 01 00 00 00 00 00
Default configuration set.
Switching to Interface (#0)
Class : 2h
SubClass : 2h
Protocol : ffh
RNDIS class started.
Tx ( 8):>> 21 00 00 00 00 00 18 00
Tx ( 24):>> 02 00 00 00 18 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 40 00 00
Tx ( 24):>> 02 00 00 00 18 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 40 00 00
Tx ( 24):>> 02 00 00 00 18 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 40 00 00

novikov
Associate II
Posted on October 26, 2015 at 13:23

Hi

!

On

another Board

I made a

RNDIS

device

and

put

the messages in

the log.

Here is what

it receives from

STM32:

E0 st:0x88804 Stp [ Rx: 21 00 00 00 00 00 18 00 ] NewReq sEnc Read0(24)
E0 st:0x88002 Rd 8 [ Rd: 02 00 00 00 18 00 00 00 ]
E0 st:0x88802 Rd 8 [ Rd: 02 00 00 00 01 00 00 00 ]
E0 st:0x88002 Rd 8 [ Rd:

02 00 00 00 18 00 00 00

]

instead of the expected

:

02 00 00 00 18 00 00 00 
02 00 00 00 01 00 00 00 
00 00 00 00 00 40 00 00

in red

I marked

the wrong data

As you can see incorrect data, repeats the first 8 bytes of the packet.
novikov
Associate II
Posted on November 06, 2015 at 09:48

Hi !

If in debug mode, execute step by step this code (

line

8-10)

:


HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len, uint8_t dma)

{

uint32_t count32b= 0 , i= 0;


if (dma == 0)

{

count32b = (len + 3) / 4;

for (i = 0; i < count32b; i++, src += 4)

{

USBx_DFIFO(ch_ep_num) = *((__packed uint32_t *)src);

}

}

return HAL_OK;

}

then everything is working correctly! How to make it work in run mode?
jairo
Associate
Posted on March 22, 2016 at 21:26

Hi Novikov.Valerri,

You succeeded in running the STM32 with Motorola radio?

I'm new in ARM technology, and would also like to communicate with the Motorola radio ... it is possible?