Skip to content

Instantly share code, notes, and snippets.

void LCD_Init(void)
{
GPIO_CfgPinOutput(5);
GPIO_CfgPinOutput(6);
GPIO_CfgPinOutput(0x1d);
GPIO_CfgPinOutput(0x10);
_DAT_5000050c = 0x10000; /* clear D16 */
GPIO_ConfOutput4_28();
D4_PulseZero50ms();
@fanoush
fanoush / espruino-FPU-softfp-inlineC.js
Last active September 3, 2019 21:41
native nrf52 FPU floating point math in Espruino inline C
// https://github.com/gfwilliams/EspruinoCompiler/issues/10
// https://www.espruino.com/service/compiler => http://127.0.0.1:32766
// old compile.js: var cflags = "-mlittle-endian -mthumb -mcpu=cortex-m3 -mfix-cortex-m3-ldrd -mthumb-interwork -mfloat-abi=soft ";
// new: var cflags = "-mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion -Wfloat-conversion ";
//
// power drain fix
// https://devzone.nordicsemi.com/f/nordic-q-a/15243/high-power-consumption-when-using-fpu
// https://devzone.nordicsemi.com/f/nordic-q-a/12433/fpu-divide-by-0-and-high-current-consumption
// https://infocenter.nordicsemi.com/index.jsp?topic=%2Ferrata_nRF52832_EngC%2FERR%2FnRF52832%2FEngineeringC%2Flatest%2Fanomaly_832_87.html&anchor=anomaly_832_87
diff --git a/make/family/NRF52.make b/make/family/NRF52.make
index 725cb55d..90bd9b69 100644
--- a/make/family/NRF52.make
+++ b/make/family/NRF52.make
@@ -46,6 +46,7 @@ NRF5X_SDK=11
NRF5X_SDK_11=1
NRF5X_SDK_PATH=$(ROOT)/targetlibs/nrf5x_11
DEFINES += -DNRF_SD_BLE_API_VERSION=2
+DEFINES += -D__HEAP_SIZE=0 -D__STACK_SIZE=0x2600 -D__STARTUP_CLEAR_BSS
SOFTDEVICE = $(SOFTDEVICE_PATH)/hex/s132_nrf52_2.0.0_softdevice.hex

C code

double __attribute__((pcs("aapcs"))) f2d(float f) {
return (double)f;
}

double __attribute__((pcs("aapcs-vfp"))) __hard_f2d(float f){
return (double)f;
}
@fanoush
fanoush / bootstrap.diff
Created November 12, 2019 11:17
Next186_SoC - load bios from MBR gap
diff -Naur Next186_SoC.orig/186Code/BIOS/bootload_BIOS_SD/bootstrap.asm Next186_SoC/186Code/BIOS/bootload_BIOS_SD/bootstrap.asm
--- Next186_SoC.orig/186Code/BIOS/bootload_BIOS_SD/bootstrap.asm 2016-09-26 14:42:28.401003600 +0200
+++ Next186_SoC/186Code/BIOS/bootload_BIOS_SD/bootstrap.asm 2018-02-14 22:57:25.033245500 +0100
@@ -95,32 +95,29 @@
call sdinit_
test ax, ax
jz short RS232
- mov dx, ax
+ mov dx, ax ; first try to read bios from end of card
shr dx, 6
#Format=Hex
#Depth=256
#Width=32
#AddrRadix=3
#DataRadix=3
#Data
C88CFCFA
C08ED88E
00BCD08E
E7C033FC
@fanoush
fanoush / HX03W.js
Last active January 1, 2020 18:58
//manual watchdog pinging mode is dangerous for Espruino Web IDE upload with 'reset() before upload' enabled
//you can brick your device with partial upload caused by watchdog reboot in the middle of upload
//E.enableWatchdog(6, false);
//var wdint=setInterval(function(){if(!BTN1.read())E.kickWatchdog();},1000);
var log=console.log;
Modules.addCached("HX03WLCD",function(){
// commands sent when initialising the display
var initCmds = new Uint8Array([
0xAE, // 0 disp off
0xD5, // 1 clk div
@fanoush
fanoush / espruino-FPU-mandel-bench.js
Last active August 27, 2020 04:29
this is benchmark of Mandelbrot set in JS, compiled JS and inline C. compiler output inside comments can be used instead of code above it, if you don't have EspruinoCompiler enabled
function mandelCompJS(x,y) {
"compiled";
var Xr = 0;
var Xi = 0;
var i = 0;
var Cr=(4*x/64)-2;
var Ci=(4*y/64)-2;
while ((i<32) & ((Xr*Xr+Xi*Xi)<4)) {
var t=Xr*Xr - Xi*Xi + Cr;
Xi=2*Xr*Xi+Ci;
// -- 1. copy paste methods for flash writing and verification below to Espruino WebIDE left side
E.setFlags({unsafeFlash:1});
var fl=require("Flash");
var ladd=0;var lpg=0;var nadd=0;// last address, last page addr, next addr
var flash=function(a,d){
if (nadd>0 && nadd<a) console.log("Hole in data, got "+a.toString(16)+", expected "+nadd.toString(16));
var p=fl.getPage(a).addr;
if (p>lpg) {fl.erasePage(p);lpg=p;console.log("Erasing page 0x"+p.toString(16));}
p=fl.getPage(a+d.length-1).addr;
if (p>lpg) {fl.erasePage(p);lpg=p;console.log("Erasing page 0x"+p.toString(16));}
diff --git a/targetlibs/nrf5x_12/components/libraries/bootloader/dfu/nrf_dfu_utils.c b/targetlibs/nrf5x_12/components/libraries/bootloader/dfu/nrf_dfu_utils.c
index 6da88aa9..5ba66f3d 100644
--- a/targetlibs/nrf5x_12/components/libraries/bootloader/dfu/nrf_dfu_utils.c
+++ b/targetlibs/nrf5x_12/components/libraries/bootloader/dfu/nrf_dfu_utils.c
@@ -461,10 +461,11 @@ uint32_t nrf_dfu_continue(uint32_t * p_enter_dfu_mode)
bool nrf_dfu_app_is_valid(void)
{
NRF_LOG_INFO("Enter nrf_dfu_app_is_valid\r\n");
- if (s_dfu_settings.bank_0.bank_code != NRF_DFU_BANK_VALID_APP &&
+ if (s_dfu_settings.bank_0.bank_code != NRF_DFU_BANK_VALID_APP ^M