Skip to main content
BMart.2
Associate III
August 4, 2020
Question

USB_CDC and BLE Hard Fault

  • August 4, 2020
  • 2 replies
  • 2783 views

0693W000003C5bNQAS.pngHello,

I'm using CubeMx to create a project with usb cdc serial port and BLE functionality. CubeMx generates a sequencer UTIL_SEQ_Run(~0); that runs the BLE state machine. In the code below, if I comment out UTIL_SEQ_Run(~0); the code runs fine per Workshop #3 on Youtube. Prints out the data "Hello World" to hyperterminal. As soon as I uncomment UTIL_SEQ_Run(~0); and run the app in the debugger I get a hard fault. Has anyone seen this behavior while trying to run the sequencer with usb cdc? Any thoughts as to how to debug this as far as where I should start looking?

Thanks,

This topic has been closed for replies.

2 replies

BMart.2
BMart.2Author
Associate III
August 4, 2020

Here is the code:

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 char usbOut[256];

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  sprintf(usbOut, "Hello World\r\n");

  //CDC_Transmit_FS(( uint8_t * )usbOut, strlen( usbOut ));

  USBD_CDC_SetTxBuffer(&hUsbDeviceFS, ( uint8_t * )usbOut, strlen( usbOut ));

  USBD_CDC_TransmitPacket(&hUsbDeviceFS);

  HAL_Delay(1000);   

  UTIL_SEQ_Run(~0);

 }

 /* USER CODE END 3 */

XPonc.1
Associate II
August 6, 2020

Yes, I had the same issue. Apparently the BLE stack uses the USB clock for RNG purposes, and the clock can't have shared ressources.

See solution here:

https://community.st.com/s/question/0D50X0000C7cRcvSQE/problems-using-usb-mass-storage-middleware-with-ble-stack-on-stm32wb55

BMart.2
BMart.2Author
Associate III
August 6, 2020
Thanks for the reply. I’ve actually implemented the code in the thread you’ve provided and I am still getting the same issue. The code is being called as I’ve got the define set to 1, but it seems to be the same behavior. I’ll keep digging.
XPonc.1
Associate II
August 6, 2020

Oh, yes, it doesn't look the same as the problem I was facing: I did not have a hardfault, but my USB was not working

Also, as far as I know, you're supposed to have only the  UTIL_SEQ_Run(~0); in your while loop... If you want to print something (blink test with USB) try to set up a TIM interrupt that starts a new task in the sequencer.

Also, did you implement these 3 interrupts in your _it.c file? They are called by the RF stack.

/**
 * @brief This function handles RTC wake-up interrupt through EXTI line 19.
 */
void RTC_WKUP_IRQHandler(void)
{
 HW_TS_RTC_Wakeup_Handler();
}
/**
 * @brief This function handles IPCC RX occupied interrupt.
 */
void IPCC_C1_RX_IRQHandler(void)
{
 HW_IPCC_Rx_Handler();
}
/**
 * @brief This function handles IPCC TX free interrupt.
 */
void IPCC_C1_TX_IRQHandler(void)
{
 HW_IPCC_Tx_Handler();
}
 
/* USER CODE END 1 */