Waveshare ESP32-P4-WIFI6-POE-ETH#
ESP32-P4-WIFI6-POE-ETH#
The Waveshare ESP32-P4-WIFI6-POE-ETH pairs an ESP32-P4 (dual-core 360 MHz RISC-V, 32 MB stacked PSRAM, 32 MB NOR flash) with an on-board ESP32-C6-MINI-1 Wi-Fi 6 / Bluetooth 5 LE co-processor and a 10/100 RJ45 Ethernet port with a reserved header for Waveshare’s plug-in PoE power module.
The espp::Esp32P4Wifi6PoeEth component provides a singleton hardware
abstraction for bringing up the board’s peripherals:
Ethernet: 10/100 via the internal EMAC and an IP101GRI RMII PHY, delegating to the reusable espp::Ethernet component and supplying the board-specific RMII pins (DHCP client / server). PoE is purely a power-supply feature — no GPIO is involved, so a PoE-powered board looks identical to a USB-powered one in software.
Internal I2C bus: shared by the on-board ES8311 audio codec and the MIPI-DSI / MIPI-CSI connectors and 40-pin header.
Note
The board’s BOOT key shares GPIO35 with the RMII TXD1 line (GPIO35 is the ESP32-P4’s boot-strap pin, sampled only at reset), so it cannot be used as a runtime input and the BSP does not expose a button API.
Wi-Fi 6 / BLE are provided by the on-board ESP32-C6 over SDIO using
Espressif’s ESP-Hosted + esp_wifi_remote components; the BSP documents the
board’s SDIO wiring (which matches the ESP-Hosted defaults for the ESP32-P4)
rather than wrapping it — see the example README for how to enable Wi-Fi in
your own application.
API Reference#
Header File#
Classes#
-
class Esp32P4Wifi6PoeEth : public espp::BaseComponent#
Board Support Package (BSP) for the Waveshare ESP32-P4-WIFI6-POE-ETH board.
The ESP32-P4-WIFI6-POE-ETH pairs an ESP32-P4 (dual-core 360 MHz RISC-V, 32 MB stacked PSRAM, 32 MB NOR flash) with an on-board ESP32-C6-MINI-1 (Wi-Fi 6 + Bluetooth 5 LE co-processor over SDIO) and a 10/100 RJ45 Ethernet port with a reserved header for a plug-in PoE power module.
This class provides a singleton interface to the board’s peripherals:
10/100 Ethernet via the ESP32-P4 internal EMAC and an IP101GRI RMII PHY. PoE is purely a power-supply feature (the RJ45 center taps feed bridge rectifiers and a 5-pin header for Waveshare’s PoE module, which produces the board’s 5 V rail) — no GPIO is involved, so a PoE-powered board looks identical to a USB-powered one in software.
The internal I2C bus (SDA=GPIO7, SCL=GPIO8), shared by the on-board ES8311 audio codec (0x18) and the DSI/CSI connectors + 40-pin header.
Wi-Fi 6 / BLE are provided by the on-board ESP32-C6 over SDIO using Espressif’s ESP-Hosted + esp_wifi_remote components; espp does not (yet) wrap that pattern in a BSP API, so this BSP documents the wiring (see the pin constants below and the example README) instead of wrapping it:
Signal
ESP32-P4 GPIO
ESP32-C6 pin
SDIO CLK
18
IO19 (SDIO_CLK)
SDIO CMD
19
IO18 (SDIO_CMD)
SDIO D0
14
IO20 (SDIO_DATA0)
SDIO D1
15
IO21 (SDIO_DATA1)
SDIO D2
16
IO22 (SDIO_DATA2)
SDIO D3
17
IO23 (SDIO_DATA3)
C6 reset (CHIP_PU / EN)
54
EN
Spare cross-connect (0 Ω)
6
IO2
RMII pin mapping (ESP32-P4 routable EMAC pins; identical to the Waveshare ESP32-P4-ETH / ESP32-P4-NANO). REF_CLK carries a 50 MHz reference clock generated by the IP101GRI from its 25 MHz crystal:
Signal
GPIO
REF_CLK
50
TX_EN
49
TXD0
34
TXD1
35 (also the BOOT key / boot-strap pin, see below)
CRS_DV
28
RXD0
29
RXD1
30
MDC
31
MDIO
52
PHY_RST
51
Audio: the ES8311 codec (I2S: MCLK=13, BCLK=12, WS/LRCK=10, DSDIN=9, ASDOUT=11), the NS4150B speaker amplifier (enable=GPIO53) and the analog microphone, through the espp::Audio component: mono playback and recording, full duplex on one I2S bus.
Other on-board hardware not (yet) wrapped by this BSP (pin data from the Waveshare schematic, see the component README):
microSD / TF slot on the fixed 4-bit SDMMC pins (CLK=43, CMD=44, D0..D3=39/40/41/42; pull-ups powered from LDO_VO4).
MIPI-DSI and MIPI-CSI 15-pin (Raspberry-Pi-style) connectors; panels and cameras are sold separately (the Kit-C / Kit-D bundles include them).
USB-A: native USB 2.0 OTG HS. USB-C: CH343P USB-UART console on UART0 (TX=GPIO37, RX=GPIO38) with auto-reset/boot circuitry.
The red LED next to the RJ45 is a 5 V power indicator, and the RJ45 green/yellow LEDs are driven by the PHY — none are GPIO-controllable.
The class is a singleton and can be accessed via get().
Example#
Get Instance#
auto &board = espp::Esp32P4Wifi6PoeEth::get();
DHCP Server#
espp::Esp32P4Wifi6PoeEth::ServerConfig srv_cfg; if (esp_netif_str_to_ip4(CONFIG_EXAMPLE_ETH_SERVER_IP, &srv_cfg.ip_info.ip) != ESP_OK || esp_netif_str_to_ip4(CONFIG_EXAMPLE_ETH_SERVER_NETMASK, &srv_cfg.ip_info.netmask) != ESP_OK || esp_netif_str_to_ip4(CONFIG_EXAMPLE_ETH_SERVER_GW, &srv_cfg.ip_info.gw) != ESP_OK) { logger.error("Invalid DHCP-server address in menuconfig (ip='{}' netmask='{}' gw='{}'); " "aborting Ethernet init", CONFIG_EXAMPLE_ETH_SERVER_IP, CONFIG_EXAMPLE_ETH_SERVER_NETMASK, CONFIG_EXAMPLE_ETH_SERVER_GW); return; } srv_cfg.on_client_assigned = [&](esp_ip4_addr_t ip, std::array<uint8_t, 6> mac) { logger.info("Client assigned {}.{}.{}.{} (mac {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x})", esp_ip4_addr1_16(&ip), esp_ip4_addr2_16(&ip), esp_ip4_addr3_16(&ip), esp_ip4_addr4_16(&ip), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); }; bool eth_ok = board.initialize_ethernet({ .mode = DhcpMode::SERVER, .server_config = srv_cfg, .on_link_up = [&]() { logger.info("Ethernet link up"); }, .on_link_down = [&]() { logger.warn("Ethernet link down"); }, .on_got_ip = [&](esp_ip4_addr_t ip) { logger.info("DHCP server up at {}.{}.{}.{}", esp_ip4_addr1_16(&ip), esp_ip4_addr2_16(&ip), esp_ip4_addr3_16(&ip), esp_ip4_addr4_16(&ip)); }, .on_lost_ip = [&]() { logger.warn("Ethernet lost IP"); }, });
DHCP Client#
bool eth_ok = board.initialize_ethernet({ .mode = DhcpMode::CLIENT, .on_link_up = [&]() { logger.info("Ethernet link up"); }, .on_link_down = [&]() { logger.warn("Ethernet link down"); }, .on_got_ip = [&](esp_ip4_addr_t ip) { logger.info("DHCP lease acquired: {}.{}.{}.{}", esp_ip4_addr1_16(&ip), esp_ip4_addr2_16(&ip), esp_ip4_addr3_16(&ip), esp_ip4_addr4_16(&ip)); }, .on_lost_ip = [&]() { logger.warn("Ethernet lost IP"); }, });
Audio#
static constexpr uint32_t audio_rate = 16000; auto audio_config = board.default_audio_config(); audio_config.sample_rate = audio_rate; if (board.initialize_audio(audio_config)) { board.volume(60.0f); // play() queues what fits and returns how much that was: stream from the // returned offset auto play_all = [&](std::span<const uint8_t> data) { while (!data.empty()) { const size_t queued = board.play_audio(data); data = data.subspan(queued); if (queued == 0) { std::this_thread::sleep_for(5ms); } } }; // a 300 ms, 880 Hz beep (16-bit mono) std::vector<int16_t> beep(audio_rate * 3 / 10); for (size_t i = 0; i < beep.size(); i++) { beep[i] = static_cast<int16_t>( 8000.0f * std::sin(2.0f * std::numbers::pi_v<float> * 880.0f * i / audio_rate)); } logger.info("Playing a beep"); play_all({reinterpret_cast<const uint8_t *>(beep.data()), beep.size() * sizeof(int16_t)}); std::this_thread::sleep_for(500ms); // record two seconds of 16-bit mono (the callback runs on the microphone // task) static std::vector<int16_t> recording; recording.reserve(audio_rate * 2); logger.info("Recording for 2 s..."); board.start_audio_recording([](const uint8_t *data, size_t length) { const auto *samples = reinterpret_cast<const int16_t *>(data); const size_t count = std::min(length / sizeof(int16_t), recording.capacity() - recording.size()); recording.insert(recording.end(), samples, samples + count); }); std::this_thread::sleep_for(2s); board.stop_audio_recording(); const int peak = std::accumulate(recording.begin(), recording.end(), 0, [](int m, int16_t s) { return std::max(m, std::abs(static_cast<int>(s))); }); logger.info("Recorded {} samples (peak {}); playing them back", recording.size(), peak); play_all( {reinterpret_cast<const uint8_t *>(recording.data()), recording.size() * sizeof(int16_t)}); } else { logger.error("Audio initialization failed"); }
Note
The BOOT key (Key1) is wired to GPIO35, which per the schematic is also the RMII TXD1 line to the IP101GRI. GPIO35 is the ESP32-P4’s boot-strap pin, sampled only at reset — once the EMAC is running the pin is a TXD1 output, so the BOOT key cannot be used as a runtime input. Like the other ESP32-P4 RMII BSPs (ESP32-P4-ETH / ESP32-P4-NANO, identical pinout) this BSP therefore does not expose a button API; the key is only useful for entering the serial bootloader at reset.
Note
Assumption pending hardware verification: PHY address 1 (PHY_AD0 is strapped high through a 5.1 kΩ pull-up like the ESP32-P4-ETH).
Public Types
-
enum class DhcpMode#
DHCP operating mode for the Ethernet interface.
Values:
-
enumerator CLIENT#
DHCP client — acquire an IP from an upstream server (default).
-
enumerator SERVER#
DHCP server — assign IPs to hosts connected to this interface.
-
enumerator CLIENT#
-
using client_ip_callback_t = std::function<void(esp_ip4_addr_t ip, std::array<uint8_t, 6> mac)>#
Callback invoked (SERVER mode only) each time the DHCP server assigns an IP address to a connected client.
-
using EthernetLinkCallback = std::function<void()>#
Callback invoked when the Ethernet link state changes (comes up or goes down) or when the IP address is lost.
Note
Runs in the ESP-IDF event-loop task context — return quickly, do not block.
-
using EthernetIpCallback = std::function<void(esp_ip4_addr_t ip)>#
Callback invoked when the interface obtains an IPv4 address.
Note
Runs in the ESP-IDF event-loop task context — return quickly, do not block.
- Param ip:
The assigned IPv4 address.
-
using AudioConfig = espp::Audio::AppConfig#
How initialize_audio() sets the audio system up: the application’s side of espp::Audio (the board’s wiring is filled in by initialize_audio()). Start from default_audio_config() to keep this board’s defaults.
sample_rate: The audio sample rate, in Hz: 8000, 11025, 16000, 22050, 24000, 32000, 44100 or 48000 (the ES8311’s clock coefficients)
playback_enabled: Set up playback: the I2S TX channel, the ES8311 DAC, the speaker and the playback task. Without it play_audio() queues nothing.
recording_enabled: Set up recording: the I2S RX channel, the ES8311 ADC (the onboard microphone) and the microphone task. Without it start_audio_recording() fails.
playback_buffer_size / playback_buffer_caps: the stream play_audio() queues into (0: about 67 ms of audio; larger lets one play_audio() call queue a whole UI sound, e.g. in MALLOC_CAP_SPIRAM)
playback_task_config / recording_task_config: the audio tasks (the recording callback runs on the recording task)
Note
Each I2S channel has a DMA ring of about 11.5 KB of internal DMA- capable RAM, and each task’s stack is in internal RAM too, so an application that only plays (or only records) saves that memory by turning the other direction off.
Public Functions
-
inline I2c &internal_i2c()#
Get a reference to the internal I2C bus (SDA=GPIO7, SCL=GPIO8)
Note
Shared by the on-board ES8311 audio codec (0x18) and the DSI / CSI connectors and 40-pin header
- Returns:
A reference to the internal I2C bus
-
bool initialize_ethernet(const EthernetConfig &config)#
Initialize the Ethernet interface (EMAC + IP101GRI RMII PHY).
Note
Requires the ESP-IDF TCP/IP stack and default event loop. The underlying espp::Ethernet component calls esp_netif_init() and esp_event_loop_create_default() during its initialize(), so they are created here if the application has not already done so.
Warning
If Ethernet is already initialized, the provided
configis IGNORED and a warning is logged — the interface keeps running with its original configuration (reconfiguration is not supported).- Parameters:
config – Ethernet configuration (DHCP mode, callbacks). All fields have defaults so
EthernetConfig{}gives a plain DHCP-client interface with no callbacks.- Returns:
True if Ethernet was successfully initialized and started, or if it was already initialized (the call is idempotent). False only on initialization failure.
-
bool initialize_ethernet()#
Initialize Ethernet with default configuration (DHCP client mode).
- Returns:
True if Ethernet was successfully initialized and started, or if it was already initialized (the call is idempotent). False only on initialization failure.
-
inline bool is_ethernet_connected() const#
Check whether the interface has a usable IP address (DHCP lease granted in CLIENT mode, or link is up in SERVER mode).
- Returns:
True if the interface is connected with a valid IP.
-
inline esp_ip4_addr_t ethernet_ip() const#
Get the most recently acquired IPv4 address (0 if none).
- Returns:
The IPv4 address.
-
bool initialize_audio()#
Initialize the audio system with the default AudioConfig: ES8311 playback and recording at 48 kHz
- Returns:
true if the audio system was successfully initialized, false otherwise
-
bool initialize_audio(const AudioConfig &config)#
Initialize the audio system (ES8311 codec + NS4150B amplifier)
Note
A failure part way through undoes what was set up before it (the I2S channels and their DMA rings, the stream buffer, the tasks, the codec), so the call can be retried.
- Parameters:
config – The sample rate, which directions to set up, the playback buffer and the task configuration
- Returns:
true if the audio system was successfully initialized, false otherwise (also when neither playback nor recording is enabled, or the sample rate is not one the ES8311 supports)
-
void deinitialize_audio()#
Stop the audio system and free what initialize_audio() set up (the speaker is switched off). Idempotent.
Note
The audio methods below may be called from any task meanwhile, but initialize_audio() and deinitialize_audio() must not run concurrently with each other, nor from an audio callback.
-
inline bool is_audio_initialized() const#
Whether the audio system is initialized
- Returns:
True if initialize_audio() succeeded (until deinitialize_audio())
-
inline std::shared_ptr<espp::Audio> audio() const#
The audio component, for anything the BSP methods below do not expose
Note
deinitialize_audio() releases the hardware even while the returned pointer is held: the object is then uninitialized (its methods fail / return 0), and a later initialize_audio() makes a new one.
- Returns:
The audio component, or nullptr before initialize_audio()
-
void enable_audio(bool enable)#
Enable or disable the speaker amplifier (NS4150B)
Note
initialize_audio() enables it when playback is set up.
- Parameters:
enable – True to enable, false to disable
-
void volume(float volume)#
Set the audio volume
Note
Before initialize_audio() (or without playback) the value is stored and applied when playback starts.
- Parameters:
volume – The volume as a percentage (0-100)
-
float volume() const#
Get the audio volume
- Returns:
The volume as a percentage (0-100)
-
void mute(bool mute)#
Mute or unmute the audio
Note
Before initialize_audio() (or without playback) the value is stored and applied when playback starts.
- Parameters:
mute – True to mute, false to unmute
-
bool is_muted() const#
Check if audio is muted
- Returns:
True if muted, false otherwise
-
uint32_t audio_sample_rate() const#
Get the audio sample rate
- Returns:
The audio sample rate, in Hz
-
bool audio_sample_rate(uint32_t sample_rate)#
Set the audio sample rate (the I2S clocks and the codec). The audio queued for playback is dropped, since it was for the old rate.
- Parameters:
sample_rate – The audio sample rate, in Hz
- Returns:
True on success (false before initialize_audio(), or if the ES8311 does not support the rate: the previous rate is kept)
-
size_t audio_buffer_size() const#
Get the audio buffer size
- Returns:
The size of one playback block, in bytes (1/60 s of audio)
-
size_t play_audio(const uint8_t *data, size_t num_bytes)#
Play audio data
Note
This function is non-blocking and queues the data for the audio task to play; to stream data larger than the internal buffer, call it repeatedly, advancing by the returned number of bytes (or make the buffer larger: AudioConfig::playback_buffer_size)
Note
Must be called from task context, not from an ISR.
- Parameters:
data – The audio data to play (16-bit signed mono samples)
num_bytes – The number of bytes to play
- Returns:
The number of bytes actually queued (may be less than
num_bytesif the internal stream buffer is full)
-
size_t play_audio(std::span<const uint8_t> data)#
Play audio data
Note
This function is non-blocking and queues the data for the audio task to play; to stream data larger than the internal buffer, call it repeatedly, advancing by the returned number of bytes (or make the buffer larger: AudioConfig::playback_buffer_size)
Note
Must be called from task context, not from an ISR.
- Parameters:
data – The audio data to play (16-bit signed mono samples)
- Returns:
The number of bytes actually queued (may be less than the data size if the internal stream buffer is full)
-
void clear_audio()#
Drop any queued (not yet played) audio so a subsequent play_audio() starts immediately instead of waiting behind previously queued sound. Useful for UI sounds where a new event should restart the sound for maximum responsiveness.
-
bool start_audio_recording(std::function<void(const uint8_t *data, size_t length)> callback)#
Start recording audio
Note
The callback runs in the dedicated microphone task’s context (a separate task from audio playback), so keep it quick and non- blocking and size that task’s stack accordingly
- Parameters:
callback – Function to call with recorded audio data: 16-bit signed mono samples (the onboard microphone, through the ES8311’s ADC) at audio_sample_rate()
- Returns:
True if recording started successfully (false, among other reasons, when initialize_audio() did not enable recording)
-
void stop_audio_recording()#
Stop recording audio. Once it returns the callback is not called again (unless it is called from the callback itself).
-
void microphone_volume(float volume)#
Set the microphone volume
Note
Before initialize_audio() (or without recording) the value is stored and applied when recording starts.
- Parameters:
volume – The volume as a percentage (0 - 100), mapped onto the ES8311 analog microphone gain range (0 dB - +42 dB)
-
float microphone_volume() const#
Get the microphone volume
- Returns:
The microphone volume as a percentage (0 - 100)
-
inline const std::string &get_name() const#
Get the name of the component
Note
This is the tag of the logger
- Returns:
A const reference to the name of the component
-
template<typename T = void>
inline void set_log_tag(const std::string_view&)# Not available: the tag is fixed at construction (pass it to the constructor). Enable CONFIG_ESPP_LOGGER_MUTABLE_TAG (menuconfig: ESPP Logger -> Mutable tag) to change it afterwards.
-
inline espp::Logger::Verbosity get_log_level() const#
Get the log level for the logger
See also
See also
- Returns:
The verbosity level of the logger
-
inline void set_log_level(espp::Logger::Verbosity level)#
Set the log level for the logger
See also
See also
- Parameters:
level – The verbosity level to use for the logger
-
inline void set_log_verbosity(espp::Logger::Verbosity level)#
Set the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls set_log_level
- Parameters:
level – The verbosity level to use for the logger
-
inline espp::Logger::Verbosity get_log_verbosity() const#
Get the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls get_log_level
- Returns:
The verbosity level of the logger
-
inline void set_log_rate_limit(std::chrono::duration<float> rate_limit)#
Set the rate limit for the logger
See also
Note
Only calls to the logger that have _rate_limit suffix will be rate limited
- Parameters:
rate_limit – The rate limit to use for the logger
Public Static Functions
-
static inline Esp32P4Wifi6PoeEth &get()#
Access the singleton instance.
- Returns:
Reference to the singleton instance
-
static AudioConfig default_audio_config()#
The board’s default AudioConfig: 48 kHz, playback and recording, and the tasks “poe audio out” / “poe audio in” with this board’s stack, priority and core.
- Returns:
The default AudioConfig
Public Static Attributes
-
static int c6_sdio_clk_io = 18#
P4 SDIO CLK -> C6 IO19 (SDIO_CLK).
-
static int c6_sdio_cmd_io = 19#
P4 SDIO CMD -> C6 IO18 (SDIO_CMD).
-
static int c6_sdio_d0_io = 14#
P4 SDIO D0 -> C6 IO20 (SDIO_DATA0).
-
static int c6_sdio_d1_io = 15#
P4 SDIO D1 -> C6 IO21 (SDIO_DATA1).
-
static int c6_sdio_d2_io = 16#
P4 SDIO D2 -> C6 IO22 (SDIO_DATA2).
-
static int c6_sdio_d3_io = 17#
P4 SDIO D3 -> C6 IO23 (SDIO_DATA3).
-
static int c6_reset_io = 54#
P4 GPIO54 -> C6 EN (CHIP_PU) via 0 Ω
-
static int c6_spare_io = 6#
P4 GPIO6 -> C6 IO2 via 0 Ω (unused spare).
-
struct ServerConfig#
Static IP configuration used when operating as a DHCP server. Leave
ip_infozero-initialised to use the built-in defaults (192.168.4.1 / 255.255.255.0 / gw 192.168.4.1).Public Members
-
esp_netif_ip_info_t ip_info = {}#
zero-initialised → 192.168.4.1/24
-
client_ip_callback_t on_client_assigned = {nullptr}#
Called for each assigned client IP.
-
esp_netif_ip_info_t ip_info = {}#
-
struct EthernetConfig#
Configuration for the Ethernet interface.
Public Members
-
ServerConfig server_config = {}#
Only used when mode == SERVER.
-
EthernetLinkCallback on_link_up = {nullptr}#
Physical link came up.
-
EthernetLinkCallback on_link_down = {nullptr}#
Physical link went down.
-
EthernetIpCallback on_got_ip = {nullptr}#
Interface obtained an IPv4 address.
-
EthernetLinkCallback on_lost_ip = {nullptr}#
Interface lost its IPv4 address.
-
ServerConfig server_config = {}#