How to use a 40MHz crystal instead of default 26MHz crystal
Posted: Wed Feb 10, 2016 8:55 pm
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
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