Skip to content

Commit

Permalink
Merge pull request #39 from MarlinFirmware/bugfix-2.0.x
Browse files Browse the repository at this point in the history
sync from Bugfix 2.0.x
  • Loading branch information
Msq001 authored Jul 1, 2019
2 parents f7bdc3a + 0ca64a0 commit 078d97a
Show file tree
Hide file tree
Showing 161 changed files with 15,356 additions and 1,077 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@
#endif // SDSUPPORT

/**
* By default an onboard SD card reader will be shared as a USB mass-
* By default an onboard SD card reader may be shared as a USB mass-
* storage device. This option hides the SD card from the host PC.
*/
//#define NO_SD_HOST_DRIVE // Disable SD Card access over USB (for security).
Expand Down
4 changes: 2 additions & 2 deletions Marlin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ LIBWARN = -w -Wno-packed-bitfield-compat
CSTANDARD = -std=gnu99
CXXSTANDARD = -std=gnu++11
CDEBUG = -g$(DEBUG)
CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas
CXXWARN = -Wall -Wno-packed-bitfield-compat -Wno-pragmas
CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter
CXXWARN = -Wall -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter
CTUNING = -fsigned-char -funsigned-bitfields -fpack-struct -fno-exceptions \
-fshort-enums -ffunction-sections -fdata-sections
ifneq ($(HARDWARE_MOTHERBOARD),)
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/HAL/HAL_AVR/fastio_AVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ enum ClockSource2 : char {

#if ANY_PIN(FAN, FAN1, FAN2)
#if PIN_EXISTS(FAN2)
#define PWM_CHK_FAN_A(P) (P == FAN_PIN || P == FAN1_PIN || P == FAN2_PIN)
#define PWM_CHK_FAN_A(P) (P == FAN0_PIN || P == FAN1_PIN || P == FAN2_PIN)
#elif PIN_EXISTS(FAN1)
#define PWM_CHK_FAN_A(P) (P == FAN_PIN || P == FAN1_PIN)
#define PWM_CHK_FAN_A(P) (P == FAN0_PIN || P == FAN1_PIN)
#else
#define PWM_CHK_FAN_A(P) (P == FAN_PIN)
#define PWM_CHK_FAN_A(P) (P == FAN0_PIN)
#endif
#else
#define PWM_CHK_FAN_A(P) false
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/HAL/HAL_AVR/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Marlin 3D Printer Firmware
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/HAL/HAL_AVR/pinsDebug_Teensyduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Marlin 3D Printer Firmware
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/HAL/HAL_AVR/pinsDebug_plus_70.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Marlin 3D Printer Firmware
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/HAL/HAL_DUE/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Marlin 3D Printer Firmware
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_sw_spi_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
MOSI_pPio->PIO_CODR = MOSI_dwMask;
DELAY_NS(48);
SCK_pPio->PIO_SODR = SCK_dwMask;
DELAY_NS(125);
DELAY_NS(905);
val <<= 1;
SCK_pPio->PIO_CODR = SCK_dwMask;
}
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/HAL/HAL_LINUX/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Marlin 3D Printer Firmware
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/HAL/HAL_LPC1768/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Marlin 3D Printer Firmware
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down
9 changes: 2 additions & 7 deletions Marlin/src/HAL/HAL_STM32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)


// --------------------------------------------------------------------------
// Includes
// --------------------------------------------------------------------------

#include "HAL.h"

#include "../../inc/MarlinConfig.h"
Expand All @@ -41,7 +36,7 @@
#else
#error "EEPROM_EMULATED_WITH_SRAM is currently only supported for STM32F4xx and STM32F7xx"
#endif
#endif // EEPROM_EMULATED_WITH_SRAM
#endif

// --------------------------------------------------------------------------
// Externals
Expand Down Expand Up @@ -146,4 +141,4 @@ uint16_t HAL_adc_get_result(void) {
return HAL_adc_result;
}

#endif // ARDUINO_ARCH_STM32
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
2 changes: 1 addition & 1 deletion Marlin/src/HAL/HAL_STM32/HAL_Servo_STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ void libServo::move(const int value) {
}
#endif // HAS_SERVOS

#endif // ARDUINO_ARCH_STM32
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
2 changes: 1 addition & 1 deletion Marlin/src/HAL/HAL_STM32/HAL_spi_STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {

#endif // SOFTWARE_SPI

#endif // ARDUINO_ARCH_STM32
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
2 changes: 1 addition & 1 deletion Marlin/src/HAL/HAL_STM32/HAL_timers_STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F);
}

#endif // ARDUINO_ARCH_STM32
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
2 changes: 1 addition & 1 deletion Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ size_t PersistentStore::capacity() {
}

#endif // EEPROM_SETTINGS
#endif // ARDUINO_ARCH_STM32
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
2 changes: 1 addition & 1 deletion Marlin/src/HAL/HAL_STM32/watchdog_STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
}

#endif // USE_WATCHDOG
#endif // ARDUINO_ARCH_STM32
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
43 changes: 16 additions & 27 deletions Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,18 @@
// Local defines
// --------------------------------------------------------------------------

#define NUM_HARDWARE_TIMERS 4

//#define PRESCALER 1
// --------------------------------------------------------------------------
// Types
// --------------------------------------------------------------------------


// --------------------------------------------------------------------------
// Public Variables
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// Private Variables
// --------------------------------------------------------------------------
/* VGPV
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
{ TC0, 0, TC0_IRQn, 0}, // 0 - [servo timer5]
{ TC0, 1, TC1_IRQn, 0}, // 1
{ TC0, 2, TC2_IRQn, 0}, // 2
{ TC1, 0, TC3_IRQn, 2}, // 3 - stepper
{ TC1, 1, TC4_IRQn, 15}, // 4 - temperature
{ TC1, 2, TC5_IRQn, 0}, // 5 - [servo timer3]
{ TC2, 0, TC6_IRQn, 0}, // 6
{ TC2, 1, TC7_IRQn, 0}, // 7
{ TC2, 2, TC8_IRQn, 0}, // 8
};
*/

// --------------------------------------------------------------------------
// Function prototypes
// --------------------------------------------------------------------------
Expand Down Expand Up @@ -101,11 +85,14 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
case 3: irq_num = NVIC_TIMER3; break;
case 4: irq_num = NVIC_TIMER4; break;
case 5: irq_num = NVIC_TIMER5; break;
#ifdef STM32_HIGH_DENSITY
// 6 & 7 are basic timers, avoid them
case 8: irq_num = NVIC_TIMER8_CC; break;
#endif
default:
/**
* We should not get here, add Sanitycheck for timer number. Should be a general timer
* since basic timers do not have CC channels.
* Advanced timers should be skipped if possible too, and are not listed above.
* This should never happen. Add a Sanitycheck for timer number.
* Should be a general timer since basic timers have no CC channels.
*/
break;
}
Expand All @@ -118,23 +105,27 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
switch (timer_num) {
case STEP_TIMER_NUM:
timer_pause(STEP_TIMER_DEV);
timer_set_mode(STEP_TIMER_DEV, STEP_TIMER_CHAN, TIMER_OUTPUT_COMPARE); // counter
timer_set_count(STEP_TIMER_DEV, 0);
timer_set_prescaler(STEP_TIMER_DEV, (uint16_t)(STEPPER_TIMER_PRESCALE - 1));
timer_set_reload(STEP_TIMER_DEV, 0xFFFF);
timer_oc_set_mode(STEP_TIMER_DEV, STEP_TIMER_CHAN, TIMER_OC_MODE_FROZEN, TIMER_OC_NO_PRELOAD); // no output pin change
timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (STEPPER_TIMER_RATE / frequency)));
timer_no_ARR_preload_ARPE(STEP_TIMER_DEV); // Need to be sure no preload on ARR register
timer_attach_interrupt(STEP_TIMER_DEV, STEP_TIMER_CHAN, stepTC_Handler);
nvic_irq_set_priority(irq_num, 1);
nvic_irq_set_priority(irq_num, STEP_TIMER_IRQ_PRIO);
timer_generate_update(STEP_TIMER_DEV);
timer_resume(STEP_TIMER_DEV);
break;
case TEMP_TIMER_NUM:
timer_pause(TEMP_TIMER_DEV);
timer_set_mode(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, TIMER_OUTPUT_COMPARE);
timer_set_count(TEMP_TIMER_DEV, 0);
timer_set_prescaler(TEMP_TIMER_DEV, (uint16_t)(TEMP_TIMER_PRESCALE - 1));
timer_set_reload(TEMP_TIMER_DEV, 0xFFFF);
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), ((F_CPU / TEMP_TIMER_PRESCALE) / frequency)));
timer_attach_interrupt(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, tempTC_Handler);
nvic_irq_set_priority(irq_num, 2);
nvic_irq_set_priority(irq_num, TEMP_TIMER_IRQ_PRIO);
timer_generate_update(TEMP_TIMER_DEV);
timer_resume(TEMP_TIMER_DEV);
break;
Expand All @@ -145,20 +136,18 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM: ENABLE_STEPPER_DRIVER_INTERRUPT(); break;
case TEMP_TIMER_NUM: ENABLE_TEMPERATURE_INTERRUPT(); break;
default: break;
}
}

void HAL_timer_disable_interrupt(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM: DISABLE_STEPPER_DRIVER_INTERRUPT(); break;
case TEMP_TIMER_NUM: DISABLE_TEMPERATURE_INTERRUPT(); break;
default: break;
}
}

static inline bool timer_irq_enabled(const timer_dev * const dev, const uint8_t interrupt) {
return bool(*bb_perip(&(dev->regs).adv->DIER, interrupt));
return bool(*bb_perip(&(dev->regs).gen->DIER, interrupt));
}

bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
Expand Down Expand Up @@ -208,12 +197,12 @@ timer_dev* get_timer_dev(int number) {
case 12: return &timer12;
#endif
#if STM32_HAVE_TIMER(13)
case 13: return &timer14;
case 13: return &timer13;
#endif
#if STM32_HAVE_TIMER(14)
case 14: return &timer14;
#endif
default: return nullptr;
default: return nullptr;
}
}

Expand Down
40 changes: 19 additions & 21 deletions Marlin/src/HAL/HAL_STM32F1/HAL_timers_STM32F1.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
typedef uint16_t hal_timer_t;
#define HAL_TIMER_TYPE_MAX 0xFFFF

#define HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals
#define HAL_TIMER_RATE uint32_t(F_CPU) // frequency of timers peripherals

#define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
Expand All @@ -60,6 +60,9 @@ typedef uint16_t hal_timer_t;
#define PULSE_TIMER_NUM STEP_TIMER_NUM
#define SERVO0_TIMER_NUM 1 // SERVO0 or BLTOUCH

#define STEP_TIMER_IRQ_PRIO 1
#define TEMP_TIMER_IRQ_PRIO 2

#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency

Expand Down Expand Up @@ -126,43 +129,38 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
*/

FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
//compare = MIN(compare, HAL_TIMER_TYPE_MAX);
switch (timer_num) {
case STEP_TIMER_NUM:
timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, compare);
return;
// NOTE: WE have set ARPE = 0, which means the Auto reload register is not preloaded
// and there is no need to use any compare, as in the timer mode used, setting ARR to the compare value
// will result in exactly the same effect, ie trigerring an interrupt, and on top, set counter to 0
timer_set_reload(STEP_TIMER_DEV, compare); // We reload direct ARR as needed during counting up
break;
case TEMP_TIMER_NUM:
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, compare);
return;
default:
return;
}
}

FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM:
return timer_get_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN);
case TEMP_TIMER_NUM:
return timer_get_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN);
default:
return 0;
break;
}
}

FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM:
timer_set_count(STEP_TIMER_DEV, 0);
// No counter to clear
timer_generate_update(STEP_TIMER_DEV);
return;
case TEMP_TIMER_NUM:
timer_set_count(TEMP_TIMER_DEV, 0);
timer_generate_update(TEMP_TIMER_DEV);
return;
default:
return;
}
}

#define HAL_timer_isr_epilogue(TIMER_NUM)

// No command is available in framework to turn off ARPE bit, which is turned on by default in libmaple.
// Needed here to reset ARPE=0 for stepper timer
FORCE_INLINE static void timer_no_ARR_preload_ARPE(timer_dev *dev) {
bb_peri_set_bit(&(dev->regs).gen->CR1, TIMER_CR1_ARPE_BIT, 0);
}

#define TIMER_OC_NO_PRELOAD 0 // Need to disable preload also on compare registers.
3 changes: 0 additions & 3 deletions Marlin/src/HAL/HAL_TEENSY35_36/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Marlin 3D Printer Firmware
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down
Loading

0 comments on commit 078d97a

Please sign in to comment.