cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 CDC Host with Custom baud rate

MKDas
Associate II

I've created a project with STM32F407xxx, and using as USBH_CDC with this MCU. STM is working fine but the problem is, the baud rate can not be edited. It is auto by default. How can I keep it fixed at a certain baud rate such as 9600 or 115200?

I tried with GetLineCoding & SetLineCoding but it did not work. It is always in auto baud rate.

8 REPLIES 8
Bob S
Principal

[EDIT - NEVER MIND - I just re-read your post and this is in HOST mode - my original post doesn't apply]

MKDas
Associate II

Actual thing is, I'm using STM32F407 as the host and there are some devices connected with it through USB. and I'm using USB CDC as protocol. Everything working fine except for this problem. What is happening, is if one of the connected devices is in reset condition, ST finds and starts transferring at a different baud rate rather than 115200. But if those devices are in an active condition, ST selects 115200. So, when anyhow the connected device(s) is in reset condition, ST can not communicate with those again as those device is not responding at a different baud rate rather than 115200. So I need to fix the auto baud rate option from ST Host.

Tried editing inside USBH_CDC_ClassRequest with

CDC_Handle->data_rx_state = CDC_IDLE;

CDC_Handle->data_tx_state = CDC_IDLE;

CDC_Handle->LineCoding.b.bCharFormat = 1;

CDC_Handle->LineCoding.b.bDataBits = 8;

CDC_Handle->LineCoding.b.bParityType = 0;

CDC_Handle->LineCoding.b.dwDTERate = 115200;

But, I found that this has no effect on selecting the baud rate. From somewhere, anyhow, ST is selecting the baud-rate automatically.

Also tried editing the GetLineCoding & SetLineCoding. But also those are not effective.

MKDas
Associate II

Tried in different ways, but editing those parameters makes nothing change. It is somewhere inside to change.

AScha.3
Chief II

just to understand: you have stm32-host -> usb7cdc -> to what target ? cdc-device?

If you feel a post has answered your question, please click "Accept as Solution".

CH340 based custom device. Which can read only at 115200. but STM is setting baud rate randomly with different devices if once it is reset anyhow. But it the power is not disconnected and once it got a data at 115200, ST selects 115200.

So, I want to make the STM Host fixed at 115200.

AScha.3
Chief II

ok,

  1. usb/cdc has no "serial port speed" , usb is always 12Mb and so is transfer ;
  2. to set target speed, you need send a command (..set port 115k, 8n1 )

maybe, you find in host lib something to set/change target speed, or look in Cube FW repository.

here: in STM32H743I-EVAL/Applications/USB_Host/CDC_Standalone -> cdc_configuration.c

see example , should help you. 'CdcSelectMode' ...

If you feel a post has answered your question, please click "Accept as Solution".
MKDas
Associate II

Tried, but it did not change anything.

bCharFormat = 1 means 1.5 stop bits. I doubt this is what you want.

Per CDC spec for PSTN SubClass:

  • bCharFormat
    0 - 1 Stop bit
    1 - 1.5 Stop bits
    2 - 2 Stop bits