Category: BrainDamage

CUDA compilation error

mkdir -p ./bin 
/usr/bin/nvcc -I/usr/include -O2 -Xcompiler -fPIC -o bin/out/ProgramCU.o src/pba/ -c
src/pba/ warning: statement is unreachable

src/pba/ warning: statement is unreachable

/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
   return (char *) memcpy (__dest, __src, __n) + __n;
src/pba/ In member function ‘void CuTexImage::BindTexture(textureReference&)’:
src/pba/ warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
     if(sz > MAX_TEXSIZE) fprintf(stderr, "cudaBindTexture: %d > %d\n", sz , MAX_TEXSIZE); 
src/pba/ In function ‘bool ProgramCU::ShuffleCameraJacobian(CuTexImage&, CuTexImage&, CuTexImage&)’:
src/pba/ warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
         fprintf(stderr, "datasize way too big %d, %d+...\n", szjc, (szjc)/ MAX_TEXSIZE); 
src/pba/ warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
makefile:49: recipe for target 'bin/out/ProgramCU.o' failed
make: *** [bin/out/ProgramCU.o] Error 1

Fix: open the makefile and replace:

NVCC_FLAGS = -I$(CUDA_INC_PATH) -O2 -Xcompiler -fPIC




Compiling KiCAD from source code on Debian Sid

These are the steps I did to compile KiCAD on Debian 8 Sid:

Download the source code:

$ git clone

Create a build directory:

$ cd kicad-source-mirror/
$ mkdir -p build/release
$ cd build/release

Install the dependences:

$ sudo apt-get install libwxbase3.0-dev libwxgtk3.0-dev libgl1-mesa-dev libglew-dev libglm-dev libcurl4-openssl-dev libboost-dev libboost-thread-dev libboost-system-dev libboost-context-dev libssl-dev wx-common libpython-dev python-wxgtk3.0-dev swig3.0

//create a symbolic link to pretend be swig2.0 for cmake:
$ sudo ln -s /usr/bin/swig3.0 /usr/bin/swig2.0

Execute the cmake configuration:

$ make
$ sudo checkinstall

Done! Now we have a cutting-edge KiCAD version installed on our system!

Testing the Nordic UART Service for nRF51822

Today I decided to test the Nordic Uart Service (NUS) to enable a serial communication (emulated) between a Bluetooh Low Energy device (nRF51822) and an Android device.

The Nordic SDK comes with an example (nordic/examples/ble_peripheral/ble_app_uart) used for serial communication over BLE. For more info:

I download the SDK modified to compile with open-source toolchains:

For more info read me previous post:

The compilation was not so easy as it is supposed to do. I got some undefined references, like this one:

.../newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk' 

I fixed it editting “relayr/ld/libc-nano.ld” file and adding:


Also I created a custom board definition based on wunderbar-master-nrf.h

$ cp relayr/include/wunderbar-master-nrf.h relayr/include/custom_board.h

And finally created a with all files needed to compile the example:


SDKINCDIRS+= toolchain toolchain/gcc drivers_nrf/hal device libraries/scheduler
SDKINCDIRS+= softdevice/common/softdevice_handler libraries/timer
SDKINCDIRS+= ble/ble_advertising libraries/button ble/ble_services/ble_nus
SDKINCDIRS+= drivers_nrf/uart drivers_nrf/gpiote drivers_nrf/config drivers_nrf/common
SDKINCDITS+= drivers_nrf/hal libraries/fifo

EXPINCDIR+= ble_peripheral/ble_app_uart/config

SDKSRCS+= toolchain/gcc/gcc_startup_nrf51.s toolchain/system_nrf51.c
SDKSRCS+= libraries/timer/app_timer.c
SDKSRCS+= ble/common/ble_advdata.c
SDKSRCS+= ble/common/ble_conn_params.c
SDKSRCS+= softdevice/common/softdevice_handler/softdevice_handler.c
SDKSRCS+= libraries/scheduler/app_scheduler.c
SDKSRCS+= libraries/timer/app_timer_appsh.c
SDKSRCS+= drivers_nrf/uart/app_uart_fifo.c
SDKSRCS+= ble/ble_services/ble_nus/ble_nus.c
SDKSRCS+= ble/ble_advertising/ble_advertising.c
SDKSRCS+= libraries/button/app_button.c
SDKSRCS+= drivers_nrf/gpiote/nrf_drv_gpiote.c
SDKSRCS+= drivers_nrf/common/nrf_drv_common.c
SDKSRCS+= libraries/fifo/app_fifo.c

EXPSRCS+= bsp/bsp.c
EXPSRCS+= bsp/bsp_btn_ble.c


SDKDIR:= $(abspath $(dir $(lastword ${MAKEFILE_LIST})))
ifndef SDDIR
SDKINCDIRS+= softdevice/${USE_SOFTDEVICE}/headers
CFLAGS+= -I${SDDIR}/include

SOFTDEV_HEX?= $(lastword $(wildcard ${SDKDIR}/nordic/components/softdevice/${USE_SOFTDEVICE}/hex/${USE_SOFTDEVICE}*softdevice.hex))

SDKINCDIRS+= $(sort $(dir ${SDKSRCS}) )

SRCS+= $(patsubst %,${SDKDIR}/nordic/examples/%,${EXPSRCS})

ifdef USE_RTX
SRCS+= ${SDKDIR}/nordic/external/rtx/port/RTX_Conf_CM.c
CFLAGS+= -I${SDKDIR}/nordic/external/rtx/include
LDLIBS+= ${SDKDIR}/nordic/external/rtx/source/GCC/libRTX_CM0.a

ifeq ($(filter FALSE false NO no 0,${USE_SIMBLE}),)
include ${SDKDIR}/relayr/src/

CPPFLAGS+= $(patsubst %,-D%,${DEFINES})

CFLAGS+= -I${SDKDIR}/relayr/include
CFLAGS+= $(patsubst %,-I${SDKDIR}/nordic/examples/%,${EXPINCDIR})

CFLAGS+= $(patsubst %,-I${SDKDIR}/nordic/components/%,${SDKINCDIRS})
CFLAGS+= -mcpu=cortex-m0 -mfloat-abi=soft -mthumb -mabi=aapcs	\
	-ffunction-sections -fdata-sections -fno-builtin \
CFLAGS+= -std=gnu11
CFLAGS+= -fshort-wchar -Wl,--no-wchar-size-warning
CFLAGS+= -Wall -Wno-main -Werror


LDFLAGS+= -Wl,--gc-sections -fwhole-program --specs=nano.specs
LDFLAGS+= -Wl,-Map=${PROG}.map
LDFLAGS+= -Wl,-T,${SDKDIR}/relayr/ld/libc-nano.ld
LDFLAGS+= -Wl,-L${SDKDIR}/relayr/ld
LDFLAGS+= -Wl,-L${SDKDIR}/nordic/components/toolchain/gcc
LDFLAGS+= -lgcc -lc -lm -lg -lrdimon -lnosys

ASFLAGS+= -x assembler-with-cpp

SRCS+=	$(patsubst %,${SDKDIR}/nordic/components/%,${SDKSRCS})

CC=	arm-none-eabi-gcc
OBJCOPY=	arm-none-eabi-objcopy
OBJDUMP=	arm-none-eabi-objdump
GDB=	arm-none-eabi-gdb

GENERATE.d=	$(CC) -MM ${CFLAGS} ${CPPFLAGS} -MT $@ -MT ${@:.d=.o} -MP -MF $@ $<

all: ${PROG}.hex ${PROG}.bin

define compile_source
ifneq ($(filter %.c %.S %.s,${1}),)
$(addsuffix .o,$(notdir $(basename ${1}))): ${1}
	$${COMPILE$(suffix ${1})} $${OUTPUT_OPTION} $$<

ifneq ($(filter %.c,${1}),)
$(addsuffix .d,$(notdir $(basename ${1}))): ${1}

OBJS+=	$$(addsuffix .o,$(notdir $(basename ${1})))

$(foreach f,${SRCS},$(eval $(call compile_source,$f)))

ifneq (${MAKECMDGOALS},clean)
-include $(patsubst %.o,%.d,${OBJS})

CLEANFILES+= ${OBJS} ${OBJS:.o=.d} ${PROG}.hex ${PROG}.elf ${PROG}.bin ${PROG}.map ${PROG}.jlink ${PROG}-all.jlink

${PROG}.elf: ${OBJS}
	${CC} -o $@ ${CFLAGS} ${LDFLAGS} ${OBJS} ${LDLIBS}

%.hex: %.elf
	${OBJCOPY} -O ihex $< $@

%.bin: %.elf
	${OBJCOPY} -O binary $< $@

%.jlink: %.hex
	${OBJDUMP} -h $< | \
	awk '$$1 ~ /^[0-9]+$$/ {addr="0x"$$5; if (!min || addr < min) min = addr} END { printf "\
	loadbin %s,%s\n\
	exit\n", f, min}' f="$ $@

%-all.jlink: %.jlink ${SOFTDEV_HEX} FORCE
	@[ -e "${SOFTDEV_HEX}" ] || echo "cannot find softdevice hex image '${SOFTDEV_HEX}'" >&2
	# w4 0x4001e504, 0x2 -> enable erase: CONFIG.WEN = EEN
	# w4 0x4001e50c, 0x1 -> erase all: ERASEALL = 1
	printf "\
	device NRF51822_XXAA\n\
	w4 0x4001e504, 0x2\n\
	w4 0x4001e50c, 0x1\n\
	sleep 1\n\
	loadbin %s,0\n" ${SOFTDEV_HEX} > $@
	cat $> $@

flash: ${PROG}.hex ${PROG}.jlink
	JLinkExe -device nRF51822_xxAA -if SWD ${PROG}.jlink

flash-all: ${PROG}.hex ${SOFTDEV_HEX} ${PROG}-all.jlink
	JLinkExe -device nRF51822_xxAA -if SWD ${PROG}-all.jlink

gdbserver: ${PROG}.elf
	JLinkGDBServer -device nRF51822_xxAA -if SWD

gdb: ${PROG}.elf
	${GDB} ${PROG}.elf -ex 'target extended-remote :2331'

GITREV= $(shell git describe --always)

mailfile: ${MAILFILE}
	-$(foreach f,$(filter-out $<,$(wildcard ${PROG}-*.hex)),rm $f;)
	-@md5sum $<
	-@sha256sum $<

${PROG}-${GITREV}.hex: ${PROG}.hex
	cp $< $@

	-rm -f ${CLEANFILES}

.PHONY: all flash flash-all gdbserver gdb clean FORCE

Running NuttX on a less than U$2.00 board

Few months ago I discovered a low cost board powered by STM32F103C8T6 microcontroller.

That board is referenced as “STM32 Minimum System Development Board” or as “BluePill Board”:

I bought that board from Aliexpress for U$1.96:

Then when it arrived I got NuttX running on it and submitted a patch to Mr. Greg to add it to NuttX mainline. Now everybody can get NuttX running on it easily.

This tutorial will explain how to do that, first let me list what you will need:
– The STM32F103C8T6 Minimum board;
– A STLinkV2 programmer (or a low cost clone) ;
– A USB/Serial adapter 3.3V compatible (like this one on ebay);
– A USB to MicroUSB cable, like these used to recharge your smartphone;
– A computer running Linux Debian or Ubuntu (it is possible on Windows using Cygwin or Mac OS, but I don’t use these OS).

First step is the instalation of development tools:
1) Install gcc-arm-none-eabi package:

$ sudo apt-get install gcc-arm-none-eabi

2) Compile and install OpenOCD
Note: If your system doesn’t have the development tools and libraries then install these packages listed here:

$ git clone
$ cd openocd
$ ./bootstrap
$ ./configure --enable-internal-jimtcl --enable-maintainer-mode --disable-werror --disable-shared --enable-stlink --enable-jlink --enable-rlink --enable-vsllink --enable-ti-icdi --enable-remote-bitbang

You will see it at end of this process:

libjaylink configuration summary:
 - Package version ................ 0.1.0
 - Library version ................ 0:0:0
 - Installation prefix ............ /usr/local
 - Building on .................... x86_64-pc-linux-gnu
 - Building for ................... x86_64-pc-linux-gnu

OpenOCD configuration summary
MPSSE mode of FTDI based devices        yes (auto)
Segger J-Link JTAG Programmer           yes
ST-Link JTAG Programmer                 yes
TI ICDI JTAG Programmer                 yes
Keil ULINK JTAG Programmer              yes (auto)
Altera USB-Blaster II Compatible        yes (auto)
Versaloon-Link JTAG Programmer          yes
OSBDM (JTAG only) Programmer            yes (auto)
eStick/opendous JTAG Programmer         yes (auto)
Andes JTAG Programmer                   yes (auto)
USBProg JTAG Programmer                 yes (auto)
Raisonance RLink JTAG Programmer        yes
Olimex ARM-JTAG-EW Programmer           yes (auto)
CMSIS-DAP Compliant Debugger            yes (auto)

Now compile and install it:

$ make
$ sudo make install

Now the next step is download and compiling NuttX:

1) Download the NuttX kernel and its applications:

$ mkdir NuttX
$ cd NuttX
$ git clone
$ git clone
$ git clone

2) Compile the Kconfig Frontend needed by NuttX:

$ cd tools/kconfig-frontends
$ ./configure
$ make
$ sudo make install

3) Compile NuttX for stm32f103-minimum board:

$ cd ../..
$ cd nuttx/tools
$ ./ stm32f103-minimum/nsh
$ make menuconfig

Enter into "Build Setup" menu and confirm that "Build Host Platform" is defined to Linux
Enter in "System Type" -> "Toolchain Selection" and confirm that:
(X) Generic GNU EABI toolchain under Linux

Select <EXIT> and confirm to save everything.

Now you can compile it:

$ make

At end of compilation you will see:

make[2]: Leaving directory '/tmp/NuttX/nuttx/configs/stm32f103-minimum/src'
LD: nuttx
make[1]: Leaving directory '/tmp/NuttX/nuttx/arch/arm/src'
CP: nuttx.bin

3) Flashing the firmware nuttx.bin in the stm32f103-minimum board:
Connect the USB Cable and the STLinkV2 programmer to STM32F103 board this way:

Create a file openocd_stm32f1.cfg with this content:

# Using stlink as SWD programmer
source [find interface/stlink-v2.cfg]

# SWD as transport
transport select hla_swd

# Use STM32F103 target
source [find target/stm32f103c8t6.cfg]

Execute OpenOCD passing this configuration file:

$ sudo openocd -f openocd_stm32f1.cfg

Open On-Chip Debugger 0.10.0-dev-00300-g89bf96f-dirty (2016-05-20-17:42)
Licensed under GNU GPL v2
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.297181
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints

Open a new shell terminal and execute:

$ telnet 4444

You will be presented with this message:

Connected to
Escape character is '^]'.
Open On-Chip Debugger

Now execute this command to store nuttx.bin in the stm32f103 flash memory:

> reset halt

stm32f1x.cpu: target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080003ac msp: 0x20000730

> flash write_image erase nuttx.bin 0x08000000

auto erase enabled
device id = 0x20036410
ignoring flash probed value, using configured bank size
flash size = 128kbytes
stm32f1x.cpu: target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000730
wrote 40960 bytes from file nuttx.bin in 2.384699s (16.774 KiB/s)

Finally all you need to do is to connect a USB/Serial and use a Serial Console as Minicom/Picocom/Screen to get access to NuttX terminal .

|USB/Serial | STM32F103 Board |
|   RXD     |       A9        |
|   TXD     |      A10        |
|   GND     |       G         |

Configure Minicom or use your preferred serial program to 115200 8n1 with your USB/Serial adapter, i.e /dev/ttyUSB0. You will get this message after pressing the RESET button:

NuttShell (NSH)

Getting started with RFM69

The RF transceivers RFM69 are really nice for low power applications. There are many projects using it currently.

It supports FSK, GFSK, MSK, GMSK and OOK modulations. Also it has AES and CRC-16 engines internally.

I decide to list some projects here as future reference.

First project is called RadioHead (no! it is not the music band). The main advantage of RadioHead is because it supports many types of transceivers (nRF24, CC1100, MRF89, etc) :

The second project is from LowPowerLab, it is devoted exclusively to RFM69 family:

Other project devoted to RFM69 is plainRFM69, this project has some optimization to enter on low power mode as soon os possible and doesn’t have all features from previous project:

There is an interesting thread from iwanders (Ivor Wanders is the author of plainRFM69) :

Another interesting project: Using a RFM69 to control a KaKu switch with OOK modulation:

I receive some RFM69HW modules (bought from Alibaba) and my plan is to use it with NuttX, this transceiver has many features, then creating a Network Driver is not so easy. The datasheet is here:

Running NuttX on Teensy 3.1

The PJRC Teensy 3.1 board is a very nice and powerful board. It has a small form-factor powered by NXP/Freescale MK20DX256 ARM Cortex-M4 microcontroller at 72MHz.

Normally it is used to run Arduino compatible sketches. Since I’m not a great Arduino fan the logic thing to do is run something else on it.

Fortunately NuttX has support to this board.

These are the steps I did to get it running:

1) Download the teensy loader for your platform:

$ gunzip teensy.64bit.gz 
$ mv teensy.64bit teensy_loader
$ chmod a+x teensy_loader
$ sudo cp teensy_loader /usr/local/bin/

3) Get the udev rules and copy it to right place:

$ wget
Resolving (
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1622 (1.6K) [text/plain]
Saving to: ‘49-teensy.rules’

49-teensy.rules                100%[=================================================>]   1.58K  --.-KB/s    in 0s      

2016-04-16 15:23:31 (47.7 MB/s) - ‘49-teensy.rules’ saved [1622/1622]

$ sudo cp 49-teensy.rules /etc/udev/rules.d/

3) Clone NuttX mainline bitbucket apps and nuttx repositories.

$ mkdir nuttx_teensy
$ cd nuttx_teensy
$ git clone
$ git clone

4) Compile NuttX to Teensy 3.1:

$ cd nuttx
$ cd tools/
$ ./ teensy-3.x/nsh
$ cd ..
$ make menuconfig
  Build Setup  --->
    Build Host Platform (Linux)  --->

$ make
LD: nuttx
make[1]: Leaving directory '/comum/workspace/NuttX/nuttx/nuttx/arch/arm/src'
CP: nuttx.hex
CP: nuttx.bin

5) Plug Teensy 3.1 on USB cable and press the board’s button.

6) Now run the teensy loader:

$ teensy_loader
File ->
  Open HEX File
    Select nuttx.hex

Click on Program icon Button it will program nuttx.hex in the board

7) Connect a USB/Serial 3.3V to Teensy 3.1 board, this way:

USB Serial | Teensy Board pin
   GND     |       GND
   TXD     |        0
   RXD     |        1

8) Run minicom or other serial console program
Configure it to use your USB/Serial port as 115200 8n1

Now in the teensy load program click on Reset icon Button, the NuttX shell will appear:

NuttShell (NSH)
nsh> ?
help usage:  help [-v] []

  [           cmp         free        mkfifo      set         unset       
  ?           dirname     help        mh          sh          usleep      
  basename    dd          hexdump     mv          sleep       xd          
  break       echo        kill        mw          test        
  cat         exec        ls          pwd         time        
  cd          exit        mb          rm          true        
  cp          false       mkdir       rmdir       uname       

Builtin Apps: