libopeninv STM32F4
Posted: Tue Jun 29, 2021 3:31 pm
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
we now write
The only additional command is selecting the channel of the stream
ADC
Looks to work the same, only the calibration commands are missing.
An additional command is needed to enable continuous conversion via DMA:
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
we write
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
changes to
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:
and finally the linker needs to ling against -lopencm3_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);
Code: Select all
dma_enable_stream(DMA2, DMA_STREAM0);
Code: Select all
dma_channel_select(DMA2, DMA_STREAM0, DMA_SxCR_CHSEL_4);
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);
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);
Code: Select all
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12);
gpio_set_af(GPIOA, GPIO_AF9, GPIO11 | GPIO12);
Clock setup
Code: Select all
rcc_clock_setup_in_hse_8mhz_out_72mhz()
Code: Select all
rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ])
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