iMX-RT1010 ZepyrOS Development Setup with Micropython
Part-1:On Ubuntu 18.04
Development ToolchainA toolchain includes necessary tools used to build Zephyr applications including: compiler, assembler, linker, and their dependencies.
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.10.3/zephyr-sdk-0.10.3-setup.run
chmod +x zephyr-sdk-0.10.3-setup.run
./zephyr-sdk-0.10.3-setup.run -- -d ~/zephyr-sdk-0.10.3
Next we set the environmental variable for our toolchains: issue the commands below or put them in your ~/.bashrc (if you put them in.bashrc then run: source ~/.bashrc to activate the enviroment)
Also they could put in.sh script file, chmod it +x do this as you like.
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=~/zephyr-sdk-0.11.1
Now we need to add udev rules file that provides information needed to identify boards and grant hardware access permission to flash tools. Install these udev rules with these commands: run the commands below:
sudo cp ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
Testing the Zephyr OS:
We need to test zephyr-os at this point to make sure that the imx-rt1010 board is configure and works well in zephyr-os kit.
cd into your zephyrproject directory:- cd ~/zephyrproject/zephyr
Next run the environmental setup file:- source zephyr-env.sh
Taking the board for spin-drive: running the sample application
from the root directory, run the west routine below to build the sample App for RT1010
west build -b mimxrt1015_evk samples/hello_world
cmake and ninja-build
error-message: CMake was unable to find a build program corresponding to "Ninja"
Soln: sudo apt-get install ninja-build
Error message: target build directory already exist
Soln: including one of the following directives in your build command:
use --pristine, or
use --build-dir to specify a different one or
use --force due to enforce build
e.g. west build -b mimxrt1015_evk samples/hello_world –pristine
if everything else is okay the you end up with a build like shown below here:
You should an zephyr/zephyr.elf file created for your board
Next to get the firmware onto your board the perform the following routines
Additional Installation and Setup:
Via MCUXpresso IDE:
Why I was having problems to flash the firmware as it requires J-Link hardware that I do not have at hand so I need an alternative routine function to the board flash with the newly built firmaware.
MCUxpresso IDE is NXP tool made for the board and other series so it should pretty well using the USB debugger interface. Lets how far we could go here.
A finished IDE installation as shown in thescreenshot below:
Getting RT1010 sdk install into the IDE environment:
Getting familiar with RT1010 SDK and sampling:
The sdk comes with plenthora sample applications that showcase the board features:
PART-2 Exploring MicroPython
MicroPython Platform:
There are few documents that could be found on Google search that explain how to go about about getting MicroPython build for MIMXRT1010 board but each goes a bit less or none to what I was looking for. These are expecting since each of them are trying to get it built for a particular board or for a particular vendor interest. I think we are in the same boat here doing the same for MIMXRT1010 board.
- We are build a port of Micropython and Zephyr OS
Step 1:
We are going to clone Micropython repository as a sibling of Zephyr OS that we have built previously, tested and working for MIMXRT1010 board above in this project.
Navigate into Zephyrproject folder: cd zephyrproject
git clone https://github.com/micropython/micropython.git
Your folder layout should look similar to what is shown below here:
Step 2:
Next cd zephyrproject/micropython/ports/zephyr
Now run the command => make BOARD=mimxrt1010_evk
The above command if everything goes as it should be should get you a port of MicroPython with Zephyr OS firmware to ready to be flash ed onto MIMXRT1010 board.
If you encounter build errors like the ones shown below:
Then you need to set zephyr enviroment variable, run the command:
source zephyr/zephyr-env.sh (from the zephyrproject root folder)
Next go back into previous zephyr port inside the micropython directory.
Run make BOARD=mimxrt1010_evk
Another problem that may be encounter is the toolchain unable to locate header files like shown below here:
Remedy:
In micropython root directory, run
git checkout master
git pull
and that should update to the latest git headThen repeat:
make BOARD=mimxrt1010_evk clean
make BOARD=mimxrt1010_evk
Board configuration problems (zephyr pre-built choke)
the issue here is listed below:
ld: zephyr_prebuilt.elf section `noinit' will not fit in region `SRAM'
ld: section.intList VMA [0000000020008000, 0000000020008047] overlaps section noinit VMA [00000000200058a8, 0000000020009e26]
ld: region `SRAM' overflowed by 9572 bytes
We have:
[ 96%] Linking C executable zephyr_prebuilt.elf
Memory region Used Size Region Size %age Used
OCRAM: 0 GB 64 KB 0.00%
ITCM: 0 GB 32 KB 0.00%
FLASH: 236545 B 16 MB 1.41%
SRAM: 42340 B 32 KB 129.21% <== ram issue is here
IDT_LIST: 72 B 2 KB 3.52%
The above issues are from Linker complaining about SRAM value, so loacte mimxrt1010 board yaml file in the zephyr/boards/mimxrt1010_evk folder to the followings:
#
# Copyright (c) 2019, NXP
#
# SPDX-License-Identifier: Apache-2.0
#
identifier: mimxrt1010_evk
name: NXP MIMXRT1010-EVK
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 32 <== *** You need to bump this up to ram: 128
flash: 16384
supported:
- i2c
- hwinfo
- counter
- usb_device
As you can see we have minimum value of flash 16MB (16384) and ram size of 32kb
It always an issue and you may have to adjust the linker script assocaited for a board. This is also what porting entails. See here: https://github.com/zephyrproject-rtos/zephyr/pull/6617 for more information and Google to get more on overcoming the problem.
Well sadly increasing the ram size does not cure the pre-built elf size error so at the moment I only able to build with the minimal configuration:
./make-minimal BOARD=mimxrt1010_evk
Screenshot of this build configuration is as shown below:
The good news here is that we can use the minimal build configuration as a starting point to ge the full build done. So I will be studying those source code, dts, config,.mk and make files to work-on form there but we need to test our built firmware and flash the with it.
NOTICE:
1.) for the minimal build mode, you may need to turn VFS direct in mpconfig.h as shown here:
// Support for generic VFS sub-system
#ifndef MICROPY_VFS
#define MICROPY_VFS (1)
#endif
2.) You may also need to adjust the linker-cmd file to increase the ram size. (Hey! This is Micropython + Zephyr OS. Okay!):
MEMORY
{
OCRAM (wx) : ORIGIN = 0x20200000, LENGTH = 262144
ITCM (wx) : ORIGIN = 0x0, LENGTH = 131072
}
OUTPUT_FORMAT("elf32-littlearm")
_region_min_align = 32;
MEMORY
{
FLASH (rx) : ORIGIN = (0x60000000 + 0x0), LENGTH = (16384*1K - 0x0)
SRAM (wx) : ORIGIN = 0x20000000, LENGTH = (128 * 1K)
IDT_LIST (wx) : ORIGIN = (0x20000000 + (128 * 1K)), LENGTH = 2K
}
Why bumping ram size? Well according to the following extract from the Micropython build instructions. See the extract below:
Minimal buildMicroPython is committed to maintain minimal binary size for Zephyr port below 128KB, as long as Zephyr project is committed to maintain stable minimal size of their kernel (which they appear to be). Note that at such size, there is no support for any Zephyr features beyond REPL over UART, and only very minimal set of builtin Python modules is available. Thus, this build is more suitable for code size control and quick demonstrations on smaller systems. It's also suitable for careful enabling of features one by one to achieve needed functionality and code size. This is in the contrast to the "default" build, which may get more and more features enabled over time.
To make a minimal build:
./make-minimal BOARD=<board>
Now as you can see that anything below 128KB will be a struggle for us but luckily the MIMXRT1010 has:
- 64 KB ROM
- 128 KB RAM
So we should almost fine. Lets go on:
Getting the full build error fix around the corners. This is what worked foe me:
[ 96%] Linking C executable zephyr_prebuilt.elf
Memory region Used Size Region Size %age Used
OCRAM: 0 GB 128 KB 0.00%
ITCM: 0 GB 64 KB 0.00%
FLASH: 235421 B 16 MB 1.40%
SRAM: 42340 B 64 KB 64.61%
IDT_LIST: 72 B 2 KB 3.52%
with the linker-cmd settings:
MEMORY
{
OCRAM (wx) : ORIGIN = 0x20200000, LENGTH = 131072
ITCM (wx) : ORIGIN = 0x0, LENGTH = 65536
}
OUTPUT_FORMAT("elf32-littlearm")
_region_min_align = 32;
MEMORY
{
FLASH (rx) : ORIGIN = (0x60000000 + 0x0), LENGTH = (16384*1K - 0x0)
SRAM (wx) : ORIGIN = 0x20000000, LENGTH = (64 * 1K)
IDT_LIST (wx) : ORIGIN = (0x20000000 + (64 * 1K)), LENGTH = 2K
}
and
the board.yaml settings of:
#
# Copyright (c) 2019, NXP
#
# SPDX-License-Identifier: Apache-2.0
#
identifier: mimxrt1010_evk
name: NXP MIMXRT1010-EVK
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 64 <== work for standard built of Micropython plus Zephyr
flash: 16384
supported:
- i2c
- hwinfo
- counter
- usb_device
The screenshot for a full built of MicroPython+Zephyr OS is as shown below:
Part-4: Test Drive Routines:
The Mistry of Debuggers/Flashers:
JTAG Alternative Tools:
ULINK2:
After about a week going round websites and Google insanely, I finally was lucky to find the following guide on Keil forum. It was as a reply previously to those people having the same issues like the ones I was experiencing. Huuh!
How to load and flash hex or bin or firmware using uVision
Developers can create a µVision project for downloading a HEX file to Flash. Such a project can be used within a batch file for automated Flash programming. Follow these steps to create the project file:
- Create a µVision project through the menu Project — New Project.
- Select the microcontroller from the Device Database, but do not copy any startup code to this project.
- Enter the HEX file name into the field Project — Options for Target — Output — Name of Executable.
- Setup the download utility as described in Flash Download Configuration.
📷 Download the HEX file to the Flash ROM device using the menu Flash — Download.
The above steps proven positive, so now I have an Ubuntu Linux setup to build firmware and applications on then move the output binary onto Windows 7 box to get it flash on MIMXRT1010_EVK board. Let’s see how far I can go on these steps.
Test Driving with MIMXRt1010:
Part-1: Zephyr – O/S:
Part-2: MicroPython + Zephyr port
- Flashing the board:
A quick test drive of the minimal build (Micrpython+Zephyr)
We also carried the standard and a full build of Micropython+Zephr OS:
Part-4: CircuitPython Platform:
After clone Circuitpython, change into its folder
cd circuitpython
next run the commnand: make -C mpy-cross
This will compile a frozen library that will be include in our firmware when we build that firmware object next.
Now change directory into the iMMXRT ports:
cd ports/mimxrt10xx
if type the ls command to list the folder contents, you should the following items shown in the screenshot below:
Most files are common to iMMXRT10xx family but the folder named ==> boards is important to us as it contains each RT10xx specific board configuration and we can have our iMMXRT1010 configured for our firmware build options.
We want the imxrt1010_evk folder, so cd into that folder and lets work through it.
First build step:
Type the following commands to build the firmware:
make BOARD=imxrt1010_evk
if everything goes well then you should see the following out about the firmware was successifully built:
The TinyUf2 Toolkit: (by ARTURO182)
I discover this brilliant usb utilities that could facilitate drag and drop of firmware, programming files, python code onto a board and have run those files without having to flash board each time/repeatedly. Cool stuff, thanks and credit goes to arturo 182 guy.
Step1:
git clone –recursive https://github.com/arturo182/tinyuf2.git
next cd tinyuf2
now issue the command:=> make BOARD=mimxrt1010_evk
The above command will build it for our iMMXRT1010 evaluation board.
If everything goes on well then you should see the following screenshot output:
Now the next thing is to flash your board with the tinyuf2 just built firmware. Happy hacking!
==> insert here Keil on Windows procedures
Hurray! It works! Now the next step is to get MicroPython setup and build the Zephyr port of it.
Hurray!
ince we have got:
- MCUExpres Studio => built and tested
- Zephyr OS => built and tested
- CircuitPython => built and tested
- MicroPython+Zephyr => built and tested
Now that we have many options and environments that we can provide for our target users (6-16yr) old children. The next step is to bring up these environments with user interface (UX) and top layer for an End-to-End environments that are suitable and make it possible for creative explorations.
In the next part we will using our environment to create learning environments with control systems using MIMXRT1010_EVK board:
Visual Programming like scratch/block programming for kids
Power a small car robot
Develop App to control devices attached to board
Do Music App
Simple A.I. (Face detection and gesture recognition)
Some issues:
J-Link debugger
Issues Ulink2 (does work in Linux nor Ubuntu. What a waste?)
Bibliography:
Comments