Saturday, April 29, 2017

Installing OpenOCD on Windows WSL Ubuntu

While working on my OpenDPS Project I needed to use OpenOCD onw Windows. I cheated and used the one that came with VisualGDB running in a DOS Window:

from the \openocd\scripts directory:

C:\Users\gojimmypi\AppData\Local\VisualGDB\EmbeddedDebugPackages\com.sysprogs.arm.openocd\bin\openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg

but really, I want to have OpenOCD in Ubuntu.

So I downloaded it from or specifically:


and unzipped it:

tar -xzvf openocd_0.9.0.orig.tar.gz 

There's an INSTALL file that gives basic instructions:

sudo make install

if you don't use "sudo" on that last command, you'll get this wonderfully intuitive error:

(ho - and people wonder why Windows is so popular.. but I digress...)

Now from the /openocd/scripts directory, this command:

openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg

or simply:


from the /openocd directory.

well, it does not find my ST-LINK, or any other USB devices. It seems WSL does not recognize any of my USB ports.

$ lsusb
unable to initialize libusb: -99

On to installing the toolchain in a Debian VM....

If there are problems, well there's

Friday, April 28, 2017

OpenDPS with the DPS5015

Once again, I found an awesome project via twitter, this time from Johan Kanflo via this article from hackaday folks:

Or more directly, Johan's blog here:

After reading the details, I promptly ordered my own device, specifically this RD DPS5015 Buck Power Supply LCD color display step-down voltage converter on eBay. This DPS is similar, but different than the one Johan used, going on the assumption that it is similar: "Although this guide is written for the ‘5005 it should work for the entire DPS family but I only have 5005s to test with."

Upon inspection, I found that the onboard processor is an 32F100C8T6B with the LQFP48 pinout using the same pin configuration as on the DPS5005 in Johan's project:

"Medium-density devices are STM32F100x8 and STM32F100xB microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes." [*1]

The [x] is a placeholder for only 1 character, not "all characters until the end, excluding the last B". The "B" in STM32F100CB means "128KB". This is not to be confused with STM32F100C8 or in the case of the DPS5015 - the STM32F100C8T6B - which are 64KB devices.

Don't confuse the 8 or B  with the trailing "B" on the end, That last B is an "Internal Code" having nothing to do with flash size.

I had OpenOCD for Windows installed via the sysprog VisualGDB app, so I used  that one:

cd C:\SysGCC\esp8266\esp8266-bsp\OpenOCD\share\openocd\scripts
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg

Compiling on Windows turned out to be a real pain, giving lame errors like this:

GENHDR include/libopencm3/stm32/l1/irq.json
GENHDR include/libopencm3/stm32/l4/irq.json
GENHDR include/libopencm3/vf6xx/irq.json
BUILD lib/stm32/f0
make[1]:  No rule to make target desig.o', needed byC:/workspace/libopencm3/lib/libopencm3_stm32f0.a'. Stop.
make:  [lib/stm32/f0] Error 2

@ChuckM over on the libopencm3 gitter:

...suggested that I install the WSL

and so ok, once I have Ubuntu on Windows (am I the only one to find that crazy?!?! *Ubuntu* on *Windows* - wow!)... all the toolchain items need to be installed fresh. None of the Windows binaries will run. So I installed the items listed here:


sudo apt-get update
sudo apt-get install binutils
sudo apt-get install gcc
sudo apt-get install gdb
sudo apt-get install make
sudo apt-get install build-essential

sudo apt-get install python
sudo apt-get install gawk

sudo apt-get install openocd

then download the GNU ARM Embedded Toolchain from:

sudo tar -xvjf gcc-arm-none-eabi-6-2017-q1-update-linux.tar.bz2

(I put mine in c:\Downloads\arm\  aka  /mnt/c/download/arm in Ubuntu window)

All this ended up needing a path like this:

export PATH="/usr/bin/Python27:/mnt/c/download/arm/gcc-arm-none-eabi-6-2017-q1-update/bin:/usr/local/bin:/usr/bin:/bin"

I ended up hosting the OpenOCD from MINGW64 bash prompt, but programming via the Ubuntu bash prompt (this is NOT a good idea). The problem is with the apparent path. When doing a "make flash" - I kept getting a "couldn't open opendps.elf" error (yet the file was there).

Doing a "pwd" from the OpenOCD telnet session revealed all!


This is despite the fact that MINGW64 sees the path as:


and the Ubuntu Bash sees it as:

/mnt/c/workspace/ ...

the file had this simple command for "make flash":

program $(*).elf verify reset exit
so I used a manual command in the OpenOCD telnet session:

program c:/workspace/opendps/opendps/opendps.elf verify reset

and voila! a newly programmed  DPS5015!

Other stuff:

I found a couple of nice cases on Aliexpress: this console-style and this this shelf unit style.

There's also this interesting hack that uses an Arduino to control the unit by emulating the button presses:

The Hangzhou Ruideng Technologies Co., Ltd store can be found here:

There's also this video:

Next step: follow Johan's instructions for using ESP8266 for WiFicontrol....

*1 - page 6 of PM0063 Programming manual STM32F100xx value line Flash programming

Thursday, April 27, 2017

Building Z80 Emulator for CP/M on ESP8266 with a Raspberry Pi

Last month I saw an intriguing article on creating a Z80 CP/M Emulator on my favorite device - the ESP8266 on

My first real computer was a dual processor 6502 / Z80. That was a bit of a misnomer, as one could not actually use both them at the same time. This was a "Basis 108" Apple II compatible from West Germany: A behemoth of a computer in an awesome cast aluminum case. Essentially the "second" processor was the Z80 add-on board but built-in to the motherboard. The thoughts of revisiting my old friend CP/M was too hard to resist.

I used my existing Build-ESP8266 project on a Raspberry Pi, originally created to ease compiling of MicroPython:

As this script downloads and recompiles everything needed for the ESP8266 toolchain, it was a simple matter to adapt for this Z80 CP/M project.

I only needed to adjust one value in the ./cpm8266/code/Makefile

-FLASHBAUD      =  921600
+FLASHBAUD      =  115200
The speed of 921600 was just too crazy, giving an error at upload time:

Makefile:180: recipe for target 'flashinit' failed
make: *** [flashinit] Error 2
So adjusting down to 115200 solved that problem.

I also had the ESP8266 toolchain installed in slightly different locations. Fortunately everything was parameterized in environment variables. So when using my Build_ESP8266 script the values are:

export ESP8266SDK=/opt/esp-open-sdk/
export ESPPORT=/dev/ttyUSB0
export ESPTOOL=/opt/esp-open-sdk/esptool/

I added these items to my (be sure to run with source command):

source ./

From their instructions, I only needed add a few additional items not covered in my script:

Install prerequisites for cpm8266
apt-get install z80asm cpmtools zip vim-common

After that, a quick compile and upload via "make full" and voila! A working CP/M emulator, shockingly easy!

Many thanks to the SmallRoomLabs folks - this is an awesome project! Seeing a CP/M prompt in a putty window is unbelievable!
Now I wonder if I can get WiFi working from CP/M....

Friday, April 7, 2017

Setting up AWS CLI for IoT

I've been wanting to get my ESP8266 to talk MQTT to AWS.

steverino on twitter provided this link:

But first the AWS Command Line Interface needs to be installed (no sense in making things EASY, eh, takes away all the fun).

So first Amazon has some online instructions:

simply, really: in a git bash shell:

pip install --upgrade --user awscli

then add the path:

which in my case was this: %USERPROFILE%\AppData\Roaming\Python\Scripts

next, after restarting the git bash shell to have the new path available, a simple command:

aws configure

There was some confusion as to what, exactly to enter for the prompt: AWS Access Key ID [None]:

As this page (from [your name] - Security Credentials):

will indicate that you should ensure to have deleted all the (root) Access Keys.

There's also an option to "Get Started with IAM Users"... that's what we want:

...and use the Access key and Secret access key for the first two aws config prompts.

next is to figure out the region (a name without spaces!). In my case, that's us-west-2.

Moving on to the security configuration, I spent hours fussing with the "aws iot create-certificate-from-csr" before before submitting an AWS CLI issue here:

The problem there - was apparently when copy/pasting the aws command, one or more of the dashes were converted to evil dashes (some sort of character that looks and acts like a dash, but is not!)

the corrected command is:

aws iot create-certificate-from-csr --certificate-signing-request file://eccCsr.csr --certificate-pem-outfile eccCert.crt --set-as-active

The MQTT is available for Windows and Linux. The Windows version gives this additional install message:

But I chose the Raspberry Pi version since it is in the main repository (and I was getting an error in Windows):

Install on RPi with this command:

sudo apt-get install mosquitto

but alas, that's not enough ... and there's nothing on the Mosquitto web site to indicate that. But I found this helpful site:

that shows the install command with a few options:

sudo apt-get install mosquitto mosquitto-clients python-mosquitto

OpenSSL also needs to be installed:

sudo apt-get install openssl

and so I'm trying the sample test at:

Specifically this command:

mosquitto_pub --cafile AWSIoTCACert.crt --cert eccCert.crt --key ecckey.key -h -d -p 8883 -q 1 -t foo/bar -i test --tls-version tlsv1.2 -m "HelloWorld" --ciphers ECDHE-ECDSA-AES128-GCM-SHA256

but alas I don't have a "AWSIoTCACert.crt " file,

So I found this link:

That said to "click here" to download this CA:

I saved mine as AWS-root-ca-pem.crt and tried this command:

mosquitto_pub --cafile AWS-root-ca-pem.crt --cert eccCert.crt --key ecckey.key -h -d -p 8883 -q 1 -t foo/bar -i test --tls-version tlsv1.2 -m "HelloWorld" --ciphers ECDHE-ECDSA-AES128-GCM-SHA256

AAARRGH. Got this error:

Client test sending CONNECT OpenSSL Error: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Error: Success

(gotta really love the "Error: Success", eh?)

So far I've spent the better part of the day fussing with this. This is way more difficult than it should be.

Programming the Lattice Semiconductor FPGA iCE40 Ultra Plus Breakout Board iCE40UP5K-B-EVN

FPGA programming the Lattice Semiconductor iCE40 Ultra Plus Breakout Board. (work in progress, come back soon) TL;DR The Diamond Lat...