Skip to content

Commit a6cf361

Browse files
⛙ Merge w/Marlin
2 parents dea3c84 + 849e432 commit a6cf361

File tree

165 files changed

+5307
-2437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+5307
-2437
lines changed

.github/workflows/ci-build-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,16 @@ jobs:
155155
# - STM32F103RE_creality_maple
156156
# - STM32F103RC_creality_maple
157157
# - GD32F303RC_creality_maple
158-
# - GD32F303RC_creality_maple
159158
- GD32F103RC_voxelab_maple
160159
- N32F103RC_voxelab_maple
161160
# - N32G455RE_voxelab_maple
162161

163162
# STM32G0
164163
- STM32G0B1RE_btt
165164

165+
# GD32F3
166+
- GD32F303RE_creality_mfl
167+
166168
# LPC176x - Lengthy tests
167169
# - LPC1768
168170
# - LPC1769

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ help:
1717
@echo "make tests-all-local-docker : Run all tests locally, using docker"
1818
@echo "make unit-test-single-local : Run unit tests for a single config locally"
1919
@echo "make unit-test-single-local-docker : Run unit tests for a single config locally, using docker"
20-
@echo "make unit-test-all-local : Run all code tests locally"
20+
@echo "make unit-test-all-local : Run all code tests locally"
2121
@echo "make unit-test-all-local-docker : Run all code tests locally, using docker"
2222
@echo "make setup-local-docker : Setup local docker using buildx"
2323
@echo ""

Marlin/Configuration.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,6 @@
10341034
// Print surface diameter/2 minus unreachable space (avoid collisions with vertical towers).
10351035
#define PRINTABLE_RADIUS 140.0 // (mm)
10361036

1037-
// Maximum reachable area
1038-
#define DELTA_MAX_RADIUS 140.0 // (mm)
1039-
10401037
// Center-to-center distance of the holes in the diagonal push rods.
10411038
#define DELTA_DIAGONAL_ROD 250.0 // (mm)
10421039

Marlin/Configuration_adv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,6 +3016,8 @@
30163016

30173017
#define HOLD_MULTIPLIER 0.5 // Scales down the holding current from run current
30183018

3019+
//#define EDITABLE_HOMING_CURRENT // Add a G-code and menu to modify the Homing Current
3020+
30193021
/**
30203022
* Interpolate microsteps to 256
30213023
* Override for each driver with <driver>_INTERPOLATE settings below

Marlin/src/HAL/GD32_MFL/HAL.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2025 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#include "../platforms.h"
24+
25+
#ifdef ARDUINO_ARCH_MFL
26+
27+
#include "../../inc/MarlinConfig.h"
28+
#include "../shared/Delay.h"
29+
30+
uint16_t MarlinHAL::adc_result;
31+
32+
#if ENABLED(POSTMORTEM_DEBUGGING)
33+
extern void install_min_serial();
34+
#endif
35+
36+
#if ENABLED(MARLIN_DEV_MODE)
37+
// Dump the clock frequencies of the system, AHB, APB1, APB2, and F_CPU.
38+
static inline void HAL_clock_frequencies_dump() {
39+
auto& rcuInstance = rcu::RCU::get_instance();
40+
uint32_t freq = rcuInstance.get_clock_frequency(rcu::Clock_Frequency::CK_SYS);
41+
SERIAL_ECHOPGM("\nSYSTEM_CLOCK=", freq);
42+
freq = rcuInstance.get_clock_frequency(rcu::Clock_Frequency::CK_AHB);
43+
SERIAL_ECHOPGM("\nABH_CLOCK=", freq);
44+
freq = rcuInstance.get_clock_frequency(rcu::Clock_Frequency::CK_APB1);
45+
SERIAL_ECHOPGM("\nAPB1_CLOCK=", freq);
46+
freq = rcuInstance.get_clock_frequency(rcu::Clock_Frequency::CK_APB2);
47+
SERIAL_ECHOPGM("\nAPB2_CLOCK=", freq,
48+
"\nF_CPU=", F_CPU);
49+
// Done
50+
SERIAL_ECHOPGM("\n--\n");
51+
}
52+
#endif // MARLIN_DEV_MODE
53+
54+
// Initializes the Marlin HAL
55+
void MarlinHAL::init() {
56+
constexpr unsigned int cpuFreq = F_CPU;
57+
UNUSED(cpuFreq);
58+
59+
#if PIN_EXISTS(LED)
60+
OUT_WRITE(LED_PIN, LOW);
61+
#endif
62+
63+
SetTimerInterruptPriorities();
64+
65+
// Print clock frequencies to host serial
66+
TERN_(MARLIN_DEV_MODE, HAL_clock_frequencies_dump());
67+
68+
// Register min serial
69+
TERN_(POSTMORTEM_DEBUGGING, install_min_serial());
70+
}
71+
72+
// Returns the reset source based on the flags set in the RCU module
73+
uint8_t MarlinHAL::get_reset_source() {
74+
return
75+
(RCU_I.get_flag(rcu::Status_Flags::FLAG_FWDGTRST)) ? RST_WATCHDOG :
76+
(RCU_I.get_flag(rcu::Status_Flags::FLAG_SWRST)) ? RST_SOFTWARE :
77+
(RCU_I.get_flag(rcu::Status_Flags::FLAG_EPRST)) ? RST_EXTERNAL :
78+
(RCU_I.get_flag(rcu::Status_Flags::FLAG_PORRST)) ? RST_POWER_ON :
79+
(RCU_I.get_flag(rcu::Status_Flags::FLAG_LPRST)) ? RST_BROWN_OUT :
80+
0;
81+
}
82+
83+
// Returns the amount of free memory available in bytes
84+
int MarlinHAL::freeMemory() {
85+
volatile char top;
86+
return &top - reinterpret_cast<char*>(_sbrk(0));
87+
}
88+
89+
// Watchdog Timer
90+
#if ENABLED(USE_WATCHDOG)
91+
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
92+
93+
#include <FWatchdogTimer.h>
94+
95+
FWatchdogTimer& watchdogTimer = FWatchdogTimer::get_instance();
96+
97+
// Initializes the watchdog timer
98+
void MarlinHAL::watchdog_init() {
99+
IF_DISABLED(DISABLE_WATCHDOG_INIT, watchdogTimer.begin(WDT_TIMEOUT_US));
100+
}
101+
102+
// Refreshes the watchdog timer to prevent system reset
103+
void MarlinHAL::watchdog_refresh() {
104+
watchdogTimer.reload();
105+
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
106+
TOGGLE(LED_PIN); // Heartbeat indicator
107+
#endif
108+
}
109+
#endif
110+
111+
extern "C" {
112+
extern unsigned int _ebss; // End of bss section
113+
}
114+
115+
// Resets the system to initiate a firmware flash.
116+
WEAK void flashFirmware(const int16_t) {
117+
hal.reboot();
118+
}
119+
120+
#endif // ARDUINO_ARCH_MFL

Marlin/src/HAL/GD32_MFL/HAL.h

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2025 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
#define CPU_32_BIT
25+
26+
#include "../../core/macros.h"
27+
#include "../shared/Marduino.h"
28+
#include "../shared/math_32bit.h"
29+
#include "../shared/HAL_SPI.h"
30+
31+
#include "temp_soc.h"
32+
#include "fastio.h"
33+
#include "Servo.h"
34+
35+
#include "../../inc/MarlinConfigPre.h"
36+
37+
#include <stdint.h>
38+
#include <GPIO.hpp>
39+
#include <AFIO.hpp>
40+
41+
// Default graphical display delays
42+
#define CPU_ST7920_DELAY_1 300
43+
#define CPU_ST7920_DELAY_2 40
44+
#define CPU_ST7920_DELAY_3 340
45+
46+
// Serial Ports
47+
#include "MarlinSerial.h"
48+
49+
// Interrupts
50+
#define CRITICAL_SECTION_START() const bool irqon = !__get_PRIMASK(); __disable_irq()
51+
#define CRITICAL_SECTION_END() if (irqon) __enable_irq()
52+
53+
#define cli() __disable_irq()
54+
#define sei() __enable_irq()
55+
56+
// Alias of __bss_end__
57+
#define __bss_end __bss_end__
58+
59+
// Types
60+
typedef double isr_float_t; // FPU ops are used for single-precision, so use double for ISRs.
61+
typedef uint8_t pin_t; // Parity with mfl platform
62+
63+
// Servo
64+
class libServo;
65+
typedef libServo hal_servo_t;
66+
#define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos()
67+
#define RESUME_SERVO_OUTPUT() libServo::resume_all_servos()
68+
69+
// Debugging
70+
#define JTAG_DISABLE() AFIO_I.set_remap(gpio::Pin_Remap_Select::SWJ_DP_ONLY_REMAP)
71+
#define JTAGSWD_DISABLE() AFIO_I.set_remap(gpio::Pin_Remap_Select::SWJ_ALL_DISABLED_REMAP)
72+
#define JTAGSWD_RESET() AFIO_I.set_remap(gpio::Pin_Remap_Select::FULL_SWJ_REMAP)
73+
74+
// ADC
75+
#ifdef ADC_RESOLUTION
76+
#define HAL_ADC_RESOLUTION ADC_RESOLUTION
77+
#else
78+
#define HAL_ADC_RESOLUTION 12
79+
#endif
80+
81+
#define HAL_ADC_VREF_MV 3300
82+
83+
// Disable Marlin's software oversampling.
84+
// The MFL framework uses 16x hardware oversampling by default
85+
#define HAL_ADC_FILTERED
86+
87+
#define GET_PIN_MAP_PIN(index) index
88+
#define GET_PIN_MAP_INDEX(pin) pin
89+
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
90+
91+
#ifndef PLATFORM_M997_SUPPORT
92+
#define PLATFORM_M997_SUPPORT
93+
#endif
94+
95+
void flashFirmware(const int16_t);
96+
97+
#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment
98+
99+
extern "C" char* _sbrk(int incr);
100+
extern "C" char* dtostrf(double val, signed char width, unsigned char prec, char* sout);
101+
102+
// MarlinHAL Class
103+
class MarlinHAL {
104+
public:
105+
// Before setup()
106+
MarlinHAL() {}
107+
108+
// Watchdog
109+
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
110+
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
111+
112+
static void init(); // called early in setup()
113+
static void init_board() {} // called less early in setup()
114+
static void reboot() { NVIC_SystemReset(); } // restart the firmware from 0x0
115+
116+
// Interrupts
117+
static bool isr_state() { return !__get_PRIMASK(); }
118+
static void isr_on() { sei(); }
119+
static void isr_off() { cli(); }
120+
static void delay_ms(const int ms) { delay(ms); }
121+
122+
// Tasks called from idle()
123+
static void idletask() {}
124+
125+
// Reset
126+
static uint8_t get_reset_source();
127+
static void clear_reset_source() { RCU_I.clear_all_reset_flags(); }
128+
129+
// Free SRAM
130+
static int freeMemory();
131+
132+
// ADC methods
133+
static uint16_t adc_result;
134+
135+
// Called by Temperature::init once at startup
136+
static void adc_init() { analogReadResolution(HAL_ADC_RESOLUTION); }
137+
138+
// Called by Temperature::init for each sensor at startup
139+
static void adc_enable(const pin_t pin) { pinMode(pin, INPUT); }
140+
141+
// Called from Temperature::isr to start ADC sampling on the given pin
142+
static void adc_start(const pin_t pin) { adc_result = static_cast<uint16_t>(analogRead(pin)); }
143+
144+
// Check if ADC is ready for reading
145+
static bool adc_ready() { return true; }
146+
147+
// Current value of the ADC register
148+
static uint16_t adc_value() { return adc_result; }
149+
150+
// Set the PWM duty cycle for the pin to the given value.
151+
// Optionally invert the duty cycle [default = false]
152+
// Optionally change the maximum size of the provided value to enable finer PWM duty control [default = 255]
153+
static void set_pwm_duty(const pin_t pin, const uint16_t value, const uint16_t scale = 255U, const bool invert = false);
154+
155+
// Set the frequency of the timer for the given pin.
156+
// All Timer PWM pins run at the same frequency.
157+
static void set_pwm_frequency(const pin_t pin, const uint16_t f_desired);
158+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2025 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
#include <SPI.h>
25+
26+
using MarlinSPI = SPIClass;

0 commit comments

Comments
 (0)