Environment
- Host PC: Ubuntu 16.04
- Device: mbed NXP LPC1768
- IDE: Eclipse IDE for C/C++ Developers Version: Photon Release (4.8.0)
I just bought a mbed NXP LPC1768 to learn mbed programming.
Install Java
$ sudo sudo apt install default-jdk
$ sudo apt-get update
$ java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
Install gcc4mbed
$ git clone https://github.com/adamgreen/gcc4mbed.git
$ cd gcc4mbed/
$ sudo apt install make
$ ./linux_install
~/github_playground/gcc4mbed ~/github_playground/gcc4mbed
Logging install results to /home/reyes/github_playground/gcc4mbed/linux_install.log
Downloading GNU Tools for ARM Embedded Processors...
--2018-09-14 20:14:05-- https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/6_1-2017q1/gcc-arm-none-eabi-6-2017-q1-update-linux.tar.bz2
Resolving armkeil.blob.core.windows.net (armkeil.blob.core.windows.net)... 191.235.193.32
Connecting to armkeil.blob.core.windows.net (armkeil.blob.core.windows.net)|191.235.193.32|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 100247592 (96M) [application/octet-stream]
Saving to: ‘gcc-arm-none-eabi-6-2017-q1-update-linux.tar.bz2’
gcc-arm-none-eabi-6-2017-q1-update- 100%[==================================================================>] 95.60M 963KB/s in 54s
2018-09-14 20:15:01 (1.76 MB/s) - ‘gcc-arm-none-eabi-6-2017-q1-update-linux.tar.bz2’ saved [100247592/100247592]
Validating md5 signature of GNU Tools for ARM Embedded Processors...
Extracting GNU Tools for ARM Embedded Processors...
Creating helper scripts...
Performing a clean build of the gcc4mbed samples...
Cleaning up intermediate files...
To build gcc4mbed samples, you will first need to run the following script
so that your environment variables are set correctly:
/home/reyes/github_playground/gcc4mbed/BuildShell
You will want to run this each time you start a new Terminal. You
can simply double-click on this script file from Finder to launch a
bash Terminal that has been properly initialized for building gcc4mbed
based code. Feel free to customize it as you desire.
You can also just edit your existing setup script such as ~/.profile
to update the PATH environment variable to include:
/home/reyes/github_playground/gcc4mbed/gcc-arm-none-eabi/bin
Finished successfully
Press any key to continue...
$ cd ./external/mbed-os/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/
$ vim device.h
#ifndef MBED_DEVICE_H
#define MBED_DEVICE_H
#define DEVICE_PORTIN 1
#define DEVICE_PORTOUT 1
#define DEVICE_PORTINOUT 1
#define DEVICE_INTERRUPTIN 1
#define DEVICE_ANALOGIN 1
#define DEVICE_ANALOGOUT 1
#define DEVICE_SERIAL 1
#define DEVICE_SERIAL_FC 1
#define DEVICE_I2C 1
#define DEVICE_I2CSLAVE 1
#define DEVICE_SPI 1
#define DEVICE_SPISLAVE 1
#define DEVICE_CAN 1
#define DEVICE_RTC 1
#define DEVICE_ETHERNET 1
#define DEVICE_PWMOUT 1
#define DEVICE_SEMIHOST 1
#define DEVICE_LOCALFILESYSTEM 1
#define DEVICE_SLEEP 1
#define DEVICE_DEBUG_AWARENESS 1
#define DEVICE_STDIO_MESSAGES 1
#define DEVICE_ERROR_PATTERN 1
Upgrade Firmware
$ cd ~/Downloads/
$ wget https://os.mbed.com/media/uploads/samux/mbedmicrontroller_141212.if
$ cp mbed*.if /media/reyes/MBED/
Testing GCC4MBED
$ cd ~/gcc4mbed/samples/HelloWorld/
$ ls
LPC1768 main.cpp Makefile
$ vim Makefile
#DEVICES := KL25Z \
# K64F \
# LPC1768 \
# NRF51_DK
DEVICES := LPC1768
$ make
Linking release library ../../external/mbed-os/Release/mbedos/LPC1768/mbedos.a
Linking LPC1768/HelloWorld.elf
Extracting LPC1768/HelloWorld.bin
Extracting LPC1768/HelloWorld.hex
Extracting disassembly to LPC1768/HelloWorld.disasm
text data bss dec hex filename
12600 144 7468 20212 4ef4 LPC1768/HelloWorld.elf
$ ls ./LPC1768/
gcc4mbed.d gcc4mbed.o HelloWorld.bin HelloWorld.disasm HelloWorld.elf HelloWorld.hex HelloWorld.ld HelloWorld.map main.d main.o
$ cp ./LPC1768/HelloWorld.bin /media/reyes/MBED/
Install Eclipse
Chose Eclipse IDE for C/C++ Developers Linux 64bit, and download “eclipse-cpp-photon-R-linux-gtk-x86_64.tar.gz”.
https://www.eclipse.org/downloads/packages/
$ cd ~/Downloads
$ tar -xvf eclipse-cpp-photon-R-linux-gtk-x86_64.tar.gz -C ..
$ cd ~/.local/share/applications
$ vim eclipse.desktop
[Desktop Entry]
Type=Application
Exec=/home//eclipse/eclipse
Name=Eclipse
GeneriName=An IDE for C/C++ development
Icon=/home//eclipse/icon.xpm
Terminal=false
Categories=Development;IDE;C++
MimeType=text/x-c++src;text/x-c++hdr;text/x-xsrc;application/x-designer;
Now we can see “Eclipse” in Application.
Here is overview of Eclipse.
File -> New -> Makefile Project from Existing Code
Select “HelloWorld” and right click and select “Properties”.
C/C++ Build -> Manage Configurations… -> New…
Create “Debug”.
Delete “Default” and set like this.
Build (Incremental build): all deploy GCC4MBED_TARGET=Debug
C/C++Build -> Environment
Name: GCC4MBED_DEPLOY
Value: cp PROJECT.bin /media/$(USER)/MBED/; sync
C/C++ General -> Paths and Symbols
/home/reyes/gcc4mbed/external/mbed-os
/home/reyes/gcc4mbed/external/mbed-os/platform
/home/reyes/gcc4mbed/external/mbed-os/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768
Add “MBED_OS_ENABLE := 0” to Makefile.
Connect mbed to Host PC.
Right click “HelloWorld” and select Build Project.
Console window.
23:27:07 **** Incremental Build of configuration Debug for project HelloWorld ****
make all deploy GCC4MBED_TARGET=Debug
Compiling main.cpp
In file included from ../../external/mbed-os/mbed.h:97:0,
from main.cpp:4:
../../external/mbed-os/drivers/LocalFileSystem.h: In constructor 'mbed::LocalFileSystem::LocalFileSystem(const char*)':
../../external/mbed-os/drivers/LocalFileSystem.h:99:54: warning: 'mbed::FileSystemLike::FileSystemLike(const char*)' is deprecated: The mbed 2 filesystem classes have been superseeded by the FileSystem api, Replaced by FileSystem [since mbed-os-5.4] [-Wdeprecated-declarations]
LocalFileSystem(const char* n) : FileSystemLike(n) {
^
In file included from ../../external/mbed-os/drivers/LocalFileSystem.h:23:0,
from ../../external/mbed-os/mbed.h:97,
from main.cpp:4:
../../external/mbed-os/drivers/FileSystemLike.h:47:5: note: declared here
FileSystemLike(const char *name);
^~~~~~~~~~~~~~
Linking LPC1768/HelloWorld.elf
Extracting LPC1768/HelloWorld.bin
Extracting LPC1768/HelloWorld.hex
Extracting disassembly to LPC1768/HelloWorld.disasm
text data bss dec hex filename
6724 120 588 7432 1d08 LPC1768/HelloWorld.elf
Deploying to target.
23:27:08 Build Finished. 0 errors, 1 warnings. (took 1s.772ms)
Setting Build Targets
Right click the tab on the right side window, and click new.
Build target: -j4 all deploy GCC4MBED_TARGET=Debug
After setup it, you just click build button.