From 7dc256432f10aa5e0acd87cbcf817e64c26b5828 Mon Sep 17 00:00:00 2001 From: xC0000005 <32139633+xC0000005@users.noreply.github.com> Date: Wed, 28 Mar 2018 11:07:52 -0700 Subject: [PATCH] Restore STM32F1 series to working order. (#10229) The `_O2` attribute is no longer needed on the malyanlcd function, and the macros have broken timer numbers - reset this to a function to return the right device. Also fix the bit order cast in SPI. --- Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.cpp | 1 + Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.h | 2 + .../src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp | 3 +- .../HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp | 47 +++++++++++++++++++ .../src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h | 7 +-- Marlin/src/lcd/malyanlcd.cpp | 2 +- 6 files changed, 57 insertions(+), 5 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.cpp index a5a3c2bdf..d47b960ab 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.cpp @@ -55,6 +55,7 @@ // -------------------------------------------------------------------------- // Public Variables // -------------------------------------------------------------------------- +USBSerial SerialUSB; uint16_t HAL_adc_result; diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.h b/Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.h index 23b8be33a..fdbb5a53c 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.h +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.h @@ -69,6 +69,7 @@ #error "SERIAL_PORT must be from -1 to 3" #endif #if SERIAL_PORT == -1 +extern USBSerial SerialUSB; #define MYSERIAL0 SerialUSB #elif SERIAL_PORT == 0 #define MYSERIAL0 Serial @@ -88,6 +89,7 @@ #endif #define NUM_SERIAL 2 #if SERIAL_PORT_2 == -1 + extern USBSerial SerialUSB; #define MYSERIAL1 SerialUSB #elif SERIAL_PORT_2 == 0 #define MYSERIAL1 Serial diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp index 7406c2d78..aed7e2dce 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp @@ -41,6 +41,7 @@ #include "pins_arduino.h" #include "spi_pins.h" #include "../../core/macros.h" +#include // -------------------------------------------------------------------------- // Public Variables @@ -166,7 +167,7 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) { /** Begin SPI transaction, set clock, bit order, data mode */ void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) { - spiConfig = SPISettings(spiClock, bitOrder, dataMode); + spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode); SPI.beginTransaction(spiConfig); } diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp index 3e890999d..21b703367 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp @@ -163,4 +163,51 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { return false; } +timer_dev* get_timer_dev(int number) { + switch (number) { + #if STM32_HAVE_TIMER(1) + case 1: return &timer1; + #endif + #if STM32_HAVE_TIMER(2) + case 2: return &timer2; + #endif + #if STM32_HAVE_TIMER(3) + case 3: return &timer3; + #endif + #if STM32_HAVE_TIMER(4) + case 4: return &timer4; + #endif + #if STM32_HAVE_TIMER(5) + case 5: return &timer5; + #endif + #if STM32_HAVE_TIMER(6) + case 6: return &timer6; + #endif + #if STM32_HAVE_TIMER(7) + case 7: return &timer7; + #endif + #if STM32_HAVE_TIMER(8) + case 8: return &timer8; + #endif + #if STM32_HAVE_TIMER(9) + case 9: return &timer9; + #endif + #if STM32_HAVE_TIMER(10) + case 10: return &timer10; + #endif + #if STM32_HAVE_TIMER(11) + case 11: return &timer11; + #endif + #if STM32_HAVE_TIMER(12) + case 12: return &timer12; + #endif + #if STM32_HAVE_TIMER(13) + case 13: return &timer14; + #endif + #if STM32_HAVE_TIMER(14) + case 14: return &timer14; + #endif + } +} + #endif // __STM32F1__ diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h index 6c2c6a68c..08486a6ff 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h @@ -32,6 +32,7 @@ // -------------------------------------------------------------------------- #include +#include // -------------------------------------------------------------------------- // Defines @@ -56,8 +57,9 @@ typedef uint16_t hal_timer_t; #define TEMP_TIMER_NUM 2 // index of timer to use for temperature #define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts -#define CAT(a, ...) a ## __VA_ARGS__ -#define TIMER_DEV(num) CAT (&timer, num) +timer_dev* get_timer_dev(int number); + +#define TIMER_DEV(num) get_timer_dev(num) #define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM) #define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM) @@ -86,7 +88,6 @@ typedef uint16_t hal_timer_t; #define HAL_timer_get_count(timer_num) timer_get_count(TIMER_DEV(timer_num)) - #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0) // TODO change this diff --git a/Marlin/src/lcd/malyanlcd.cpp b/Marlin/src/lcd/malyanlcd.cpp index 14f20859f..2292abd1b 100644 --- a/Marlin/src/lcd/malyanlcd.cpp +++ b/Marlin/src/lcd/malyanlcd.cpp @@ -393,7 +393,7 @@ void update_usb_status(const bool forceUpdate) { * The optimize attribute fixes a register Compile * error for amtel. */ -void lcd_update() _O2 { +void lcd_update() { static char inbound_buffer[MAX_CURLY_COMMAND]; // First report USB status.