Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2771f27

Browse files
fabik111pennam
authored andcommitted
add esp32 chip manager on ESPHome for portenta C33
1 parent 4ebe747 commit 2771f27

File tree

3 files changed

+119
-31
lines changed

3 files changed

+119
-31
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* ########################################################################## */
2+
/* - File: EspChipManager.h
3+
- Copyright (c): 2025 Arduino srl.
4+
- Author: Fabio Massimo Centonze (f.centonze@arduino.cc)
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc.,51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
19+
/* ########################################################################## */
20+
21+
#include "EspChipManager.h"
22+
23+
#define ESP_RESET BSP_IO_PORT_08_PIN_04
24+
#define ESP_DOWNLOAD DATA_READY // The DATA_READY pin is shared with the ESP_DOWNLOAD pin
25+
26+
CEspChipManager& CEspChipManager::getInstance() {
27+
static CEspChipManager instance;
28+
return instance;
29+
}
30+
31+
void CEspChipManager::initialize() {
32+
if (!isInitialized) {
33+
forceReset();
34+
isInitialized = true;
35+
}
36+
}
37+
38+
void CEspChipManager::forceReset() {
39+
R_IOPORT_PinCfg(NULL, ESP_RESET, IOPORT_CFG_PORT_DIRECTION_OUTPUT);
40+
// Set the ESP_DOWNLOAD pin to high to ensure the ESP doesn't enter in download mode when resetting
41+
R_IOPORT_PinCfg(NULL, ESP_DOWNLOAD, (uint32_t) (IOPORT_CFG_PORT_DIRECTION_OUTPUT));
42+
R_IOPORT_PinWrite(NULL, ESP_DOWNLOAD, BSP_IO_LEVEL_HIGH);
43+
delay(100);
44+
R_IOPORT_PinWrite(NULL, ESP_RESET, BSP_IO_LEVEL_HIGH);
45+
R_IOPORT_PinWrite(NULL, ESP_RESET, BSP_IO_LEVEL_LOW);
46+
R_IOPORT_PinWrite(NULL, ESP_RESET, BSP_IO_LEVEL_HIGH);
47+
R_IOPORT_PinWrite(NULL, ESP_DOWNLOAD, BSP_IO_LEVEL_LOW);
48+
R_IOPORT_PinCfg(NULL, ESP_DOWNLOAD, (uint32_t) (IOPORT_CFG_IRQ_ENABLE | IOPORT_CFG_PORT_DIRECTION_INPUT));
49+
}
50+

‎libraries/ESPhost/src/EspChipManager.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* ########################################################################## */
2+
/* - File: EspChipManager.h
3+
- Copyright (c): 2025 Arduino srl.
4+
- Author: Fabio Massimo Centonze (f.centonze@arduino.cc)
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc.,51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
19+
/* ########################################################################## */
20+
21+
#ifndef ESP_CHIP_MANAGER_H
22+
#define ESP_CHIP_MANAGER_H
23+
#include <Arduino.h>
24+
25+
#ifdef USE_ESP32_C3_DEVKIT_RUST_1
26+
/* GPIOs */
27+
#define HANDSHAKE BSP_IO_PORT_05_PIN_05
28+
#define DATA_READY BSP_IO_PORT_08_PIN_02
29+
#define DATA_READY_PIN 33
30+
31+
/* SPI PIN definition */
32+
#define ESP_MISO BSP_IO_PORT_01_PIN_00
33+
#define ESP_MOSI BSP_IO_PORT_01_PIN_01
34+
#define ESP_CK BSP_IO_PORT_01_PIN_02
35+
#define ESP_CS BSP_IO_PORT_01_PIN_03
36+
#else
37+
/* GPIOs */
38+
#define HANDSHAKE BSP_IO_PORT_08_PIN_06
39+
#define DATA_READY BSP_IO_PORT_08_PIN_03
40+
#define DATA_READY_PIN 100
41+
42+
/* SPI PIN definition */
43+
#define ESP_MISO BSP_IO_PORT_01_PIN_00
44+
#define ESP_MOSI BSP_IO_PORT_01_PIN_01
45+
#define ESP_CK BSP_IO_PORT_01_PIN_02
46+
#define ESP_CS BSP_IO_PORT_01_PIN_04
47+
#endif
48+
49+
50+
class CEspChipManager {
51+
public:
52+
static CEspChipManager& getInstance();
53+
54+
// Delete copy constructor and assignment operator to enforce singleton
55+
CEspChipManager(const CEspChipManager&) = delete;
56+
CEspChipManager& operator=(const CEspChipManager&) = delete;
57+
// General initialization
58+
void initialize();
59+
// Force a reset of the ESP chip, don't use for initialization
60+
void forceReset();
61+
private:
62+
CEspChipManager() = default;
63+
~CEspChipManager() = default;
64+
bool isInitialized = false;
65+
};
66+
#endif // ESP_CHIP_MANAGER_H

‎libraries/ESPhost/src/EspSpiDriver.cpp

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* ######## */
3030

3131
#include "EspSpiDriver.h"
32+
#include "EspChipManager.h"
3233

3334
/* #####################
3435
* Configuration defines
@@ -45,31 +46,6 @@
4546

4647
#define EXT_IRQ_CHANNEL (0)
4748

48-
#ifdef USE_ESP32_C3_DEVKIT_RUST_1
49-
/* GPIOs */
50-
#define HANDSHAKE BSP_IO_PORT_05_PIN_05
51-
#define DATA_READY BSP_IO_PORT_08_PIN_02
52-
#define DATA_READY_PIN 33
53-
54-
/* SPI PIN definition */
55-
#define ESP_MISO BSP_IO_PORT_01_PIN_00
56-
#define ESP_MOSI BSP_IO_PORT_01_PIN_01
57-
#define ESP_CK BSP_IO_PORT_01_PIN_02
58-
#define ESP_CS BSP_IO_PORT_01_PIN_03
59-
#else
60-
/* GPIOs */
61-
#define ESP_RESET BSP_IO_PORT_08_PIN_04
62-
#define HANDSHAKE BSP_IO_PORT_08_PIN_06
63-
#define DATA_READY BSP_IO_PORT_08_PIN_03
64-
#define DATA_READY_PIN 100
65-
66-
/* SPI PIN definition */
67-
#define ESP_MISO BSP_IO_PORT_01_PIN_00
68-
#define ESP_MOSI BSP_IO_PORT_01_PIN_01
69-
#define ESP_CK BSP_IO_PORT_01_PIN_02
70-
#define ESP_CS BSP_IO_PORT_01_PIN_04
71-
#endif
72-
7349
/* #################
7450
* PRIVATE Variables
7551
* ################# */
@@ -157,15 +133,11 @@ int esp_host_spi_init(void) {
157133
}
158134

159135
/* ++++++++++++++++++++++++++++++++++
160-
* GPIOs (HANDSHAKE and DATA_READY)
136+
* GPIOs (HANDSHAKE and CS)
161137
* ++++++++++++++++++++++++++++++++++ */
162138
R_IOPORT_PinCfg(NULL, HANDSHAKE, IOPORT_CFG_PORT_DIRECTION_INPUT);
163-
/* DATA READY is configure in attach interrupt function below */
164139
//#ifdef EXPLICIT_PIN_CONFIGURATION
165-
R_IOPORT_PinCfg(NULL, DATA_READY, (uint32_t) (IOPORT_CFG_IRQ_ENABLE | IOPORT_CFG_PORT_DIRECTION_INPUT ));
166-
167140
R_IOPORT_PinCfg(NULL, ESP_CS, IOPORT_CFG_PORT_DIRECTION_OUTPUT);
168-
R_IOPORT_PinCfg(NULL, ESP_RESET, IOPORT_CFG_PORT_DIRECTION_OUTPUT);
169141
//#endif
170142

171143
/* +++++
@@ -270,7 +242,7 @@ int esp_host_spi_init(void) {
270242
return ESP_HOSTED_SPI_DRIVER_SPI_FAIL_OPEN;
271243
}
272244

273-
R_IOPORT_PinWrite(NULL, ESP_RESET, BSP_IO_LEVEL_HIGH);
245+
CEspChipManager::getInstance().initialize();
274246
spi_driver_initialized = true;
275247
return ESP_HOSTED_SPI_DRIVER_OK;
276248
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /