mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2026-11-26 23:29:02 +00:00
✅ HAL for Artery Technology AT32F403 (Wanhao 0327001) (#28488)
Co-authored-by: Andy Rexx <299255+cyberman@users.noreply.github.com>
This commit is contained in:
parent
8bf528ddcd
commit
bc8ff4a54b
53 changed files with 2567 additions and 17 deletions
4
.github/workflows/ci-build-tests.yml
vendored
4
.github/workflows/ci-build-tests.yml
vendored
|
|
@ -177,6 +177,10 @@ jobs:
|
|||
- HC32F460E_kobra_go
|
||||
- HC32F460E_kobra_neo
|
||||
|
||||
# AT32
|
||||
- WANHAO_0327001
|
||||
- EASYTHREED_ET4000_PLUS
|
||||
|
||||
# GD32F3
|
||||
- GD32F303RE_creality_mfl
|
||||
- GD32F303RG_kobra2_neo_mfl
|
||||
|
|
|
|||
61
Marlin/src/HAL/AT32/AGENTS.md
Normal file
61
Marlin/src/HAL/AT32/AGENTS.md
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# AGENTS.md — AT32 HAL
|
||||
|
||||
Working notes and conventions for the **AT32 HAL** folder (`Marlin/src/HAL/AT32/`). This file is the precedent for per-HAL `AGENTS.md` files: it captures the build/test loop, the framework-integration gotchas that are NOT obvious from the source, and the conventions a maintainer or agent must follow when touching this HAL.
|
||||
|
||||
## Build & Test Loop
|
||||
|
||||
Always validate with `mftest` (it regenerates `Marlin/Configuration.h` per target, which raw `pio run -e` does not do reliably):
|
||||
|
||||
```bash
|
||||
cd "$(git rev-parse --show-toplevel)"
|
||||
buildroot/bin/mftest -t WANHAO_0327001 -n1 -y # AT32F403ARGT7, 1 MB flash
|
||||
buildroot/bin/mftest -t EASYTHREED_ET4000_PLUS -n1 -y # AT32F403ARCT7, 256 KB flash
|
||||
```
|
||||
|
||||
Both targets must be green before considering AT32 work done. The 256 KB EasyThreed builds are the tighter constraint — if they fit, the Wanhao (1 MB) build will too.
|
||||
|
||||
> Do NOT use `rm -rf .pio/build/...` to force a rebuild — the cross-profile write guard blocks it and it is unsafe. Use `pio run -e <env> -t clean` (removes only build artifacts) or just let `mftest` rebuild.
|
||||
|
||||
## Framework / Platform Integration
|
||||
|
||||
The AT32 Arduino core is **not** in this repo. PlatformIO downloads it from the [MarlinFirmware/ArduinoCore-AT32F4](https://github.com/MarlinFirmware/ArduinoCore-AT32F4) fork (tag `marlin-1.0.0.3`, branch `marlin`), which carries the Marlin-specific fixes and the `marlin_at32f403` variant. The platform is [MarlinFirmware/platform-at32](https://github.com/MarlinFirmware/platform-at32) (tag `1.0.0` in `ini/at32.ini`); its `platform.json` names the framework archive and its `boards/` holds the board JSONs.
|
||||
|
||||
- Framework changes (core, variant, linker scripts, build script) are made in the fork, then pinned by updating the framework URL in platform-at32's `platform.json`, tagging platform-at32, and updating the platform URL in `ini/at32.ini`.
|
||||
- Editing `~/.platformio/packages/framework-arduino-at32f4/` only changes your local build. It is overwritten on reinstall and never reaches a PR.
|
||||
- Board JSONs live in platform-at32's `boards/`, not in Marlin.
|
||||
|
||||
### Gotchas that are not obvious from the source
|
||||
|
||||
1. **Pins are an `enum`, not `#define`.** The core's `libcore/gpio.h` defines `PC6`, `PC7`, … as a C `enum`. The C preprocessor cannot see `enum` values in `#if`, so `PIN_EXISTS(PC6)` evaluated `PC6` as `0` → false pin-conflict errors (e.g. `PART_COOLING_FAN1_PIN == PART_COOLING_FAN0_PIN`). The fix: the framework variant's `variants/marlin_at32f403/pins_arduino.h` (included by `HAL.h` as `<pins_arduino.h>`) defines numeric macros (`#define PC6 38`, …) in enum order, checked by a `static_assert` on `PIN_MAX`. The AT32F403A has ports A–E only. **Do not "fix" the symptom by editing SanityCheck — fix it at the pin-define level.**
|
||||
|
||||
2. **Optimization flags live in the framework build script, not `platform.json`.** PlatformIO does not auto-apply a custom `platform.json` `build.flags` to a custom framework `platformio-build-arduino.py`. Without `-Os -DNDEBUG` appended to `CFLAGS`/`CXXFLAGS` in that script, Marlin compiles to ~2 MB and overflows flash. Hard-float `LINKFLAGS` (`-mfloat-abi=hard -mfpu=fpv4-sp-d16`) are also required there or the link step rejects the hard-float objects.
|
||||
|
||||
3. **`FrameLib` is an empty stub.** The shipped `FrameLib.a` has no symbols. The real peripheral driver code is in `system/Drivers/Firmware/src/` and is compiled as `BuildSources`. Do not add `-lFrameLib` back.
|
||||
|
||||
4. **Device header family macro.** `system/Drivers/Firmware/src/at32f403a_407.h` ships with `//#define AT32F403Axx` commented out. It must be uncommented or peripheral base addresses are undefined. Board JSONs also pass `-DAT32F403Axx` in `extra_flags`.
|
||||
|
||||
5. **USB-CDC is guarded out.** Marlin uses hardware UART, not USB-CDC. All USB-CDC code in `mcu_core.c` / `usb_vcp_wrapper.cpp` / `usb_vcp_wrapper.h` is behind `#ifdef AT32_USB_CDC` (undefined for Marlin). The core also declared `extern VcpSerial Serial;` which conflicts with Marlin's `Serial`; guarding it out is what lets the `HardwareSerial& Serial = Serial1;` alias stand.
|
||||
|
||||
6. **The bare `Serial` global + `println`.** The core only defines `Serial1`–`Serial5` / `Serial7`. Marlin feature code in the core (`DShot.cpp`, `UbxGpsParser.cpp`) references `Serial.println(...)`. `HardwareSerial.h` declares `extern HardwareSerial& Serial;`, `HardwareSerial.cpp` defines `HardwareSerial& Serial = Serial1;` and a `println(const char*)` that emits CRLF via `write((uint8_t)0x0D)` / `write((uint8_t)0x0A)`. **The core files are CRLF and string-literal `\r\n` escapes get mangled by some edit layers — use the hex byte writes instead.**
|
||||
|
||||
7. **Flash size / linker script.** The ARCT7 (EasyThreed ET4000+) has 256 KB flash and uses `AT32F403AxR_FLASH.ld`; the ARGT7 (Wanhao) has 1 MB and uses `AT32F403AxG_FLASH.ld`; the AT32F407RCT7 (K7 Rev. B) uses `AT32F407xC_FLASH.ld`. These live in the framework variant and are named by the board JSONs.
|
||||
|
||||
8. **EEPROM backend is per-board, not auto-selected.** Marlin does NOT auto-pick `SDCARD_EEPROM_EMULATION`. Each AT32 board's pins file must `#define SDCARD_EEPROM_EMULATION` (both Wanhao and EasyThreed do). `PersistentStore` is implemented in `eeprom/eeprom_sdcard.cpp` (ported from the STM32 HAL).
|
||||
|
||||
9. **Pin modes come from the GPIO registers.** The core doesn't track pin modes, so `fastio.h` reads each pin's 4-bit config from CFGLR/CFGHR (`_GET_CFG`) for `IS_INPUT`/`IS_OUTPUT`/`IS_ANALOG`/`IS_MUX`. M43 (`pinsDebug.h`) uses these plus the timer registers (`ctrl1.tmren`, `cctrl` channel enable, `cNdt`/`pr`) to report PWM. The core's `analogRead()` takes a pin, so `PinsDebug::analog_index()` returns the pin and `print_analog()` shows the ADC channel.
|
||||
|
||||
10. **`pinMode` overload.** The core declares `pinMode(pin, PinMode_TypeDef)` strictly; `M43.cpp` calls `pinMode(pin, bool)`. `HAL/AT32/fastio.h` adds a `pinMode(uint8_t, int)` overload.
|
||||
|
||||
11. **`SPI` global.** The core leaves the global `SPI` commented out; `HAL_SPI.cpp` instantiates `SPIClass SPI(SPI_CLASS_1_SPI);` and provides `spiBegin()`.
|
||||
|
||||
## Conventions
|
||||
|
||||
- All HAL source is guarded by `#ifdef ARDUINO_ARCH_AT32` (the core does not define it; `ini/at32.ini` adds `-DARDUINO_ARCH_AT32`).
|
||||
- Keep HAL changes in `Marlin/src/HAL/AT32/` and board pin changes in `Marlin/src/pins/at32f4/`. Platform and board-JSON changes go in MarlinFirmware/platform-at32; framework changes go in the ArduinoCore-AT32F4 fork.
|
||||
- After changing the framework fork, tag it, update platform-at32 and tag that, then update `ini/at32.ini` and verify the build before committing.
|
||||
- Pin mappings in `pins_at32f4/*.h` are placeholders pending schematic verification — mark them as such and do not "fix" them to match guesses without a source.
|
||||
|
||||
## Related
|
||||
|
||||
- `README.md` in this folder — overview and supported boards.
|
||||
- `Marlin/src/HAL/shared/` — shared HAL APIs (`eeprom_api`, SPI helpers) the AT32 HAL reuses.
|
||||
91
Marlin/src/HAL/AT32/HAL.cpp
Normal file
91
Marlin/src/HAL/AT32/HAL.cpp
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "HAL.h"
|
||||
#include "../../core/mstring.h"
|
||||
#include "../../core/serial.h"
|
||||
#include "../../core/language.h"
|
||||
#include "../../core/utility.h"
|
||||
#include "../../core/endianness.h"
|
||||
#include "../../MarlinCore.h"
|
||||
#include "core_hooks.h"
|
||||
|
||||
extern "C" char* _sbrk(int incr);
|
||||
|
||||
#if ENABLED(MARLIN_DEV_MODE)
|
||||
inline void HAL_clock_frequencies_dump() {
|
||||
SERIAL_ECHOPGM("-- clocks dump --\nF_CPU=", F_CPU);
|
||||
SERIAL_EOL();
|
||||
}
|
||||
#endif
|
||||
|
||||
uint16_t MarlinHAL::adc_result = 0;
|
||||
|
||||
void MarlinHAL::watchdog_init() {
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
WDG_Init(5000); // 5-second timeout
|
||||
#endif
|
||||
}
|
||||
|
||||
void MarlinHAL::watchdog_refresh() {
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
WDG_ReloadCounter();
|
||||
#endif
|
||||
}
|
||||
|
||||
void MarlinHAL::init() {
|
||||
NVIC_SetPriorityGrouping(0x3);
|
||||
TERN_(MARLIN_DEV_MODE, HAL_clock_frequencies_dump());
|
||||
#if ENABLED(MARLIN_DEV_MODE)
|
||||
if (freeMemory() < 1024) SERIAL_ECHOLNPGM("HAL: low memory after init!");
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t MarlinHAL::get_reset_source() {
|
||||
return 1; // Simplified: always report power-on reset
|
||||
}
|
||||
|
||||
int MarlinHAL::freeMemory() {
|
||||
volatile char top;
|
||||
return &top - _sbrk(0);
|
||||
}
|
||||
|
||||
void MarlinHAL::set_pwm_duty(const pin_t pin, const uint16_t value, const uint16_t scale, const bool invert) {
|
||||
const uint16_t val = invert ? scale - value : value;
|
||||
// Map from [0,scale] to [0,255] for PWM_Write
|
||||
const uint16_t duty = (scale == 255) ? val : (uint16_t)map(val, 0, scale, 0, 255);
|
||||
PWM_Write(pin, duty);
|
||||
}
|
||||
|
||||
void MarlinHAL::set_pwm_frequency(const pin_t pin, const uint16_t f_desired) {
|
||||
PWM_Init(pin, 255, f_desired);
|
||||
}
|
||||
|
||||
void flashFirmware(const int16_t) { MarlinHAL::reboot(); }
|
||||
|
||||
// Emergency parser integration is handled via core_hook_usart_rx_irq
|
||||
// in core_hooks.h (weak alias pattern). The actual implementation
|
||||
// is in the AT32 core's serial IRQ handler.
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
115
Marlin/src/HAL/AT32/HAL.h
Normal file
115
Marlin/src/HAL/AT32/HAL.h
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* HAL for AT32F403 based boards
|
||||
*
|
||||
* Note: MarlinHAL class is in MarlinHAL.h/cpp
|
||||
*/
|
||||
|
||||
#define CPU_32_BIT
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
#include "../shared/math_32bit.h"
|
||||
#include "../shared/HAL_SPI.h"
|
||||
#include <pins_arduino.h> // Pin names as macros (from the framework variant)
|
||||
|
||||
#include "fastio.h"
|
||||
#include "timers.h"
|
||||
#include "MarlinHAL.h"
|
||||
|
||||
//
|
||||
// Default graphical display delays
|
||||
//
|
||||
#define CPU_ST7920_DELAY_1 300
|
||||
#define CPU_ST7920_DELAY_2 40
|
||||
#define CPU_ST7920_DELAY_3 340
|
||||
|
||||
//
|
||||
// Serial Ports
|
||||
//
|
||||
#include "MarlinSerial.h"
|
||||
|
||||
//
|
||||
// Emergency Parser
|
||||
//
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
extern "C" void usart_rx_irq_hook(uint8_t ch, uint8_t usart);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Misc. Defines
|
||||
//
|
||||
#define square(x) ((x) * (x))
|
||||
|
||||
#ifndef strncpy_P
|
||||
#define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
|
||||
#endif
|
||||
|
||||
#ifndef analogInputToDigitalPin
|
||||
#define analogInputToDigitalPin(p) pin_t(p)
|
||||
#endif
|
||||
|
||||
#define CRITICAL_SECTION_START() \
|
||||
const bool irqon = !__get_PRIMASK(); \
|
||||
__disable_irq(); \
|
||||
__DSB();
|
||||
#define CRITICAL_SECTION_END() \
|
||||
__DSB(); \
|
||||
if (irqon) __enable_irq();
|
||||
|
||||
#ifndef cli
|
||||
#define cli() __disable_irq() // __set_PRIMASK(1)
|
||||
#endif
|
||||
#ifndef sei
|
||||
#define sei() __enable_irq() // __set_PRIMASK(0)
|
||||
#endif
|
||||
|
||||
#define __bss_end __bss_end__
|
||||
|
||||
// Servo
|
||||
class libServo;
|
||||
typedef libServo hal_servo_t;
|
||||
#define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos()
|
||||
#define RESUME_SERVO_OUTPUT() libServo::resume_all_servos()
|
||||
|
||||
#define JTAG_DISABLE()
|
||||
#define JTAGSWD_DISABLE()
|
||||
#define JTAGSWD_RESET()
|
||||
|
||||
#ifdef ADC_RESOLUTION
|
||||
#define HAL_ADC_RESOLUTION ADC_RESOLUTION
|
||||
#else
|
||||
#define HAL_ADC_RESOLUTION 12
|
||||
#endif
|
||||
#define HAL_ADC_VREF_MV 3300
|
||||
|
||||
#define GET_PIN_MAP_PIN(index) index
|
||||
#define GET_PIN_MAP_INDEX(pin) pin
|
||||
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
|
||||
|
||||
#define HAL_CAN_SET_PWM_FREQ
|
||||
|
||||
extern "C" char* _sbrk(int incr);
|
||||
extern "C" char* dtostrf(double val, signed char width, unsigned char prec, char* sout);
|
||||
107
Marlin/src/HAL/AT32/HAL_SPI.cpp
Normal file
107
Marlin/src/HAL/AT32/HAL_SPI.cpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include "../platforms.h"
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
// The AT32 Arduino core leaves the global SPI instances commented out,
|
||||
// expecting the application to instantiate one. Bind Marlin's global `SPI`
|
||||
// object to the peripheral selected by the board.
|
||||
#ifndef SPI_DEVICE
|
||||
#define SPI_DEVICE 1
|
||||
#endif
|
||||
|
||||
#if SPI_DEVICE == 1
|
||||
SPIClass SPI(SPI_CLASS_1_SPI);
|
||||
#elif SPI_DEVICE == 2
|
||||
SPIClass SPI(SPI_CLASS_2_SPI);
|
||||
#elif SPI_DEVICE == 3
|
||||
SPIClass SPI(SPI_CLASS_3_SPI);
|
||||
#else
|
||||
#error "Unsupported AT32 SPI_DEVICE. Expected 1, 2, or 3."
|
||||
#endif
|
||||
|
||||
void spiBegin() {
|
||||
#if PIN_EXISTS(SD_SS)
|
||||
OUT_WRITE(SD_SS_PIN, HIGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// Hardware SPI
|
||||
// ------------------------
|
||||
|
||||
/**
|
||||
* Initialize hardware SPI
|
||||
* Set SCK rate to appropriate speed for spiRate [0,6]
|
||||
*/
|
||||
void spiInit(uint8_t spiRate) {
|
||||
uint32_t clock;
|
||||
switch (spiRate) {
|
||||
case 0: clock = 8000000; break; // ~8-10 MHz
|
||||
case 1: clock = 4000000; break; // ~4-5 MHz
|
||||
case 2: clock = 2000000; break; // ~2-2.5 MHz
|
||||
case 3: clock = 1000000; break; // ~1-1.25 MHz
|
||||
case 4: clock = 500000; break; // ~500-625 kHz
|
||||
case 5: clock = 250000; break; // ~250-312 kHz
|
||||
case 6: clock = 125000; break; // ~125-156 kHz
|
||||
default: clock = 8000000; break;
|
||||
}
|
||||
SPI.begin();
|
||||
SPI.setClock(clock);
|
||||
}
|
||||
|
||||
/** SPI receive a byte */
|
||||
uint8_t spiRec() {
|
||||
return SPI.transfer(0xFF);
|
||||
}
|
||||
|
||||
/** SPI send a byte */
|
||||
void spiSend(uint8_t data) {
|
||||
SPI.transfer(data);
|
||||
}
|
||||
|
||||
/** SPI read data into buffer */
|
||||
void spiRead(uint8_t *buf, uint16_t nbyte) {
|
||||
while (nbyte--) *buf++ = SPI.transfer(0xFF);
|
||||
}
|
||||
|
||||
/** SPI send token and data block */
|
||||
void spiSendBlock(uint8_t token, const uint8_t *buf) {
|
||||
SPI.transfer(token);
|
||||
if (buf) {
|
||||
for (uint16_t i = 0; i < 512; i++) {
|
||||
SPI.transfer(buf[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (uint16_t i = 0; i < 512; i++) {
|
||||
SPI.transfer(0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __HAL_AT32__
|
||||
80
Marlin/src/HAL/AT32/MarlinHAL.h
Normal file
80
Marlin/src/HAL/AT32/MarlinHAL.h
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// AT32 pin type: numeric index into PIN_MAP[] (uint8_t, values PA0=0 .. PD15=63)
|
||||
typedef uint8_t pin_t;
|
||||
|
||||
#ifndef HAL_ADC_RESOLUTION
|
||||
#define HAL_ADC_RESOLUTION 12
|
||||
#endif
|
||||
#define HAL_ADC_VREF_MV 3300
|
||||
|
||||
/**
|
||||
* HAL class for Marlin on AT32F403
|
||||
*/
|
||||
class MarlinHAL {
|
||||
public:
|
||||
MarlinHAL() = default;
|
||||
|
||||
// Watchdog — AT32 core provides WDG_Init / WDG_ReloadCounter
|
||||
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||
|
||||
static void init();
|
||||
static void init_board() {}
|
||||
static void reboot() { NVIC_SystemReset(); }
|
||||
|
||||
static bool isr_state() { return !__get_PRIMASK(); }
|
||||
static void isr_on() { __enable_irq(); }
|
||||
static void isr_off() { __disable_irq(); }
|
||||
static void delay_ms(const int ms) { delay(ms); }
|
||||
|
||||
static void idletask() {}
|
||||
|
||||
static uint8_t get_reset_source();
|
||||
static void clear_reset_source() {}
|
||||
|
||||
static int freeMemory();
|
||||
|
||||
// ADC — AT32 core analogRead() is synchronous; result is stored here
|
||||
static uint16_t adc_result;
|
||||
|
||||
static void adc_init() {}
|
||||
static void adc_enable(const pin_t pin) { pinMode(pin, INPUT_ANALOG); }
|
||||
static void adc_start(const pin_t pin) { adc_result = (uint16_t)analogRead(pin); }
|
||||
static bool adc_ready() { return true; }
|
||||
static uint16_t adc_value() { return adc_result; }
|
||||
|
||||
// PWM — AT32 core: PWM_Init(pin, resolution, freq) / PWM_Write(pin, value)
|
||||
static void set_pwm_duty(const pin_t pin, const uint16_t value, const uint16_t scale = 255, const bool invert = false);
|
||||
static void set_pwm_frequency(const pin_t pin, const uint16_t f_desired);
|
||||
};
|
||||
|
||||
// M997 SD firmware update (just reboots; let the bootloader do it)
|
||||
#ifndef PLATFORM_M997_SUPPORT
|
||||
#define PLATFORM_M997_SUPPORT
|
||||
#endif
|
||||
|
||||
void flashFirmware(const int16_t);
|
||||
36
Marlin/src/HAL/AT32/MarlinSPI.h
Normal file
36
Marlin/src/HAL/AT32/MarlinSPI.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* AT32F403 SPI support
|
||||
* Uses Arduino's built-in SPI library
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
// AT32 SPI pins are defined in spi_pins.h
|
||||
// SPI clock speed defaults
|
||||
#ifndef SPI_CLOCK
|
||||
#define SPI_CLOCK 8000000 // 8 MHz default
|
||||
#endif
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
42
Marlin/src/HAL/AT32/MarlinSerial.cpp
Normal file
42
Marlin/src/HAL/AT32/MarlinSerial.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "MarlinSerial.h"
|
||||
|
||||
// AT32 core provides Serial1–Serial5 and Serial7 as HardwareSerial globals.
|
||||
// Each adapter wraps the global by pointer; each MSerialN wraps the adapter.
|
||||
static AT32SerialAdapter at32_adapter1(&Serial1);
|
||||
static AT32SerialAdapter at32_adapter2(&Serial2);
|
||||
static AT32SerialAdapter at32_adapter3(&Serial3);
|
||||
static AT32SerialAdapter at32_adapter4(&Serial4);
|
||||
static AT32SerialAdapter at32_adapter5(&Serial5);
|
||||
|
||||
MSerialT MSerial1(true, at32_adapter1);
|
||||
MSerialT MSerial2(true, at32_adapter2);
|
||||
MSerialT MSerial3(true, at32_adapter3);
|
||||
MSerialT MSerial4(true, at32_adapter4);
|
||||
MSerialT MSerial5(true, at32_adapter5);
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
70
Marlin/src/HAL/AT32/MarlinSerial.h
Normal file
70
Marlin/src/HAL/AT32/MarlinSerial.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// The AT32 Arduino core's HardwareSerial is a complete class (declared in
|
||||
// libcore/HardwareSerial.h) but it does NOT inherit Arduino's Print/Stream.
|
||||
// Marlin's serial hooks need a type that provides begin()/read()/write()/
|
||||
// available()/end()/flush()/operator bool(), so we wrap it with an adapter
|
||||
// rather than subclassing (the core already instantiates Serial1..Serial5 as
|
||||
// globals, so we wrap those by reference).
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "../../core/serial_hook.h"
|
||||
#include <libcore/HardwareSerial.h>
|
||||
|
||||
struct AT32SerialAdapter {
|
||||
HardwareSerial* const _uart;
|
||||
|
||||
AT32SerialAdapter(HardwareSerial* uart) : _uart(uart) {}
|
||||
|
||||
void begin(uint32_t baud) { _uart->begin(baud); }
|
||||
void end() {} // Not provided by AT32 core; no-op
|
||||
|
||||
int available() { return _uart->available(); }
|
||||
int read() { return _uart->read(); }
|
||||
size_t write(uint8_t c) { _uart->write(c); return 1; }
|
||||
size_t write(const uint8_t* buf, size_t len) { _uart->write(buf, (uint16_t)len); return len; }
|
||||
void flush() {} // Not provided by AT32 core; no-op
|
||||
|
||||
operator bool() { return true; }
|
||||
};
|
||||
|
||||
typedef ForwardSerial1Class<AT32SerialAdapter> MSerialT;
|
||||
|
||||
// Serial port index range (AT32 core provides Serial1–Serial5 and Serial7)
|
||||
#define SERIAL_INDEX_MIN 1
|
||||
#define SERIAL_INDEX_MAX 5
|
||||
|
||||
// Declare MSerial1–MSerial5 as ForwardSerial instances
|
||||
#define DECLARE_SERIAL(X) extern MSerialT MSerial##X
|
||||
|
||||
#include "../shared/serial_ports.h"
|
||||
|
||||
extern MSerialT MSerial1;
|
||||
extern MSerialT MSerial2;
|
||||
extern MSerialT MSerial3;
|
||||
extern MSerialT MSerial4;
|
||||
extern MSerialT MSerial5;
|
||||
|
||||
#if defined(LCD_SERIAL_PORT) && ANY(HAS_DGUS_LCD, EXTENSIBLE_UI)
|
||||
#define LCD_SERIAL_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
|
||||
#endif
|
||||
95
Marlin/src/HAL/AT32/MinSerial.cpp
Normal file
95
Marlin/src/HAL/AT32/MinSerial.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(POSTMORTEM_DEBUGGING)
|
||||
|
||||
#include "../shared/MinSerial.h"
|
||||
|
||||
/**
|
||||
* Minimal AT32 USART register layout for postmortem output.
|
||||
*
|
||||
* AT32F403A USART register offsets (from datasheet):
|
||||
* sts +0x00 status (tdbe = bit 7: TX data buffer empty)
|
||||
* dt +0x04 data register
|
||||
* brt +0x08 baud rate
|
||||
* ctrl1 +0x0C control 1 (TE = bit 3, UEN = bit 13)
|
||||
* ctrl2 +0x10 control 2
|
||||
* ctrl3 +0x14 control 3
|
||||
*/
|
||||
struct AT32USARTMin {
|
||||
volatile uint32_t sts;
|
||||
volatile uint32_t dt;
|
||||
volatile uint32_t brt;
|
||||
volatile uint32_t ctrl1;
|
||||
};
|
||||
|
||||
static const uintptr_t usart_base[] = {
|
||||
0x40013800, // USART1 (APB2)
|
||||
0x40004400, // USART2 (APB1)
|
||||
0x40004800, // USART3 (APB1)
|
||||
0x40004C00, // UART4 (APB1)
|
||||
0x40005000, // UART5 (APB1)
|
||||
};
|
||||
|
||||
#if WITHIN(SERIAL_PORT, 1, 5)
|
||||
static AT32USARTMin* const regs = (AT32USARTMin*)usart_base[SERIAL_PORT - 1];
|
||||
#endif
|
||||
|
||||
static void TXBegin() {
|
||||
#if WITHIN(SERIAL_PORT, 1, 5)
|
||||
// Disable USART interrupt in NVIC so we can poll safely
|
||||
const IRQn_Type irqs[] = {
|
||||
USART1_IRQn, USART2_IRQn, USART3_IRQn, UART4_IRQn, UART5_IRQn
|
||||
};
|
||||
NVIC_DisableIRQ(irqs[SERIAL_PORT - 1]);
|
||||
__DSB(); __ISB();
|
||||
// Re-enable TX only: TE | UEN (preserve baud rate register)
|
||||
uint32_t brt = regs->brt;
|
||||
regs->ctrl1 = 0;
|
||||
regs->ctrl2 = 0;
|
||||
regs->ctrl3 = 0;
|
||||
regs->brt = brt;
|
||||
regs->ctrl1 = (1U << 3) | (1U << 13); // TE | UEN
|
||||
#endif
|
||||
}
|
||||
|
||||
#define sw_barrier() __asm__ volatile("": : :"memory")
|
||||
|
||||
static void TX(char c) {
|
||||
#if WITHIN(SERIAL_PORT, 1, 5)
|
||||
constexpr uint32_t TDBE = (1U << 7);
|
||||
while (!(regs->sts & TDBE)) { sw_barrier(); }
|
||||
regs->dt = (uint32_t)(uint8_t)c;
|
||||
#endif
|
||||
}
|
||||
|
||||
void install_min_serial() {
|
||||
HAL_min_serial_init = &TXBegin;
|
||||
HAL_min_serial_out = &TX;
|
||||
}
|
||||
|
||||
#endif // POSTMORTEM_DEBUGGING
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
88
Marlin/src/HAL/AT32/README.md
Normal file
88
Marlin/src/HAL/AT32/README.md
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
# AT32F403 HAL for Marlin
|
||||
|
||||
This HAL provides support for Artery Technology **AT32F403-series** ARM Cortex-M4 microcontrollers. It was added to satisfy feature requests #24894 (Wanhao 0327001 v2.0 / AT32F403ARGT7) and #25952 (EasyThreed K7 ET4000+ / AT32F403ARCT7).
|
||||
|
||||
The HAL is modeled on the HC32 HAL pattern: a Chinese-vendor Cortex-M4 MCU with its own Arduino core (not stm32duino), so only the Cortex-M4 core / SysTick / NVIC / FPU are binary-compatible with STM32 — the entire peripheral layer differs.
|
||||
|
||||
## Supported Boards
|
||||
|
||||
| Board | MCU | Flash | PlatformIO env | Pins file |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `BOARD_WANHAO_0327001` (7500) | AT32F403ARGT7 | 1 MB | `WANHAO_0327001` | `src/pins/at32f4/pins_WANHAO_0327001.h` |
|
||||
| `BOARD_EASYTHREED_ET4000_PLUS` (7501) | AT32F403ARCT7 | 256 KB | `EASYTHREED_ET4000_PLUS` | `src/pins/at32f4/pins_EASYTHREED_ET4000_PLUS.h` |
|
||||
| `BOARD_EASYTHREED_K7_REVB_AT32F407` (7502) | AT32F407RCT7 | 256 KB | `EASYTHREED_K7_REVB_AT32F407` | `src/pins/at32f4/pins_EASYTHREED_K7_REVB_AT32F407.h` |
|
||||
|
||||
**Build status:** both targets compile and link cleanly via `mftest` (see `AGENTS.md` in this folder).
|
||||
|
||||
## Why a New HAL (not STM32 reuse)
|
||||
|
||||
The AT32F403 is **not register-compatible** with STM32F4 despite sharing the Cortex-M4 core:
|
||||
|
||||
| Component | STM32F4 | AT32F403 | Compatible? |
|
||||
| --- | --- | --- | --- |
|
||||
| Clock module | `RCC` | `CRM` | no — different registers/bits/PLL ranges |
|
||||
| GPIO alt-func | `AFR[0/1]` | `AFR1/AFR2` | no — different naming/indices |
|
||||
| Internal osc | 16 MHz HSI | 48 MHz HICK | no — different frequency |
|
||||
| PLL config | ST-specific | `CRM_PLL_OUTPUT_RANGE_*` | no — AT32-unique |
|
||||
| Unique periph | — | ACC (auto clock cal) | no — no STM32 equivalent |
|
||||
| Flash | Single bank | Dual bank (256+768 KB) | differs |
|
||||
|
||||
Arduino cores (`rizacelik/ArduinoCore-AT32F4`, derived from `WeActStudio/ArduinoCore-AT32F4`) wrap Artery's own Standard Peripheral Library, not stm32duino, so there is no AT32 support in `Arduino_Core_STM32`.
|
||||
|
||||
## Arduino Core Dependency
|
||||
|
||||
Uses `rizacelik/ArduinoCore-AT32F4` v1.0.0 (based on WeActStudio's core). Key core facts driving the HAL:
|
||||
|
||||
- Header chain `Arduino.h` → `libcore/mcu_core.h` → `adc.h`, `delay.h`, `exti.h`, `gpio.h`, `pwm.h`, `timer.h`, `wdg.h`.
|
||||
- `PIN_MAP[pin]` → `{ GPIOx, TIMx, ADCx, GPIO_Pin_x, TimerChannel, ADC_Channel }`; `IS_PIN` / `IS_ADC_PIN` / `IS_PWM_PIN`.
|
||||
- `F_CPU = system_core_clock` (set at runtime) — build forces `-DF_CPU=240000000L` for `constexpr` math.
|
||||
- **The core defines pin names (`PC6`, `PC7`, …) as a C `enum`, not `#define`.** The C preprocessor cannot see `enum` values in `#if`, so Marlin's `PIN_EXISTS(PC6)` evaluated `PC6` as `0` and produced false pin-conflict errors. The `marlin_at32f403` variant's `pins_arduino.h` (included by `HAL.h`) defines the same names as numeric macros (`#define PC6 38`, etc.) matching the enum order, with a `static_assert` on `PIN_MAX`.
|
||||
- The core's `HardwareSerial` is **NOT** derived from Arduino `Stream` (no `flush()` / `end()` / `peek()`); `AT32SerialAdapter` wraps it. The core also does not define a bare `Serial` global (only `Serial1`–`Serial5`), so `HardwareSerial.cpp` provides `HardwareSerial& Serial = Serial1;` plus a `println(const char*)` for Marlin feature code.
|
||||
- No core `Servo` class, no panic/postmortem — `MinSerial` uses raw USART writes.
|
||||
- USB-CDC is **not** used by Marlin (it uses hardware UART). All USB-CDC code in the core is guarded behind `#ifdef AT32_USB_CDC` (undefined for Marlin).
|
||||
|
||||
## PlatformIO Integration
|
||||
|
||||
The PlatformIO platform is [MarlinFirmware/platform-at32](https://github.com/MarlinFirmware/platform-at32), referenced by tag in `ini/at32.ini`. Its board JSONs: `at32f403argt7` (Wanhao, 1 MB), `at32f403arct7` (EasyThreed, 256 KB), `at32f407rct7` (EasyThreed K7 Rev. B, 256 KB). Variant: `marlin_at32f403` (provided by the framework package). Build flags add `-DARDUINO_ARCH_AT32`, `-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16`.
|
||||
|
||||
Build/test commands:
|
||||
|
||||
```bash
|
||||
cd $MARLIN_REPO
|
||||
buildroot/bin/mftest -t WANHAO_0327001 -n1 -y
|
||||
buildroot/bin/mftest -t EASYTHREED_ET4000_PLUS -n1 -y
|
||||
# or directly:
|
||||
pio run -e WANHAO_0327001
|
||||
pio run -e EASYTHREED_ET4000_PLUS
|
||||
```
|
||||
|
||||
> Note: `pio run -e <env>` resolves the board from the generated `Marlin/Configuration.h`. If you switch envs with raw `pio`, an outdated generated `Configuration.h` can cause a spurious "incompatible with BOARD_…" preflight error. `mftest` regenerates the config correctly per target, so prefer `mftest` for HAL validation.
|
||||
|
||||
The framework (downloaded from the [MarlinFirmware/ArduinoCore-AT32F4](https://github.com/MarlinFirmware/ArduinoCore-AT32F4) fork, branch `marlin`) and the platform ([MarlinFirmware/platform-at32](https://github.com/MarlinFirmware/platform-at32)) carry the integration fixes needed to build Marlin (optimization flags, hard-float link flags, peripheral-driver sources, clock config, 256 KB linker script, USB-CDC guards). See `AGENTS.md` in this folder for the full list and the integration gotchas.
|
||||
|
||||
## Implementation Status
|
||||
|
||||
Fully compiling for both boards. Key subsystems:
|
||||
|
||||
- Core HAL (`HAL.h` / `MarlinHAL`), timers (TMR2 stepper / TMR4 temp @ 240 MHz), fast GPIO, serial (`AT32SerialAdapter`), servo (via `PWM_Init`/`PWM_Write`), PWM, ADC, endstop interrupts, SPI, SoC temp sensor, M43 pin debugging.
|
||||
- EEPROM: `SDCARD_EEPROM_EMULATION` is enabled per-board in the pins files; the `PersistentStore` SD backend is implemented in `eeprom/eeprom_sdcard.cpp`.
|
||||
- SD card: supported via the hardware-SPI path (`HAL_SPI.cpp`).
|
||||
- Graphical (U8glib) displays: not yet supported. `CPU_ST7920_DELAY_*` are set in `HAL.h` like other HALs, but a graphical LCD build currently fails: the core has no `wiring_private.h`, `spi_pins.h` defines `SPI_*_PIN` instead of `SD_*_PIN`, and there is no AT32 U8G hardware-SPI com function.
|
||||
|
||||
## Open / Placeholder Items
|
||||
|
||||
- Pin mappings in `src/pins/at32f4/pins_*.h` are **placeholders** — awaiting schematic verification.
|
||||
- `get_reset_source()` is simplified (always power-on); `idletask()` is a no-op.
|
||||
- Graphical LCD support (U8G com layer, SPI pin names) is still to do.
|
||||
|
||||
## References
|
||||
|
||||
- AT32F403 datasheet: https://www.arterytek.com/en/product/AT32F403.html
|
||||
- ArduinoCore-AT32F4 (rizacelik): https://github.com/rizacelik/ArduinoCore-AT32F4
|
||||
- ArduinoCore-AT32F4 (Marlin fork, branch `marlin`): https://github.com/MarlinFirmware/ArduinoCore-AT32F4
|
||||
- Issue #24894: Wanhao 0327001 support
|
||||
- Issue #25952: EasyThreed ET4000+ support
|
||||
|
||||
## License
|
||||
|
||||
This HAL follows the same license as the rest of Marlin (GPLv3).
|
||||
70
Marlin/src/HAL/AT32/Servo.cpp
Normal file
70
Marlin/src/HAL/AT32/Servo.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_SERVOS
|
||||
|
||||
#include "Servo.h"
|
||||
#include <Servo.h> // AT32 core's Servo class (uses tmr_type directly)
|
||||
|
||||
static uint8_t servoCount = 0;
|
||||
static MarlinServo* servos[NUM_SERVOS] = {nullptr};
|
||||
|
||||
constexpr uint32_t servoDelays[] = SERVO_DELAY;
|
||||
static_assert(COUNT(servoDelays) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
|
||||
|
||||
MarlinServo::MarlinServo() {
|
||||
this->channel = servoCount++;
|
||||
servos[this->channel] = this;
|
||||
}
|
||||
|
||||
int8_t MarlinServo::attach(const pin_t apin) {
|
||||
if (apin >= 0) this->pin = apin;
|
||||
if (this->pin < 0) return -1;
|
||||
return this->_servo.attach(this->pin) ? 0 : -1;
|
||||
}
|
||||
|
||||
void MarlinServo::detach() { this->_servo.detach(); }
|
||||
|
||||
bool MarlinServo::attached() { return this->_servo.attached_state(); }
|
||||
|
||||
void MarlinServo::write(servo_angle_t angle) {
|
||||
this->angle = angle;
|
||||
this->_servo.write(angle);
|
||||
}
|
||||
|
||||
void MarlinServo::move(servo_angle_t angle) {
|
||||
if (attach(-1) < 0) return;
|
||||
write(angle);
|
||||
safe_delay(servoDelays[this->channel]);
|
||||
TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
|
||||
}
|
||||
|
||||
servo_angle_t MarlinServo::read() {
|
||||
return TERN(OPTIMISTIC_SERVO_READ, this->angle, (servo_angle_t)this->_servo.read());
|
||||
}
|
||||
|
||||
#endif // HAS_SERVOS
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
67
Marlin/src/HAL/AT32/Servo.h
Normal file
67
Marlin/src/HAL/AT32/Servo.h
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_SERVOS
|
||||
|
||||
#include <Servo.h> // AT32 Arduino core Servo class
|
||||
|
||||
// Forward declarations for Servo.cpp
|
||||
extern uint8_t servoCount;
|
||||
extern MarlinServo* servos[];
|
||||
|
||||
/**
|
||||
* MarlinServo wraps the AT32 Arduino core Servo class.
|
||||
*/
|
||||
class MarlinServo {
|
||||
public:
|
||||
MarlinServo();
|
||||
|
||||
int8_t attach(const pin_t pin);
|
||||
void detach();
|
||||
bool attached();
|
||||
void write(servo_angle_t angle);
|
||||
void move(servo_angle_t angle);
|
||||
servo_angle_t read();
|
||||
|
||||
pin_t pin = -1;
|
||||
servo_angle_t angle = 0;
|
||||
uint8_t channel = 0;
|
||||
|
||||
private:
|
||||
Servo _servo; // AT32 core Servo instance
|
||||
};
|
||||
|
||||
class libServo : public MarlinServo {
|
||||
public:
|
||||
static void pause_all_servos() {
|
||||
for (int i = 0; i < NUM_SERVOS; i++)
|
||||
if (servos[i]) servos[i]->detach();
|
||||
}
|
||||
static void resume_all_servos() {
|
||||
for (int i = 0; i < NUM_SERVOS; i++)
|
||||
if (servos[i]) servos[i]->attach(-1);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // HAS_SERVOS
|
||||
13
Marlin/src/HAL/AT32/app_config.h
Normal file
13
Marlin/src/HAL/AT32/app_config.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// Application-specific configuration overrides for AT32 builds.
|
||||
// This file is force-included by the AT32 PlatformIO platform builder.
|
||||
27
Marlin/src/HAL/AT32/core_hooks.h
Normal file
27
Marlin/src/HAL/AT32/core_hooks.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* AT32 Core Hooks - Emergency Parser Integration
|
||||
*
|
||||
* This header provides the weak alias for the AT32 emergency parser hook.
|
||||
* The actual implementation is in emergency_parser.cpp to avoid include issues.
|
||||
*/
|
||||
|
||||
#ifndef CORE_HOOKS_H
|
||||
#define CORE_HOOKS_H
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
// Include serial definitions for MYSERIAL1
|
||||
#include "../../core/serial.h"
|
||||
|
||||
// Declare the actual implementation (defined in emergency_parser.cpp)
|
||||
extern "C" void AT32_emergency_parser_irq(uint8_t ch, uint8_t usart);
|
||||
|
||||
// Use the implementation directly
|
||||
#define core_hook_usart_rx_irq AT32_emergency_parser_irq
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
|
||||
#endif // CORE_HOOKS_H
|
||||
32
Marlin/src/HAL/AT32/eeprom/eeprom_if_iic.cpp
Normal file
32
Marlin/src/HAL/AT32/eeprom/eeprom_if_iic.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#if ENABLED(EEPROM_I2C) || ENABLED(EEPROM_SPI)
|
||||
|
||||
// I2C/SPI EEPROM emulation
|
||||
// AT32 uses Wire library for I2C (already available in Arduino core)
|
||||
|
||||
#endif // EEPROM_I2C || EEPROM_SPI
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
93
Marlin/src/HAL/AT32/eeprom/eeprom_sdcard.cpp
Normal file
93
Marlin/src/HAL/AT32/eeprom/eeprom_sdcard.cpp
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../../platforms.h"
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
/**
|
||||
* Implementation of EEPROM settings in SD Card
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#if ENABLED(SDCARD_EEPROM_EMULATION)
|
||||
|
||||
#include "../../shared/eeprom_api.h"
|
||||
#include "../../../sd/cardreader.h"
|
||||
|
||||
#define EEPROM_FILENAME "eeprom.dat"
|
||||
|
||||
#ifndef MARLIN_EEPROM_SIZE
|
||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||
#endif
|
||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||
|
||||
#define _ALIGN(x) __attribute__ ((aligned(x)))
|
||||
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
|
||||
|
||||
bool PersistentStore::access_start() {
|
||||
if (!card.isMounted()) return false;
|
||||
|
||||
MediaFile file, root = card.getroot();
|
||||
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
|
||||
return true;
|
||||
|
||||
int bytes_read = file.read(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
|
||||
if (bytes_read < 0) return false;
|
||||
for (; bytes_read < long(MARLIN_EEPROM_SIZE); bytes_read++)
|
||||
HAL_eeprom_data[bytes_read] = 0xFF;
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PersistentStore::access_finish() {
|
||||
if (!card.isMounted()) return false;
|
||||
|
||||
MediaFile file, root = card.getroot();
|
||||
int bytes_written = 0;
|
||||
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
|
||||
bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
|
||||
file.close();
|
||||
}
|
||||
return (bytes_written == MARLIN_EEPROM_SIZE);
|
||||
}
|
||||
|
||||
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||
for (size_t i = 0; i < size; i++)
|
||||
HAL_eeprom_data[pos + i] = value[i];
|
||||
crc16(crc, value, size);
|
||||
pos += size;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
uint8_t c = HAL_eeprom_data[pos + i];
|
||||
if (writing) value[i] = c;
|
||||
crc16(crc, &c, 1);
|
||||
}
|
||||
pos += size;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // SDCARD_EEPROM_EMULATION
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
75
Marlin/src/HAL/AT32/eeprom/eeprom_wired.cpp
Normal file
75
Marlin/src/HAL/AT32/eeprom/eeprom_wired.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#if USE_WIRED_EEPROM
|
||||
|
||||
/**
|
||||
* PersistentStore for Arduino-style EEPROM interface
|
||||
* with simple implementations supplied by Marlin.
|
||||
*/
|
||||
|
||||
#include "../../shared/eeprom_if.h"
|
||||
#include "../../shared/eeprom_api.h"
|
||||
|
||||
#ifndef MARLIN_EEPROM_SIZE
|
||||
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
||||
#endif
|
||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
||||
bool PersistentStore::access_finish() { return true; }
|
||||
|
||||
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||
uint16_t written = 0;
|
||||
while (size--) {
|
||||
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||
uint8_t v = *value;
|
||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||
eeprom_write_byte(p, v);
|
||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||
if (eeprom_read_byte(p) != v) {
|
||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
crc16(crc, &v, 1);
|
||||
pos++;
|
||||
value++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
do {
|
||||
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||
if (writing) *value = c;
|
||||
crc16(crc, &c, 1);
|
||||
pos++;
|
||||
value++;
|
||||
} while (--size);
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // USE_WIRED_EEPROM
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
39
Marlin/src/HAL/AT32/emergency_parser.cpp
Normal file
39
Marlin/src/HAL/AT32/emergency_parser.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* AT32 Emergency Parser Integration
|
||||
*
|
||||
* This file provides the AT32-specific implementation of the emergency parser
|
||||
* interrupt hook that feeds serial characters to the emergency parser.
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "../../MarlinCore.h"
|
||||
#include "../../core/serial.h"
|
||||
#include "core_hooks.h" // For core_hook_usart_rx_irq weak alias
|
||||
|
||||
// Emergency parser integration for AT32
|
||||
// The AT32 core's USART IRQ handler calls core_hook_usart_rx_irq()
|
||||
// which is aliased to AT32_emergency_parser_irq() in core_hooks.h
|
||||
|
||||
void AT32_emergency_parser_irq(uint8_t ch, uint8_t usart) {
|
||||
// Only handle receive on host serial ports
|
||||
if (usart != SERIAL_PORT
|
||||
#ifdef SERIAL_PORT_2
|
||||
&& usart != SERIAL_PORT_2
|
||||
#endif
|
||||
#ifdef SERIAL_PORT_3
|
||||
&& usart != SERIAL_PORT_3
|
||||
#endif
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Submit character to emergency parser
|
||||
if (MYSERIAL1.emergency_parser_enabled())
|
||||
emergency_parser.update(MYSERIAL1.emergency_state, ch);
|
||||
}
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
32
Marlin/src/HAL/AT32/endstop_interrupts.h
Normal file
32
Marlin/src/HAL/AT32/endstop_interrupts.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Endstop interrupt support for AT32F403
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
// AT32 endstop interrupts use external interrupt capability
|
||||
// The exact implementation depends on the Arduino core's interrupt API
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
87
Marlin/src/HAL/AT32/fastio.h
Normal file
87
Marlin/src/HAL/AT32/fastio.h
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Fast I/O interfaces for AT32F403
|
||||
* The AT32 Arduino core provides digitalRead/digitalWrite/togglePin helpers.
|
||||
*
|
||||
* AT32F403A GPIO registers (vs STM32):
|
||||
* gpio_x->scr - Set bits (vs STM32 GPIOx->BSRR)
|
||||
* gpio_x->clr - Clear bits (vs STM32 GPIOx->BRR)
|
||||
* gpio_x->odt - Output data (vs STM32 GPIOx->ODR)
|
||||
* gpio_x->idt - Input data (vs STM32 GPIOx->IDR)
|
||||
* gpio_x->cfglr - Config pins 0-7 (vs STM32 GPIOx->CRL)
|
||||
* gpio_x->cfghr - Config pins 8-15 (vs STM32 GPIOx->CRH)
|
||||
*
|
||||
* Reference: CrealityOfficial/K2_Series_Klipper src/at32/gpio.c
|
||||
*/
|
||||
// Map Marlin pin-mode names to the core's PinMode_TypeDef
|
||||
#ifndef INPUT_FLOATING
|
||||
#define INPUT_FLOATING INPUT
|
||||
#endif
|
||||
#ifndef OUTPUT_PWM
|
||||
#define OUTPUT_PWM PWM
|
||||
#endif
|
||||
|
||||
#define READ(IO) digitalRead(IO)
|
||||
#define WRITE(IO, V) digitalWrite(IO, V)
|
||||
#define TOGGLE(IO) togglePin(IO)
|
||||
|
||||
// The AT32 Arduino core declares pinMode(pin, PinMode_TypeDef) with a strict
|
||||
// enum, so callers passing a bool / int (as Marlin's M43 and shared code do)
|
||||
// fail to compile. Wrap it to accept any integral mode and map it to OUTPUT/
|
||||
// INPUT via the framework's own enum.
|
||||
inline void pinMode(uint8_t pin, int mode) {
|
||||
pinMode(pin, mode ? OUTPUT : INPUT);
|
||||
}
|
||||
|
||||
#define _SET_MODE(IO, M) pinMode(IO, (PinMode_TypeDef)(M))
|
||||
#define _SET_OUTPUT(IO) _SET_MODE(IO, OUTPUT)
|
||||
|
||||
#define OUT_WRITE(IO, V) do { _SET_OUTPUT(IO); WRITE(IO, V); } while (0)
|
||||
|
||||
#define SET_INPUT(IO) _SET_MODE(IO, INPUT_FLOATING)
|
||||
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP)
|
||||
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN)
|
||||
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
|
||||
#define SET_PWM(IO) _SET_MODE(IO, OUTPUT_PWM)
|
||||
|
||||
// Read a pin's 4-bit GPIO configuration from CFGLR/CFGHR:
|
||||
// IOMC [1:0] : 0 = input, 1..3 = output (speed)
|
||||
// IOFC [3:2] : input: 0 = analog, 1 = floating, 2 = pull-up/down
|
||||
// output: 0 = push-pull, 1 = open-drain, 2 = mux push-pull, 3 = mux open-drain
|
||||
inline uint8_t _GET_CFG(const uint8_t IO) {
|
||||
gpio_type * const gpio = PIN_MAP[IO].GPIOx;
|
||||
const uint8_t bit = IO & 0x0F;
|
||||
return ((bit < 8 ? gpio->cfglr : gpio->cfghr) >> ((bit & 0x07) * 4)) & 0x0F;
|
||||
}
|
||||
#define IS_INPUT(IO) ((_GET_CFG(IO) & 0x03) == 0)
|
||||
#define IS_OUTPUT(IO) !IS_INPUT(IO)
|
||||
#define IS_ANALOG(IO) (_GET_CFG(IO) == 0) // Input, analog
|
||||
#define IS_MUX(IO) (IS_OUTPUT(IO) && (_GET_CFG(IO) & 0x08)) // Output, peripheral (alternate function)
|
||||
|
||||
#define PWM_PIN(IO) IS_PWM_PIN(IO)
|
||||
|
||||
#define extDigitalRead(IO) digitalRead(IO)
|
||||
#define extDigitalWrite(IO, V) digitalWrite(IO, V)
|
||||
|
||||
#define NO_COMPILE_TIME_PWM // Can't check for PWM at compile time
|
||||
21
Marlin/src/HAL/AT32/inc/Conditionals_LCD.h
Normal file
21
Marlin/src/HAL/AT32/inc/Conditionals_LCD.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
37
Marlin/src/HAL/AT32/inc/Conditionals_adv.h
Normal file
37
Marlin/src/HAL/AT32/inc/Conditionals_adv.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* AT32-specific advanced conditionals
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
// AT32F403 supports M997 firmware update trigger
|
||||
#ifndef PLATFORM_M997_SUPPORT
|
||||
#define PLATFORM_M997_SUPPORT
|
||||
#endif
|
||||
|
||||
// AT32 supports PWM frequency adjustment
|
||||
#define HAL_CAN_SET_PWM_FREQ
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
36
Marlin/src/HAL/AT32/inc/Conditionals_post.h
Normal file
36
Marlin/src/HAL/AT32/inc/Conditionals_post.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* AT32-specific post-conditionals
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#if ENABLED(I2C_EEPROM)
|
||||
#define USE_SHARED_EEPROM 1
|
||||
#endif
|
||||
|
||||
// AT32F403 / AT32F407 have an FPU
|
||||
#define CPU_HAS_FPU
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
31
Marlin/src/HAL/AT32/inc/Conditionals_type.h
Normal file
31
Marlin/src/HAL/AT32/inc/Conditionals_type.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* AT32-specific type conditionals
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
// AT32 pin_t type is already defined in HAL.h
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
99
Marlin/src/HAL/AT32/inc/SanityCheck.h
Normal file
99
Marlin/src/HAL/AT32/inc/SanityCheck.h
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Test AT32-specific configuration values for errors at compile-time.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Require pins to be defined as macros with numerical values
|
||||
*/
|
||||
#ifndef PA0
|
||||
#error "Your ARM platform pins are not defined as macros, only as enums! Provide pins_arduino.h and/or 'buildroot/share/PlatformIO/variants/*/variant.h' to define the pins."
|
||||
#endif
|
||||
|
||||
// Require Arduino core version check if available
|
||||
#if defined(ARDUINO_CORE_VERSION_INT) && ARDUINO_CORE_VERSION_INT < 100000
|
||||
#error "The AT32 HAL requires Arduino Core version >= 1.0.0. Consider updating the Arduino Core."
|
||||
#endif
|
||||
|
||||
// Serial stats not supported on AT32
|
||||
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
|
||||
#error "SERIAL_STATS_MAX_RX_QUEUED is not supported on AT32."
|
||||
#elif ENABLED(SERIAL_STATS_DROPPED_RX)
|
||||
#error "SERIAL_STATS_DROPPED_RX is not supported on AT32."
|
||||
#endif
|
||||
|
||||
// SDCARD_EEPROM_EMULATION requires SDSUPPORT
|
||||
#if ENABLED(SDCARD_EEPROM_EMULATION) && !HAS_MEDIA
|
||||
#undef SDCARD_EEPROM_EMULATION
|
||||
#if USE_FALLBACK_EEPROM
|
||||
#warning "EEPROM type not specified. Fallback is SDCARD_EEPROM_EMULATION."
|
||||
#endif
|
||||
#error "SDCARD_EEPROM_EMULATION requires SDSUPPORT. Enable SDSUPPORT or choose another EEPROM emulation."
|
||||
#endif
|
||||
|
||||
// TEMP_SENSOR_SOC requires TEMP_SOC_PIN
|
||||
#if TEMP_SENSOR_SOC
|
||||
#ifndef TEMP_SOC_PIN
|
||||
#error "TEMP_SOC_PIN must be defined to use TEMP_SENSOR_SOC on AT32."
|
||||
#elif IS_GPIO_PIN(TEMP_SOC_PIN)
|
||||
#error "TEMP_SOC_PIN must not be a valid GPIO pin to avoid conflicts."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Emergency Parser needs at least one serial with HardwareSerial
|
||||
#if ENABLED(EMERGENCY_PARSER) && ((SERIAL_PORT == -1 && !defined(SERIAL_PORT_2)) || (SERIAL_PORT_2 == -1 && !defined(SERIAL_PORT)))
|
||||
#error "EMERGENCY_PARSER requires HardwareSerial on AT32."
|
||||
#endif
|
||||
|
||||
// Check for common serial pin conflicts
|
||||
#define _CHECK_SERIAL_PIN(N) (( \
|
||||
BTN_EN1 == N || BTN_EN2 == N || DOGLCD_CS == N || HEATER_BED_PIN == N || FAN0_PIN == N \
|
||||
))
|
||||
#define CHECK_SERIAL_PIN(T,N) defined(UART##N##_##T##_PIN) && _CHECK_SERIAL_PIN(UART##N##_##T##_PIN)
|
||||
#if SERIAL_IN_USE(1)
|
||||
#if CHECK_SERIAL_PIN(TX,1)
|
||||
#error "Serial Port 1 TX IO pins conflict with another pin on the board."
|
||||
#endif
|
||||
#if CHECK_SERIAL_PIN(RX,1)
|
||||
#error "Serial Port 1 RX IO pins conflict with another pin on the board."
|
||||
#endif
|
||||
#endif
|
||||
#if SERIAL_IN_USE(2)
|
||||
#if CHECK_SERIAL_PIN(TX,2)
|
||||
#error "Serial Port 2 TX IO pins conflict with another pin on the board."
|
||||
#endif
|
||||
#if CHECK_SERIAL_PIN(RX,2)
|
||||
#error "Serial Port 2 RX IO pins conflict with another pin on the board."
|
||||
#endif
|
||||
#endif
|
||||
#if SERIAL_IN_USE(3)
|
||||
#if CHECK_SERIAL_PIN(TX,3)
|
||||
#error "Serial Port 3 TX IO pins conflict with another pin on the board."
|
||||
#endif
|
||||
#if CHECK_SERIAL_PIN(RX,3)
|
||||
#error "Serial Port 3 RX IO pins conflict with another pin on the board."
|
||||
#endif
|
||||
#endif
|
||||
#undef CHECK_SERIAL_PIN
|
||||
#undef _CHECK_SERIAL_PIN
|
||||
121
Marlin/src/HAL/AT32/pinsDebug.h
Normal file
121
Marlin/src/HAL/AT32/pinsDebug.h
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Pins Debugging for AT32
|
||||
* See PinsDebugBase in pins/pinsDebug.h for the hooks.
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "fastio.h"
|
||||
|
||||
// AT32 pin debugging uses the Arduino PIN_MAP infrastructure
|
||||
#define NUM_DIGITAL_PINS PIN_MAX
|
||||
|
||||
#ifndef BOARD_USART1_TX_PIN
|
||||
#define BOARD_USART1_TX_PIN PA9
|
||||
#endif
|
||||
#ifndef BOARD_USART1_RX_PIN
|
||||
#define BOARD_USART1_RX_PIN PA10
|
||||
#endif
|
||||
|
||||
struct PinsDebug : PinsDebugBase<PinsDebug> {
|
||||
static constexpr uint16_t count = PIN_MAX;
|
||||
static constexpr uint8_t name_pad = 21; // Space needed to be pretty if not first name assigned to a pin
|
||||
|
||||
static bool is_valid(const pin_t pin) { return IS_PIN(pin); }
|
||||
|
||||
//
|
||||
// Pins that will cause a hang / reset / disconnect in M43 Toggle and Watch utils
|
||||
//
|
||||
static bool never_touch(const uint16_t index) {
|
||||
const pin_t pin = pin_t(index);
|
||||
return pin == BOARD_USART1_TX_PIN || pin == BOARD_USART1_RX_PIN // Host USART
|
||||
|| pin == PD0 || pin == PD1 || pin == PC14 || pin == PC15; // Oscillators (HEXT, LEXT)
|
||||
}
|
||||
|
||||
// The core's analogRead() takes a pin, not an ADC channel, so the "analog index"
|
||||
// passed to it by the shared code is the pin itself. print_analog shows the channel.
|
||||
static int16_t analog_index(const pin_t pin) { return IS_ADC_PIN(pin) ? int16_t(pin) : -1; }
|
||||
|
||||
static bool is_analog(const pin_t pin) { return IS_ADC_PIN(pin) && IS_ANALOG(pin) && !never_touch(pin); }
|
||||
|
||||
static bool is_output(const pin_t pin) { return is_valid(pin) && IS_OUTPUT(pin); }
|
||||
|
||||
static bool is_digital_at(const uint16_t index) { return !is_analog(getPinByIndex(index)); }
|
||||
|
||||
// Timer number for a PIN_MAP timer, or 0 if unknown
|
||||
static uint8_t timer_number(const tmr_type * const tmr) {
|
||||
static tmr_type * const timers[] = { TMR1, TMR2, TMR3, TMR4, TMR5, TMR6, TMR7, TMR8, TMR9, TMR10, TMR11, TMR12, TMR13, TMR14 };
|
||||
for (uint8_t i = 0; i < COUNT(timers); ++i) if (tmr == timers[i]) return i + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Compare value of the pin's timer channel (1-4)
|
||||
static uint32_t channel_value(const tmr_type * const tmr, const uint8_t ch) {
|
||||
switch (ch) {
|
||||
case 1: return tmr->c1dt;
|
||||
case 2: return tmr->c2dt;
|
||||
case 3: return tmr->c3dt;
|
||||
default: return tmr->c4dt;
|
||||
}
|
||||
}
|
||||
|
||||
// A pin is PWM output if it's routed to its timer (mux output),
|
||||
// the timer is running, and the timer channel output is enabled.
|
||||
static bool pwm_active(const pin_t pin) {
|
||||
if (!IS_PWM_PIN(pin) || !IS_MUX(pin)) return false;
|
||||
const tmr_type * const tmr = PIN_MAP[pin].TIMx;
|
||||
const uint8_t ch = PIN_MAP[pin].TimerChannel;
|
||||
return tmr->ctrl1_bit.tmren && TEST(tmr->cctrl, (ch - 1) * 4);
|
||||
}
|
||||
|
||||
// Print the pin's timer and channel, e.g. "TMR3 CH2", plus the duty if PWM is active
|
||||
static void print_pwm(const pin_t pin) {
|
||||
if (!IS_PWM_PIN(pin)) return;
|
||||
const tmr_type * const tmr = PIN_MAP[pin].TIMx;
|
||||
const uint8_t ch = PIN_MAP[pin].TimerChannel;
|
||||
SERIAL_ECHO(F("TMR"), timer_number(tmr), F(" CH"), ch);
|
||||
if (pwm_active(pin)) SERIAL_ECHO(F(" PWM "), channel_value(tmr, ch), C('/'), tmr->pr + 1);
|
||||
}
|
||||
|
||||
static void print_port(const pin_t pin) {
|
||||
const char port = 'A' + char(pin >> 4);
|
||||
const uint8_t gbit = pin & 0x0F;
|
||||
char buffer[8];
|
||||
sprintf_P(buffer, PSTR("P%c%hd "), port, gbit);
|
||||
if (gbit < 10) SERIAL_CHAR(' ');
|
||||
SERIAL_ECHO(buffer);
|
||||
}
|
||||
|
||||
static void print_number(const pin_t pin) {
|
||||
char buffer[16];
|
||||
sprintf_P(buffer, PSTR("%3hd "), int16_t(pin));
|
||||
SERIAL_ECHO(buffer);
|
||||
}
|
||||
|
||||
static void print_analog(const pin_t pin) {
|
||||
char buffer[16];
|
||||
sprintf_P(buffer, PSTR(" (A%2d) "), int(PIN_MAP[pin].ADC_Channel));
|
||||
SERIAL_ECHO(buffer);
|
||||
}
|
||||
};
|
||||
34
Marlin/src/HAL/AT32/sd/SDCard.cpp
Normal file
34
Marlin/src/HAL/AT32/sd/SDCard.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
#include "../../../sd/SdVolume.h"
|
||||
|
||||
#if HAS_SDCARD
|
||||
|
||||
// SD card support for AT32F403
|
||||
// Uses SPI or SDIO depending on board configuration
|
||||
// The Arduino core provides SPI library for SD card access
|
||||
|
||||
#endif // HAS_SDCARD
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
47
Marlin/src/HAL/AT32/spi_pins.h
Normal file
47
Marlin/src/HAL/AT32/spi_pins.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* SPI pin definitions for AT32F403
|
||||
* AT32 uses standard SPI peripheral naming: SPI1, SPI2, SPI3
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
// Default SPI pins (can be overridden by board pins files)
|
||||
#ifndef SPI_SCK_PIN
|
||||
#define SPI_SCK_PIN PC3
|
||||
#endif
|
||||
|
||||
#ifndef SPI_MISO_PIN
|
||||
#define SPI_MISO_PIN PC4
|
||||
#endif
|
||||
|
||||
#ifndef SPI_MOSI_PIN
|
||||
#define SPI_MOSI_PIN PC5
|
||||
#endif
|
||||
|
||||
#ifndef SPI_SS_PIN
|
||||
#define SPI_SS_PIN PA4
|
||||
#endif
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
44
Marlin/src/HAL/AT32/temp_soc.h
Normal file
44
Marlin/src/HAL/AT32/temp_soc.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* SoC (System on Chip) temperature sensor support for AT32F403
|
||||
*
|
||||
* The AT32F403 has an internal temperature sensor accessible via ADC.
|
||||
* This provides a basic implementation using the AT32 ADC peripheral.
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
// AT32 internal temperature sensor is connected to ADC channel
|
||||
// The exact channel depends on the board design - typically an unused ADC pin
|
||||
#ifndef TEMP_SOC_PIN
|
||||
#define TEMP_SOC_PIN -1 // Disabled by default
|
||||
#endif
|
||||
|
||||
// Convert ADC reading to temperature in degrees C
|
||||
// AT32 internal temp sensor: ~1.43V at 25C, -2.6mV/degree C
|
||||
// ADC clock: SYSCLK/6 = 40 MHz (per CrealityOfficial/K2_Series_Klipper src/at32/adc.c)
|
||||
// ADC sample time: ADC_SAMPLETIME_239_5 (slowest, for thermistors)
|
||||
#define TEMP_SOC_TO_C(ADC_RAW) (25.0f - ((3.3f * (ADC_RAW) / 4095.0f - 1.43f) / 0.0026f))
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
51
Marlin/src/HAL/AT32/timers.cpp
Normal file
51
Marlin/src/HAL/AT32/timers.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
|
||||
#include "timers.h"
|
||||
|
||||
/**
|
||||
* HAL_timer_start — configure a hardware timer with exact prescaler and period.
|
||||
*
|
||||
* Uses Timer_SetInterruptBase() so that the prescaler is exactly what Marlin
|
||||
* expects (STEPPER_TIMER_PRESCALE / TEMP_TIMER_PRESCALE), ensuring that
|
||||
* STEPPER_TIMER_RATE compile-time constants are valid.
|
||||
*
|
||||
* Timer_SetInterruptBase(TIMx, Period, Prescaler, callback, PreemptPrio, SubPrio)
|
||||
* Period = (timer_clock / prescaler / frequency) - 1
|
||||
* Prescaler = desired prescaler - 1 (hardware loads prescaler+1)
|
||||
*/
|
||||
void HAL_timer_start(const timer_channel_t timer_ch, const uint32_t frequency) {
|
||||
if (timer_ch == MF_TIMER_TEMP) {
|
||||
const uint16_t period = (uint16_t)(F_PCLK1 / TEMP_TIMER_PRESCALE / frequency) - 1;
|
||||
Timer_SetInterruptBase(TMR4, period, (uint16_t)(TEMP_TIMER_PRESCALE - 1),
|
||||
Temp_Handler, TEMP_TIMER_PRIORITY, 0);
|
||||
}
|
||||
else if (timer_ch == MF_TIMER_STEP) {
|
||||
const uint16_t period = (uint16_t)(F_PCLK1 / STEPPER_TIMER_PRESCALE / frequency) - 1;
|
||||
Timer_SetInterruptBase(TMR2, period, (uint16_t)(STEPPER_TIMER_PRESCALE - 1),
|
||||
Step_Handler, STEP_TIMER_PRIORITY, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ARDUINO_ARCH_AT32
|
||||
122
Marlin/src/HAL/AT32/timers.h
Normal file
122
Marlin/src/HAL/AT32/timers.h
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <libcore/timer.h>
|
||||
|
||||
// AT32 timer peripheral type (from at32f403a_407.h via the Arduino core)
|
||||
typedef tmr_type* timer_channel_t;
|
||||
typedef uint16_t hal_timer_t;
|
||||
#define HAL_TIMER_TYPE_MAX hal_timer_t(UINT16_MAX)
|
||||
|
||||
//
|
||||
// Timer Assignments
|
||||
// TMR2 → stepper/pulse (APB1, 240 MHz timer clock)
|
||||
// TMR4 → temperature (APB1, 240 MHz timer clock)
|
||||
//
|
||||
// AT32F403A timer register names (ref: CrealityOfficial/K2_Series_Klipper src/at32/):
|
||||
// tmr_x->div prescaler (STM32: PSC)
|
||||
// tmr_x->pr auto-reload (STM32: ARR)
|
||||
// tmr_x->cval current count (STM32: CNT)
|
||||
// tmr_x->c1dt compare 1 (STM32: CCR1)
|
||||
// tmr_x->iden_bit.ovfien overflow interrupt enable
|
||||
// tmr_x->ists_bit.ovfif overflow interrupt flag (write 0 to clear)
|
||||
//
|
||||
|
||||
#define MF_TIMER_TEMP TMR4
|
||||
#define MF_TIMER_STEP TMR2
|
||||
#define MF_TIMER_TEMP_IRQn TMR4_GLOBAL_IRQn
|
||||
#define MF_TIMER_STEP_IRQn TMR2_GLOBAL_IRQn
|
||||
#define TEMP_TIMER_PRIORITY 2
|
||||
#define STEP_TIMER_PRIORITY 0
|
||||
|
||||
// AT32F403A: SYSCLK 240 MHz, APB1 120 MHz, timer clock = APB1×2 = 240 MHz
|
||||
#define F_PCLK1 240000000UL
|
||||
|
||||
// HAL_TIMER_RATE must be compile-time for constexpr stepper math
|
||||
#define HAL_TIMER_RATE F_PCLK1
|
||||
|
||||
#define TEMP_TIMER_PRESCALE 240UL // 240 MHz / 240 = 1 MHz tick
|
||||
#define TEMP_TIMER_RATE 1000 // 1 kHz ISR
|
||||
#define TEMP_TIMER_FREQUENCY TEMP_TIMER_RATE
|
||||
|
||||
#define STEPPER_TIMER_PRESCALE 120UL // 240 MHz / 120 = 2 MHz tick
|
||||
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
||||
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000UL)
|
||||
|
||||
#define MF_TIMER_PULSE MF_TIMER_STEP
|
||||
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE
|
||||
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||
|
||||
//
|
||||
// HAL timer functions
|
||||
//
|
||||
void HAL_timer_start(const timer_channel_t timer_ch, const uint32_t frequency);
|
||||
|
||||
#define MARLIN_HAL_TIMER_INLINE_ATTR __attribute__((always_inline)) inline
|
||||
|
||||
MARLIN_HAL_TIMER_INLINE_ATTR void HAL_timer_enable_interrupt(const timer_channel_t timer_ch) {
|
||||
timer_ch->iden_bit.ovfien = 1;
|
||||
}
|
||||
|
||||
MARLIN_HAL_TIMER_INLINE_ATTR void HAL_timer_disable_interrupt(const timer_channel_t timer_ch) {
|
||||
timer_ch->iden_bit.ovfien = 0;
|
||||
}
|
||||
|
||||
MARLIN_HAL_TIMER_INLINE_ATTR bool HAL_timer_interrupt_enabled(const timer_channel_t timer_ch) {
|
||||
return timer_ch->iden_bit.ovfien;
|
||||
}
|
||||
|
||||
MARLIN_HAL_TIMER_INLINE_ATTR void HAL_timer_set_compare(const timer_channel_t timer_ch, const hal_timer_t compare) {
|
||||
timer_ch->pr = compare;
|
||||
}
|
||||
|
||||
MARLIN_HAL_TIMER_INLINE_ATTR hal_timer_t HAL_timer_get_count(const timer_channel_t timer_ch) {
|
||||
return (hal_timer_t)timer_ch->cval;
|
||||
}
|
||||
|
||||
MARLIN_HAL_TIMER_INLINE_ATTR void HAL_timer_isr_prologue(const timer_channel_t timer_ch) {
|
||||
timer_ch->ists = 0; // Clear all timer status flags (rc_w0 — write 0 to clear)
|
||||
}
|
||||
|
||||
inline void HAL_timer_isr_epilogue(const timer_channel_t) {}
|
||||
|
||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_STEP)
|
||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_STEP)
|
||||
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(MF_TIMER_STEP)
|
||||
|
||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_TEMP)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_TEMP)
|
||||
|
||||
//
|
||||
// ISR callbacks (defined in Marlin's temperature.cpp / stepper.cpp)
|
||||
//
|
||||
void Step_Handler();
|
||||
void Temp_Handler();
|
||||
|
||||
#ifndef HAL_STEP_TIMER_ISR
|
||||
#define HAL_STEP_TIMER_ISR() void Step_Handler()
|
||||
#endif
|
||||
#ifndef HAL_TEMP_TIMER_ISR
|
||||
#define HAL_TEMP_TIMER_ISR() void Temp_Handler()
|
||||
#endif
|
||||
26
Marlin/src/HAL/AT32/u8g/LCD_defines.h
Normal file
26
Marlin/src/HAL/AT32/u8g/LCD_defines.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* AT32 LCD-specific defines
|
||||
* No AT32-specific U8G com functions yet (see HAL_LCD_com_defines.h for the defaults).
|
||||
*/
|
||||
|
|
@ -17,7 +17,7 @@ buildroot/bin/mftest -t HC32F460C_aquila_101 -n1 -y # Voxelab Aquila V1.0.x, 2
|
|||
|
||||
## Framework / Platform Integration (upstream, not vendored)
|
||||
|
||||
Unlike AT32, the HC32 HAL uses **upstream (third-party) Arduino packages** pulled straight from GitHub by PlatformIO — there is **no vendored framework** in this repo (`buildroot/share/PlatformIO/` carries only `framework-arduino-at32f4` and `platform-at32`, nothing for HC32). `ini/hc32.ini` declares them as remote archives:
|
||||
The HC32 HAL uses **upstream (third-party) Arduino packages** pulled straight from GitHub by PlatformIO — there is **no vendored framework** in this repo. `ini/hc32.ini` declares them as remote archives:
|
||||
|
||||
```ini
|
||||
platform = https://github.com/shadow578/platform-hc32f46x/archive/1.1.1.zip
|
||||
|
|
@ -27,7 +27,7 @@ platform_packages = framework-hc32f46x-ddl@https://github.com/shadow578/framewor
|
|||
|
||||
Implications:
|
||||
|
||||
- **Framework fixes are NOT made in this repo.** To change the core (flags, serial, USB, DDL/DDL options) you edit `ini/hc32.ini` `build_flags` / `board_build.*` keys, or pin a new upstream core tag. There is no `buildroot/share/PlatformIO/framework-arduino-hc32f4x` to keep in sync with an installed package — the AT32 "mirror the two copies" rule does **not** apply here.
|
||||
- **Framework fixes are NOT made in this repo.** To change the core (flags, serial, USB, DDL/DDL options) you edit `ini/hc32.ini` `build_flags` / `board_build.*` keys, or pin a new upstream core tag.
|
||||
- The core version is pinned and **enforced at compile time**: `inc/SanityCheck.h` requires `ARDUINO_CORE_VERSION_INT >= 1.1.0` (for `app_config.h`) and gates `SERIAL_DMA`, `EMERGENCY_PARSER`, and `SoftwareSerial` on core 1.2.0 / 1.3.1. Bumping the core tag is a real compatibility event — check the `ARDUINO_CORE_VERSION_INT` checks before doing so.
|
||||
|
||||
### Gotchas that are not obvious from the source
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@
|
|||
#define HAL_PATH(PATH, NAME) XSTR(PATH/HAL/SAMD21/NAME)
|
||||
#elif defined(__PLAT_RP2040__)
|
||||
#define HAL_PATH(PATH, NAME) XSTR(PATH/HAL/RP2040/NAME)
|
||||
#elif defined(ARDUINO_ARCH_AT32)
|
||||
#define HAL_PATH(PATH, NAME) XSTR(PATH/HAL/AT32/NAME)
|
||||
#else
|
||||
#error "Unsupported Platform!"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@
|
|||
|
||||
#include <Arduino.h> // NOTE: If included earlier then this line is a NOOP
|
||||
|
||||
#ifdef ARDUINO_ARCH_AT32
|
||||
#undef ABS
|
||||
#endif
|
||||
|
||||
#undef DISABLED
|
||||
#define DISABLED(V...) DO(DIS,&&,V)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
// Faux pins for Dependency Check
|
||||
//
|
||||
|
||||
#if !defined(ARDUINO_ARCH_AT32)
|
||||
//
|
||||
// STM32 Pin Names
|
||||
//
|
||||
|
|
@ -197,6 +198,7 @@
|
|||
#define PJ13 0xAD
|
||||
#define PJ14 0xAE
|
||||
#define PJ15 0xAF
|
||||
#endif // !ARDUINO_ARCH_AT32
|
||||
|
||||
//
|
||||
// LPC Pin Names
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@
|
|||
#include "../HC32/Servo.h"
|
||||
#elif defined(ARDUINO_ARCH_MFL)
|
||||
#include "../GD32_MFL/Servo.h"
|
||||
#elif defined(ARDUINO_ARCH_AT32)
|
||||
#include "../AT32/Servo.h"
|
||||
#elif defined(__STM32F1__) || defined(TARGET_STM32F1)
|
||||
#include "../STM32F1/Servo.h"
|
||||
#elif defined(ARDUINO_ARCH_STM32)
|
||||
|
|
|
|||
|
|
@ -588,6 +588,14 @@
|
|||
#define BOARD_CREALITY_V427_GD32_MFL 7401 // Creality V4.2.7 MFL (GD32F303RE) ... STM32 Variant Above!
|
||||
#define BOARD_TRIGORILLA_V401_GD32_MFL 7402 // Anycubic TriGorilla Gen V4.0.1 - Kobra 2 Neo (GD32F303RG) ... STM32 Variant Above!
|
||||
|
||||
//
|
||||
// AT32 ARM Cortex-M4
|
||||
//
|
||||
|
||||
#define BOARD_WANHAO_0327001 7500 // Wanhao 0327001 v2.0 (AT32F403ARGT7)
|
||||
#define BOARD_EASYTHREED_ET4000_PLUS 7501 // EasyThreed K7 ET4000+ (AT32F403ARCT7)
|
||||
#define BOARD_EASYTHREED_K7_REVB_AT32F407 7502 // EasyThreed K7 Rev. B ET4000+ (AT32F407RCT7)
|
||||
|
||||
//
|
||||
// Raspberry Pi
|
||||
//
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
#endif
|
||||
|
||||
// Clock speed factors
|
||||
#if !defined(CYCLES_PER_MICROSECOND) && !defined(__STM32F1__)
|
||||
#if !defined(CYCLES_PER_MICROSECOND) && !defined(__STM32F1__) && !defined(ARDUINO_ARCH_AT32)
|
||||
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20 on AVR
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -221,9 +221,9 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
|
|||
#error "SERIAL_XON_XOFF and SERIAL_STATS_* features not supported on USB-native AVR devices."
|
||||
#endif
|
||||
|
||||
// Serial DMA is only available for some STM32 MCUs, HC32 and GD32
|
||||
// Serial DMA is only available for some STM32 MCUs, HC32, GD32 and AT32
|
||||
#if ENABLED(SERIAL_DMA)
|
||||
#if ANY(ARDUINO_ARCH_HC32, ARDUINO_ARCH_MFL)
|
||||
#if ANY(ARDUINO_ARCH_HC32, ARDUINO_ARCH_MFL, ARDUINO_ARCH_AT32)
|
||||
// See HAL/.../inc/SanityCheck.h
|
||||
#elif DISABLED(HAL_STM32) || NONE(STM32F0xx, STM32F1xx, STM32F2xx, STM32F4xx, STM32F7xx, STM32H7xx)
|
||||
#error "SERIAL_DMA is only available for some STM32 MCUs and requires HAL/STM32."
|
||||
|
|
|
|||
29
Marlin/src/pins/at32f4/env_validate.h
Normal file
29
Marlin/src/pins/at32f4/env_validate.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifndef ENV_VALIDATE_H
|
||||
#define ENV_VALIDATE_H
|
||||
|
||||
#ifndef ARDUINO_ARCH_AT32
|
||||
#error "AT32 HAL required for this board"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
86
Marlin/src/pins/at32f4/pins_EASYTHREED_ET4000_PLUS.h
Normal file
86
Marlin/src/pins/at32f4/pins_EASYTHREED_ET4000_PLUS.h
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* EasyThreed K7 ET4000+ pin assignments
|
||||
* MCU: AT32F403ARCT7
|
||||
*/
|
||||
|
||||
#include "env_validate.h"
|
||||
|
||||
// Stepper motor pins
|
||||
#define X_STEP_PIN PA0
|
||||
#define X_DIR_PIN PA1
|
||||
#define X_ENABLE_PIN PA2
|
||||
|
||||
#define Y_STEP_PIN PA3
|
||||
#define Y_DIR_PIN PA4
|
||||
#define Y_ENABLE_PIN PA5
|
||||
|
||||
#define Z_STEP_PIN PA6
|
||||
#define Z_DIR_PIN PA7
|
||||
#define Z_ENABLE_PIN PB0
|
||||
|
||||
#define E0_STEP_PIN PB1
|
||||
#define E0_DIR_PIN PB2
|
||||
#define E0_ENABLE_PIN PB3
|
||||
|
||||
// Endstops
|
||||
#define X_MIN_PIN PB4
|
||||
#define X_MAX_PIN PB5
|
||||
#define Y_MIN_PIN PB6
|
||||
#define Y_MAX_PIN PB7
|
||||
#define Z_MIN_PIN PC0
|
||||
#define Z_MAX_PIN PC1
|
||||
|
||||
// Temperature sensors
|
||||
#define TEMP_0_PIN PC2 // HE0
|
||||
#define TEMP_BED_PIN PC3 // BED
|
||||
|
||||
// Heaters
|
||||
#define HEATER_0_PIN PC4
|
||||
#define HEATER_BED_PIN PC5
|
||||
|
||||
// Fans
|
||||
#define FAN0_PIN PC6
|
||||
#define FAN1_PIN PC7
|
||||
|
||||
// LCD / Controller
|
||||
#define BEEPER_PIN PC8
|
||||
#define LCD_BACKLIGHT_PIN PC9
|
||||
#define LCD_RESET_PIN PC10
|
||||
|
||||
// SD Card
|
||||
#define SD_DETECT_PIN PC11
|
||||
#define SD_SS_PIN PC12 // CS
|
||||
|
||||
// SPI pins
|
||||
#define SCK_PIN PC13
|
||||
#define MISO_PIN PC14
|
||||
#define MOSI_PIN PC15
|
||||
|
||||
// EEPROM emulation on SD card (sdsupport is enabled for this board)
|
||||
#define SDCARD_EEPROM_EMULATION
|
||||
|
||||
// Note: Pin mappings are approximate and need verification from schematics
|
||||
// The actual pin assignments should be verified against the EasyThreed ET4000+ board
|
||||
176
Marlin/src/pins/at32f4/pins_EASYTHREED_K7_REVB_AT32F407.h
Normal file
176
Marlin/src/pins/at32f4/pins_EASYTHREED_K7_REVB_AT32F407.h
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* EasyThreed K7 Rev. B ET4000+ pin assignments
|
||||
*
|
||||
* Board marking: AT32F407ARCT7
|
||||
* Build profile: AT32F407RCT7
|
||||
*
|
||||
* Derived from the MKS Robin Lite mapping used by the known-working
|
||||
* Vexisu K7 Rev. B firmware. That firmware has run and printed on the
|
||||
* exact target machine. Individual functions still require staged
|
||||
* native-AT32 hardware validation.
|
||||
*
|
||||
* The K7 has no heated bed, so no bed heater or bed sensor is exposed.
|
||||
*/
|
||||
|
||||
#include "env_validate.h"
|
||||
|
||||
#if HAS_MULTI_HOTEND || E_STEPPERS > 1
|
||||
#error "EasyThreed K7 Rev. B only supports 1 hotend / E stepper."
|
||||
#endif
|
||||
|
||||
#ifndef BOARD_INFO_NAME
|
||||
#define BOARD_INFO_NAME "EasyThreed K7 Rev. B ET4000+"
|
||||
#endif
|
||||
|
||||
#define BOARD_NO_NATIVE_USB
|
||||
#define DISABLE_JTAG
|
||||
|
||||
//
|
||||
// External 24C16 EEPROM
|
||||
//
|
||||
// The known-working Maple firmware uses I2C1 on PB6 / PB7.
|
||||
// Software I2C avoids relying on the incomplete AT32 Wire singleton.
|
||||
//
|
||||
#if NO_EEPROM_SELECTED || ENABLED(I2C_EEPROM)
|
||||
#define I2C_EEPROM
|
||||
#define SOFT_I2C_EEPROM
|
||||
#define I2C_SCL_PIN PB6
|
||||
#define I2C_SDA_PIN PB7
|
||||
#define MARLIN_EEPROM_SIZE 0x800U // 2K (24C16)
|
||||
#endif
|
||||
|
||||
//
|
||||
// Limit Switches
|
||||
//
|
||||
#define X_STOP_PIN PC13
|
||||
#define Y_STOP_PIN PC0
|
||||
#define Z_MIN_PIN PC12
|
||||
#define Z_MAX_PIN PB9
|
||||
|
||||
//
|
||||
// Steppers
|
||||
//
|
||||
#define X_STEP_PIN PC6
|
||||
#define X_DIR_PIN PB12
|
||||
#define X_ENABLE_PIN PB10
|
||||
|
||||
#define Y_STEP_PIN PB11
|
||||
#define Y_DIR_PIN PB2
|
||||
#define Y_ENABLE_PIN PB10
|
||||
|
||||
#define Z_STEP_PIN PB1
|
||||
#define Z_DIR_PIN PC5
|
||||
#define Z_ENABLE_PIN PB10
|
||||
|
||||
#define E0_STEP_PIN PC4
|
||||
#define E0_DIR_PIN PA5
|
||||
#define E0_ENABLE_PIN PA4
|
||||
|
||||
//
|
||||
// Hotend / Fan
|
||||
//
|
||||
#define HEATER_0_PIN PC9
|
||||
#define FAN0_PIN PA8
|
||||
|
||||
//
|
||||
// Temperature Sensor
|
||||
//
|
||||
#define TEMP_0_PIN PA0
|
||||
|
||||
//
|
||||
// Filament runout input
|
||||
//
|
||||
#define FIL_RUNOUT_PIN PB8
|
||||
|
||||
/**
|
||||
* ------
|
||||
* PD2 | 1 2 | PB3
|
||||
* PB5 | 3 4 | PA11
|
||||
* PB4 | 5 6 | PC1
|
||||
* PC3 | 7 8 | PC2
|
||||
* GND | 9 10 | 5V
|
||||
* ------
|
||||
* EXP3
|
||||
*/
|
||||
#define EXP3_01_PIN PD2
|
||||
#define EXP3_02_PIN PB3
|
||||
#define EXP3_03_PIN PB5
|
||||
#define EXP3_04_PIN PA11
|
||||
#define EXP3_05_PIN PB4
|
||||
#define EXP3_06_PIN PC1
|
||||
#define EXP3_07_PIN PC3
|
||||
#define EXP3_08_PIN PC2
|
||||
#define EXP3_09_PIN -1 // GND
|
||||
#define EXP3_10_PIN -1 // 5V
|
||||
|
||||
//
|
||||
// Four-button K7 Rev. B user interface
|
||||
//
|
||||
#if ENABLED(EASYTHREED_UI)
|
||||
#define BTN_HOME EXP3_07_PIN // INPUT_PULLUP (unused)
|
||||
#define BTN_FEED EXP3_02_PIN // Run E forward
|
||||
#define BTN_RETRACT EXP3_03_PIN // Run E backward
|
||||
#define BTN_PRINT EXP3_04_PIN // Start file print
|
||||
#define BTN_HOME_GND EXP3_08_PIN // OUTPUT LOW
|
||||
#define BTN_FEED_GND EXP3_05_PIN // OUTPUT LOW
|
||||
#define BTN_RETRACT_GND EXP3_06_PIN // OUTPUT LOW
|
||||
#define EASYTHREED_LED_PIN EXP3_01_PIN
|
||||
#endif
|
||||
|
||||
//
|
||||
// Motor current PWM
|
||||
//
|
||||
#define MOTOR_CURRENT_PWM_XY_PIN PB0
|
||||
#define MOTOR_CURRENT_PWM_Z_PIN PA7
|
||||
#define MOTOR_CURRENT_PWM_E_PIN PA6
|
||||
#define MOTOR_CURRENT_PWM_RANGE (65535/10/3.3)
|
||||
#define DEFAULT_PWM_MOTOR_CURRENT { 1000, 1000, 1000 }
|
||||
|
||||
//
|
||||
// Early safe output states
|
||||
//
|
||||
// Keep the heater, fan, and motor-current outputs inactive and disable
|
||||
// all stepper drivers before serial, media, EEPROM, and subsystem init.
|
||||
//
|
||||
#define BOARD_PREINIT() do { \
|
||||
OUT_WRITE(HEATER_0_PIN, LOW); \
|
||||
OUT_WRITE(FAN0_PIN, LOW); \
|
||||
OUT_WRITE(X_ENABLE_PIN, HIGH); \
|
||||
OUT_WRITE(E0_ENABLE_PIN, HIGH); \
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_XY_PIN, LOW); \
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_Z_PIN, LOW); \
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_E_PIN, LOW); \
|
||||
} while (0)
|
||||
|
||||
//
|
||||
// SD Card
|
||||
//
|
||||
#define SD_DETECT_PIN PC10
|
||||
#define SPI_DEVICE 2
|
||||
#define SD_SCK_PIN PB13
|
||||
#define SD_MISO_PIN PB14
|
||||
#define SD_MOSI_PIN PB15
|
||||
#define SD_SS_PIN PA15
|
||||
86
Marlin/src/pins/at32f4/pins_WANHAO_0327001.h
Normal file
86
Marlin/src/pins/at32f4/pins_WANHAO_0327001.h
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2026 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Wanhao 0327001 v2.0 pin assignments
|
||||
* MCU: AT32F403ARGT7
|
||||
*/
|
||||
|
||||
#include "env_validate.h"
|
||||
|
||||
// Stepper motor pins
|
||||
#define X_STEP_PIN PA0
|
||||
#define X_DIR_PIN PA1
|
||||
#define X_ENABLE_PIN PA2
|
||||
|
||||
#define Y_STEP_PIN PA3
|
||||
#define Y_DIR_PIN PA4
|
||||
#define Y_ENABLE_PIN PA5
|
||||
|
||||
#define Z_STEP_PIN PA6
|
||||
#define Z_DIR_PIN PA7
|
||||
#define Z_ENABLE_PIN PB0
|
||||
|
||||
#define E0_STEP_PIN PB1
|
||||
#define E0_DIR_PIN PB2
|
||||
#define E0_ENABLE_PIN PB3
|
||||
|
||||
// Endstops
|
||||
#define X_MIN_PIN PB4
|
||||
#define X_MAX_PIN PB5
|
||||
#define Y_MIN_PIN PB6
|
||||
#define Y_MAX_PIN PB7
|
||||
#define Z_MIN_PIN PC0
|
||||
#define Z_MAX_PIN PC1
|
||||
|
||||
// Temperature sensors
|
||||
#define TEMP_0_PIN PC2 // HE0
|
||||
#define TEMP_BED_PIN PC3 // BED
|
||||
|
||||
// Heaters
|
||||
#define HEATER_0_PIN PC4
|
||||
#define HEATER_BED_PIN PC5
|
||||
|
||||
// Fans
|
||||
#define FAN0_PIN PC6
|
||||
#define FAN1_PIN PC7
|
||||
|
||||
// LCD / Controller
|
||||
#define BEEPER_PIN PC8
|
||||
#define LCD_BACKLIGHT_PIN PC9
|
||||
#define LCD_RESET_PIN PC10
|
||||
|
||||
// SD Card
|
||||
#define SD_DETECT_PIN PC11
|
||||
#define SD_SS_PIN PC12 // CS
|
||||
|
||||
// SPI pins
|
||||
#define SCK_PIN PC13
|
||||
#define MISO_PIN PC14
|
||||
#define MOSI_PIN PC15
|
||||
|
||||
// EEPROM emulation on SD card (sdsupport is enabled for this board)
|
||||
#define SDCARD_EEPROM_EMULATION
|
||||
|
||||
// Note: Pin mappings are approximate and need verification from schematics
|
||||
// The actual pin assignments should be verified against the Wanhao 0327001 v2.0 board
|
||||
|
|
@ -977,6 +977,17 @@
|
|||
#elif MB(TRIGORILLA_V401_GD32_MFL)
|
||||
#include "gd32f3/pins_TRIGORILLA_V401_GD32_MFL.h" // GD32F303RG env:GD32F303RG_kobra2_neo_mfl
|
||||
|
||||
//
|
||||
// AT32 ARM Cortex-M4
|
||||
//
|
||||
|
||||
#elif MB(WANHAO_0327001)
|
||||
#include "at32f4/pins_WANHAO_0327001.h" // AT32F403 env:WANHAO_0327001
|
||||
#elif MB(EASYTHREED_ET4000_PLUS)
|
||||
#include "at32f4/pins_EASYTHREED_ET4000_PLUS.h" // AT32F403 env:EASYTHREED_ET4000_PLUS
|
||||
#elif MB(EASYTHREED_K7_REVB_AT32F407)
|
||||
#include "at32f4/pins_EASYTHREED_K7_REVB_AT32F407.h" // AT32F407 env:EASYTHREED_K7_REVB_AT32F407
|
||||
|
||||
//
|
||||
// Raspberry Pi RP2040
|
||||
//
|
||||
|
|
|
|||
|
|
@ -17,11 +17,19 @@ def copytree(src, dst, symlinks=False, ignore=None):
|
|||
shutil.copy2(item, dst / item.name)
|
||||
|
||||
def replace_define(field, value):
|
||||
envdefs = env['CPPDEFINES'].copy()
|
||||
for define in envdefs:
|
||||
if define[0] == field:
|
||||
env['CPPDEFINES'].remove(define)
|
||||
env['CPPDEFINES'].append((field, value))
|
||||
def matches(define):
|
||||
return define == field or (
|
||||
isinstance(define, (tuple, list))
|
||||
and define
|
||||
and define[0] == field
|
||||
)
|
||||
|
||||
envdefs = [
|
||||
define for define in env.get("CPPDEFINES", [])
|
||||
if not matches(define)
|
||||
]
|
||||
env.Replace(CPPDEFINES=envdefs)
|
||||
env.Append(CPPDEFINES=[(field, value)])
|
||||
|
||||
# Relocate the firmware to a new address, such as "0x08005000"
|
||||
def relocate_firmware(address):
|
||||
|
|
|
|||
|
|
@ -57,14 +57,16 @@ if pioutil.is_pio_build():
|
|||
val = key + "=" + (hex(value) if value >= 10 else str(value))
|
||||
else:
|
||||
val = key + "=" + str(value)
|
||||
found = False
|
||||
for i, flag in enumerate(env["LINKFLAGS"]):
|
||||
if key in flag:
|
||||
env["LINKFLAGS"][i] = val
|
||||
found = True
|
||||
|
||||
linkflags = list(env.get("LINKFLAGS", []))
|
||||
for i, flag in enumerate(linkflags):
|
||||
if key in str(flag):
|
||||
linkflags[i] = val
|
||||
break
|
||||
if not found:
|
||||
env.Append(LINKFLAGS=[val])
|
||||
else:
|
||||
linkflags.append(val)
|
||||
|
||||
env.Replace(LINKFLAGS=linkflags)
|
||||
|
||||
# Provide the symbols the linker script expects:
|
||||
# ORIGIN = 0x08000000 + LD_FLASH_OFFSET
|
||||
|
|
|
|||
14
buildroot/tests/EASYTHREED_ET4000_PLUS/config-01.ini
Normal file
14
buildroot/tests/EASYTHREED_ET4000_PLUS/config-01.ini
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# Marlin Firmware
|
||||
# Test: AT32F403ARCT7_easythreed_et4000_plus/config-01.ini
|
||||
#
|
||||
# Default Configuration with Fallback SD EEPROM
|
||||
#
|
||||
|
||||
[config:base]
|
||||
motherboard = BOARD_EASYTHREED_ET4000_PLUS
|
||||
serial_port = 1
|
||||
eeprom_settings = on
|
||||
sdsupport = on
|
||||
emergency_parser = on
|
||||
pins_debugging = on
|
||||
20
buildroot/tests/EASYTHREED_K7_REVB_AT32F407/config-01.ini
Normal file
20
buildroot/tests/EASYTHREED_K7_REVB_AT32F407/config-01.ini
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#
|
||||
# Marlin Firmware
|
||||
# Test: EasyThreed K7 Rev. B ET4000+ with AT32F407
|
||||
#
|
||||
# Native AT32 build fixture with external 24C16 EEPROM.
|
||||
# The target printer has no heated bed.
|
||||
#
|
||||
|
||||
[config:base]
|
||||
motherboard = BOARD_EASYTHREED_K7_REVB_AT32F407
|
||||
serial_port = 1
|
||||
serial_port_2 = 2
|
||||
baudrate = 115200
|
||||
temp_sensor_0 = 1
|
||||
temp_sensor_bed = 0
|
||||
eeprom_settings = on
|
||||
sdsupport = on
|
||||
emergency_parser = on
|
||||
pins_debugging = on
|
||||
easythreed_ui = on
|
||||
14
buildroot/tests/WANHAO_0327001/config-01.ini
Normal file
14
buildroot/tests/WANHAO_0327001/config-01.ini
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# Marlin Firmware
|
||||
# Test: AT32F403ARGT7_wanhao_0327001/config-01.ini
|
||||
#
|
||||
# Default Configuration with Fallback SD EEPROM
|
||||
#
|
||||
|
||||
[config:base]
|
||||
motherboard = BOARD_WANHAO_0327001
|
||||
serial_port = 1
|
||||
eeprom_settings = on
|
||||
sdsupport = on
|
||||
emergency_parser = on
|
||||
pins_debugging = on
|
||||
92
ini/at32.ini
Normal file
92
ini/at32.ini
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#
|
||||
# Marlin Firmware
|
||||
# PlatformIO Configuration File
|
||||
#
|
||||
|
||||
#################################
|
||||
#
|
||||
# AT32F403 Architecture with AT32 HAL
|
||||
#
|
||||
# Naming Example: AT32F403ARGT7
|
||||
#
|
||||
# |- Artery Technology
|
||||
# | |- CPU bit width (32: 32-bit)
|
||||
# | | |- Product Type (F: Universal MCU)
|
||||
# | | | |- Core Type (4: Cortex-M4)
|
||||
# | | | | |- Product Line (03A: AT32F403A, 07: AT32F407)
|
||||
# | | | | | |- Pin Count (R: 64, V: 100)
|
||||
# | | | | | | |- Flash Capacity (C: 256KB, G: 1MB)
|
||||
# | | | | | | | |- Package (T: LQFP)
|
||||
# | | | | | | | | |- Temperature range (7: -40-105°C)
|
||||
# AT 32 F 4 03A R G T 7
|
||||
#
|
||||
#################################
|
||||
|
||||
#
|
||||
# Base Environment for AT32F403
|
||||
#
|
||||
[AT32F403_base]
|
||||
platform = https://github.com/MarlinFirmware/platform-at32/archive/1.0.0.zip
|
||||
framework = arduino
|
||||
board = at32f403argt7
|
||||
build_src_filter = ${common.default_src_filter} +<src/HAL/AT32>
|
||||
build_type = release
|
||||
build_flags = -mcpu=cortex-m4 # ARM Cortex-M4 processor
|
||||
-mthumb # Thumb-2 instruction set
|
||||
-mfloat-abi=hard # Hardware floating point
|
||||
-mfpu=fpv4-sp-d16 # FPv4-Sp single-precision
|
||||
-DF_CPU=240000000L # Force constant F_CPU for constexpr
|
||||
-DARDUINO_ARCH_AT32 # Marlin HAL detection
|
||||
-DARDUINO_ARCH_AT32F4 # Arduino core compat (if needed)
|
||||
-DPLATFORM_M997_SUPPORT # Enable M997 command
|
||||
|
||||
# AT32 app configuration file
|
||||
board_build.app_config = Marlin/src/HAL/AT32/app_config.h
|
||||
|
||||
# Extra build flags
|
||||
board_build.flags.common = -g3 # Force emit debug symbols to elf
|
||||
-fno-signed-char # Force unsigned char
|
||||
|
||||
# Additional flags to reduce binary size
|
||||
board_build.flags.cpp = -fno-threadsafe-statics # Disable thread-safe statics
|
||||
-fno-exceptions # Disable exceptions (not used by Marlin)
|
||||
-fno-rtti # Disable RTTI (not used by Marlin)
|
||||
|
||||
#
|
||||
# Wanhao 0327001 v2.0 (AT32F403ARGT7) - 1MB Flash
|
||||
#
|
||||
[env:WANHAO_0327001]
|
||||
extends = AT32F403_base
|
||||
board = at32f403argt7
|
||||
board_build.variant = marlin_at32f403
|
||||
board_build.offset = 0x7000
|
||||
board_build.rename = Robin_nano.bin
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
pre:buildroot/share/PlatformIO/scripts/offset_and_rename.py
|
||||
board_upload.maximum_size = 1048576
|
||||
board_upload.offset_address = 0x08007000
|
||||
|
||||
#
|
||||
# EasyThreed K7 ET4000+ (AT32F403ARCT7) - 256K Flash
|
||||
#
|
||||
[env:EASYTHREED_ET4000_PLUS]
|
||||
extends = AT32F403_base
|
||||
board = at32f403arct7
|
||||
board_build.variant = marlin_at32f403
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
board_upload.maximum_size = 262144
|
||||
board_upload.offset_address = 0xC000 # Bootloader start address
|
||||
|
||||
#
|
||||
# EasyThreed K7 Rev. B ET4000+ (AT32F407RCT7 profile) - 256K Flash
|
||||
#
|
||||
[env:EASYTHREED_K7_REVB_AT32F407]
|
||||
extends = AT32F403_base
|
||||
board = at32f407rct7
|
||||
board_build.variant = marlin_at32f403
|
||||
board_build.offset = 0x5000
|
||||
board_build.encrypt_mks = mksLite.bin
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
pre:buildroot/share/PlatformIO/scripts/offset_and_rename.py
|
||||
board_upload.maximum_size = 262144
|
||||
board_upload.offset_address = 0x08005000
|
||||
|
|
@ -22,6 +22,7 @@ extra_configs =
|
|||
ini/esp32.ini
|
||||
ini/features.ini
|
||||
ini/hc32.ini
|
||||
ini/at32.ini
|
||||
ini/gd32.ini
|
||||
ini/lpc176x.ini
|
||||
ini/native.ini
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue