Page 2 of 3

Re: new Blackpill STM32G431CBU6

Posted: Thu Oct 05, 2023 8:03 am
by trimarco232
thanks ag123
my problem isn't the RM or the code to generate , but the fact that the libraries I use then , are not allowed / known by stm32duino
so , where can I find the "include files for the predefined registers" , and how can I import and declare them ?
(it is a general problem of using the libraries , not specific to comparator , it is the reason why I asked for a working exemple)

Re: new Blackpill STM32G431CBU6

Posted: Thu Oct 05, 2023 8:45 am
by ag123
after you install the 'official' stm core
in the folder where the core is installed, you should find a similar folder structure as that in the repository
https://github.com/stm32duino/Arduino_C ... /tree/main
in the system folder/directory
https://github.com/stm32duino/Arduino_C ... ain/system
you would find a huge set of folders and files for practically the whole series of stm32
further down in drivers folder, you would find the folders for CMSIS drivers and HAL drivers
I think there are some additional steps to use the HAL drivers, not too sure as I've not yet done that.
then in CMSIS if you drill further in you would find the CMSIS support files e.g. for G4
https://github.com/stm32duino/Arduino_C ... /STM32G4xx
and the includes in include
https://github.com/stm32duino/Arduino_C ... xx/Include
e.g. for stm32g431xx
https://github.com/stm32duino/Arduino_C ... 32g431xx.h
e.g.for comparator there are some definitions here
https://github.com/stm32duino/Arduino_C ... xx.h#L1103
https://github.com/stm32duino/Arduino_C ... 1xx.h#L283
then in the ref manual RM0440 chapter 24 comparator p773
https://www.st.com/resource/en/referenc ... ronics.pdf
hence accessing the register may be something like

Code: Select all

COMP1->CSR |= Configuration_bits;
replace Configuration bits with a constant number that would set the bits you need in the register.
it is likely you need to enable alternate functions on the GPIO pins and to select the alternate function (e.g. comparator) as well
those are covered in RM440 chapter 9 GPIO in the sub section
9.3.2 I/O pin alternate function multiplexer and mapping
9.3.11 Alternate function configuration
https://www.st.com/resource/en/referenc ... ronics.pdf
it is likely there are HAL LL functions for those tasks or one could access them using registers e.g. the CMSIS includes etc.

start by using the generic variant for the board and later you can make a custom variant that runs on HSE external crystal.

Re: new Blackpill STM32G431CBU6

Posted: Thu Nov 02, 2023 4:12 pm
by trimarco232
for the comparator , the solution is here : viewtopic.php?p=13269#p13269

for the HSE , I am trying umejopa's code , but it doesn't seam to work , I have :
- defined : #define HSE_VALUE (8000000UL) /// for a 8Mhz 24Mhz cristal that the board have
- put : extern "C" void SystemClock_Config(void) { ... etc ... in a dedicated TAB
- and called it from the setup : SystemClock_Config();

if I change the define to : #define HSE_VALUE (16000000UL) , the timings doesn't change , so I expect the stm32 is still in HSI mode : please what should I have to do now ?

Re: new Blackpill STM32G431CBU6

Posted: Thu Nov 02, 2023 5:19 pm
by dannyf
the answer to your question depends on a lot of factors, like your environment, your goal (do you want to boot-up to HSE or do you want to boot-up to HSI and switch over to HSE?)...

the easiest is to write a set of routings that switch between differernt clock sources. You can do that via HAL/LL or just roll your own vs. the datasheet (the easiest and the most difficult at the same time, depending on your level of comfort).

I don't have your chip but I do have a set of routines for G030. you can likely modify them for your chip, if not compiling directly.

Re: new Blackpill STM32G431CBU6

Posted: Thu Nov 02, 2023 7:46 pm
by ag123
btw, I'm not sure if every one is seeing the same, but that currently STM32G431 'pill board'
https://www.aliexpress.com/item/1005005303669884.html
seemed to be priced at modestly low(er), as compared to some simpler boards or chips
if may be worth grabbing a few for to try them out etc.
the good thing is this soc has DAC, Comparator, Op amps, etc. and runs quite fast 170mhz on a Cortex M4 core.
many of the 'lower priced', rather more basic socs e.g. stm32f103, stm32f401 etc don't have the DAC, Comparators and Op amps

a thing about the DAC is I think it possibly can't handle too much loads/currents. I'm thinking about using LM386 to buffer the outputs
https://www.ti.com/lit/ds/symlink/lm386 ... 8903967298
not sure if that made sense

Re: new Blackpill STM32G431CBU6

Posted: Thu Nov 02, 2023 11:15 pm
by dannyf
may want to check out tda2822. dual channel vs. mono on 386.

Re: new Blackpill STM32G431CBU6

Posted: Fri Nov 03, 2023 12:33 pm
by ag123
TDA2822 looks interesting
https://www.st.com/resource/en/datasheet/tda2822d.pdf
https://www.st.com/resource/en/datasheet/cd00000134.pdf
seemed quite available in the 'flea markets' as well
https://www.aliexpress.com/w/wholesale-tda2822.html
and a good thing is the pretty low supply voltage

LM386 it seemed is mostly a 5v part
https://www.ti.com/lit/ds/symlink/lm386.pdf

Another way though is a simple (npn) transistor, but that the output at collector is inverted.
https://en.wikipedia.org/wiki/Common_emitter
my guess is it is probably ok as the DAC would be able to select its output voltage
or maybe an emitter follower
https://en.wikipedia.org/wiki/Common_collector
just that for this the voltage is always input voltage - 0.7 (diode bias) voltage, so it'd leave less headroom to play with.

Re: new Blackpill STM32G431CBU6

Posted: Sat Nov 04, 2023 2:56 pm
by trimarco232
ag123 wrote: Thu Nov 02, 2023 7:46 pm btw, I'm not sure if every one is seeing the same, but that currently STM32G431 'pill board'
https://www.aliexpress.com/item/1005005303669884.html
seemed to be priced at modestly low(er), as compared to some simpler boards or chips
(...)
probably because the chip itself is just $2 in China

Re: new Blackpill STM32G431CBU6

Posted: Sat Nov 04, 2023 2:59 pm
by trimarco232
dannyf wrote: Thu Nov 02, 2023 5:19 pm (...)
I don't have your chip but I do have a set of routines for G030. you can likely modify them for your chip, if not compiling directly.
oh yes , thanks , in addition G030F6P6 will probably be my next one

Re: new Blackpill STM32G431CBU6

Posted: Sat Nov 04, 2023 6:04 pm
by dannyf
Another way though is a simple (npn) transistor
depends on what you want to do. if you are looking to output ac, both 2822/386 will work.

if you are looking to buffer the output (amplify current), a follower would be better / simpler. I often use 5532 - good current capability, and output down to ground... a npn will work but needs negative bias / feedback to go to ground.