Skip to content

๐Ÿš€ Trying out libhal

๐Ÿ› ๏ธ Building Demos

Make sure to complete ๐Ÿงฐ Install Prerequisites

Cloning the target libraries

Clone the target library you would like to run the demos for. You can download just one or both if you have both devices.

git clone https://github.com/libhal/libhal-lpc40
cd libhal-lpc40/demos

Installing microcontroller profiles

This command will install the profiles for the ARM cortex processor and LPC40 series microcontrollers. The LPC40 microcontrollers are:

  • lpc4072
  • lpc4074
  • lpc4076
  • lpc4078
  • lpc4088

The LPC40 profiles import cortex-m4 and cortex-m4f profiles from the ARM cortex processor library libhal-armcortex and thus need to be installed as well.

conan config install -sf conan/profiles/ -tf profiles https://github.com/libhal/libhal-armcortex.git
conan config install -sf conan/profiles/ -tf profiles https://github.com/libhal/libhal-lpc40.git

Building using Conan & CMake

To build using conan and cmake, you just need to run the following:

conan build . -pr lpc4078 -s build_type=MinSizeRel

Note

You may need to add the argument -b missing at the end of the above command if you get an error stating that the prebuilt binaries are missing. -b missing will build them locally for your machine. After which those libraries will be cached on your machine and you'll no longer need to include those arguments.

To build a binary for a particular microcontroller, you need to specify the microcontroller you plan to target such as the lpc4078 and the build type.

Each microcontroller has different properties such as more or less ram and the presence or lack of a floating point unit.

The following build types, build_type argument are available:

  • โŒ Debug: No optimization, do not recommend, normally used for unit testing.
  • ๐Ÿงช RelWithDebInfo: Turn on some optimizations to reduce binary size and improve performance while still maintaining the structure to make debugging easier. Recommended for testing and prototyping.
  • โšก๏ธ Release: Turn on optimizations and favor higher performance optimizations over space saving optimizations.
  • ๐Ÿ—œ๏ธ MinSizeRel: Turn on optimizations and favor higher space saving optimizations over higher performance.

Note that Release and MinSizeRel build types both usually produce binaries faster and smaller than RelWithDebInfo and thus should definitely be used in production.

When this completes you should have some applications in the build/lpc4078/MinSizeRel/ with names such as uart.elf or blinker.elf.

Error

You can get this error if the arm gnu toolchain wasn't installed correctly and the cmake toolchain was already generated.

-- Using Conan toolchain: /Users/kammce/git/libhal/libhal-lpc40/demos/build/lpc4088/MinSizeRel/generators/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 20 with extensions ON
CMake Error at CMakeLists.txt:18 (project):
  The CMAKE_CXX_COMPILER:

    /Users/kammce/.conan2/p/b/arm-ged7418b49387e/p/bin/bin/arm-none-eabi-g++

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "/Users/kammce/git/libhal/libhal-lpc40/demos/build/lpc4088/MinSizeRel/CMakeFiles/CMakeOutput.log".
See also "/Users/kammce/git/libhal/libhal-lpc40/demos/build/lpc4088/MinSizeRel/CMakeFiles/CMakeError.log".

Fix this by deleting the build/ in the demo directory like so:

rm -r demos/build

Error

You can get this error if the arm gnu toolchain wasn't installed correctly and the cmake toolchain was already generated.

-- Using Conan toolchain: /Users/kammce/git/libhal/libhal-lpc40/demos/build/lpc4088/MinSizeRel/generators/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 20 with extensions ON
CMake Error at CMakeLists.txt:18 (project):
  The CMAKE_CXX_COMPILER:

    /Users/kammce/.conan2/p/b/arm-ged7418b49387e/p/bin/bin/arm-none-eabi-g++

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "/Users/kammce/git/libhal/libhal-lpc40/demos/build/lpc4088/MinSizeRel/CMakeFiles/CMakeOutput.log".
See also "/Users/kammce/git/libhal/libhal-lpc40/demos/build/lpc4088/MinSizeRel/CMakeFiles/CMakeError.log".

Fix this by deleting the build/ in the demo directory like so:

rm -r demos/build

๐Ÿ’พ Uploading Demos to Device

Necessary Parts

In order to complete this tutorial you'll need either a

  • LPC4078 MicroMod with SparkFun ATP board

or

  • or SJ2 Board

Uploading Applications

There are python programs built for uploading binary files to devices.

First step is connecting your MicroMod carrier board to your computer using the USB-C connector.

Question

Don't know which serial port to use? Use this guide Find Arduino Port on Windows, Mac, and Linux from the MATLAB docs to help. Simply ignore that its made for Arduino, this guide will work for any serial USB device.

Install the nxpprog flashing software for LPC devices:

python3 -m pip install nxpprog

Tip

On Ubuntu 22.04 you will need to use the command python3.10 because the default python is usually 3.8.

python3.10 -m pip install nxpprog
nxpprog --control --binary "build/lpc4078/MinSizeRel/uart.elf.bin" --device "/dev/tty.usbserial-140"
  • Replace /dev/tty.usbserial-140 with the correct port.
  • Replace uart.elf.bin with any other application found in the demos/applications/ directory.