STM32GENERIC, my arduino implementation

Discussions about the STM32generic core
Post Reply
danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

STM32GENERIC, my arduino implementation

Post by danieleff » Mon Apr 10, 2017 6:53 am

It seems current cores target specific boards, and try to make them work on others are an afterthought.
Even the official one is full of copy/paste and unnecessary code layers upon layers.

Last friday I also got the 407, so I decided to do a generic one on the weekend: https://github.com/danieleff/STM32GENERIC

Edit: documentation: https://danieleff.github.io/STM32GENERIC/

* Highlight is that USB Serial was working on 103s, on the 407VE, and on L0538-disco (did not test other boards), using the same code.
* tools and a few generic files shamelessly copied from stm32duino
* HAL from STM32 for every series, selecting the right one is with simple ifdefs. Blink should compile on every chip now.
* The implementation as of now is only a light wrapper on HAL (not code from the official core)
* Make it work first (with HAL), make it fast/small later (with register access on a case by case basis)
* Edit: No SPI / I2C / ADC / PWM yet... Although Serial UART is, and based on it, if the API is mostly the same for every series (I think yes), they should not be hard. these are in testable state
* No precompiled-staticlibrary stuff thingy
* Make variants (folder) as light as possible, so a new one can be easily added. Clock setup and pin list and thats it (and unfotunately ldscript). The chip-related peripheral settings are not in variant. (But variant should be able to override defaults.)
* Generated the chip related peripheral setup from cubemx .xml files
* Did not yet rearrange the pins
* Make a script to compile blink & others to see if everything compiles on every variant.

Well I have to go to work now...
Last edited by danieleff on Wed Apr 19, 2017 9:57 am, edited 1 time in total.

ag123
Posts: 798
Joined: Thu Jul 21, 2016 4:24 pm

Re: STM32GENERIC, my arduino implementation

Post by ag123 » Wed Apr 12, 2017 4:07 pm

this is really cool :D

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: STM32GENERIC, my arduino implementation

Post by danieleff » Wed Apr 12, 2017 8:29 pm

Thanks!

Added basic SPI implementation. Official adafruit ili9341 graphicstest already runs happily on black f407

zmemw16
Posts: 1484
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: STM32GENERIC, my arduino implementation

Post by zmemw16 » Wed Apr 12, 2017 10:03 pm

@danieleff
i couldn't resist trying it !
so the full list of minor tickles
  • 1.

    Code: Select all

    chmod u+x /home/stephen/sketchbook/hardware/STM32GENERIC/tools/linux/stlink_upload
    chmod u+x /home/stephen/sketchbook/hardware/STM32GENERIC/tools/linux/stlink/st-flash
    
    2.
    a fbrace of pairs (2)+(2)

    Code: Select all

    Invalid library found in /home/stephen/sketchbook/hardware/STM32GENERIC/STM32/libraries/test: /home/stephen/sketchbook/hardware/STM32GENERIC/STM32/libraries/test
    Invalid library found in /home/stephen/sketchbook/libraries/test: /home/stephen/sketchbook/libraries/test
    Invalid library found in /home/stephen/sketchbook/hardware/STM32GENERIC/STM32/libraries/test: /home/stephen/sketchbook/hardware/STM32GENERIC/STM32/libraries/test
    Invalid library found in /home/stephen/sketchbook/libraries/test: /home/stephen/sketchbook/libraries/test
    
    3.
    i assumed test lib goes under sketchbook/libraries, when i tried to find its example, in the drop down, it's grayed out and no example

    Code: Select all

    Examples for Black F407VE (upload STLink) 
    
btw the led blinks nicely :D

please tell me you're written all your steps down ? instructable / hackaday
last is true, seems less than a day :D

stephen

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: STM32GENERIC, my arduino implementation

Post by danieleff » Thu Apr 13, 2017 10:19 pm

Thanks, I fixed the linux execute flags.

The HardwareTest library should work now (no need to copy anywhere), there is a loop-back self test.
Connect PA0-PA1, PA6-PA7 (MOSI1-MISO1), RX/TX(UART1), PA2/PA3(UART2).
It tests if sending something on one pin (using digitalwrite/spi write/serial write) is received on the other. Good enough self test.
4 fast blink means a test passes, slow means fails. Later will add more.
Result is also printed through SerialUSB (on Black 407 at least).

Biggest problem is I don't have enough boards to test with.
Now onto analogread, than analogwrite...

zmemw16
Posts: 1484
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: STM32GENERIC, my arduino implementation

Post by zmemw16 » Thu Apr 13, 2017 10:26 pm

my lastest Black F407VE files are attached , only the ioc file is truly required :-)
it pretty much matches the schematic, lot of alternates to be set up, but the HAL generated code does that.
i suspect that if the JTAG is reduced to only SWD pins, then PB3 is then free to use as digital, consequently SCK

stephen
Attachments
stm32f407_black_vet.tar.gz
(188.07 KiB) Downloaded 33 times

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: STM32GENERIC, my arduino implementation

Post by danieleff » Sun Apr 16, 2017 1:42 pm

Added basic analogRead and analogWrite/PWM. And now I2C.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: STM32GENERIC, my arduino implementation

Post by danieleff » Mon Apr 17, 2017 10:46 am

And added basic I2C master. This concludes the first round of the implementation.
Next up: documentation and automated tests.

michael_l
Posts: 337
Joined: Mon Aug 24, 2015 6:11 pm

Re: STM32GENERIC, my arduino implementation

Post by michael_l » Wed Apr 19, 2017 7:25 am

This looks interesting, the variant specific files are very small.

I'm trying to understand the structure here. So actual implementation is based on CMSIS and HAL libraries which basically covers every peripheral for every board series. For getting this work in Arduino API - a light wrapper has to be created?

"Generated the chip related peripheral setup from cubemx .xml files". Can I ask how have you done this? is it so that CMSIS/HAL does not contain any chip related peripheral setup code and this needs to be done with e.g. cubemx ? Thanks.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: STM32GENERIC, my arduino implementation

Post by danieleff » Wed Apr 19, 2017 9:17 am

Hello

I have written now about the current project structure here: https://danieleff.github.io/STM32GENERI ... -structure
Currently lot of things just work by calling the HAL functions.
michael_l wrote: "Generated the chip related peripheral setup from cubemx .xml files". Can I ask how have you done this? is it so that CMSIS/HAL does not contain any chip related peripheral setup code and this needs to be done with e.g. cubemx ? Thanks.
There are a few things not in HAL files, mainly pin-peripheral alternate functions or which pin is connected to which ADC channel, what is the base clock frequencies for peripherals... This is not that important in the grand picture as it is generated using a python script from cubemx db/*.xml files.

Post Reply