Skip to content

Commit

Permalink
- various fixes & adjustments across Marlin
Browse files Browse the repository at this point in the history
- fixed a bug in ESP32 HAL SPI where interrupt code cannot be assumed to be entirely in IRAM due to access to peripheral memory, possibility of having a compiler-internal function inside the generated code-graph
  • Loading branch information
quiret committed Feb 15, 2023
1 parent a603ce2 commit d576b48
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/HAL/AVR/fastio/fastio_1280.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Logical Pin : 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 78 79 80 xx xx 84 85 71 70 xx xx xx xx xx 81 82 83 xx xx 72 73 75 76 77 74 xx xx xx xx xx
*
* Arduino Pin Layout video: https://www.youtube.com/watch?v=rIqeVCX09FA
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=Gz9QU3FvdXs
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=1yd8wuI5Plg
*/

#include "../fastio.h"
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/AVR/fastio/fastio_1281.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Port: A0 A1 A2 A3 A4 A5 A6 A7 B0 B1 B2 B3 B4 B5 B6 B7 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7 E0 E1 E2 E3 E4 E5 E6 E7 F0 F1 F2 F3 F4 F5 F6 F7 G0 G1 G2 G3 G4 G5
*
* Arduino Pin Layout video: https://www.youtube.com/watch?v=rIqeVCX09FA
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=Gz9QU3FvdXs
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=1yd8wuI5Plg
*/

#include "../fastio.h"
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/AVR/fastio/fastio_168.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Port: B0 B1 B2 B3 B4 B5 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7
*
* Arduino Pin Layout video: https://www.youtube.com/watch?v=rIqeVCX09FA
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=Gz9QU3FvdXs
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=1yd8wuI5Plg
*/

#include "../fastio.h"
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/AVR/fastio/fastio_644.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Port: B0 B1 B2 B3 B4 B5 B6 B7 D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 C2 C3 C4 C5 C6 C7 A7 A6 A5 A4 A3 A2 A1 A0
*
* Arduino Pin Layout video: https://www.youtube.com/watch?v=rIqeVCX09FA
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=Gz9QU3FvdXs
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=1yd8wuI5Plg
*/

/** ATMega644
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/AVR/fastio/fastio_AT90USB.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* The logical pins 46 and 47 are not supported by Teensyduino, but are supported below as E2 and E3
*
* Arduino Pin Layout video: https://www.youtube.com/watch?v=rIqeVCX09FA
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=Gz9QU3FvdXs
* AVR alternate pin function overview video: https://www.youtube.com/watch?v=1yd8wuI5Plg
*/

#include "../fastio.h"
Expand Down
15 changes: 5 additions & 10 deletions Marlin/src/HAL/ESP32/HAL_SPI_HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ using esp32BitManager = eir::BitManager <hostNumberType, eir::template choose_de
#define HALSPI_DISABLE_DMA
#endif

static void _spi_on_error(const uint32_t code=0) {
static void IRAM_ATTR _spi_on_error(const uint32_t code=0) {
for (;;) {
#if defined(HALSPI_DO_ERRORBEEPS) && PIN_EXISTS(BEEPER)
OUT_WRITE(BEEPER_PIN, HIGH); delay(500);
Expand Down Expand Up @@ -1530,7 +1530,7 @@ inline uint16_t SPIGetWriteBufferStartIndex(volatile spi_dev_t& SPI) {
}

template <eir::bitmanager_type bitManType>
inline void SPIPrepareWriteBitManager(volatile spi_dev_t& SPI, bitManType& bitman) noexcept {
inline void IRAM_ATTR SPIPrepareWriteBitManager(volatile spi_dev_t& SPI, bitManType& bitman) noexcept {
bool wr_msbfirst = (SPI.SPI_CTRL_REG.SPI_WR_BIT_ORDER == _ESP32_BIT_ORDER_MSB);

bitman.SetDefaultStorageProperty(
Expand All @@ -1540,7 +1540,7 @@ inline void SPIPrepareWriteBitManager(volatile spi_dev_t& SPI, bitManType& bitma
}

template <eir::bitmanager_type bitManType>
inline void SPIPrepareReadBitManager(volatile spi_dev_t& SPI, bitManType& bitman) noexcept {
inline void IRAM_ATTR SPIPrepareReadBitManager(volatile spi_dev_t& SPI, bitManType& bitman) noexcept {
bool rd_msbfirst = (SPI.SPI_CTRL_REG.SPI_RD_BIT_ORDER == _ESP32_BIT_ORDER_MSB);

bitman.SetDefaultStorageProperty(
Expand All @@ -1550,7 +1550,7 @@ inline void SPIPrepareReadBitManager(volatile spi_dev_t& SPI, bitManType& bitman
}

template <typename numberType>
inline void SPIWriteDataToTransferIsolated(
inline void IRAM_ATTR SPIWriteDataToTransferIsolated(
volatile spi_dev_t& SPI, const numberType *buf, uint16_t cnt, uint32_t srcByteStartIdx,
uint16_t& cntSentBytes_out
) {
Expand Down Expand Up @@ -1962,11 +1962,6 @@ static void IRAM_ATTR spi_async_process_isr(void *ud, uint32_t spibusIdx) {
}
}
}
#ifdef HALSPI_DEBUG
else {
SERIAL_ECHO_MSG("SPI ERROR (", spibusIdx, ")");
}
#endif
}

#ifdef HALSPI_ESP32_ENABLE_INTERNBUS
Expand Down Expand Up @@ -2010,7 +2005,7 @@ static void SPIInstallAsync(volatile spi_dev_t& SPI, intr_handle_t& handleOut) {
else
_spi_on_error(1);

esp_err_t err = esp_intr_alloc(intsrc, ESP_INTR_FLAG_IRAM, inthandler, nullptr, &handleOut);
esp_err_t err = esp_intr_alloc(intsrc, 0 /*ESP_INTR_FLAG_IRAM*/, inthandler, nullptr, &handleOut);

if (err != ESP_OK)
_spi_on_error(1);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/ESP32/WebSocketSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#pragma once

#include "../../inc/MarlinConfig.h"
#include "../../inc/MarlinConfigPre.h"
#include "../../core/serial_hook.h"

#include <Stream.h>
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/ESP32/ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void OTA_init() {
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
char *str;
const char *str = "unknown";
switch (error) {
case OTA_AUTH_ERROR: str = "Auth Failed"; break;
case OTA_BEGIN_ERROR: str = "Begin Failed"; break;
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/HAL/ESP32/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void wifi_init() {

MDNS.addService("http", "tcp", 80);

SERIAL_ECHOLNPGM("Successfully connected to WiFi with SSID '" WIFI_SSID "', hostname: '" WIFI_HOSTNAME "', IP address: ", WiFi.localIP().toString().c_str());
auto str = WiFi.localIP().toString();
SERIAL_ECHOLNPGM("Successfully connected to WiFi with SSID '" WIFI_SSID "', hostname: '" WIFI_HOSTNAME "', IP address: ", str.c_str());
}

#endif // WIFISUPPORT
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/core/serial_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "../inc/MarlinConfigPre.h"

#include <stddef.h> // for size_t

#if ENABLED(EMERGENCY_PARSER)
#include "../feature/e_parser.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3693,7 +3693,7 @@ void Stepper::report_positions() {

#if HAS_MOTOR_CURRENT_SPI

SET_OUTPUT(DIGIPOTSS_PIN);
spiSetupChipSelect(DIGIPOTSS_PIN);

LOOP_L_N(i, COUNT(motor_current_setting))
set_digipot_current(i, motor_current_setting[i]);
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/pins/mega/pins_GT2560_V3.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,12 @@
#if ENABLED(YHCB2004)
#ifndef YHCB2004_CLK
#define YHCB2004_CLK PinE3
#define DIO52 YHCB2004_CLK
#endif
#ifndef YHCB2004_MOSI
#define YHCB2004_MOSI PinD0
#define DIO50 YHCB2004_MOSI
#endif
#ifndef YHCB2004_MISO
#define YHCB2004_MISO PinC1
#define DIO51 YHCB2004_MISO
#endif
#elif HAS_WIRED_LCD
#ifndef LCD_PINS_RS
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/pins/ramps/pins_RUMBA.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
#define E1_ENABLE_PIN PinA5
#endif

#if E1_STEP_PIN != 29
#if E1_STEP_PIN != PinA7
#define E2_STEP_PIN PinA7
#define E2_DIR_PIN PinA6
#define E2_ENABLE_PIN PinG2
Expand Down

0 comments on commit d576b48

Please sign in to comment.