Skip to content

Commit

Permalink
BTT SKR Mini E3 for HAL/STM32 (MarlinFirmware#21488)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhapsodyv authored and Night69 committed Aug 31, 2021
1 parent 42e4634 commit b4c128c
Show file tree
Hide file tree
Showing 10 changed files with 596 additions and 458 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:

# STM32 (ST) Environments

- STM32F103RC_btt_stm32
- STM32F407VE_black
- STM32F401VE_STEVAL
- BIGTREE_BTT002
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/HAL/STM32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ void HAL_init() {
delay(1000); // Give OS time to notice
WRITE(USB_CONNECT_PIN, USB_CONNECT_INVERTING);
#endif

#if PIN_EXISTS(USB_CONNECT)
OUT_WRITE(USB_CONNECT_PIN, !USB_CONNECT_INVERTING); // USB clear connection
delay(1000); // Give OS time to notice
WRITE(USB_CONNECT_PIN, USB_CONNECT_INVERTING);
#endif
}

// HAL idle task
Expand Down
129 changes: 58 additions & 71 deletions Marlin/src/pins/pins.h

Large diffs are not rendered by default.

95 changes: 39 additions & 56 deletions Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*/
#pragma once

#include "env_validate.h"
#if NOT_TARGET(__STM32F1__, STM32F1)
#error "Oops! Select an STM32F1 board in 'Tools > Board.'"
#endif

// Release PB3/PB4 (E0 STP/DIR) from JTAG pins
#define DISABLE_JTAG
Expand Down Expand Up @@ -117,14 +119,14 @@

/**
* SKR Mini E3 V1.0, V1.2 SKR Mini E3 V2.0
* ______ ______
* 5V | 1 2 | GND 5V | 1 2 | GND
* (LCD_EN) PB7 | 3 4 | PB8 (LCD_RS) (LCD_EN) PB15 | 3 4 | PB8 (LCD_RS)
* (LCD_D4) PB9 | 5 6 PA10 (BTN_EN2) (LCD_D4) PB9 | 5 6 PA10 (BTN_EN2)
* RESET | 7 8 | PA9 (BTN_EN1) RESET | 7 8 | PA9 (BTN_EN1)
* (BTN_ENC) PB6 | 9 10 | PB5 (BEEPER) (BTN_ENC) PA15 | 9 10 | PB5 (BEEPER)
* ------ ------
* EXP1 EXP1
* _____ _____
* 5V | 1 2 | GND 5V | 1 2 | GND
* (LCD_EN) PB7 | 3 4 | PB8 (LCD_RS) (LCD_EN) PB15 | 3 4 | PB8 (LCD_RS)
* (LCD_D4) PB9 | 5 6 PA10 (BTN_EN2) (LCD_D4) PB9 | 5 6 PA10 (BTN_EN2)
* RESET | 7 8 | PA9 (BTN_EN1) RESET | 7 8 | PA9 (BTN_EN1)
* (BTN_ENC) PB6 | 9 10| PB5 (BEEPER) (BTN_ENC) PA15 | 9 10| PB5 (BEEPER)
* ----- -----
* EXP1 EXP1
*/
#ifdef SKR_MINI_E3_V2
#define EXP1_9 PA15
Expand All @@ -134,28 +136,7 @@
#define EXP1_3 PB7
#endif

#if ENABLED(DWIN_CREALITY_LCD)
/**
* ------ ------ ------
* VCC | 1 2 | GND VCC | 1 2 | GND GND | 2 1 | VCC
* A | 3 4 | B A | 3 4 | B B | 4 3 | A
* | 5 6 TX BEEP | 5 6 ENT ENT | 6 5 | BEEP
* | 7 8 | RX TX | 7 8 | RX RX | 8 7 | TX
* BEEP | 9 10 | ENT | 9 10 | | 10 9 |
* ------ ------ ------
* EXP1 DWIN DWIN (plug)
*
* All pins are labeled as printed on DWIN PCB. Connect TX-TX, A-A and so on.
*/

#error "DWIN_CREALITY_LCD requires a custom cable, see diagram above this line. Comment out this line to continue."

#define BEEPER_PIN EXP1_9
#define BTN_EN1 EXP1_3
#define BTN_EN2 PB8
#define BTN_ENC PB5

#elif HAS_WIRED_LCD
#if HAS_WIRED_LCD

#if ENABLED(CR10_STOCKDISPLAY)

Expand Down Expand Up @@ -205,19 +186,19 @@
* TFTGLCD_PANEL_SPI display pinout
*
* Board Display
* ______ ______
* 5V | 1 2 | GND (SPI1-MISO) MISO | 1 2 | SCK (SPI1-SCK)
* (FREE) PB7 | 3 4 | PB8 (LCD_CS) (PA9) LCD_CS | 3 4 | SD_CS (PA10)
* (FREE) PB9 | 5 6 | PA10 (SD_CS) (FREE) | 5 6 | MOSI (SPI1-MOSI)
* RESET | 7 8 | PA9 (MOD_RESET) (PB5) SD_DET | 7 8 | (FREE)
* (BEEPER) PB6 | 9 10 | PB5 (SD_DET) GND | 9 10 | 5V
* ------ ------
* EXP1 EXP1
* _____ _____
* 5V | 1 2 | GND (SPI1-MISO) MISO | 1 2 | SCK (SPI1-SCK)
* (FREE) PB7 | 3 4 | PB8 (LCD_CS) (PA9) LCD_CS | 3 4 | SD_CS (PA10)
* (FREE) PB9 | 5 6 | PA10 (SD_CS) (FREE) | 5 6 | MOSI (SPI1-MOSI)
* RESET | 7 8 | PA9 (MOD_RESET) (PB5) SD_DET | 7 8 | (FREE)
* (BEEPER) PB6 | 9 10| PB5 (SD_DET) GND | 9 10| 5V
* ----- -----
* EXP1 EXP1
*
* Needs custom cable:
*
* Board Display
*
* Board Adapter Display
* _________
* EXP1-1 ----------- EXP1-10
* EXP1-2 ----------- EXP1-9
* SPI1-4 ----------- EXP1-6
Expand All @@ -244,18 +225,17 @@

#error "CAUTION! LCD_FYSETC_TFT81050 requires wiring modifications. See 'pins_BTT_SKR_MINI_E3_common.h' for details. Comment out this line to continue."

/**
* FYSETC TFT TFT81050 display pinout
/** FYSETC TFT TFT81050 display pinout
*
* Board Display
* ______ ______
* 5V | 1 2 | GND (SPI1-MISO) MISO | 1 2 | SCK (SPI1-SCK)
* (FREE) PB7 | 3 4 | PB8 (LCD_CS) (PA9) MOD_RESET | 3 4 | SD_CS (PA10)
* (FREE) PB9 | 5 6 | PA10 (SD_CS) (PB8) LCD_CS | 5 6 | MOSI (SPI1-MOSI)
* RESET | 7 8 | PA9 (MOD_RESET) (PB5) SD_DET | 7 8 | RESET
* (BEEPER) PB6 | 9 10 | PB5 (SD_DET) GND | 9 10 | 5V
* ------ ------
* EXP1 EXP1
* _____ _____
* 5V | 1 2 | GND (SPI1-MISO) MISO | 1 2 | SCK (SPI1-SCK)
* (FREE) PB7 | 3 4 | PB8 (LCD_CS) (PA9) MOD_RESET | 3 4 | SD_CS (PA10)
* (FREE) PB9 | 5 6 | PA10 (SD_CS) (PB8) LCD_CS | 5 6 | MOSI (SPI1-MOSI)
* RESET | 7 8 | PA9 (MOD_RESET) (PB5) SD_DET | 7 8 | RESET
* (BEEPER) PB6 | 9 10| PB5 (SD_DET) GND | 9 10| 5V
* ----- -----
* EXP1 EXP1
*
* Needs custom cable:
*
Expand Down Expand Up @@ -302,8 +282,11 @@
#define ONBOARD_SPI_DEVICE 1 // SPI1 -> used only by HAL/STM32F1...
#define ONBOARD_SD_CS_PIN PA4 // Chip select for "System" SD card

#define ENABLE_SPI1
#define SDSS ONBOARD_SD_CS_PIN
#define SD_SCK_PIN PA5
#define SD_MISO_PIN PA6
#define SD_MOSI_PIN PA7
#define CUSTOM_SPI_PINS // TODO: needed because is the only way to set SPI for SD on STM32 (for now)
#if ENABLED(CUSTOM_SPI_PINS)
#define ENABLE_SPI1
#define SDSS ONBOARD_SD_CS_PIN
#define SD_SCK_PIN PA5
#define SD_MISO_PIN PA6
#define SD_MOSI_PIN PA7
#endif
43 changes: 43 additions & 0 deletions buildroot/share/PlatformIO/scripts/stm32_bootloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# stm32_bootloader.py
#
import os,sys,shutil,marlin
Import("env")

from SCons.Script import DefaultEnvironment
board = DefaultEnvironment().BoardConfig()

#
# Copy the firmware.bin file to build.firmware, no encryption
#
def noencrypt(source, target, env):
firmware = os.path.join(target[0].dir.path, board.get("build.firmware"))
shutil.copy(target[0].path, firmware)

#
# For build.offset define LD_FLASH_OFFSET, used by ldscript.ld
#
if 'offset' in board.get("build").keys():
LD_FLASH_OFFSET = board.get("build.offset")
marlin.relocate_vtab(LD_FLASH_OFFSET)

# Flash size
maximum_flash_size = int(board.get("upload.maximum_size") / 1024)
marlin.replace_define('STM32_FLASH_SIZE', maximum_flash_size)

# Get upload.maximum_ram_size (defined by /buildroot/share/PlatformIO/boards/VARIOUS.json)
maximum_ram_size = board.get("upload.maximum_ram_size")

for i, flag in enumerate(env["LINKFLAGS"]):
if "-Wl,--defsym=LD_FLASH_OFFSET" in flag:
env["LINKFLAGS"][i] = "-Wl,--defsym=LD_FLASH_OFFSET=" + LD_FLASH_OFFSET
if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag:
env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40)

#
# Only copy the file if there's no encrypt
#
board_keys = board.get("build").keys()
if 'firmware' in board_keys and ('encrypt' not in board_keys or board.get("build.encrypt") == 'No'):
import marlin
marlin.add_post_action(noencrypt)
10 changes: 5 additions & 5 deletions buildroot/share/PlatformIO/variants/MARLIN_F103Rx/ldscript.ld
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ SECTIONS
. = ALIGN(4);
} >FLASH

.ARM.extab : {
.ARM.extab : {
. = ALIGN(4);
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(4);
Expand Down Expand Up @@ -146,7 +146,7 @@ SECTIONS
_sidata = LOADADDR(.data);

/* Initialized data sections into "RAM" Ram type memory */
.data :
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
Expand All @@ -157,12 +157,12 @@ SECTIONS
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH


/* Uninitialized data section into "RAM" Ram type memory */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
Expand All @@ -185,7 +185,7 @@ SECTIONS
. = ALIGN(8);
} >RAM



/* Remove information from the compiler libraries */
/DISCARD/ :
Expand Down
24 changes: 5 additions & 19 deletions buildroot/share/PlatformIO/variants/MARLIN_F103Rx/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,11 @@ extern "C" {
#endif

// Override default Arduino configuration

// SPI Definitions
#if DEFAULT_SPI == 3
#define PIN_SPI_SS PA15
#define PIN_SPI_MOSI PB3
#define PIN_SPI_MISO PB4
#define PIN_SPI_SCK PB5
#elif DEFAULT_SPI == 2
#define PIN_SPI_SS PB12
#define PIN_SPI_MOSI PB13
#define PIN_SPI_MISO PB14
#define PIN_SPI_SCK PB15
#else
#define PIN_SPI_SS PA4
#define PIN_SPI_MOSI PA7
#define PIN_SPI_MISO PA6
#define PIN_SPI_SCK PA5
#endif
#define PIN_SPI_SS PA4
#define PIN_SPI_MOSI PA7
#define PIN_SPI_MISO PA6
#define PIN_SPI_SCK PA5

// I2C Definitions
#define PIN_WIRE_SDA PB7
Expand All @@ -131,7 +118,6 @@ extern "C" {
#ifndef TIMER_SERVO
#define TIMER_SERVO TIM2
#endif

// UART Definitions
// Define here Serial instance number to map on Serial generic name
#define SERIAL_UART_INSTANCE 1
Expand All @@ -140,7 +126,7 @@ extern "C" {
#define PIN_SERIAL_RX PA10
#define PIN_SERIAL_TX PA9

// Extra HAL modules
/* Extra HAL modules */
#if defined(STM32F103xE) || defined(STM32F103xG)
#define HAL_DAC_MODULE_ENABLED
#endif
Expand Down
17 changes: 17 additions & 0 deletions buildroot/tests/STM32F103RC_btt_USB_stm32
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# Build tests for STM32F103RC BigTreeTech (SKR Mini v1.1)
#

# exit on first failure
set -e

#
# Build with the default configurations
#
restore_configs
opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_V1_1 SERIAL_PORT 1 SERIAL_PORT_2 -1
exec_test $1 $2 "BigTreeTech SKR Mini v1.1 - Basic Configuration" "$3"

# clean up
restore_configs
20 changes: 20 additions & 0 deletions buildroot/tests/STM32F103RC_btt_stm32
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
# Build tests for STM32F103RC BigTreeTech (SKR Mini E3)
#

# exit on first failure
set -e

#
# Build with the default configurations
#
restore_configs
opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_E3_V1_0 SERIAL_PORT 1 SERIAL_PORT_2 -1 \
X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209
opt_enable PINS_DEBUGGING Z_IDLE_HEIGHT

exec_test $1 $2 "BigTreeTech SKR Mini E3 1.0 - Basic Config with TMC2209 HW Serial" "$3"

# clean up
restore_configs
Loading

0 comments on commit b4c128c

Please sign in to comment.