Skip to content

Instantly share code, notes, and snippets.

Last active Apr 29, 2021
What would you like to do?
E104-BT5032A board file
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
# Copyright (C) 2013 Gordon Williams <>
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at
# ----------------------------------------------------------------------------------------
# This file contains information for a specific board - the available pins, and where LEDs,
# Buttons, and other in-built peripherals are. It is used to build documentation as well
# as various source and header files for Espruino.
# ----------------------------------------------------------------------------------------
import pinutils;
info = {
'name' : "E104-BT5032A",
'boardname' : "E104BT5032A",
'link' : [ "" ],
# 'espruino_page_link' : 'nRF52832DK',
'default_console' : "EV_SERIAL1",
'default_console_tx' : "D18",
'default_console_rx' : "D14",
'default_console_baudrate' : "115200",
'variables' : 2565-((0x2d18-0x2c40)/16), # How many variables are allocated for Espruino to use. RAM will be overflowed if this number is too high and code won't compile.
'bootloader' : 1,
'binary_name' : 'espruino_%v_E104BT5032A.hex',
'build' : {
'optimizeflags' : '-Os',
'libraries' : [
# 'NET',
# 'NFC',
'makefile' : [
# 'DEFINES+=-DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work as reset
'LDFLAGS += -Xlinker --defsym=LD_APP_RAM_BASE=0x2d18', #MTU 53 0x2c40, 59 0x2d18
'DEFINES+=-DNO_DUMP_HARDWARE_INITIALISATION', # don't dump hardware init - not used and saves 1k of flash
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C,0x91'
chip = {
'part' : "NRF52832",
'family' : "NRF52",
'package' : "QFN48",
'ram' : 64,
'flash' : 512,
'speed' : 64,
'usart' : 1,
'spi' : 1,
'i2c' : 1,
'adc' : 1,
'dac' : 0,
'saved_code' : {
'address' : ((118 - 20) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
'page_size' : 4096,
'pages' : 20,
'flash_available' : 512 - ((31 + 8 + 2 + 20)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
devices = {
'BTN1' : { 'pin' : 'D29', 'pinstate' : 'IN_PULLDOWN' }, # Pin negated in software
# 'BTN2' : { 'pin' : 'D21', 'pinstate' : 'IN_PULLDOWN' }, # Pin negated in software
'LED1' : { 'pin' : 'D30' }, # Pin negated in software
'LED2' : { 'pin' : 'D31' }, # Pin negated in software
'RX_PIN_NUMBER' : { 'pin' : 'D14'},
'TX_PIN_NUMBER' : { 'pin' : 'D18'},
'CTS_PIN_NUMBER' : { 'pin' : 'D20'},
'RTS_PIN_NUMBER' : { 'pin' : 'D19'},
# left-right, or top-bottom order
board = {
'left' : [ 'VDD', 'VDD', 'RESET', 'VDD','5V','GND','GND','','','D3','D4','D28','D29','D30','D31'],
'right' : [
'D27', 'D26', 'D2', 'GND', 'D25','D24','D23', 'D22','D20','D19','',
'_notes' : {
'D14' : "Serial console RX",
'D18' : "Serial console TX"
board["_css"] = """
#board {
width: 528px;
height: 800px;
top: 0px;
left : 200px;
background-image: url(img/NRF52832DK.jpg);
#boardcontainer {
height: 900px;
#left {
top: 219px;
right: 466px;
#right {
top: 150px;
left: 466px;
.leftpin { height: 17px; }
.rightpin { height: 17px; }
def get_pins():
pins = pinutils.generate_pins(0,31) # 32 General Purpose I/O Pins.
pinutils.findpin(pins, "PD0", True)["functions"]["XL1"]=0;
pinutils.findpin(pins, "PD1", True)["functions"]["XL2"]=0;
pinutils.findpin(pins, "PD19", True)["functions"]["RTS"]=0;
pinutils.findpin(pins, "PD18", True)["functions"]["TXD"]=0;
pinutils.findpin(pins, "PD20", True)["functions"]["CTS"]=0;
pinutils.findpin(pins, "PD14", True)["functions"]["RXD"]=0;
# pinutils.findpin(pins, "PD9", True)["functions"]["NFC1"]=0;
# pinutils.findpin(pins, "PD10", True)["functions"]["NFC2"]=0;
pinutils.findpin(pins, "PD2", True)["functions"]["ADC1_IN0"]=0;
pinutils.findpin(pins, "PD3", True)["functions"]["ADC1_IN1"]=0;
pinutils.findpin(pins, "PD4", True)["functions"]["ADC1_IN2"]=0;
pinutils.findpin(pins, "PD5", True)["functions"]["ADC1_IN3"]=0;
pinutils.findpin(pins, "PD28", True)["functions"]["ADC1_IN4"]=0;
pinutils.findpin(pins, "PD29", True)["functions"]["ADC1_IN5"]=0;
pinutils.findpin(pins, "PD30", True)["functions"]["ADC1_IN6"]=0;
pinutils.findpin(pins, "PD31", True)["functions"]["ADC1_IN7"]=0;
# Make buttons and LEDs negated
# pinutils.findpin(pins, "PD21", True)["functions"]["NEGATED"]=0;
pinutils.findpin(pins, "PD29", True)["functions"]["NEGATED"]=0;
pinutils.findpin(pins, "PD30", True)["functions"]["NEGATED"]=0;
pinutils.findpin(pins, "PD31", True)["functions"]["NEGATED"]=0;
# everything is non-5v tolerant
for pin in pins:
#The boot/reset button will function as a reset button in normal operation. Pin reset on PD21 needs to be enabled on the nRF52832 device for this to work.
return pins
Copy link

acalatrava commented Apr 28, 2021

I'm trying flashing this exact module with my own firmware. However everytime I flash a softdevice the module enters on a bootloop and it loses contact to jlink so I'm forced to erase it completely by issuing nrfjprog -f nrf52 --recover.

I saw this file and wanted to try with Espruino on it, however I got this error while compiling:

Testing espruino_2v09.1_E104BT5032A.elf for E104_BT5032A
STORAGE: 401408 -> 483328
FS DATA: 428156 -> 428172 (16 bytes)
CODE: 126976 -> 428172 (300940 bytes)
   by 26764 bytes
make/common/NRF5X.make:441: recipe for target 'espruino_2v09.1_E104BT5032A.app_hex' failed
make: *** [espruino_2v09.1_E104BT5032A.app_hex] Error 1

any help?

Copy link

fanoush commented Apr 28, 2021

just tried with this board file and latest tree

make BOARD=E104_BT5032A RELEASE=1
CODE: 126976 -> 392892 (265660 bytes)

you either forgot RELEASE=1 or have old gcc compiler. you can get latest one from

Copy link

acalatrava commented Apr 28, 2021

Yeah, that seems to do the trick!
And now, after flashing it, at least something different this time! Somehow the device is not connectable through SWDIO anymore (just like everytime I flash any softdevice, I need to do a recover to, well, recover the ability to flash it, but at least now it's advertising a UART service "E104-BT5032A 2106"... so, this means Espruino is working? (first time on Espruino)
Do you have the same behavior everytime you flash a softdevice on it?

Copy link

fanoush commented Apr 28, 2021

Do you have the same behavior everytime you flash a softdevice on it?

not same behaviour, however i am using openocd, if there already is some app flashed and I flash compatible softdevice (e.g. S132 3.1.0 hex over 3.0.0) the app still works. Flashing just softdevice without any application present makes little sense so didn't try that.

yes espruino is working, you can try in Chrome to connect over bluetooth or use serial over usb cable

Copy link

acalatrava commented Apr 29, 2021

You're right, espruino works and I'm able to connect over BLE Serial to it. However the device is kind of "protected". Everytime I flash a program with a softdevice in it the device keeps "protected", meaning that I can't access to it over SWD anymore. I read about the APProtect register on UIPR so I guess this could be it, but it seems that any program I flash will lock the SWD... I don't think that even espruino will enable APProtect register...

I tried with OpenOCD aswell but it was unable to even flash it when the device is erased, spitting a weird error:

> program /Users/acalatrava/Downloads/espruino.bin
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
embedded:startup.tcl:476: Error: ** Programming Failed **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 532
at file "embedded:startup.tcl", line 476

I guess you are using OpenOCD with ST-Link instead of JLink so maybe that is a difference but I don't think ST-Link will be able to connect either...

Some questions:
1.- Did your E104-BT5032A modules come with CTRL-AP protected too? meaning you needed to erase all the contents before flashing them the first time?
2.- I tried to compile a very simple BLE advertiser ( using that environment ( and flash both the s132 softdevice and the compiled app. The device becomes "locked" again but it seems that it's not advertising... Would you be so kind to try the compiled hex (or compile it by yourself) and check if you see it working? (I know it's a lot to ask but I don't understand why this modules behave like this)

Thank you again!

Copy link

fanoush commented Apr 29, 2021

yes, it came protected, mass erasing it unprotected it. with espruino you can check status via peek32(0x10001208). espruino does not lock it. if locked via APPROTECT it can be also unlocked in software via erasing UICR registers (e.g. from Espruino)

not sure what "locked" means for you but if softdevice is not starting and you started from nordic devboard configuration you should remove definitions for those boards (e.g. like PCA10040) so it does not include board specific files from SDK and also it may be due to missing external 32kHz crystal. those devboards have it but it is optional component that BT5032A does not have. check source/configs for setting that include _CLOCK_LF_SRC , it should be set to 0 = internal RC to have it working on E104BT5032A, not 1

e.g. here and more places
see also difference here for RC you also need to configure those two 'ctiv' calibration values 16,2

this should of course not affect SWD functionality and the APPROTECT lock in any way

Copy link

acalatrava commented Apr 29, 2021

My goodness! It was the fricking internal oscillator.... I can’t express how grateful I’m for all your help. It was driving me nuts!
Well, you learn something new every day, ;)

The SWD problem should be another story, but at least now I can flash my own binary.

Again, thank you very much indeed!!

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