Page 3 of 3

Re: new Blackpill STM32G431CBU6

Posted: Sat Nov 04, 2023 6:05 pm
by dannyf
I tried this on PY32, but untested on G0/G4.

Code: Select all

//simplest routine to switch to HSE
//no error checking
void SystemCoreClock2HSE(void) {
	//turn on hse
	RCC->CR |= RCC_CR_HSEON;				//1->turn on HSE, 0->turn off HSE
	//wait for HSE to be ready - error if stuck here
	while ((RCC->CR & RCC_CR_HSERDY)==0);		//1->HSE ready, 0->HSE not ready
	//switch to HSE
	RCC->CFGR = (RCC->CFGR &~RCC_CFGR_SW) |	//CLEAR_BIT SW bits
				(1 << RCC_CFGR_SW_Pos);		//0->HSI, 1->HSE, 2->PLLRCLK, 3->LSI, 4->LSE, others->reserved
	//wait for the switch to take place
	//while ((RCC->CFGR & RCC_CFGR_SWS) != (1<< RCC_CFGR_SWS_Pos));	//if stuck here, there is an error
	SystemCoreClockUpdate();				//update systemcoreclock
}

it can be easily changed to switch to HSI or other sources.

caution: zero error handing.

Re: new Blackpill STM32G431CBU6

Posted: Sun Nov 05, 2023 10:32 pm
by trimarco232
thanks !
maybe it works , but 10 time too slow ...

Re: new Blackpill STM32G431CBU6

Posted: Mon Nov 06, 2023 12:00 pm
by dannyf
That means it is working. As the crystal is like a few mhz and your default oscillator likely runs at 10s of mhz.

Re: new Blackpill STM32G431CBU6

Posted: Mon Jun 10, 2024 11:41 am
by GonzoG
I've put the clock config in arduino and timings ware 3x longer.
Adding

Code: Select all

#define HSE_VALUE               (8000000UL)
in arduino didn't help, but adding it in variant_generic.h file (in c:\Users\<user>\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.7.1\variants\STM32G4xx\G431C(6-8-B)U_G441CBU\) fixed it.
Delay and PWM work fine.

Edit:
USB Serial works without any issues.


Edit 2:

There's new version of WeAct G341CB with a single row pins:
https://www.aliexpress.com/item/1005007079255256.html