-->
Page 1 of 2

How to use a 40MHz crystal instead of default 26MHz crystal

PostPosted: Wed Feb 10, 2016 8:55 pm
by gaber
FYI: there is a set of memory addresses associated with the RF initconfig on the ESP8266. They are detailed in the file called ESP8266_RF_init.xls in the Flash Tool 2.4 (http://bbs.espressif.com/viewtopic.php?f=5&t=433).

Address 0x30 is important because if it is 1 then you are setup to use the 26MHz crystal, and if 0, then it uses a 40MHz crystal--default is 1, so 26MHz crystal is required. The offset address for that value is different depending upon your code base, but it appears it is quite commonly at 0x7C030. On my setup it is also at that location. Many people are aware of this that are doing the unofficial SDK work -- but I did not see a nice shortcut to changing the crystal setting using esptool.

If you want to use a 40MHz crystal, you need to change a byte in the flash at address 0x7C030 from 1 to 0. If your board has a 26MHz crystal, don't do this.

1. Flash your code to your ESP8266 SPI flash as you normally would using esptool
2. run the following commands to change from 26MHz to 40MHz crystal source (only do this if you physically have a 40MHz crystal on your ESP8266 board): (run each one line by line to make sure each one succeeds)

./esptool.py read_flash 0x7C000 128 rfblock.bin

printf '\x00' | dd conv=notrunc of=rfblock.bin bs=1 seek=$((0x30))

./esptool.py write_flash 0x7C000 rfblock.bin


3. Explanation: The first command reads back the 128 bytes from the RF init block, the second command changes the value at address 0x30 from 0x01 to 0x0, then the third command writes everything back.

4. You may need to hit the reset button after the flash read/write commands to get the chip to wake up into UART debug mode and allow reading/writing spi flash

Hopefully its helpful to somebody.

-Gabe

Re: How to use a 40MHz crystal instead of default 26MHz crys

PostPosted: Mon Feb 15, 2016 5:32 pm
by gaber
After you create the rfblock.bin file once, you can re-use for later during the flashing process.

For example, here is what I do now:

./esptool.py --port /dev/ttyUSB0 write_flash 0x00000 parse-0x00000.bin 0x40000 parse-0x40000.bin 0x7C000 rfblock-0x7C000.bin

So the 128 byte RF settings block is also written to the flash memory. So you could also just generate different settings binary files using the ESP flash tool 2.4 from windows and use that file. In the windows tool it saves a file called "esp_init_data_setting.bin" which is 128 bytes long. So you just change the name to rfblock-0x7C000.bin and use in the command above.

-Gabe

Re: How to use a 40MHz crystal instead of default 26MHz crys

PostPosted: Wed Oct 26, 2016 4:34 pm
by dmarkey
Hi,

I believe I bought a smart socket with a 40hz crystal(115200 boot messages). However the commands above dont work :(

Any ideas?

Re: How to use a 40MHz crystal instead of default 26MHz crys

PostPosted: Wed Oct 26, 2016 5:20 pm
by martinayotte
Take a look at this thread : viewtopic.php?f=13&t=12175