diff --git a/variants/board_template/PeripheralPins.c b/variants/board_template/PeripheralPins.c new file mode 100644 index 0000000000..28c05001dd --- /dev/null +++ b/variants/board_template/PeripheralPins.c @@ -0,0 +1,25 @@ +/* + * This file could be generated thanks a python script: genpinmap_arduino.py + * + * This script allows to generate the pins mapping of a STM32 MCU. + * + * It is included with the STM32Tools package install with this core. + * Go to: + * \packages\STM32\tools\STM32Tools\\tools\src\genpinmap\ + * Tips: is displayed in the "Preferences" dialog of the Arduino IDE. + * + * This script is able to generate the PeripheralPins.c using STM32 + * xml file description in Cube MX. + * After file generation, review it carefully. + * Comment a line if the pin is generated several times for the same IP + * or if the pin should not be used + * (overlaid with some HW on the board, for instance) + * + * USAGE: genpinmap_arduino.py + * + * is the name of the board as it will be named in variant folder + * is the STM32 file description in Cube MX + * + * !!This xml file contains non alpha characters in its name, you should call it with quotes + * + */ \ No newline at end of file diff --git a/variants/board_template/ldscript.ld b/variants/board_template/ldscript.ld new file mode 100644 index 0000000000..d7c85e9c40 --- /dev/null +++ b/variants/board_template/ldscript.ld @@ -0,0 +1,26 @@ +/* +***************************************************************************** +** +** File : ldscript.ld +** +** Abstract : Linker script for STM32 Device +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used. +** +** Target : STMicroelectronics STM32 +** +** +***************************************************************************** +*/ +/* Copy here linker script for the new STM32 Device + * or + * replace this file by the new one with the same file name + * It could be get thanks STM32CubeMX after code generation for Toolchain/IDE: 'SW4STM32', + * ldscript will be availabe in the root folder (STM32YYxxxxxx_FLASH.ld) + * or + * copied from a STM32CubeYY project examples + * where 'YY' could be F0, F1, F2, F3, F4, F7, L0, L1, L4) + */ diff --git a/variants/board_template/readme.txt b/variants/board_template/readme.txt new file mode 100644 index 0000000000..519e6b0e10 --- /dev/null +++ b/variants/board_template/readme.txt @@ -0,0 +1,2 @@ +See Wiki: +https://github.com/stm32duino/wiki/wiki/Add-a-new-variant-(board) \ No newline at end of file diff --git a/variants/board_template/stm32yyxx_hal_conf.h b/variants/board_template/stm32yyxx_hal_conf.h new file mode 100644 index 0000000000..e50097fbe9 --- /dev/null +++ b/variants/board_template/stm32yyxx_hal_conf.h @@ -0,0 +1,18 @@ +/* + * Copy the STM32 HAL config file from the targeted MCU Series HAL + * from ../../system/Drivers/STM32YYxx_HAL_Driver/Inc/stm32yyxx_hal_conf_template.h + * to + * stm32yyxx_hal_conf.h + * where 'yy' could be f0, f1, f2, f3, f4, f7, l0, l1, l4) + * + * Example for a STM32 F4 based board: + * cp ../../system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_conf_template.h stm32f4xx_hal_conf.h + * + * Then edit it in order to: + * - Disable undesired HAL modules by commenting line like: + * "#define HAL_XXX_MODULE_ENABLED" + * where "XXX" is the feature (ETH, I2S,...) + * - Adjust HSE/HSI Values adaptation if needed + * - Update any other configurations + * + */ \ No newline at end of file diff --git a/variants/board_template/variant.cpp b/variants/board_template/variant.cpp new file mode 100644 index 0000000000..d5a2e010ae --- /dev/null +++ b/variants/board_template/variant.cpp @@ -0,0 +1,194 @@ +/* + ******************************************************************************* + * Copyright (c) 2017, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ + +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Pin number +// This array allows to wrap Arduino pin number(Dx or x) +// to STM32 PinName (PYx) +const PinName digitalPin[] = { +//PYx, //Dx + P, //D0 + P, //D1 + P, //D2 + P, //D3 + P, //D4 + P, //D5 + P, //D6 + P, //D7 + P, //D8 + P, //D9 + P, //D10 + P, //D11 + P, //D12 + P, //D13 + P, //D14 + P, //D15 + P, //D16 + P, //D17 + P, //D18 + P, //D19 + P, //D20 + P, //D21 + P, //D22 + P, //D23 + P, //D24 + P, //D25 + P, //D26 + P, //D27 + P, //D28 + P, //D29 + P, //D30 + P, //D31 + P, //D32 + P, //D33 + P, //D34 + P, //D35 + P, //D36 + P, //D37 + P, //D38 + P, //D39 + P, //D40 + P, //D41 + P, //D42 + P, //D43 + P, //D44 + P, //D45 + P, //D46 + P, //D47 + P, //D48 + P, //D49 + P, //D50 + P, //D51 + P, //D52 + P, //D53 + P, //D54 + P, //D55 + P, //D56 + P, //D57 + P, //D58 + P, //D59 + P, //D60 + P, //D61 + P, //D62 + P, //D63 + P, //D64 + P, //D65 + P, //D66 + P, //D67 + P, //D68 + P, //D69 + P, //D70 + P, //D71 + P, //D72 + P, //D73 + P, //D74 + P, //D75 + P, //D76 + P, //D77 + P, //D78/A0 + P, //D79/A1 + P, //D80/A2 + P, //D81/A3 + P, //D82/A4 + P, //D83/A5 + P, //D84/A6 + P, //D85/A7 + P, //D86/A8 + P, //D87/A9 + // Duplicated pins in order to be aligned with PinMap_ADC + P, //D88/A10 = D + P, //D89/A11 = D + P, //D90/A12 = D + P, //D91/A13 = D + P, //D92/A14 = D + P, //D93/A15 = D + P, //D94/A16 = D + P //D95/A17 = D +}; + +#ifdef __cplusplus +} +#endif + +/* + * UART objects + */ +// Replace PYx_Rx and PYx_Tx by UART_RX and UART_TX pin names +HardwareSerial Serial(PYx_Rx, PYx_Tx); // Connected to ST-Link + +void serialEvent() __attribute__((weak)); +void serialEvent() { } + +// Define as many Serial instance as desired +// Replace 'SerialX' by the desired name +//#ifdef ENABLE_SERIALX +//HardwareSerial SerialX(PYx_Rx, PYx_Tx); +// +//void serialEventx() __attribute__((weak)); +//void serialEventx() { } +//#endif + +void serialEventRun(void) +{ + if (Serial.available()) serialEvent(); +//#ifdef ENABLE_SERIALX +// if (SerialX.available()) serialEventX(); +//#endif +} + +// ---------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief System Clock Configuration + * @param None + * @retval None + */ +WEAK void SystemClock_Config(void) +{ +// Here copy the desired System Clock Configuration +// It could be generated thanks STM32CubeMX after code generation for Toolchain/IDE: 'SW4STM32', +// available in src/main.c +// or +// copied from a STM32CubeYY project examples +// where 'YY' could be F0, F1, F2, F3, F4, F7, L0, L1, L4 +} + +#ifdef __cplusplus +} +#endif diff --git a/variants/board_template/variant.h b/variants/board_template/variant.h new file mode 100644 index 0000000000..9c95621ff4 --- /dev/null +++ b/variants/board_template/variant.h @@ -0,0 +1,172 @@ +/* + ******************************************************************************* + * Copyright (c) 2017, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ + +#ifndef _VARIANT_ARDUINO_STM32_ +#define _VARIANT_ARDUINO_STM32_ + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "Arduino.h" + +#ifdef __cplusplus +extern "C"{ +#endif // __cplusplus + +/*---------------------------------------------------------------------------- + * Pins + *----------------------------------------------------------------------------*/ +#include "PeripheralPins.h" + +extern const PinName digitalPin[]; + +// Enum defining Arduino style alias for digital pin number --> Dx +// !!! +// !!! It must be aligned with the number of PinName +// !!! defined in digitalPin[] array in variant.cpp +// !!! +enum { + D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, + D10, D11, D12, D13, D14, D15, D16, D17, D18, D19, + D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, + D30, D31, D32, D33, D34, D35, D36, D37, D38, D39, + D40, D41, D42, D43, D44, D45, D46, D47, D48, D49, + D50, D51, D52, D53, D54, D55, D56, D57, D58, D59, + D60, D61, D62, D63, D64, D65, D66, D67, D68, D69, + D70, D71, D72, D73, D74, D75, D76, D77, D78, D79, + D80, D81, D82, D83, D84, D85, D86, D87, D88, D89, + D90, D91, D92, D93, D94, D95, + DEND +}; +// Enum defining Arduino style alias for analog pin number --> Ax +// !!! +// !!! It must be aligned with the number of analog PinName +// !!! defined in digitalPin[] array in variant.cpp +// !!! +enum { + A_START_AFTER = D77, // pin number preceding A0 + A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, + A10, A11, A12, A13, A14, A15, A16, A17, + AEND +}; + +//ADC resolution is 12bits +#define ADC_RESOLUTION 12 +#define DACC_RESOLUTION 12 + +//PWR resolution +#define PWM_RESOLUTION 8 +#define PWM_FREQUENCY 1000 +#define PWM_MAX_DUTY_CYCLE 255 + +//On-board LED pin number +#define LED_BUILTIN Dx +#define LED_GREEN LED_BUILTIN + +//On-board user button +#define USER_BTN Dx + + +//SPI definitions +//define 16 channels. As many channel as digital IOs +#define SPI_CHANNELS_NUM 16 + +//default chip salect pin +#define BOARD_SPI_DEFAULT_SS 10 // Default for Arduino connector compatibility + +//In case SPI CS channel is not used we define a default one +#define BOARD_SPI_OWN_SS SPI_CHANNELS_NUM + +#define SS BOARD_SPI_DEFAULT_SS +#define MOSI 11 // Default for Arduino connector compatibility +#define MISO 12 // Default for Arduino connector compatibility +#define SCLK 13 // Default for Arduino connector compatibility +#define SCK SCLK + +//I2C Definitions +#define SDA 14 // Default for Arduino connector compatibility +#define SCL 15 // Default for Arduino connector compatibility + +//Timer Definitions +//Do not use timer used by PWM pins when possible. See PinMap_PWM in PeripheralPins.c +#define TIMER_TONE TIMx +#define TIMER_UART_EMULATED TIMx + +//Do not use basic timer: OC is required +#define TIMER_SERVO TIMx //TODO: advanced-control timers don't work + +#define DEBUG_UART ((USART_TypeDef *) U(S)ARTX) // ex: USART3 + +// UART Emulation (uncomment if needed, required TIM1) +//#define UART_EMUL_RX PYxx // PinName used for RX +//#define UART_EMUL_TX PYxx // PinName used for TX + +// Serial Pin Firmata +#define PIN_SERIAL_RX Dx +#define PIN_SERIAL_TX Dx +// Define as many PIN_SERIALX than desired +//#define PIN_SERIAL1_RX Dx +//#define PIN_SERIAL1_TX Dx +//... + +#ifdef __cplusplus +} // extern "C" +#endif +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +// declare here as many UART objects than defined in variant.cpp +extern HardwareSerial Serial; +//extern HardwareSerial SerialX; +//... + +// These serial port names are intended to allow libraries and architecture-neutral +// sketches to automatically default to the correct port name for a particular type +// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, +// the first hardware serial port whose RX/TX pins are not dedicated to another use. +// +// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor +// +// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial +// +// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library +// +// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. +// +// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX +// pins are NOT connected to anything by default. +#define SERIAL_PORT_MONITOR Serial +#define SERIAL_PORT_HARDWARE Serial +#endif + +#endif /* _VARIANT_ARDUINO_STM32_ */