content/hp34970a_6.rst

changeset 137
f3070bd842cd
child 148
2f87039dd0b5
equal deleted inserted replaced
133:0c9f5038fc63 137:f3070bd842cd
1 ==========================================
2 HP 34970A Data Acquisition Unit - part 6
3 ==========================================
4
5
6 :Author: David Douard
7 :Category: Electronics
8 :Tags: HP, 34970A, HP34970A, DMM, repair, test equipment
9 :series: HP 34970A repair
10 :series_index: 6
11
12
13 Quick follow up; I recently got back on this project to try to complete it and fix
14 remaining problems.
15
16 The source code for the firmware is available here:
17
18 https://hg.sdfa3.org/hp34970-firmware
19
20 The Kicad project is available here:
21
22 https://hg.sdfa3.org/hp34970-pcb
23
24
25 Making the USBDevice work
26 =========================
27
28 As described in the `previous episode <{filename}/hp34970a_5.rst>`_, I could not make
29 the USBDevice of the STM32F303RD work with `mbed-os <https://os.mbed.com/>`_ framework I
30 use to write the firmware.
31
32 The `STM32F303RD
33 <https://www.st.com/en/microcontrollers-microprocessors/stm32f303rd.html>`_ is not yet
34 officially supported by mbed-os (mainl because there is no `NUCLEO
35 <https://www.st.com/en/evaluation-tools/stm32-nucleo-boards.html>`_ board with
36 this CPU.
37
38 However the STM32F303RE is supported, at least partially. For example, the USBDevice is
39 not working at all in the latest version of mbed-os (6.15.0). But some `work has been
40 done recently <https://github.com/ARMmbed/mbed-os/pull/15116>`_ to enable USB_DEVICE on
41 CPUs of the STM32F3 family. But this last PR was not enoght to make the USB device work;
42 I have submitted a `PR <https://github.com/ARMmbed/mbed-os/pull/15132>`_ that needs to
43 be merged to make the USB device actually work.
44
45 Also, the difference between the 2 being (as far as I know) only the size of the flash size
46 (384KB vs. 512 KB).
47
48 So I had 3 problems to solve:
49
50 - compile the code for a custom board using the mbed framework in platformio,
51 - use a custom CPU decription,
52 - use a patched version of the latest version of mbed-os in platformio (while the
53 officially supported version at this moment is only the 6.9.0).
54
55
56 Custom version of mbed in platformio
57 ------------------------------------
58
59 Using a custom version of a framework (here mbed) in platformio is not properly
60 documented. But thanks to `the response
61 <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>`_
62 to my question on the `platformio forum <https://community.platformio.org/>`_, I could
63 make it work. Obviously, I submitted `a PR
64 <https://github.com/platformio/platformio-docs/pull/214>`_ to `platformio-docs
65 <https://github.com/platformio/platformio-docs>`_.
66
67 So now I have my (more or less) `up to date repository
68 <https://github.com/douardda/platformio-framework-mbed>`_ usable as `platform_packages`
69 config argument.
70
71 Custom board and CPU description
72 --------------------------------
73
74 This part I am not completely sure how it should be done. There are actually 2 parts:
75 - tell mbed about the CPU description,
76 - tell platformio about is and use it.
77
78 The platformio part is `documented here
79 <https://docs.platformio.org/en/latest/platforms/creating_board.html>`_
80
81 It mostly consists in creating a json file in the `boards/` directory of the platformio
82 project directory.
83
84 For this project, I used the description of the NUCLEO_F303RE as starting point. The
85 file is `boards/hp34970_fp_f303rd.json
86 <https://hg.sdfa3.org/hp34970-firmware/file/tip/boards/hp34970_fp_f303rd.json>`_ in the
87 `firmware source code repository <https://hg.sdfa3.org/hp34970-firmware/>`_.
88
89 Once the board is described, it can be used in the `platformio.ini` file:
90
91 .. code-block:: bash
92
93 ~/e/hp34970-firmware$ pio boards | grep hp34
94 hp34970_fp_f303rd STM32F303RDT7 72MHz 384KB 64KB HP34970 Replace Front Panel Board (STM32F303RD, 64k RAM, 384k Flash)
95
96
97
98 Then we need to tell mbed about this board. This is `documented there
99 <https://os.mbed.com/docs/mbed-os/v6.15/porting/porting-custom-boards.html>`_
100
101 It is a matter of creating a `custom_targets.json` file with the board description.
102 Again, I used the existing NUCLEO_F303RE as starting point, then added/removed what I
103 needed for this project:
104
105 .. code-block:: json
106
107 {
108 "HP34970_FP_F303RD": {
109 "inherits": [
110 "MCU_STM32F303xE"
111 ],
112 "overrides": {
113 "clock_source": "USE_PLL_HSE_XTAL"
114 },
115 "device_has_add": [
116 "USBDEVICE"
117 ],
118 "mbed_rom_size": "0x60000",
119 "bootloader_supported": true,
120 "device_name": "STM32F303RE"
121 }
122 }
123
124 Then the actual description (pins, memory config, etc.) are C files put in a
125 `TARGET_HP34970_FP_F303RD` directory. Here again, started from files copied from the
126 `STM32F303xE target
127 <https://github.com/ARMmbed/mbed-os/tree/master/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE>`_.
128
129
130 End result
131 ==========
132
133 It took me some time, but in the end, I finally got a firmware that works OK, including
134 a working USB serial port. For now, this serial connection is still used only for
135 debugging purpose (and firmware upload in DFU mode), but it may be improved in the
136 future, if needs be.
137
138 So I could put the HP34970A back together (at last). I drilled a couple of small holes
139 for the Reset and DFU buttons and a (not so) square hole for the USB plug in the blue
140 glass.
141
142 The result looks very decent to me:
143
144 .. image:: {static}/images/hp34970a/finished.jpg
145 :alt: finished look of the device with the replacement front panel
146 :class: image-process-large-photo
147
148 .. peertube:: 14d0e7e2-74d5-44fe-90e9-d6b102ae01a1

mercurial