Skip to content
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

STM32: Prevent possible crashes before HAL init #22508

Merged
merged 12 commits into from
Aug 9, 2021
8 changes: 4 additions & 4 deletions Marlin/src/HAL/STM32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "HAL.h"
#include "usb_serial.h"
Expand Down Expand Up @@ -61,8 +63,6 @@ TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial());

// HAL initialization task
void HAL_init() {
FastIO_init();

// Ensure F_CPU is a constant expression.
// If the compiler breaks here, it means that delay code that should compute at compile time will not work.
// So better safe than sorry here.
Expand Down Expand Up @@ -165,4 +165,4 @@ void HAL_SYSTICK_Callback() {
if (systick_user_callback) systick_user_callback();
}

#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/HAL_MinSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

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

Expand Down Expand Up @@ -149,4 +151,4 @@ extern "C" {
#endif

#endif // POSTMORTEM_DEBUGGING
#endif // ARDUINO_ARCH_STM32
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -224,4 +226,4 @@ static SPISettings spiConfig;

#endif // SOFTWARE_SPI

#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32/MarlinSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1) && !defined(STM32H7xx)
#if defined(HAL_STM32) && !defined(STM32H7xx)

#include "MarlinSPI.h"

Expand Down Expand Up @@ -165,4 +165,4 @@ uint8_t MarlinSPI::dmaSend(const void * transmitBuf, uint16_t length, bool minc)
return 1;
}

#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1 && !STM32H7xx
#endif // HAL_STM32 && !STM32H7xx
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/MarlinSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"
#include "MarlinSerial.h"
Expand Down Expand Up @@ -101,4 +103,4 @@ void MarlinSerial::_rx_complete_irq(serial_t *obj) {
}
}

#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -320,4 +322,4 @@ extern "C" void SDIO_IRQHandler(void) { HAL_SD_IRQHandler(&hsd); }
extern "C" void DMA_IRQ_HANDLER(void) { HAL_DMA_IRQHandler(&hdma_sdio); }

#endif // SDIO_SUPPORT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -107,4 +109,4 @@ void libServo::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriori
}

#endif // HAS_SERVOS
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/eeprom_flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -270,4 +272,4 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
}

#endif // FLASH_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/eeprom_sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

/**
* Implementation of EEPROM settings in SD Card
Expand Down Expand Up @@ -88,4 +90,4 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uin
}

#endif // SDCARD_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/eeprom_sram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -65,4 +67,4 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
}

#endif // SRAM_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/eeprom_wired.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -75,4 +77,4 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
}

#endif // USE_WIRED_EEPROM
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

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

Expand Down Expand Up @@ -56,4 +58,4 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
}

#endif // NEEDS_HARDWARE_PWM
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
8 changes: 5 additions & 3 deletions Marlin/src/HAL/STM32/fastio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

GPIO_TypeDef* FastIOPortMap[LastPort + 1];
GPIO_TypeDef* FastIOPortMap[LastPort + 1] = { 0 };

void FastIO_init() {
LOOP_L_N(i, NUM_DIGITAL_PINS)
FastIOPortMap[STM_PORT(digitalPin[i])] = get_GPIO_Port(STM_PORT(digitalPin[i]));
}

#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/msc_sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

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

Expand Down Expand Up @@ -125,4 +127,4 @@ void MSC_SD_init() {
}

#endif // HAS_SD_HOST_DRIVE
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/tft/gt911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../platforms.h"

#ifdef HAL_STM32

#include "../../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -199,4 +201,4 @@ bool GT911::getPoint(int16_t *x, int16_t *y) {
}

#endif // TFT_TOUCH_DEVICE_GT911
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/tft/tft_fsmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../platforms.h"

#ifdef HAL_STM32

#include "../../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -178,4 +180,4 @@ void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Cou
}

#endif // HAS_FSMC_TFT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/tft/tft_ltdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../platforms.h"

#ifdef HAL_STM32

#include "../../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -384,4 +386,4 @@ void TFT_LTDC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Cou
}

#endif // HAS_LTDC_TFT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../platforms.h"

#ifdef HAL_STM32

#include "../../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -240,4 +242,4 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
}

#endif // HAS_SPI_TFT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/tft/xpt2046.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../platforms.h"

#ifdef HAL_STM32

#include "../../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -167,4 +169,4 @@ uint16_t XPT2046::SoftwareIO(uint16_t data) {
}

#endif // HAS_TFT_XPT2046
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -319,4 +321,4 @@ static constexpr bool verify_no_timer_conflicts() {
// when hovering over it, making it easy to identify the conflicting timers.
static_assert(verify_no_timer_conflicts(), "One or more timer conflict detected. Examine \"timers_in_use\" to help identify conflict.");

#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
5 changes: 3 additions & 2 deletions Marlin/src/HAL/STM32/usb_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "../platforms.h"

#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#ifdef HAL_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -114,4 +115,4 @@ uint8_t BulkStorage::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t b
}

#endif // USE_OTG_USB_HOST && USBHOST
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/usb_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../platforms.h"

#ifdef HAL_STM32

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

Expand Down Expand Up @@ -51,4 +53,4 @@ void USB_Hook_init() {
}

#endif // EMERGENCY_PARSER && USBD_USE_CDC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1
#endif // HAL_STM32
Loading