Skip to content

Commit

Permalink
Add support for Fysetc S6
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikssn committed Apr 7, 2022
1 parent 1c8cfac commit bddf409
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ build

.vscode/settings.json
.vscode/c_cpp_properties.json
*.code-workspace
2 changes: 2 additions & 0 deletions Inc/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
#include "btt_skr_2.0_map.h"
#elif defined(BOARD_BTT_SKR_20_DAC)
#include "btt_skr_2.0_dac_map.h"
#elif defined(BOARD_FYSETC_S6)
#include "fysetc_s6_map.h"
#elif defined(BOARD_PROTONEER_3XX)
#include "protoneer_3.xx_map.h"
#elif defined(BOARD_GENERIC_UNO)
Expand Down
123 changes: 123 additions & 0 deletions Inc/fysetc_s6_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
fysetc_s6_map.h - driver code for STM32F407 ARM processors
Part of grblHAL
Grbl 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.
Grbl 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 Grbl. If not, see <http://www.gnu.org/licenses/>.
*/

#if N_ABC_MOTORS > 3
#error "Axis configuration is not supported!"
#endif

#if !defined(STM32F446xx) || HSE_VALUE != 12000000
#error "This board has STM32F446 processor with a 12MHz crystal, select a corresponding build!"
#endif

#define BOARD_NAME "Fysetc S6 V2.0"

#define I2C_ENABLE 1
#define I2C_PORT 1 // PB8 / PB9
// #define I2C1_ALT_PINMAP // GPIOB, SCL_PIN = 6, SDA_PIN = 7
#define EEPROM_ENABLE 1 // 2K single byte addressing

// Define step pulse output pins.
#define X_STEP_PORT GPIOE
#define X_STEP_PIN 11
#define Y_STEP_PORT GPIOD
#define Y_STEP_PIN 8
#define Z_STEP_PORT GPIOD
#define Z_STEP_PIN 14
#define STEP_OUTMODE GPIO_BITBAND
//#define STEP_PINMODE PINMODE_OD // Uncomment for open drain outputs

// Define step direction output pins.
#define X_DIRECTION_PORT GPIOE
#define X_DIRECTION_PIN 10
#define Y_DIRECTION_PORT GPIOB
#define Y_DIRECTION_PIN 12
#define Z_DIRECTION_PORT GPIOD
#define Z_DIRECTION_PIN 13
#define DIRECTION_OUTMODE GPIO_BITBAND
//#define DIRECTION_PINMODE PINMODE_OD // Uncomment for open drain outputs

// Define stepper driver enable/disable output pin.
#define X_ENABLE_PORT GPIOE
#define X_ENABLE_PIN 9
#define Y_ENABLE_PORT GPIOD
#define Y_ENABLE_PIN 9
#define Z_ENABLE_PORT GPIOD
#define Z_ENABLE_PIN 15
//#define STEPPERS_ENABLE_PINMODE PINMODE_OD // Uncomment for open drain outputs

// Define homing/hard limit switch input pins.
#define X_LIMIT_PORT GPIOB
#define X_LIMIT_PIN 14 // X- Limit
#define Y_LIMIT_PORT GPIOB
#define Y_LIMIT_PIN 13 // Y- Limit
#define Z_LIMIT_PORT GPIOA
#define Z_LIMIT_PIN 0 // Z- Limit
#define LIMIT_INMODE GPIO_BITBAND

// Define spindle enable and spindle direction output pins.
#define SPINDLE_ENABLE_PORT GPIOB
#define SPINDLE_ENABLE_PIN 1 // FAN1
#define SPINDLE_DIRECTION_PORT GPIOB
#define SPINDLE_DIRECTION_PIN 2 // FAN2

// Define spindle PWM output pin.
#define SPINDLE_PWM_PORT_BASE GPIOB_BASE
#define SPINDLE_PWM_PIN 0 // FAN0

// Define flood and mist coolant enable output pins.
#define COOLANT_FLOOD_PORT GPIOB
#define COOLANT_FLOOD_PIN 1 // HEAT0
#define COOLANT_MIST_PORT GPIOD
#define COOLANT_MIST_PIN 14 // HEAT1

// Define user-control controls (cycle start, reset, feed hold) input pins.
#define RESET_PORT GPIOA
#define RESET_PIN 1 // X+ Limit
#define FEED_HOLD_PORT GPIOA
#define FEED_HOLD_PIN 2 // Y+ Limit
#define CYCLE_START_PORT GPIOA
#define CYCLE_START_PIN 3 // Z+ Limit

#if SAFETY_DOOR_ENABLE
//#define SAFETY_DOOR_PORT GPIOG
//#define SAFETY_DOOR_PIN 6 // EXP1 PG4
#endif
#define CONTROL_INMODE GPIO_BITBAND

// Define probe switch input pin.
#define PROBE_PORT GPIOA
#define PROBE_PIN 1 // BLTouch PA1

#if SDCARD_ENABLE
#define SD_CS_PORT GPIOA
#define SD_CS_PIN 4
#define SPI_PORT 1 // GPIOA, SCK_PIN = 5, MISO_PIN = 6, MOSI_PIN = 7 (EXP2 Header)
#endif

#if TRINAMIC_UART_ENABLE

#define MOTOR_UARTX_PORT GPIOE
#define MOTOR_UARTX_PIN 8
#define MOTOR_UARTY_PORT GPIOC
#define MOTOR_UARTY_PIN 4
#define MOTOR_UARTZ_PORT GPIOD
#define MOTOR_UARTZ_PIN 12

#endif

1 change: 1 addition & 0 deletions Inc/my_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//#define BOARD_BTT_SKR_PRO_1_2 // F407 based 3D Printer board
//#define BOARD_BTT_SKR_20 // F407 based 3D Printer board
//#define BOARD_BTT_SKR_20_DAC // F407 based 3D Printer board, uses analog output (DAC) for spindle speed control
//#define BOARD_FYSETC_S6 // F446 based 3D Printer board
//#define BOARD_MY_MACHINE // Add my_machine_map.h before enabling this!

// WARNING: BOARD_BTT_SKR_20 may fry your Trinamic drivers due to bad hardware design.
Expand Down
180 changes: 180 additions & 0 deletions STM32F446RETX_NO_BL_FLASH.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/**
******************************************************************************
* @file LinkerScript.ld
* @author Auto-generated by STM32CubeIDE
* Abstract : Linker script for NUCLEO-F446RE Board embedding STM32F446RETx Device from stm32f4 series
* 512Kbytes FLASH
* 128Kbytes RAM
*
* Set heap size, stack size and stack location according
* to application requirements.
*
* Set memory bank area and size if external memory is used
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x2000 ; /* required amount of heap */
_Min_Stack_Size = 0x400 ; /* required amount of stack */

/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K - 128K
EEPROM_EMUL(xrw) : ORIGIN = 0x8060000, LENGTH = 128K
}

_FLASH_VectorTable = ORIGIN(FLASH);
_EEPROM_Emul_Start = ORIGIN(EEPROM_EMUL);
_EEPROM_Emul_Sector = 11;

/* Sections */
SECTIONS
{
/* The startup code into "FLASH" Rom type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH

/* The program code and other data into "FLASH" Rom type memory */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)

KEEP (*(.init))
KEEP (*(.fini))

. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH

/* Constant data into "FLASH" Rom type memory */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH

.ARM.extab : {
. = ALIGN(4);
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(4);
} >FLASH

.ARM : {
. = ALIGN(4);
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
. = ALIGN(4);
} >FLASH

.preinit_array :
{
. = ALIGN(4);
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
} >FLASH

.init_array :
{
. = ALIGN(4);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
} >FLASH

.fini_array :
{
. = ALIGN(4);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
} >FLASH

/* Used by the startup to initialize data */
_sidata = LOADADDR(.data);

/* Initialized data sections into "RAM" Ram type memory */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */

. = ALIGN(4);
_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 */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)

. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM

/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM

/* Remove information from the compiler libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}

.ARM.attributes 0 : { *(.ARM.attributes) }
}
17 changes: 17 additions & 0 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ static void SystemClock_Config(void)
#define APB1CLKDIV RCC_HCLK_DIV4
#define APB2CLKDIV RCC_HCLK_DIV2

#elif defined(BOARD_FYSETC_S6)

/** Configure the main internal regulator output voltage */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 12; // Input clock divider (12MHz crystal) = Base clock 1MHz
RCC_OscInitStruct.PLL.PLLN = 336; // Main clock multiplier
RCC_OscInitStruct.PLL.PLLP = 2; // Main clock divider = Main clock 168MHz
RCC_OscInitStruct.PLL.PLLQ = 7; // Special peripheral (USB) clock divider (relative to main clock multiplier) = USB clock 48MHz
RCC_OscInitStruct.PLL.PLLR = 2;

#define FLASH_LATENCY FLASH_LATENCY_5

#elif defined(STM32F411xE)

/** Configure the main internal regulator output voltage */
Expand Down
31 changes: 31 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,37 @@ lib_extra_dirs = ${common.lib_extra_dirs}
# With the default boot loader, you must deploy new firmware by copying
# .pio/build/<env name>/firmware.bin (produced by `pio run`) to the SD card.

[env:fysetc_s6]
board = fysetc_s6
board_build.ldscript = STM32F446RETX_NO_BL_FLASH.ld
build_flags = ${common.build_flags}
# See Inc/my_machine.h for options
-D BOARD_FYSETC_S6=
# 12MHz crystal
-D HSE_VALUE=12000000
-D USB_SERIAL_CDC=1
lib_deps = ${common.lib_deps}
eeprom
lib_extra_dirs = ${common.lib_extra_dirs}
upload_protocol = dfu

[env:fysetc_s6_tmc2209]
board = fysetc_s6
board_build.ldscript = STM32F446RETX_NO_BL_FLASH.ld
build_flags = ${common.build_flags}
# See Inc/my_machine.h for options
-D BOARD_FYSETC_S6=
# 12MHz crystal
-D HSE_VALUE=12000000
-D USB_SERIAL_CDC=1
# TMC2209 stepper drivers
-D TRINAMIC_ENABLE=2209
lib_deps = ${common.lib_deps}
eeprom
trinamic
lib_extra_dirs = ${common.lib_extra_dirs}
upload_protocol = dfu

[env:nucleo_f411re_morpho_cnc]
board = nucleo_f411re
board_build.ldscript = STM32F411CEUX_FLASH.ld
Expand Down

0 comments on commit bddf409

Please sign in to comment.