There is a mistake with the STM32L476R processor in CUBE.
This affects the Nucleo-L476RG board.
The size of the memory it wrong, as a result CUBE will place the stack in memory that does not exist. The result being that you can't run or debug the program. In the debugger you are always in an infinite loop as soon as a subroutine call is made.
To fix it:
To get CUBE working correctly with the STM32L476RG:
Edit the file "families.xml" (C:\Program Files (x86)\STMicroelectronics\STM32Cube\STM32CubeMX\db\mcu\families.xml)
Line 20608, in the entry:
<Mcu Name="STM32L476R(C-E-G)Tx" PackageName="LQFP64" RefName="STM32L476RGTx" RPN="STM32L476RG">
Was 128, change it to 96.