Blackpill STM32G431CBU6 - 170 MHz / 32k RAM / 128k ROM / 12-bit ADC and DAC,... - Page 1
Forum section: electronics / general

author: radiolistener
author_rank: Super Contributor
timestamp: July 23, 2023, 11:54:02 pm
content: Just bought pretty nice blackpill STM32G431CBU6:https://www.aliexpress.com/item/1005005303669884.htmlAllows to run core at 170 MHz, 32k RAM, 128k ROM, 12-bit ADC and 12-bit DAC on the chip, hardware floating point, hardware CORDIC and AES support...All this just for 3 USDChinese ST-LINKv2 supports it, but it requires to update ST-LINK utility and upgrade ST-LINK firmware, I had old ST-LINK utlility and it was unable to recognize it. After ST-LINK firmware upgrade it detects it as:Code:Device ID:0x468Device flash Size : 128KBytesDevice family :STM32G43x/G44xOnboard HSE is 8 MHz (claimed as 10 ppm) also has onboard clock crystal 32.768 kHz. The module has one blue user LED (PC6) and one user key (PC13), both are duplicated on module GPIO. Also it comes with NRST button, BOOT button and USB-C connector.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 24, 2023, 12:08:48 am
content: Indeed, nice MCU for the priceHere's a cheaper option if first time buying (Aliexpress Welcome deal):https://www.aliexpress.com/item/1005005451007632.htmlI might prefer the stm32f411ceu6 black pill, it's slower but packs a lot of storage (128/512K), however last years it got a lot more expensive.

author: radiolistener
author_rank: Super Contributor
timestamp: July 24, 2023, 01:36:30 am
content: Sawtooth and sine waveform from onchip 12-bit DAC running at 2 MS/s on this STM32G431CBU6 board.The sawtooth signal is increment on each next sample.The sine signal is generated at realtime

author: radiolistener
author_rank: Super Contributor
timestamp: July 24, 2023, 01:47:40 am
content: Quote from: DavidAlfa on July 24, 2023, 12:08:48 amstm32f411ceu6 doesn't have DAC, ADC only.I bought this STM32G431CBU6 module because it has onchip ADC and DAC, so it can be used for DSP...

author: iMo
author_rank: Super Contributor
timestamp: July 24, 2023, 07:45:48 am
content: Do the pins have 0.1inch pitch or 0.05inch? (the picture shows "1,37mm")..

author: bingo600
author_rank: Super Contributor
timestamp: July 24, 2023, 08:18:12 am
content: Quote from: radiolistener on July 24, 2023, 01:36:30 amAny chance of a link/zip to the sourcecode for this demo/Bingo

author: dobsonr741
author_rank: Frequent Contributor
timestamp: July 24, 2023, 09:29:23 am
content: Nice find. These are the docs:https://github.com/WeActStudio/WeActStudio.STM32G431CoreBoard/

author: Doctorandus_P
author_rank: Super Contributor
timestamp: July 24, 2023, 10:32:18 am
content: I think WeAct is one of my favourite Ali stores.For one, they have the "Blue Pill" both in STM and some other variant, which suggests that they are one of the very few that do not lie about the "Blue Pill" pcb's. But I do have plenty on storage so have not bought those.I did buy a bunch of STM32F411 "Black Pills" halfway though Chippageddon for over EUR7 a piece. Now prices seem to have come down t below EUR4.I also appreciate they have some github repositories with example code. It shows that they at least put in some effort beyond just delivering the bare hardware.

author: ozcar
author_rank: Frequent Contributor
timestamp: July 24, 2023, 10:38:09 am
content: Quote from: iMo on July 24, 2023, 07:45:48 amI think the 1.37mm is the distance from the outer row to the edge of the board. Assuming that to be the case, from the other dimensions given, I calculate the spacing is 2.54mm, so, yeah 0.1 inch.For the sort of things I do I prefer boards with a single row of pins on each side though.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: July 24, 2023, 10:50:09 am
content: Quote from: ozcar on July 24, 2023, 10:38:09 amYeah, I also thought of that.In the comment on the We Act store, there is also a wish for being "breadboard compatible".Then I had an epiphany...You can solder half the header pins on the bottom, and the other half on the top.Then, with the bottom pins you can stick it in a breadboard, and you can use the top pins and "Dupont Wires" to bugger off to some other place on your breadboard.

author: iMo
author_rank: Super Contributor
timestamp: July 24, 2023, 11:04:26 am
content: .. while reading the github docs - there is a warning of fakes alreadyQuote

author: radiolistener
author_rank: Super Contributor
timestamp: July 24, 2023, 04:12:21 pm
content: Quote from: iMo on July 24, 2023, 07:45:48 amJust measured it, the distance between first pin and last pin is about ~27.95 mm / 11 (12 pins) = 2.54 mm between pins. The step between pins is the same as on original blue pill. But holes are very small, so they have very tight contact even without soldering it...

author: radiolistener
author_rank: Super Contributor
timestamp: July 24, 2023, 04:37:29 pm
content: Quote from: iMo on July 24, 2023, 11:04:26 amI bought it here:https://www.aliexpress.com/item/1005005303669884.htmlIt has WeAct label and version V1.0. It comes with PLS headers for GPIO and for SWD but they are not soldered, so you can solder it as you wish. I soldered just SWD header.The board is very small. It has extreme small smd components, so if you want to resolder something, it will be not so easy.Actual HSE crystal frequency on my instance is 8000054 Hz (6 ppm). I measured it by enable MCO output of HSE signal on PA8 pin.Quote from: ozcar on July 24, 2023, 10:38:09 amYeah, I also stuck on that. If I solder double row pls headers, it will be problematic to deal with all gpio on breadboard. So, I'm thinking about soldering just a single row headers...

author: tszaboo
author_rank: Super Contributor
timestamp: July 24, 2023, 04:51:33 pm
content: That looks like a really cool part. Searched the price on LCSC, 1.7USD for a single piece. Same price on Digikey, 4 EUR if you buy a whole reel.Something is really broken with our pricing.

author: radiolistener
author_rank: Super Contributor
timestamp: July 24, 2023, 05:50:33 pm
content: Quote from: bingo600 on July 24, 2023, 08:18:12 amok, I will publish it later, currently it uses hand made header files, I want to replace it with standard one...

author: radiolistener
author_rank: Super Contributor
timestamp: July 25, 2023, 10:07:31 am
content: Quote from: bingo600 on July 24, 2023, 08:18:12 amhere is source code for this test demo which generate sine wave with hardcoded frequency on PA4 DAC output, also it put HSE clock to PA8 and use LED blink in background.A short description: PLL is configured to be clocked from external HSE 8 MHz clock and produce 170 MHz clock, which is used for SYSCLK and as a source for TIM2. TIM2 is configured to be triggered at 2 MHz rate. TIM2 interrupt handler contains code to calculate sine wave and update DAC with a new value.PLL frequency is the following:Fout = ((Finput / PLLM) * PLLN) / PLLRSince Finput= 8 MHz, we use PLLM=2, PLLN=85 and PLLR=2, so the PLL output frequency will be:Fout = ((8 MHz / 2) * 85) / 2 = 170 MHzYou can change sine frequency on DAC output in init_sine argument. Note that you're needs to update sample rate in init_sine arguments if you change TIM2 divider.Header files consume 13 MB of space even without HAL, but I think it's better to include it. All required files are included in archive.for GCC compiller just enter to GCC folder and type make.for EWARM enter to EWARM folder and use included workspace file.here is main.c:Code:#include <math.h>#include <stm32g431.h>// test code for STM32G431CBU6 module// https://www.eevblog.com/forum/microcontrollers/blackpill-stm32g431cbu6-170-mhz-32k-ram-128k-rom-12-bit-adc-and-dac///// PC6 = LED// PC13 = KEY// PA4 = DAC out// PA8 = HSE outvoid init_gpio(void){// Enable GPIOC clockSET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_GPIOCEN);// PC6 = OUT (LED)MODIFY_REG(GPIOC->MODER,GPIO_MODER_MODE6,1 << GPIO_MODER_MODE6_Pos);// PC6 speedMODIFY_REG(GPIOC->OSPEEDR,GPIO_OSPEEDR_OSPEED6_Msk,GPIO_SPEED_FREQ_VERY_HIGH << GPIO_OSPEEDR_OSPEED6_Pos);// PC13 = IN (KEY)MODIFY_REG(GPIOC->MODER,GPIO_MODER_MODE13,0 << GPIO_MODER_MODE13_Pos);// Enable GPIOA clockSET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_GPIOAEN);// PA8 = ALTFN MCOMODIFY_REG(GPIOA->MODER,GPIO_MODER_MODE8,2 << GPIO_MODER_MODE8_Pos);// PA8 alternate function MCOMODIFY_REG(GPIOA->AFR[8 >> 3U],GPIO_AFRH_AFSEL8_Msk, // 0xFU << ((8 & 0x07U) * 4U),GPIO_AF0_MCO << GPIO_AFRH_AFSEL8_Pos); // GPIO_AF0_MCO << ((8 & 0x07U) * 4U));// PA8 speedMODIFY_REG(GPIOA->OSPEEDR,GPIO_OSPEEDR_OSPEED8_Msk,GPIO_SPEED_FREQ_VERY_HIGH << GPIO_OSPEEDR_OSPEED8_Pos);// PA8 pull modeMODIFY_REG(GPIOA->PUPDR,GPIO_PUPDR_PUPD8_Msk,GPIO_NOPULL << GPIO_PUPDR_PUPD8_Pos);// Configure MCO = HSE / 1MODIFY_REG(RCC->CFGR,RCC_CFGR_MCOSEL | RCC_CFGR_MCOPRE,RCC_MCO1SOURCE_HSE | RCC_MCODIV_1);}void init_clock(void){// Select SYSCLK source = HSIMODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_HSI);while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI);// Stop PLLCLEAR_BIT(RCC->CR, RCC_CR_PLLON);while ((RCC->CR & RCC_CR_PLLRDY) != 0);// Enable high voltage for power regulator to 1.28 VCLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);// Configure FLASH latency = 4FLASH->ACR = FLASH_ACR_DBG_SWEN | FLASH_ACR_DCEN | FLASH_ACR_ICEN | FLASH_ACR_LATENCY_4WS ;while ((FLASH->ACR & FLASH_ACR_LATENCY_Msk) != FLASH_ACR_LATENCY_4WS);// Power on HSE crystalSET_BIT(RCC->CR, RCC_CR_HSEON);while ((RCC->CR & RCC_CR_HSERDY) == 0);// Configure PLL used for SYSCLK// PLLM=2 (value 1), PLLN=85 (value 85), PLLR=2 (value 0)MODIFY_REG(RCC->PLLCFGR,RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLM | RCC_PLLCFGR_PLLN | RCC_PLLCFGR_PLLR,RCC_PLLCFGR_PLLSRC_HSE | (1 <<RCC_PLLCFGR_PLLM_Pos) | (85 << RCC_PLLCFGR_PLLN_Pos) | (0 << RCC_PLLCFGR_PLLR_Pos));// Start PLLSET_BIT(RCC->CR, RCC_CR_PLLON);while ((RCC->CR & RCC_CR_PLLRDY) == 0);// Enable PLL output for SYSCLKSET_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLREN);// Select SYSCLK source = PLLMODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL);while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL);}void init_TIM2(void){SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_TIM2EN); // Enable TIM2 clockTIM2->ARR = 85 - 1; // Auto-reload register f = 170 000 000/(TIM2_ARR+1), 2 MHz -> (85 - 1)SET_BIT(NVIC->ISER, (1 << 28));// Enable NVIC interrupt #28 (TIM2)SET_BIT(TIM2->DIER, TIM_DIER_UIE);// Enable timer overflow interruptSET_BIT(TIM2->CR1, TIM_CR1_CEN); // Enable timer}// DAC1 on PA4void init_DAC1(void){SET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_DAC1EN); // Enable DAC1 clockSET_BIT(DAC1->CR, DAC_CR_EN1);// Enable DAC1 outputDAC1->DHR12R1 = 0;// Write DAC1 = 0}#ifndef M_PI#define M_PI 3.14159265358979323846#endiffloat R;float V;float X;float S;void init_sine(float freq, uint32_t sample_rate){// init sine oscillatorR = pow(2.0 * sin(freq * M_PI / sample_rate), 2.0); // = 4.0 * (freq * M_PI / sample_rate) * (freq * M_PI / sample_rate);V = 0;X = 2000; // initial value (amplitude)S = 2048; // offset}void main(){init_sine(10000.0, 2000000);init_gpio();init_clock();init_DAC1();init_TIM2();for (;;){for (uint32_t i=1000000; i > 0; i--); // delayGPIOC->ODR ^= GPIO_ODR_OD6; // change LED state}}void TIM2_IRQHandler(void){CLEAR_BIT(TIM2->SR, TIM_SR_UIF);// Reset TIM2 overflow flag// update sine oscillatorV -= X * R;X += V;DAC1->DHR12R1 = (uint32_t)(X + S);}//----------------------------------------------------void NMI_Handler(void){__asm("BKPT 0");}void HardFault_Handler(void){__asm("BKPT 0");}void MemManage_Handler(void){__asm("BKPT 0");}void BusFault_Handler(void){__asm("BKPT 0");}void UsageFault_Handler(void){__asm("BKPT 0");}PS: stm32g431.h is my file, it includes standard stm32g4xx.h and stm32g431xx.h and also add some constants taken from HAL headers. I don't include HAL, because it eats > 70 MB of space.PPS: in order to build it on linux you're needs to install:Code:sudo pacman -S arm-none-eabi-gcc arm-none-eabi-newlib

author: dobsonr741
author_rank: Frequent Contributor
timestamp: July 25, 2023, 10:35:12 am
content: How come not calling the sine() function in the interrupt handler, neither using pre calculated sine table values?

author: radiolistener
author_rank: Super Contributor
timestamp: July 25, 2023, 10:49:49 am
content: Quote from: dobsonr741 on July 25, 2023, 10:35:12 amprecalculated table for sine will leads to a very dirty sine with high distortions and harmonics. Especially when sample rate is not integer multiply of sine frequency. I'm using sine calculated at runtime to avoid distortions and harmonics to get more clean sine. It eats just 3 arithmetic operations, don't eats memory and allows to produce any fractional sine frequency.Adding call for sine calculation leads to additional tacts delay so it reduces maximum possible sample rate for DAC, because ISR handler needs more time to execute call for sine().

author: iMo
author_rank: Super Contributor
timestamp: July 25, 2023, 11:10:47 am
content: He is using a trick, imho - something like hacked optimized cordicAnd with the single precision FPU enabled it is pretty fast..

author: dobsonr741
author_rank: Frequent Contributor
timestamp: July 25, 2023, 06:13:55 pm
content: Yes, and it works great with fixed point too, not just with floating. Just run it in Python/Fxp.

author: iMo
author_rank: Super Contributor
timestamp: July 25, 2023, 06:53:05 pm
content: There are freqs where it gets out of range, like for 222222 you get 4107, -10, etc..

author: radiolistener
author_rank: Super Contributor
timestamp: July 25, 2023, 08:16:52 pm
content: Quote from: iMo on July 25, 2023, 06:53:05 pmYou can fix it with reduce amplitude in X variable or offset in S variable.Also it has some frequency error because R is calculated with approximation. If you use this one:Code:R = 4.0 * (freq * M_PI / sample_rate) * (freq * M_PI / sample_rate);it gives you pretty high frequency error (about 85 kHz instead of 80 kHz), but doesn't needs to use sin function.If you use this one:Code:R = pow(2.0 * sin(freq * M_PI / sample_rate), 2.0);it gives you better frequency precision, but requires sin function. But also has some frequency error, just smaller.If you're needs a fixed frequency, you can adjust the frequency manually in order to get a more accurate result

author: peter-h
author_rank: Super Contributor
timestamp: July 27, 2023, 07:53:46 am
content: Is this CPU made by ST, or is it a chinese replica?It is very cheap.You can do arbitrary waveform generation by using a timer to trigger a DAC fed with DMA. I am doing that on my 32F417, two concurrent channels.

author: ag123
author_rank: Contributor
timestamp: July 27, 2023, 01:06:30 pm
content: Quote from: Doctorandus_P on July 24, 2023, 10:50:09 amthat is 'a pretty good idea'but that these days 'dupont wires' 'nearly replaced' breadboards for some of my projects, I actually bothered to buy those 'dupont pins'https://www.aliexpress.com/w/wholesale-dupont-pins.htmland crimped my own wires, I made do without shells.as for shells, a good replacement is simply heat shrink tubes 1 per pin, they save a lot in the overall height of the pins without the shellsand for 'modular' wires, I sometimes used ribbon cables with the pins, e.g. with LCDs that often is a 'bunch' of wires.so these days it becomes a 'mess of wires', but that I'm finding it 'better' than breadboards as the whole circuit is complete without needing a breadboard.they can practically be placed into (project) boxes

author: radiolistener
author_rank: Super Contributor
timestamp: July 29, 2023, 06:11:13 am
content: Quote from: peter-h on July 27, 2023, 07:53:46 amWho knows, but it looks good and works great, so I don't see reason to worry about it.I think they sell it with cheap price to make it popular so many users will request large quantity from factory.I hear that fake STM32 chips are made with different brand name. So, if it marked with original ST, most of all it's original.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: July 29, 2023, 05:29:52 pm
content: QuoteIf it really has the math accelerators, floating point, the rich analog (3 opamps, 4 comparators, voltage reference) then I highly doubt it's a replica. Rather factory reject or maybe stolen or auctioned off.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 05, 2023, 09:12:57 am
content: Quote from: radiolistener on July 29, 2023, 06:11:13 amJust wait until you've been banging your head to the wall and bouncing between the floor and the ceiling for a few days because you can't get some kind of feature of your chip to work, and then find out later that it's some kind of incompatible chip made by some other vendor.Quote from: radiolistener on July 29, 2023, 06:11:13 amNope. Take for example the ubiquitous "Blue Pill". Some (5?) years ago they cost around USD 4 and were great. Then the market got swamped by fakes, and prices also dropped to USD1.5 There are some 8 manurefacturers of xxx32F103xxx chips and it became very common to take one of those chips, blacktop it and print an STM part number on it. There is a long thread about these fakes on this forum.It's why I stopped buying Blue Pills. (and also because it's a very old chip)It also shows why I like WeAct. WeAct still sells Blue Pills, but they sell different variants.This one with an STM part number:https://www.aliexpress.com/item/1005004918334754.htmlAnd another listing where you can choose between GD, APM and CH variants.https://www.aliexpress.com/item/1005001474741936.htmlAnd as long as they send you what they show in their shop, it's not a fake, but a ... clone? alternative? At least, as long as you get what you buy I'm OK with it, but when I discover a black topped chip and some other part number printed on it, then it's instant negative feedback. I have no tolerance for that. Just having to fiddle with the ID code in makefiles to get it to recognize some other chip is already more bothersome then the price difference is worth.

author: iMo
author_rank: Super Contributor
timestamp: August 05, 2023, 09:23:59 am
content: Rumors say they cannot copy beyond stm32F3xx technology yet (because the F4+ is difficult). So their copies are limited to stm32F1xx and 3xx chips these days.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: August 06, 2023, 03:51:14 am
content: Got one, this is the chip. Looks authentic.A code above the manufacturing date (213) is different: 129R vs OP’s 1A9R

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 06, 2023, 04:43:43 am
content: Fakes have pretty bad marking quality, with low resolution and irregular characters.When you see that perfectly laser-engraved marking you know it's original.

author: prosper
author_rank: Regular Contributor
timestamp: August 10, 2023, 09:17:54 pm
content: I bought a couple. They sure seem to look and act real.They're a dynamite little platform for mixed-signal work, with the math accelerator. Kind of an odd interface though - you twiddle some register bits to set up the operation you want to perform, then you poke and peek data from a register to get it into and out of the device, as opposed to an instruction set extension to the cpu itself. Feels kind of weird to use.Still, the thing works great for all sorts of analog work. Got mine doing some audio synthesis stuff so far, and I'm curious to see how far I can take it before it hits it's limits, or I hit my skill limit. DSP maths is not my most favourite thing, and I only just passed my math courses back in school by a not-impressive margin.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 10, 2023, 11:48:23 pm
content: Just today I had a look at theb-g431b-esc1. It is an ESC ("Electronic speed controller", aka BLDC motor driver for folks outside the hobby RC market) and it also has an STM32G431 It's not exactly cheap as a development board, but as the complete ESC is included, it's price for around EUR30 is very reasonable for a product you can buy in "western" stores. (Or directly from ST?)I also opened the design files (altium project) in KiCad and discovered this is an 8 layer PCB, and that makes it quite amazing. All the 3D models are also included and it looks "complete" in KiCad's 3D viewer. (I have not matched schematic symbols with PCB footprints, that is still a limitation in the altium importer in KiCad).