Showing results for 
Search instead for 
Did you mean: 

FreeRTOS and USB - UART PRECISERR HardFault. Any idea?

Associate II


I have a STM32F407VET6 with FreeRTOS continuously receiving data, normally 250-300 characters every 4[ms], by UART+DMA, when it receives a '\n' and idle-line sends the data received to a mailbox(8 mails length). Then a receiver task get one mail from the mailbox and sends the data by USB with CDC_Transmit_FS().

The problem is that after 3-5 minutes operating I get a HardFault error and the STM32 stucks. The UART+DMA should be OK, I have tested it before and the when I disable the receiver tasks no HardFault error occurs. The fault analyzer shows the flags PRECISERR and it happens in a macro USBx_DFIFO((uint32_t)ch_ep_num) = __UNALIGNED_UINT32_READ(pSrc) inside USB_WritePacket(). What can be the reason of this problem?

If I change CDC_Transmit_FS() for HAL_UART_Transmit() occurs the same

Thank you!

USB_WritePacket() attached

HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
                                  uint8_t ch_ep_num, uint16_t len, uint8_t dma)
  uint32_t USBx_BASE = (uint32_t)USBx;
  uint8_t *pSrc = src;
  uint32_t count32b;
  uint32_t i;
  if (dma == 0U)
    count32b = ((uint32_t)len + 3U) / 4U;
    for (i = 0U; i < count32b; i++)
      USBx_DFIFO((uint32_t)ch_ep_num) = __UNALIGNED_UINT32_READ(pSrc);
  return HAL_OK;


Precise suggests the src pointer points to an illegal address, validate it, perhaps print it out, or look at register content at hardfault address. Posted means of doing this many times.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..