Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 6 additions & 3 deletions cores/esp32/HWCDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ static void ARDUINO_ISR_ATTR cdc0_write_char(char c) {
}

HWCDC::HWCDC() {
perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, HWCDC::deinit);
perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, HWCDC::deinit);
// SOF in ISR causes problems for uploading firmware
// lastSOF_ms = 0;
// SOF_TIMEOUT = 5;
Expand Down Expand Up @@ -324,14 +322,19 @@ void HWCDC::begin(unsigned long baud) {

// Peripheral Manager setting for USB D+ D- pins
uint8_t pin = USB_INT_PHY0_DM_GPIO_NUM;
if (perimanGetBusDeinit(ESP32_BUS_TYPE_USB_DM) == NULL) {
perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, HWCDC::deinit);
}
if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *)this, -1, -1)) {
goto err;
}
pin = USB_INT_PHY0_DP_GPIO_NUM;
if (perimanGetBusDeinit(ESP32_BUS_TYPE_USB_DP) == NULL) {
perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, HWCDC::deinit);
}
if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *)this, -1, -1)) {
goto err;
}

// Configure PHY
// USB_Serial_JTAG use internal PHY
USB_SERIAL_JTAG.conf0.phy_sel = 0;
Expand Down
2 changes: 0 additions & 2 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ HardwareSerial::HardwareSerial(uint8_t uart_nr)
}
}
#endif
// set deinit function in the Peripheral Manager
uart_init_PeriMan();
}

HardwareSerial::~HardwareSerial() {
Expand Down
24 changes: 16 additions & 8 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
ret &= perimanSetPinBus(rxPin, ESP32_BUS_TYPE_UART_RX, (void *)uart, uart_num, -1);
if (ret) {
uart->_rxPin = rxPin;
// set Peripheral Manager deInit Callback for this UART pin
if (perimanGetBusDeinit(ESP32_BUS_TYPE_UART_RX) == NULL) {
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RX, _uartDetachBus_RX);
}
}
}
if (!ret) {
Expand All @@ -502,6 +506,10 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
ret &= perimanSetPinBus(txPin, ESP32_BUS_TYPE_UART_TX, (void *)uart, uart_num, -1);
if (ret) {
uart->_txPin = txPin;
// set Peripheral Manager deInit Callback for this UART pin
if (perimanGetBusDeinit(ESP32_BUS_TYPE_UART_TX) == NULL) {
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_TX, _uartDetachBus_TX);
}
}
}
if (!ret) {
Expand All @@ -525,6 +533,10 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
ret &= perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_UART_CTS, (void *)uart, uart_num, -1);
if (ret) {
uart->_ctsPin = ctsPin;
// set Peripheral Manager deInit Callback for this UART pin
if (perimanGetBusDeinit(ESP32_BUS_TYPE_UART_CTS) == NULL) {
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_CTS, _uartDetachBus_CTS);
}
}
}
if (!ret) {
Expand All @@ -548,6 +560,10 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
ret &= perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_UART_RTS, (void *)uart, uart_num, -1);
if (ret) {
uart->_rtsPin = rtsPin;
// set Peripheral Manager deInit Callback for this UART pin
if (perimanGetBusDeinit(ESP32_BUS_TYPE_UART_RTS) == NULL) {
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RTS, _uartDetachBus_RTS);
}
}
}
if (!ret) {
Expand All @@ -567,14 +583,6 @@ int8_t uart_get_TxPin(uint8_t uart_num) {
return _uart_bus_array[uart_num]._txPin;
}

void uart_init_PeriMan(void) {
// set Peripheral Manager deInit Callback for each UART pin
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RX, _uartDetachBus_RX);
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_TX, _uartDetachBus_TX);
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_CTS, _uartDetachBus_CTS);
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RTS, _uartDetachBus_RTS);
}

// Routines that take care of UART events will be in the HardwareSerial Class code
void uartGetEventQueue(uart_t *uart, QueueHandle_t *q) {
// passing back NULL for the Queue pointer when UART is not initialized yet
Expand Down
1 change: 0 additions & 1 deletion cores/esp32/esp32-hal-uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, in
// helper functions
int8_t uart_get_RxPin(uint8_t uart_num);
int8_t uart_get_TxPin(uint8_t uart_num);
void uart_init_PeriMan(void);

// Enables or disables HW Flow Control function -- needs also to set CTS and/or RTS pins
// UART_HW_FLOWCTRL_DISABLE = 0x0 disable hardware flow control
Expand Down
12 changes: 6 additions & 6 deletions cores/esp32/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ __attribute__((weak)) uint64_t getArduinoSetupWaitTime_ms(void) {
}

void loopTask(void *pvParameters) {
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
// sets UART0 (default console) RX/TX pins as already configured in boot or as defined in variants/pins_arduino.h
Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0));
// time in ms that the sketch may wait before starting its execution - default is zero
// usually done for opening the Serial Monitor and seeing all debug messages
delay(getArduinoSetupWaitTime_ms());
#endif
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
printBeforeSetupInfo();
#else
if (shouldPrintChipDebugReport()) {
printBeforeSetupInfo();
}
#endif
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
// sets UART0 (default console) RX/TX pins as already configured in boot or as defined in variants/pins_arduino.h
Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0));
// time in ms that the sketch may wait before starting its execution - default is zero
// usually done for opening the Serial Monitor and seeing all debug messages
#endif
setup();
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
Expand Down
Loading