Code Monkey home page Code Monkey logo

mbed-os-example-blinky-baremetal's Introduction

Bare metal blinky Mbed OS example

This example shows how to achieve memory optimizations in Mbed OS. Starting with a blinky application, the example illustrates how to enable the bare metal profile and further memory optimizations.

You can build this project with all supported Mbed OS build tools. However, this example project specifically refers to the command-line interface tool Arm Mbed CLI.

  1. Install Mbed CLI.
  2. From the command-line, import the example: mbed import mbed-os-example-blinky-baremetal
  3. Change the current directory to where the project was imported.

Application functionality

The main() function toggles the state of a digital output connected to an LED on the board.

Building and running

  1. Connect a USB cable between the USB port on the target and the host computer.

  2. Run the following command to build the example project, program the microcontroller flash memory, and open a serial terminal:

    $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash --sterm
    

Your PC may take a few minutes to compile your code.

The binary is located at ./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky-baremetal.bin.

Alternatively, you can manually copy the binary to the target, which gets mounted on the host computer through USB.

Depending on the target, you can build the example project with the GCC_ARM, ARM or IAR toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target:

$ mbed compile -S

Expected output

The LED on your target turns on and off every 500 milliseconds, and the serial terminal shows an output similar to:

--- Terminal on /dev/tty.usbmodem21102 - 9600,8,N,1 ---
This is the bare metal blinky example running on Mbed OS 99.99.99.

Configuring the application

The bare metal profile

The bare metal profile is a configuration of Mbed OS that excludes the RTOS, as well as other features. We designed it specifically for ultraconstrained devices because it gives you more control over the system. For more details, please see the bare metal documentation

To build with the bare metal profile, the application configuration file must contain:

{
    "requires": ["bare-metal"]
}

Futher optimizations

Some of the configurations shown below are already set by default in targets/targets.json and platform/mbed_lib.json.

Linking with smaller C libraries

Both the ARM and GCC_ARM toolchains support optimized versions of their C standard libraries, microlib and newlib-nano. We recommend using them with the bare metal profile.

To build with the smaller C libraries, modify the application configuration file:

{
    "target_overrides": {
        "*": {
            "target.c_lib": "small"
        }
    }
}

The build system reverts to the standard C library if support for the small C library is not enabled for your target. You can find more information here.

Using Mbed minimal printf library

Mbed OS offers a smaller printf() alternative. The minimal printf library implements a subset of the v/s/f/printf function family, and you can disable floating points to further reduce code size.

To build with the minimal printf library and disable floating points printing, you need to modify the application configuration file:

{
    "target_overrides": {
        "*": {
            "target.printf_lib": "minimal-printf",
            "platform.minimal-printf-enable-floating-point": false
        }
    }
}

Further optimizations are possible. For more details, please see the minimal printf README.

Using a minimal console

If your application only needs unbuffered I/O operations, you can save additional memory by using a configuration of the platform library, which removes file handling functionality from the system I/O retarget code.

To build with the minimal console functionality, modify the application configuration file:

{
    "target_overrides": {
        "*": {
            "platform.stdio-minimal-console-only": true
        }
    }
}

Memory comparison

The below table shows the result for the blinky bare metal application compiled with the release profile on K64F for the GCC_ARM toolchain.

The baseline configuration used is the blinky bare metal application built with the standard C library.

Mbed OS release: mbed-os-6.0.0-alpha-2

Standard C lib Small C lib Minimal printf Minimal console RAM Flash
X 0 0
X -2,592 -28,581
X X -2,592 -29,918
X X X -2,592 -30,810

Troubleshooting

If you have problems, you can review the documentation for suggestions on what could be wrong and how to fix it.

Related links

License and contributions

The software is provided under the Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more information.

This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.

mbed-os-example-blinky-baremetal's People

Contributors

0xc0170 avatar adbridge avatar evedon avatar gpsimenos avatar harrisonmutai-arm avatar hugueskamba avatar kegilbert avatar ldong-arm avatar mbedmain avatar patater avatar rajkan01 avatar rwalton-arm avatar saheerb avatar studavekar avatar urutva avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mbed-os-example-blinky-baremetal's Issues

CMake build fails with `Use full profile as baremetal profile is not supported for this Mbed target`

Description of defect

#### STDERR ####

#### End of STDOUT/STDERR ####

[EXAMPLES]> WARNING  Test for mbed-os-example-blinky will not be generated.
[EXAMPLES]> INFO     In folder 'mbed-os-example-blinky-baremetal'
[EXAMPLES]> INFO     Compiling mbed-os-example-blinky-baremetal ARCH_PRO GCC_ARM
[EXAMPLES]> INFO     Executing command 'mbed-tools compile -t GCC_ARM -m ARCH_PRO -c'...

#### STDOUT ####
Configuring project and generating build system...
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- The ASM compiler identification is GNU
-- Found assembler: /usr/local/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /usr/bin/python3.7 (found version "3.7.4") found components: Interpreter 
-- Checking for Python package prettytable -- found
-- Checking for Python package future -- found
-- Checking for Python package jinja2 -- found
-- Checking for Python package intelhex -- found
-- Configuring incomplete, errors occurred!
See also "/builds/workspace/mbed-os-ci_cmake-example-GCC_ARM-dev@5/examples/mbed-os-example-blinky-baremetal/cmake_build/ARCH_PRO/develop/GCC_ARM/CMakeFiles/CMakeOutput.log".
See also "/builds/workspace/mbed-os-ci_cmake-example-GCC_ARM-dev@5/examples/mbed-os-example-blinky-baremetal/cmake_build/ARCH_PRO/develop/GCC_ARM/CMakeFiles/CMakeError.log".

#### STDERR ####
CMake Error at mbed-os/CMakeLists.txt:233 (message):
  Use full profile as baremetal profile is not supported for this Mbed target
Call Stack (most recent call first):
  mbed-os/CMakeLists.txt:250 (mbed_validate_application_profile)
  CMakeLists.txt:30 (mbed_set_post_build)


ERROR: CMake invocation failed!

Target(s) affected by this defect ?

ARCH_PRO
LPC1768

Toolchain(s) (name and version) displaying this defect ?

GCC_ARM

What version of Mbed-os are you using (tag or sha) ?

9bbc8c914c7e

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

Mbed CLI 2

How is this defect reproduced ?

mbed-tools compile -t GCC_ARM -m ARCH_PRO -c

Build failure when building for LPC11U35_401 with ARMC6

Building the example for LPC11U35_401 with toolchain ARMC6 results in the following build error:

[Warning] @0,0: L3912W: Option 'legacyalign' is deprecated.
[Warning] @0,0: L6320W: Ignoring --keep command. Cannot find argument 'os_cb_sections'.
[Error] @0,0: L6218E: Undefined symbol _scanf_mbtowc (referred from ../BUILD/LPC11U35_401/ARMC6/mbed-os/platform/ATCmdParser.o).
[Error] @0,0: L6218E: Undefined symbol us_ticker_irq_handler (referred from ../BUILD/LPC11U35_401/ARMC6/mbed-os/targets/TARGET_NXP/TARGET_LPC11UXX/us_ticker.o).
Warning: L3912W: Option 'legacyalign' is deprecated.
Warning: L6320W: Ignoring --keep command. Cannot find argument 'os_cb_sections'.
Error: L6218E: Undefined symbol _scanf_mbtowc (referred from ../BUILD/LPC11U35_401/ARMC6/mbed-os/platform/ATCmdParser.o).
Error: L6218E: Undefined symbol us_ticker_irq_handler (referred from ../BUILD/LPC11U35_401/ARMC6/mbed-os/targets/TARGET_NXP/TARGET_LPC11UXX/us_ticker.o).
Finished: 0 information, 2 warning and 2 error messages.
[ERROR] Warning: L3912W: Option 'legacyalign' is deprecated.
Warning: L6320W: Ignoring --keep command. Cannot find argument 'os_cb_sections'.
Error: L6218E: Undefined symbol _scanf_mbtowc (referred from ../BUILD/LPC11U35_401/ARMC6/mbed-os/platform/ATCmdParser.o).
Error: L6218E: Undefined symbol us_ticker_irq_handler (referred from ../BUILD/LPC11U35_401/ARMC6/mbed-os/targets/TARGET_NXP/TARGET_LPC11UXX/us_ticker.o).
Finished: 0 information, 2 warning and 2 error messages.

[mbed] ERROR: "/usr/bin/python" returned error.
       Code: 1
       Path: "/home/roneld01/work/mbed-os-example-blinky-baremetal/mbed-os"
       Command: "/usr/bin/python -u /home/roneld01/work/mbed-os-example-blinky-baremetal/mbed-os/tools/make.py -t ARMC6 -m LPC11U35_401 --source .. --build ../BUILD/LPC11U35_401/ARMC6"

I believe the Undefined symbol _scanf_mbtowc error has been fixed in ARMmbed/mbed-os#10704 and the mbed-os.lib requires updating to latest versoin, once next Mbed OS release is published.
I believe error Undefined symbol us_ticker_irq_handler is because the targets.json doesn't have device US_TICKER for LPC11U35_401 . To resolve this, either add US_TICKER DEVICE in ``targets.jsonor add#if DEVICE_USTICKER` in the targets' us_ticker.c file

Note that same errors happen with ARM toolchain which is mentioned as supported toolchain

This was reported in the forum

Crashes on F030 Nucleo board

Description of defect

It crashes when running on F030 board

++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: "OS timer not available - check MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER" && >false
Location: 0x8000DFB
File: ../mbed-os/platform/source/mbed_os_timer.cpp+55
Error Value: 0x0

Target(s) affected by this defect ?

Nucleo F030

Toolchain(s) (name and version) displaying this defect ?

GCC

What version of Mbed-os are you using (tag or sha) ?

mbed-os-5.15.3-rc1

Build failure when building for Renesas GR-PEACH or GR-LYCHEE target

Step to reproduce

$ mbed import mbed-os-example-blinky-baremetal
$ cd mbed-os-example-blinky-baremetal
$ mbed compile -m gr_lychee -t gcc_arm

I got link error below (missing mbed_get_a9_tick_irqn function for non RTOS build) :

Link: mbed-os-example-blinky-baremetal
BUILD/GR_LYCHEE/GCC_ARM/mbed-os/platform/source/SysTimer.o: In function `mbed::internal::SysTimer<1000ul, true>::_set_irq_pending()':
/Users/toywat01/test/renesas/mbed-os-example-blinky-baremetal/./mbed-os/platform/source/SysTimer.cpp:282: undefined reference to `mbed_get_a9_tick_irqn'
BUILD/GR_LYCHEE/GCC_ARM/mbed-os/platform/source/SysTimer.o: In function `mbed::internal::SysTimer<1000ul, true>::_clear_irq_pending()':
/Users/toywat01/test/renesas/mbed-os-example-blinky-baremetal/./mbed-os/platform/source/SysTimer.cpp:298: undefined reference to `mbed_get_a9_tick_irqn'
collect2: error: ld returned 1 exit status
[ERROR] BUILD/GR_LYCHEE/GCC_ARM/mbed-os/platform/source/SysTimer.o: In function `mbed::internal::SysTimer<1000ul, true>::_set_irq_pending()':
/Users/toywat01/test/renesas/mbed-os-example-blinky-baremetal/./mbed-os/platform/source/SysTimer.cpp:282: undefined reference to `mbed_get_a9_tick_irqn'
BUILD/GR_LYCHEE/GCC_ARM/mbed-os/platform/source/SysTimer.o: In function `mbed::internal::SysTimer<1000ul, true>::_clear_irq_pending()':
/Users/toywat01/test/renesas/mbed-os-example-blinky-baremetal/./mbed-os/platform/source/SysTimer.cpp:298: undefined reference to `mbed_get_a9_tick_irqn'
collect2: error: ld returned 1 exit status

[mbed] ERROR: "/Users/toywat01/mbed-venv/bin/python" returned error.
       Code: 1
       Path: "/Users/toywat01/test/renesas/mbed-os-example-blinky-baremetal"
       Command: "/Users/toywat01/mbed-venv/bin/python -u /Users/toywat01/test/renesas/mbed-os-example-blinky-baremetal/mbed-os/tools/make.py -t gcc_arm -m gr_lychee --source . --build ./BUILD/GR_LYCHEE/GCC_ARM"
       Tip: You could retry the last command with "-v" flag for verbose output
---

Mbed OS version

mbed-os-example-blinky-baremetal (#e196549b6ddc)
`- mbed-os (#b6e5a0a8afa3, tags: mbed-os-5.14.0, mbed-os-5.14.0-rc3)

@ARMmbed/team-renesas

Issue with using example on PSOC 63 - CyReservedRegionBlockDevice.h

Description of defect

When compiling the mbed-os-example-blinky-baremetal i get the following error, indicating that something is not correctly setup for using the bare metal example on psoc 63. I did not modify anything to the example, just followed the [README.md] on mbed-os-5.15.0
[Error] CyReservedRegionBlockDevice.h@35,62: expected class-name before '{' token
[Error] CyReservedRegionBlockDevice.h@43,44: expected ')' before '' token
[Error] CyReservedRegionBlockDevice.h@77,42: 'mbed::bd_addr_t' has not been declared
[Error] CyReservedRegionBlockDevice.h@77,64: 'mbed::bd_size_t' has not been declared
[Error] CyReservedRegionBlockDevice.h@89,51: 'mbed::bd_addr_t' has not been declared
[Error] CyReservedRegionBlockDevice.h@89,73: 'mbed::bd_size_t' has not been declared
[Error] CyReservedRegionBlockDevice.h@100,29: 'mbed::bd_addr_t' has not been declared
[Error] CyReservedRegionBlockDevice.h@100,51: 'mbed::bd_size_t' has not been declared
[Error] CyReservedRegionBlockDevice.h@107,19: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.h@115,19: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.h@123,19: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.h@132,19: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.h@152,19: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.h@169,43: 'mbed::bd_addr_t' has not been declared
[Error] CyReservedRegionBlockDevice.h@169,65: 'mbed::bd_size_t' has not been declared
[Error] CyReservedRegionBlockDevice.h@176,11: 'bd_addr_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.h@179,5: 'BlockDevice' does not name a type
[Error] CyReservedRegionBlockDevice.h@180,11: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.h@181,11: 'bd_addr_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.h@50,17: 'virtual int CyReservedRegionBlockDevice::init()' marked 'override', but does not override
[Error] CyReservedRegionBlockDevice.h@57,17: 'virtual int CyReservedRegionBlockDevice::deinit()' marked 'override', but does not override
[Error] CyReservedRegionBlockDevice.h@64,13: 'virtual CyReservedRegionBlockDevice::~CyReservedRegionBlockDevice()' marked 'override', but does not override
[Error] CyReservedRegionBlockDevice.h@77,17: 'virtual int CyReservedRegionBlockDevice::read(void
, int, int)' marked 'override', but does not override
[Error] CyReservedRegionBlockDevice.h@89,17: 'virtual int CyReservedRegionBlockDevice::program(const void*, int, int)' marked 'override', but does not override
[Error] CyReservedRegionBlockDevice.h@100,17: 'virtual int CyReservedRegionBlockDevice::erase(int, int)' marked 'override', but does not override
[Error] CyReservedRegionBlockDevice.h@144,17: 'virtual int CyReservedRegionBlockDevice::get_erase_value() const' marked 'override', but does not override
[Error] CyReservedRegionBlockDevice.h@159,25: 'virtual const char* CyReservedRegionBlockDevice::get_type() const' marked 'override', but does not override
[Error] CyReservedRegionBlockDevice.cpp@28,57: expected constructor, destructor, or type conversion before '(' token
[Error] CyReservedRegionBlockDevice.cpp@37,18: '_underlying_bd' was not declared in this scope; did you mean '__underlying_type'?
[Error] CyReservedRegionBlockDevice.cpp@38,19: 'BD_ERROR_OK' was not declared in this scope; did you mean 'MBED_ERROR_H'?
[Error] CyReservedRegionBlockDevice.cpp@41,13: '_reserved_region_size' was not declared in this scope
[Error] CyReservedRegionBlockDevice.cpp@41,37: 'get_erase_size' was not declared in this scope; did you mean 'get_erase_value'?
[Error] CyReservedRegionBlockDevice.cpp@42,13: '_reserved_region_end' was not declared in this scope
[Error] CyReservedRegionBlockDevice.cpp@44,13: '_reserved_region_end' was not declared in this scope
[Error] CyReservedRegionBlockDevice.cpp@52,18: '_underlying_bd' was not declared in this scope; did you mean '__underlying_type'?
[Error] CyReservedRegionBlockDevice.cpp@53,19: 'BD_ERROR_OK' was not declared in this scope; did you mean 'MBED_ERROR_H'?
[Error] CyReservedRegionBlockDevice.cpp@54,9: '_reserved_region_end' was not declared in this scope
[Error] CyReservedRegionBlockDevice.cpp@59,59: 'mbed::bd_addr_t' has not been declared
[Error] CyReservedRegionBlockDevice.cpp@59,81: 'mbed::bd_size_t' has not been declared
[Error] CyReservedRegionBlockDevice.cpp@61,12: '_underlying_bd' was not declared in this scope; did you mean '__underlying_type'?
[Error] CyReservedRegionBlockDevice.cpp@61,48: '_reserved_region_end' was not declared in this scope
[Error] CyReservedRegionBlockDevice.cpp@64,68: 'mbed::bd_addr_t' has not been declared
[Error] CyReservedRegionBlockDevice.cpp@64,90: 'mbed::bd_size_t' has not been declared
[Error] CyReservedRegionBlockDevice.cpp@66,12: '_underlying_bd' was not declared in this scope; did you mean '__underlying_type'?
[Error] CyReservedRegionBlockDevice.cpp@66,51: '_reserved_region_end' was not declared in this scope
[Error] CyReservedRegionBlockDevice.cpp@69,5: 'int CyReservedRegionBlockDevice::erase' is not a static data member of 'class CyReservedRegionBlockDevice'
[Error] CyReservedRegionBlockDevice.cpp@69,46: 'bd_addr_t' is not a member of 'mbed'
[Error] CyReservedRegionBlockDevice.cpp@69,68: 'bd_size_t' is not a member of 'mbed'
[Error] CyReservedRegionBlockDevice.cpp@69,82: expression list treated as compound expression in initializer [-fpermissive]
[Error] CyReservedRegionBlockDevice.cpp@74,7: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.cpp@79,7: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.cpp@84,7: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.cpp@89,7: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.cpp@96,12: '_underlying_bd' was not declared in this scope; did you mean '__underlying_type'?
[Error] CyReservedRegionBlockDevice.cpp@99,7: 'bd_size_t' in namespace 'mbed' does not name a type
[Error] CyReservedRegionBlockDevice.cpp@106,12: '_underlying_bd' was not declared in this scope; did you mean '__underlying_type'?
[Error] CyReservedRegionBlockDevice.cpp@109,68: 'mbed::bd_addr_t' has not been declared
[Error] CyReservedRegionBlockDevice.cpp@109,90: 'mbed::bd_size_t' has not been declared
[Error] CyReservedRegionBlockDevice.cpp@111,23: '_reserved_region_end' was not declared in this scope
[Error] CyReservedRegionBlockDevice.cpp@111,54: 'get_read_size' was not declared in this scope
[Error] CyReservedRegionBlockDevice.cpp@112,16: 'BD_ERROR_DEVICE_ERROR' was not declared in this scope; did you mean 'MBED_ERROR_DEVICE_BUSY'?
[Error] CyReservedRegionBlockDevice.cpp@115,12: '_underlying_bd' was not declared in this scope; did you mean '__underlying_type'?
[Error] CyReservedRegionBlockDevice.cpp@118,7: 'bd_addr_t' in namespace 'mbed' does not name a type
[ERROR] In file included from ./mbed-os/platform/include/platform/platform.h:31,
from ./mbed-os/mbed.h:40,
from .\mbed-os\targets\TARGET_Cypress\TARGET_PSOC6\reserved-region-bd\CyReservedRegionBlockDevice.h:29,
from .\mbed-os\targets\TARGET_Cypress\TARGET_PSOC6\reserved-region-bd\CyReservedRegionBlockDevice.cpp:26:

Target(s) affected by this defect ?

CY8CKIT-062-BLE

Toolchain(s) (name and version) displaying this defect ?

GCC_ARM 11.3.1.67

What version of Mbed-os are you using (tag or sha) ?

mbed-os-6.17.0 bare metal

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

mbed cli 1.8.3

How is this defect reproduced ?

Downloading the bare metal example using
$ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash --sterm

and compiling for the target:
$ mbed compile -m CY8CKIT_062_BLE -t GCC_ARM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.