Bare Metal STM32 Development on Windows

It’s been a year and a half since I last posted on this and some new tools are available; they work great with STM32L1xx, STM32F1xx, STM32L4xx, etc.

  1. For an integrated IDE, I still like EmBitz
  2. When working from the command line, I still like vim for Windows
  3. For hardware-level debugging (JTAG/SWD), OpenOCD has dramatically improved their support for STM32 and is now better than the Texane STLink IMHO.  You can download windows binaries and the pdf manual or browse the online documentation.  OpenOCD is a GDB server that listens on:
    • port 3333 for a GDB debugger connection for source-level debugging
    • port 4444 for a telnet connection and sophisticated command line interface that lets you use commands like these:

      > stm32l4x unlock 0 (unlock flash bank 0)
      > stm32l4x mass_erase 0 (erase all flash)
      > flash probe 0
      > flash list
      > flash erase_address 0x08000000 0x3000
      > flash write_image myProgram.bin 0x08000000
      > reset halt
      > mdb 0x08000000 32 (dump 32-bytes at start of flash)

    OpenOCD supports many target processors and many hardware interfaces; when you launch OpenOCD, you must pass it two parameters that tell it which hardware interface to use and what target it will be controlling. For example:

    openocd -f interface\stlink-v2.cfg -f target\stm32l4x.cfg

    There are many pre-built configuration files in the interface and target sub-directories wherever you installed openocd. If your interface or target aren’t supported, the configuration files are text and can be easily edited to support your needs.

  4. GNU ARM Embedded Toolchain continues to be the best pre-compiled toolchain and is kept up-to-date.  It includes gdb which can attach easily to an OpenOCD server and let you do source-level debugging from its command-line interface and is well documented and there are many tutorials and cheatsheets.  An example of the CLI use is:
    arm-none-eabi-gdb <myApplication.elf>
    (gdb) target extended-remote localhost:3333
    (gdb) load myApplication.elf (loads image into flash)
    OR
    (gdb) file myApplication.elf (to debug an image already in flash)
    (gdb) set remote hardware-watchpoint-limit 6
    (gdb) b main
    (gdb) monitor reset run
    (gdb) c
    (gdb) step (s) or next (n)
    (gdb) i b (info breakpoints)
    (gdb) list [fnName]
    (gdb) interrupt (halt execution)
    (gdb) print <symbolName>
  5. Note: the ‘monitor’ command lets you issue any of the OpenOCD CLI commands from within GDB. For example:
    (gdb) monitor reset halt(reset target and halt target)

  6. Eclipse CDT (especially the standalone version) integrates nicely with gdb and OpenOCD and provides a friendly, smart, graphical source-level debugger.
    • On launch, select the appropriate .elf file for debugging at first dialog
    • Under Window->Preferences->C/C++->Debug->GDB set GDB debugger to arm-none-eabi-gdb (in the appropriate directory – you only need to do this once)
    • In a separate Command window, start OpenOCD with the appropriate interface and target (see above)
    • Under File->Debug Remote Executable: set Binary to the .elf file, Hostname to localhost, Port to 3333, check Attach (you should see gdb connect in the OpenOCD window)
    • In the bottom panel of Eclipse CDT, select the Debugger Console tab (accesses the gdb console)
      • file myProgram.elf (if the firmware is already running on the target)
        OR
      • load myProgram.elf (to program the .elf file into the target flash)
      • b main
      • monitor reset run OR
      • monitor reset halt
      • jump Reset_Handler
      • next
      • print myVariable
      • continue
    • From there you can step into/over lines of source code, browse variables and C and assembler source code, view/set/clear breakpoints graphically, and do everything you would expect from a modern debugger.
    • You can read more about it here.

Hybrid Smartwatch

For a long time, I resisted the urge to buy a smartwatch.  Most of them look like you’ve strapped a cellphone to your wrist,  they need to be recharged nightly, they require a button press or a wrist flick just to see the time, many aren’t waterproof, and most of the features aren’t appealing to me due to the small screen.  I tried wearing a fitness band and a regular watch, but wearing two things bugged me.

To the rescue comes the Withings Steel HR, a hybrid of an analog watch, a smart watch, and a fitness band in a nice looking package that is slightly smaller than my old watch.  I’ve been wearing it for several weeks now and I really like it.

The winning features include:

  • Small and light, no bigger than a normal watch
  • Professional appearance
  • Analog hands show time at a glance
  • Fitness dial shows steps at a glance
  • Heartrate monitoring
  • Waterproof
  • Bluetooth link to decent smartphone app
  • 3 week battery life for smart features, longer for watch and steps.
  • Full charge takes about an hour
  • OLED display covers the rest with a single button: date, steps, miles, calories, etc.
  • OLED and gentle vibration also alert you to incoming calls (displays caller) and text messages (displays from whom) and calendar events (displays event title), allowing you to decide whether you need to fish your phone out of your pocket.
  • Note: my eyes and I are over 50 so I was concerned about the size of the text on the small OLED display, but it turned out to be OK.

The watch comes in two sizes, I prefer the smaller (36mm) variant; it includes a black silicone band that is very comfortable and secure, but I am used to a stainless band; fortunately, this watch takes any standard 18mm band so I bought a nice looking replacement on eBay for $10 and it fit perfectly.

It’s not yet officially available in the US, but it will be soon, you can read more about it here.

I still don’t understand why we don’t see old-fashioned LCD or modern eInk smart watches that show the time continuously and run for years on a coin cell, but for whatever reason, we don’t and for now, this is the best solution I’ve found.  Other features I’d like to see in the future:

  • blood pressure monitoring
  • display text of messages (not just who they are from)
  • saphire crystal and/or better protection for the crystal like a standard dive watch

10/24/2017 – A new contender is the Amazfit BiP or the snazzier Amazfit Pace. The BiP has very long battery life (45 days) and the Pace has much less (~5 days) but looks better, both are waterproof, have fitness monitor, GPS, smarter watch features, low price, and always on display. The only down-sides I can see are appearance/size: both are large and considerably less attractive than the Steel HR (the Pace looks better, but the battery life is too short). You can see a video review of the BiP here. When they make one that looks like the Pace but has the battery life of the BiP, I’ll buy one.