cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H742VTG6 USB CDC HS hardwarefault "0xfffffffc <error: Cannot access memory at address 0xfffffffc>" at OUT_ep(1).xfer_buff

HTran.2
Associate II

hello, my project uses USB CDC HS to communicate with PC.

Sometimes USB CDC HS work, sometime didnt (it depends on other variables of my project. and these variables doesnt relate to USB CDC HS, just any variable is added/removed).

MCU send data to CDC 30 message 42 byte per second

PC send 100 bytes to MCU when connect 1st time.

Picture 1: when USB CDC work normally.

Picture 2: when hardware fault happens with hardware fault signal trace

Picture 3: when hardware fault happens I just add any variable into OTG_HS_IRQHandler() and it works again.

I use:

  • both CubeMX6.3 and 6.8 (generate USB CDC HS, USB CHID FS), CubeIDE Version: 1.11.0 and 1.12.0. they have same problem.
  • Bare metal
  • increase heap 500, stack 1000 already

Any idea to debug this case?

4 REPLIES 4
Bob S
Principal

Looks like a memory corruption, probably stack overflow. 0xfffffffc is a typical LR register value (link register), that gets pushed on the stack on every function/IRQ call. If you are running FreeRTOS or Azure try increasing the task stack sizes.

i use bare metal, already increased heap 500 and stack 1000

Bob S
Principal

Use CubeIDE's fault analyzer, see where the code was when it hit that exception. Though I suspect that may not be too helpful. But worth a shot.

Look for buffers that are allocated on the stack (i.e. local to that function) and then passed to the USB TX functions. These buffers will "disappear" when that function exits, and the RAM used by that buffer will be re-used as stack on future function calls. Something like this very crude example:

void some_function( void )
{
   uint8_t buf[100];
 
   function_to_fill_buffer( buf, sizeof(buf) );
   CDC_Transmit_FS( buf, sizeof(buf) );
}

Note: I don't recall if the CubeMX/HAL transmit functions copy data from your buffer to internal buffers before they return. If they do, then this is not an issue.

I just read UM1734 6.7 optimization foot print. tried to increase

void *USBD_static_malloc(uint32_t size)

{

 UNUSED(size);

 static uint32_t mem[(sizeof(USBD_CUSTOM_HID_HandleTypeDef) + sizeof(USBD_CDC_HandleTypeDef)/4+1)];/* On 32-bit boundary */

 return mem;

}

and it works again. Continue to use to see happen again. maybe I use both of CDC HS and HID FS need more memory. I continue to use and see 🙂