cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to send via USB_CDC more than 8 characters (code from CubeMX)

zdzichucb
Associate II
Posted on January 13, 2017 at 14:51

edit: previously I wrote that problems occurs with freertos, I checked without it and I am having the same problem (ending in dead loop after sending more than 8 characters).

Steps to reproduce:

Create project in CubeMX for STM32F4DISCOVERY, enable USB_FS Device only. Configure clock: PLL_N = 72, PLL_Q=3, that gives me 48 MHz for usb, other settings remain unchanged. In configuration I enable CDC device with default parameters. Generate code for SW.

I add some led toggle in order to know it it is running.

/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{
 /* init code for USB_DEVICE */
 MX_USB_DEVICE_Init();
 /* USER CODE BEGIN 5 */
 /* Infinite loop */
 for(;;)
 {
 HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
 osDelay(500);
 }
 /* USER CODE END 5 */ 
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

In file usbd_cdc_if.c I am setting breakpoint at CDC_Receive_FS function.

When I am sending 8 characters or less it works fine. Program enters function above. When I send more than 8 characters, program is not entering CDC_Receive_FS function

>>> import serial
>>> ser = serial.Serial(port='/dev/ttyACM0')
>>> ser.write('12345678')
8
>>> ser.write('123456789')
9
>>> ser.write('12345678')
# python hangs here�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

  1. Sometimes program hangs in this loop:

    /**
     * @brief This is the code that gets called when the processor receives an 
     * unexpected interrupt. This simply enters an infinite loop, preserving
     * the system state for examination by a debugger.
     * @param None 
     * @retval None 
    */
     .section .text.Default_Handler,'ax',%progbits
    Default_Handler:
    Infinite_Loop:
     b Infinite_Loop
     .size Default_Handler, .-Default_Handler�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

#stm32f4-discovery #cubemx #usb-cdc #freertos
1 ACCEPTED SOLUTION

Accepted Solutions
rwmao
Senior
Posted on January 16, 2017 at 07:06

Hello,

Please check the link:

https://community.st.com/0D50X00009XkfcpSAB

There is a link in the thread.

/external-link.jspa?url=https%3A%2F%2Fbitbucket.org%2Frwmao%2Fcdc_onstm32f411rc%2Fdownloads

You can download the detailed instructions of using CDC. Code is geneated by cubemx. Or simply click this to download:

https://bitbucket.org/rwmao/cdc_onstm32f411rc/src/12de104e5bb561881af2c471d97ab3d46b30f6b4/Data%20exchange%20between%20STM32F411%20and%20PC%20using%20USB.pdf?at=master

The buffer typically is much large, such as I have tested to send over 200bytes at a time. And tested to keep sending data.

To receive data from pc, please check another thread

https://community.st.com/0D50X00009Xkfd1SAB

View solution in original post

4 REPLIES 4
Amel NASRI
ST Employee
Posted on January 13, 2017 at 18:24

Hi

Krajewski.Zdzis_

‌,

It seems that you are adding mbed code after generating initial project using CubeMX, right?

This shouldn't be the correct way to do it: either you start CubeMX and call Cube functions (as done in the examples available in the Cube package), or use mbed.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on January 13, 2017 at 18:56

Hi,

Nope, I'm not adding anything but one line for blinking led. Beside that pre code generated by CubeMX

https://hastebin.com/ucobocuwih.swift

and here settings from CubeMX:

0690X0000060630QAA.png

I will try now to makek it without freertos to see if something will change.

zdzichucb
Associate II
Posted on January 13, 2017 at 21:53

By default CubeMX sets rx and tx buffer to 4 bytes (but they remain in user code section.

/* Define size for the receive and transmit buffer over CDC */
/* It's up to user to redefine and/or remove those define */
#define APP_RX_DATA_SIZE 4
#define APP_TX_DATA_SIZE 4�?�?�?�?

further buffers are defined one by one, so while receiving data if you go outside rx buffer, you will be in tx buffer (so kind of safe zone), writing 9 bits will write data further.

rwmao
Senior
Posted on January 16, 2017 at 07:06

Hello,

Please check the link:

https://community.st.com/0D50X00009XkfcpSAB

There is a link in the thread.

/external-link.jspa?url=https%3A%2F%2Fbitbucket.org%2Frwmao%2Fcdc_onstm32f411rc%2Fdownloads

You can download the detailed instructions of using CDC. Code is geneated by cubemx. Or simply click this to download:

https://bitbucket.org/rwmao/cdc_onstm32f411rc/src/12de104e5bb561881af2c471d97ab3d46b30f6b4/Data%20exchange%20between%20STM32F411%20and%20PC%20using%20USB.pdf?at=master

The buffer typically is much large, such as I have tested to send over 200bytes at a time. And tested to keep sending data.

To receive data from pc, please check another thread

https://community.st.com/0D50X00009Xkfd1SAB