Debian Codegraph @

ports/stm32/boards/LEGO_HUB_NO6/README.md

raw
1 LEGO Hub No.6
2 =============
3
4 This board definition is for the LEGO Hub No. 6, a LEGO control unit with a 5x5
5 LED display, 6 Powered Up ports, speaker, 6-DOF sensor, Bluetooth, external SPI
6 flash storage, and a rechargeable battery. The Hub can work without the battery if
7 it is plugged in to, and powered by, its USB port. But without the battery the LEDs
8 and power on the Powered Up ports will not function.
9
10 Features that are currently supported:
11 - standard MicroPython
12 - machine and bluetooth modules
13 - filesystem
14 - USB VCP, MSC and HID
15
16 The Hub has a bootloader preinstalled at 0x08000000 (which is 32kiB in size) which
17 cannot be erased. This bootloader is entered by holding down the Bluetooth button,
18 plugging in USB to power it up, then releasing the Bluetooth button after 5 seconds,
19 at which point the USB DFU device appears. If the battery is installed then the
20 Bluetooth button's RGB LED will cycle colours. When this bootloader is active, the
21 flash from 0x08008000 and up can be erased and programmed via USB DFU.
22
23 The built-in bootloader has some drawbacks: it cannot be entered programmatically,
24 and it does not keep the Hub powered up when running from battery (which requires
25 keeping BAT_PWR_EN high). As such, this board is configured to work with mboot as
26 a secondary bootloader: mboot is placed at 0x08008000 and the main application
27 firmware at 0x08010000. When mboot is installed it can be entered programmatically
28 via machine.bootloader(), or by holding down the left arrow button when powering
29 on the Hub and waiting until the display says "B" before releasing the button.
30
31 Backing up original Hub firmware
32 --------------------------------
33
34 Before install MicroPython it is advised to backup the original LEGO firmware that
35 the Hub comes installed with. To do this, enter the built-in bootloader by holding
36 down the Bluetooth button for 5 seconds while powering up the Hub via USB (you may
37 need to take out the battery and disconnect USB to power off the Hub first). Then
38 run the following command from the root of this repository:
39
40 $ cd ports/stm32
41 $ make BOARD=LEGO_HUB_NO6 backup-hub-firmware
42
43 This will create a file called `lego_hub_firmware.dfu`. Put this file in a safe
44 location. To restore it, enter the built-in bootloader again and run:
45
46 $ make BOARD=LEGO_HUB_NO6 restore-hub-firmware
47
48 This will restore the original firmware but not the filesystem. To recreate the
49 original filesystem the Hub must be updated using the appropriate LEGO PC
50 application.
51
52 Installing MicroPython
53 ----------------------
54
55 You first need to build and install mboot, which only needs to be done once. From
56 the root of this repository run:
57
58 $ cd ports/stm32/mboot
59 $ make BOARD=LEGO_HUB_NO6
60
61 Now enter the built-in bootloader by holding down the Bluetooth button for 5
62 seconds while powering up the Hub via USB (you may need to take out the battery
63 and disconnect USB to power off the Hub first). Then run:
64
65 $ make BOARD=LEGO_HUB_NO6 deploy
66
67 mboot should now be installed. Enter mboot by holding down the left arrow
68 button when powering up the Hub. The display will cycle the letters: N, S, F, B.
69 When it gets to "B" release the left arrow and it will start mboot. The Hub then
70 blinks the centre button red once per second, and appears as a USB DFU device.
71
72 Now build MicroPython (start at the root of this repository):
73
74 $ cd mpy-cross
75 $ make
76 $ cd ../ports/stm32
77 $ make submodules
78 $ make BOARD=LEGO_HUB_NO6
79
80 And deploy to the Hub (making sure mboot is active, the centre button is blinking
81 red):
82
83 $ make BOARD=LEGO_HUB_NO6 deploy
84
85 If successful, the Hub should now appear as a USB serial and mass storage device.
86
87 Using MicroPython on the Hub
88 ----------------------------
89
90 Access the MicroPython REPL using mpremote (pip install mpremote), or with any
91 serial terminal program.
92
93 To scan for BLE devices:
94
95 >>> import bluetooth
96 >>> ble = bluetooth.BLE()
97 >>> ble.irq(lambda *x: print(*x))
98 >>> ble.active(1)
99 >>> ble.gap_scan(2000, 625, 625)
100
101 Use help("modules") to see available built-in modules.
102
103 Updating MicroPython from the Hub's filesystem
104 ----------------------------------------------
105
106 You can update the MicroPython application firmware using the instructions above
107 for installing the firmware for the first time. The Hub also supports updating
108 the application firmware from within MicroPython itself, using the on-board
109 filesystem.
110
111 To use this feature, build the firmware (see above for details) then gzip it and
112 copy the resulting file to the Hub (eg using mpremote):
113
114 $ make BOARD=LEGO_HUB_NO6
115 $ gzip build-LEGO_HUB_NO6/firmware.dfu
116 $ mpremote cp build-LEGO_HUB_NO6/firmware.dfu.gz :
117
118 Then get a REPL on the Hub and execute:
119
120 >>> import appupdate
121 >>> appupdate.update_app("firmware.dfu.gz")
122
123 You can alternatively run this REPL command using mpremote:
124
125 $ mpremote exec --no-follow "import appupdate; appupdate.update_app('firmware.dfu.gz')"
126
127 At that point the Hub should restart and the LED on the central button will flash
128 different colours. Once the update is complete the LED will stop flashing and the
129 Hub will appear again as a USB device. The application firmware is now updated
130 and you can remove the firmware.dfu.gz file if desired.