$ sudo pip install mbed-cli
pip
:
$ wget http://bootstrap.pypa.io/ez_setup.py $ python ez_setup.py --user $ ~/.local/bin/pip install virtualenv --user $ ~/.local/bin/virtualenv venv $ source venv/bin/activate (venv) $ pip install mbed-cli
/work/gcc-arm-none-eabi-5_4-2016q2/
, then it is registered in the mbed CLI command
$ mbed config --global GCC_ARM_PATH /work/gcc-arm-none-eabi-5_4-2016q2/bin/
$ mbed new mb_clock $ cd mb_clock $ mbed target NRF51_MICROBIT $ mbed toolchain GCC_ARM
If thembed new
command is executed as root and / or inside venv, then it will automatically install the necessary Python modules into the system. Otherwise, she will ask
$ sudo pip install -r mbed-os/requirements.txt
$ mbed add https://github.com/lancaster-university/microbit # $ mbed add https://github.com/tyomitch/microbit-dal #
CortexContextSwitch.s
, which comes in two versions: for GNU as and for armasm . The library for mbed OS 3 included the CMakeLists.txt
file, in which the automatic selection of the desired option was registered. Alas, mbed OS 5 ignores CMakeLists.txt
, so you have to manually select the option for GNU as:
$ cp microbit-dal/source/asm/CortexContextSwitch.s.gcc microbit-dal/source/asm/CortexContextSwitch.s
$ rm mbed-os/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/source/nRF5xn.cpp
#include "MicroBit.h" MicroBit uBit; const uint8_t digit_bits[10][10] = { { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, { 1, 1, 0, 1, 1, 1, 1, 0, 1, 1 }, { 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 }, { 0, 1, 1, 1, 1, 1, 0, 1, 0, 1 }, { 1, 1, 1, 0, 1, 1, 0, 1, 1, 1 }, { 0, 1, 1, 0, 1, 0, 1, 1, 1, 1 }, { 1, 1, 0, 1, 0, 1, 1, 0, 1, 0 }, { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 }, { 1, 1, 1, 1, 0, 1, 0, 1, 1, 0 } }; MicroBitImage digits[] = { MicroBitImage(2,5,digit_bits[0]), MicroBitImage(2,5,digit_bits[1]), MicroBitImage(2,5,digit_bits[2]), MicroBitImage(2,5,digit_bits[3]), MicroBitImage(2,5,digit_bits[4]), MicroBitImage(2,5,digit_bits[5]), MicroBitImage(2,5,digit_bits[6]), MicroBitImage(2,5,digit_bits[7]), MicroBitImage(2,5,digit_bits[8]), MicroBitImage(2,5,digit_bits[9]) }; int started_at = 18*60+53; void onButtonAClick(MicroBitEvent evt) { started_at--; } void onButtonBClick(MicroBitEvent evt) { started_at++; } int main() { uBit.init(); uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonAClick); uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonBClick); while(1) { int cur_time = (started_at + uBit.systemTime() / 60000L) % (24*60); int hours = cur_time / 60; int minutes = cur_time % 60; uBit.display.image.paste(digits[hours/10],0,0,0); uBit.display.image.paste(digits[hours%10],3,0,0); uBit.sleep(300); uBit.display.image.paste(digits[minutes/10],0,0,0); uBit.display.image.paste(digits[minutes%10],3,0,0); uBit.sleep(300); uBit.display.clear(); uBit.sleep(600); } }
mb_clock.cpp
), the whole project can be compiled and downloaded to the device:
$ mbed compile -D __STACK_SIZE=512 -D ISR_STACK_SIZE=512 -D MICROBIT_BLE_ENABLED=0 $ cp ./.build/NRF51_MICROBIT/GCC_ARM/mb_clock.hex /media/MICROBIT
Source: https://habr.com/ru/post/307806/