Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef STM32F7xx

#ifdef ARDUINO_ARCH_STM32

// --------------------------------------------------------------------------
// Includes
// --------------------------------------------------------------------------

#include "HAL.h"
#include "stm32f7xx_ll_pwr.h"

#if ENABLED(EEPROM_EMULATED_WITH_SRAM)
#if STM32F7xx
#include "stm32f7xx_ll_pwr.h"
#else
#error "EEPROM_EMULATED_WITH_SRAM is currently only supported for STM32F7xx"
#endif
#endif // EEPROM_EMULATED_WITH_SRAM

// --------------------------------------------------------------------------
// Externals
Expand Down Expand Up @@ -103,30 +111,6 @@ extern "C" {
extern unsigned int _ebss; // end of bss section
}

// return free memory between end of heap (or end bss) and whatever is current

/*
#include "wirish/syscalls.c"
//extern caddr_t _sbrk(int incr);
#ifndef CONFIG_HEAP_END
extern char _lm_heap_end;
#define CONFIG_HEAP_END ((caddr_t)&_lm_heap_end)
#endif

extern "C" {
static int freeMemory() {
char top = 't';
return &top - reinterpret_cast<char*>(sbrk(0));
}
int freeMemory() {
int free_memory;
int heap_end = (int)_sbrk(0);
free_memory = ((int)&free_memory) - ((int)heap_end);
return free_memory;
}
}
*/

// --------------------------------------------------------------------------
// ADC
// --------------------------------------------------------------------------
Expand All @@ -139,4 +123,4 @@ uint16_t HAL_adc_get_result(void) {
return HAL_adc_result;
}

#endif // STM32F7xx
#endif // ARDUINO_ARCH_STM32
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,21 @@

#include "Arduino.h"

//#ifdef USBCON
// #include <USBSerial.h>
//#endif
#ifdef USBCON
#include <USBSerial.h>
#endif

#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
#include "fastio_STM32F7.h"
#include "watchdog_STM32F7.h"
#include "fastio_STM32.h"
#include "watchdog_STM32.h"

#include "HAL_timers_STM32F7.h"
#include "HAL_timers_STM32.h"

// --------------------------------------------------------------------------
// Defines
// --------------------------------------------------------------------------

//Serial override
//extern HalSerial usb_serial;

#if SERIAL_PORT == 0
#error "Serial port 0 does not exist"
#endif
Expand All @@ -63,7 +60,7 @@
#error "SERIAL_PORT must be from -1 to 6"
#endif
#if SERIAL_PORT == -1
#define MYSERIAL0 Serial0 // TODO Once CDC is supported
#define MYSERIAL0 SerialUSB
#elif SERIAL_PORT == 1
#define MYSERIAL0 Serial1
#elif SERIAL_PORT == 2
Expand Down Expand Up @@ -178,22 +175,8 @@ uint8_t HAL_get_reset_source (void);

void _delay_ms(const int delay);

/*
extern "C" {
int freeMemory(void);
}
*/

extern "C" char* _sbrk(int incr);

/*
static int freeMemory() {
volatile int top;
top = (int)((char*)&top - reinterpret_cast<char*>(_sbrk(0)));
return top;
}
*/

static int freeMemory() {
volatile char top;
return &top - reinterpret_cast<char*>(_sbrk(0));
Expand All @@ -211,7 +194,6 @@ uint8_t spiRec(uint32_t chan);
// EEPROM

/**
* TODO: Write all this eeprom stuff. Can emulate eeprom in flash as last resort.
* Wire library should work for i2c eeproms.
*/
void eeprom_write_byte(unsigned char *pos, unsigned char value);
Expand All @@ -233,20 +215,6 @@ void HAL_adc_start_conversion(const uint8_t adc_pin);

uint16_t HAL_adc_get_result(void);

/* Todo: Confirm none of this is needed.
uint16_t HAL_getAdcReading(uint8_t chan);

void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);

uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);

void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);

*/

#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef STM32F7xx
#ifdef ARDUINO_ARCH_STM32

#include "../../inc/MarlinConfig.h"

#if HAS_SERVOS

#include "HAL_Servo_STM32F7.h"
#include "HAL_Servo_STM32.h"

uint8_t servoPin[MAX_SERVOS] = { 0 };

Expand Down Expand Up @@ -54,4 +54,4 @@ void libServo::move(const int value) {
}
#endif // HAS_SERVOS

#endif // STM32F7xx
#endif // ARDUINO_ARCH_STM32
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifdef STM32F7xx
#ifdef ARDUINO_ARCH_STM32

// --------------------------------------------------------------------------
// Includes
Expand Down Expand Up @@ -49,7 +48,7 @@ static SPISettings spiConfig;
// --------------------------------------------------------------------------
// Software SPI
// --------------------------------------------------------------------------
#error "Software SPI not supported for STM32F7. Use hardware SPI."
#error "Software SPI not supported for STM32F7. Use Hardware SPI."

#else

Expand All @@ -70,7 +69,7 @@ static SPISettings spiConfig;
*/
void spiBegin(void) {
#if !PIN_EXISTS(SS)
#error SS_PIN not defined!
#error "SS_PIN not defined!"
#endif

SET_OUTPUT(SS_PIN);
Expand Down Expand Up @@ -157,4 +156,4 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {

#endif // SOFTWARE_SPI

#endif // STM32F7xx
#endif // ARDUINO_ARCH_STM32
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

// TODO Make timer selection configurable

#ifdef STM32F7xx
#ifdef ARDUINO_ARCH_STM32

// --------------------------------------------------------------------------
// Includes
// --------------------------------------------------------------------------

#include "HAL.h"

#include "HAL_timers_STM32F7.h"
#include "HAL_timers_STM32.h"

// --------------------------------------------------------------------------
// Externals
Expand All @@ -41,8 +38,6 @@
// --------------------------------------------------------------------------

#define NUM_HARDWARE_TIMERS 2
#define STEP_TIMER_IRQ_ID TIM2_IRQn
#define TEMP_TIMER_IRQ_ID TIM7_IRQn

//#define PRESCALER 1
// --------------------------------------------------------------------------
Expand Down Expand Up @@ -80,19 +75,19 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
temp_prescaler = TEMP_TIMER_PRESCALE - 1;
switch (timer_num) {
case STEP_TIMER_NUM:
// STEPPER TIMER TIM2 - use a 32bit timer
TimerHandle[timer_num].timer = TIM2;
// STEPPER TIMER - use a 32bit timer if possible
TimerHandle[timer_num].timer = STEP_TIMER_DEV;
TimerHandle[timer_num].irqHandle = Step_Handler;
TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / step_prescaler) / frequency) - 1, step_prescaler);
HAL_NVIC_SetPriority(STEP_TIMER_IRQ_ID, 6, 0);
HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, 6, 0);
break;

case TEMP_TIMER_NUM:
// TEMP TIMER TIM7 - any available 16bit Timer (1 already used for PWM)
TimerHandle[timer_num].timer = TIM7;
// TEMP TIMER - any available 16bit Timer
TimerHandle[timer_num].timer = TEMP_TIMER_DEV;
TimerHandle[timer_num].irqHandle = Temp_Handler;
TimerHandleInit(&TimerHandle[timer_num], (((HAL_TIMER_RATE) / temp_prescaler) / frequency) - 1, temp_prescaler);
HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_ID, 2, 0);
HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, 2, 0);
break;
}
timers_initialised[timer_num] = true;
Expand All @@ -119,4 +114,4 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
return NVIC->ISER[IRQ_Id >> 5] & _BV32(IRQ_Id & 0x1F);
}

#endif STM32F7xx
#endif // ARDUINO_ARCH_STM32
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,78 @@
#define hal_timer_t uint32_t // TODO: One is 16-bit, one 32-bit - does this need to be checked?
#define HAL_TIMER_TYPE_MAX 0xFFFF

#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
#ifdef STM32F0xx

#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()) // frequency of timer peripherals
#define TEMP_TIMER_PRESCALE 666 // prescaler for setting temperature timer, 72Khz
#define STEPPER_TIMER_PRESCALE 24 // prescaler for setting stepper timer, 2Mhz

#define STEP_TIMER 16
#define TEMP_TIMER 17

#elif defined STM32F1xx

#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting temperature timer, 72Khz
#define STEPPER_TIMER_PRESCALE 36 // prescaler for setting stepper timer, 2Mhz.

#define STEP_TIMER 4
#define TEMP_TIMER 2

#elif defined STM32F4xx

#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals
#define TEMP_TIMER_PRESCALE 2333 // prescaler for setting temperature timer, 72Khz
#define STEPPER_TIMER_PRESCALE 84 // prescaler for setting stepper timer, 2Mhz

#define STEP_TIMER 4
#define TEMP_TIMER 5

#elif defined STM32F7xx

#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()/2) // frequency of timer peripherals
#define TEMP_TIMER_PRESCALE 1500 // prescaler for setting temperature timer, 72Khz
#define STEPPER_TIMER_PRESCALE 54 // prescaler for setting stepper timer, 2Mhz.

#define STEP_TIMER 5
#define TEMP_TIMER 7

#if MB(REMRAM_V1)
#define STEP_TIMER 2
#endif

#endif

#define STEP_TIMER_NUM 0 // index of timer to use for stepper
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
#define PULSE_TIMER_NUM STEP_TIMER_NUM

#define TEMP_TIMER_PRESCALE 3000 // prescaler for setting temperature timer, 72Khz
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency

#define STEPPER_TIMER_PRESCALE 108 // prescaler for setting stepper timer, 2Mhz
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs

#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency

#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US

#define __TIMER_DEV(X) TIM##X
#define _TIMER_DEV(X) __TIMER_DEV(X)
#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER)
#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER)

#define __TIMER_CALLBACK(X) TIM##X##_IRQHandler
#define _TIMER_CALLBACK(X) __TIMER_CALLBACK(X)

#define STEP_TIMER_CALLBACK _TIMER_CALLBACK(STEP_TIMER)
#define TEMP_TIMER_CALLBACK _TIMER_CALLBACK(TEMP_TIMER)

#define __TIMER_IRQ_NAME(X) TIM##X##_IRQn
#define _TIMER_IRQ_NAME(X) __TIMER_IRQ_NAME(X)

#define STEP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(STEP_TIMER)
#define TEMP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(TEMP_TIMER)

#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
Expand Down
11 changes: 11 additions & 0 deletions Marlin/src/HAL/HAL_STM32/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Generic STM32 HAL based on the stm32duino core

This HAL is intended to act as the generic STM32 HAL for all STM32 chips (The whole F, H and L family).

Currently it supports:
* STM32F0xx
* STM32F1xx
* STM32F4xx
* STM32F7xx

Targeting the official [Arduino STM32 Core](https://github.com/stm32duino/Arduino_Core_STM32).
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@
#endif // SPINDLE_LASER_ENABLE

#if ENABLED(EMERGENCY_PARSER)
#error "EMERGENCY_PARSER is not yet implemented for STM32F7. Disable EMERGENCY_PARSER to continue."
#error "EMERGENCY_PARSER is not yet implemented for STM32. Disable EMERGENCY_PARSER to continue."
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef STM32F7xx
#ifdef ARDUINO_ARCH_STM32

#include "../../inc/MarlinConfig.h"

Expand Down Expand Up @@ -100,4 +100,4 @@ size_t PersistentStore::capacity() {
}

#endif // EEPROM_SETTINGS
#endif // STM32F7xx
#endif // ARDUINO_ARCH_STM32
1 change: 1 addition & 0 deletions Marlin/src/HAL/HAL_STM32/pinsDebug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#error "Debug pins is not yet supported for STM32!"
Loading