Skip to content

Instantly share code, notes, and snippets.

@fanoush
Last active April 29, 2021 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanoush/3be052f44398ee44cc8c272ee8eadc81 to your computer and use it in GitHub Desktop.
Save fanoush/3be052f44398ee44cc8c272ee8eadc81 to your computer and use it in GitHub Desktop.
E104-BT5032A board file
#!/bin/false
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
#
# Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
#
# 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 http://mozilla.org/MPL/2.0/.
#
# ----------------------------------------------------------------------------------------
# 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' : [ "http://www.ebyte.com/en/product-view-news.aspx?id=956" ],
# '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' : [
'BLUETOOTH',
# 'NET',
'GRAPHICS',
# 'NFC',
# 'NEOPIXEL'
],
'makefile' : [
# 'DEFINES+=-DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work as reset
'DEFINES+=-DNRF_BLE_GATT_MAX_MTU_SIZE=59 -DNRF_BLE_MAX_MTU_SIZE=59',
'LDFLAGS += -Xlinker --defsym=LD_APP_RAM_BASE=0x2d18', #MTU 53 0x2c40, 59 0x2d18
# 'DEFINES+=-DUSE_FONT_6X8 -DGRAPHICS_PALETTED_IMAGES',
'DEFINES+=-DNO_DUMP_HARDWARE_INITIALISATION', # don't dump hardware init - not used and saves 1k of flash
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"E104-BT5032A"\'',
'DEFINES+=-DNRF_BL_DFU_INSECURE=1', # -DBUTTONPRESS_TO_REBOOT_BOOTLOADER=1',
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
'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','',
'D18','D17','D16','D15','D14','D13','D12','D11','',
'D10','D9','D8','D7','D6','D5','D21','D1','D0'],
'_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:
pin["functions"]["3.3"]=0;
#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
@fanoush
Copy link
Author

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 https://github.com/lab11/nrf52x-base/blob/master/sdk/nrf5_sdk_16.0.0/config/nrf52832/config/sdk_config.h#L12640 and more places
see also difference here https://github.com/espruino/Espruino/blob/master/targets/nrf5x/bluetooth.c#L2344 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

@acalatrava
Copy link

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