Makefile framework for STM32

Managing multiple projects for the STM32 Controller family using makefiles


Currently I'm building a new CAN based network for my little big data collector. This thing consists of several sensors and data aquisition boards scattered around my home. As it is homegrown and organic, things tend to get confusing - which sensor is connected to which board and what data are transferred where to and so on.

As a solution I've started to rebuild some of the data aquisition boards, and designing a new CAN based communication protocol. The goal is to get rid of most of the old Modbus based boards. There will be still one board acting as a gateway from CAN to Modbus.

The key requirements for the CAN protocol are:

  • keep it simple and stupid (no runtime or automatic configuration)
  • keep it consistent over all units
  • firmware update over CAN should work
  • To fulfill the first two requirements, I've set up a makefile framework which supports using the same source code in multiple projects. This way I'm able to include the same protocol code and data definitions into all projects, compile and deploy the binaries over CAN to all boards, just by typing "make". No need for extensive runtime configuration of the data transfers. Everything is kept consistent at compile time.

    The makefile framework is organized this way:

  • each project is a subdirectory of the main project directory
  • the common code is located in the subdirectory "com"
  • the project makefiles include several makefiles from the "com" subdirectory according to their requirements
  • the main makefile core is inside "pj.mk" and "pjhdr.mk" in "com/pj"
  • there are several makefile includes for various debuggers (ST-Link, Versaloon, JLink, Black Magic Probe, FTDI-based adaptors)
  • there's one makefile include to start the CAN bootloader
  • there are various makefile includes for libraries and common code
  • Throw the mandatory ("pjhdr.mk" and "pj.mk") and optional makefile includes together into the project specific Makefile. Use the makefile of one of the projects or the template from "pj-template" as a starting point. The template schema is expandable for more libraries, common code, debuggers, other microcontroller families and so on.

    I've integrated some great OSS into this framework:

  • ChibiOS - the real time OS
  • OpenBLT - the bootloader for updating over CAN
  • There is some modification of ChibiOS required to get it working together with OpenBLT:

  • OpenBLT expects the whole vector table of the largest STM32F1x derivative to be present
  • The linker script must be modified according to the higher start address
  • The startup code must load the SP register
  • The latter two were well documented by OpenBLT, the first one was rather dastardly: OpenBLT writes a checksum right after the last vector table entry, same address for every derivative, but the ChibiOS vector table varies in size according to the used derivative. So on my first tries to get it up and running, OpenBLT patched its checksum into code, which made it fail. The simple and after discovering the issue obvious fix is to patch ChibiOS to always create the largest derivatives vector table.

    One additional item for updating the firmware over CAN is required: some kind of a CAN adapter for the PC. I've used this one: UConnect for XE164. This is a simple demo kit by Infineon promoting their XE16x controllers. Afaik this particular kit isn't available any more, I've used it simply because it was there at the right time. There comes a demo firmware with this kit, the "horch" application, this is a simple CAN to UART over USB gateway. I've modified this firmware and the SerialBoot application from openBLT to work together.

    The project isn't finished yet at the time of this writing. It contains the makefile framework itself, the STM32 standard peripheral library, ChibiOS, OpenBLT. Included are three projects using my simple and stupid homebus CAN protocol as a shared code base:

  • A hydrostatic water level meter for my water cistern, based on a cheap blood pressure monitor (this will be a separate project page at some time), up and running now
  • A multi I/O and sensor data aquisition board, still work in progress
  • Some kind of a gateway to Modbus (modbus not yet ported, work in progress)
  • Find my makefile framework and the related code here: The source tarball
    The source code for the UConnect board: can-gw.zip

    Links

    Make a STM32VL-Discovery board more useful by replacing the ST-Link-V1 with Black Magic Probe: DorkbotPDX. Tip of the day: make it even more useful by replacing the STM32F100 with a STM32F103RB.
    The Black Magic Probe: Black Sphere Technologies
    Versaloon: Simon Quian
    stlink by texane repository on github
    Freddie Chopin provides a arm-none-eabi toolchain and openocd builds for windows
    ChibiOS
    OpenBLT

    Look here: The STM32 files for my other STM32 related pages. ... und ein Zaehlpixel hab ich auch :-)