Using float on STM32F1

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:

Using float on STM32F1

Post by johu »

After playing with the F4 a bit I thought it would be pretty neat to be able to use floats on the F1. Yes it will be soft-float but that should be ok for the slower 10 & 100ms tasks. I would like to restrict the fixed-point math to the 8.8 kHz control ISR only.

Problem so far has been that using any sort of float operation would result in a hard fault. That is because gcc by default uses the "wrong" libgcc.a.

I have forced it to use one with floating point implemented by changing LDFLAGS from

Code: Select all

-Llibopencm3/lib -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections,-Map,linker.map
to

-Llibopencm3/lib -L/usr/lib/gcc/arm-none-eabi/11.1.0/thumb/v7+fp/softfp -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections,-Map,linker.map

Code: Select all

-Llibopencm3/lib -march=armv7 -T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections,-Map,linker.map
There is probably a better way to do this, i.e. not having an absolute path in there.
UPDATE: there is. Just specify -march=armv7

I think this is particularly interesting for the ZombieVerter project as that has no fast loops at all.
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: Using float on STM32F1

Post by johu »

Now the plan for porting to float:
1. Add a function Param::GetFloat()
2. Port modules like Throttle, VehicleControl etc. to float
3. At some point actually store parameters as float, while being able to load legacy fixed point parameters
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: Using float on STM32F1

Post by johu »

Ok, sine project ported up to step 2, take a peek here: https://github.com/jsphuebner/stm32-sine/tree/float

Binary size increased by 4k.
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: Using float on STM32F1

Post by johu »

Successfully tested in Touran :) CPU usage is unchanged I think, 33%
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: Using float on STM32F1

Post by Jack Bauer »

Thanks for this Johannes. I am concerned by your work on the F4. If you can run a car with foc on an F1 using only 33% of its run time then what will you do with all that spare horsepower in an f4?? Oh wait! CCS of course :)
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: Using float on STM32F1

Post by johu »

yes lets bitbang PLC with one of the DACs to get rid of that Qualcomm rubbish ;)
The F4 project will be sending and receiving some CAN. Hope it won't quit work because of bore-out.
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: Using float on STM32F1

Post by johu »

Drove around with the float firmware a bit and somehow it's not as smooth as before. Cruise control started stuttering on an uphill. Must be still some scaling issues.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Post Reply