2017-09-27 07:30:23 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-27 07:30:23 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
* Copyright (c) 2017 Victor Perez
|
2017-09-27 07:30:23 +02:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-11-04 09:25:55 +01:00
|
|
|
#pragma once
|
2017-09-27 07:30:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fast I/O interfaces for STM32F1
|
|
|
|
* These use GPIO functions instead of Direct Port Manipulation, as on AVR.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libmaple/gpio.h>
|
|
|
|
|
[2.0.x] Multiple updates to STM32F1 HAL (#8733)
* STM32F1 HAL
Adding files for STM32F1 HAL based on libmaple/stm32duino core.
Current persistent_store uses cardreader changes to be sent in separate
commit, but could be changed to use i2c eeprom.
There is another persistent_store implementation that uses the MCU flash memory
to emulate eeprom
Adding readme with some information about the stm32 HAL.
* Switch to Timer4 to avoid a hard reset on STM32F103C6 boards
On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers.
* Add support for EEPROM emulation using Flash
Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled.
* Basic Pins for a malyan M200
This is a work in progress to go hand in hand with the STM32 work.
* Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor.
* Missing file - change HAL_adc_init to actually do something
We have an actual ADC init function now.
* Remove pinmode hack
Remove the pin mode hack that I was using to init PA0.
Updated Readme.md
* Several changes to timers and GPIO
Faster GPIO, and faster timer functions by accesing registers and
libmaple.
Still more changes pending for the Timer's code to skip using the
HardwareTimer class altogether.
Switch all enums to be within #defines
This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order.
* Update Malyan M200 pins
Update Malyan M200 pins with correct fan values.
* Test all pins on actual hardware, update definitions
Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final.
* Update HAL_timers_Stm32f1.cpp
* Add sample configurations for Malyan M200
Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan.
Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer.
readme.md update
* Updates to timers, and some stm32 boards definitiions
* Correct pin toggle macro.
* Remove duplicated Malyan M200 entry from pins.h
* Update configuration_store.cpp
* Formatting, indentation
* Formatting in HAL_Stm32f1.cpp
2017-12-11 06:12:45 +01:00
|
|
|
#define READ(IO) (PIN_MAP[IO].gpio_device->regs->IDR & (1U << PIN_MAP[IO].gpio_bit) ? HIGH : LOW)
|
2019-06-12 13:30:24 +02:00
|
|
|
#define WRITE(IO,V) (PIN_MAP[IO].gpio_device->regs->BSRR = (1U << PIN_MAP[IO].gpio_bit) << ((V) ? 0 : 16))
|
[2.0.x] Multiple updates to STM32F1 HAL (#8733)
* STM32F1 HAL
Adding files for STM32F1 HAL based on libmaple/stm32duino core.
Current persistent_store uses cardreader changes to be sent in separate
commit, but could be changed to use i2c eeprom.
There is another persistent_store implementation that uses the MCU flash memory
to emulate eeprom
Adding readme with some information about the stm32 HAL.
* Switch to Timer4 to avoid a hard reset on STM32F103C6 boards
On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers.
* Add support for EEPROM emulation using Flash
Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled.
* Basic Pins for a malyan M200
This is a work in progress to go hand in hand with the STM32 work.
* Add support for ADC with DMA. This work has exposed a problem with the pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor.
* Missing file - change HAL_adc_init to actually do something
We have an actual ADC init function now.
* Remove pinmode hack
Remove the pin mode hack that I was using to init PA0.
Updated Readme.md
* Several changes to timers and GPIO
Faster GPIO, and faster timer functions by accesing registers and
libmaple.
Still more changes pending for the Timer's code to skip using the
HardwareTimer class altogether.
Switch all enums to be within #defines
This change allows a user to have, for instance, TEMP_4 and TEMP_BED definied but nothing else. The enums which are not defined move "out", allowing the first ones to take the slots in the enum, and since the array is sized on ADC_PIN_COUNT, we always have the right size data and in order.
* Update Malyan M200 pins
Update Malyan M200 pins with correct fan values.
* Test all pins on actual hardware, update definitions
Some of the pin definitions were from knowlege base/pdfs. Now they've been tested against actual hardware. This should be very close to final.
* Update HAL_timers_Stm32f1.cpp
* Add sample configurations for Malyan M200
Add sample configuration for Malyan M200 without bed leveling, and move fan to auto cool E0 since this printer by default has only one fan.
Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer.
readme.md update
* Updates to timers, and some stm32 boards definitiions
* Correct pin toggle macro.
* Remove duplicated Malyan M200 entry from pins.h
* Update configuration_store.cpp
* Formatting, indentation
* Formatting in HAL_Stm32f1.cpp
2017-12-11 06:12:45 +01:00
|
|
|
#define TOGGLE(IO) (PIN_MAP[IO].gpio_device->regs->ODR = PIN_MAP[IO].gpio_device->regs->ODR ^ (1U << PIN_MAP[IO].gpio_bit))
|
2017-09-27 07:30:23 +02:00
|
|
|
|
2018-04-24 20:45:43 +02:00
|
|
|
#define _GET_MODE(IO) gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
|
|
|
|
#define _SET_MODE(IO,M) gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)
|
2017-09-27 07:30:23 +02:00
|
|
|
#define _SET_OUTPUT(IO) _SET_MODE(IO, GPIO_OUTPUT_PP)
|
2019-05-18 23:12:00 +02:00
|
|
|
#define _SET_OUTPUT_OD(IO) _SET_MODE(IO, GPIO_OUTPUT_OD)
|
2017-09-27 07:30:23 +02:00
|
|
|
|
2019-05-18 23:12:00 +02:00
|
|
|
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); } while(0)
|
|
|
|
#define OUT_WRITE_OD(IO,V) do{ _SET_OUTPUT_OD(IO); WRITE(IO,V); } while(0)
|
2018-04-24 20:45:43 +02:00
|
|
|
|
2017-09-27 07:30:23 +02:00
|
|
|
#define SET_INPUT(IO) _SET_MODE(IO, GPIO_INPUT_FLOATING)
|
|
|
|
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, GPIO_INPUT_PU)
|
2019-03-13 02:39:55 +01:00
|
|
|
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
|
2019-03-13 12:51:15 +01:00
|
|
|
#define SET_PWM(IO) pinMode(IO, PWM) // do{ gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, GPIO_AF_OUTPUT_PP); timer_set_mode(PIN_MAP[pin].timer_device, PIN_MAP[pin].timer_channel, TIMER_PWM); }while(0)
|
2019-05-18 23:12:00 +02:00
|
|
|
#define SET_PWM_OD(IO) pinMode(IO, PWM_OPEN_DRAIN)
|
2017-09-27 07:30:23 +02:00
|
|
|
|
2019-03-29 18:21:14 +01:00
|
|
|
#define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
|
2019-06-07 14:11:48 +02:00
|
|
|
#define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD)
|
2017-09-27 07:30:23 +02:00
|
|
|
|
2019-05-22 23:57:19 +02:00
|
|
|
#define PWM_PIN(IO) (PIN_MAP[IO].timer_device != nullptr)
|
2019-03-05 07:41:31 +01:00
|
|
|
|
|
|
|
// digitalRead/Write wrappers
|
|
|
|
#define extDigitalRead(IO) digitalRead(IO)
|
|
|
|
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|
2019-03-13 12:51:15 +01:00
|
|
|
|