-
You will need the Board Support Package (BSP) from NXP. The bare minimum files are included here for convenience, so this should not be necessary. To obtain the latest BSP:
- Create an account on nxp.com
- Use the MCUexpresso SDK Builder to select and download your desired components
- Place the relevant files and subdirectories in core/include and core/src.
- The
startup_MK64F12.S
file may be found here, for unknown reasons it is not included in the MCUexpresso SDK: CMSIS CM4 boot code
Please note that using any of the MCUexpresso drivers with this project is not tested. The maintainers of this project have no experience with them.
-
Install Meson.
-
Install the following:
- For Arch derivatives:
arm-none-eabi-gcc
arm-none-eabi-binutils
arm-none-eabi-newlib
(optional, for libc functions)arm-none-eabi-gdb
(recommended, for debugging)openocd
(recommended, for flashing)
- For Debian derivatives:
gcc-arm-none-eabi
binutils-arm-none-eabi
libnewlib-arm-none-eabi
gdb-multiarch
(includes arm-none-eabi)openocd
- For Arch derivatives:
-
(Optional) In the event that flashing fails, you may need to add some udev rules:
- As root, create three files under
/etc/udev/rules.d
with the following names and contents:45-mbed_debugger.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", ATTR{idProduct}=="0204", MODE="0660", GROUP="plugdev"
50-tty_cmsis.rules
KERNEL=="ttyACM[0 ... 9]" SYMLINK+="%k" GROUP="plugdev" MODE="0660"
99-hidraw-permissions.rules
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"
- Create the plugdev group, if it does not exist:
sudo getent group plugdev || sudo groupadd plugdev
- Add your user to the plugdev group:
sudo usermod -aG plugdev $USER
- And finally, reload the udev rules:
sudo udevadm control --reload-rules sudo udevadm trigger
- As root, create three files under
-
Customize the
meson.build
file to include the files for your project.- C source files should be added separately from ASM source files, as denoted in the build file.
local_headers
should be set to the root of the include search tree. Do not list every header file.- Add any project options you require with
add_project_arguments
- Define the correct CPU for your target. (default: MK64FN1M0VLL12)
-
Run
python init.py
. Only Python 3 is supported. This script will customize files in template_files with the included replacements. This may be extended for your project if necessary, and acts as a way to configure the build before handing over control to meson. -
Run
meson <build dir> --cross-file k64_files/k64_cross_properties.cfg
. This will create a Ninja build description in<build dir>
. -
Run
ninja -C <build dir>
. This will create a binary file which can be flashed to the K64 in<build dir>
.
An OpenOCD flash description usable for k64 should be included by the default
install of OpenOCD. In the case it is not, it has been included in k64_files
.
The file scripts/flash.sh
references this included file.
- Run
scripts/flash.sh
. If all goes well, the lights on your K64 board will light up and your code will be running immediately. - To kill the running OpenOCD session, run
scripts/openocd_server.sh stop
.
OpenOCD provides a GDB server which acts as an arbiter for the actual debug protocols used on target devices, OpenSDA in this case. Do the following:
- From your terminal, run
scripts/gdb.sh build/main.elf
. You may need to change the target file if you edited the inner workings ofmeson.build
- From another pty, run
telnet localhost 4444
. This will allow you to control OpenOCD when GDB gets out of sync with the target. - In the telnet shell, type
reset init
before doing anything in GDB. This allows OpenOCD to sync GDB to the current state of the MCU before continuing.
When debugging and flashing, an OpenOCD server is started that runs in the
background. The scripts here create a PID file in case you need to kill it
manually, which is located at the project root with the name openocd.pid
.
Normally, this should not be necessary. Running
scripts/openocd_server.sh stop
or typing shutdown
in the telnet console
should be enough to end your OpenOCD session gracefully.
When debugging the target, a new ROM may be flashed to the device, but GDB will
not be aware of the change, nor the reset. By default, the flash script causes
the target to be running after a flash, meaning that reset init
must be issued
in the telnet console in order to reset and halt the target. Note that GDB will
still not be aware of the new debugging symbols, so it needs to be restarted or
the ELF file reloaded for correct source-level debugging.