• I have a nRF52832 board equipped with an external low-frequency 32678 kHz crystal.
    Is there a way to switch the low-frequency oscillator from:

    • the internal RC oscillator to
    • the external 32678 kHz crystal oscillator?
      ...to generate an espruino build?

    I would like to use the external low-frequency 32678 kHz crystal to improve the board power consumption when used as a beacon.

    The external low-frequency crystal is connected between P0.00/XL1 and P0.01/XL2 (see enclosed picture).
    D0 and D1 are used on the Esprino MDBT42Q board to switch to DFU/reset modes and to light an LED.

    • I believe that D0=P0.00/XL1 and D1=P0.01/XL2. Is this true?
    • I believe there is an easy way to use different pins to switch to DFU/reset modes and to light an LED by creating a different board definition. Is that right?
    • But I can't see any easy way to switch from the internal low-frequency RC oscillator to an external 32678 kHz crystal. Is there one?

    1 Attachment

  • I think you just need this in BOARDNAME.py:

       'makefile' : [
  • Thank you so much! I will do some digging...

    What about D0 being P0.00/XL1 and D1 being P0.01/XL2. Is this true?

  • the software config is here https://github.com/espruino/Espruino/blo­b/master/targets/nrf5x/bluetooth.c#L2365­

    If you would use Nordic SDK directly, LF source it is typically chosen in the SDK config file https://github.com/espruino/Espruino/blo­b/master/targetlibs/nrf5x_12/nrf52_confi­g/sdk_config.h#L262 (in newer SDKs there are actually two settings there to change, one generic and one for the softdevice)

  • It is very clear. Thank you very much!

    So I guess I have to reassign the Espruino DFU/reset Pin to something other than D0 to have this feature working?
    Maybe by modifying D0 in line 'BTN1' : { 'pin' : 'D0', 'pinstate' : 'IN_PULLDOWN' } of file MDBT42Q.py with D3.

  • Oh, so you want to add crystal to existing MDBT42Q board? And now I also noticed

    I would like to use the external low-frequency 32678 kHz crystal to improve the board power consumption when used as a beacon.

    How much of power you expect to save? It may not be that much and it is likely other components on board may draw more. See e.g. this https://devzone.nordicsemi.com/f/nordic-­q-a/25540/is-external-crystal-neccessary­-at-all-on-52832/100707#100707 so it is really not much. Was thinking you already have board with the crystal and just want to enable it so it is not sitting there wasted.

    And BTW there is also the builtin DCDC converter, it could save more if used , that is however more complicated to enable as it needs more components. see https://infocenter.nordicsemi.com/topic/­com.nordic.infocenter.nrf52832.ps.v1.1/p­ower.html?cp=4_2_0_17_0#topic and https://infocenter.nordicsemi.com/topic/­com.nordic.infocenter.nrf52832.ps.v1.1/r­ef_circuitry.html?cp=4_2_0_52_1#schemati­c_qfn48_dcdc

    just googled and here https://www.programmersought.com/article­/18503111047/ someone claims enabling DC/DC can save 40% and crystal 1-2%

    Anyway, yes those board file changes will help freeing D0 pin, however you need to build and update also the bootloader as that is where the button is actually checked.

  • Sorry for being that little clear: I don't have a MDBT42Q board. I want to define my own definition board, and I thought MDBT42Q.py was a good start...

    Indeed I do have a board with a low-frequency crystal (actually it is still in the mail) and I want to enable it so it is not sitting there wasted + to save some power.

    I have 2 nRF52832 boards I would like to use as beacons:

    I used the standard MDBT42Q.py definition file to build the firmware for the Holyot board.
    I would like to write a board definition file for the FEASYCOM that:

    • enables its MCU-external though board-embedded low-frequency crystal +
    • sets a pin to let the board enter DFU mode / hard reset mode.

    I did some power measurements on nRF51822 boards programmed as beacons (not nRF52832 boards though, not Espruino based) using the NORDIC Power Profiler Kit II, and I came out with this comparison chart:

    Low-Frequency Oscillator Average Current Consumption @ 3V
    External 32768 kHz crystal 7.85 uA
    Internal RC circuit 8.24 uA (14% more)

    Thus I expect to save about 14%. This result corroborates this discussion on Nordic DevZone Q&A.

    Once I successfully generate an optimised Esprino firmware for my FEASYCOM board, I would like to do the same comparison...

    I did some measurements on the Holyot board programmed as a beacon using Espruino and was impressed by its low power consumption already!

    However I also noticed little current spikes here and there in-between two broadcasting emissions (the board was sleeping?) that might be due (I have no clue though) to the use of the RC internal oscillator.

    This is why I would like to try the same code on the FEASYCOM board which Espruino firmware is built enabling its low-frequency crystal (+ redefining the reset pin to be able to exit the NRF.setAdvertising mode easily).

    • Regarding the builtin DC/DC converter, I need to understand how to enable it using Espruino?
    • Regarding the bootloader, I need to understand how to account for that new button pin definition?
  • That post you linked is excellent summary, thank you. Of course the calibration takes power, nice someone took care to compute that part too.

    BTW if schematics in the Holyot YJ-17095 page is correct the DCDC should be supported there. It saves most power when current is high = bluetooth transmit. Now found source for information in that article I linked previously here https://devzone.nordicsemi.com/nordic/no­rdic-blog/b/blog/posts/optimizing-power-­on-nrf52-designs

    For enabling DCDC define ESPR_DCDC_ENABLE as checked here https://github.com/espruino/Espruino/blo­b/99541c982aeef8114374cc673919fc42f1f874­c7/targets/nrf5x/bluetooth.c#L2458

  • Great that the Holyot YJ-17095 board supports the DC/DC regulator!
    It seems that the FEASYCOM FSC-BT630 board supports the DC/DC regulator too (see board datasheet, page 11, 4. PHYSICAL INTERFACE, 4.1 Power Supply).

    I will compare power consumption of the FEASYCOM FSC-BT630 used as a beacon, programmed using Espruino, for all the different setting combinations (as soon as I receive it).


    Low-Frequency Oscillator / Internal Power Supply Regulator LDO (Default) DC/DC
    Internal RC Circuit (Default) ? ?
    External 32.768 kHz Crystal ? ?

    To let the bootloader take into account the new reset pin definition D3, I modified my board definition file with 'BTN1' : { 'pin' : 'D3', 'pinstate' : 'IN_PULLDOWN' } and invoked make with argument BOOTLOADER=1. Is this enough?

    The Espruino documentation is top-notch and the file entitled Espruino Internals: Build Process explains how to enable the low-frequency crystal and the DC/DC converter as well:

       'makefile' : [
         'DEFINES += -DESPR_LSE_ENABLE ', # to enable low-frequency crystal
         'DEFINES += -DESPR_DCDC_ENABLE', # to enable DC/DC converter

    @Gordon : Can you tell me how to get the Donated badge under my name in the forum? I did donate during the Bangle.js Kickstarter campaign and I own official Espruino boards (Pico, Puck.js) + your book.

  • I modified my board definition file with 'BTN1' : { 'pin' : 'D3', 'pinstate' : 'IN_PULLDOWN' } and invoked make with argument BOOTLOADER=1. Is this enough?

    The line 'bootloader' : 1, here enables bootloader and it is built as part of running make. If you use SWD you can even disable bootloader by setting value 0 there to make it more simple. Anyway when checking MDBT42Q.py board definition now, there is also LED1 on pin D1 so that one needs to be moved too. LED1 is optional so you can remove it completely. Button is also optional if you disable bootloader. Also you can set the default_console to EV_BLUETOOTH if you want to remove serial pin definitions too.

  • Thank you!
    I already had removed LED1 from the definition file.
    I kept BTN1 (set to D3 thought for the FEASYCOM FSC-BT630 board) to allow HARD RESET mainly, but to perform DFU upgrade too as I find it a nice feature. I was thinking to use SWD to flash the firmware only once and to perform next upgrades OTA.
    Thanks to your assistance, I just switched the default console to bluetooth and removed default_console_tx and default_console_rx from the definition file.

    I am currently experimenting with my Holyot YJ-17095 board and will try it enabling the DC/DC regulator. I will make screenshots to observe the current spikes I was talking of and to compare power consumptions.

  • Hi @sebi! You mean you donated extra on the KickStarter campaign?

    The badge is semi-automated and I hadn't actually added those who'd contributed in the campaign (just by http://www.espruino.com/Donate) so that's why you didn't show up. I'll add you on the list, and the next website update should have that in. Thanks!

  • @Gordon : I bought a pixel during the Bangle.js campaign. It is peanuts but I made sure to buy official boards and your book. I thought the donated badge was automatic when buying something during the campaign and it could be a mistake... I realise buying/donating are two different things. Additionally it is not worth putting that badge for peanuts.

  • @MaBe pointed out to me that I can get inspired from the Bangle.JS2 board definition file to tweak my boards' settings.

  • It seems enabling the DC/DC regulator doesn't improve (always?) performances: check my post on GitHub where I compare different settings on a nRF51 board programmed to be a beacon in C. Enabling the low-frequency crystal does improve power consumption thought.

    I am planning to do the same comparison with my FEASYCOM FSC-BT630 (nRF52) as soon as I get it. Additionally I would like to compare the beacon when programmed using Espruino (see this post for the original code). But from my current tries with my Holyiot YJ-17095 board, it seems the Espruino version consumes about 45uA so about 5 to 6 times more than the beacon version in C.

    I can't explain this as I thought

    NRF.setAdvertising(adv, {interval:5000});

    required restarting the BLE stack with different settings (disabling the communication with the IDE, etc) that would make this code running very similar to the code directly generated from C.

  • EDIT: I moved the content of this post to another thread in the forum as I plan to publish the code on Espruino App loader once it is finalized and refer to it for explanations.

  • But from my current tries with my Holyiot YJ-17095 board, it seems the Espruino version consumes about 45uA so about 5 to 6 times more than the beacon version in C

    It seems something was wrong with my preliminary tests on the Holyiot YJ-17095 board since today I measured an average power consumption on the Puck.js acting as a beacon of only 6.30uA @ 3V (see this post on the forum).

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Espruino build for nRF52832 board with external low-frequency 32678 kHz crystal

Posted by Avatar for sebi @sebi