Skip to content

Fix BLE and WiFi coexistance on Portenta c33 #472

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions libraries/ESPhost/src/EspChipManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* ########################################################################## */
/* - File: EspChipManager.h
- Copyright (c): 2025 Arduino srl.
- Author: Fabio Massimo Centonze (f.centonze@arduino.cc)

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 */
/* ########################################################################## */

#include "EspChipManager.h"

#define ESP_RESET BSP_IO_PORT_08_PIN_04
#define ESP_BLE_PIN_EN 100

CEspChipManager& CEspChipManager::getInstance() {
static CEspChipManager instance;
return instance;
}

void CEspChipManager::initialize() {
if (!isInitialized) {
R_IOPORT_PinCfg(NULL, ESP_RESET, IOPORT_CFG_PORT_DIRECTION_OUTPUT);
R_IOPORT_PinWrite(NULL, ESP_RESET, BSP_IO_LEVEL_HIGH);

isInitialized = true;
}
}

void CEspChipManager::initializeBLE() {
if (!isBLEInitialized) {
R_IOPORT_PinCfg(NULL, digitalPinToBspPin(ESP_BLE_PIN_EN), IOPORT_CFG_PORT_DIRECTION_OUTPUT);
R_IOPORT_PinWrite(NULL, digitalPinToBspPin(ESP_BLE_PIN_EN), BSP_IO_LEVEL_HIGH);
isBLEInitialized = true;
}
}
42 changes: 42 additions & 0 deletions libraries/ESPhost/src/EspChipManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* ########################################################################## */
/* - File: EspChipManager.h
- Copyright (c): 2025 Arduino srl.
- Author: Fabio Massimo Centonze (f.centonze@arduino.cc)

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 */
/* ########################################################################## */

#ifndef ESP_CHIP_MANAGER_H
#define ESP_CHIP_MANAGER_H
#include <Arduino.h>

class CEspChipManager {
public:
static CEspChipManager& getInstance();

// Delete copy constructor and assignment operator to enforce singleton
CEspChipManager(const CEspChipManager&) = delete;
CEspChipManager& operator=(const CEspChipManager&) = delete;
// General initialization
void initialize();
// Initialize the BLE
void initializeBLE();
private:
CEspChipManager() = default;
~CEspChipManager() = default;
bool isInitialized = false;
bool isBLEInitialized = false;
};
#endif // ESP_CHIP_MANAGER_H
5 changes: 2 additions & 3 deletions libraries/ESPhost/src/EspSpiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* ######## */

#include "EspSpiDriver.h"
#include "EspChipManager.h"

/* #####################
* Configuration defines
Expand Down Expand Up @@ -58,7 +59,6 @@
#define ESP_CS BSP_IO_PORT_01_PIN_03
#else
/* GPIOs */
#define ESP_RESET BSP_IO_PORT_08_PIN_04
#define HANDSHAKE BSP_IO_PORT_08_PIN_06
#define DATA_READY BSP_IO_PORT_08_PIN_03
#define DATA_READY_PIN 100
Expand Down Expand Up @@ -165,7 +165,6 @@ int esp_host_spi_init(void) {
R_IOPORT_PinCfg(NULL, DATA_READY, (uint32_t) (IOPORT_CFG_IRQ_ENABLE | IOPORT_CFG_PORT_DIRECTION_INPUT ));

R_IOPORT_PinCfg(NULL, ESP_CS, IOPORT_CFG_PORT_DIRECTION_OUTPUT);
R_IOPORT_PinCfg(NULL, ESP_RESET, IOPORT_CFG_PORT_DIRECTION_OUTPUT);
//#endif

/* +++++
Expand Down Expand Up @@ -270,7 +269,7 @@ int esp_host_spi_init(void) {
return ESP_HOSTED_SPI_DRIVER_SPI_FAIL_OPEN;
}

R_IOPORT_PinWrite(NULL, ESP_RESET, BSP_IO_LEVEL_HIGH);
CEspChipManager::getInstance().initialize();
spi_driver_initialized = true;
return ESP_HOSTED_SPI_DRIVER_OK;
}
Expand Down
Loading