• Welcome to Andy's Workshop Forums. Please login or sign up.
 
March 29, 2024, 02:25:42 am

News:

SMF - Just Installed!


STM32 L0 support

Started by matthewphilyaw, October 16, 2016, 09:23:13 pm

Previous topic - Next topic

matthewphilyaw

I'm trying to gauge what is ahead of me to add support for the STM32 L0 line. I have been using this library for the STM32F030R8 part with good success and have a project in mind for the L0 line. By the way, really appreciate the work that has gone into this library and has been a great reference to study in regards to using C++.

For reference this board is what I'm targeting which uses the STM32L031K6 micro.

After studying the library the general flow I think I have down in that for each peripheral (under include and src) there is usually some common piece and then device specific specializations under folder matching the line (e.g F0). So I can see that working through those for L0 which in some cases maybe wholesale copies of F0 implementation where it fits.

Where things get a bit murky for me though is under the lib/fwlib for the L0 line. I understand the role of CMSIS and the stdperiph however, I'm not sure if the stdperiph is available for the L0 line. I believe (can't find a reliable answer) the L0 family only has the new HAL available.

If that is true, are the extensive parts I would need to modify to use the new HAL or can it be contained to the L0 specializations? Apologies if I'm not expressing this correctly, but by specializations I mean for instance take gpio/f0/features/DigitalInputFeature.h. In my case I would have something similar but would be like gpio/l0/features... and within it use the new HAL layer to setup the GPIO.

My plan would be to add STM32PUS_L0 define and in the config/stdperiph.h include HAL headers instead of stdperiph for that family and work my way through - mainly curious if there is something major impeding me from doing that or if this has been done before?

Andy Brown

Fundamentally the issue is that stm32plus depends throughout on the standard peripheral library which has now been replaced for the new MCU lines with the HAL. If the L0 is similar enough to the F0 then you might find that peripherals common to both will 'just work' because the register locations and formats are the same so standard peripheral library methods designed for the F0 will work on the L0. This is just my guesswork though. Try compiling the 'blink' example targeting the F030 and upload it to the L031 (with startup files modified for the L0).

If you need support for peripherals unique to the L0 then you'd have to use the HAL (or registers) to access them and your approach of creating a new section in config/stdperiph.h is the right way. Personally I think that the HAL is so badly written I'd be sorely tempted to just go straight for the registers if the peripheral is simple enough.
It's worse than that, it's physics Jim!

matthewphilyaw

I may actually be mistaken, well in part. Seems that ST does provide a "Low Layer" (not the most interesting doc) API that is distributed along side the HAL and can use it without the need of the HAL.

Out of curiosity started comparing LL API source to the stdperiph and it's very similar. It "feels" like the same code, but just updated in places. Unfortunately, I'm still somewhat "new" to this facet of programming (day job is in C#) so can't really say that it's better or worse. It also seems fairly complete for the L0 family.

The HAL was appalling enough for me to dig into CMSIS and learn to write drivers against the registers (actually glad I did, great experience) - if that says anything about what I thought of it. It was rather disorienting and recently started looking at it again last week in prep in cases I needed it and it wasn't much better the second time around. It's great they have examples etc, but the API is a bit opinionated and it seems like would dictate your program design heavily.

I appreciate your quick reply, you confirmed what I was thinking. My plan is to attempt to add the L0 family in, and now knowing about the LL API it will likely be the route I take or go against the registers. As mentioned above, revisiting the HAL again in the last week it didn't become any more appealing. Definitely will try the F0 blinky program on the L0 as well to see what happens. I have feeling it will show me what I can copy from the F0 code. There are some L0 specific things I want to add in as well.