From e19d247a5b019b1e9a78f79525eaf190a43ec839 Mon Sep 17 00:00:00 2001 From: Stanimir Petev Date: Thu, 25 Mar 2021 14:33:58 +0100 Subject: [PATCH] [Variant] Add OLIMEXINO-STM32F3 Supersede #1115 Signed-off-by: Stanimir Petev Co-authored-by: Alexandre Bourdiol --- README.md | 2 + boards.txt | 25 ++ .../STM32F3xx/F303R(B-C)T/generic_clock.c | 67 ++++- variants/STM32F3xx/F303R(B-C)T/ldscript.ld | 179 ++++++++++++ .../F303R(B-C)T/variant_OLIMEXINO_STM32F3.cpp | 136 +++++++++ .../F303R(B-C)T/variant_OLIMEXINO_STM32F3.h | 262 ++++++++++++++++++ 6 files changed, 669 insertions(+), 2 deletions(-) create mode 100644 variants/STM32F3xx/F303R(B-C)T/ldscript.ld create mode 100644 variants/STM32F3xx/F303R(B-C)T/variant_OLIMEXINO_STM32F3.cpp create mode 100644 variants/STM32F3xx/F303R(B-C)T/variant_OLIMEXINO_STM32F3.h diff --git a/README.md b/README.md index cb8e1d10f5..b7d327c08c 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,8 @@ User can add a STM32 based board following this [wiki](https://github.com/stm32d | :green_heart: | STM32F303CC | [RobotDyn Black Pill](https://stm32-base.org/boards/STM32F303CCT6-RobotDyn-Black-Pill) | *1.6.1* | [More info](https://robotdyn.com/catalog/development-boards/stm-boards-and-shields.html) | | :yellow_heart: | STM32F303K6
STM32F303K8 | Generic Board | **2.0.0** | | | :yellow_heart: | STM32F303RD
STM32F303RE | Generic Board | **2.0.0** | | +| :yellow_heart: | STM32F303RB
STM32F303RC | Generic Board | **2.0.0** | | +| :yellow_heart: | STM32F303RC | [OLIMEXINO-STM32F3](https://www.olimex.com/Products/Duino/STM32/OLIMEXINO-STM32F3/) | **2.0.0** | | | :yellow_heart: | STM32F303VBT
STM32F303VCT | Generic Board | **2.0.0** | | | :yellow_heart: | STM32F334K4
STM32F334K6
STM32F334K8 | Generic Board | **2.0.0** | | diff --git a/boards.txt b/boards.txt index 50edbae7a7..d1ca82f7d4 100644 --- a/boards.txt +++ b/boards.txt @@ -1565,6 +1565,15 @@ GenF3.menu.pnum.BLACKPILL_F303CC.build.product_line=STM32F303xC GenF3.menu.pnum.BLACKPILL_F303CC.build.variant_h=variant_{build.board}.h GenF3.menu.pnum.BLACKPILL_F303CC.build.variant=STM32F3xx/F303C(B-C)T +# OLIMEXINO_STM32F3 +GenF3.menu.pnum.OLIMEXINO_STM32F3=OLIMEXINO-STM32F3 +GenF3.menu.pnum.OLIMEXINO_STM32F3.upload.maximum_size=262144 +GenF3.menu.pnum.OLIMEXINO_STM32F3.upload.maximum_data_size=40960 +GenF3.menu.pnum.OLIMEXINO_STM32F3.build.board=OLIMEXINO_STM32F3 +GenF3.menu.pnum.OLIMEXINO_STM32F3.build.product_line=STM32F303xC +GenF3.menu.pnum.OLIMEXINO_STM32F3.build.variant_h=variant_{build.board}.h +GenF3.menu.pnum.OLIMEXINO_STM32F3.build.variant=STM32F3xx/F303R(B-C)T + # Generic F302R6Tx GenF3.menu.pnum.GENERIC_F302R6TX=Generic F302R6Tx GenF3.menu.pnum.GENERIC_F302R6TX.upload.maximum_size=32768 @@ -1613,6 +1622,22 @@ GenF3.menu.pnum.GENERIC_F303K8TX.build.board=GENERIC_F303K8TX GenF3.menu.pnum.GENERIC_F303K8TX.build.product_line=STM32F303x8 GenF3.menu.pnum.GENERIC_F303K8TX.build.variant=STM32F3xx/F303K(6-8)T_F334K(4-6-8)T +# Generic F303RBTx +GenF3.menu.pnum.GENERIC_F303RBTX=Generic F303RBTx +GenF3.menu.pnum.GENERIC_F303RBTX.upload.maximum_size=131072 +GenF3.menu.pnum.GENERIC_F303RBTX.upload.maximum_data_size=32768 +GenF3.menu.pnum.GENERIC_F303RBTX.build.board=GENERIC_F303RBTX +GenF3.menu.pnum.GENERIC_F303RBTX.build.product_line=STM32F303xC +GenF3.menu.pnum.GENERIC_F303RBTX.build.variant=STM32F3xx/F303R(B-C)T + +# Generic F303RCTx +GenF3.menu.pnum.GENERIC_F303RCTX=Generic F303RCTx +GenF3.menu.pnum.GENERIC_F303RCTX.upload.maximum_size=262144 +GenF3.menu.pnum.GENERIC_F303RCTX.upload.maximum_data_size=40960 +GenF3.menu.pnum.GENERIC_F303RCTX.build.board=GENERIC_F303RCTX +GenF3.menu.pnum.GENERIC_F303RCTX.build.product_line=STM32F303xC +GenF3.menu.pnum.GENERIC_F303RCTX.build.variant=STM32F3xx/F303R(B-C)T + # Generic F303RDTx GenF3.menu.pnum.GENERIC_F303RDTX=Generic F303RDTx GenF3.menu.pnum.GENERIC_F303RDTX.upload.maximum_size=393216 diff --git a/variants/STM32F3xx/F303R(B-C)T/generic_clock.c b/variants/STM32F3xx/F303R(B-C)T/generic_clock.c index dc9ffd5f42..076364d1bb 100644 --- a/variants/STM32F3xx/F303R(B-C)T/generic_clock.c +++ b/variants/STM32F3xx/F303R(B-C)T/generic_clock.c @@ -19,9 +19,72 @@ * @retval None */ WEAK void SystemClock_Config(void) +#if defined(USBCON) { - /* SystemClock_Config can be generated by STM32CubeMX */ -#warning "SystemClock_Config() is empty. Default clock at reset is used." + RCC_OscInitTypeDef RCC_OscInitStruct = {}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {}; + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + Error_Handler(); + } + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK + | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { + Error_Handler(); + } + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { + Error_Handler(); + } +} +#else +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {}; + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + Error_Handler(); + } + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK + | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { + Error_Handler(); + } } +#endif /* USBCON */ #endif /* ARDUINO_GENERIC_* */ diff --git a/variants/STM32F3xx/F303R(B-C)T/ldscript.ld b/variants/STM32F3xx/F303R(B-C)T/ldscript.ld new file mode 100644 index 0000000000..335c828f91 --- /dev/null +++ b/variants/STM32F3xx/F303R(B-C)T/ldscript.ld @@ -0,0 +1,179 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32F303RCTx Device from STM32F3 series + * 256Kbytes FLASH + * 8Kbytes CCMRAM + * 40Kbytes 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 + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * 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 = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 8K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE + FLASH (rx) : ORIGIN = 0x8000000 + LD_FLASH_OFFSET, LENGTH = LD_MAX_SIZE - LD_FLASH_OFFSET +} + +/* 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 */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* 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) } +} diff --git a/variants/STM32F3xx/F303R(B-C)T/variant_OLIMEXINO_STM32F3.cpp b/variants/STM32F3xx/F303R(B-C)T/variant_OLIMEXINO_STM32F3.cpp new file mode 100644 index 0000000000..06b71a4010 --- /dev/null +++ b/variants/STM32F3xx/F303R(B-C)T/variant_OLIMEXINO_STM32F3.cpp @@ -0,0 +1,136 @@ +/* + ******************************************************************************* + * Copyright (c) 2018-2021, STMicroelectronics + * All rights reserved. + * + * 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 + * + ******************************************************************************* + */ +#if defined(ARDUINO_OLIMEXINO_STM32F3) + +#include "pins_arduino.h" + +// Pin number +const PinName digitalPin[] = { + PA_3, //D0 - A6 - RX2 + PA_2, //D1 - A7 - TX2 + PA_0, //D2 - A8 + PA_1, //D3 - A9 - LED2 (yellow) + PB_5, //D4 + PB_6, //D5 - TX1 + PA_8, //D6 + PA_9, //D7 - I2C2 SCL + + PA_10, //D8 - I2C2 SDA + PB_7, //D9 - RX1 + PA_4, //D10 - A10 - SS1 + PA_7, //D11 - A11 - MOSI1 + PA_6, //D12 - A12 - MISO1 + PA_5, //D13 - A13 - SCK1, LED1 (green) + PB_8, //D14 - CAN_RX + + PC_0, //D15 - A0 + PC_1, //D16 - A1 + PC_2, //D17 - A2 + PC_3, //D18 - A3 + PC_4, //D19 - A4 + PC_5, //D20 - A5 + + PC_13, //D21 + PC_9, //D22 - Button (not an actual D pin) + + PC_15, //D23 + PB_9, //D24 - CAN_TX + PD_2, //D25 - MMC_CS + PC_10, //D26 + PB_0, //D27 - A14 + PB_1, //D28 - A15 + PB_10, //D29 - TX3 + PB_11, //D30 - RX3 + PB_12, //D31 - A16 - #SS2 + PB_13, //D32 - A17 - SCK2 + PB_14, //D33 - A18 - MISO2 + PB_15, //D34 - A19 - MOSI2 + PC_6, //D35 + PC_7, //D36 + PC_8, //D37 + + PF_4, //D38 - A20 - UEXT_PWR (not actual D pin) + PC_12 //D39 - USB DISC +}; + +// Analog (Ax) pin number array +const uint32_t analogInputPin[] = { + 15, // A0 + 16, // A1 + 17, // A2 + 18, // A3 + 19, // A4 + 20, // A5 + 0, // A6 + 1, // A7 + 2, // A8 + 3, // A9 + 10, // A10 + 11, // A11 + 12, // A12 + 13, // A13 + 27, // A14 + 28, // A15 + 31, // A16 + 32, // A17 + 33, // A18 + 34, // A19 + 38 // A20 +}; + +// ---------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +WEAK void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {}; + + /* Initializes the CPU, AHB and APB busses clocks */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + Error_Handler(); + } + /* Initializes the CPU, AHB and APB busses clocks */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK + | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { + Error_Handler(); + } + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { + Error_Handler(); + } +} + +#ifdef __cplusplus +} +#endif + +#endif /* ARDUINO_OLIMEXINO_STM32F3 */ diff --git a/variants/STM32F3xx/F303R(B-C)T/variant_OLIMEXINO_STM32F3.h b/variants/STM32F3xx/F303R(B-C)T/variant_OLIMEXINO_STM32F3.h new file mode 100644 index 0000000000..d143216d47 --- /dev/null +++ b/variants/STM32F3xx/F303R(B-C)T/variant_OLIMEXINO_STM32F3.h @@ -0,0 +1,262 @@ +/* + ******************************************************************************* + * Copyright (c) 2020-2021, STMicroelectronics + * All rights reserved. + * + * 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 + * + ******************************************************************************* + */ +#pragma once + +/*---------------------------------------------------------------------------- + * STM32 pins number + *----------------------------------------------------------------------------*/ +// Digital connector 1 +#define PA3 PIN_A6 +#define PA2 PIN_A7 +#define PA0 PIN_A8 +#define PA1 PIN_A9 +#define PB5 4 +#define PB6 5 +#define PA8 6 +#define PA9 7 + +// Digital connector 2 +#define PA10 8 +#define PB7 9 +#define PA4 PIN_A10 +#define PA7 PIN_A11 +#define PA6 PIN_A12 +#define PA5 PIN_A13 +#define PB8 14 + +// Analog connector +#define PC0 PIN_A0 +#define PC1 PIN_A1 +#define PC2 PIN_A2 +#define PC3 PIN_A3 +#define PC4 PIN_A4 +#define PC5 PIN_A5 +#define PC13 21 + +// Button +#define PC9 22 + +// GPIO extention +#define PC15 23 +#define PB9 24 +#define PD2 25 +#define PC10 26 +#define PB0 PIN_A14 +#define PB1 PIN_A15 +#define PB10 29 +#define PB11 30 +#define PB12 PIN_A16 +#define PB13 PIN_A17 +#define PB14 PIN_A18 +#define PB15 PIN_A19 +#define PC6 35 +#define PC7 36 +#define PC8 37 + +// UEXT_PWR +#define PF4 PIN_A20 +// USB DISC +#define PC12 39 + +// Alternate pins number +#define PA1_ALT1 (PA1 | ALT1) +#define PA2_ALT1 (PA2 | ALT1) +#define PA3_ALT1 (PA3 | ALT1) +#define PA4_ALT1 (PA4 | ALT1) +#define PA6_ALT1 (PA6 | ALT1) +#define PA7_ALT1 (PA7 | ALT1) +#define PA7_ALT2 (PA7 | ALT2) +#define PA7_ALT3 (PA7 | ALT3) +#define PA9_ALT1 (PA9 | ALT1) +#define PA10_ALT1 (PA10 | ALT1) +#define PA11_ALT1 (PA11 | ALT1) +#define PA11_ALT2 (PA11 | ALT2) +#define PA12_ALT1 (PA12 | ALT1) +#define PA12_ALT2 (PA12 | ALT2) +#define PA13_ALT1 (PA13 | ALT1) +#define PA15_ALT1 (PA15 | ALT1) +#define PB0_ALT1 (PB0 | ALT1) +#define PB0_ALT2 (PB0 | ALT2) +#define PB1_ALT1 (PB1 | ALT1) +#define PB1_ALT2 (PB1 | ALT2) +#define PB3_ALT1 (PB3 | ALT1) +#define PB4_ALT1 (PB4 | ALT1) +#define PB4_ALT2 (PB4 | ALT2) +#define PB5_ALT1 (PB5 | ALT1) +#define PB5_ALT2 (PB5 | ALT2) +#define PB6_ALT1 (PB6 | ALT1) +#define PB6_ALT2 (PB6 | ALT2) +#define PB7_ALT1 (PB7 | ALT1) +#define PB7_ALT2 (PB7 | ALT2) +#define PB8_ALT1 (PB8 | ALT1) +#define PB8_ALT2 (PB8 | ALT2) +#define PB9_ALT1 (PB9 | ALT1) +#define PB9_ALT2 (PB9 | ALT2) +#define PB14_ALT1 (PB14 | ALT1) +#define PB15_ALT1 (PB15 | ALT1) +#define PB15_ALT2 (PB15 | ALT2) +#define PC0_ALT1 (PC0 | ALT1) +#define PC1_ALT1 (PC1 | ALT1) +#define PC2_ALT1 (PC2 | ALT1) +#define PC3_ALT1 (PC3 | ALT1) +#define PC6_ALT1 (PC6 | ALT1) +#define PC7_ALT1 (PC7 | ALT1) +#define PC8_ALT1 (PC8 | ALT1) +#define PC9_ALT1 (PC9 | ALT1) +#define PC10_ALT1 (PC10 | ALT1) +#define PC11_ALT1 (PC11 | ALT1) + +// Alias GPIO1 extention +#define EXT_GPIO1 PC15 +#define EXT_GPIO2 PB9 +#define EXT_GPIO3 PD2 +#define EXT_GPIO4 PC10 +#define EXT_GPIO5 PB0 +#define EXT_GPIO6 PB1 +#define EXT_GPIO7 PB10 +#define EXT_GPIO8 PB11 +#define EXT_GPIO9 PB12 +#define EXT_GPIO10 PB13 +#define EXT_GPIO11 PB14 +#define EXT_GPIO12 PB15 +#define EXT_GPIO13 PC6 +#define EXT_GPIO14 PC7 +#define EXT_GPIO15 PC8 + +// Alias UEXT +#define UEXTPWR PF4 +#define UEXT3 PB10 +#define UEXT4 PB11 +#define UEXT5 PA9 +#define UEXT6 PA10 +#define UEXT7 PA6 +#define UEXT8 PA7 +#define UEXT9 PA5 +#define UEXT10 PB5 + +#define NUM_DIGITAL_PINS 40 +#define NUM_ANALOG_INPUTS 21 + +// On-board LED pin number +#define LED1 PA5 +#define LED_GREEN LED1 +#define LED2 PA1 +#define LED_YELLOW LED2 + +#ifndef LED_BUILTIN + #define LED_BUILTIN LED_GREEN +#endif + +// On-board button pin button +#ifndef USER_BTN + #define USER_BTN PC9 +#endif + +// SPI Definitions +// SPI1 on default Arduino UNO R3 connector (10-13) + +// SPI2 +#define PIN_SPI2_SS PB12 // D31 +#define PIN_SPI2_SCK PB13 // D32 +#define PIN_SPI2_MISO PB14 // D33 +#define PIN_SPI2_MOSI PB15 // D34 + +// SD card SPI2 definitions +// These definitions are used by SD library but could not be used +// as SPI_2 is not instantiated +// Could be reviewed when SPI_INTERFACES_COUNT will be supported +// See https://github.com/stm32duino/Arduino_Core_STM32/issues/705 +// #define SDCARD_SPI SPI_2 +// #define SDCARD_SS_PIN PD2 // D254 +// #define SDCARD_SCK_PIN PIN_SPI2_SCK // D32 +// #define SDCARD_MISO_PIN PIN_SPI2_MISO // D33 +// #define SDCARD_MOSI_PIN PIN_SPI2_MOSI // D34 + +// I2C Definitions +#ifndef PIN_WIRE_SDA + #define PIN_WIRE_SDA PA10 +#endif +#ifndef PIN_WIRE_SCL + #define PIN_WIRE_SCL PA9 +#endif + +// Timer Definitions +// Use TIM6 when possible as servo and tone don't need GPIO output pin +#ifndef TIMER_TONE + #define TIMER_TONE TIM6 +#endif +#ifndef TIMER_SERVO + #define TIMER_SERVO TIM2 +#endif + +// UART Definitions +#ifndef SERIAL_UART_INSTANCE + #define SERIAL_UART_INSTANCE 2 +#endif + +// Default pin used for generic 'Serial' instance +// Mandatory for Firmata +#ifndef PIN_SERIAL_RX + #define PIN_SERIAL_RX PA3 +#endif +#ifndef PIN_SERIAL_TX + #define PIN_SERIAL_TX PA2 +#endif + +#define HAVE_HWSERIAL1 +#define PIN_SERIAL1_TX PB6 // D5 +#define PIN_SERIAL1_RX PB7 // D9 + +#define HAVE_HWSERIAL3 +#define PIN_SERIAL3_TX PB10 // TX GPIO29 +#define PIN_SERIAL3_RX PB11 // RX GPIO30 + +// USB, pull this pin low to enable the USB attach pullup +#define USBD_ATTACH_PIN PC12 +#define USBD_ATTACH_LEVEL LOW + +/* Extra HAL modules */ +#if !defined(HAL_DAC_MODULE_DISABLED) + #define HAL_DAC_MODULE_ENABLED +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#ifdef __cplusplus + // 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. + #ifndef SERIAL_PORT_MONITOR + #define SERIAL_PORT_MONITOR Serial + #endif + #ifndef SERIAL_PORT_HARDWARE + #define SERIAL_PORT_HARDWARE Serial1 + #endif + #ifndef SERIAL_PORT_USBVIRTUAL + #define SERIAL_PORT_USBVIRTUAL SerialUSB + #endif +#endif