STMicroelectronics / STM32CubeF4

STM32Cube MCU Full Package for the STM32F4 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
899 stars 424 forks source link

HAL_Delay() causes infinite loop because systick not incrementing on stm32F4 and stm32L4 and stm32G4 boards due to bugs in system_stm32f4xx.c / system_stm32l4xx.c when making new default project running from flash #113

Open beachmiles opened 2 years ago

beachmiles commented 2 years ago

Caution The Issues are strictly limited for the reporting of problem encountered with the software provided in this project. For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post a topic in the ST Community/STM32 MCUs forum.

Describe the set-up

Describe the bug A clear and concise description of what the bug is. Creating a new stm32cubemx project for either of the stm32F4 chips using the stm32cube 1.26.0-1.26.2 drivers causes HAL_Delay to enter infinite loop because the systick timer to not increment and the default systick priority set to 15 instead of 0. Setting systick priority to 0 does not help.

How To Reproduce

  1. Indicate the global behavior of your application project. Create a new stm32cube project for the stm32f469VI or stm32f479AI (suspect same issue on all stm32F4 chips) using stm32cube 1.26.0-1.26.2 drivers. Insert a HAL_Delay(5) in the while loop.

  2. The modules that you suspect to be the cause of the problem (Driver, BSP, MW ...). system_stm32f4xx.c

  3. The use case that generates the problem. Trying to make a stm32cube project.

  4. How we can reproduce the problem. Make a new stm32cube project for the stm32f469VI or stm32f479AI (suspect same issue on all stm32F4 chips)

Additional context If you have a first analysis or patch correction, thank you to share your proposal.

Edit this section in system_stm32f4xx.c by doing the following 2 things. Full updated code snippet below
  1) uncommenting the "#define USER_VECT_TAB_ADDRESS" 
  2) adding the line #if defined(USER_VECT_TAB_ADDRESS) 

/* Note: Following vector table addresses must be defined in line with linker
         configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
     anywhere in Flash or Sram, else the vector table is kept at the automatic
     remap of boot address selected */
#define USER_VECT_TAB_ADDRESS                   //This needs to be uncommented out by default! -MILES

/*!< Uncomment the following line if you need to relocate your vector Table in
     Internal SRAM. */
/* #define VECT_TAB_SRAM */
#if defined(USER_VECT_TAB_ADDRESS)              // THIS LINE WAS PREVIOUSLY MISSING! -MILES

Screenshots If applicable, add screenshots to help explain your problem.

fpistm commented 2 years ago

Hi @beachmiles,

Are you flashing using Serial? (Thanks bootloader)? If yes then this issue is probably the same than this one: https://github.com/stm32duino/Arduino_Core_STM32/pull/1653

By default the system_stm32f4xx.c template file does not restore the VTOR. In that case systick could not be incremented. Moreover you should ensure clock config is properly reset to not use the PLL else if your system clock config try to reconfigure it then it will failed as PLL is already used.

beachmiles commented 2 years ago

I am flashing / debugging using a stlink v3 usb programmer. I just updated to stm32cubeide 1.9 with this version of the firmware STM32Cube FW_F4 V1.27.0

Creating a new project still had this line commented out #define USER_VECT_TAB_ADDRESS which still keeps the systick from incrementing. Uncommenting it fixes the problem. / Note: Following vector table addresses must be defined in line with linker configuration. / /!< Uncomment the following line if you need to relocate the vector table anywhere in Flash or Sram, else the vector table is kept at the automatic remap of boot address selected /

define USER_VECT_TAB_ADDRESS

vahidajalluian commented 2 years ago

Dear @beachmiles Your solution worked also for me with F429.

RKOUSTM commented 2 years ago

Hi @beachmiles,

Thank you your contribution. Actually, the point you raised has already been dealt and fixed internally. The fix will be made available in the frame of a future release.

Thank you once more for your contribution. We are looking forward to reading from you again.

With regards,

RKOUSTM commented 2 years ago

ST Internal Reference: 116475

wilgaced commented 1 year ago

I am flashing / debugging using a stlink v3 usb programmer. I just updated to stm32cubeide 1.9 with this version of the firmware STM32Cube FW_F4 V1.27.0

Creating a new project still had this line commented out #define USER_VECT_TABADDRESS which still keeps the systick from incrementing. Uncommenting it fixes the problem. /* Note: Following vector table addresses must be defined in line with linker configuration. / /_!< Uncomment the following line if you need to relocate the vector table anywhere in Flash or Sram, else the vector table is kept at the automatic remap of boot address selected */ #define USER_VECT_TAB_ADDRESS

wilgaced commented 1 year ago

It Work for STM32L496

beachmiles commented 1 year ago

Creating a new project still had this line commented out #define USER_VECT_TABADDRESS which still keeps the systick from incrementing. Uncommenting it fixes the problem. /* Note: Following vector table addresses must be defined in line with linker configuration. / /_!< Uncomment the following line if you need to relocate the vector table anywhere in Flash or Sram, else the vector table is kept at the automatic remap of boot address selected */ #define USER_VECT_TAB_ADDRESS

It looks like this is still "In Progress" as of 1/17/2023, it's unfortunate this is the case as I suspect many people across the world will have ripped many hairs out from this bug the past 10+ months. https://github.com/orgs/STMicroelectronics/projects/2#card-79208657

beachmiles commented 1 year ago

Verified this is still a bug in the stm32L496ZG-P on the Nucleo board. I'm using stm32cubeide 1.11.2 using stm32cube firmware L4 V1.17.2 Luckily the same fix for the stm32f4 works on the stm32l4. Can't believe a major bug like this could persist for close to a year spanning at least the stm32F4 and stm32L4 lines.

beachmiles commented 1 year ago

Dear @fpistm @ALABSTM @RKOUSTM , I verified this is still a bug when creating a new project for a stm32L4 (NUCLEO-L496ZG-P) with the original fix still working except the the 2nd step is no longer needed as the #if defined(USER_VECT_TAB_ADDRESS) line is now in both of the latest system_stm32f4xx.c and system_stm32l4xx.c files. So now I only had to uncomment this line to get the system from freezing on initialization due to a frozen systick. #define USER_VECT_TAB_ADDRESS

So it looks like ST needs to update these files with this one line fix unless there is a better/different fix in the works. Thanks! https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c

https://github.com/STMicroelectronics/STM32CubeL4/blob/master/Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates/system_stm32l4xx.c

vahidajalluian commented 1 year ago

I didn't like to say this like, out of morality, but as it has wasted a lot of time from developers who trusted developers of cube MicroXplorer, it is a pity that til now there had been no workaround for a line to be uncommented, and a line to be added.

stnigg commented 1 year ago

Currently the lates version for L4 seems to be 1.17.2. The issue is present in this library at least for the STM32L431. I must say it is disapointing to find out that this is known for this long and is still wasting my time.

fpistm commented 1 year ago

Hi @beachmiles I'm aware of this and fixed this in https://github.com/stm32duino/Arduino_Core_STM32. From my point of view, VTOR should be unconditionally set but I'm not working on Cube, I'm only use it for stm32duino core. An internal bugtracker has been submitted and so I hope it will be resolved by concerned team.

mrpj100 commented 1 year ago

Can confirm this also affected me on an STM32L432,

timonburkard commented 1 year ago

Issue also exists on STM32L433CBT6 using STM32CubeIDE 1.12.1, STM32CubeMX version 6.8.1

Ashish-Jog commented 1 year ago

Issue still exists on STM32H743IIT6., CubeIDE Version :- 1.11.2

crnorris commented 1 year ago

Issue exists with a fresh project built with STM32CubeIDE 1.13.2, STM32CubeMX 6.9.2, targeting STM32G030J6M6.

smelting commented 10 months ago

Issue persistent with STM32G491RET6, STM32CubeIDE 1.11.0, STM32Cube FW_G4 V1.5.2. Wasted my time checking my board design/soldering because a blank project with a blink and delay was broken.

beachmiles commented 9 months ago

@fpistm @ALABSTM @RKOUSTM We are now close to this being a 2 year old open bug that can be fixed by 1 line!!! How many headaches this has caused during that time is sad to think about. Can we please fix this???

YocoZuna commented 5 months ago

Issue persistent with STM32L051R8T6

DAflamingFOX commented 3 months ago

Can confirm this issue is still persistent on STM32G431KBU6, STM32CubeIDE 1.16.0 & STM32Cube FW_G4 V1.6.0

The solution posted here still works...

It's been over 2 years, this is a joke right?

augustas534 commented 2 months ago

Issue still exists with a fresh project built with STM32CubeIDE 1.16.0, STM32Cube FW_U5 V1.6.0, targeting STM32U545RETxQ.

Following fix does not work on this processor...