Skip to content

Commit d13ffa0

Browse files
ellenspellenspthinkyhead
committed
🔨 Creality v4 with STM32 HAL (#21999)
- New STM32 env for Creality V4 boards. - Separate Libmaple targets into their own `ini` file. - Temporarily remove unusable targets from `pins.h`. Co-authored-by: ellensp <ellensp@hotmsil.com> Co-authored-by: Scott Lahteine <github@thinkyhead.com>
1 parent fb0be29 commit d13ffa0

File tree

19 files changed

+692
-505
lines changed

19 files changed

+692
-505
lines changed

.github/workflows/test-builds.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,31 @@ jobs:
5656

5757
# STM32F1 (Maple) Environments
5858

59-
- STM32F103RC_btt
60-
- STM32F103RC_btt_USB
61-
- STM32F103RE_btt
62-
- STM32F103RE_btt_USB
59+
#- STM32F103RC_btt_maple
60+
- STM32F103RC_btt_USB_maple
6361
- STM32F103RC_fysetc
6462
- STM32F103RC_meeb
6563
- jgaurora_a5s_a1
6664
- STM32F103VE_longer
67-
- mks_robin
65+
#- mks_robin_maple
6866
- mks_robin_lite
6967
- mks_robin_pro
70-
- STM32F103RET6_creality
71-
- mks_robin_nano35
68+
#- mks_robin_nano35_maple
69+
#- STM32F103RET6_creality_maple
7270

7371
# STM32 (ST) Environments
7472

75-
- STM32F103RC_btt_stm32
73+
- STM32F103RC_btt
74+
#- STM32F103RC_btt_USB
75+
- STM32F103RE_btt
76+
- STM32F103RE_btt_USB
77+
- STM32F103RET6_creality
7678
- STM32F407VE_black
7779
- STM32F401VE_STEVAL
7880
- BIGTREE_BTT002
7981
- BIGTREE_SKR_PRO
8082
- BIGTREE_GTR_V1_0
81-
- mks_robin_stm32
83+
- mks_robin
8284
- ARMED
8385
- FYSETC_S6
8486
- STM32F070CB_malyan
@@ -88,7 +90,7 @@ jobs:
8890
- rumba32
8991
- LERDGEX
9092
- LERDGEK
91-
- mks_robin_nano35_stm32
93+
- mks_robin_nano35
9294
- NUCLEO_F767ZI
9395
- REMRAM_V1
9496
- BTT_SKR_SE_BX
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 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+
#ifdef STM32F1
23+
24+
/**
25+
* PersistentStore for Arduino-style EEPROM interface
26+
* with simple implementations supplied by Marlin.
27+
*/
28+
29+
#include "../../inc/MarlinConfig.h"
30+
31+
#if ENABLED(IIC_BL24CXX_EEPROM)
32+
33+
#include "../shared/eeprom_if.h"
34+
#include "../shared/eeprom_api.h"
35+
36+
//
37+
// PersistentStore
38+
//
39+
40+
#ifndef MARLIN_EEPROM_SIZE
41+
#error "MARLIN_EEPROM_SIZE is required for IIC_BL24CXX_EEPROM."
42+
#endif
43+
44+
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
45+
46+
bool PersistentStore::access_start() { eeprom_init(); return true; }
47+
bool PersistentStore::access_finish() { return true; }
48+
49+
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
50+
uint16_t written = 0;
51+
while (size--) {
52+
uint8_t v = *value;
53+
uint8_t * const p = (uint8_t * const)pos;
54+
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
55+
eeprom_write_byte(p, v);
56+
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
57+
if (eeprom_read_byte(p) != v) {
58+
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
59+
return true;
60+
}
61+
}
62+
crc16(crc, &v, 1);
63+
pos++;
64+
value++;
65+
}
66+
return false;
67+
}
68+
69+
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
70+
do {
71+
uint8_t * const p = (uint8_t * const)pos;
72+
uint8_t c = eeprom_read_byte(p);
73+
if (writing) *value = c;
74+
crc16(crc, &c, 1);
75+
pos++;
76+
value++;
77+
} while (--size);
78+
return false;
79+
}
80+
81+
#endif // IIC_BL24CXX_EEPROM
82+
#endif // STM32F1
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 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+
/**
24+
* Platform-independent Arduino functions for I2C EEPROM.
25+
* Enable USE_SHARED_EEPROM if not supplied by the framework.
26+
*/
27+
28+
#ifdef STM32F1
29+
30+
#include "../../inc/MarlinConfig.h"
31+
32+
#if ENABLED(IIC_BL24CXX_EEPROM)
33+
34+
#include "../../libs/BL24CXX.h"
35+
#include "../shared/eeprom_if.h"
36+
37+
void eeprom_init() { BL24CXX::init(); }
38+
39+
// ------------------------
40+
// Public functions
41+
// ------------------------
42+
43+
void eeprom_write_byte(uint8_t *pos, uint8_t value) {
44+
const unsigned eeprom_address = (unsigned)pos;
45+
return BL24CXX::writeOneByte(eeprom_address, value);
46+
}
47+
48+
uint8_t eeprom_read_byte(uint8_t *pos) {
49+
const unsigned eeprom_address = (unsigned)pos;
50+
return BL24CXX::readOneByte(eeprom_address);
51+
}
52+
53+
#endif // IIC_BL24CXX_EEPROM
54+
#endif // STM32F1

Marlin/src/libs/BL24CXX.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
*/
2828

2929
#include "BL24CXX.h"
30-
#include <libmaple/gpio.h>
30+
#ifdef __STM32F1__
31+
#include <libmaple/gpio.h>
32+
#else
33+
#include "../HAL/shared/Delay.h"
34+
#define delay_us(n) DELAY_US(n)
35+
#endif
3136

3237
#ifndef EEPROM_WRITE_DELAY
3338
#define EEPROM_WRITE_DELAY 10
@@ -37,8 +42,13 @@
3742
#endif
3843

3944
// IO direction setting
40-
#define SDA_IN() do{ PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH &= 0XFFFF0FFF; PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH |= 8 << 12; }while(0)
41-
#define SDA_OUT() do{ PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH &= 0XFFFF0FFF; PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH |= 3 << 12; }while(0)
45+
#ifdef __STM32F1__
46+
#define SDA_IN() do{ PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH &= 0XFFFF0FFF; PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH |= 8 << 12; }while(0)
47+
#define SDA_OUT() do{ PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH &= 0XFFFF0FFF; PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH |= 3 << 12; }while(0)
48+
#elif STM32F1
49+
#define SDA_IN() SET_INPUT(IIC_EEPROM_SDA)
50+
#define SDA_OUT() SET_OUTPUT(IIC_EEPROM_SDA)
51+
#endif
4252

4353
// IO ops
4454
#define IIC_SCL_0() WRITE(IIC_EEPROM_SCL, LOW)

Marlin/src/pins/pins.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,13 @@
489489
#elif MB(CHITU3D)
490490
#include "stm32f1/pins_CHITU3D.h" // STM32F1 env:STM32F103RE
491491
#elif MB(MKS_ROBIN)
492-
#include "stm32f1/pins_MKS_ROBIN.h" // STM32F1 env:mks_robin env:mks_robin_stm32
492+
#include "stm32f1/pins_MKS_ROBIN.h" // STM32F1 env:mks_robin env:mks_robin_maple
493493
#elif MB(MKS_ROBIN_MINI)
494494
#include "stm32f1/pins_MKS_ROBIN_MINI.h" // STM32F1 env:mks_robin_mini
495495
#elif MB(MKS_ROBIN_NANO)
496-
#include "stm32f1/pins_MKS_ROBIN_NANO.h" // STM32F1 env:mks_robin_nano35 env:mks_robin_nano35_stm32
496+
#include "stm32f1/pins_MKS_ROBIN_NANO.h" // STM32F1 env:mks_robin_nano35 env:mks_robin_nano35_maple
497497
#elif MB(MKS_ROBIN_NANO_V2)
498-
#include "stm32f1/pins_MKS_ROBIN_NANO_V2.h" // STM32F1 env:mks_robin_nano35 env:mks_robin_nano35_stm32
498+
#include "stm32f1/pins_MKS_ROBIN_NANO_V2.h" // STM32F1 env:mks_robin_nano35 env:mks_robin_nano35_maple
499499
#elif MB(MKS_ROBIN_LITE)
500500
#include "stm32f1/pins_MKS_ROBIN_LITE.h" // STM32F1 env:mks_robin_lite
501501
#elif MB(MKS_ROBIN_LITE3)
@@ -513,17 +513,17 @@
513513
#elif MB(MKS_ROBIN_E3P)
514514
#include "stm32f1/pins_MKS_ROBIN_E3P.h" // STM32F1 env:mks_robin_e3p
515515
#elif MB(BTT_SKR_MINI_V1_1)
516-
#include "stm32f1/pins_BTT_SKR_MINI_V1_1.h" // STM32F1 env:STM32F103RC_btt_stm32 env:STM32F103RC_btt_512K_stm32 env:STM32F103RC_btt_USB_stm32 env:STM32F103RC_btt_512K_USB_stm32 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_USB env:STM32F103RC_btt_512K_USB
516+
#include "stm32f1/pins_BTT_SKR_MINI_V1_1.h" // STM32F1 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_maple env:STM32F103RC_btt_512K_maple env:STM32F103RC_btt_USB_maple env:STM32F103RC_btt_512K_USB_maple
517517
#elif MB(BTT_SKR_MINI_E3_V1_0)
518-
#include "stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h" // STM32F1 env:STM32F103RC_btt_stm32 env:STM32F103RC_btt_512K_stm32 env:STM32F103RC_btt_USB_stm32 env:STM32F103RC_btt_512K_USB_stm32 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_USB env:STM32F103RC_btt_512K_USB
518+
#include "stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h" // STM32F1 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_maple env:STM32F103RC_btt_512K_maple env:STM32F103RC_btt_USB_maple env:STM32F103RC_btt_512K_USB_maple
519519
#elif MB(BTT_SKR_MINI_E3_V1_2)
520-
#include "stm32f1/pins_BTT_SKR_MINI_E3_V1_2.h" // STM32F1 env:STM32F103RC_btt_stm32 env:STM32F103RC_btt_512K_stm32 env:STM32F103RC_btt_USB_stm32 env:STM32F103RC_btt_512K_USB_stm32 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_USB env:STM32F103RC_btt_512K_USB
520+
#include "stm32f1/pins_BTT_SKR_MINI_E3_V1_2.h" // STM32F1 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_maple env:STM32F103RC_btt_512K_maple env:STM32F103RC_btt_USB_maple env:STM32F103RC_btt_512K_USB_maple
521521
#elif MB(BTT_SKR_MINI_E3_V2_0)
522-
#include "stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h" // STM32F1 env:STM32F103RC_btt_stm32 env:STM32F103RC_btt_512K_stm32 env:STM32F103RC_btt_USB_stm32 env:STM32F103RC_btt_512K_USB_stm32 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_USB env:STM32F103RC_btt_512K_USB
522+
#include "stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h" // STM32F1 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_maple env:STM32F103RC_btt_512K_maple env:STM32F103RC_btt_USB_maple env:STM32F103RC_btt_512K_USB_maple
523523
#elif MB(BTT_SKR_MINI_MZ_V1_0)
524-
#include "stm32f1/pins_BTT_SKR_MINI_MZ_V1_0.h" // STM32F1 env:STM32F103RC_btt_stm32 env:STM32F103RC_btt_512K_stm32 env:STM32F103RC_btt_USB_stm32 env:STM32F103RC_btt_512K_USB_stm32 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_USB env:STM32F103RC_btt_512K_USB
524+
#include "stm32f1/pins_BTT_SKR_MINI_MZ_V1_0.h" // STM32F1 env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_maple env:STM32F103RC_btt_512K_maple env:STM32F103RC_btt_USB_maple env:STM32F103RC_btt_512K_USB_maple
525525
#elif MB(BTT_SKR_E3_DIP)
526-
#include "stm32f1/pins_BTT_SKR_E3_DIP.h" // STM32F1 env:STM32F103RE_btt env:STM32F103RE_btt_USB env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_USB env:STM32F103RC_btt_512K_USB
526+
#include "stm32f1/pins_BTT_SKR_E3_DIP.h" // STM32F1 env:STM32F103RE_btt env:STM32F103RE_btt_USB env:STM32F103RC_btt env:STM32F103RC_btt_512K
527527
#elif MB(BTT_SKR_CR6)
528528
#include "stm32f1/pins_BTT_SKR_CR6.h" // STM32F1 env:STM32F103RE_btt env:STM32F103RE_btt_USB
529529
#elif MB(JGAURORA_A5S_A1)
@@ -543,17 +543,17 @@
543543
#elif MB(CHITU3D_V6)
544544
#include "stm32f1/pins_CHITU3D_V6.h" // STM32F1 env:chitu_f103
545545
#elif MB(CREALITY_V4)
546-
#include "stm32f1/pins_CREALITY_V4.h" // STM32F1 env:STM32F103RET6_creality
546+
#include "stm32f1/pins_CREALITY_V4.h" // STM32F1 env:STM32F103RET6_creality env:STM32F103RET6_creality_maple
547547
#elif MB(CREALITY_V4210)
548-
#include "stm32f1/pins_CREALITY_V4210.h" // STM32F1 env:STM32F103RET6_creality
548+
#include "stm32f1/pins_CREALITY_V4210.h" // STM32F1 env:STM32F103RET6_creality env:STM32F103RET6_creality_maple
549549
#elif MB(CREALITY_V427)
550-
#include "stm32f1/pins_CREALITY_V427.h" // STM32F1 env:STM32F103RET6_creality
550+
#include "stm32f1/pins_CREALITY_V427.h" // STM32F1 env:STM32F103RET6_creality env:STM32F103RET6_creality_maple
551551
#elif MB(CREALITY_V431)
552-
#include "stm32f1/pins_CREALITY_V431.h" // STM32F1 env:STM32F103RET6_creality
552+
#include "stm32f1/pins_CREALITY_V431.h" // STM32F1 env:STM32F103RET6_creality env:STM32F103RET6_creality_maple
553553
#elif MB(CREALITY_V452)
554-
#include "stm32f1/pins_CREALITY_V452.h" // STM32F1 env:STM32F103RET6_creality
554+
#include "stm32f1/pins_CREALITY_V452.h" // STM32F1 env:STM32F103RET6_creality env:STM32F103RET6_creality_maple
555555
#elif MB(CREALITY_V453)
556-
#include "stm32f1/pins_CREALITY_V453.h" // STM32F1 env:STM32F103RET6_creality
556+
#include "stm32f1/pins_CREALITY_V453.h" // STM32F1 env:STM32F103RET6_creality env:STM32F103RET6_creality_maple
557557
#elif MB(TRIGORILLA_PRO)
558558
#include "stm32f1/pins_TRIGORILLA_PRO.h" // STM32F1 env:trigorilla_pro
559559
#elif MB(FLY_MINI)

Marlin/src/pins/stm32f1/env_validate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
*/
2222
#pragma once
2323

24-
#if NOT_TARGET(__STM32F1__)
24+
#if NOT_TARGET(__STM32F1__, STM32F1)
2525
#error "Oops! Select an STM32F1 board in 'Tools > Board.'"
2626
#endif

buildroot/share/PlatformIO/scripts/mks_encrypt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# buildroot/share/PlatformIO/scripts/mks_encrypt.py
33
#
44
# Apply encryption and save as 'build.firmware' for these environments:
5-
# - env:mks_robin_stm32
5+
# - env:mks_robin
66
# - env:flsun_hispeedv1
7-
# - env:mks_robin_nano35_stm32
7+
# - env:mks_robin_nano35
88
#
99
Import("env")
1010

buildroot/tests/STM32F103RC_btt_USB

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set -e
1010
# Build with the default configurations
1111
#
1212
restore_configs
13-
opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_V1_1 SERIAL_PORT 1 SERIAL_PORT_2 -1 BAUDRATE_2 115200
13+
opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_V1_1 SERIAL_PORT 1 SERIAL_PORT_2 -1
1414
exec_test $1 $2 "BigTreeTech SKR Mini v1.1 - Basic Configuration" "$3"
1515

1616
# clean up
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Build tests for STM32F103RC BigTreeTech (SKR Mini v1.1)
3+
# Build tests for STM32F103RC BigTreeTech (SKR Mini v1.1) with LibMaple STM32F1 HAL
44
#
55

66
# exit on first failure
@@ -10,7 +10,7 @@ set -e
1010
# Build with the default configurations
1111
#
1212
restore_configs
13-
opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_V1_1 SERIAL_PORT 1 SERIAL_PORT_2 -1
13+
opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_V1_1 SERIAL_PORT 1 SERIAL_PORT_2 -1 BAUDRATE_2 115200
1414
exec_test $1 $2 "BigTreeTech SKR Mini v1.1 - Basic Configuration" "$3"
1515

1616
# clean up
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Build tests for STM32F103RC BigTreeTech (SKR Mini E3)
3+
# Build tests for STM32F103RC BigTreeTech (SKR Mini E3) with LibMaple STM32F1 HAL
44
#
55

66
# exit on first failure

0 commit comments

Comments
 (0)