Table of Contents
Zephyr on Windows-hosted 64 bit Linux Virtual Machine
Introduction
The following instructions can be used to develop an application using Zephyr and program it on to a suitable board.
Requirements
- PC with 64 bit virtualization
- Internet connection
- Suitable board (e.g. B-L475E-IOT01A Discovery kit)
- Cable to connect board (e.g. USB Type-A to Micro-B cable)
Setting up Linux Virtual Machine
Zephyr requires a 64 bit version of Linux. In order to run a 64 bit version of Linux in a Virtual Machine, your computer must be capable of 64 bit virtualization. This may require changing a setting in your BIOS. A web search of your particular model should help clarify if your machine is capable of 64 bit virtualization and if any steps are required to enable this feature.
More details on setting up a Linux Virtual Machine on Windows can be found here: https://www.storagecraft.com/blog/the-dead-simple-guide-to-installing-a-linux-virtual-machine-on-windows/
Install Virtual Machine Software
There are several different programs for virtual machines. Oracle Virtual Box was chosen as it is fairly popular, free, and cross-platform.
Download Linux OS
Zephyr requires a 64 bit version of Linux.
These instructions were developed using a Xubuntu distribution (https://xubuntu.org/) but should work equally well for other Linux distributions. A lightweight distribution may improve performance on a host machine with limited resources.
Configure Virtual Machine
In Oracle Virtual Box, Create a new Virtual Machine.
- Give it an appropriate name (e.g. LinuxVM), select Linux as the type, and choose the version that matches the Linux OS you obtained in the previous step.
Note: If the versions only list 32 bit, your system may not be capable of virtualizing a 64 bit system or you may need to enable the option in the BIOS. Consult the Google.
- Select the amount of RAM you want to allocate to the Virtual Machine. The default 1024 MB seems to work fine.
- Create a new virtual hard drive. Again, the default setting of VDI should work fine. Give this file a name and choose where it is stored within your existing Windows file system. Adjust the slider or type in a specific number in the box to the right to specify the virtual hard drive size. At least 20 GB is recommended, as it is no trivial to extend the size after it is created.
Install Linux OS on Virtual Machine
In Oracle Virtual Box, start the Virtual Machine you created in the last session. You should be prompted to select a start-up disc.
- Navigate to and select the .iso of the Linux OS you downloaded in a previous step.
- Follow the instructions to install the Linux OS to your virtual machine.
Optional
It may be convenient to create a shared folder between your Windows machine and your Linux virtual machine:
Install Guest Tools:
- sudo apt-get install virtualbox-guest-dkms
Add permission for user to shared folder:
- sudo usrmod -G vboxsf -a <your username>
You can now add and configure a shared folder in Oracle Virtual Machine.
- DEVICES > SHARED FOLDERS > SHARED FOLDER SETTINGS
Setting up Linux Build Environment
The following instructions are largely based on Instructions for Setting up the Development Environment Setup on Linux: https://www.zephyrproject.org/doc/getting_started/installation_linux.html
Open a terminal, and update the os:
- sudo apt-get update
- sudo apt-get upgrade
Install necessary packages:
- sudo apt-get install git make gcc g++ ncurses-dev gperf ccache doxygen dfu-util device-tree-compiler python3-ply python3-pip python-pip
Install serial communication program:
- sudo apt-get install minicom
Install CMake:
- cd cmake/
Optional - check tags:
- git tag -l
Checkout version 3.8.2
- git checkout v3.8.2
- ./bootstrap && make -j8
- sudo make install
Optional - It may be necessary to check to see if the newly installed CMake is going to be called correctly:
- type -a cmake dpkg -S /usr/bin/cmake gvim -p ~/.bashrc ~/.pr ofile
- alias cmake='/usr/local/bin/cmake'
Install Zephyr Software Development Kit
For SDK Version 0.9.2 :
- chmod +x zephyr-sdk-0.9.2-setup.run
- sudo ./zephyr-sdk-0.9.2-setup.run
Get Zephyr Source Code
git clone https://github.com/zephyrproject-rtos/zephyr.git
Navigate to the Zephyr source code directory (e.g. /home/zephyr) and install required Python packages:
- pip3 install –user -r scripts/requirements.txt
Board Specific Setup
The following instructions are some specific steps for programming the B-L475E-IOT01A Discovery kit board.
Manufacturer page:
Zephyr Project Page:
Install USB drivers for Windows
Install additional packages
- sudo apt-get install pkg-config autoconf automake libtool libusb-dev libusb-1.0-0-dev libhidapi-dev
Load rules from St Link firmware upgrade:
Copy rules from stsw-link007/AllPlatforms/StlinkRulesFilesForLinux over to /etc/udev/rules.d
- sudo cp *.rules /etc/udev/rules.d
Reload rules:
- sudo udevadm control –reload-rules
Enable USB Device access to Virtual Machine
By default, you need to explicitly allow the virtual machine to connect to USB devices.
Connect the board to your computer using the USB cable. Make sure to connect to the jack marked “USB STLINK” (Not the USB OTG jack)
Enabled the connection in Oracle Virtual Box:
- DEVICES > USB
- Select “STMicroelectronics STM32 STLINK [0100]”
Making Hello World
Set build variables:
- export ZEPHYR_GCC_VARIANT=zephyr
- export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk
Navigate to Zephyr directory:
- cd <zephyr_root_path>
Set build environment:
- source zephyr-env.sh
Navigate to Hello world code:
- cd $ZEPHYR_BASE/samples/hello_world/
Build code for the corresponding board configuration:
- mkdir -p build/disco_l475_iot1
- cd build/disco_l475_iot1
- cmake -DBOARD=disco_l475_iot1 ../..
- make -j8
If it isn't already, connect the board to your computer using the USB cable. Make sure you've configured the Virtual Machine access to the USB device as described above.
Flash the board with the program:
- make flash
Run a serial host program to connect with your board. You may want to execute these in a second terminal:
- minicom -D /dev/ttyACM0
Press the reset button on the board. If all has gone well, you should see:
Hello World! arm
Next Steps
Resources
- General Info on Setting up Virtual Machine to Run Linux: https://www.linux.com/learn/why-when-and-how-use-virtual-machine
- Resize a Virtual Box guest Linux VDI under Windows Host: http://derekmolloy.ie/resize-a-virtualbox-disk/