Tuesday, March 11, 2014

STM32CubeF4 gcc makefile example

I started to play with the STM32CubeF4 hal code, in the context of helping to add support for it in MicroPython. I looked around for an example Makefile which used gcc, and couldn't find one.
So, of course, I created my own.
You can find my Makefile (if you've seen MicroPython's makefile then this will look familiar, since I copied most of the bits and pieces from there) here. It's setup to work with the STM32F4-Discovery board.
The STM32F407VG_FLASH.ld and startup_stm32f407xx.s came from the TrueSTUDIO tree.
The Makefile only works for the GPIO_EXTI example and would need to be modified for other examples. I'll probably only do the one example, since that's enough to get the basics working.

Monday, March 10, 2014

Formatting 32-bit floating point numbers (aka convert 32-bit float to string)

While working on MicroPython, I went looking for some code to format 32-bit floating point numbers.
I spent quite a while looking, and all of the examples I found were focused on doubles or long-doubles and used a lot more RAM than what was required for just 32-bit floats.
Of the ones, I did find, Fred Bayer's pdouble.c was one of the easiest to understand.
I used that as a base, and added support for e, f, and g formats, as well as allowing the caller to specify the buffer (and size) to receive the results. This version uses no RAM (other than some stack). The caller provides the output buffer, and all globals are constant so that they can come from flash. All of the arithmetic is either 32-bit integer or 32-bit float, so that processors like the Cortex-M4's with FPU can use this with no extra support libraries.
I figured that others might find it useful, so I put my version, along with some test code in github.
Since Fred Bayer's code (on which this code was based) was pubic domain, I made my code public domain. So you can use it however you like. If you do use it, it would be nice to hear from you, but even that's not a requirement.