diff options
author | Manuel Coenen <manuel@duet3d.com> | 2021-01-26 11:59:39 +0300 |
---|---|---|
committer | Manuel Coenen <manuel@duet3d.com> | 2021-01-26 11:59:39 +0300 |
commit | f8bc851baed276ab2ea2e8b91bc2dfe99653d8cb (patch) | |
tree | 077ea93a163bbb13fe5ed34e43b325f85063d8e4 /src/Hardware | |
parent | cfb3fca8b8cf43d74bbf186625d63ae637af7bd5 (diff) |
Fix Duet2_SBC configuration
Add SAM4S hardware directory (just a copy of SAM4E for now)
Move contents of AppUrgentInit() into AppInit()
Diffstat (limited to 'src/Hardware')
-rw-r--r-- | src/Hardware/SAM4E/Main.cpp | 10 | ||||
-rw-r--r-- | src/Hardware/SAM4E/PinDescription.h | 2 | ||||
-rw-r--r-- | src/Hardware/SAM4S/Devices.cpp | 74 | ||||
-rw-r--r-- | src/Hardware/SAM4S/Devices.h | 29 | ||||
-rw-r--r-- | src/Hardware/SAM4S/Main.cpp | 26 | ||||
-rw-r--r-- | src/Hardware/SAM4S/PinDescription.h | 49 |
6 files changed, 189 insertions, 1 deletions
diff --git a/src/Hardware/SAM4E/Main.cpp b/src/Hardware/SAM4E/Main.cpp index 4d26da64..355443b4 100644 --- a/src/Hardware/SAM4E/Main.cpp +++ b/src/Hardware/SAM4E/Main.cpp @@ -7,10 +7,20 @@ */ #include <CoreIO.h> +#include <RepRapFirmware.h> // Program initialisation void AppInit() noexcept { + // When the reset button is pressed on pre-production Duet WiFi boards, if the TMC2660 drivers were previously enabled then we get + // uncommanded motor movements if the STEP lines pick up any noise. Try to reduce that by initialising the pins that control the drivers early here. + // On the production boards the ENN line is pulled high by an external pullup resistor and that prevents motor movements. + for (size_t drive = 0; drive < MaxSmartDrivers; ++drive) + { + pinMode(STEP_PINS[drive], OUTPUT_LOW); + pinMode(DIRECTION_PINS[drive], OUTPUT_LOW); + pinMode(ENABLE_PINS[drive], OUTPUT_HIGH); + } } // End diff --git a/src/Hardware/SAM4E/PinDescription.h b/src/Hardware/SAM4E/PinDescription.h index c39b56ef..d08e16de 100644 --- a/src/Hardware/SAM4E/PinDescription.h +++ b/src/Hardware/SAM4E/PinDescription.h @@ -46,4 +46,4 @@ struct PinDescription : public PinDescriptionBase const char* GetNames() const noexcept { return pinNames; } }; -#endif /* SRC_HARDWARE_SAME70_PINDESCRIPTION_H_ */ +#endif /* SRC_HARDWARE_SAM4E_PINDESCRIPTION_H_ */ diff --git a/src/Hardware/SAM4S/Devices.cpp b/src/Hardware/SAM4S/Devices.cpp new file mode 100644 index 00000000..11d01398 --- /dev/null +++ b/src/Hardware/SAM4S/Devices.cpp @@ -0,0 +1,74 @@ +/* + * Devices.cpp + * + * Created on: 11 Aug 2020 + * Author: David + */ + +#include "Devices.h" +#include <RepRapFirmware.h> +#include <AnalogIn.h> +#include <AnalogOut.h> +#include <pmc/pmc.h> + +AsyncSerial Serial (UART0, UART0_IRQn, ID_UART0, 512, 512, [](AsyncSerial*) noexcept { }, [](AsyncSerial*) noexcept { }); +AsyncSerial Serial1(UART1, UART1_IRQn, ID_UART1, 512, 512, [](AsyncSerial*) noexcept { }, [](AsyncSerial*) noexcept { }); +SerialCDC SerialUSB; + +void UART0_Handler(void) noexcept +{ + Serial.IrqHandler(); +} + +void UART1_Handler(void) noexcept +{ + Serial1.IrqHandler(); +} + +void SerialInit() noexcept +{ + SetPinFunction(APIN_Serial0_RXD, Serial0PeriphMode); + SetPinFunction(APIN_Serial0_TXD, Serial0PeriphMode); + SetPullup(APIN_Serial0_RXD, true); + + SetPinFunction(APIN_Serial1_RXD, Serial1PeriphMode); + SetPinFunction(APIN_Serial1_TXD, Serial1PeriphMode); + SetPullup(APIN_Serial1_RXD, true); +} + +void SdhcInit() noexcept +{ + for (Pin p : HsmciPins) + { + SetPinFunction(p, HsmciPinsFunction); + } +} + +void WireInit() noexcept +{ + pmc_enable_periph_clk(WIRE_INTERFACE_ID); + SetPinFunction(TWI_Data, TWIPeriphMode); + SetPinFunction(TWI_CK, TWIPeriphMode); + + NVIC_DisableIRQ(WIRE_ISR_ID); + NVIC_ClearPendingIRQ(WIRE_ISR_ID); +} + +TwoWire Wire(WIRE_INTERFACE, WireInit); + + +// Device initialisation +void DeviceInit() noexcept +{ + LegacyAnalogIn::AnalogInInit(); + AnalogOut::Init(); + + SerialInit(); + SdhcInit(); +} + +void StopAnalogTask() noexcept +{ +} + +// End diff --git a/src/Hardware/SAM4S/Devices.h b/src/Hardware/SAM4S/Devices.h new file mode 100644 index 00000000..da8d3c08 --- /dev/null +++ b/src/Hardware/SAM4S/Devices.h @@ -0,0 +1,29 @@ +/* + * Devices.h + * + * Created on: 11 Aug 2020 + * Author: David + */ + +#ifndef SRC_HARDWARE_SAM4S_DEVICES_H_ +#define SRC_HARDWARE_SAM4S_DEVICES_H_ + +#include <AsyncSerial.h> +typedef AsyncSerial UARTClass; +#include <USARTClass.h> + +extern AsyncSerial Serial; +extern AsyncSerial Serial1; + +#define SUPPORT_USB 1 // needed by SerialCDC.h +#include <SerialCDC.h> + +extern SerialCDC SerialUSB; + +#include <Wire.h> +extern TwoWire Wire; + +void DeviceInit() noexcept; +void StopAnalogTask() noexcept; + +#endif /* SRC_HARDWARE_SAM4S_DEVICES_H_ */ diff --git a/src/Hardware/SAM4S/Main.cpp b/src/Hardware/SAM4S/Main.cpp new file mode 100644 index 00000000..13261267 --- /dev/null +++ b/src/Hardware/SAM4S/Main.cpp @@ -0,0 +1,26 @@ +/* + * Main.cpp + * Program entry point + * Created on: 11 Jul 2020 + * Author: David + * License: GNU GPL version 3 + */ + +#include <CoreIO.h> +#include <RepRapFirmware.h> + +// Program initialisation +void AppInit() noexcept +{ + // The prototype boards don't have a pulldown on LCD_BEEP, which causes a hissing sound from the beeper on the 12864 display until the pin is initialised + pinMode(LcdBeepPin, OUTPUT_LOW); + + // Set the 12864 display CS pin low to prevent it from receiving garbage due to other SPI traffic + pinMode(LcdCSPin, OUTPUT_LOW); + + // On the prototype boards the stepper driver expansion ports don't have external pullup resistors on their enable pins + pinMode(ENABLE_PINS[5], OUTPUT_HIGH); + pinMode(ENABLE_PINS[6], OUTPUT_HIGH); +} + +// End diff --git a/src/Hardware/SAM4S/PinDescription.h b/src/Hardware/SAM4S/PinDescription.h new file mode 100644 index 00000000..6f552cff --- /dev/null +++ b/src/Hardware/SAM4S/PinDescription.h @@ -0,0 +1,49 @@ +/* + * PinDescription.h + * + * Created on: 10 Jul 2020 + * Author: David + */ + +#ifndef SRC_HARDWARE_SAM4S_PINDESCRIPTION_H_ +#define SRC_HARDWARE_SAM4S_PINDESCRIPTION_H_ + +#include <CoreIO.h> + +// Enum to represent allowed types of pin access +// We don't have a separate bit for servo, because Duet PWM-capable ports can be used for servos if they are on the Duet main board +enum class PinCapability: uint8_t +{ + // Individual capabilities + none = 0, + read = 1, + ain = 2, + write = 4, + pwm = 8, + + // Combinations + ainr = 1|2, + rw = 1|4, + wpwm = 4|8, + rwpwm = 1|4|8, + ainrw = 1|2|4, + ainrwpwm = 1|2|4|8 +}; + +constexpr inline PinCapability operator|(PinCapability a, PinCapability b) noexcept +{ + return (PinCapability)((uint8_t)a | (uint8_t)b); +} + +// The pin description says what functions are available on each pin, filtered to avoid allocating the same function to more than one pin.. +// It is a struct not a class so that it can be direct initialised in read-only memory. +struct PinDescription : public PinDescriptionBase +{ + PinCapability cap; + const char* pinNames; + + PinCapability GetCapability() const noexcept { return cap; } + const char* GetNames() const noexcept { return pinNames; } +}; + +#endif /* SRC_HARDWARE_SAM4S_PINDESCRIPTION_H_ */ |