Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Esp8266 PHY settings runtime modification #2830

Merged
merged 10 commits into from
Jun 24, 2024
24 changes: 24 additions & 0 deletions Sming/Arch/Esp8266/Components/esp8266/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,27 @@ support code.

Sming uses libraries from the ESP8266 NON-OS SDK version 3, imported as a submodule.
The header and linker files are provided by this Component.


.. envvar:: ENABLE_CUSTOM_PHY

Default: undefined (off)

The ``phy_init`` partition contains data which the ESP8266 SDK uses to initialise WiFi hardware at startup.

You may want to change settings for a certain ROM on the device without changing it for all ROMs on the device.
To do this, build with ``ENABLE_CUSTOM_PHY=1`` and add code to your application::

#include <esp_phy.h>

void customPhyInit(PhyInitData data)
{
// Use methods of `data` to modify as required
data.set_vdd33_const(0xff);
}

See :cpp:struct:`PhyInitData` for further details.


.. doxygenstruct:: PhyInitData
:members:
12 changes: 11 additions & 1 deletion Sming/Arch/Esp8266/Components/esp8266/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ ifeq ($(DISABLE_WIFI),1)
COMPONENT_DEPENDS += esp-lwip
endif


COMPONENT_RELINK_VARS += ENABLE_CUSTOM_PHY
ENABLE_CUSTOM_PHY ?= 0
ifeq ($(ENABLE_CUSTOM_PHY),1)
COMPONENT_CXXFLAGS += -DENABLE_CUSTOM_PHY=1
LDFLAGS += $(call Wrap,register_chipv6_phy)
endif


$(FLASH_INIT_DATA): $(SDK_BASE)/.submodule
$(Q) cp -f $(@D)/esp_init_data_default_v08.bin $@

Expand All @@ -29,7 +38,8 @@ export SDK_LIBDIR

COMPONENT_DOXYGEN_INPUT := \
include/gpio.h \
include/pwm.h
include/pwm.h \
include/esp_phy.h

# Crash handler hooks this so debugger can be invoked
EXTRA_LDFLAGS := $(call Wrap,system_restart_local)
Expand Down
43 changes: 43 additions & 0 deletions Sming/Arch/Esp8266/Components/esp8266/esp8266_phy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Adapted from Arduino for Sming.
Original copyright note is kept below.

phy.c - ESP8266 PHY initialization data
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// #ifdef ENABLE_CUSTOM_PHY

#include "include/esp_phy.h"
#include <Storage.h>
#include <esp_attr.h>
#include <sys/pgmspace.h>
#include <string.h>

extern "C" {
extern int __wrap_register_chipv6_phy(uint8_t* initData);
extern int __real_register_chipv6_phy(uint8_t* initData);
}

int ICACHE_RAM_ATTR __wrap_register_chipv6_phy(uint8_t* initData)
{
if(initData != NULL) {
PhyInitData data{initData};
customPhyInit(data);
}
return __real_register_chipv6_phy(initData);
}

// #endif /* ENABLE_CUSTOM_PHY */
Loading
Loading