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 https://launchpad.net/ubuntu/+source/openocd or specifically:

wget https://launchpad.net/ubuntu/+archive/primary/+files/openocd_0.9.0.orig.tar.gz

and unzipped it:

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

There's an INSTALL file that gives basic instructions:

./configure
make
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:

./run-openocd.sh

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

https://answers.launchpad.net/ubuntu/
https://github.com/Microsoft/BashOnWindows/issues/

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:

http://hackaday.com/2017/03/07/open-source-firmware-for-a-cheap-programmable-power-supply/

Or more directly, Johan's blog here:

https://johan.kanflo.com/hacking-the-dps5005/

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:



http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f100-value-line/stm32f100c8.html

"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

https://github.com/libopencm3/libopencm3

@ChuckM over on the libopencm3 gitter:

https://gitter.im/libopencm3/

...suggested that I install the WSL

https://msdn.microsoft.com/en-us/commandline/wsl/install_guide

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:

https://developer.arm.com/open-source/gnu-toolchain/gnu-rm

specifically:

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:

https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads

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!

 C:/workspace/opendps/openocd/scripts

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

/c/workspace/opendps/openocd/scripts

and the Ubuntu Bash sees it as:

/mnt/c/workspace/ ...

the libopencm3.rules.mk 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: http://www.instructables.com/id/Power-Supply-Automation-DPS5015-DP50V5A-Controlled/

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

https://rdtech.aliexpress.com/store/923042

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 hackaday.io.

https://hackaday.io/project/20552-cpm-8266

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:

https://github.com/gojimmypi/build_esp8266

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/esptool.py

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

source ./doPathLink.sh

From their instructions, I only needed add a few additional items not covered in my Build_esp8266.sh 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:

http://blogs.paasmer.co/series-blogs-connect-esp-8266-nodemcu-aws-iot/

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:

http://docs.aws.amazon.com/cli/latest/userguide/installing.html

simply, really: in a git bash shell:

pip install --upgrade --user awscli

then add the path:

http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-windows.html#awscli-install-windows-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):

https://console.aws.amazon.com/iam/home?/security_credential

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:

http://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html

...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:

https://github.com/aws/aws-cli/issues/2535

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:

http://jpmens.net/2013/09/01/installing-mosquitto-on-a-raspberry-pi/

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:

https://aws.amazon.com/blogs/iot/elliptic-curve-cryptography-and-forward-secrecy-support-in-aws-iot-3/

Specifically this command:

mosquitto_pub --cafile AWSIoTCACert.crt --cert eccCert.crt --key ecckey.key -h a2s48sx7uszy0k.iot.us-west-2.amazonaws.com -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:

http://iot-hackseries.s3-website-us-west-2.amazonaws.com/aws-iot.html

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

https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem

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 a2s48sx7uszy0k.iot.us-west-2.amazonaws.com -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.




Find gojimmypi at gojimmypi.github.io

I'm currently working on my new blog home at  gojimmypi.github.io After implementing a variety of features such as dark mode , syntax hi...