Skip to content

Commit

Permalink
Easier voltage reading for ESP8266. (#2264)
Browse files Browse the repository at this point in the history
  • Loading branch information
slaff authored Mar 15, 2021
1 parent 89e8089 commit 8218fe7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
25 changes: 25 additions & 0 deletions Sming/Arch/Esp8266/Components/esp8266/Tools/patch-phy-bin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
########################################################
#
# Simple PHY binary patcher
# Author: Slavey Karadzhov <[email protected]>
#
########################################################
import os
import sys

def usage():
print("Usage: \n\t%s <file.bin> [offset]" % sys.argv[0])

if __name__ == "__main__":
if len(sys.argv) not in list(range(2,4)):
usage()
sys.exit(1)

offset = 107
if len(sys.argv) > 2:
offset = int(sys.argv[2])

with os.fdopen(os.open(sys.argv[1], os.O_RDWR | os.O_CREAT), 'rb+') as f:
f.seek(offset)
f.write(bytearray(b'\xff'));
9 changes: 8 additions & 1 deletion Sming/Arch/Esp8266/Components/esp8266/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ SDK_BASE ?= $(COMPONENT_PATH)/ESP8266_NONOS_SDK

SDK_BASE := $(call FixPath,$(SDK_BASE))
FLASH_INIT_DATA = $(SDK_BASE)/bin/esp_init_data_default.bin
FLASH_INIT_DATA_VCC = $(SDK_BASE)/bin/esp_init_data_vdd_default.bin

CUSTOM_TARGETS += $(FLASH_INIT_DATA)
CUSTOM_TARGETS += $(FLASH_INIT_DATA) $(FLASH_INIT_DATA_VCC)

# => 'Internal' SDK - for SDK Version 3+ as submodule in Sming repository
# SDK_BASE just needs to point into our repo as it's overridden with the correct submodule path
Expand All @@ -24,6 +25,12 @@ else
SDK_INTERNAL := 0
endif

PHY_TOOL := $(COMPONENT_PATH)/Tools/patch-phy-bin.py

$(FLASH_INIT_DATA_VCC): $(FLASH_INIT_DATA)
$(Q) cp $< $@
$(Q) $(PYTHON) $(PHY_TOOL) $@

DEBUG_VARS += SDK_LIBDIR SDK_INCDIR
SDK_LIBDIR := $(SDK_BASE)/lib
SDK_INCDIR := $(SDK_BASE)/include
Expand Down
2 changes: 1 addition & 1 deletion docs/source/information/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Information
debugging
rboot-ota
command-handler
hot-tips
tips-n-tricks
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
Hot Tips!
=========
Tips and Tricks
===============

.. highlight:: c++

Reading VCC on ESP8266
----------------------
If you are running on a battery operated device then function `system_get_vdd33()` from
the official ESP8266 NONOS SDK can help you read the power voltage.
For the latter to work properly you should make a small change in your application `component.mk`
file and add `vdd` to the `HWCONFIG_OPTS` configuration variable.

If you cannot see such a variable in your `component.mk` file then append the following line to it::

HWCONFIG := vdd

You can have multiple options selected. They should be separated by comma.
For example the command below will add 4MB flash, spiffs and vdd support::

HWCONFIG := 4m,spiffs,vdd

You can check the final hardware configuration using the command below::

make hwconfig

If a custom hardware configuration is needed then read :component:`Storage`.

Minimising Memory Usage
-----------------------

Expand Down Expand Up @@ -37,7 +59,7 @@ version::
See :component:`FlashString` for further details.

Webpages Performance
====================
--------------------

HTML markup can get quite large and the bigger the file the slower the
page loads. One way to deal with that is to remove the white space, this
Expand Down

0 comments on commit 8218fe7

Please sign in to comment.