awk – print text between 2 identical markers in a file

Like this:

awk 'BEGIN{flag=0} /MARKER/{flag = !flag;next} flag' inputfule

Adapted from: here.

esp8266 SPI duplex transfers

I’ve been working with the esp8266 spi driver by MetalPhreak located here. One of the issues I’ve found is that duplex transfers (where you want to both send and receive at the same time) don’t work correctly. If you attempt to call spi_transaction specifying 8 dout_bits and 8 din_bits 16 clocks will be sent (IIRC a receive followed by a transmit).

The misunderstanding is likely down to the fact that the esp8266 has very little documentation. And the SPI registers aren’t documented at all. However the Arduino guys seem to have figured it out and it works correctly in the Arduino IDE board pack for the esp8266.

The trick is to set the SPI_USER register just so. There are 3 bits which control the direction of transfer SPI_USR_MOSI, SPI_USR_MISO and SPI_DOUTDIN (bits 27,28 and 0). In order to send and receive you need to set SPI_DOUTDIN and SPI_USR_MOSI but NOT SPI_USR_MISO. At least that’s what’s worked for me.

I made the following modification to spi_transaction to fix this. Change the line reading:

if(din_bits) {SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MISO);}


  if((din_bits) && (dout_bits)) {
  } else {
    if(din_bits) {SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MISO);}

I’ll probably submit a pull request once I’ve made all the changes required for my project. But in this meantime this should work.

A git pre-commit hook to do SVN style $Date$ substitution

Put the following in .git/pre-commit (make sure it’s executable):

git diff --cached --name-only > commits_list

And the following in .git/post-commit:


if [ -f commits_list ]

	cat commits_list | while read F
 	 echo $PWD/$F
 	 filebase=`basename $F`
 	 sed -i -e 's/\$Date[^$]*\$/\$Date '"$currentdate"'\$/' $PWD/$F
 	 sed -i -e 's/\$Filename[^$]*\$/\$Filename '"$filebase"'\$/' $PWD/$F
	 git add $PWD/$F

	rm commits_list
	git commit --amend --no-verify -C HEAD


Still not extensively tested…

SDG2024x Flash Recovery Files

I’ll update this post with further notes, but these files can be used to recover the SDG2024x with complete corrupt flash (such as you might happen if you put an SD in the internal SD card slot and rebooted the device). The MLO is the u-boot spl, but you need to removed the first 520 bytes. If you upload this over xmodem, followed by u-boot.img over ymodem (do not reboot between uploads) over the internal serial console (exposed on a header) you should get a u-boot prompt. From here you can upload the other images (kernel, rootfs etc.). Alternatively on an SD card and insert it into the SDF2024x and run mmc-all (IIRC) this should also flash all the remaining image files.