new Blackpill STM32G431CBU6

Post here first, or if you can't find a relevant section!
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

new Blackpill STM32G431CBU6

Post by ag123 »

https://www.aliexpress.com/item/1005005303669884.html
https://github.com/WeActStudio/WeActStu ... eBoard.git
https://www.eevblog.com/forum/microcont ... c-and-dac/
Blackpill STM32G431CBU6
https://www.st.com/en/microcontrollers- ... 431cb.html
170 MHz, 32k RAM, 128k Flash, 12-bit ADC and 12-bit DAC on the chip, hardware floating point, hardware CORDIC and AES support...
3 usd
:D
grabbed 2 pieces, what next :lol:

sram is a bit low but manageable.
a nice thing is this chip has 4 x 12-bit DAC channels
and which are pretty fast
and plus analog comparators and op amps
a bit like stm32f303 but much faster cpu speeds
2x4 Msps ADC?
a bunch of 'advanced' timers

commonly a 'bottleneck' is the ADC can produce a large amount of data at rather high speeds, but that usb full speeds is 12 mbps.
this limits to 'oscilloscope' type scenarios, i.e. the 'sweep' is determined by sram buffer in terms of the amount of data stored per sweep.

the op amps, pga is quite interesting, they probably can be used to measure currents (ground referenced though), not likely to do 'high side' stuff.

that CORDIC thing may be useful for delta robots / 3d printers, more accurate and high speed IK(inverse kinematics)
for this chip pin count is a bit low to do 3d printing. probably need a bigger chip with more sram and pins.

AES ? play with http(S)? well, 32k sram is a bit cram to do 'web' stuff

oh and these days
https://www.aliexpress.com/item/1005005303669884.html
double row pins practically means that it is 'dupont wires'
https://www.youtube.com/watch?v=eI3fxTH6f6I
all the way, rather than using breadboards
:lol:
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: new Blackpill STM32G431CBU6

Post by Bakisha »

Thanks for recommendation, i was looking for cheap (under 5€) board with DAC for some my old sound projects to play with.
As you said, no breadboard for this one, but dupont wires between modules and having three GND, two 3.3V and two 5V pins helps.
One thing that i find annoying is the user button, they decided to connect as Vcc->button->resistor->pin. Need internal pulldown resistor, but button logic is reversed compared to other boards.
Other is that SPI1 clock and MOSI line are next to DAC output pins and it have annoying interference on audio when using both. But for hobby stuff is OK.
SdFat library works on SPI1 port without problems.

analogWrite(PA4,x) is somewhat slow, around 500mS for 4096 incremented values, or around 122µS per write. But after first write, DAC1->DHR12R1 = x is blazing fast, i can see (and hear) 6.8Khz sawtooth waveform clearly.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: new Blackpill STM32G431CBU6

Post by ag123 »

oh, just realised that the user key is tied to PC13 and the button is tied to VCC
https://github.com/WeActStudio/WeActStu ... SchDoc.pdf

I'm thinking it may be feasible to use

Code: Select all

 pinMode(PC13, INPUT_PULLDOWN)
but that the series 330 ohm resistance is a little on the low side.

and oops about that MOSI issue too, I've not tried DAC codes yet, probably experiment with this one. many of the chips/boards didn't come with a DAC and it is good that this one has a DAC.
My thoughts are that to drive any loads, it would probably need a transistor in a common collector setup:
https://en.wikipedia.org/wiki/Common_collector
the load can be simply connected at the emittor pin.
This simple circuit has worked well for me, just that there would always be a Vbe reducing the output voltage of about 0.7v lesser than the input voltage.
I actually used that transistor circuit to drive a beeper / little speaker
https://github.com/ag88/stm32duino_rtttl
I'm thinking it may take an op amp to translate voltages to a higher level as well, perhaps things like LM358 may help.
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: new Blackpill STM32G431CBU6

Post by Bakisha »

I am yet to find what load DAC can drive, for now i directly connected to audio input of some old radio. Slap some infrared receiver module and it was very easy to port my https://github.com/Bakisha/STM32-SID-PLAYER
I replaced just the part from pwm driven pin to DAC driven pin. No more that high-pitched aliasing...

Code for DAC was very easy (thanks to core):

Code: Select all

void setup() {
  pinMode(PA4, OUTPUT);
   analogWrite(PA4, 0);
}
void loop() {
     for (int i = 0; i < 4096; i++) {
        DAC1->DHR12R1 = i; // faster version of analogWrite(PA4, i);
     }
}
You are right for transistor, it need 0.7V minimum, that is around from 869 to 4095 , which gives more then 11bit resolution.

I have some lm386, PAM8403 and that diy amplifier with bluetooth, like https://www.aliexpress.com/item/1005005053778718.html
Or i'll leave it as audio out directly from DAC.
Somehow, interference from SPI port have disappeared, maybe because i moved dupont wires a bit :D
For now, it's all wires :D
Few ULN2803 and i think i can add bunch of LEDs too...
Clipboard01.jpg
Clipboard01.jpg (91.88 KiB) Viewed 3819 times
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: new Blackpill STM32G431CBU6

Post by ag123 »

oh there is something else I'd think I'd want to explore on this chip/board is the comparators and the PGA op amps. from 2 - 64 gain
the opamps can be convenient to measure currents against GND at the low side e.g.
put a 100 milli ohm resistor at gnd, at 64x gain, it peaks at 0.515 amp, while at 32x gain it is 1.03 amp etc.
unfortunately, this is unlikely to work like INA219
https://www.ti.com/lit/ds/symlink/ina219.pdf
which can do high side current measurements.

I've been looking at various current measurement means with op amps, but that I've not found any 'ordinary' op amps which can do 'high side' measurements in part due to the limits for CMRR, almost all of them have voltage limits for CMRR and rather often no more than 0.7 VCC.

for 'low side' i.e. measuring at GND, it is ok provided that the DUT (device under test) is not connected to any other ground paths, otherwise the current measurements can be false and can be much lower than what is sourced from the +ve power supply.
That is likely useful say to use it as a buck converter say for MPPT solar lipo ion battery charging
umejopa
Posts: 9
Joined: Sat Oct 16, 2021 7:37 pm
Location: Stockholm

Re: new Blackpill STM32G431CBU6

Post by umejopa »

I order one and it works :)
Have anyone made a variant of this board in arduino for STM32 ?
I was setting the HSE with a extern "C" from CubeMX or the clock file from WeAct at 170Mhz but delay() will 3 time as long ?

extern "C" void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);

/** Configure LSE Drive Capability
*/
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);

/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE
|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV2;
RCC_OscInitStruct.PLL.PLLN = 85;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}

/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: new Blackpill STM32G431CBU6

Post by ag123 »

it would be good to start work on a variant and perhaps commit that as a PR to the STM core when it is good

some details though based on the schematics the onboard crystal seemed to be 8mhz
https://github.com/WeActStudio/WeActStu ... SchDoc.pdf

from the datasheet, (max) sysclock is 170 mhz
https://www.st.com/resource/en/datashee ... g431c6.pdf
then from the ref manual - RM440 chapter 7 figure 17 p278
https://www.st.com/resource/en/referenc ... ronics.pdf
the PLL multipliers which you are using seemed a little strange
PLL multipliers are normally of the form:

PCLK = fcrystal * N / M / P
QCLK = fcrystal * N / M / Q
RCLK = fcrystal * N / M / R

so if we take
M = 1
N = 42
R = 2
Q = 7
RCLK = 8 mhz (fcrystal) * 42 / 1 / 2 = 168 Mhz - note you would need to select SYSCLK from RCLK
QCLK = 8 mhz (fcrystal) * 42 / 1 / 7 = 48 Mhz - this one goes to the USB

the above would look like more 'sane' PLL multipliers.
you can experiment with finding PLL multipliers using a python sketch like this
viewtopic.php?t=78

In addition the AHB and APB speeds would normally need to step down from sysclk, RM440 chapter 7 figure 17 p278
https://www.st.com/resource/en/referenc ... ronics.pdf
it seemed a little strange that both the AHB and APB can run at 170 mhz, normally APB are run at lower speeds e.g. 40-80mhz to prevent io issues.
perhaps run AHB at sysclk i.e. sysclk divide by 1 - 168 Mhz
and run both APB1 and APB2 at 50% AHB speeds e.g. hclk divide by 2 ~ 84 Mhz.

then that those PLL setting codes would need to go into:
void SystemClock_Config(void) in the variant
https://github.com/stm32duino/Arduino_C ... figuration
take a look at other existing variants to see how those boards did it.
review the wiki on setting up a variant
https://github.com/stm32duino/Arduino_C ... ic-variant
review the source codes for existing variants (in particular existing custom boards) see how it is done
and boards.txt etc to see what entries is needed
umejopa
Posts: 9
Joined: Sat Oct 16, 2021 7:37 pm
Location: Stockholm

Re: new Blackpill STM32G431CBU6

Post by umejopa »

Well I take the setting from WeAht clock setting and put them in CubMx and it did not complane and get the same setting for clock.
I find in variant_B_G431B_ESC1.h
/* HAL configuration */
#define HSE_VALUE (24000000UL) and if rember right this board have 24Mhz cristal.
And set that in variant_generic.h
/* HAL configuration */
#define HSE_VALUE (8000000UL) for a 8Mhz 24Mhz cristal that the board have.

And now delay(1000) get 1 second before it was 3 second

It is good for me .
Now i will get debuging to work as it does for F103 , F303 , F407 for me and then see if i get CAN to work.

The generic clock setting for HSI (16Mhz) looks wery close for PLL and get 170Mhz
WEAK void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
#ifdef USBCON
RCC_PeriphCLKInitTypeDef PeriphClkInit = {};
#endif

/* Configure the main internal regulator output voltage */
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);
/* Initializes the CPU, AHB and APB busses clocks */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; //16Mhz / 4 * 85 /2 = 170
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
RCC_OscInitStruct.PLL.PLLN = 85;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/* Initializes the CPU, AHB and APB busses clocks */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8) != HAL_OK) {
Error_Handler();
}
trimarco232
Posts: 13
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

Re: new Blackpill STM32G431CBU6

Post by trimarco232 »

ag123 wrote: Thu Aug 24, 2023 7:05 pm oh there is something else I'd think I'd want to explore on this chip/board is the comparators (...)
I have just a question on how to program the comparator : nor the HAL or the LL or the LL structure worked for me on stm32duino , and I don't want to do it bare metal , so , ag123 , can you please share your code , or tell me the way to do , thanks !
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: new Blackpill STM32G431CBU6

Post by ag123 »

for the comparator, a good way is to 1st read the ref manual rm0440
https://www.st.com/resource/en/referenc ... ronics.pdf
if you couldn't figure out how to do it in HAL, one way is read the ref manual regarding the registers to setup.
then search in the include files for the predefined register definitions and use those.

in terms of the RCC codes i.e. setting up the PLL, it would seem the Weact codes could be using HSI (internal RC oscillator).
that is still different from settng up HSE i.e. to run the system clock and peripherals on the external crystal.
those pll multipliers I've given would likely work for the crystal and the board, what it takes is to take those and make a new variant.
otherwise, you could try the generic variants.
Post Reply

Return to “General discussion”