[chbot] AI help with STM32
Robin Gilks
gb7ipd at gmail.com
Thu Jul 3 06:32:25 BST 2025
My approach has always been if you can't write maintainable code by using a
reasonable HAL then buy a faster processor.
I've yet to find any HAL code that is so bad it stops things from working -
due to the conditional compilation in a lot of it, the actual code
generated actually isn't that huge. You'll also find that the documentation
isn't so bad provided you just read the relevant bits and not worry about
the number of pages!! You will need 3 documents - the Reference Manual,
the Production Data sheet (for the specific variant you have) and the HAL
for the range. There are also very useful Application Notes with things
like Timer cookbook, peripheral interconnect (very handy when getting DMA
events organised) and several DMA specific ones.
One thing I will advise on - most of the examples in the HAL packages are
total crap and repeat ad nauseum for most of the processors in a range
which really doesn't give you many different examples to help understand
what is going on . The hardware JPEG encode/decode in the F7 series had me
jumping about for 6 months before I twigged that the cache memory mapping
needed adjustment for that IP block to work in anything other than the
default memory region used in the examples.
My latest project took about 2 hours to assign all the peripherals and pins
for a Black Pill (stm32f411) which was USART, SPI, Timer (with 2 capture
events), all using DMA (so 7 streams) plus USB and the CDC USB stack. It
also has the usual debug, GPIO stuff and interrupt handlers. Generate code
and run 'make' to convince yourself that it worked and then fill in the
blanks of your application.
On Thu, Jul 3, 2025 at 2:42 PM Mark Atherton <markaren1 at xtra.co.nz> wrote:
> Ha! Well done Richard.
>
> .. and thanks Charles.
>
> -Mark
>
>
> On 03-Jul-25 2:32 PM, Richard Jones wrote:
> > I used the HAL to configure registers as needed, then read out the
> > results in code to write the instructions to load registers directly for
> > speed. In my case I printed the results as 'C' code using printf ( using
> > bit band or register writes ) so I just cut and pasted the printed 'C'
> > code into the application. Not at all portable, and not obvious to read,
> > but I achieved the speed that I needed at the time.
> >
> > Cheers
> >
> > Richard
> >
> > On Thu, Jul 3, 2025 at 12:56 PM Charles Manning <cdhmanning at gmail.com
> > <mailto:cdhmanning at gmail.com>> wrote:
> >
> > OK, I can't help in your stated quest of an AI assistant, but here
> > is how I tend to go about STM32 development which might get what you
> > want.
> >
> > First I use the CubeMX tool to do all the primary set up (peripheral
> > initialisation, clock trees, dma channel assignment etc).
> > For some of the peripherals, the performance is not too critical and
> > the HAL podge is not too podgy. The HAL can work there.
> > Then there are the few bits where the HAL is too bloaty and/or slow
> > and/or missing the features you want. That is where I write my own
> > drivers and bypass the HAL.
> >
> > It is OK to mix and match like that. It means you only need to go
> > datasheet mining in a few critical places.
> >
> > Obviously you don't want to do things like write to the
> > peripheral at the same time via HAL and your own code, but it is OK
> > to use HAL to set things up, then apply your own tweaks then use
> > your own code to do all the read/write stuff etc.
> >
> > This has worked well for me in the past and gives me the best of
> > both worlds (well most of the time anyway).
> >
> >
> > On Thu, Jul 3, 2025 at 10:49 AM Mark Atherton <markaren1 at xtra.co.nz
> > <mailto:markaren1 at xtra.co.nz>> wrote:
> >
> > Hi Charles,
> >
> > You are quite right, I could just dig straight into the
> > documentation,
> > but at last count, there are something over 2,600 pages
> > associated with
> > the STM32G491.
> >
> > I was rather hoping to implement then experiment with some new
> > ideas,
> > rather than go into battle over trying to get peripherals
> > configured.
> >
> > I am also quite shameless in terms of asking for help in any
> > form that
> > might be available.
> >
> > Anyway, can anyone recommend an AI assistant that might be
> > useful in my
> > journey ?
> >
> > Thanks,
> >
> > Mark
> >
> > ----------
> >
> > Charles Manning said
> >
> > What's wrong with the grey stuff sitting on your shoulders?
> >
> > The HAL normally has multiple modes of operation, including DMA
> > options,
> > but if you're pushing the micro hard the HAL is often a bit
> > bloated and
> > slow.
> >
> > _______________________________________________
> > Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> > <mailto:Chchrobotics at lists.ourshack.com>
> > https://lists.ourshack.com/mailman/listinfo/chchrobotics
> > <https://lists.ourshack.com/mailman/listinfo/chchrobotics>
> > Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> > <http://lists.ourshack.com/pipermail/chchrobotics/>
> > Meetings usually 3rd Monday each month. See http://kiwibots.org
> > <http://kiwibots.org> for venue, directions and dates.
> > When replying, please edit your Subject line to reflect new
> > subjects.
> >
> > _______________________________________________
> > Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> > <mailto:Chchrobotics at lists.ourshack.com>
> > https://lists.ourshack.com/mailman/listinfo/chchrobotics
> > <https://lists.ourshack.com/mailman/listinfo/chchrobotics>
> > Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> > <http://lists.ourshack.com/pipermail/chchrobotics/>
> > Meetings usually 3rd Monday each month. See http://kiwibots.org
> > <http://kiwibots.org> for venue, directions and dates.
> > When replying, please edit your Subject line to reflect new subjects.
> >
> >
> > _______________________________________________
> > Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> > https://lists.ourshack.com/mailman/listinfo/chchrobotics
> > Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> > Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> > When replying, please edit your Subject line to reflect new subjects.
>
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> https://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20250703/1b3f0c34/attachment-0001.html>
More information about the Chchrobotics
mailing list