Posted on sam. 09 octobre 2021

Quick follow up; I recently got back on this project to try to complete it and fix remaining problems.

The source code for the firmware is available here:

https://hg.sdfa3.org/hp34970-firmware

The Kicad project is available here:

https://hg.sdfa3.org/hp34970-pcb

Making the USBDevice work

As described in the previous episode, I could not make the USBDevice of the STM32F303RD work with mbed-os framework I use to write the firmware.

The STM32F303RD is not yet officially supported by mbed-os (mainl because there is no NUCLEO board with this CPU.

However the STM32F303RE is supported, at least partially. For example, the USBDevice is not working at all in the latest version of mbed-os (6.15.0). But some work has been done recently to enable USB_DEVICE on CPUs of the STM32F3 family. But this last PR was not enoght to make the USB device work; I have submitted a PR that needs to be merged to make the USB device actually work.

Also, the difference between the 2 being (as far as I know) only the size of the flash size (384KB vs. 512 KB).

So I had 3 problems to solve:

  • compile the code for a custom board using the mbed framework in platformio,
  • use a custom CPU decription,
  • use a patched version of the latest version of mbed-os in platformio (while the officially supported version at this moment is only the 6.9.0).

Custom version of mbed in platformio

Using a custom version of a framework (here mbed) in platformio is not properly documented. But thanks to the response to my question on the platformio forum, I could make it work. Obviously, I submitted a PR to platformio-docs.

So now I have my (more or less) up to date repository usable as platform_packages config argument.

Custom board and CPU description

This part I am not completely sure how it should be done. There are actually 2 parts: - tell mbed about the CPU description, - tell platformio about is and use it.

The platformio part is documented here

It mostly consists in creating a json file in the boards/ directory of the platformio project directory.

For this project, I used the description of the NUCLEO_F303RE as starting point. The file is boards/hp34970_fp_f303rd.json in the firmware source code repository.

Once the board is described, it can be used in the platformio.ini file:

~/e/hp34970-firmware$ pio boards | grep hp34
hp34970_fp_f303rd          STM32F303RDT7    72MHz        384KB     64KB      HP34970 Replace Front Panel Board (STM32F303RD, 64k RAM, 384k Flash)

Then we need to tell mbed about this board. This is documented there

It is a matter of creating a custom_targets.json file with the board description. Again, I used the existing NUCLEO_F303RE as starting point, then added/removed what I needed for this project:

{
  "HP34970_FP_F303RD": {
    "inherits": [
      "MCU_STM32F303xE"
    ],
    "overrides": {
      "clock_source": "USE_PLL_HSE_XTAL"
    },
    "device_has_add": [
      "USBDEVICE"
    ],
    "mbed_rom_size": "0x60000",
    "bootloader_supported": true,
    "device_name": "STM32F303RE"
  }
}

Then the actual description (pins, memory config, etc.) are C files put in a TARGET_HP34970_FP_F303RD directory. Here again, started from files copied from the STM32F303xE target.

End result

It took me some time, but in the end, I finally got a firmware that works OK, including a working USB serial port. For now, this serial connection is still used only for debugging purpose (and firmware upload in DFU mode), but it may be improved in the future, if needs be.

So I could put the HP34970A back together (at last). I drilled a couple of small holes for the Reset and DFU buttons and a (not so) square hole for the USB plug in the blue glass.

The result looks very decent to me:

finished look of the device with the replacement front panel