Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBC MicroBit configuration #709

Closed
tiferrei opened this issue Jul 1, 2016 · 64 comments
Closed

BBC MicroBit configuration #709

tiferrei opened this issue Jul 1, 2016 · 64 comments
Milestone

Comments

@tiferrei
Copy link

tiferrei commented Jul 1, 2016

Example


Configuration

Operating system: macOS Sierra (10.12)

PlatformIO Version (platformio --version): 2.11.0

Hello there, I was trying to use platformIO with the microbit board (bbcmicrobit), however, even the simplest program fails to compile because it misses the main file. I have also tried to add the main source code of the framework to the lib, but as it is compiled by yotta the structure is not the same, has anyone used the microbit with PlatformIO before?

If problems with PlatformIO Build System:

The content of platformio.ini:

#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#

# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.

# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload

[env:bbcmicrobit]
platform = nordicnrf51
framework = mbed
board = bbcmicrobit

Source file to reproduce issue:

#include "MicroBit.h"

MicroBit uBit;

void onData(MicroBitEvent)
{
  ManagedString s = uBit.radio.datagram.recv();
  ManagedString t(uBit.thermometer.getTemperature());

  if (s == "1")
  uBit.display.print("A");

  if (s == "2")
  uBit.display.print("B");

  if (s == "3")
  uBit.display.print("C");

  if (s == "4")
  uBit.display.print("D");

  if (s == "5")
  uBit.display.print("E");

  if (s == "7")
  uBit.display.scroll(t);

}

void onButton (MicroBitEvent e) {
   if (e.source == MICROBIT_ID_BUTTON_A && e.value == MICROBIT_BUTTON_EVT_CLICK)
   uBit.radio.datagram.send("6");
}

int main()
{
  uBit.init();

  uBit.radio.setGroup(126);
  uBit.radio.enable();

  uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_EVT_ANY, onButton);
  uBit.messageBus.listen(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, onData);

  while (1)
    uBit.sleep(10);
}

Additional info

Run output:

platformio run
[Fri Jul  1 15:40:25 2016] Processing bbcmicrobit (platform: nordicnrf51, board: bbcmicrobit, framework: mbed)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
arm-none-eabi-g++ -o .pioenvs/bbcmicrobit/core/MicroBit.o -c -std=gnu++98 -fno-rtti -fdata-sections -ffunction-sections -Wno-unused-parameter -fno-exceptions -Wextra -fno-delete-null-pointer-checks -fmessage-length=0 -mthumb -Wno-missing-field-initializers -c -fno-builtin -O2 -fomit-frame-pointer -Wall -MMD -mcpu=cortex-m0 -DTARGET_MCU_NRF51_16K_S110 -D__CORTEX_M0 -DTARGET_MCU_NRF51_16K -DTOOLCHAIN_GCC -DTARGET_MCU_NRF51822 -DTARGET_LIKE_MBED -DTARGET_CORTEX_M -DTARGET_NRF_LFCLK_RC -DMBED_BUILD_TIMESTAMP=1464362417.38 -DTARGET_NRF51822 -DARM_MATH_CM0 -DTARGET_NRF51_MICROBIT -DTOOLCHAIN_GCC_ARM -DTARGET_NORDIC -DTARGET_MCU_NRF51 -DTARGET_MCU_NORDIC_16K -DTARGET_M0 -DNRF51 -D__MBED__=1 -DTARGET_LIKE_CORTEX_M0 -DPLATFORMIO=021100 -I.pioenvs/bbcmicrobit/FrameworkMbedInc248832578 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-213564679 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-250686161 -I.pioenvs/bbcmicrobit/FrameworkMbedInc2103166472 -I.pioenvs/bbcmicrobit/FrameworkMbedInc636649457 -I.pioenvs/bbcmicrobit/FrameworkMbedInc24945669 -I.pioenvs/bbcmicrobit/FrameworkMbedInc840111810 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-1439381592 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-715659618 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-1703762731 -I.pioenvs/bbcmicrobit/FrameworkMbedInc615864670 -I.pioenvs/bbcmicrobit/FrameworkMbedInc555830279 -I.pioenvs/bbcmicrobit/FrameworkMbedInc2043334312 -I.pioenvs/bbcmicrobit/FrameworkMbedInc226820145 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-464402851 -I.pioenvs/bbcmicrobit/FrameworkMbedInc1031615723 -I.pioenvs/bbcmicrobit/FrameworkMbedInc857456459 -I.pioenvs/bbcmicrobit/platform -I.pioenvs/bbcmicrobit/core -I.pioenvs/bbcmicrobit/drivers -I.pioenvs/bbcmicrobit/types -I.pioenvs/bbcmicrobit/bluetooth .pioenvs/bbcmicrobit/core/MicroBit.cpp
arm-none-eabi-g++ -o .pioenvs/bbcmicrobit/core/MicroBitDevice.o -c -std=gnu++98 -fno-rtti -fdata-sections -ffunction-sections -Wno-unused-parameter -fno-exceptions -Wextra -fno-delete-null-pointer-checks -fmessage-length=0 -mthumb -Wno-missing-field-initializers -c -fno-builtin -O2 -fomit-frame-pointer -Wall -MMD -mcpu=cortex-m0 -DTARGET_MCU_NRF51_16K_S110 -D__CORTEX_M0 -DTARGET_MCU_NRF51_16K -DTOOLCHAIN_GCC -DTARGET_MCU_NRF51822 -DTARGET_LIKE_MBED -DTARGET_CORTEX_M -DTARGET_NRF_LFCLK_RC -DMBED_BUILD_TIMESTAMP=1464362417.38 -DTARGET_NRF51822 -DARM_MATH_CM0 -DTARGET_NRF51_MICROBIT -DTOOLCHAIN_GCC_ARM -DTARGET_NORDIC -DTARGET_MCU_NRF51 -DTARGET_MCU_NORDIC_16K -DTARGET_M0 -DNRF51 -D__MBED__=1 -DTARGET_LIKE_CORTEX_M0 -DPLATFORMIO=021100 -I.pioenvs/bbcmicrobit/FrameworkMbedInc248832578 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-213564679 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-250686161 -I.pioenvs/bbcmicrobit/FrameworkMbedInc2103166472 -I.pioenvs/bbcmicrobit/FrameworkMbedInc636649457 -I.pioenvs/bbcmicrobit/FrameworkMbedInc24945669 -I.pioenvs/bbcmicrobit/FrameworkMbedInc840111810 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-1439381592 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-715659618 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-1703762731 -I.pioenvs/bbcmicrobit/FrameworkMbedInc615864670 -I.pioenvs/bbcmicrobit/FrameworkMbedInc555830279 -I.pioenvs/bbcmicrobit/FrameworkMbedInc2043334312 -I.pioenvs/bbcmicrobit/FrameworkMbedInc226820145 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-464402851 -I.pioenvs/bbcmicrobit/FrameworkMbedInc1031615723 -I.pioenvs/bbcmicrobit/FrameworkMbedInc857456459 -I.pioenvs/bbcmicrobit/platform -I.pioenvs/bbcmicrobit/core -I.pioenvs/bbcmicrobit/drivers -I.pioenvs/bbcmicrobit/types -I.pioenvs/bbcmicrobit/bluetooth .pioenvs/bbcmicrobit/core/MicroBitDevice.cpp
arm-none-eabi-g++ -o .pioenvs/bbcmicrobit/core/MicroBitFiber.o -c -std=gnu++98 -fno-rtti -fdata-sections -ffunction-sections -Wno-unused-parameter -fno-exceptions -Wextra -fno-delete-null-pointer-checks -fmessage-length=0 -mthumb -Wno-missing-field-initializers -c -fno-builtin -O2 -fomit-frame-pointer -Wall -MMD -mcpu=cortex-m0 -DTARGET_MCU_NRF51_16K_S110 -D__CORTEX_M0 -DTARGET_MCU_NRF51_16K -DTOOLCHAIN_GCC -DTARGET_MCU_NRF51822 -DTARGET_LIKE_MBED -DTARGET_CORTEX_M -DTARGET_NRF_LFCLK_RC -DMBED_BUILD_TIMESTAMP=1464362417.38 -DTARGET_NRF51822 -DARM_MATH_CM0 -DTARGET_NRF51_MICROBIT -DTOOLCHAIN_GCC_ARM -DTARGET_NORDIC -DTARGET_MCU_NRF51 -DTARGET_MCU_NORDIC_16K -DTARGET_M0 -DNRF51 -D__MBED__=1 -DTARGET_LIKE_CORTEX_M0 -DPLATFORMIO=021100 -I.pioenvs/bbcmicrobit/FrameworkMbedInc248832578 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-213564679 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-250686161 -I.pioenvs/bbcmicrobit/FrameworkMbedInc2103166472 -I.pioenvs/bbcmicrobit/FrameworkMbedInc636649457 -I.pioenvs/bbcmicrobit/FrameworkMbedInc24945669 -I.pioenvs/bbcmicrobit/FrameworkMbedInc840111810 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-1439381592 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-715659618 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-1703762731 -I.pioenvs/bbcmicrobit/FrameworkMbedInc615864670 -I.pioenvs/bbcmicrobit/FrameworkMbedInc555830279 -I.pioenvs/bbcmicrobit/FrameworkMbedInc2043334312 -I.pioenvs/bbcmicrobit/FrameworkMbedInc226820145 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-464402851 -I.pioenvs/bbcmicrobit/FrameworkMbedInc1031615723 -I.pioenvs/bbcmicrobit/FrameworkMbedInc857456459 -I.pioenvs/bbcmicrobit/platform -I.pioenvs/bbcmicrobit/core -I.pioenvs/bbcmicrobit/drivers -I.pioenvs/bbcmicrobit/types -I.pioenvs/bbcmicrobit/bluetooth .pioenvs/bbcmicrobit/core/MicroBitFiber.cpp
arm-none-eabi-g++ -o .pioenvs/bbcmicrobit/core/MicroBitFont.o -c -std=gnu++98 -fno-rtti -fdata-sections -ffunction-sections -Wno-unused-parameter -fno-exceptions -Wextra -fno-delete-null-pointer-checks -fmessage-length=0 -mthumb -Wno-missing-field-initializers -c -fno-builtin -O2 -fomit-frame-pointer -Wall -MMD -mcpu=cortex-m0 -DTARGET_MCU_NRF51_16K_S110 -D__CORTEX_M0 -DTARGET_MCU_NRF51_16K -DTOOLCHAIN_GCC -DTARGET_MCU_NRF51822 -DTARGET_LIKE_MBED -DTARGET_CORTEX_M -DTARGET_NRF_LFCLK_RC -DMBED_BUILD_TIMESTAMP=1464362417.38 -DTARGET_NRF51822 -DARM_MATH_CM0 -DTARGET_NRF51_MICROBIT -DTOOLCHAIN_GCC_ARM -DTARGET_NORDIC -DTARGET_MCU_NRF51 -DTARGET_MCU_NORDIC_16K -DTARGET_M0 -DNRF51 -D__MBED__=1 -DTARGET_LIKE_CORTEX_M0 -DPLATFORMIO=021100 -I.pioenvs/bbcmicrobit/FrameworkMbedInc248832578 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-213564679 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-250686161 -I.pioenvs/bbcmicrobit/FrameworkMbedInc2103166472 -I.pioenvs/bbcmicrobit/FrameworkMbedInc636649457 -I.pioenvs/bbcmicrobit/FrameworkMbedInc24945669 -I.pioenvs/bbcmicrobit/FrameworkMbedInc840111810 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-1439381592 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-715659618 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-1703762731 -I.pioenvs/bbcmicrobit/FrameworkMbedInc615864670 -I.pioenvs/bbcmicrobit/FrameworkMbedInc555830279 -I.pioenvs/bbcmicrobit/FrameworkMbedInc2043334312 -I.pioenvs/bbcmicrobit/FrameworkMbedInc226820145 -I.pioenvs/bbcmicrobit/FrameworkMbedInc-464402851 -I.pioenvs/bbcmicrobit/FrameworkMbedInc1031615723 -I.pioenvs/bbcmicrobit/FrameworkMbedInc857456459 -I.pioenvs/bbcmicrobit/platform -I.pioenvs/bbcmicrobit/core -I.pioenvs/bbcmicrobit/drivers -I.pioenvs/bbcmicrobit/types -I.pioenvs/bbcmicrobit/bluetooth .pioenvs/bbcmicrobit/core/MicroBitFont.cpp
.pioenvs/bbcmicrobit/core/MicroBitDevice.cpp:48:21: fatal error: nrf_soc.h: No such file or directory
#include "nrf_soc.h"
^
compilation terminated.
scons: *** [.pioenvs/bbcmicrobit/core/MicroBitDevice.o] Error 1
.pioenvs/bbcmicrobit/core/MicroBit.cpp:41:21: fatal error: nrf_soc.h: No such file or directory
#include "nrf_soc.h"
^
compilation terminated.
scons: *** [.pioenvs/bbcmicrobit/core/MicroBit.o] Error 1
============================================================================ [ ERROR ] Took 4.52 seconds ============================================================================
@palfrey
Copy link

palfrey commented Jul 22, 2016

I've just been digging around a bit, and this is a lot harder than it looks. Despite the addition of the Micro:bit to the supported boards list, it won't work with the out-of-the-box mbed. https://github.com/lancaster-university/microbit-dal and https://github.com/lancaster-university/microbit have the main sources to all the bits needed to properly support it, and that's not part of the main mbed github yet, so PlatformIO isn't picking that up.

It almost might sense for this to be an entirely separate framework, but I can't seem to find any nice docs on building a new one...

@ivankravets ivankravets added this to the 3.0.0 milestone Jul 22, 2016
@ivankravets
Copy link
Member

@palfrey please wait for the first PlatformIO 3.0 beta. It will have support for mbed modules.

@palfrey
Copy link

palfrey commented Jul 22, 2016

@ivankravets: Awesome! Is there any particular branch or issue I should be watching to keep up with that or be able to test development versions?

@ivankravets
Copy link
Member

I've jus taken a look at https://github.com/lancaster-university/microbit and I don't have good news. It depends on https://github.com/lancaster-university/microbit-dal that is written for CMake and hardcoded for yota https://github.com/lancaster-university/microbit-dal/blob/master/source/CMakeLists.txt

Nevertheless, we can try together to make it working. PlatformIO 3.0 has a new refactored powerful cross platform build system that could be tuned "on-the-fly". No need to write custom frameworks (PlatformIO 2.0) or etc.

If someone is ready to play with it, I can explain.

@palfrey
Copy link

palfrey commented Jul 23, 2016

So, I decided to have a quick bit of hacking around this morning, and have come up with https://github.com/palfrey/microbit-blink. It's meant to be a "hello world" app for Micro:bit using PlatformIO that was basically me trying to establish just how much deviation there was in the codebase from core mbed, and the short answer is "lots". Lancaster have all sorts of their own very specific versions of the various libraries that are needed, and it was kinda horrible. OTOH, the repository does compile a file that doesn't whinge for the Micro:bit, but it doesn't seem to do anything useful yet :( I'm heading out to a social event now, but would be interested in exploring this further later this week...

Yes, I'm aware it does things in a really awful way by recompiling everything as it's own source code, not as libraries. It's intended mostly as a "can this be done at all" experiment before then getting into the depths of doing this with the proper PlatformIO way.

@ivankravets
Copy link
Member

@palfrey do you mean that our version of ARM mbed framework from https://github.com/mbedmicro/mbed is not compatible with https://github.com/lancaster-university/microbit ?

@ivankravets ivankravets removed this from the 3.0.0 milestone Jul 24, 2016
@palfrey
Copy link

palfrey commented Jul 24, 2016

Possibly not. I've found https://github.com/lancaster-university/mbed-classic as well, and I'm not sure how that fits in with https://github.com/mbedmicro/mbed. TBH, the entire set of repositories seems like someone's hacked something together that they know how to make work, but haven't shared with the rest of us yet...

Other bits of progress made: Tried using the debugging guide at https://docs.mbed.com/docs/debugging-on-mbed/en/latest/Debugging/debugging_microbit/ and got not very far because it pretty much immediately jumps to 0xfffffffe and I'm not entirely sure why. OTOH, the HEX file I've got at the moment gets the following info out of srec_info

(ENV)palfrey@weizen:[~/src/microbit-blink] srec_info .pioenvs/bbcmicrobit/firmware.hex -intel
Format: Intel Hexadecimal (MCS-86)
Execution Start Address: 0002A12D
Data:   018000 - 02EA23

Note the single Data line, and the complete lack of anything at the beginning of memory. Running similar commands on known good programs (a "hello world" from elsewhere I've got for example) gets me two Data blocks, one starting at 000000 and that's also the same for the HEX files in the debug guide, which makes me think there's something missing there. Bootloader possibly?

@palfrey
Copy link

palfrey commented Jul 24, 2016

Hah! Some success. So having been digging around in https://github.com/lancaster-university/microbit-targets and especially https://github.com/lancaster-university/microbit-targets/blob/master/bbc-microbit-classic-gcc-nosd/ld/NRF51822.ld which is the "no softdevice" version of the code, I edited my local ~/.platformio/packages/framework-mbed/variant/NRF51_MICROBIT/mbed/TARGET_NRF51_MICROBIT/TOOLCHAIN_GCC_ARM/NRF51822.ld and changed the Flash origin to "0x00000000". This, in combination with "-DMICROBIT_DBG=1 -DMICROBIT_HEAP_DBG=1" in my build_flags got me the first indication I actually had something half-functional in the form of some heap debug on the serial port. Still not got working leds yet, but at least it's running my code :)

@ivankravets
Copy link
Member

This is not a big problem. We can specify custom LD script per board which will be used instead ARM mbed.

When you have work "blink" project, I'll explain how to use PlatformIO 3.0 and custom build script for the specific library.

@palfrey
Copy link

palfrey commented Jul 24, 2016

After quite some struggling, I have a working "blink". Checkout https://github.com/palfrey/microbit-blink and do the following:

  1. Edit ~/.platformio/packages/framework-mbed/variant/NRF51_MICROBIT/mbed/TARGET_NRF51_MICROBIT/TOOLCHAIN_GCC_ARM/NRF51822.ld and change the Flash origin to "0x0001C000"
  2. Run "platformio run"
  3. Make sure you've got SRecord installed (brew install srecord works on a Mac)
  4. srec_cat lib/microbit-targets/bbc-microbit-classic-gcc-s130/bootloader/BLE_BOOTLOADER_RESERVED.hex -intel lib/microbit-targets/bbc-microbit-classic-gcc-s130/softdevice/s130_nrf51_1.0.0_softdevice.hex -intel .pioenvs/bbcmicrobit/firmware.hex -intel -o microbit-combined.hex -intel --line-length=44
  5. Copy microbit-combined.hex to the root of your Microbit

There's possibly ways to do this without SRecord, and also this gives you the all-singing all-dancing firmware with BLE support, but rather low spare RAM, so other options are wanted in the future, but this at least gets us somewhere.

@ivankravets
Copy link
Member

ivankravets commented Jul 24, 2016

Woooow! Great result! 👍

I see that you "linked" libraries to the source code and used an extra script. How can we simplify it?

  1. Please install in virtual environment PlatformIO 3.0 (scroll down to the installation section)
  2. PlatformIO 3.0 understands ARM mbed "module.json" manifest. It means that "extraIncludes" should be handled automatically.
  3. You can extend PlatformIO Library Build System with custom extra script per each library 😊 In this case, need to create library.json file in the root of library and specify build field. This manifest could be useful for you to have custom build flags per library or etc.
  4. I'm working on the new library manager. It will allow installation of the library directly from external resource (VCS, Github, etc). I hope that I'll push initial support tomorrow.

P.S: To see verbose build output in PlatformIO 3.0, please use -v.
P.S.S: We can have custom library.json for lancaster-university's library and keep it in our library mirror repository. Only the manifest file. See examples, https://github.com/platformio/platformio-libmirror/tree/master/configs/mbed

@palfrey
Copy link

palfrey commented Jul 24, 2016

So, I've just done step 1, but I'm running into issues with bits of the library support. Someone else has already made a library.json for the core microbit bits (http://platformio.org/lib/show/361/Microbit) which looks perfectly good to me, but as far as I can tell doesn't pull in any of the headers or source from the Microbit git repository referenced there. Given there's a perfectly good "module.json" in that folder with "extraIncludes" set, this is particularly confusing. Any thoughts as to why this one doesn't work?

@ivankravets
Copy link
Member

@palfrey I've just pushed PR to that repo rossng/microbit#1

You can copy my changes to your local library.json while manifest's author has not merged yet.

@palfrey
Copy link

palfrey commented Jul 24, 2016

Still no luck. https://github.com/palfrey/microbit-blink/tree/platform-3.0 has my WIP v3 version. I've copied your library.json changes into ~/.platformio/lib/Microbit_ID361 (and also https://raw.githubusercontent.com/rossng/microbit/master/module.json just for good luck) and no luck. The build flags specified are not turning up in the build of main.cpp, and so it can't find MicroBit.h

@ivankravets
Copy link
Member

@palfrey This is a bug... I'll fix it tomorrow and reply here.

Thanks and good night! 😊

@ivankravets
Copy link
Member

@palfrey I have some progress on it. I'll push modified PlatformIO later. All builds success without any hacks. The only one change is replacement with "twi_master_init_and_clear()", "twi_master_init_and_clear(NRF_TWI1)".

Nevertheless, I have problem with linker. Do you have any ideas?

arm-none-eabi-g++ -o .pioenvs/bbcmicrobit/firmware.elf -Wl,--gc-sections -Wl,--wrap,main -mcpu=cortex-m0 -mthumb --specs=nano.specs -Wl,-T"/Users/ikravets/.platformio/packages/framework-mbed/variant/NRF51_MICROBIT/mbed/TARGET_NRF51_MICROBIT/TOOLCHAIN_GCC_ARM/NRF51822.ld" .pioenvs/bbcmicrobit/src/main.o -L/Users/ikravets/.platformio/platforms/nordicnrf51/ldscripts -L/Users/ikravets/.platformio/packages/framework-mbed/variant/NRF51_MICROBIT/mbed/TARGET_NRF51_MICROBIT/TOOLCHAIN_GCC_ARM -L.pioenvs/bbcmicrobit -Wl,--start-group -lstdc++ -lsupc++ -lnosys -lmbed -lc -lgcc .pioenvs/bbcmicrobit/libFrameworkMbed.a -lc -lgcc -lm .pioenvs/bbcmicrobit/lib/libnrf51-sdk.a .pioenvs/bbcmicrobit/lib/libble.a .pioenvs/bbcmicrobit/lib/libble-nrf51822.a .pioenvs/bbcmicrobit/lib/libmicrobit.a .pioenvs/bbcmicrobit/lib/libmicrobit-dal.a -Wl,--end-group
.pioenvs/bbcmicrobit/lib/libmicrobit-dal.a(MicroBitFiber.o): In function `schedule()':
MicroBitFiber.cpp:(.text._Z8schedulev+0x6e): undefined reference to `swap_context'
MicroBitFiber.cpp:(.text._Z8schedulev+0xb8): undefined reference to `save_context'
MicroBitFiber.cpp:(.text._Z8schedulev+0xc4): undefined reference to `restore_register_context'
MicroBitFiber.cpp:(.text._Z8schedulev+0x108): undefined reference to `swap_context'
.pioenvs/bbcmicrobit/lib/libmicrobit-dal.a(MicroBitFiber.o): In function `invoke(void (*)(void*), void*)':
MicroBitFiber.cpp:(.text._Z6invokePFvPvES_+0x20): undefined reference to `save_register_context'
collect2: error: ld returned 1 exit status
[.pioenvs/bbcmicrobit/firmware.elf] Error 1

@palfrey
Copy link

palfrey commented Jul 25, 2016

@ivankravets Yeah, you're missing the little bit of assembler code from CortexContextSwitch.s. Multiple versions in https://github.com/lancaster-university/microbit-dal/tree/master/source/asm and you'll want CortexContextSwitch.s.gcc

@ivankravets ivankravets modified the milestone: 3.0.0 Jul 25, 2016
@palfrey
Copy link

palfrey commented Jul 27, 2016

@ivankravets How are you getting on with this?

@ivankravets
Copy link
Member

This issue depends on #500 and #533. We should fix these issues before.

Need to pre-built (or find somewhere) static srec_cat package for the all popular host OS (Win, macOS, Linux + Linux ARM).

Could you help us with this? See here examples of our packages https://bintray.com/platformio/dl-packages/tool-openocd#files

@palfrey
Copy link

palfrey commented Jul 27, 2016

Any examples of how the compilation is managed for existing tools? e.g. openocd? If so, I have access to all of those types of systems for making srec_cat.

@ivankravets
Copy link
Member

@palfrey we do that manually (download source code, install deps/libs, make) 😢

We would be thankful if you share somewhere these packages.

@ivankravets
Copy link
Member

ivankravets commented Jul 28, 2016

The Library Dependency Finder has been rewritten. Now it understands nested dependencies automatically. Also, if you don't need extra scripting, just remove library.json manifest and PlatformIO Build System will switch automatically to ARM mbed library builder and will use module.json data.

Please update to the latest development version.

platformio.ini

[env:bbcmicrobit]
platform = nordicnrf51
framework = mbed
board = bbcmicrobit
lib_install = 361

A few ARM mbed libraries require extra scripts:

nrf51-sdk-2.2.0-mb4

library.json

{
  "name": "nrf51-sdk",
  "version": "2.2.0",
  "description": "Module to contain files provided by the nordic nRF51 SDK",
  "keywords": [
    "nordic",
    "nrf51",
    "sdk"
  ],
  "author": "",
  "repository": {
    "url": "[email protected]:ARMmbed/nrf51-sdk.git",
    "type": "git"
  },
  "build":{
    "flags": [
      "-Isource/nordic_sdk/components/ble/ble_radio_notification",
      "-Isource/nordic_sdk/components/ble/ble_services/ble_dfu",
      "-Isource/nordic_sdk/components/ble/common",
      "-Isource/nordic_sdk/components/ble/device_manager",
      "-Isource/nordic_sdk/components/ble/device_manager/config",
      "-Isource/nordic_sdk/components/ble/peer_manager",
      "-Isource/nordic_sdk/components/device",
      "-Isource/nordic_sdk/components/drivers_nrf/ble_flash",
      "-Isource/nordic_sdk/components/drivers_nrf/delay",
      "-Isource/nordic_sdk/components/drivers_nrf/hal",
      "-Isource/nordic_sdk/components/drivers_nrf/pstorage",
      "-Isource/nordic_sdk/components/drivers_nrf/pstorage/config",
      "-Isource/nordic_sdk/components/libraries/bootloader_dfu",
      "-Isource/nordic_sdk/components/libraries/bootloader_dfu/hci_transport",
      "-Isource/nordic_sdk/components/libraries/crc16",
      "-Isource/nordic_sdk/components/libraries/hci",
      "-Isource/nordic_sdk/components/libraries/scheduler",
      "-Isource/nordic_sdk/components/libraries/timer",
      "-Isource/nordic_sdk/components/libraries/util",
      "-Isource/nordic_sdk/components/libraries/fds",
      "-Isource/nordic_sdk/components/libraries/fstorage",
      "-Isource/nordic_sdk/components/libraries/experimental_section_vars",
      "-Isource/nordic_sdk/components/softdevice/common/softdevice_handler",
      "-Isource/nordic_sdk/components/softdevice/s130/headers",
      "-Isource/nordic_sdk/components/toolchain"
    ],
    "extraScript": "platformio_extra.py"
  },
  "frameworks": "mbed",
  "platforms": "nordicnrf51"
}

platformio_extra.py

Import("pio_lib_builder")

# skip built-in ARM mbed NRF51 SDK, place library's includes before
pio_lib_builder.env.Prepend(CPPPATH=pio_lib_builder.get_inc_dirs())

Microbit-DAL_ID360

library.json

{
    "name": "Microbit-DAL",
    "keywords": "microbit, framework, bbc",
    "description": "The core set of drivers, mechanisms and types that make up the micro:bit runtime.",
    "repository":
    {
        "type": "git",
        "url": "https://github.com/rossng/microbit-dal.git"
    },
    "build":
    {
      "flags": [
        "-Iinc/core",
        "-Iinc/types",
        "-Iinc/drivers",
        "-Iinc/bluetooth",
        "-Iinc/platform"
      ],
      "extraScript": "platformio_extra.py"
    },
    "url": "https://github.com/lancaster-university/microbit-dal",
    "frameworks": "mbed",
    "platforms": "nordicnrf51"
}

platformio_extra.py

from os import unlink
from os.path import isfile, join
from shutil import copy
Import("pio_lib_builder")

# enable GCC ASM
if isfile(
        join(pio_lib_builder.path, "source", "asm",
             "CortexContextSwitch.s.gcc")):
    if isfile(
            join(pio_lib_builder.path, "source", "asm",
                 "CortexContextSwitch.s")):
        unlink(
            join(pio_lib_builder.path, "source", "asm",
                 "CortexContextSwitch.s"))
    copy(
        join(pio_lib_builder.path, "source", "asm",
             "CortexContextSwitch.s.gcc"),
        join(pio_lib_builder.path, "source", "asm", "CortexContextSwitch.S"))

# fix TWI API

twi_file_path = join(pio_lib_builder.path, "source", "drivers",
                     "MicroBitI2C.cpp")
if isfile(twi_file_path):
    content = ""
    with open(twi_file_path) as fp:
        content = fp.read()
    if "twi_master_init_and_clear()" in content:
        with open(twi_file_path, "w") as fp:
            fp.write(
                content.replace("twi_master_init_and_clear()",
                                "twi_master_init_and_clear(NRF_TWI1)"))

Here is the your project with the fixes.

P.S: I'm working on the improved library manager. It'll allow to install library directly from the repository. Please play with the project locally. When all works well, we can create forks of the dependent packages and update with extra scripts and manifests.

@ivankravets
Copy link
Member

I have 1 error. See my log http://pastebin.com/Qc6nGQ1T

I hope you will fix it.

@palfrey
Copy link

palfrey commented Jul 29, 2016

Will hopefully have a better look at this at the weekend, but meanwhile, to solve the createBLEInstance issue you'll need https://github.com/lancaster-university/nRF51822/blob/master/source/nRF5xn.cpp. The commit in my code that fixed this for me was palfrey/microbit-blink@c40f903

@ivankravets
Copy link
Member

@palfrey it has not been merged yet. PlatformIO 3.0 has decentralized architecture with development platforms. See https://github.com/platformio?utf8=✓&query=platform-

I'm working on the merging. Give me a few minutes. I'll reply here.

@ivankravets
Copy link
Member

Please upgrade to the latest PlatformIO 3.0 dev, remove ~/.platformio/platforms folder and it should work now.

@ivankravets
Copy link
Member

Would be good to run platformio update to update all packages.

@palfrey
Copy link

palfrey commented Aug 3, 2016

Did that, got the following (from platformio run -v, after LDF output):

/Users/palfrey/.platformio/packages/tool-sreccat/srec_cat -intel .pioenvs/bbcmicrobit/userfirmware.hex -intel -o .pioenvs/bbcmicrobit/firmware.hex -intel --line-length=44
arm-none-eabi-size -B -d .pioenvs/bbcmicrobit/firmware.elf
misplaced "-Intel" option
Usage: srec_cat [ <option>... ] <filename>...
srec_cat -Help
srec_cat -VERSion
srec_cat -LICense
scons: *** [.pioenvs/bbcmicrobit/firmware.hex] Error 1

I think it's still missing the softdevice firmware judging from the srec_info output (also that lines up with a missing argument before the first "-Intel")

@valeros
Copy link
Member

valeros commented Aug 4, 2016

Hi @palfrey !
Please make sure that you are using latest framework-mbed package with target.json file here
/Users/palfrey/.platformio/packages/framework-mbed

@palfrey
Copy link

palfrey commented Aug 4, 2016

Ah... Was missing the target.json entirely from there. Ran platformio platforms update and got framework-mbed @ 1.121.1 installed (did have 1.121.0). platformio run -t upload --upload-port /Volumes/MICROBIT now successfully installs a working Micro:bit binary!

@ivankravets
Copy link
Member

@palfrey what is your platformio --version? PlatformIO should update packages automatically when you upgrade it.

@palfrey
Copy link

palfrey commented Aug 4, 2016

3.0.0.dev19

@ivankravets
Copy link
Member

Thanks, that is strange. I'll take a look.

The last thing that we need is to create Microbit dependencies and register with http://platformio.org/lib

I'll do that when fix #413

@palfrey
Copy link

palfrey commented Aug 8, 2016

Now that #413 is merged, I've got a new version of my blink project (which I've added a few bells and whistles to along the way...) at https://github.com/palfrey/microbit-blink/tree/platform-3.0. At the moment however the platformio.ini has all of the dependencies listed, as without that it doesn't appear to be able to locate the others, when I think that all should be needed is the "Microbit" one.

Given that one has a library.json with what looks like a perfectly good Microbit-DAL dependency, I think there's either a bug or some part of the library dependency code is missing?

@ivankravets
Copy link
Member

  1. I don't recommend to use VCS because it requires to have installed client. The idea of PlatformIO Library Manager to work from a box without dependencies to system software.
  2. PlatformIO Library Manager handles only .library.json manifest file from the package. This file creates by PaltformIO Library Crawler and fills with required information (library ID in the registry, other info). The Library Builder uses library.json, module.json or library.properties that depends on a library type.

The ideal solution is when all dependencies are located in PlatformIO Library Registry. In this case, Library Manager will use prepared archives by Library Crawler.


In any case, I updated 2 manifests and now it should work with a simple platformio.ini

[env:bbcmicrobit]
platform = nordicnrf51
framework = mbed
board = bbcmicrobit
lib_deps = microbit@~2.0.0-rc4

@palfrey
Copy link

palfrey commented Aug 9, 2016

Tried that, got the following. This is using current develop branch of PlatformIO

[Tue Aug  9 12:07:06 2016] Processing bbcmicrobit (platform: nordicnrf51, lib_deps: microbit@~2.0.0-rc4, board: bbcmicrobit, framework: mbed)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Collected 1 compatible libraries
Looking for dependencies...
Error: Could not find `microbit-dal` dependency for `microbit` library

@ivankravets
Copy link
Member

Please remove .piolibdeps folder and pio upgrade

@palfrey
Copy link

palfrey commented Aug 9, 2016

Nice! Confirmed clean build with 3.0.0a3. I don't have my Micro:bit to hand to test, but will test this evening.

@ivankravets
Copy link
Member

Should we improve here something?

P.S: Thanks a lot for the great help on this issue! 👍

@ivankravets ivankravets mentioned this issue Aug 9, 2016
37 tasks
@palfrey
Copy link

palfrey commented Aug 9, 2016

Couple of things still outstanding:

  • IIRC, upload location wasn't correctly detected (certainly on my Mac). I had to add "--upload-port /Volumes/MICROBIT" to make it work
  • We're still using the "kitchen sink" bootloader/softdevice. These are fine for my purposes, but some larger Micro:bit projects may not work due to lack of space (e.g. MicroPython which appears to use the "no softdevice" option https://microbit-micropython.readthedocs.io/en/latest/devguide/flashfirmware.html)
  • The upload process ends with the words "please reset your device", which isn't necessary on the Micro:bit as it automagically flashes and resets when you copy a new image onto it.

Overall, very happy. Will be doing a blog post on the matter in the nearby future, and will send you a link when done.

@ivankravets
Copy link
Member

  1. Is fixed in fe76192
  2. We don't support MicroPython and it's very bad :( We don't have time for that, but have an open issue Micropython support #728 . Would be thankful if someone helps us with that. There is no problem to do that with PlatformIO 3.0. All development platforms with build scripts have been moved outside from PlatformIO Core. What is more, we are ready to provide full help in this way.
  3. Fixed in 92e8294 . Or, maybe, you can propose better wording for https://github.com/platformio/platformio/blob/develop/platformio/builder/tools/pioupload.py#L144?

@palfrey
Copy link

palfrey commented Aug 9, 2016

  1. fe76192 works well
  2. I was only using MicroPython as an example, but simply noting that larger programs like that will be excluded from being able to be built for the Micro:bit unless there's some sort of platform option of "use this different bootloader".
  3. Does Only do "please restart" message for boards that need it #744 work?

@palfrey
Copy link

palfrey commented Aug 28, 2016

FYI, there's now a blog post up about all of this http://www.lshift.net/blog/2016/08/28/using-the-bbc-microbit-with-platformio/

@ivankravets
Copy link
Member

@palfrey Thanks for a blog post, but big THANKS A LOT for the help on this issue :)

ivankravets added a commit that referenced this issue Sep 9, 2016
* develop:
  Fix incorrect line order when converting from INO to CPP and pointer is used
  Fix unit test
  Notify about `version` field when creating library
  Add support for SparkFun Blynk Board
  Return valid exit code from ``plaformio test`` command
  Disable SSL Server-Name-Indication for Python < 2.7.9
  Version bump to 3.0.1 (issue #772)
  Disable temporary SSL for PlatformIO services // Resolve #772
  Version bump to 3.0.0 (issues #770, #766, #747, #730, #765, #640, #659, #742, #459, #542, #763, #759, #753, #757, #749, #748, #745, #519, #709, #743, #413, #498, #410, #740, #361, #414, #554, #732, #588, #475, #461, #101, #719, #721, #537, #415, #522, #289, #556, #570, #456, #617, #432, #408, #479, #667, #510)
  Fix menu height for  docs
  Fix issue with multiple archives when linking firmware
  Add migration guide for PIO2 to PIO3
  Search libraries by headers/includes with ``platformio lib search --header`` option
  Update pio run command examples
  Add Unit Testing Demo
  Update PIO Plus badge title and link
  Add PlatformIO Plus badge
  Add links to PlatformIO Plus
@gunhaxxor
Copy link

Hello! I'm using platformIO, IDE 1.7.2 | Core 3.2.1
I'm doing a project initialization as follows (using the microbit-hello-world example):

[env:bbcmicrobit]
platform = nordicnrf51
board = bbcmicrobit
framework = mbed
lib_deps =
   microbit@~2.0.0-rc4

The example code is this:

#define MICROBIT_DBG 1
#include <MicroBit.h>

MicroBit uBit;

int main() {
    // Initialise the micro:bit runtime.
    uBit.init();

    // Insert your code here!
    // while(1){
      uBit.display.scroll("HELLO WORLD! :)");
    // }

    // If main exits, there may still be other fibers running or registered event handlers etc.
    // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
    // sit in the idle task forever, in a power efficient sleep.
    release_fiber();
    return 0;
}

The example compiles fine and uploads to the microbit. But the pinout configuration seems to be somewhat off, as the led matrix doesn't display any sensible text. I've tried to use the equivalent example in the mbed-online-compiler, and the display scrolls HELLO WORLD as expected.

@ivankravets
Copy link
Member

@Dealerpriest please file an issue here https://github.com/platformio/platform-nordicnrf51/issues

It seems that previous Microbit integration doesn't work with our latest mbed SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants