├── .gitignore ├── LICENSE ├── README.md ├── Vagrantfile ├── scripts ├── build_codal.sh ├── build_cpp.sh ├── build_pxt.sh ├── build_upy1.sh ├── build_upy2.sh ├── install_build-tools.sh ├── install_gcc-arm.sh └── install_yotta.sh ├── upy.py └── vagrant_shared └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Vagrant 2 | .vagrant/ 3 | 4 | # Vagrant shared folder 5 | vagrant_shared/ 6 | 7 | # Vagrant log file 8 | *-cloudimg-console.log 9 | 10 | 11 | ##################### 12 | # OS Specific files # 13 | ##################### 14 | 15 | # Windows image file caches 16 | Thumbs.db 17 | ehthumbs.db 18 | 19 | # Folder config file 20 | Desktop.ini 21 | 22 | # Recycle Bin used on file shares 23 | $RECYCLE.BIN/ 24 | 25 | # Windows Installer files 26 | *.cab 27 | *.msi 28 | *.msm 29 | *.msp 30 | 31 | # Windows shortcuts 32 | *.lnk 33 | 34 | # Linux 35 | *~ 36 | 37 | # temporary files which can be created if a process still has a handle open of a deleted file 38 | .fuse_hidden* 39 | 40 | # KDE directory preferences 41 | .directory 42 | 43 | # Linux trash folder which might appear on any partition or disk 44 | .Trash-* 45 | 46 | # OS X 47 | .DS_Store 48 | .AppleDouble 49 | .LSOverride 50 | 51 | # Icon must end with two \r 52 | Icon 53 | 54 | # Thumbnails 55 | ._* 56 | 57 | # Files that might appear in the root of a volume 58 | .DocumentRevisions-V100 59 | .fseventsd 60 | .Spotlight-V100 61 | .TemporaryItems 62 | .Trashes 63 | .VolumeIcon.icns 64 | 65 | # Directories potentially created on remote AFP share 66 | .AppleDB 67 | .AppleDesktop 68 | Network Trash Folder 69 | Temporary Items 70 | .apdisk 71 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Carlos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BBC micro:bit Development Environment for C/C++, MakeCode, and MicroPython 2 | 3 | This repository contains a Vagrant box configured to facilitate the development of MicroPython, MakeCode, and C/C++ programs for the BBC micro:bit. 4 | 5 | [Vagrant](https://www.vagrantup.com/intro/index.html) is a tool to easily build and manage virtual machine environments. 6 | 7 | If you prefer to use 🐳 Docker this other project might interest you: 8 | [Docker micro:bit Toolchain](https://github.com/carlosperate/docker-microbit-toolchain) 9 | 10 | 11 | ## 🗂️ Table of contents: 12 | 13 | * [✨ Features](#-features) 14 | * [📀 Install](#-install) 15 | * [🚀 Getting Started](#-getting-started) 16 | * [🔁 Workflow](#-workflow) 17 | * [🏞️ Environments](#%EF%B8%8F-environments) 18 | * [©️ C/C++ DAL (V1)](#%EF%B8%8F-cc-dal-v1) 19 | * [©️ C/C++ CODAL (V2)](#%EF%B8%8F-cc-codal-v2) 20 | * [🐍 MicroPython V1](#-micropython-v1) 21 | * [🐍 MicroPython V2](#-micropython-v2) 22 | * [Ⓜ️ MakeCode](#ⓜ%EF%B8%8F-makecode) 23 | * [📑 License](#-license) 24 | * [⚖️ Trademarks](#%EF%B8%8F-trademarks) 25 | 26 | 27 | ## ✨ Features 28 | 29 | This virtual machine is very easy to use and contains everything you need to: 30 | * Build micro:bit MicroPython from source 31 | * Easily load Python scripts using your own built MicroPython 32 | * Easily access the MicroPython REPL 33 | * Run a local version of MakeCode/PXT 34 | * Develop your own MakeCode packages 35 | * Build C/C++ applications for the micro:bit using the DAL (micro:bit runtime) 36 | 37 | With a single command this project takes care of creating a virtual machine, installing all the development tools and dependencies required, download all the source code into a shared folder, compile everything, and get it ready for use. 38 | 39 | It offers a replicable development environment that is independent of your operating system, working the same way under Windows, macOS, or Linux. 40 | 41 | 42 | ## 📀 Install 43 | 44 | ### Prerequisites 45 | You will need the following applications first: 46 | 47 | * [VirtualBox](https://www.virtualbox.org/) 48 | * [Vagrant](https://www.vagrantup.com/) 49 | * (Optional) [Python](https://www.python.org/) (2.7 or >=3.4) 50 | 51 | ### Vagrant Project Bring-up 52 | 53 | Clone, or [download](https://github.com/carlosperate/microbit-dev-env.git) this repository: 54 | 55 | ```bash 56 | git clone https://github.com/carlosperate/microbit-dev-env.git 57 | cd microbit-dev-env 58 | ``` 59 | 60 | Getting the virtual machine up and running with Vagrant is extremely easy, on the Command Line Interface just run: 61 | 62 | ```bash 63 | vagrant up --provision 64 | ``` 65 | 66 | This will first ask you what project would you like to build. Selecting only the project you are interested will significantly reduce the bring up time. 67 | 68 | ``` 69 | $ vagrant up --provision 70 | Build MakeCode? (y/n): y ✅ 71 | Build C++ samples (DAL)? (y/n): y ✅ 72 | Build CODAL? (y/n): y ✅ 73 | Build MicroPython V1? (y/n): y ✅ 74 | Build MicroPython V2? (y/n): y ✅ 75 | ``` 76 | 77 | After the questions have been answered, it will download an Ubuntu 16.04 64-bit Virtual Box image, so it might take a while depending on your internet connection. 78 | It will also install the build tool-chain, download and build all the source code for the selected projects, ensuring everything is ready to develop your application in any of these platforms. 79 | 80 | 81 | ## 🚀 Getting Started 82 | 83 | First, start-up the virtual machine: 84 | ```bash 85 | vagrant up 86 | ``` 87 | 88 | If this is the first time you've run this command it will ask you which projects you would like to build. Enter `y` to select any of the prompted projects. 89 | 90 | You can now SSH into the virtual machine with Vagrant itself: 91 | 92 | ```bash 93 | vagrant ssh 94 | ``` 95 | 96 | Or with your preferred SSH client: 97 | 98 | ``` 99 | Host: 127.0.0.1 100 | Port: 2222 101 | Username: vagrant 102 | Password: vagrant 103 | ``` 104 | 105 | This will give you command line access to the virtual machine, allowing you to compile the source code contained in the `vagrant_shared` folder. By default you will find the `cpp-samples`, `micropython`, `pxt-workspace` and a couple of extra folders there, which can be accessed from the virtual machine to build the projects. So within the SSH connection you can: 106 | 107 | ```bash 108 | cd vagrant_shared/micropython 109 | make all 110 | ``` 111 | 112 | To stop the virtual machine from running, you can use the following command on the host: 113 | 114 | ``` 115 | vagrant halt 116 | ``` 117 | 118 | More information can be found in the [Vagrant documentation](https://www.vagrantup.com/docs/). 119 | 120 | 121 | ## 🔁 Workflow 122 | 123 | The general workflow concept is to have one folder that is accessible by both the host operating system (your computer), and the virtual machine. 124 | 125 | This allows you to create and edit your code like you would normally do, using any IDE or editor you prefer, and then use the virtual machine to build it or compile it. 126 | 127 | In essence the steps are: 128 | 129 | * Edit the code inside the `vagrant_shared` folder in your OS as you would normally do 130 | * SSH into the virtual machine 131 | * Compile/build the project from the SSH session (accessible via `~/vagrant_shared/`) 132 | * The built output can be accessed from the `vagrant_shared` folder within your OS 133 | 134 | The `vagrant_shared` folder is where the source code and projects have to be located, as Vagrant configures it as a shared folder that can be accessed indiscriminately by both your OS and the virtual machine. 135 | Remember! If you delete something within the virtual machine `~/vagrant_shared/` directory it will also be removed from the folder you see in your Operating System. 136 | 137 | The `vagrant_shared` directory has been gitignored, so feel free to add or clone your own repositories there without interference from this one. 138 | 139 | 140 | ## 🏞️ Environments 141 | 142 | ### ©️ C/C++ DAL (V1) 143 | #### Project/code location 144 | The [microbit samples](https://github.com/lancaster-university/microbit-samples) project contains a collection of example programs using the micro:bit runtime (DAL). 145 | The project directory can be found at: 146 | ``` 147 | vagrant_shared/cpp-samples/ 148 | ``` 149 | 150 | 151 | #### Building 152 | This C/C++ project has already been built, but if you wish to recompile the examples you can access the virtual machine via SSH, and run: 153 | 154 | ```bash 155 | cd ~/vagrant_shared/cpp-samples/ 156 | yt clean 157 | yt build 158 | ``` 159 | 160 | The `cpp-samples/source/examples` folder contains a selection of samples demonstrating the capabilities and usage of the runtime APIs. To select a sample, simply copy the .cpp files from the relevant folder into the `cpp-samples/source/` folder. More info can be found in the [microbit samples](https://github.com/lancaster-university/microbit-samples) repository. 161 | 162 | #### Built output location 163 | To load the application into the micro:bit you will need to copy the `microbit-xxx-combined.hex` file into the micro:bit USB drive. 164 | 165 | ``` 166 | vagrant_shared/cpp-samples/build/bbc-microbit-classic-gcc/source/microbit-samples-combined.hex 167 | ``` 168 | 169 | ### ©️ C/C++ CODAL (V2) 170 | #### Project/code location 171 | The [microbit samples](https://github.com/lancaster-university/microbit-v2-samples) project contains a collection of example programs using the micro:bit runtime for V2 (CODAL). 172 | The project directory can be found at: 173 | ``` 174 | vagrant_shared/microbit-v2-samples/ 175 | ``` 176 | 177 | 178 | #### Building 179 | This C/C++ project has already been built, but if you wish to recompile the examples you can access the virtual machine via SSH, and run: 180 | 181 | ```bash 182 | cd ~/vagrant_shared/microbit-v2-samples/ 183 | python3 build.py 184 | ``` 185 | 186 | The `microbit-v2-samples/source/samples/` folder contains a selection of samples demonstrating the capabilities and usage of the runtime APIs. To select a sample, simply copy the .cpp files from the relevant folder into the `cpp-samples/source/` folder. More info can be found in the [micro:bit V2 samples](https://github.com/lancaster-university/microbit-v2-samples) repository. 187 | 188 | #### Built output location 189 | To load the application into the micro:bit you will need to copy the `MICROBIT.hex` file into the micro:bit USB drive. 190 | 191 | ``` 192 | vagrant_shared/microbit-v2-samples/MICROBIT.hex 193 | ``` 194 | 195 | ### 🐍 MicroPython V1 196 | #### Project/code location 197 | The MicroPython source code can be found in: 198 | 199 | ```bash 200 | vagrant_shared/micropython/ 201 | ``` 202 | 203 | #### Building 204 | MicroPython has already been built, but if you wish to build it again, you can open an SSH session and run: 205 | 206 | ```bash 207 | cd ~/vagrant_shared/micropython/ 208 | yt clean 209 | make all 210 | ``` 211 | 212 | #### Built output location 213 | The MicroPython hex file is saved into the following path: 214 | 215 | ```bash 216 | vagrant_shared/micropython/build/firmware.hex 217 | ``` 218 | 219 | #### Flashing to the micro:bit 220 | You can simply copy the MicroPython hex into your micro:bit USB drive. 221 | 222 | To simplify the process and be able to load MicroPython with or without an additional Python program, [uflash](https://github.com/ntoll/uflash/) (by [Nicholas Tollervey](https://github.com/ntoll)) has been included with a wrapper script. So, from the host operating system you can run the following if you have Python (2 or 3) installed. 223 | 224 | To load only the new MicroPython simply run this script: 225 | 226 | ```bash 227 | python upy.py flash 228 | ``` 229 | 230 | To load the new MicroPython together with your Python code: 231 | 232 | ```bash 233 | python upy.py flash 234 | ``` 235 | 236 | For a quick test you could load any of the included MicroPython examples for the microbit: 237 | 238 | ```bash 239 | python upy.py flash vagrant_shared/micropython/examples/conway.py 240 | ``` 241 | 242 | All command line arguments sent to the `upy_load.py` wrapper script are sent over to uFlash (more info about available options in the [uFlash's README](https://github.com/ntoll/uflash)). So, for example, if you'd like to save the combined `micropython.hex` file (MicroPython + user Python code) into the current directory (indicated using `.`), you can do so with the following command: 243 | 244 | ```bash 245 | python upy.py flash vagrant_shared/micropython/examples/conway.py . 246 | ``` 247 | 248 | #### Access the MicroPython REPL 249 | Once MicroPython is flashed, you will have access to the REPL on the USB CDC serial port, with baud rate 115200 (eg `picocom /dev/ttyACM0 -b 115200` on Linux, `screen /dev/tty.usbmodem* 115200` on OS X, or a tool like putty/TeraTerm on Windows). 250 | 251 | The [microrepl](https://github.com/ntoll/microrepl) tool (by [Nicholas Tollervey](https://github.com/ntoll))is also bundled and easily accessible via a provided helper script. If you'd like to access the micro:bit REPL using your host computer terminal/console you can simply run the following Python (2 or 3) script: 252 | 253 | ```bash 254 | python upy.py repl 255 | ``` 256 | 257 | If you are running Windows you might need to install the microbit driver, which can be found at: https://developer.mbed.org/handbook/Windows-serial-configuration 258 | 259 | #### Access the MicroPython file system 260 | MicroPython implements a simple file system inside the micro:bit flash, allowing you to read and write small files. The [microfs](https://github.com/ntoll/microfs) Python command line utility (by [Nicholas Tollervey](https://github.com/ntoll)), is bundled with a wrapper script to enable easy access from the host computer. 261 | 262 | You can use the following commands: 263 | * List the files on the micro:bit: `python upy.py fs ls` 264 | * Copy a file onto the micro:bit: `python upy.py fs put path/to/local.txt` 265 | * Get a file from the micro:bit: `python upy.py fs get remote.txt` 266 | * Delete a file on the micro:bit: `python upy.py fs rm remote.txt` 267 | * More info in the built-in help: `python upy.py fs --help` 268 | 269 | ### 🐍 MicroPython V2 270 | #### Project/code location 271 | The MicroPython source code can be found in: 272 | 273 | ```bash 274 | vagrant_shared/micropython-microbit-v2/ 275 | ``` 276 | 277 | #### Building 278 | MicroPython has already been built, but if you wish to build it again, you can open an SSH session and run: 279 | 280 | ```bash 281 | cd ~/vagrant_shared/micropython-microbit-v2/src 282 | make 283 | ``` 284 | 285 | #### Built output location 286 | The MicroPython hex file is saved into the following path: 287 | 288 | ```bash 289 | vagrant_shared/micropython-microbit-v2/src/MICROBIT.hex 290 | ``` 291 | 292 | ### Ⓜ️ MakeCode 293 | 294 | WIP 295 | 296 | #### Project/code location 297 | 298 | The PXT workspace is installed in the following directory: 299 | 300 | ```bash 301 | vagrant_shared/pxtworkspace/ 302 | ``` 303 | 304 | #### Launch MakeCode server 305 | 306 | To run MakeCode, open an SSH session and run: 307 | 308 | ```bash 309 | cd ~/vagrant_shared/pxtworkspace 310 | pxt serve --no-browser --no-serial --hostname 0.0.0.0 --port 3232 --wsport 3233 311 | ``` 312 | 313 | **VERY IMPORTANT**: From your host OS open a browser and go to the address displayed in the SSH terminal with one **CHANGE**: Replace `0.0.0.0` with `localhost`. 314 | 315 | The terminal session should have showed you a message similar to the one below, but with a different token in the URL, which you need to keep: 316 | 317 | ``` 318 | --------------------------------------------- 319 | 320 | To launch the editor, open this URL: 321 | http://0.0.0.0:3232/#local_token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&wsport=3233 322 | 323 | --------------------------------------------- 324 | ``` 325 | 326 | So in the example above, point your browser to `http://localhost:3232/#local_token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&wsport=3233` instead. 327 | 328 | 329 | ## 📑 License 330 | 331 | [MIT](LICENSE) 332 | 333 | 334 | ## ⚖️ Trademarks 335 | 336 | This projects is not endorsed, sponsored or associated with the BBC or the Micro:bit Educational Foundation. 337 | "BBC” and “micro:bit” are trade marks of the BBC. https://microbit.org 338 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Before bringing up Vagrant ask the user what they want to build 5 | pxt = false 6 | upy1 = upy2 = false 7 | dal = codal = false 8 | yotta = false 9 | if ARGV[0] == 'up' and (Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/microbit-vg/virtualbox/*").empty? || ARGV[1] == '--provision') 10 | print "Build MakeCode? (y/n): " 11 | response = STDIN.getch 12 | print response + (response.start_with?('y') ? " ✅\n" : " ❌\n") 13 | if response.start_with?('y') 14 | pxt = true 15 | yotta = true 16 | end 17 | print "Build C++ samples (DAL)? (y/n): " 18 | response = STDIN.getch 19 | print response + (response.start_with?('y') ? " ✅\n" : " ❌\n") 20 | if response.start_with?('y') 21 | dal = true 22 | yotta = true 23 | end 24 | print "Build CODAL? (y/n): " 25 | response = STDIN.getch 26 | print response + (response.start_with?('y') ? " ✅\n" : " ❌\n") 27 | if response.start_with?('y') 28 | codal = true 29 | end 30 | print "Build MicroPython V1? (y/n): " 31 | response = STDIN.getch 32 | print response + (response.start_with?('y') ? " ✅\n" : " ❌\n") 33 | if response.start_with?('y') 34 | upy1 = true 35 | yotta = true 36 | end 37 | print "Build MicroPython V2? (y/n): " 38 | response = STDIN.getch 39 | print response + (response.start_with?('y') ? " ✅\n" : " ❌\n") 40 | if response.start_with?('y') 41 | upy2 = true 42 | end 43 | print "\n\n" 44 | end 45 | 46 | 47 | Vagrant.configure("2") do |config| 48 | # Building from Ubuntu 18.04 64 bit 49 | config.vm.box = "ubuntu/bionic64" 50 | 51 | # Forwarding SSH Agents 52 | config.ssh.forward_agent = true 53 | 54 | # This Ubuntu image creates a ubuntu-bionic-18.04-cloudimg-console.log file 55 | # https://betacloud.io/get-rid-of-ubuntu-xenial-16-04-cloudimg-console-log/ 56 | config.vm.provider "virtualbox" do |vb| 57 | vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] 58 | end 59 | 60 | # Adding a recognisable names to vagrant and the virtual machine 61 | config.vm.define "microbit-vg" do |t| 62 | end 63 | config.vm.provider "virtualbox" do |v| 64 | v.name = "microbit-vm" 65 | end 66 | 67 | # Uncomment this line to boot with a GUI (default is headless). 68 | # config.vm.boot_mode = :gui 69 | 70 | # Assign the VM settings according to your host computer capabilities. You can 71 | # change the CPU count and memory by setting these environmental variables: 72 | # VAGRANT_MEMORY_SIZE=x 73 | # VAGRANT_CPUS=x 74 | config.vm.provider "virtualbox" do |v| 75 | mem_size = ENV['VAGRANT_MEMORY_SIZE'].to_i 76 | v.memory = mem_size > 0 ? mem_size : 2048 77 | cpu_count = ENV['VAGRANT_CPUS'].to_i 78 | v.cpus = cpu_count > 0 ? cpu_count : 1 79 | # Display or hide the VirtualBox GUI when booting the machine 80 | v.gui = false 81 | # Enable USB and pass through the micro:bit 82 | # It is more effective to plug-in the device when the vm is already running 83 | # v.customize ["modifyvm", :id, "--usb", "on"] 84 | # v.customize ["modifyvm", :id, "--usbehci", "on"] 85 | # v.customize ["usbfilter", "add", "0", "--target", :id, 86 | # "--name", "BBC micro:bit", 87 | # "--vendorid", "0x0D28", "--productid", "0x0204"] 88 | end 89 | 90 | # Create a forwarded port mapping which allows access to a specific port. 91 | # This one is for running PXT HTTP port 3232 WS port 3233. 92 | # Note that when you run a VM local server you need to specify that it binds 93 | # to host 0.0.0.0, not localhost, or the port forwarding won't work. 94 | # pxt serve --hostname 0.0.0.0 --port 3232 --wsport 3233 95 | config.vm.network 'forwarded_port', guest: 3232, host: 3232, auto_correct: true 96 | config.vm.network 'forwarded_port', guest: 3233, host: 3233, auto_correct: true 97 | 98 | # Share an additional folders to the guest VM. The first argument is the path 99 | # on the host to the actual folder. The second argument is the path on the 100 | # guest to mount the folder. And the optional third argument is a set of 101 | # non-required options. 102 | config.vm.synced_folder "vagrant_shared", "/home/vagrant/vagrant_shared" 103 | 104 | # Enable creation of symlinks in the shared folder under Windows/macOS hosts 105 | config.vm.provider "virtualbox" do |v| 106 | v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant_shared", "1"] 107 | end 108 | 109 | # Example to copy file from repository root to shared folder in VM 110 | # config.vm.provision "file", source: "file.x", destination: "~/vagrant_shared/file.x" 111 | 112 | # Every optional build will need the GCC ARM compiler, yotta, and build tools 113 | config.vm.provision "shell", privileged: false, path: "scripts/install_gcc-arm.sh" 114 | if yotta then config.vm.provision "shell", privileged: false, path: "scripts/install_yotta.sh" end 115 | config.vm.provision "shell", privileged: false, path: "scripts/install_build-tools.sh" 116 | 117 | # Install MakeCode and set up the workspace for micro:bit 118 | if pxt then config.vm.provision "shell", privileged: false, path: "scripts/build_pxt.sh" end 119 | # Download and compile C++ DAL examples 120 | if dal then config.vm.provision "shell", privileged: false, path: "scripts/build_cpp.sh" end 121 | # Download and compile MicroPython 122 | if upy1 then config.vm.provision "shell", privileged: false, path: "scripts/build_upy1.sh" end 123 | if upy2 then config.vm.provision "shell", privileged: false, path: "scripts/build_upy2.sh" end 124 | # Download and compile C++ CODAL 125 | if codal then config.vm.provision "shell", privileged: false, path: "scripts/build_codal.sh" end 126 | 127 | 128 | config.vm.post_up_message = "All done! execute 'vagrant ssh' to enter the virtual machine." \ 129 | "\n\tUsername: vagrant\n\tPassword: vagrant" 130 | end 131 | -------------------------------------------------------------------------------- /scripts/build_codal.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -i 2 | alias pretty_echo='{ set +x; } 2> /dev/null; f(){ tput setaf 3; echo -e "\n#\n#\n# $1\n#\n#"; tput sgr0; set -x; }; f' 3 | alias error_echo='{ set +x; } 2> /dev/null; f(){ tput setaf 1; echo -e "\n#\n#\n# $1\n#\n#" >&2; tput sgr0; set -x; }; f' 4 | 5 | # Download sources 6 | cd ~/vagrant_shared 7 | pretty_echo "CODAL: Cloning CODAL head repository..." 8 | git clone https://github.com/lancaster-university/microbit-v2-samples.git 9 | 10 | # Build it 11 | pretty_echo "CODAL: Building CODAL..." 12 | cd ~/vagrant_shared/microbit-v2-samples 13 | python3 build.py 14 | if [ "$?" -eq "0" ]; then 15 | pretty_echo "CODAL: Built hex location:\n# vagrant_shared/microbit-v2-samples/MICROBIT.hex" 16 | else 17 | error_echo "CODAL: BUILD FAILED!" 18 | fi 19 | -------------------------------------------------------------------------------- /scripts/build_cpp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | alias pretty_echo='{ set +x; } 2> /dev/null; f(){ echo "#\n#\n# $1\n#\n#"; set -x; }; f' 3 | 4 | # Download sources 5 | cd ~/vagrant_shared 6 | pretty_echo "DAL: Cloning C++ Examples..." 7 | git clone https://github.com/lancaster-university/microbit-samples.git cpp-samples 8 | 9 | # Build it 10 | pretty_echo "DAL: Building C++ examples using DAL..." 11 | cd ~/vagrant_shared/cpp-samples 12 | yt clean 13 | yt build 14 | { set +x; } 2> /dev/null 15 | echo "#\n# C++ hello world hex file location:" 16 | echo "# vagrant_shared/cpp-samples/build/bbc-microbit-classic-gcc/source/microbit-samples-combined.hex\n#\n#" 17 | -------------------------------------------------------------------------------- /scripts/build_pxt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | alias pretty_echo='{ set +x; } 2> /dev/null; f(){ echo "#\n#\n# $1\n#\n#"; set -x; }; f' 3 | 4 | # Needs GCC-ARM and Yotta to be installed as well, Vagrant file should have installed this already 5 | pretty_echo "PXT: Removing present installation of node and npm..." 6 | sudo apt-get update -qq 7 | sudo apt-get remove -y nodejs npm 8 | pretty_echo "PXT: Installing node.js and npm..." 9 | curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - 10 | sudo apt-get install -y nodejs 11 | 12 | pretty_echo "PXT: Global install of the PXT cli tool..." 13 | sudo npm install -g pxt 14 | # There was an issue with old versions of npm where the cache folder contains root-owned files 15 | sudo chown -R 1000:1000 "/home/vagrant/.npm" 16 | sudo chown -R $USER:$(id -gn $USER) /home/vagrant/.config 17 | 18 | # pretty_echo "PXT: Set up MakeCode stable v5..." 19 | # git clone https://github.com/microsoft/pxt.git --branch v5.15.17 --single-branch --depth 1 20 | # cd ~/vagrant_shared/pxtworkspace/pxt 21 | # npm install 22 | # npm run build 23 | # sudo npm install -g pxt 24 | 25 | pretty_echo "PXT: Set up MakeCode micro:bit target..." 26 | cd ~/vagrant_shared 27 | mkdir -p pxtworkspace/projects 28 | cd ~/vagrant_shared/pxtworkspace 29 | pxt target microbit 30 | 31 | pretty_echo "PXT: Set up example extension..." 32 | cd ~/vagrant_shared/pxtworkspace/projects 33 | git clone https://github.com/carlosperate/pxt-banana.git 34 | git clone --single-branch --branch local-project https://github.com/carlosperate/pxt-banana.git project-with-extension 35 | 36 | 37 | { set +x; } 2> /dev/null 38 | echo "#\n#\n# PXT workspace set up at vagrant_shared/pxtworkspace, to run server:" 39 | echo "# \$ cd ~/vagrant_shared/pxtworkspace/" 40 | echo "# \$ pxt serve --no-browser --no-serial --hostname 0.0.0.0 --port 3232 --wsport 3233" 41 | echo "# Then connect from host machine at http://localhost:3232 with the local" 42 | echo "# token shown on the terminal.\n#\n#" 43 | -------------------------------------------------------------------------------- /scripts/build_upy1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | alias pretty_echo='{ set +x; } 2> /dev/null; f(){ tput setaf 3; echo -e "\n#\n#\n# $1\n#\n#"; tput sgr0; set -x; }; f' 3 | alias error_echo='{ set +x; } 2> /dev/null; f(){ tput setaf 1; echo -e "\n#\n#\n# $1\n#\n#" >&2; tput sgr0; set -x; }; f' 4 | 5 | # Download sources 6 | cd ~/vagrant_shared 7 | pretty_echo "Upy: Cloning MicroPython repository..." 8 | git clone https://github.com/bbcmicrobit/micropython.git 9 | mkdir python_helpers 10 | cd ~/vagrant_shared/python_helpers 11 | pretty_echo "Upy: Cloning pySerial repository at release v3.4..." 12 | git clone --branch v3.4 https://github.com/pyserial/pyserial.git 13 | pretty_echo "Upy: Cloning uFlash repository..." 14 | git clone https://github.com/ntoll/uflash.git 15 | pretty_echo "Upy: Cloning microREPL repository..." 16 | git clone https://github.com/ntoll/microrepl.git 17 | pretty_echo "Upy: Cloning microFS repository..." 18 | git clone https://github.com/ntoll/microfs.git 19 | 20 | # Build it 21 | pretty_echo "Upy: Building MicroPython..." 22 | cd ~/vagrant_shared/micropython 23 | yt clean 24 | yotta target bbc-microbit-classic-gcc-nosd@https://github.com/lancaster-university/yotta-target-bbc-microbit-classic-gcc-nosd 25 | yt up 26 | make all 27 | if [ "$?" -eq "0" ]; then 28 | pretty_echo "Upy: MicroPython hex file location:\n# vagrant_shared/micropython/build/firmware.hex" 29 | else 30 | error_echo "Upy: BUILD FAILED!" 31 | fi 32 | -------------------------------------------------------------------------------- /scripts/build_upy2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | alias pretty_echo='{ set +x; } 2> /dev/null; f(){ tput setaf 3; echo -e "\n#\n#\n# $1\n#\n#"; tput sgr0; set -x; }; f' 3 | alias error_echo='{ set +x; } 2> /dev/null; f(){ tput setaf 1; echo -e "\n#\n#\n# $1\n#\n#" >&2; tput sgr0; set -x; }; f' 4 | 5 | # Download sources 6 | cd ~/vagrant_shared 7 | pretty_echo "Upy V2: Cloning MicroPython repository..." 8 | git clone https://github.com/microbit-foundation/micropython-microbit-v2.git 9 | mkdir python_helpers 10 | 11 | # Build it 12 | pretty_echo "Upy V2: Building MicroPython..." 13 | cd ~/vagrant_shared/micropython-microbit-v2 14 | git submodule update --init 15 | make -C lib/micropython/mpy-cross 16 | cd src 17 | make 18 | if [ "$?" -eq "0" ]; then 19 | pretty_echo "Upy V2: MicroPython hex file location:\n# vagrant_shared/micropython-microbit-v2/src/MICROBIT.hex" 20 | else 21 | error_echo "Upy V2: BUILD FAILED!" 22 | fi 23 | 24 | -------------------------------------------------------------------------------- /scripts/install_build-tools.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | alias pretty_echo='{ set +x; } 2> /dev/null; f(){ echo "#\n#\n# $1\n#\n#"; set -x; }; f' 3 | 4 | pretty_echo "Build Tools: Installing git..." 5 | sudo apt-get update -qq 6 | sudo apt-get install -y git 7 | pretty_echo "Build Tools: Installing extra Python dependencies..." 8 | sudo apt-get install -y python-setuptools python-dev python-pip python3-dev python3-pip 9 | pretty_echo "Build Tools: Installing general C/C++ build tools..." 10 | sudo apt-get install -y cmake ninja-build srecord build-essential 11 | -------------------------------------------------------------------------------- /scripts/install_gcc-arm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | alias pretty_echo='{ set +x; } 2> /dev/null; f(){ echo "#\n#\n# $1\n#\n#"; set -x; }; f' 3 | 4 | pretty_echo "GCC: Removing present installation of GCC ARM compiler..." 5 | sudo apt-get remove binutils-arm-none-eabi gcc-arm-none-eabi 6 | pretty_echo "GCC: Installing GCC ARM compiler..." 7 | sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa 8 | sudo apt-get update -qq 9 | sudo apt-get install -y gcc-arm-embedded 10 | pretty_echo "GCC: Checking GCC ARM compiler version..." 11 | which arm-none-eabi-gcc 12 | arm-none-eabi-gcc --version 13 | -------------------------------------------------------------------------------- /scripts/install_yotta.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | alias pretty_echo='{ set +x; } 2> /dev/null; f(){ echo "#\n#\n# $1\n#\n#"; set -x; }; f' 3 | 4 | pretty_echo "Yotta: Installing yotta dependencies..." 5 | sudo apt-get update -qq 6 | sudo apt-get install -y python3-setuptools python3-dev python3-pip python3-venv cmake build-essential ninja-build libffi-dev libssl-dev libreadline-dev libyaml-dev 7 | pretty_echo "Yotta: Updating pip to a known version..." 8 | sudo -H pip3 install -U pip==19.3.1 9 | sudo -H pip3 install pipx 10 | pipx ensurepath 11 | pretty_echo "Yotta: Installing yotta..." 12 | pipx install yotta==0.20.5 13 | -------------------------------------------------------------------------------- /upy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | """MicroPython helper script 4 | 5 | This script provides the functionality to flash MicroPython to the micro:bit, 6 | open the MicroPython REPL, or transfer files to the MicroPython file system. 7 | It does so by providing an easy to use wrapper around the uFlash, microREPL, 8 | and microFS Python modules. 9 | 10 | These modules and their dependencies have been downloaded as part of the 11 | Vagrant provisioning step and are included to the system path from the 12 | `vagrant_shared/python_helpers` directory. 13 | 14 | This means that the host computer only needs to have Python installed, without 15 | any other Python dependencies or modules. 16 | 17 | uFlash 18 | ====== 19 | The MicroPython hex file is saved into the directory below, which you can drop 20 | into the micro:bit USB drive for flashing: 21 | 22 | vagrant_shared/micropython/build/firmware.hex 23 | 24 | To simplify the process uflash has been included with this wrapper script to 25 | load MicroPython with or without an additional Python program. So, from the 26 | host operating system: 27 | python upy.py flash 28 | or 29 | python upy.py flash 30 | 31 | For a quick test you could load a MicroPython examples for the micro:bit: 32 | python upy.py flash vagrant_shared/micropython/examples/conway.py 33 | 34 | 35 | microREPL 36 | ========= 37 | Launched with: python upy.py repl 38 | The pySerial module is the only dependency and included in python_helpers. 39 | This command enters the micro:bit MicroPython REPL directly via serial. 40 | 41 | 42 | microFS 43 | ======= 44 | Launched with: python upy.py fs 45 | The pySerial module is the only dependency and included in python_helpers. 46 | All the arguments are passed through to microFS. 47 | """ 48 | from __future__ import (absolute_import, division, 49 | print_function, unicode_literals) 50 | import sys 51 | import os 52 | import time 53 | from datetime import datetime, timedelta 54 | 55 | 56 | # Figure out full paths to the required folders 57 | project_root = os.path.dirname(os.path.realpath(__file__)) 58 | py_helpers_dir = os.path.join(project_root, 'vagrant_shared', 'python_helpers') 59 | 60 | # Add Python modules closed in the Vagrant shared folder to the system path 61 | sys.path.append(os.path.join(py_helpers_dir, 'pyserial')) 62 | sys.path.append(os.path.join(py_helpers_dir, 'uflash')) 63 | sys.path.append(os.path.join(py_helpers_dir, 'microfs')) 64 | sys.path.append(os.path.join(py_helpers_dir, 'microrepl')) 65 | 66 | 67 | def flash(): 68 | import uflash 69 | micropython_hex = os.path.join(project_root, 'vagrant_shared', 70 | 'micropython', 'build', 'firmware.hex') 71 | if os.path.isfile(micropython_hex): 72 | uflash_args = sys.argv[2:] 73 | uflash_args.append('--runtime=%s' % micropython_hex) 74 | # Print useful information about the MicroPython hex time stamp 75 | file_timestamp = os.path.getmtime(micropython_hex) 76 | print('Flashing MicroPython modified on %s (%s ago):\n\t%s' % 77 | (datetime.fromtimestamp(file_timestamp).strftime("%Y-%m-%d %H:%M:%S"), 78 | timedelta(seconds=int(time.time() - file_timestamp)), 79 | micropython_hex)) 80 | # If flashing with a Python script print the info 81 | if len(sys.argv) > 2: 82 | print('With Python script: %s\n' % sys.argv[2]) 83 | # print(uflash_args) 84 | uflash.main(uflash_args) 85 | else: 86 | print('The file %s does not exists' % micropython_hex + 87 | 'are you sure the MicroPython build was successful?') 88 | sys.exit(1) 89 | 90 | 91 | def fs(): 92 | import microfs 93 | microfs.main(sys.argv[2:]) 94 | 95 | 96 | def repl(): 97 | import microrepl 98 | microrepl.main() 99 | 100 | 101 | def main(): 102 | if sys.argv[1].lower() == 'flash': 103 | flash() 104 | elif sys.argv[1].lower() == 'fs': 105 | fs() 106 | elif sys.argv[1].lower() == 'repl': 107 | repl() 108 | else: 109 | print('Unrecognised command, please use of the of following three:\n\n' 110 | 'flash - To flash MicroPython with or without a Python script\n' 111 | ' For example: python upy.py flash vagrant_shared/micropython/examples/conway.py\n' 112 | 'fs - To transfer files to a micro:bit running MicroPython\n' 113 | ' To get more info use: python upy.py fs -h\n' 114 | 'repl - To enter the micro:bit MicroPython REPL\n') 115 | sys.exit(1) 116 | 117 | 118 | if __name__ == '__main__': 119 | main() 120 | -------------------------------------------------------------------------------- /vagrant_shared/README.md: -------------------------------------------------------------------------------- 1 | # vagrant_shared folder 2 | This folder is present in the repository to serve as a shared directory between the host and the Vagrant virtual machine. 3 | 4 | Git will ignore empty directories, hence this README. 5 | 6 | --------------------------------------------------------------------------------