]]>https://blog.danman.eu/controlling-esc-via-usb/feed/0Turning ST-Link programmer into IR controlled USB keyboardhttps://blog.danman.eu/turning-st-link-programmer-into-ir-controlled-usb-keyboard/
https://blog.danman.eu/turning-st-link-programmer-into-ir-controlled-usb-keyboard/#commentsThu, 08 Mar 2018 17:55:17 +0000https://blog.danman.eu/?p=1029Continue reading Turning ST-Link programmer into IR controlled USB keyboard→]]>As I promised last time, I’m going to continue with st-link programmer clones. This time I wanted to use mbed which has some ready made libraries for utilizing USB and since it was very comfortable to use DFU upload with arduino library, at first I checked if it is usable with mbed too.

Preparing DFU bootloader

So I googled a bit and found this example. It describes how to build and install DFU bootlader. What I like about it is that it resides in the upper 8kB of flash so you don’t need to modify your main application. Because my board has very little pins broken out, I cannot afford to sacrifice one for forcing boot into DFU so I made some changes to the bootloader so it stays in DFU mode after each boot and then starts the main code – similarly like the one in maple_mini. My board has 128kB of flash so I also changed the LDSCRIPT:

Building main application

Next question was how to build working application for my board. Again I’ve found nice example on mbed pages. The key is this section:

Create a program as if it was for a NUCLEO-F103RB board (select NUCLEO-F103RB as target platform for the online compiler). Or click here to import this demo into your online compiler (then you can skip the following two steps).

$ cat /dev/ttyACM0
I am a USB serial prt
I am a USB srial ort
I am a serial port
I am a USB serial po
I am a USBeri
I am SB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
I am a USB serial port
^C
$

The USB serial is a bit buggy (Update: works ok after disabling ModemManager: systemctl stop ModemManagers) but it doesn’t matter, the main point is that it works! But this also works with arduino framework so nothing that new.

Emulating USB keyboard

Next I wanted to try something different. The USBDevice lib includes functions to emulate USB keyboard. So I put together an example which blinks LED and sends CapsLock key so it also makes your keyboard blink. You can find it here and the result looks like this:

Using PlatformIO

Then I wanted to recreate the blinking keyboard using PlatformIO so I took the mbed-blink code (which worked) and replaced the main.cpp with the one from project above. At first it was not working and I opened issue on github but then I found out that the USB library is probably not correctly linked in and only needs correct configuration. I solved this by putting line in platformio.ini:

lib_deps = https://os.mbed.com/users/hudakz/code/USBDevice_STM32F103/

This way I got working binary for upload with DFU.

Automating DFU upload

Until now I was still manually uploading the compiled binary with dfu-util. But I wanted to integrate it with PlatformIO so it would be uploaded automatically. PIO allows you to add custom upload/build scripts. So I made one which modifies upload process to use my own script which in turn uses dfu-util.

The working project can be found here and the upload is super comfortable. Just press upload in PIO, reinsert USB dongle when asked and it’s done.

The result

When I had all components ready, it was time to create something useful. With just 1 additional component I decided to create IR remote control receiver. For this I used SFH-506 IR demodulator. Connection was easy: just VCC, GND and one signal pin. The pin pitch after desoldering pin header was correct but not a perfect match with receiver, so I helped it with one jumper wire:

I was quite satisfied with the resulting look. Next step was to write the software. Similarly as the arduino framework, mbed has many ready-to-use libraries and I was hoping to find one, which will process IR signals and fortunately I’ve found one. So I just took the example code, let the output print to USBSerial and watched the result after pressing keys:

After assembling and turning it on, Android 7 popped up but this was not my target OS. I wanted to use LibreELEC so I followed installation howto: downloaded and burned latest image to SD card, replaced dtb file with gxl_p212_1g.dtb, and run reboot update from Android terminal.

Box rebooted into working LibreELEC, nice! Now I wanted to burn it into internal eMMC so I run installtointernal despite a big red warning on howto page and warning in the script itself, rebooted and… I got sad. The LED was blinking red-blue and the box stopped booting. I tried all voodoo recovery instructions (holding reset button, powering from both usb and adapter, with HDMI, without it…) to boot into upload mode where the box would be detected by a PC and I would use USB Burning Tool but nothing helped. I also wrote to the seller to get help, they’ve sent me USB Burning Tool, factory image and Upgrade instruction which was nice but it didn’t work either.

So I hooked up serial interface to see what’s going on insideand the result was following:

The box was in a boot loop without accepting any input or keystrokes. Some guides suggest to short out some pins on flash chip but my eMMC has BGA package so this was not possible. I randomly shorted out some resistors and capacitors nearby the eMMC but without luck. I was afraid I’ll need to use JTAG which seemed quite hard to solder and there were no howtos for using this method. Then I took some time to rethink this.

The point of shorting out pins is to avoid detecting the eMMC and to force the main chip boot into upload mode. So to avoid detecting it, it should be enough to break the communication by grounding some of the DATA, CLK or CMD lanes. So again I took ampermeter (to see if I’m not grounding power lane), attached one probe to GND and with the other one I was probing pins around the eMMC chip. After few tries, the status LED stayed blue and the board got detected, bingo!

For those with the same board, it was this pin:

Now it was just a piece of cake, I connected it to Windows machine, grounded pin again and used the upload utility:

Of course I tried to run and install LibreELEC to eMMC again but this time it worked and I wasn’t able to simulate the boot loop again, even with uploading garbage to /dev/dtb.

Hope this guide will help someone, if you have some questions or ideas please leave a comment.

These are for DLP-Link projectors which can quickly strobe white frame between video frames for shutter signalling. You can read more about this technology here. They use specialized chip TPS65835 which integrates most of the needed functionality. Maybe I’ll try some hacking on this later.

]]>https://blog.danman.eu/cheap-433mhz-receivers-comparison/feed/0Old radio clock upgraded to NTPhttps://blog.danman.eu/old-radio-clock-upgraded-to-ntp/
https://blog.danman.eu/old-radio-clock-upgraded-to-ntp/#respondSat, 20 Jan 2018 14:56:36 +0000https://blog.danman.eu/?p=945Continue reading Old radio clock upgraded to NTP→]]>I own the radio clock on the title picture. I’ve used it for some time but it annoyed me because it drifted a lot (several seconds a day). It’s synchronized to power network frequency but it doesn’t work well in my case and I hate to adjust the clock over and over again. So I decided to sync it automatically using esp8266.First I opened it up to see what’s inside.

The heart of the clock is SC8560 and it’s implemented very similarly as the reference circuit in the datasheet. My first idea was to disconnect a clock signal (derived from network) and increase minute and hour counter by cron on esp each minute. But when I disconnected the clock signal, the display went off because the input clock also drives display driver.

Then I wanted to create my own 50Hz clock source but it needs to be about 9V peak-to-peak which would require more external components so I decided not to.

My last idea was to keep the original clock source but to reset the device daily so the inaccuracy is only few seconds in worst case. When you unpower the device the time resets to 0:00 but starts blinking annoyingly and stops only after you set the time so I needed to hook up to 2 circuits: power and hour setting. I also needed to get some power for the esp8266 so I started with this.

The SC8560 is powered by half-wave rectified 9V AC (one diode and capacitor) so I connected my NodeMCU Amica board to the same rail (the board has onboard 3.3V LDO regulator so it can be powered by 9V) but it didn’t work. When I measured the power waveform half of the time it was zero due to high power consumption by esp so I decided to add my own full-wave rectifier and capacitor behind AC transformer. This worked very well so I moved to controlling the main chip. This solution also implies using optocouplers to controll the main circuit.

So I started to poke with the main chip power circuit to find out how to reset it. There are many wire connections on the upper side of the main board so I tried disconecting one which leads to Vss. Current through this connection was about 60mA which is quite high for using basic optocoupler so I also tried to measure the Vdd connection. This was much better with current only about 6mA so I cut it and soldered my optocoupler instead.

Next I also needed to set hours and this was done with other optocoupler soldered between pin 22 and Vss. On the input side of both optocouplers I soldered jump wires which were connected to Amicas output pins. esp8266 can source maximum of 12mA so I didn’t solder any limiting resistor between. The result looked like this:

It’s not prettiest but it does the job. I also needed to remove the speaker to make the module fit into the case but I don’t regret it – I wasn’t using it either. The rest was only to write the program main.lua:

]]>https://blog.danman.eu/openshift-exit-code-137/feed/0How to recover containerized etcd in Openshift clusterhttps://blog.danman.eu/how-to-recover-containerized-etcd-in-openshift-cluster/
https://blog.danman.eu/how-to-recover-containerized-etcd-in-openshift-cluster/#respondThu, 04 Jan 2018 18:20:01 +0000http://blog.danman.eu/?p=921Continue reading How to recover containerized etcd in Openshift cluster→]]>If you tried to add node to your etcd cluster and it failed, your cluster may have lost quorum and will not start again. To recover it you need to create new cluster identity. This is a short howto.

]]>https://blog.danman.eu/how-to-recover-containerized-etcd-in-openshift-cluster/feed/0ST-Link clone as STM32 dev boardhttps://blog.danman.eu/st-link-clone-as-stm32-dev-board/
https://blog.danman.eu/st-link-clone-as-stm32-dev-board/#commentsSat, 23 Dec 2017 21:37:27 +0000http://blog.danman.eu/?p=927Continue reading ST-Link clone as STM32 dev board→]]>Last time I played with this device, I only uploaded gnuk token software and it was done. This time I wanted to try some developement in Arduino framework.

This was easy. Then I connected to newly appeared serial port and it was showing following message in loop:

Congratulations, you have installed the STM32duino bootloader
See https://github.com/rogerclarkmelbourne/STM32duino-bootloader
For more information about Arduino on STM32
and http://www.stm32duino.com

So it worked, at least somehow…

Then I wrote a simple LED blink program using PlatformIO and ststm32 module. But when I tried to upload it, it was not working. So I opened an issue here to get some help but none of the advices worked so I tried to debug it myself.

The upload script sends special sequence to tell the bootloader to restart the device. The bootloader pulls USB D+ pin low for some time and then returns it back to USB interface. This should trigger re-enumeration in USB host (PC) and boot into DFU mode. DFU is active for a few seconds after start and then starts our main program. But this was not happening, the device didn’t reboot. I even tried to add 1k5 resistor from USB D+ to VCC but without success.

So I changed the upload script so it shows message and waits for any device in DFU mode (for details see my pull request).

After this, when I saw the message, I unplugged and plugged back in my board, it got detected, firmware was uploaded and program was running. Finally!

Thermometer

To build something useful, I decided to use DHT11 sensor I had on hand. This was only matter of finding the right Arduino library and setting right input pin. You can see the project here:

And it also looks good assembled which is the main reason for preferring this board over some generic STM32 dev board.

I can imagine this board can be used for processing and sending some data to PC where you need exact timing or bit banging with external device. I tested maximum achieved transfer rate and it was about 600kB/s which is not bad.

I have one or two more ideas how to use this board so be prepared for the next blog