The STM32G4 will hang in a reset loop after flashing with the option to use the MCU as a USB CAN bus bridge.
The USB SRAM isn´t writeable because the USB clock isn´t set.
Changing stm32g4.c line 107 from:
// Enable 48Mhz USB clock using clock recovery
if (CONFIG_USBSERIAL) {
RCC->CRRCR |= RCC_CRRCR_HSI48ON;
while (!(RCC->CRRCR & RCC_CRRCR_HSI48RDY))
;
enable_pclock(CRS_BASE);
CRS->CR |= CRS_CR_AUTOTRIMEN | CRS_CR_CEN;
}
to:
// Enable 48Mhz USB clock using clock recovery
if (CONFIG_USBSERIAL || CONFIG_HAVE_STM32_USBCANBUS) {
RCC->CRRCR |= RCC_CRRCR_HSI48ON;
while (!(RCC->CRRCR & RCC_CRRCR_HSI48RDY))
;
enable_pclock(CRS_BASE);
CRS->CR |= CRS_CR_AUTOTRIMEN | CRS_CR_CEN;
}
will also set the internal HSI48 MHz USB clock when no USB serial is used .
Cheers,
Stephan