cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F437 USB DataTx switches to hardfault handler

Nys Frédéric
Associate
Posted on August 17, 2017 at 11:30

Hello everyone, I am new to the forum.

Currently I am busy working on a project that must use USB communication.

I therefore implemented the USB VCP library for a STM32F437 microcontroller.

I am able to communicate and receive data in USB from a PC. 

Unfortunately, I encounter a problem when I try to send a lot of data continuously. The program switches to hardfault handler after a few seconds of transmission.

I use the VCP_DataTx function.

Uint16_t VCP_DataTx (uint8_t * Buf, uint32_t Len)

{

Uint32_t i;

Pour (i = 0; i <Len; i ++) {

APP_Rx_Buffer [APP_Rx_ptr_in ++] = * (Buf + i);

}

/ * Pour �viter le d�bordement du tampon * /

Si (APP_Rx_ptr_in == APP_RX_DATA_SIZE) {

APP_Rx_ptr_in = 0;

}

Retour USBD_OK;

}

I was able to read some posts on different forums concerning a problem coming from the library.

Have you solved this type of problem? Do you have any examples?

Thank you for your reply

#usb-datatx
2 REPLIES 2
Ben K
Senior III
Posted on August 18, 2017 at 19:29

If you don't mind, I will change the French keywords to the standard C ones. The problem here is a typical buffer overflow, which can be fixed by correctly placing the circular buffer index reset inside the for loop.

Uint16_t VCP_DataTx (uint8_t * Buf, uint32_t Len)

{

   Uint32_t i;

   for (i = 0; i <Len; i ++) {

      APP_Rx_Buffer [APP_Rx_ptr_in ++] = * (Buf + i);

      / * Pour éviter le débordement du tampon * /

      if (APP_Rx_ptr_in == APP_RX_DATA_SIZE) {

         APP_Rx_ptr_in = 0;

      }

   }

   return USBD_OK;

}
Nys Frédéric
Associate
Posted on August 22, 2017 at 13:49

Thank you for your reply.

Unfortunately the problem is still the same.

Could the problem come from a parameter in my CDC configuration?

#define USBD_CFG_MAX_NUM                         1

#define USBD_ITF_MAX_NUM                           1

#define USB_MAX_STR_DESC_SIZ                  255

#define CDC_DATA_MAX_PACKET_SIZE          64 /* Endpoint IN & OUT Packet size */

#define CDC_CMD_PACKET_SZE                      8 /* Control Endpoint Packet size */

#define CDC_IN_FRAME_INTERVAL                  5 /* Number of frames between IN transfers */

#define APP_RX_DATA_SIZE                              2048 /* Total size of IN buffer:

The Baudrate of my communication is 19200bit/s.

When there is an overflow, the USB port jumps and the processor goes into hardfault handler.

Would it be possible to re-establish communication?

Thank you for your reply