cancel
Showing results for 
Search instead for 
Did you mean: 

USB_CDC and BLE Hard Fault

BMart.2
Associate II

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,

5 REPLIES 5
BMart.2
Associate II

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 III

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

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.

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 */

Thanks for your reply. I do have the 3 interrupts you’ve shown added. I had the usb code in the main loop for just testing it without the sequencer. I was not aware that UTIL_SEQ_Run(~0) could be the only function in the main loop. I’ll try adding that to the sequencer.
Thanks again