libhal platform library for the lpc40 series of microcontrollers by NXP.
To learn about the available drivers and APIs see the
Doxygen
documentation page or look at the
include/libhal-lpc40
directory.
To see how each driver is used see the
demos/ directory.
Following the π Getting Started instructions.
Profiles define which platform you mean to build your project against. These profiles are needed for code and demos in this repo and for applications that wish to execute on an lpc40 device.
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.gitNote that running these functions is safe. THey simply overwrite the old files
with the latest files. So running this for libhal-armcortex between this and
other platform libraries is fine.
To build demos, start at the root of the repo and execute the following command:
conan build demos -pr lpc4078 -s build_type=DebugThis will build the demos for the lpc4078 microcontroller in Debug mode.
Replace lpc4078 with any of the other profiles. Available profiles are:
lpc4072lpc4074lpc4076lpc4078lpc4088
There are a few ways to flash an LPC40 series MCU. The recommended methods are via serial UART or using a debugger JTAG/SWD.
nxpprog is a script for programming and flashing LPC40 series chips over
serial/UART. Using it will require a USB to serial/uart adaptor.
See the README on nxpprog, for details on how to use NXPPROG.
To install nxpprog:
python3 -m pip install -U nxpprogTo flash command is:
nxpprog --control --binary demos/lpc4078/blinker.elf.bin --device /dev/tty.usbserial-10- Replace
demos/lpc4078/blinker.elf.binwith the path to the binary you'd like to flash. - Replace
/dev/tty.usbserial-10with the path to your serial port on your machine.- Don't know which serial port to use? Use this guide from the MATLAB docs to your port for your operating system. Simply ignore that its made for Arduino, this guide will work for any serial USB device: Find Arduino Port on Windows, Mac, and Linux
PyOCD is a debugging interface for programming and also debugging ARM Cortex M
processor devices over JTAG and SWD.
This will require a JTAG or SWD debugger. The recommended debugger for the LPC40 series of devices is the STLink v2 (cheap variants can be found on Amazon).
See PyOCD Installation Page for installation details.
For reference the flashing command is:
pyocd flash --target lpc4088 lpc4078_blinker.elf.binNote that target lpc4088 works for all lpc40 series microcontrollers.
This section assumes you are using the
libhal-starter
project.
Make sure to add the following options and default options to your app's
ConanFile class:
options = {"platform": ["ANY"]}
default_options = {"platform": "unspecified"}Add the following to your requirements() method:
def requirements(self):
if str(self.options.platform).startswith("lpc40"):
self.requires("libhal-lpc40/[^2.1.5]")The version number can be changed to whatever is appropriate for your application. If you don't know, using the latest is usually a good choice.
The CMake from the starter project will already be ready to support the new platform library. No change needed.
To perform a test build simple run conan build as is done above with the
desired target platform profile.
The initialize_processor() function for targets lpc4072, lpc4074 and
lpc4076 should do the following:
#include <libhal-armcortex/startup.hpp>
hal::status initialize_processor()
{
hal::cortex_m::initialize_data_section();
return hal::success();
}The initialize_processor() function for targets lpc4078, lpc4088:
#include <libhal-armcortex/startup.hpp>
#include <libhal-armcortex/system_control.hpp>
hal::status initialize_processor()
{
hal::cortex_m::initialize_data_section();
hal::cortex_m::initialize_floating_point_unit();
return hal::success();
}To setting the CPU clock speed to the maximum of 120MHz, include the line below, with the rest of the includes:
#include <libhal-lpc40/clock.hpp>Next run the following command but replace 12.0_MHz with the crystal
oscillator frequency connected to the microcontroller. This command REQUIRES
that there be a crystal oscillator attached to the microcontroller. Calling
this without the oscillator will cause the device to freeze as it will attempt
to use a clock that does not exist.
hal::lpc40::clock::maximum(12.0_MHz);Coming soon...
In one terminal:
pyocd gdbserver --target=lpc4088 --persistIn another terminal:
arm-none-eabi-gdb demos/build/lpc4078/blinker.elf -ex "target remote :3333"Replace demos/build/lpc4078/blinker.elf with the path to the elf file you'd
like to use for the debugging session.
Coming soon... (its more complicated)
See CONTRIBUTING.md for details.
Apache 2.0; see LICENSE for details.
This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.