libopeninv STM32F4

Post Reply
User avatar
johu
Site Admin
Posts: 5683
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

libopeninv STM32F4

Post by johu »

For a side project I made a branch of libopeninv for the STM32F4.

Again, I will blog a bit about it. Note that at this stage the code is untested, it doesn't run.
USART terminal via DMA and GPIO running.

You can see the changes in the stm32f4 branch: https://github.com/jsphuebner/libopeninv/tree/stm32f4

DMA
DMA is organized a bit differently. Basically there are two DMA controllers (not unique, there also also F1s with 2 DMA controllers). But they are organized in streams and channels. Streams on the F4 is a bit like channels on the F1. Every peripheral is hardware-assigned to a certain stream, sometimes to more than one, to avoid conflicts. You then have to tell the stream which of the possible peripherals it should talk to.
Consequently, only some renaming is needed, e.g. instead of

Code: Select all

dma_enable_channel(DMA2, DMA_CHANNEL1);
we now write

Code: Select all

dma_enable_stream(DMA2, DMA_STREAM0);
The only additional command is selecting the channel of the stream

Code: Select all

dma_channel_select(DMA2, DMA_STREAM0, DMA_SxCR_CHSEL_4);
ADC
Looks to work the same, only the calibration commands are missing.
An additional command is needed to enable continuous conversion via DMA:

Code: Select all

adc_set_dma_continue(ADC1);
CAN
Only slight changes in ISR names

Flash
Seems to be organized in rather large sectors rather than pages. Will have to see how that works

GPIO
Different concept. When using a pin for a peripheral we have to explicitly specify which peripheral is connected to the pin. The indexes are in the manual.
In place of

Code: Select all

gpio_set_mode(GPIO_BANK_CAN1_TX, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_TX);
we write

Code: Select all

gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12);
gpio_set_af(GPIOA, GPIO_AF9, GPIO11 | GPIO12);
So the additional clear/set command for selecting pull-up/down is not needed. Also there is just one output frequency. Note the convenience macros don't exist (or have been renamed?)

Clock setup

Code: Select all

rcc_clock_setup_in_hse_8mhz_out_72mhz()
changes to

Code: Select all

rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ])
That probably means going over the various peripheral prescalers to get valid CAN baudrates and scheduler intervals.

RTC
Seems very different, rtc_get_counter_val() doesn't exist anymore.

Makefile
in the CFLAGS and CPPFLAGS we need to change -DSTM32F1 to -DSTM32F4 to select the correct header files of libopencm3
Also some hardware specific flags need to be added/changed:

Code: Select all

-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
and finally the linker needs to ling against -lopencm3_stm32f4
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5683
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: libopeninv STM32F4

Post by johu »

Got blinky :)
Using TIM2 for scheduling turned out a bad idea, it is a 32-bit counter.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5683
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: libopeninv STM32F4

Post by johu »

Boot loader done. Same protocol as always, just different memory organization.
Look here: https://github.com/jsphuebner/tumanako- ... ee/stm32f4

Basically the F4 has 4 sectors that are 16k in size and start at address 0x08000000 (as always). Then follows sector 4 which is 64k. And finally sectors 5-11 which are 128k each. Right now I have reserved space for firmware only in sector 5, so 128k, start address 0x08020000.
The configuration data will live in one of the 16k sectors and no longer at the end of flash.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Jack Bauer
Posts: 3563
Joined: Wed Dec 12, 2018 5:24 pm
Location: Ireland
Has thanked: 1 time
Been thanked: 87 times
Contact:

Re: libopeninv STM32F4

Post by Jack Bauer »

Any f4 in particular?
I'm going to need a hacksaw
User avatar
johu
Site Admin
Posts: 5683
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: libopeninv STM32F4

Post by johu »

Currently using the Olimex STM32-H405 which is home to an STM32F405RGT6
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Jack Bauer
Posts: 3563
Joined: Wed Dec 12, 2018 5:24 pm
Location: Ireland
Has thanked: 1 time
Been thanked: 87 times
Contact:

Re: libopeninv STM32F4

Post by Jack Bauer »

It sure looks like the f407 and f107 are pin compatible ....
I'm going to need a hacksaw
User avatar
mackoffgrid
Posts: 93
Joined: Thu Jan 02, 2020 10:18 am
Location: Brisbane Australia
Has thanked: 4 times

Re: libopeninv STM32F4

Post by mackoffgrid »

Jack Bauer wrote: Thu Jul 01, 2021 5:12 pm It sure looks like the f407 and f107 are pin compatible ....
Yes, one of the strengths of the stm32 families.
https://github.com/mackelec/SolarUte
meFDCAN Arduino Library 3 FDCAN port stm32G4xx
meCAN Arduino Library 2023 version 2/3 CAN port stm32F0xx, stm32F1xx, stm32F4xx, stm32L4xx
User avatar
mackoffgrid
Posts: 93
Joined: Thu Jan 02, 2020 10:18 am
Location: Brisbane Australia
Has thanked: 4 times

Re: libopeninv STM32F4

Post by mackoffgrid »

johu wrote: Tue Jun 29, 2021 3:31 pm For a side project I made a branch of libopeninv for the STM32F4.
Might there be some benefit to look at the stm32F3 ? I've never used them but I understand they have a faster PWM clock?
https://github.com/mackelec/SolarUte
meFDCAN Arduino Library 3 FDCAN port stm32G4xx
meCAN Arduino Library 2023 version 2/3 CAN port stm32F0xx, stm32F1xx, stm32F4xx, stm32L4xx
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: libopeninv STM32F4

Post by Pete9008 »

Just wanted to say thanks for the above :)

BTW - the easiest fix for the loss of the RTC timer functionality could be using systick instead (compiles OK but not tested yet).
Post Reply