Wed, 12 Jul 2023 21:35:29 +0200
Add a blog entry for the Numworks N0110 repair
========================================== HP 34970A Data Acquisition Unit - part 6 ========================================== :Author: David Douard :Category: Electronics :Tags: HP, 34970A, HP34970A, DMM, repair, test equipment :series: HP 34970A repair :series_index: 6 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 <{filename}/hp34970a_5.rst>`_, I could not make the USBDevice of the STM32F303RD work with `mbed-os <https://os.mbed.com/>`_ framework I use to write the firmware. The `STM32F303RD <https://www.st.com/en/microcontrollers-microprocessors/stm32f303rd.html>`_ is not yet officially supported by mbed-os (mainl because there is no `NUCLEO <https://www.st.com/en/evaluation-tools/stm32-nucleo-boards.html>`_ 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 <https://github.com/ARMmbed/mbed-os/pull/15116>`_ 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 <https://github.com/ARMmbed/mbed-os/pull/15132>`_ 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 <https://community.platformio.org/t/support-for-mbed-os-6-stable-and-mature-apis-cloud-services-support-enhancements-to-the-bare-metal-profile/15079/9>`_ to my question on the `platformio forum <https://community.platformio.org/>`_, I could make it work. Obviously, I submitted `a PR <https://github.com/platformio/platformio-docs/pull/214>`_ to `platformio-docs <https://github.com/platformio/platformio-docs>`_. So now I have my (more or less) `up to date repository <https://github.com/douardda/platformio-framework-mbed>`_ 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 <https://docs.platformio.org/en/latest/platforms/creating_board.html>`_ 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 <https://hg.sdfa3.org/hp34970-firmware/file/tip/boards/hp34970_fp_f303rd.json>`_ in the `firmware source code repository <https://hg.sdfa3.org/hp34970-firmware/>`_. Once the board is described, it can be used in the `platformio.ini` file: .. code-block:: bash ~/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 <https://os.mbed.com/docs/mbed-os/v6.15/porting/porting-custom-boards.html>`_ 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: .. code-block:: json { "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 <https://github.com/ARMmbed/mbed-os/tree/master/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE>`_. 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: .. image:: {static}/images/hp34970a/finished.jpg :alt: finished look of the device with the replacement front panel :class: image-process-large-photo .. peertube:: 1b954399-4dd6-46ad-a263-ff8201b5455e