cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L433 stuck in USB interrupt with 1.0 A Apple charger

Moritz Diller
Associate II

I have built a device, in which the USB port is used for charging and firmware updates as well. During startup, the firmware checks if communication via USB is possible and switches to charging/update mode accordingly.

Now when I connect a 1.0 A Apple USB charger some strange behavior occurs. Right after initialization with MX_USB_DEVICE_Init(); the USB interrupt handler gets called with the ESOF and ERR flag set in the ISTR register. The interrupt now gets triggered continuously and the CPU is stuck in the interrupt handler.

0690X000009YrJ9QAK.png

The Apple charger is emulated with the following circuit:

0690X000009YrJOQA0.png

For testing, I connected D+ to a laboratory power supply and varied the voltage. The software gets stuck in the interrupt if D+ is between 1.6 V and 2.4 V. Below 1.6 V and above 2.4 V no continuous interrupts occur, USB initialization is executed as expected.

If the startup is performed with D+ @ 2.0 V, the interrupt does immediately stop from occurring if D+ is regulated to less than 1.25 V or more than 2.4 V. So you have a small hysteresis at the lower voltage limit.

If you like to reproduce the issue, you can use the attached STM32CubeIDE-Project and a NUCLEO-L432KC board.

Attach a USB connector like in the following picture or use the resistors from the previous schematic. 

0690X000009YrJTQA0.jpg

My current solution is a modified stm32l4xx_hal_pcd.c (see attachment). In the interrupt handler the ESOF interrupts are counted and if the counter reaches 1000 the USB interrupt gets disabled. The esofCounter is set to 0 in the CTR-interrupt. Just to be safe, because I don’t have so much experience with USB to assess how many ESOF-interrupts can be expected during normal operation in the long run. 

0690X000009YrJsQAK.png

0690X000009YrJxQAK.png

0690X000009YrK2QAK.png

Maybe there is a more elegant solution, so I hope I can trigger the HAL-development team by this post to further improve your already quite great software. 😉

HAL-Lib: STM32Cube_FW_L4_V1.14.0

CubeMX: 5.2.1

STM32CubeIDE: 1.0.1

1 REPLY 1
TDiaz
Associate

Hi, I was having a very similar problem with an STM32L433. My device is designed to be powered from external 12v or 5v from VBUS. When powering on from 12v and no USB cable connected, USB library initialization would go continuously to the USB interrupt handler, over and over.

I fixed it by enabling monitoring the VDD_USB power supply:

PWR->CR2 |= PWR_CR2_PVME1;

then on the library (HAL_PCD_MspInit), I would add a conditional to enable the USB interrupt, if USB power supply is not valid, then don't enable USB interrupts:

 if(!(PWR->SR2 & PWR_SR2_PVMO1))

  {

   HAL_NVIC_EnableIRQ(USB_IRQn); // SOUL

  }

And finally in the main loop, kept monitoring the VDD_USB power supply, once it is valid (a cable was connected). Run library initialization again.

   //--------USB no VDD_USB workaround

   present = PWR->SR2 & PWR_SR2_PVMO1;

   if(!present && past)

   {

    NVIC_EnableIRQ(USB_IRQn);

   }

   else if(present && !past)

   {

    NVIC_DisableIRQ(USB_IRQn);

   }

   past = present;

   //--------USB no VDD_USB workaround