From 68cb5f220ea83f1ec2f3776a41371a357a47cec7 Mon Sep 17 00:00:00 2001 From: fpr Date: Thu, 22 Jun 2017 15:29:09 +0200 Subject: [PATCH 01/30] NUCLEO-F103RB added. F1 configuration files imported. Signed-off-by: fpr --- boards.txt | 17 + cores/arduino/stm32/PinAF_STM32F1.h | 101 +++++ cores/arduino/stm32/stm32_def_build.h | 2 + system/STM32F1xx/system_stm32f1xx.c | 448 ++++++++++++++++++++ variants/NUCLEO_F103RB/PeripheralPins.c | 221 ++++++++++ variants/NUCLEO_F103RB/ldscript.ld | 181 ++++++++ variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h | 367 ++++++++++++++++ variants/NUCLEO_F103RB/variant.cpp | 193 +++++++++ variants/NUCLEO_F103RB/variant.h | 175 ++++++++ 9 files changed, 1705 insertions(+) create mode 100644 cores/arduino/stm32/PinAF_STM32F1.h create mode 100644 system/STM32F1xx/system_stm32f1xx.c create mode 100644 variants/NUCLEO_F103RB/PeripheralPins.c create mode 100644 variants/NUCLEO_F103RB/ldscript.ld create mode 100644 variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h create mode 100644 variants/NUCLEO_F103RB/variant.cpp create mode 100644 variants/NUCLEO_F103RB/variant.h diff --git a/boards.txt b/boards.txt index 9ce9fc22b8..afa0c37c37 100644 --- a/boards.txt +++ b/boards.txt @@ -129,6 +129,23 @@ Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.product_line=STM32L476xx Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.variant=NUCLEO_L476RG Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.cmsis_lib_gcc=arm_cortexM4l_math +# NUCLEO_F103RB board + +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB=Nucleo F103RB +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.node=NUCLEO_F103RB,NUCLEO +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_size=131071 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_data_size=20479 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.mcu=cortex-m3 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.f_cpu=64000000L +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.usb_product="NUCLEO-F103RB" +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.board=NUCLEO_F103RB +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.series=STM32F1xx +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.variant=NUCLEO_F103RB +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.cmsis_lib_gcc=arm_cortexM3l_math +#To enable USB add '-DUSBCON' +#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.extra_flags=-DSTM32F103xB {build.usb_flags} + # Upload menu Nucleo_64.menu.upload_method.MassStorageMethod=Mass Storage Nucleo_64.menu.upload_method.MassStorageMethod.upload.protocol= diff --git a/cores/arduino/stm32/PinAF_STM32F1.h b/cores/arduino/stm32/PinAF_STM32F1.h new file mode 100644 index 0000000000..7f78a8a556 --- /dev/null +++ b/cores/arduino/stm32/PinAF_STM32F1.h @@ -0,0 +1,101 @@ +/* + ******************************************************************************* + * 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 _PINAF_STM32F1_H + #define _PINAF_STM32F1_H + + #include "Arduino.h" + + #ifdef __cplusplus + extern "C" { + #endif + + static inline void pin_SetF1AFPin(uint32_t afnum) + { + // Enable AFIO clock + __HAL_RCC_AFIO_CLK_ENABLE(); + + if (afnum > 0) { + switch (afnum) { + case 1: // Remap SPI1 + __HAL_AFIO_REMAP_SPI1_ENABLE(); + break; + case 2: // Remap I2C1 + __HAL_AFIO_REMAP_I2C1_ENABLE(); + break; + case 3: // Remap USART1 + __HAL_AFIO_REMAP_USART1_ENABLE(); + break; + case 4: // Remap USART2 + __HAL_AFIO_REMAP_USART2_ENABLE(); + break; + case 5: // Partial Remap USART3 + __HAL_AFIO_REMAP_USART3_PARTIAL(); + break; + case 6: // Partial Remap TIM1 + __HAL_AFIO_REMAP_TIM1_PARTIAL(); + break; + case 7: // Partial Remap TIM3 + __HAL_AFIO_REMAP_TIM3_PARTIAL(); + break; + case 8: // Full Remap TIM2 + __HAL_AFIO_REMAP_TIM2_ENABLE(); + break; + case 9: // Full Remap TIM3 + __HAL_AFIO_REMAP_TIM3_ENABLE(); + break; + #if defined(AFIO_MAPR_CAN_REMAP_REMAP1) + case 10: // CAN_RX mapped to PB8, CAN_TX mapped to PB9 + __HAL_AFIO_REMAP_CAN1_2(); + break; + case 11: // CAN_RX mapped to PB8, CAN_TX mapped to PB9 + __HAL_AFIO_REMAP_CAN1_3(); + break; + #endif + case 12: // Full Remap USART3 + __HAL_AFIO_REMAP_USART3_ENABLE(); + break; + case 13: // Full Remap TIM1 + __HAL_AFIO_REMAP_TIM1_ENABLE(); + break; + case 14: // Full Remap TIM4 + __HAL_AFIO_REMAP_TIM4_ENABLE(); + break; + default: + break; + } + } + } + + #ifdef __cplusplus + } + #endif + + #endif /* _PINAF_STM32F1_H */ diff --git a/cores/arduino/stm32/stm32_def_build.h b/cores/arduino/stm32/stm32_def_build.h index a591946fee..798ae4cd00 100644 --- a/cores/arduino/stm32/stm32_def_build.h +++ b/cores/arduino/stm32/stm32_def_build.h @@ -40,6 +40,8 @@ #define CMSIS_STARTUP_FILE "startup_stm32l476xx.s" #elif defined(STM32L432xx) #define CMSIS_STARTUP_FILE "startup_stm32l432xx.s" +#elif defined(STM32F103xB) +#define CMSIS_STARTUP_FILE "startup_stm32f103xb.s" #else #error UNKNOWN CHIP #endif diff --git a/system/STM32F1xx/system_stm32f1xx.c b/system/STM32F1xx/system_stm32f1xx.c new file mode 100644 index 0000000000..e78886bc51 --- /dev/null +++ b/system/STM32F1xx/system_stm32f1xx.c @@ -0,0 +1,448 @@ +/** + ****************************************************************************** + * @file system_stm32f1xx.c + * @author MCD Application Team + * @version V4.1.0 + * @date 29-April-2016 + * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. + * + * 1. This file provides two functions and one global variable to be called from + * user application: + * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier + * factors, AHB/APBx prescalers and Flash settings). + * This function is called at startup just after reset and + * before branch to main program. This call is made inside + * the "startup_stm32f1xx_xx.s" file. + * + * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used + * by the user application to setup the SysTick + * timer or configure other parameters. + * + * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must + * be called whenever the core clock is changed + * during program execution. + * + * 2. After each device reset the HSI (8 MHz) is used as system clock source. + * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to + * configure the system clock before to branch to main program. + * + * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on + * the product used), refer to "HSE_VALUE". + * When HSE is used as system clock source, directly or through PLL, and you + * are using different crystal you have to adapt the HSE value to your own + * configuration. + * + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/** @addtogroup CMSIS + * @{ + */ + +/** @addtogroup stm32f1xx_system + * @{ + */ + +/** @addtogroup STM32F1xx_System_Private_Includes + * @{ + */ + +#include "stm32f1xx.h" + +/** + * @} + */ + +/** @addtogroup STM32F1xx_System_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32F1xx_System_Private_Defines + * @{ + */ + +#if !defined (HSE_VALUE) + #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz. + This value can be provided and adapted by the user application. */ +#endif /* HSE_VALUE */ + +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz. + This value can be provided and adapted by the user application. */ +#endif /* HSI_VALUE */ + +/*!< Uncomment the following line if you need to use external SRAM */ +#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) +/* #define DATA_IN_ExtSRAM */ +#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ + +/*!< Uncomment the following line if you need to relocate your vector Table in + Internal SRAM. */ +/* #define VECT_TAB_SRAM */ +#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field. + This value must be a multiple of 0x200. */ + + +/** + * @} + */ + +/** @addtogroup STM32F1xx_System_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32F1xx_System_Private_Variables + * @{ + */ + +/******************************************************************************* +* Clock Definitions +*******************************************************************************/ +#if defined(STM32F100xB) ||defined(STM32F100xE) + uint32_t SystemCoreClock = 24000000; /*!< System Clock Frequency (Core Clock) */ +#else /*!< HSI Selected as System Clock source */ + uint32_t SystemCoreClock = 72000000; /*!< System Clock Frequency (Core Clock) */ +#endif + +const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; +const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; + +/** + * @} + */ + +/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes + * @{ + */ + +#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) +#ifdef DATA_IN_ExtSRAM + static void SystemInit_ExtMemCtl(void); +#endif /* DATA_IN_ExtSRAM */ +#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ + +/** + * @} + */ + +/** @addtogroup STM32F1xx_System_Private_Functions + * @{ + */ + +/** + * @brief Setup the microcontroller system + * Initialize the Embedded Flash Interface, the PLL and update the + * SystemCoreClock variable. + * @note This function should be used only after reset. + * @param None + * @retval None + */ +void SystemInit (void) +{ + /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ + /* Set HSION bit */ + RCC->CR |= (uint32_t)0x00000001; + + /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ +#if !defined(STM32F105xC) && !defined(STM32F107xC) + RCC->CFGR &= (uint32_t)0xF8FF0000; +#else + RCC->CFGR &= (uint32_t)0xF0FF0000; +#endif /* STM32F105xC */ + + /* Reset HSEON, CSSON and PLLON bits */ + RCC->CR &= (uint32_t)0xFEF6FFFF; + + /* Reset HSEBYP bit */ + RCC->CR &= (uint32_t)0xFFFBFFFF; + + /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ + RCC->CFGR &= (uint32_t)0xFF80FFFF; + +#if defined(STM32F105xC) || defined(STM32F107xC) + /* Reset PLL2ON and PLL3ON bits */ + RCC->CR &= (uint32_t)0xEBFFFFFF; + + /* Disable all interrupts and clear pending bits */ + RCC->CIR = 0x00FF0000; + + /* Reset CFGR2 register */ + RCC->CFGR2 = 0x00000000; +#elif defined(STM32F100xB) || defined(STM32F100xE) + /* Disable all interrupts and clear pending bits */ + RCC->CIR = 0x009F0000; + + /* Reset CFGR2 register */ + RCC->CFGR2 = 0x00000000; +#else + /* Disable all interrupts and clear pending bits */ + RCC->CIR = 0x009F0000; +#endif /* STM32F105xC */ + +#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) + #ifdef DATA_IN_ExtSRAM + SystemInit_ExtMemCtl(); + #endif /* DATA_IN_ExtSRAM */ +#endif + +#ifdef VECT_TAB_SRAM + SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ +#else + SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ +#endif +} + +/** + * @brief Update SystemCoreClock variable according to Clock Register Values. + * The SystemCoreClock variable contains the core clock (HCLK), it can + * be used by the user application to setup the SysTick timer or configure + * other parameters. + * + * @note Each time the core clock (HCLK) changes, this function must be called + * to update SystemCoreClock variable value. Otherwise, any configuration + * based on this variable will be incorrect. + * + * @note - The system frequency computed by this function is not the real + * frequency in the chip. It is calculated based on the predefined + * constant and the selected clock source: + * + * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) + * + * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) + * + * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) + * or HSI_VALUE(*) multiplied by the PLL factors. + * + * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value + * 8 MHz) but the real value may vary depending on the variations + * in voltage and temperature. + * + * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value + * 8 MHz or 25 MHz, depending on the product used), user has to ensure + * that HSE_VALUE is same as the real frequency of the crystal used. + * Otherwise, this function may have wrong result. + * + * - The result of this function could be not correct when using fractional + * value for HSE crystal. + * @param None + * @retval None + */ +void SystemCoreClockUpdate (void) +{ + uint32_t tmp = 0, pllmull = 0, pllsource = 0; + +#if defined(STM32F105xC) || defined(STM32F107xC) + uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0; +#endif /* STM32F105xC */ + +#if defined(STM32F100xB) || defined(STM32F100xE) + uint32_t prediv1factor = 0; +#endif /* STM32F100xB or STM32F100xE */ + + /* Get SYSCLK source -------------------------------------------------------*/ + tmp = RCC->CFGR & RCC_CFGR_SWS; + + switch (tmp) + { + case 0x00: /* HSI used as system clock */ + SystemCoreClock = HSI_VALUE; + break; + case 0x04: /* HSE used as system clock */ + SystemCoreClock = HSE_VALUE; + break; + case 0x08: /* PLL used as system clock */ + + /* Get PLL clock source and multiplication factor ----------------------*/ + pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; + pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; + +#if !defined(STM32F105xC) && !defined(STM32F107xC) + pllmull = ( pllmull >> 18) + 2; + + if (pllsource == 0x00) + { + /* HSI oscillator clock divided by 2 selected as PLL clock entry */ + SystemCoreClock = (HSI_VALUE >> 1) * pllmull; + } + else + { + #if defined(STM32F100xB) || defined(STM32F100xE) + prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; + /* HSE oscillator clock selected as PREDIV1 clock entry */ + SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; + #else + /* HSE selected as PLL clock entry */ + if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) + {/* HSE oscillator clock divided by 2 */ + SystemCoreClock = (HSE_VALUE >> 1) * pllmull; + } + else + { + SystemCoreClock = HSE_VALUE * pllmull; + } + #endif + } +#else + pllmull = pllmull >> 18; + + if (pllmull != 0x0D) + { + pllmull += 2; + } + else + { /* PLL multiplication factor = PLL input clock * 6.5 */ + pllmull = 13 / 2; + } + + if (pllsource == 0x00) + { + /* HSI oscillator clock divided by 2 selected as PLL clock entry */ + SystemCoreClock = (HSI_VALUE >> 1) * pllmull; + } + else + {/* PREDIV1 selected as PLL clock entry */ + + /* Get PREDIV1 clock source and division factor */ + prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; + prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; + + if (prediv1source == 0) + { + /* HSE oscillator clock selected as PREDIV1 clock entry */ + SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; + } + else + {/* PLL2 clock selected as PREDIV1 clock entry */ + + /* Get PREDIV2 division factor and PLL2 multiplication factor */ + prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1; + pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2; + SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; + } + } +#endif /* STM32F105xC */ + break; + + default: + SystemCoreClock = HSI_VALUE; + break; + } + + /* Compute HCLK clock frequency ----------------*/ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; +} + +#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) +/** + * @brief Setup the external memory controller. Called in startup_stm32f1xx.s + * before jump to __main + * @param None + * @retval None + */ +#ifdef DATA_IN_ExtSRAM +/** + * @brief Setup the external memory controller. + * Called in startup_stm32f1xx_xx.s/.c before jump to main. + * This function configures the external SRAM mounted on STM3210E-EVAL + * board (STM32 High density devices). This SRAM will be used as program + * data memory (including heap and stack). + * @param None + * @retval None + */ +void SystemInit_ExtMemCtl(void) +{ + __IO uint32_t tmpreg; + /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is + required, then adjust the Register Addresses */ + + /* Enable FSMC clock */ + RCC->AHBENR = 0x00000114; + + /* Delay after an RCC peripheral clock enabling */ + tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); + + /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ + RCC->APB2ENR = 0x000001E0; + + /* Delay after an RCC peripheral clock enabling */ + tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); + + (void)(tmpreg); + +/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ +/*---------------- SRAM Address lines configuration -------------------------*/ +/*---------------- NOE and NWE configuration --------------------------------*/ +/*---------------- NE3 configuration ----------------------------------------*/ +/*---------------- NBL0, NBL1 configuration ---------------------------------*/ + + GPIOD->CRL = 0x44BB44BB; + GPIOD->CRH = 0xBBBBBBBB; + + GPIOE->CRL = 0xB44444BB; + GPIOE->CRH = 0xBBBBBBBB; + + GPIOF->CRL = 0x44BBBBBB; + GPIOF->CRH = 0xBBBB4444; + + GPIOG->CRL = 0x44BBBBBB; + GPIOG->CRH = 0x444B4B44; + +/*---------------- FSMC Configuration ---------------------------------------*/ +/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ + + FSMC_Bank1->BTCR[4] = 0x00001091; + FSMC_Bank1->BTCR[5] = 0x00110212; +} +#endif /* DATA_IN_ExtSRAM */ +#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/NUCLEO_F103RB/PeripheralPins.c b/variants/NUCLEO_F103RB/PeripheralPins.c new file mode 100644 index 0000000000..5b0a13e8ad --- /dev/null +++ b/variants/NUCLEO_F103RB/PeripheralPins.c @@ -0,0 +1,221 @@ +/* + ******************************************************************************* + * Copyright (c) 2016, 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 "Arduino.h" +#include "PeripheralPins.h" + +// ===== +// Note: Commented lines are alternative possibilities which are not used per default. +// If you change them, you will have to know what you do +// ===== + + +//*** ADC *** + +const PinMap PinMap_ADC[] = { + {PA0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 + // {PA0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 + {PA1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 + // {PA1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 + {PA2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 + // {PA2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 + {PA3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 + // {PA3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 + {PA4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 + // {PA4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 + {PA5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 + // {PA5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 + {PA6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 + // {PA6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 + {PA7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 + // {PA7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 + {PB0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 + // {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 + {PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 + // {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 + {PC0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 + // {PC0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 + {PC1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 + // {PC1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 + {PC2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 + // {PC2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 + {PC3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 + // {PC3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 + {PC4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 + // {PC4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 + {PC5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 + // {PC5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 + {NC, NC, 0} +}; + +//*** DAC *** + +const PinMap PinMap_DAC[] = { + {NC, NC, 0} +}; + +//*** I2C *** + +const PinMap PinMap_I2C_SDA[] = { + {PB7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {PB9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 + {PB11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_I2C_SCL[] = { + {PB6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {PB8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 + {PB10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {NC, NC, 0} +}; + +//*** PWM *** + +const PinMap PinMap_PWM[] = { + {PA0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM2_CH1 + {PA1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM2_CH2 + {PA2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM2_CH3 + {PA3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM2_CH4 + {PA6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM3_CH1 + // {PA7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 1, 1)}, // TIM1_CH1N - GPIO_PartialRemap_TIM1 + {PA7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM3_CH2 + {PA8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM1_CH1 + {PA9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM1_CH2 + {PA10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM1_CH3 + {PA11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM1_CH4 + {PA15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 1, 0)}, // TIM2_CH1 - GPIO_FullRemap_TIM2 + // {PB0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 2, 1)}, // TIM1_CH2N - GPIO_PartialRemap_TIM1 + {PB0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM3_CH3 + // {PB1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 3, 1)}, // TIM1_CH3N - GPIO_PartialRemap_TIM1 + {PB1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM3_CH4 + {PB3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 2, 0)}, // TIM2_CH2 - GPIO_FullRemap_TIM2 + {PB4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 1, 0)}, // TIM3_CH1 - GPIO_PartialRemap_TIM3 + {PB5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 2, 0)}, // TIM3_CH2 - GPIO_PartialRemap_TIM3 + {PB6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM4_CH1 + {PB7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM4_CH2 + {PB8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM4_CH3 + {PB9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM4_CH4 + {PB10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 3, 0)}, // TIM2_CH3 - GPIO_FullRemap_TIM2 + {PB11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 4, 0)}, // TIM2_CH4 - GPIO_FullRemap_TIM2 + {PB13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM1_CH1N + {PB14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 1)}, // TIM1_CH2N + {PB15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 1)}, // TIM1_CH3N + {PC6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 1, 0)}, // TIM3_CH1 - GPIO_FullRemap_TIM3 + {PC7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 2, 0)}, // TIM3_CH2 - GPIO_FullRemap_TIM3 + {PC8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 3, 0)}, // TIM3_CH3 - GPIO_FullRemap_TIM3 + {PC9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 4, 0)}, // TIM3_CH4 - GPIO_FullRemap_TIM3 + {NC, NC, 0} +}; + +//*** SERIAL *** + +const PinMap PinMap_UART_TX[] = { + {PA2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 + {PB10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PC10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 5)}, // GPIO_PartialRemap_USART3 + {NC, NC, 0} +}; + +const PinMap PinMap_UART_RX[] = { + {PA3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 + {PB11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PC11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 5)}, // GPIO_PartialRemap_USART3 + {NC, NC, 0} +}; + +const PinMap PinMap_UART_RTS[] = { + {PA1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_UART_CTS[] = { + {PA0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +//*** SPI *** + +const PinMap PinMap_SPI_MOSI[] = { + {PA7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_MISO[] = { + {PA6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_SCLK[] = { + {PA5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_SSEL[] = { + {PA4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +//*** CAN *** + +const PinMap PinMap_CAN_RD[] = { + {PA11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, + {PB8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_RX to PB_9 + {NC, NC, 0} +}; + +const PinMap PinMap_CAN_TD[] = { + {PA12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, + {PB9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_TX to PB_9 + {NC, NC, 0} +}; + +const TimerMap TimerMap_CONFIG[] = { + {TIM1, TIM1_UP_IRQn, 2}, + {TIM2, TIM2_IRQn, 1}, + {TIM3, TIM3_IRQn, 1}, + {TIM4, TIM4_IRQn, 1}, + {NULL, 0, 0} +}; diff --git a/variants/NUCLEO_F103RB/ldscript.ld b/variants/NUCLEO_F103RB/ldscript.ld new file mode 100644 index 0000000000..1608bb0834 --- /dev/null +++ b/variants/NUCLEO_F103RB/ldscript.ld @@ -0,0 +1,181 @@ +/** + ****************************************************************************** + * @file STM32F103RB_FLASH.ld + * @author WI6LABS + * @version V1.0.1 + * @date 21-September-2016 + * @brief Linker script for STM32F103RB Device with + * 128KByte FLASH, 20KByte 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) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + + /* Entry Point */ + ENTRY(Reset_Handler) + + /* Highest address of the user mode stack */ + _estack = 0x20005000; /* end of RAM */ + /* Generate a link error if heap and stack don't fit into RAM */ + _Min_Heap_Size = 0x200; /* required amount of heap */ + _Min_Stack_Size = 0x400; /* required amount of stack */ + + /* Specify the memory areas */ + MEMORY + { + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K + } + + /* Define output sections */ + SECTIONS + { + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .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 goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .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 */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _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 left */ + ._user_heap_stack : + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(4); + } >RAM + + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } + } diff --git a/variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h b/variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h new file mode 100644 index 0000000000..505534a30e --- /dev/null +++ b/variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h @@ -0,0 +1,367 @@ +/** + ****************************************************************************** + * @file stm32f1xx_hal_conf.h + * @author MCD Application Team + * @version V1.0.4 + * @date 29-April-2016 + * @brief HAL configuration template file. + * This file should be copied to the application folder and renamed + * to stm32f1xx_hal_conf.h. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F1xx_HAL_CONF_H +#define __STM32F1xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED +#define HAL_ADC_MODULE_ENABLED +//#define HAL_CAN_MODULE_ENABLED +//#define HAL_CEC_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED +//#define HAL_CRC_MODULE_ENABLED +//#define HAL_DAC_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +//#define HAL_ETH_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_GPIO_MODULE_ENABLED +//#define HAL_HCD_MODULE_ENABLED +#define HAL_I2C_MODULE_ENABLED +//#define HAL_I2S_MODULE_ENABLED +//#define HAL_IRDA_MODULE_ENABLED +//#define HAL_IWDG_MODULE_ENABLED +//#define HAL_NAND_MODULE_ENABLED +//#define HAL_NOR_MODULE_ENABLED +//#define HAL_PCCARD_MODULE_ENABLED +//#define HAL_PCD_MODULE_ENABLED +//#define HAL_PWR_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +//#define HAL_RTC_MODULE_ENABLED +//#define HAL_SD_MODULE_ENABLED +//#define HAL_SMARTCARD_MODULE_ENABLED +#define HAL_SPI_MODULE_ENABLED +//#define HAL_SRAM_MODULE_ENABLED +#define HAL_TIM_MODULE_ENABLED +#define HAL_UART_MODULE_ENABLED +//#define HAL_USART_MODULE_ENABLED +//#define HAL_WWDG_MODULE_ENABLED + +/* ########################## Oscillator Values adaptation ####################*/ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) +#if defined(USE_STM3210C_EVAL) + #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ +#else + #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ +#endif +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ +#endif /* LSE_VALUE */ + + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)0x000F) /*!< tick interrupt priority */ +#define USE_RTOS 0 +#define PREFETCH_ENABLE 1 + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/*#define USE_FULL_ASSERT 1*/ + + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2 +#define MAC_ADDR1 0 +#define MAC_ADDR2 0 +#define MAC_ADDR3 0 +#define MAC_ADDR4 0 +#define MAC_ADDR5 0 + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)8) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848 PHY Address*/ +#define DP83848_PHY_ADDRESS 0x01 +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FF) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF) + +#define PHY_READ_TO ((uint32_t)0x0000FFFF) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFF) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ + +#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */ +#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */ +#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */ + +#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */ +#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */ + +#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */ +#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */ + +#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */ +#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */ + + + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f1xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f1xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f1xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f1xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f1xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f1xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f1xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f1xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f1xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f1xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f1xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f1xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f1xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f1xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f1xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f1xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f1xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f1xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_PCCARD_MODULE_ENABLED + #include "stm32f1xx_hal_pccard.h" +#endif /* HAL_PCCARD_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f1xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f1xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f1xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f1xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f1xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f1xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f1xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f1xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f1xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f1xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f1xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F1xx_HAL_CONF_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/NUCLEO_F103RB/variant.cpp b/variants/NUCLEO_F103RB/variant.cpp new file mode 100644 index 0000000000..d4174856d1 --- /dev/null +++ b/variants/NUCLEO_F103RB/variant.cpp @@ -0,0 +1,193 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Pin number +const PinName digital_arduino[] = { + PA3, //D0 + PA2, //D1 + PA10, //D2 + PB3, //D3 + PB5, //D4 + PB4, //D5 + PB10, //D6 + PA8, //D7 + PA9, //D8 + PC7, //D9 + PB6, //D10 + PA7, //D11 + PA6, //D12 + PA5, //D13 + PB9, //D14 + PB8, //D15 + // ST Morpho + // CN7 Left Side + PC10, //D16 + PC12, //D17 + NC, //D18 - BOOT0 + PA13, //D19 - SWD + PA14, //D20 - SWD + PA15, //D21 + PB7, //D22 + PC13, //D23 + PC14, //D24 + PC15, //D25 + PD0, //D26 + PD1, //D27 + PC2, //D28 + PC3, //D29 + // CN7 Right Side + PC11, //D30 + PD2, //D31 + // CN10 Left Side + PC9, //D32 + // CN10 Right side + PC8, //D33 + PC6, //D34 + PC5, //D35 + PA12, //D36 + PA11, //D37 + PB12, //D38 + PB11, //D39 + PB2, //D40 + PB1, //D41 + PB15, //D42 + PB14, //D43 + PB13, //D44 + PC4, //D45 + PA0, //D46/A0 + PA1, //D47/A1 + PA4, //D48/A2 + PB0, //D49/A3 + PC1, //D50/A4 + PC0, //D51/A5 +}; + +#ifdef __cplusplus +} +#endif + +/* + * UART objects + */ + +// HardwareSerial Serial(PA3, PA2); // Connected to ST-Link +// HardwareSerial Serial1(PA10, PA9); +// +// void serialEvent() __attribute__((weak)); +// void serialEvent() { } +// +// void serialEvent1() __attribute__((weak)); +// void serialEvent1() { } +// +// void serialEventRun(void) +// { +// if (Serial.available()) serialEvent(); +// if (Serial1.available()) serialEvent1(); +// } + +// ---------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +void __libc_init_array(void); + +uint32_t pinNametoPinNumber(PinName p) +{ + uint32_t i = 0; + for(i = 0; i < NUM_DIGITAL_PINS; i++) { + if (digital_arduino[i] == p) + break; + } + return i; +} + +void init( void ) +{ + hw_config_init(); +} + +/** + * @brief System Clock Configuration + * The system Clock is configured as follow : + * System Clock source = PLL (HSI) + * SYSCLK(Hz) = 64000000 + * HCLK(Hz) = 64000000 + * AHB Prescaler = 1 + * APB1 Prescaler = 2 + * APB2 Prescaler = 1 + * PLL_Source = 2 + * PLL_Mul = 16 + * Flash Latency(WS) = 2 + * ADC Prescaler = 8 + * @param None + * @retval None + */ +WEAK void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInit; + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = 16; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + while(1); + } + + 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) + { + while(1); + } + + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; + PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV8; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + while(1); + } + + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); + + HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); + + /* SysTick_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); +} + +#ifdef __cplusplus +} +#endif diff --git a/variants/NUCLEO_F103RB/variant.h b/variants/NUCLEO_F103RB/variant.h new file mode 100644 index 0000000000..ee9cf972e7 --- /dev/null +++ b/variants/NUCLEO_F103RB/variant.h @@ -0,0 +1,175 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_ARDUINO_STM32_ +#define _VARIANT_ARDUINO_STM32_ + +/*---------------------------------------------------------------------------- + * Definitions + *----------------------------------------------------------------------------*/ + +/** Frequency of the board main oscillator */ +//#define VARIANT_MAINOSC 12000000 + +/** Master clock frequency */ +//#define VARIANT_MCK 84000000 + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "Arduino.h" + +#ifdef __cplusplus +extern "C"{ +#endif // __cplusplus + +/** + * Libc porting layers + */ +#if defined ( __GNUC__ ) /* GCC CS3 */ +# include /** RedHat Newlib minimal stub */ +#endif + +/*---------------------------------------------------------------------------- + * Pins + *----------------------------------------------------------------------------*/ +#include "PeripheralPins.h" + +extern const PinName digital_arduino[]; + +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, + DEND +}; + +enum { + A_START_AFTER = D45, + A0, A1, A2, A3, A4, A5, + AEND +}; + +#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap)) +#define MAX_DIGITAL_IOS DEND +#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS +#define NUM_ANALOG_INPUTS (AEND - A0) + +// Convert a digital pin number Dxx to a PinName Pxy +#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC) +// Convert an analog pin number Axx to a PinName Pxy +#define analogToPinName(p) (digitalToPinName(p)) +// Convert an analog pin number to a digital pin number +#define analogToDigital(p) (p) +// Convert a PinName Pxy to a pin number +uint32_t pinNametoPinNumber(PinName p); + +#define digitalPinToPort(p) ( get_GPIO_Port(digitalToPinName(p)) ) +#define digitalPinToBitMask(p) ( STM_GPIO_PIN(digitalToPinName(p)) ) + +//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 13 +#define LED_GREEN LED_BUILTIN + +//On-board user button +#define USER_BTN 23 + +//SPI defintions +//define 16 channels. As many channel as digital IOs +#define SPI_CHANNELS_NUM 16 + +//default chip salect pin +#define BOARD_SPI_DEFAULT_SS 10 + +//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 SS1 4 +#define SS2 7 +#define SS3 8 +#define MOSI 11 +#define MISO 12 +#define SCLK 13 +#define SCK SCLK + +//I2C Definitions +#define SDA 14 +#define SCL 15 + +//Timer Definitions +//Do not use timer used by PWM pins when possible. See PinMap_PWM. +#define TIMER_TONE TIM4 +#define TIMER_UART_EMULATED TIM4 + +//Do not use basic timer: OC is required +#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work + +#define DEBUG_UART ((USART_TypeDef *) USART2) + +// UART Emulation +#define UART_EMUL_RX PB13 +#define UART_EMUL_TX PB14 + +//Enable Firmata +#define STM32 1 + +#ifdef __cplusplus +} // extern "C" +#endif +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern HardwareSerial Serial; +extern HardwareSerial Serial1; + +// 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 Serial1 +#endif + +#endif /* _VARIANT_ARDUINO_STM32_ */ From 5481b4e21de62153f8c901019337c776d75021d6 Mon Sep 17 00:00:00 2001 From: fpr Date: Thu, 22 Jun 2017 17:53:21 +0200 Subject: [PATCH 02/30] uart, analog(ADC, PWM), digital validated. Disconnects debug pins if used but debug pins can be locked if needed. Signed-off-by: fpr --- cores/arduino/stm32/PinAF_STM32F1.h | 154 ++++++++++++++++------------ cores/arduino/stm32/analog.c | 16 ++- cores/arduino/stm32/digital_io.c | 4 + cores/arduino/stm32/uart.c | 12 ++- variants/NUCLEO_F103RB/variant.cpp | 33 +++--- variants/NUCLEO_F103RB/variant.h | 1 + 6 files changed, 139 insertions(+), 81 deletions(-) diff --git a/cores/arduino/stm32/PinAF_STM32F1.h b/cores/arduino/stm32/PinAF_STM32F1.h index 7f78a8a556..28d788de1d 100644 --- a/cores/arduino/stm32/PinAF_STM32F1.h +++ b/cores/arduino/stm32/PinAF_STM32F1.h @@ -28,74 +28,98 @@ ******************************************************************************* */ - #ifndef _PINAF_STM32F1_H - #define _PINAF_STM32F1_H +#ifndef _PINAF_STM32F1_H +#define _PINAF_STM32F1_H - #include "Arduino.h" +#ifdef STM32F1xx - #ifdef __cplusplus - extern "C" { - #endif +#include "Arduino.h" - static inline void pin_SetF1AFPin(uint32_t afnum) - { - // Enable AFIO clock - __HAL_RCC_AFIO_CLK_ENABLE(); +#ifdef __cplusplus +extern "C" { +#endif - if (afnum > 0) { - switch (afnum) { - case 1: // Remap SPI1 - __HAL_AFIO_REMAP_SPI1_ENABLE(); - break; - case 2: // Remap I2C1 - __HAL_AFIO_REMAP_I2C1_ENABLE(); - break; - case 3: // Remap USART1 - __HAL_AFIO_REMAP_USART1_ENABLE(); - break; - case 4: // Remap USART2 - __HAL_AFIO_REMAP_USART2_ENABLE(); - break; - case 5: // Partial Remap USART3 - __HAL_AFIO_REMAP_USART3_PARTIAL(); - break; - case 6: // Partial Remap TIM1 - __HAL_AFIO_REMAP_TIM1_PARTIAL(); - break; - case 7: // Partial Remap TIM3 - __HAL_AFIO_REMAP_TIM3_PARTIAL(); - break; - case 8: // Full Remap TIM2 - __HAL_AFIO_REMAP_TIM2_ENABLE(); - break; - case 9: // Full Remap TIM3 - __HAL_AFIO_REMAP_TIM3_ENABLE(); - break; - #if defined(AFIO_MAPR_CAN_REMAP_REMAP1) - case 10: // CAN_RX mapped to PB8, CAN_TX mapped to PB9 - __HAL_AFIO_REMAP_CAN1_2(); - break; - case 11: // CAN_RX mapped to PB8, CAN_TX mapped to PB9 - __HAL_AFIO_REMAP_CAN1_3(); - break; - #endif - case 12: // Full Remap USART3 - __HAL_AFIO_REMAP_USART3_ENABLE(); - break; - case 13: // Full Remap TIM1 - __HAL_AFIO_REMAP_TIM1_ENABLE(); - break; - case 14: // Full Remap TIM4 - __HAL_AFIO_REMAP_TIM4_ENABLE(); - break; - default: - break; - } - } - } +static inline void pinF1_DisconnectDebug(PinName pin) +{ + /** Enable this flag gives the possibility to use debug pins without any risk + * to lose traces + */ +#ifndef STM32F1_LOCK_DEBUG + // Enable AFIO clock + __HAL_RCC_AFIO_CLK_ENABLE(); - #ifdef __cplusplus - } - #endif + // Disconnect JTAG-DP + SW-DP signals. + // Warning: Need to reconnect under reset + if ((pin == PA13) || (pin == PA14)) { + __HAL_AFIO_REMAP_SWJ_DISABLE(); // JTAG-DP Disabled and SW-DP Disabled + } + if ((pin == PA15) || (pin == PB3) || (pin == PB4)) { + __HAL_AFIO_REMAP_SWJ_NOJTAG(); // JTAG-DP Disabled and SW-DP enabled + } +#endif /* STM32F1_FORCE_DEBUG */ +} - #endif /* _PINAF_STM32F1_H */ +static inline void pin_SetF1AFPin(uint32_t afnum) +{ + // Enable AFIO clock + __HAL_RCC_AFIO_CLK_ENABLE(); + + if (afnum > 0) { + switch (afnum) { + case 1: // Remap SPI1 + __HAL_AFIO_REMAP_SPI1_ENABLE(); + break; + case 2: // Remap I2C1 + __HAL_AFIO_REMAP_I2C1_ENABLE(); + break; + case 3: // Remap USART1 + __HAL_AFIO_REMAP_USART1_ENABLE(); + break; + case 4: // Remap USART2 + __HAL_AFIO_REMAP_USART2_ENABLE(); + break; + case 5: // Partial Remap USART3 + __HAL_AFIO_REMAP_USART3_PARTIAL(); + break; + case 6: // Partial Remap TIM1 + __HAL_AFIO_REMAP_TIM1_PARTIAL(); + break; + case 7: // Partial Remap TIM3 + __HAL_AFIO_REMAP_TIM3_PARTIAL(); + break; + case 8: // Full Remap TIM2 + __HAL_AFIO_REMAP_TIM2_ENABLE(); + break; + case 9: // Full Remap TIM3 + __HAL_AFIO_REMAP_TIM3_ENABLE(); + break; +#if defined(AFIO_MAPR_CAN_REMAP_REMAP1) + case 10: // CAN_RX mapped to PB8, CAN_TX mapped to PB9 + __HAL_AFIO_REMAP_CAN1_2(); + break; + case 11: // CAN_RX mapped to PB8, CAN_TX mapped to PB9 + __HAL_AFIO_REMAP_CAN1_3(); + break; +#endif + case 12: // Full Remap USART3 + __HAL_AFIO_REMAP_USART3_ENABLE(); + break; + case 13: // Full Remap TIM1 + __HAL_AFIO_REMAP_TIM1_ENABLE(); + break; + case 14: // Full Remap TIM4 + __HAL_AFIO_REMAP_TIM4_ENABLE(); + break; + default: + break; + } + } +} + +#ifdef __cplusplus +} +#endif + +#endif /* STM32F1xx */ + +#endif /* _PINAF_STM32F1_H */ diff --git a/cores/arduino/stm32/analog.c b/cores/arduino/stm32/analog.c index 909f051b08..67e4f41444 100644 --- a/cores/arduino/stm32/analog.c +++ b/cores/arduino/stm32/analog.c @@ -50,6 +50,7 @@ #include "hw_config.h" #include "analog.h" #include "timer.h" +#include "PinAF_STM32F1.h" #ifdef __cplusplus extern "C" { @@ -83,6 +84,7 @@ #error "ADC SAMPLINGTIME could not be defined" #endif +#ifndef STM32F1xx #ifdef ADC_CLOCK_SYNC_PCLK_DIV2 #define ADC_CLOCK_DIV ADC_CLOCK_SYNC_PCLK_DIV2 #elif defined(ADC_CLOCK_ASYNC_DIV1) @@ -92,6 +94,7 @@ #else #error "ADC_CLOCK_DIV could not be defined" #endif +#endif /* STM32F1xx */ #ifndef ADC_REGULAR_RANK_1 #define ADC_REGULAR_RANK_1 1 @@ -432,7 +435,8 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) #ifdef __HAL_RCC_ADC_CLK_ENABLE __HAL_RCC_ADC_CLK_ENABLE(); #endif -#ifdef __HAL_RCC_ADC_CONFIG +/* For STM32F1xx, ADC prescaler is confgured in SystemClock_Config (variant.cpp) */ +#if defined(__HAL_RCC_ADC_CONFIG) && !defined(STM32F1xx) /* ADC Periph interface clock configuration */ __HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK); #endif @@ -557,16 +561,22 @@ uint16_t adc_read_value(PinName pin) if (AdcHandle.Instance == NP) return 0; +#ifndef STM32F1xx AdcHandle.Init.ClockPrescaler = ADC_CLOCK_DIV; /* Asynchronous clock mode, input ADC clock divided */ AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; /* 12-bit resolution for converted data */ +#endif AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* Right-alignment for converted data */ AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */ +#ifndef STM32F1xx AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */ +#endif AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */ AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */ +#ifndef STM32F1xx AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */ AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */ +#endif AdcHandle.State = HAL_ADC_STATE_RESET; #if defined (STM32F0xx) || defined (STM32L0xx) AdcHandle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */ @@ -687,7 +697,11 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(function)); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(function); +#endif /* STM32F1xx */ GPIO_InitStruct.Pin = STM_GPIO_PIN(g_current_pin); HAL_GPIO_Init(port, &GPIO_InitStruct); diff --git a/cores/arduino/stm32/digital_io.c b/cores/arduino/stm32/digital_io.c index 3436121ac4..3824947999 100644 --- a/cores/arduino/stm32/digital_io.c +++ b/cores/arduino/stm32/digital_io.c @@ -38,6 +38,7 @@ #include "digital_io.h" #include "stm32_def.h" #include "hw_config.h" +#include "PinAF_STM32F1.h" #ifdef __cplusplus extern "C" { @@ -59,6 +60,9 @@ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull) GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStructure.Mode = mode; GPIO_InitStructure.Pull = pull; +#ifdef STM32F1xx + pinF1_DisconnectDebug(pin); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStructure); } diff --git a/cores/arduino/stm32/uart.c b/cores/arduino/stm32/uart.c index 03beb72094..c244844231 100644 --- a/cores/arduino/stm32/uart.c +++ b/cores/arduino/stm32/uart.c @@ -51,6 +51,7 @@ #include "digital_io.h" #include "interrupt.h" #include "variant.h" +#include "PinAF_STM32F1.h" #ifdef __cplusplus extern "C" { @@ -215,7 +216,11 @@ void uart_init(serial_t *obj) GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_rx,PinMap_UART_RX)); GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_rx,PinMap_UART_RX)); +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_rx,PinMap_UART_RX))); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_rx,PinMap_UART_RX)); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStruct); //TX @@ -224,7 +229,11 @@ void uart_init(serial_t *obj) GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_tx,PinMap_UART_TX)); GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_tx,PinMap_UART_TX)); +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_tx,PinMap_UART_TX))); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_tx,PinMap_UART_TX)); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStruct); //Configure uart @@ -519,7 +528,7 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) { volatile uint32_t tmpval; -#ifdef STM32F4xx +#if defined(STM32F4xx) || defined(STM32F1xx) if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) { tmpval = huart->Instance->DR; // Clear PE flag } else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) { @@ -659,4 +668,5 @@ void UART8_IRQHandler(void) } #endif + /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/NUCLEO_F103RB/variant.cpp b/variants/NUCLEO_F103RB/variant.cpp index d4174856d1..4976c70d57 100644 --- a/variants/NUCLEO_F103RB/variant.cpp +++ b/variants/NUCLEO_F103RB/variant.cpp @@ -91,20 +91,25 @@ const PinName digital_arduino[] = { * UART objects */ -// HardwareSerial Serial(PA3, PA2); // Connected to ST-Link -// HardwareSerial Serial1(PA10, PA9); -// -// void serialEvent() __attribute__((weak)); -// void serialEvent() { } -// -// void serialEvent1() __attribute__((weak)); -// void serialEvent1() { } -// -// void serialEventRun(void) -// { -// if (Serial.available()) serialEvent(); -// if (Serial1.available()) serialEvent1(); -// } +HardwareSerial Serial(PA3, PA2); // Connected to ST-Link +HardwareSerial Serial1(PA10, PA9); +HardwareSerial Serial2(PC11, PC10); //Morpho pins + +void serialEvent() __attribute__((weak)); +void serialEvent() { } + +void serialEvent1() __attribute__((weak)); +void serialEvent1() { } + +void serialEvent2() __attribute__((weak)); +void serialEvent2() { } + +void serialEventRun(void) +{ + if (Serial.available()) serialEvent(); + if (Serial1.available()) serialEvent1(); + if (Serial2.available()) serialEvent2(); +} // ---------------------------------------------------------------------------- diff --git a/variants/NUCLEO_F103RB/variant.h b/variants/NUCLEO_F103RB/variant.h index ee9cf972e7..0e7af75d97 100644 --- a/variants/NUCLEO_F103RB/variant.h +++ b/variants/NUCLEO_F103RB/variant.h @@ -152,6 +152,7 @@ uint32_t pinNametoPinNumber(PinName p); #ifdef __cplusplus extern HardwareSerial Serial; extern HardwareSerial Serial1; +extern HardwareSerial Serial2; // 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 From 90968640040642c1a17b1567404df2f1eb6d9205 Mon Sep 17 00:00:00 2001 From: fpr Date: Thu, 22 Jun 2017 18:00:12 +0200 Subject: [PATCH 03/30] Moving F1 to keep alphabetical order when Arduino displays names Signed-off-by: fpr --- boards.txt | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/boards.txt b/boards.txt index afa0c37c37..ccfe6ab77b 100644 --- a/boards.txt +++ b/boards.txt @@ -86,6 +86,23 @@ Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.product_line=STM32F091xC Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.variant=NUCLEO_F091RC Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.cmsis_lib_gcc=arm_cortexM0l_math +# NUCLEO_F103RB board + +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB=Nucleo F103RB +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.node=NUCLEO_F103RB,NUCLEO +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_size=131071 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_data_size=20479 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.mcu=cortex-m3 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.f_cpu=64000000L +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.usb_product="NUCLEO-F103RB" +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.board=NUCLEO_F103RB +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.series=STM32F1xx +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.variant=NUCLEO_F103RB +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.cmsis_lib_gcc=arm_cortexM3l_math +#To enable USB add '-DUSBCON' +#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.extra_flags=-DSTM32F103xB {build.usb_flags} + # NUCLEO_F303RE board # Support: Serial1 (USART1 on PA10, PA9) and Serial2 (USART2 on PA1, PA0) Nucleo_64.menu.board_part_num.NUCLEO_F303RE=Nucleo F303RE @@ -129,22 +146,6 @@ Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.product_line=STM32L476xx Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.variant=NUCLEO_L476RG Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.cmsis_lib_gcc=arm_cortexM4l_math -# NUCLEO_F103RB board - -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB=Nucleo F103RB -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.node=NUCLEO_F103RB,NUCLEO -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_size=131071 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_data_size=20479 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.mcu=cortex-m3 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.f_cpu=64000000L -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.usb_product="NUCLEO-F103RB" -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.board=NUCLEO_F103RB -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.series=STM32F1xx -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.variant=NUCLEO_F103RB -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.cmsis_lib_gcc=arm_cortexM3l_math -#To enable USB add '-DUSBCON' -#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.extra_flags=-DSTM32F103xB {build.usb_flags} # Upload menu Nucleo_64.menu.upload_method.MassStorageMethod=Mass Storage From 2c84fbaf7b38c5c0693e48ea8cfc5074bd3132ed Mon Sep 17 00:00:00 2001 From: fpr Date: Fri, 23 Jun 2017 16:51:49 +0200 Subject: [PATCH 04/30] Interrupt functions validated Signed-off-by: fpr --- cores/arduino/WInterrupts.c | 7 +++++++ cores/arduino/stm32/interrupt.c | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index 1a24ababde..bab81f2a80 100644 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -22,6 +22,8 @@ extern "C" { #endif +#include "PinAF_STM32F1.h" + void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode) { uint32_t it_mode; @@ -46,6 +48,11 @@ void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode) it_mode = GPIO_MODE_IT_RISING; break; } + +#ifdef STM32F1xx + pinF1_DisconnectDebug(p); +#endif /* STM32F1xx */ + stm32_interrupt_enable(port, STM_GPIO_PIN(p), callback, it_mode); } diff --git a/cores/arduino/stm32/interrupt.c b/cores/arduino/stm32/interrupt.c index 3bcc62039d..caa3ce5c48 100644 --- a/cores/arduino/stm32/interrupt.c +++ b/cores/arduino/stm32/interrupt.c @@ -170,8 +170,18 @@ uint8_t get_pin_id(uint16_t pin) void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(void), uint32_t mode) { GPIO_InitTypeDef GPIO_InitStruct; - uint32_t pull; uint8_t id = get_pin_id(pin); + +#ifdef STM32F1xx + uint8_t position; + uint32_t CRxRegOffset = 0; + uint32_t ODRRegOffset = 0; + volatile uint32_t *CRxRegister; + const uint32_t ConfigMask = 0x00000008; //MODE0 == 0x0 && CNF0 == 0x2 +#else + uint32_t pull; +#endif /* STM32F1xx */ + // GPIO pin configuration GPIO_InitStruct.Pin = pin; GPIO_InitStruct.Mode = mode; @@ -179,6 +189,7 @@ void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(v //read the pull mode directly in the register as no function exists to get it. //Do it in case the user already defines the IO through the digital io //interface +#ifndef STM32F1xx pull = port->PUPDR; #ifdef GPIO_PUPDR_PUPD0 pull &=(GPIO_PUPDR_PUPD0<<(id*2)); @@ -186,7 +197,28 @@ void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(v #else pull &=(GPIO_PUPDR_PUPDR0<<(id*2)); GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPDR0 & (pull>>(id*2))); -#endif +#endif /* GPIO_PUPDR_PUPD0 */ +#else + CRxRegister = (pin < GPIO_PIN_8) ? &port->CRL : &port->CRH; + + for (position = 0; position < 16; position++) { + if(pin == (0x0001 << position)) { + CRxRegOffset = (pin < GPIO_PIN_8) ? (position << 2) : ((position - 8) << 2); + ODRRegOffset = position; + } + } + + if((*CRxRegister & ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << CRxRegOffset)) == (ConfigMask << CRxRegOffset)) { + if((port->ODR & (GPIO_ODR_ODR0 << ODRRegOffset)) == (GPIO_ODR_ODR0 << ODRRegOffset)) { + GPIO_InitStruct.Pull = GPIO_PULLUP; + } else { + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + } + } else { + GPIO_InitStruct.Pull = GPIO_NOPULL; + } +#endif /* STM32F1xx */ + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(port, &GPIO_InitStruct); From 9b24864fc4308367812fdd242980cdd17bd7c4bc Mon Sep 17 00:00:00 2001 From: fpr Date: Mon, 26 Jun 2017 16:29:39 +0200 Subject: [PATCH 05/30] EEPROM validated Signed-off-by: fpr --- cores/arduino/stm32/stm32_eeprom.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cores/arduino/stm32/stm32_eeprom.c b/cores/arduino/stm32/stm32_eeprom.c index 33bf66a6b9..0333d41f86 100644 --- a/cores/arduino/stm32/stm32_eeprom.c +++ b/cores/arduino/stm32/stm32_eeprom.c @@ -72,6 +72,9 @@ #ifdef STM32F0xx // Flash base address (Bank2, page 256) #define FLASH_BASE_ADDRESS 0x0803F800 +#elif defined (STM32F1xx) +#define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_BANK1_END + 1) - FLASH_PAGE_SIZE)) //0x0801FC00 +#define FLASH_PAGE_NUMBER 127 #elif defined (STM32F3xx) #define FLASH_BASE_ADDRESS ((uint32_t)((0x0807FFFF + 1) - FLASH_PAGE_SIZE)) //0x0807F800 #elif defined (STM32F4xx) @@ -173,7 +176,8 @@ void set_data_to_flash(void) uint32_t offset = 0; uint32_t address = FLASH_BASE_ADDRESS; uint32_t address_end = FLASH_BASE_ADDRESS + E2END; -#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32L0xx) || defined(STM32L4xx) +#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || \ + defined (STM32L0xx) || defined(STM32L4xx) uint32_t pageError = 0; uint64_t data = 0; @@ -183,6 +187,9 @@ void set_data_to_flash(void) EraseInitStruct.Banks = FLASH_BANK_NUMBER; EraseInitStruct.Page = FLASH_PAGE_NUMBER; #else // STM32F4xx +#ifdef STM32F1xx + EraseInitStruct.Banks = FLASH_BANK_1; +#endif EraseInitStruct.PageAddress = FLASH_BASE_ADDRESS; #endif EraseInitStruct.NbPages = 1; From c0beef44047a7b6c917d771c0d6c17bf044b737a Mon Sep 17 00:00:00 2001 From: fpr Date: Tue, 27 Jun 2017 14:36:26 +0200 Subject: [PATCH 06/30] SPI functions validated Signed-off-by: fpr --- cores/arduino/stm32/spi_com.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cores/arduino/stm32/spi_com.c b/cores/arduino/stm32/spi_com.c index 8c2f8fd2dc..a1f0cc0e73 100644 --- a/cores/arduino/stm32/spi_com.c +++ b/cores/arduino/stm32/spi_com.c @@ -49,6 +49,7 @@ #include "stm32_def.h" #include "hw_config.h" #include "spi_com.h" +#include "PinAF_STM32F1.h" #ifdef __cplusplus extern "C" { @@ -275,7 +276,11 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb) GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI)); GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI)); GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI))); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_mosi,PinMap_SPI_MOSI)); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStruct); } @@ -285,7 +290,11 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb) GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_miso,PinMap_SPI_MISO)); GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_miso,PinMap_SPI_MISO)); GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_miso,PinMap_SPI_MISO))); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_miso,PinMap_SPI_MISO)); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStruct); } @@ -303,7 +312,11 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb) GPIO_InitStruct.Pull = GPIO_PULLUP; } GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_sclk,PinMap_SPI_SCLK))); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_sclk,PinMap_SPI_SCLK)); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStruct); } @@ -313,7 +326,11 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb) GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL)); GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL)); GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL))); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->pin_ssel,PinMap_SPI_SSEL)); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStruct); } From 0eaa4b79193f03cfe1391c87ca300e01322e4ff1 Mon Sep 17 00:00:00 2001 From: fpr Date: Tue, 27 Jun 2017 17:33:13 +0200 Subject: [PATCH 07/30] I2C functions validated Specific Wire examples for STM32F1xx added. Signed-off-by: fpr --- cores/arduino/stm32/twi.c | 91 ++++++++++++++++++- cores/arduino/stm32/twi.h | 3 + libraries/Wire/Wire.cpp | 15 +++ .../master_reader_writer.ino | 44 +++++++++ .../slave_sender_receiver.ino | 70 ++++++++++++++ 5 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 libraries/Wire/examples/master_reader_writer/master_reader_writer.ino create mode 100644 libraries/Wire/examples/slave_sender_receiver/slave_sender_receiver.ino diff --git a/cores/arduino/stm32/twi.c b/cores/arduino/stm32/twi.c index 1412729c76..4db35d0c18 100644 --- a/cores/arduino/stm32/twi.c +++ b/cores/arduino/stm32/twi.c @@ -47,10 +47,10 @@ /** @addtogroup STM32F4xx_System_Private_Includes * @{ */ - #include "stm32_def.h" #include "hw_config.h" #include "twi.h" +#include "PinAF_STM32F1.h" /** * @} @@ -168,6 +168,9 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u __HAL_RCC_I2C1_FORCE_RESET(); __HAL_RCC_I2C1_RELEASE_RESET(); obj->irq = I2C1_EV_IRQn; +#ifdef STM32F1xx + obj->irqER = I2C1_ER_IRQn; +#endif i2c_handles[0] = handle; } #endif @@ -181,6 +184,9 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u obj->irq = I2C2_IRQn; #else obj->irq = I2C2_EV_IRQn; +#ifdef STM32F1xx + obj->irqER = I2C2_ER_IRQn; +#endif #endif i2c_handles[1] = handle; } @@ -212,7 +218,11 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->scl,PinMap_I2C_SCL)); GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->scl,PinMap_I2C_SCL)); +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->scl,PinMap_I2C_SCL))); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->scl,PinMap_I2C_SCL)); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStruct); //SDA @@ -221,7 +231,11 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u GPIO_InitStruct.Mode = STM_PIN_MODE(pinmap_function(obj->sda,PinMap_I2C_SDA)); GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Pull = STM_PIN_PUPD(pinmap_function(obj->sda,PinMap_I2C_SDA)); +#ifdef STM32F1xx + pin_SetF1AFPin(STM_PIN_AFNUM(pinmap_function(obj->sda,PinMap_I2C_SDA))); +#else GPIO_InitStruct.Alternate = STM_PIN_AFNUM(pinmap_function(obj->sda,PinMap_I2C_SDA)); +#endif /* STM32F1xx */ HAL_GPIO_Init(port, &GPIO_InitStruct); handle->Instance = obj->i2c; @@ -242,6 +256,10 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u if(master == 0) { HAL_NVIC_SetPriority(obj->irq, 0, 1); HAL_NVIC_EnableIRQ(obj->irq); +#ifdef STM32F1xx + HAL_NVIC_SetPriority(obj->irqER, 0, 1); + HAL_NVIC_EnableIRQ(obj->irqER); +#endif } // Init the I2C @@ -256,6 +274,9 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u void i2c_deinit(i2c_t *obj) { HAL_NVIC_DisableIRQ(obj->irq); +#ifdef STM32F1xx + HAL_NVIC_DisableIRQ(obj->irqER); +#endif HAL_I2C_DeInit(&(obj->handle)); } @@ -402,8 +423,16 @@ i2c_t *get_i2c_obj(I2C_HandleTypeDef *hi2c){ */ void i2c_attachSlaveRxEvent(i2c_t *obj, void (*function)(uint8_t*, int) ) { + if((obj == NULL) || (function == NULL)) + return; + obj->i2c_onSlaveReceive = function; +#ifdef STM32F1xx + obj->i2cTxRxBufferSize = 0; + HAL_I2C_Slave_Receive_IT(&(obj->handle), obj->i2cTxRxBuffer, I2C_TXRX_BUFFER_SIZE); +#else HAL_I2C_EnableListen_IT(&(obj->handle)); +#endif } /** @brief sets function called before a slave write operation @@ -413,10 +442,64 @@ void i2c_attachSlaveRxEvent(i2c_t *obj, void (*function)(uint8_t*, int) ) */ void i2c_attachSlaveTxEvent(i2c_t *obj, void (*function)(void) ) { + if((obj == NULL) || (function == NULL)) + return; + obj->i2c_onSlaveTransmit = function; +#ifdef STM32F1xx + /* Fill i2c buffer with data to transmit otherwize the buffer will be empty + when master will read the data for the first time */ + obj->i2cTxRxBufferSize = 0; + obj->i2c_onSlaveTransmit(); + HAL_I2C_Slave_Transmit_IT(&(obj->handle), obj->i2cTxRxBuffer, obj->i2cTxRxBufferSize); +#else HAL_I2C_EnableListen_IT(&(obj->handle)); +#endif +} + +#ifdef STM32F1xx + +/** @brief Slave Tx Transfer completed callback. + * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains + * the configuration information for the specified I2C. + * @retval None + */ +void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c) +{ + i2c_t *obj = get_i2c_obj(hi2c); + + if(NULL != obj->i2c_onSlaveTransmit) { + // reset buffer size and fill buffer with new data before the next Tx + obj->i2cTxRxBufferSize = 0; + obj->i2c_onSlaveTransmit(); + HAL_I2C_Slave_Transmit_IT(hi2c, obj->i2cTxRxBuffer, obj->i2cTxRxBufferSize); + } +} + +/** + * @brief Slave Rx Transfer completed callback. + * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains + * the configuration information for the specified I2C. + * @retval None + */ +void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c) +{ + uint8_t nbData = 0; + i2c_t *obj = get_i2c_obj(hi2c); + + if(NULL != obj->i2c_onSlaveReceive) { + nbData = I2C_TXRX_BUFFER_SIZE - obj->handle.XferCount; + + if(nbData != 0) { + obj->i2c_onSlaveReceive(obj->i2cTxRxBuffer, nbData); + } + + HAL_I2C_Slave_Receive_IT(hi2c, obj->i2cTxRxBuffer, I2C_TXRX_BUFFER_SIZE); + } } +#else /* Others */ + /** * @brief Slave Address Match callback. * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains @@ -469,6 +552,8 @@ void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c) HAL_I2C_EnableListen_IT(hi2c); } +#endif /* STM32F1xx */ + /** * @brief I2C error callback. * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains @@ -477,7 +562,11 @@ void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c) */ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) { +#ifdef STM32F1xx + UNUSED(hi2c); +#else HAL_I2C_EnableListen_IT(hi2c); +#endif } /** diff --git a/cores/arduino/stm32/twi.h b/cores/arduino/stm32/twi.h index 348a9921e8..bd865b9e45 100644 --- a/cores/arduino/stm32/twi.h +++ b/cores/arduino/stm32/twi.h @@ -67,6 +67,9 @@ struct i2c_s { PinName sda; PinName scl; IRQn_Type irq; +#ifdef STM32F1xx + IRQn_Type irqER; +#endif uint8_t slaveMode; void (*i2c_onSlaveReceive)(uint8_t *, int); void (*i2c_onSlaveTransmit)(void); diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index e14f1b6d33..de5d201e34 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -81,6 +81,7 @@ void TwoWire::begin(uint8_t address) i2c_custom_init(&_i2c,I2C_100KHz,I2C_ADDRESSINGMODE_7BIT,ownAddress,master); +#ifndef STM32F1xx if(master == false){ // i2c_attachSlaveTxEvent(&_i2c, reinterpret_cast(&TwoWire::onRequestService)); // i2c_attachSlaveRxEvent(&_i2c, reinterpret_cast(&TwoWire::onReceiveService)); @@ -88,6 +89,7 @@ void TwoWire::begin(uint8_t address) i2c_attachSlaveTxEvent(&_i2c, onRequestService); i2c_attachSlaveRxEvent(&_i2c, onReceiveService); } +#endif } void TwoWire::begin(int address) @@ -109,6 +111,8 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres { UNUSED(sendStop); if (master == true) { + //NOTE: do not work with STM32F1xx boards (latest HAL version: 1.0.4) +#ifndef STM32F1xx if (isize > 0) { // send internal address; this mode allows sending a repeated start to access // some devices' internal registers. This function is executed by the hardware @@ -127,6 +131,7 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres } endTransmission(false); } +#endif /* !STM32F1xx */ // clamp to buffer length if(quantity > BUFFER_LENGTH){ @@ -369,12 +374,22 @@ void TwoWire::onRequestService(void) void TwoWire::onReceive( void (*function)(int) ) { user_onReceive = function; + +#ifdef STM32F1xx + //Enable slave receive IT + i2c_attachSlaveRxEvent(&_i2c, onReceiveService); +#endif } // sets function called on slave read void TwoWire::onRequest( void (*function)(void) ) { user_onRequest = function; + +#ifdef STM32F1xx + //Enable slave transmit IT + i2c_attachSlaveTxEvent(&_i2c, onRequestService); +#endif } // Preinstantiate Objects ////////////////////////////////////////////////////// diff --git a/libraries/Wire/examples/master_reader_writer/master_reader_writer.ino b/libraries/Wire/examples/master_reader_writer/master_reader_writer.ino new file mode 100644 index 0000000000..6f73acf217 --- /dev/null +++ b/libraries/Wire/examples/master_reader_writer/master_reader_writer.ino @@ -0,0 +1,44 @@ +/* Wire Master Reader Writer +by Wi6Labs + +Demonstrates use of the Wire library, particullary with STM32F1xx boards. +Reads/writes data from/to an I2C/TWI slave device. +Refer to the "Wire Slave Sender Receiver" example for use with this. + +Created 27 June 2017 + +This example code is in the public domain. +*/ + +#include + +#define I2C_ADDR 2 + +byte x = 0; + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() +{ + Wire.requestFrom(I2C_ADDR, 6); // request 6 bytes from slave device + + while(Wire.available()) // slave may send less than requested + { + char c = Wire.read(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(10); + + Wire.beginTransmission(I2C_ADDR); // transmit to device + Wire.write("x is "); // sends five bytes + Wire.write(x); // sends one byte + Wire.endTransmission(); // stop transmitting + x++; + + delay(1000); +} diff --git a/libraries/Wire/examples/slave_sender_receiver/slave_sender_receiver.ino b/libraries/Wire/examples/slave_sender_receiver/slave_sender_receiver.ino new file mode 100644 index 0000000000..92912961f9 --- /dev/null +++ b/libraries/Wire/examples/slave_sender_receiver/slave_sender_receiver.ino @@ -0,0 +1,70 @@ +/* Wire Slave Receiver +by Wi6Labs + +Demonstrates use of the Wire library, particullary with STM32F1xx boards where +we can't use slave Tx & Rx mode in same time. +Receives/sends data as an I2C/TWI slave device. +Refer to the "Wire Master Reader Writer" example for use with this. + +Created 27 June 2017 + +This example code is in the public domain. +*/ + +#include + +#define SLAVE_MODE_RX 0 +#define SLAVE_MODE_TX 1 + +#define I2C_ADDR 2 + +int w_r_mode = SLAVE_MODE_TX; +bool switch_mode = false; + +void setup() +{ + Wire.begin(I2C_ADDR); // join i2c bus with address #4 + Wire.onRequest(requestEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() +{ + if(switch_mode == true) { + switch_mode = false; + Wire.end(); + Wire.begin(I2C_ADDR); + if(w_r_mode == SLAVE_MODE_TX) { + Wire.onRequest(requestEvent); // register event + } else { + Wire.onReceive(receiveEvent); // register event + } + } +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) +{ + while(1 < Wire.available()) // loop through all but the last + { + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer + + switch_mode = true; + w_r_mode = SLAVE_MODE_TX; +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() +{ + Wire.write("hello "); // respond with message of 6 bytes + // as expected by master + + switch_mode = true; + w_r_mode = SLAVE_MODE_RX; +} From 87515a6490ec28b67f57560add33a5baa189d99b Mon Sep 17 00:00:00 2001 From: fpr Date: Wed, 28 Jun 2017 09:46:50 +0200 Subject: [PATCH 08/30] Removed emulation uart pin because can't be used currently. Removed compilation warning error in timer. Timer functions validated (Tone, Servo). Signed-off-by: fpr --- variants/NUCLEO_F103RB/variant.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/variants/NUCLEO_F103RB/variant.h b/variants/NUCLEO_F103RB/variant.h index 0e7af75d97..449f716f06 100644 --- a/variants/NUCLEO_F103RB/variant.h +++ b/variants/NUCLEO_F103RB/variant.h @@ -135,10 +135,6 @@ uint32_t pinNametoPinNumber(PinName p); #define DEBUG_UART ((USART_TypeDef *) USART2) -// UART Emulation -#define UART_EMUL_RX PB13 -#define UART_EMUL_TX PB14 - //Enable Firmata #define STM32 1 From ae3c0d6e9873a197eceeffcd9401cbfa9af34918 Mon Sep 17 00:00:00 2001 From: fpr Date: Wed, 28 Jun 2017 14:56:19 +0200 Subject: [PATCH 09/30] Aligns configuration with master Signed-off-by: fpr --- boards.txt | 10 ++-- variants/NUCLEO_F103RB/PeripheralPins.c | 8 --- variants/NUCLEO_F103RB/variant.cpp | 69 ++++++++++++------------ variants/NUCLEO_F103RB/variant.h | 71 ++++++++----------------- 4 files changed, 63 insertions(+), 95 deletions(-) diff --git a/boards.txt b/boards.txt index ccfe6ab77b..e964a382b2 100644 --- a/boards.txt +++ b/boards.txt @@ -89,19 +89,19 @@ Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.cmsis_lib_gcc=arm_cortexM0l_ma # NUCLEO_F103RB board Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB=Nucleo F103RB -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.node=NUCLEO_F103RB,NUCLEO +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.node="NODE_F103RB,NUCLEO" Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_size=131071 Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_data_size=20479 Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.mcu=cortex-m3 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.f_cpu=64000000L +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.f_cpu=72000000L Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.usb_product="NUCLEO-F103RB" Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.board=NUCLEO_F103RB Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.series=STM32F1xx Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.variant=NUCLEO_F103RB Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.cmsis_lib_gcc=arm_cortexM3l_math -#To enable USB add '-DUSBCON' -#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.extra_flags=-DSTM32F103xB {build.usb_flags} +#To enable Serial1 (USART1 on PA10, PA9) add -DENABLE_SERIAL1 +#To enable Serial2 (USART3 on PC11, PC10) add -DENABLE_SERIAL2 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.extra_flags=-DSTM32F103xB # NUCLEO_F303RE board # Support: Serial1 (USART1 on PA10, PA9) and Serial2 (USART2 on PA1, PA0) diff --git a/variants/NUCLEO_F103RB/PeripheralPins.c b/variants/NUCLEO_F103RB/PeripheralPins.c index 5b0a13e8ad..627c715850 100644 --- a/variants/NUCLEO_F103RB/PeripheralPins.c +++ b/variants/NUCLEO_F103RB/PeripheralPins.c @@ -211,11 +211,3 @@ const PinMap PinMap_CAN_TD[] = { {PB9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_TX to PB_9 {NC, NC, 0} }; - -const TimerMap TimerMap_CONFIG[] = { - {TIM1, TIM1_UP_IRQn, 2}, - {TIM2, TIM2_IRQn, 1}, - {TIM3, TIM3_IRQn, 1}, - {TIM4, TIM4_IRQn, 1}, - {NULL, 0, 0} -}; diff --git a/variants/NUCLEO_F103RB/variant.cpp b/variants/NUCLEO_F103RB/variant.cpp index 4976c70d57..7b99fa029c 100644 --- a/variants/NUCLEO_F103RB/variant.cpp +++ b/variants/NUCLEO_F103RB/variant.cpp @@ -23,7 +23,7 @@ extern "C" { #endif // Pin number -const PinName digital_arduino[] = { +const PinName digitalPin[] = { PA3, //D0 PA2, //D1 PA10, //D2 @@ -37,7 +37,7 @@ const PinName digital_arduino[] = { PB6, //D10 PA7, //D11 PA6, //D12 - PA5, //D13 + PA5, //D13 - LED PB9, //D14 PB8, //D15 // ST Morpho @@ -81,6 +81,16 @@ const PinName digital_arduino[] = { PB0, //D49/A3 PC1, //D50/A4 PC0, //D51/A5 + // Duplicated pins in order to be aligned with PinMap_ADC + PA3, //D52/A6 = D0 + PA2, //D53/A7 = D1 + PA7, //D54/A8 = D11 + PA6, //D55/A9 = D12 + PA5, //D56/A10 = D13 + PC2, //D57/A11 = D28 + PC3, //D58/A12 = D29 + PB1, //D59/A13 = D41 + PC4, //D60/A14 = D45 }; #ifdef __cplusplus @@ -92,23 +102,33 @@ const PinName digital_arduino[] = { */ HardwareSerial Serial(PA3, PA2); // Connected to ST-Link +#ifdef ENABLE_SERIAL1 HardwareSerial Serial1(PA10, PA9); +#endif +#ifdef ENABLE_SERIAL2 HardwareSerial Serial2(PC11, PC10); //Morpho pins +#endif void serialEvent() __attribute__((weak)); void serialEvent() { } - +#ifdef ENABLE_SERIAL1 void serialEvent1() __attribute__((weak)); void serialEvent1() { } - +#endif +#ifdef ENABLE_SERIAL2 void serialEvent2() __attribute__((weak)); void serialEvent2() { } +#endif void serialEventRun(void) { if (Serial.available()) serialEvent(); +#ifdef ENABLE_SERIAL1 if (Serial1.available()) serialEvent1(); +#endif +#ifdef ENABLE_SERIAL2 if (Serial2.available()) serialEvent2(); +#endif } // ---------------------------------------------------------------------------- @@ -117,36 +137,19 @@ void serialEventRun(void) extern "C" { #endif -void __libc_init_array(void); - -uint32_t pinNametoPinNumber(PinName p) -{ - uint32_t i = 0; - for(i = 0; i < NUM_DIGITAL_PINS; i++) { - if (digital_arduino[i] == p) - break; - } - return i; -} - -void init( void ) -{ - hw_config_init(); -} - /** * @brief System Clock Configuration * The system Clock is configured as follow : - * System Clock source = PLL (HSI) - * SYSCLK(Hz) = 64000000 - * HCLK(Hz) = 64000000 + * System Clock source = PLL (HSE) + * SYSCLK(Hz) = 72000000 + * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 - * PLL_Source = 2 - * PLL_Mul = 16 + * PLL_Source = HSE + * PLL_Mul = 9 * Flash Latency(WS) = 2 - * ADC Prescaler = 8 + * ADC Prescaler = 6 * @param None * @retval None */ @@ -156,12 +159,12 @@ WEAK void SystemClock_Config(void) RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = 16; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; - RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { while(1); @@ -179,7 +182,7 @@ WEAK void SystemClock_Config(void) } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; - PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV8; + PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { while(1); diff --git a/variants/NUCLEO_F103RB/variant.h b/variants/NUCLEO_F103RB/variant.h index 449f716f06..de339a1ec0 100644 --- a/variants/NUCLEO_F103RB/variant.h +++ b/variants/NUCLEO_F103RB/variant.h @@ -19,16 +19,6 @@ #ifndef _VARIANT_ARDUINO_STM32_ #define _VARIANT_ARDUINO_STM32_ -/*---------------------------------------------------------------------------- - * Definitions - *----------------------------------------------------------------------------*/ - -/** Frequency of the board main oscillator */ -//#define VARIANT_MAINOSC 12000000 - -/** Master clock frequency */ -//#define VARIANT_MCK 84000000 - /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ @@ -39,53 +29,31 @@ extern "C"{ #endif // __cplusplus -/** - * Libc porting layers - */ -#if defined ( __GNUC__ ) /* GCC CS3 */ -# include /** RedHat Newlib minimal stub */ -#endif - /*---------------------------------------------------------------------------- * Pins *----------------------------------------------------------------------------*/ #include "PeripheralPins.h" -extern const PinName digital_arduino[]; +extern const PinName digitalPin[]; 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, - DEND + 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, + DEND }; enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, - AEND + A_START_AFTER = D45, + A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, + A10, A11, A12, A13, A14, + AEND }; -#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap)) -#define MAX_DIGITAL_IOS DEND -#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS -#define NUM_ANALOG_INPUTS (AEND - A0) - -// Convert a digital pin number Dxx to a PinName Pxy -#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC) -// Convert an analog pin number Axx to a PinName Pxy -#define analogToPinName(p) (digitalToPinName(p)) -// Convert an analog pin number to a digital pin number -#define analogToDigital(p) (p) -// Convert a PinName Pxy to a pin number -uint32_t pinNametoPinNumber(PinName p); - -#define digitalPinToPort(p) ( get_GPIO_Port(digitalToPinName(p)) ) -#define digitalPinToBitMask(p) ( STM_GPIO_PIN(digitalToPinName(p)) ) - //ADC resolution is 12bits #define ADC_RESOLUTION 12 #define DACC_RESOLUTION 12 @@ -102,7 +70,7 @@ uint32_t pinNametoPinNumber(PinName p); //On-board user button #define USER_BTN 23 -//SPI defintions +//SPI definitions //define 16 channels. As many channel as digital IOs #define SPI_CHANNELS_NUM 16 @@ -135,8 +103,13 @@ uint32_t pinNametoPinNumber(PinName p); #define DEBUG_UART ((USART_TypeDef *) USART2) -//Enable Firmata -#define STM32 1 +// Serial Pin Firmata +#define PIN_SERIAL_RX 0 +#define PIN_SERIAL_TX 1 +#define PIN_SERIAL1_RX 2 +#define PIN_SERIAL1_TX 8 +#define PIN_SERIAL2_RX 30 +#define PIN_SERIAL2_TX 16 #ifdef __cplusplus } // extern "C" @@ -166,7 +139,7 @@ extern HardwareSerial Serial2; // 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 Serial1 +#define SERIAL_PORT_HARDWARE Serial #endif #endif /* _VARIANT_ARDUINO_STM32_ */ From 5d1568d9d1fbbbc83ad27a7cdab9b590f8e7f814 Mon Sep 17 00:00:00 2001 From: fpr Date: Wed, 28 Jun 2017 17:24:33 +0200 Subject: [PATCH 10/30] BluePill F103C8 variant added. Upload method Bootloader, Serial and BMP added. USBSerial class added because is required by bootloader. Signed-off-by: fpr --- boards.txt | 58 ++ cores/arduino/Arduino.h | 1 + cores/arduino/USBSerial.cpp | 212 ++++++++ cores/arduino/USBSerial.h | 101 ++++ platform.txt | 32 ++ variants/BLUEPILL_F103C8/PeripheralPins.c | 195 +++++++ variants/BLUEPILL_F103C8/bootloader.ld | 180 ++++++ variants/BLUEPILL_F103C8/ldscript.ld | 180 ++++++ variants/BLUEPILL_F103C8/stm32f1xx_hal_conf.h | 367 +++++++++++++ variants/BLUEPILL_F103C8/usb/usb_device.c | 70 +++ variants/BLUEPILL_F103C8/usb/usb_device.h | 69 +++ variants/BLUEPILL_F103C8/usb/usb_device_cdc.c | 26 + variants/BLUEPILL_F103C8/usb/usbd_cdc_if.c | 325 +++++++++++ variants/BLUEPILL_F103C8/usb/usbd_cdc_if.h | 129 +++++ variants/BLUEPILL_F103C8/usb/usbd_conf.c | 514 ++++++++++++++++++ variants/BLUEPILL_F103C8/usb/usbd_conf.h | 179 ++++++ variants/BLUEPILL_F103C8/usb/usbd_desc.c | 300 ++++++++++ variants/BLUEPILL_F103C8/usb/usbd_desc.h | 107 ++++ variants/BLUEPILL_F103C8/variant.cpp | 201 +++++++ variants/BLUEPILL_F103C8/variant.h | 148 +++++ 20 files changed, 3394 insertions(+) create mode 100644 cores/arduino/USBSerial.cpp create mode 100644 cores/arduino/USBSerial.h create mode 100644 variants/BLUEPILL_F103C8/PeripheralPins.c create mode 100644 variants/BLUEPILL_F103C8/bootloader.ld create mode 100644 variants/BLUEPILL_F103C8/ldscript.ld create mode 100644 variants/BLUEPILL_F103C8/stm32f1xx_hal_conf.h create mode 100644 variants/BLUEPILL_F103C8/usb/usb_device.c create mode 100644 variants/BLUEPILL_F103C8/usb/usb_device.h create mode 100644 variants/BLUEPILL_F103C8/usb/usb_device_cdc.c create mode 100644 variants/BLUEPILL_F103C8/usb/usbd_cdc_if.c create mode 100644 variants/BLUEPILL_F103C8/usb/usbd_cdc_if.h create mode 100644 variants/BLUEPILL_F103C8/usb/usbd_conf.c create mode 100644 variants/BLUEPILL_F103C8/usb/usbd_conf.h create mode 100644 variants/BLUEPILL_F103C8/usb/usbd_desc.c create mode 100644 variants/BLUEPILL_F103C8/usb/usbd_desc.h create mode 100644 variants/BLUEPILL_F103C8/variant.cpp create mode 100644 variants/BLUEPILL_F103C8/variant.h diff --git a/boards.txt b/boards.txt index e964a382b2..e74d31409f 100644 --- a/boards.txt +++ b/boards.txt @@ -245,6 +245,64 @@ Disco.menu.upload_method.STLinkMethod.upload.protocol=STLink Disco.menu.upload_method.STLinkMethod.upload.tool=stlink_upload +################################################################################ +# Other boards + +Other_board.name=Other + +Other_board.build.vid=0x0483 +Other_board.build.pid=0x5711 +Other_board.vid.0=0x0483 +Other_board.pid.0=0x5711 + +Other_board.build.core=arduino +Other_board.build.board=Other_board + +# BLUEPILL_F103C8 board + +Other_board.menu.Other_board.BLUEPILL_F103C8=BluePill F103C8 +Other_board.menu.Other_board.BLUEPILL_F103C8.node=NODE_F103C8 +Other_board.menu.Other_board.BLUEPILL_F103C8.upload.maximum_size=65536 +Other_board.menu.Other_board.BLUEPILL_F103C8.upload.maximum_data_size=20480 +Other_board.menu.Other_board.BLUEPILL_F103C8.build.mcu=cortex-m3 +Other_board.menu.Other_board.BLUEPILL_F103C8.build.f_cpu=72000000L +Other_board.menu.Other_board.BLUEPILL_F103C8.build.usb_product="BLUEPILL-F103C8" +Other_board.menu.Other_board.BLUEPILL_F103C8.build.board=BLUEPILL_F103C8 +Other_board.menu.Other_board.BLUEPILL_F103C8.build.series=STM32F1xx +Other_board.menu.Other_board.BLUEPILL_F103C8.build.variant=BLUEPILL_F103C8 +Other_board.menu.Other_board.BLUEPILL_F103C8.build.cmsis_lib_gcc=arm_cortexM3l_math +#To enable USB add '-DUSBCON' +#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' +#To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2 +#To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3 +Other_board.menu.Other_board.BLUEPILL_F103C8.build.extra_flags=-DSTM32F103xB {build.usb_flags} -DSERIAL_USB -DUSBCON "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" {build.upload_flags} + + +Other_board.menu.upload_method.DFUUploadMethod=STM32duino bootloader +Other_board.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu +Other_board.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload +Other_board.menu.upload_method.DFUUploadMethod.build.upload_flags=-DVECT_TAB_OFFSET=0x2000 +Other_board.menu.upload_method.DFUUploadMethod.build.ldscript=bootloader.ld +Other_board.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 +Other_board.menu.upload_method.DFUUploadMethod.upload.altID=2 + +Other_board.menu.upload_method.STLinkMethod=STLink +Other_board.menu.upload_method.STLinkMethod.upload.protocol=STLink +Other_board.menu.upload_method.STLinkMethod.upload.tool=stlink_upload +Other_board.menu.upload_method.STLinkMethod.build.upload_flags= + +Other_board.menu.upload_method.serialMethod=Serial +Other_board.menu.upload_method.serialMethod.upload.protocol=maple_serial +Other_board.menu.upload_method.serialMethod.upload.tool=serial_upload +Other_board.menu.upload_method.serialMethod.build.upload_flags= + +Other_board.menu.upload_method.BMPMethod=BMP (Black Magic Probe) +Other_board.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp +Other_board.menu.upload_method.BMPMethod.upload.tool=bmp_upload +Other_board.menu.upload_method.BMPMethod.upload.speed=230400 +Other_board.menu.upload_method.BMPMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG + + ################################################################################ # Serialx activation Nucleo_144.menu.Other_serial.enable_Serial=None diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index d948c17879..28a4177873 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -68,6 +68,7 @@ extern void loop( void ) ; #include "WMath.h" #include "HardwareSerial.h" #include "wiring_pulse.h" +#include "USBSerial.h" #endif // __cplusplus diff --git a/cores/arduino/USBSerial.cpp b/cores/arduino/USBSerial.cpp new file mode 100644 index 0000000000..93b74c0016 --- /dev/null +++ b/cores/arduino/USBSerial.cpp @@ -0,0 +1,212 @@ +/**************************************************************************** + * + * USBSerial core library for Arduino STM32 + HAL + CubeMX (HALMX). + * + * Copyright (c) 2016 by Vassilis Serasidis + * Home: http://www.serasidis.gr + * email: avrsite@yahoo.gr + * + * Arduino_STM32 forum: http://www.stm32duino.com + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted, provided that the + * above copyright notice and this permission notice appear in all copies. + * + * Some functions follow the sam and samd arduino core libray files. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR + * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * + ****************************************************************************/ + +#include + +#if defined(SERIAL_USB) && defined(USBCON) +#include +#include "variant.h" + +// Constructors //////////////////////////////////////////////////////////////// +USBSerial::USBSerial(){ + // Make sure Rx ring buffer is initialized back to empty. + rx_buffer.iHead = rx_buffer.iTail = 0; + //tx_buffer.iHead = tx_buffer.iTail = 0; +} + +void USBSerial::init(void){ +/* Re-enumerate the USB */ + volatile unsigned int i; + +#ifdef USB_DISC_PIN + pinMode(USB_DISC_PIN, OUTPUT); + digitalWrite(USB_DISC_PIN, HIGH); + for(i=0;i<512;i++); + digitalWrite(USB_DISC_PIN, LOW); +#else + #error "USB_DISC_PIN definition missing" +#endif + MX_USB_DEVICE_Init(); +} + + +void USBSerial::begin(uint32_t baud_count){ + init(); + // suppress "unused parameter" warning + (void)baud_count; +} + +void USBSerial::begin(uint32_t baud_count, uint8_t config){ + init(); + //suppress "unused parameter" warning + (void)baud_count; + (void)config; +} + +void USBSerial::end(void){ + +} + + +int USBSerial::availableForWrite(void){ + //return (CDC_SERIAL_BUFFER_SIZE - available()); + //return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + tx_buffer.iHead - tx_buffer.iTail) % CDC_SERIAL_BUFFER_SIZE; + return 0; +} + + +int USBSerial::available(void){ + return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + rx_buffer.iHead - rx_buffer.iTail) % CDC_SERIAL_BUFFER_SIZE; +} + +int USBSerial::peek(void) +{ + if ( rx_buffer.iHead == rx_buffer.iTail ) + return -1; + + return rx_buffer.buffer[rx_buffer.iTail]; +} + +int USBSerial::read(void) +{ + // if the head isn't ahead of the tail, we don't have any characters + if ( rx_buffer.iHead == rx_buffer.iTail ) + return -1; + + uint8_t uc = rx_buffer.buffer[rx_buffer.iTail]; + rx_buffer.iTail = (unsigned int)(rx_buffer.iTail + 1) % CDC_SERIAL_BUFFER_SIZE; + + return uc; +} + +void USBSerial::flush(void){ + //It's not implemented yet. +} + +size_t USBSerial::write(const uint8_t *buffer, size_t size){ + unsigned long timeout=millis()+5; + if(hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED) + { + while(millis() 0) + { + result = true; + } + + delay(10); */ + return result; +} + +uint32_t USBSerial::baud() { + //return _usbLineInfo.dwDTERate; + return 0; +} + +uint8_t USBSerial::stopbits() { + //return _usbLineInfo.bCharFormat; + return 0; +} + +uint8_t USBSerial::paritytype() { + //return _usbLineInfo.bParityType; + return 0; +} + +uint8_t USBSerial::numbits() { + //return _usbLineInfo.bDataBits; + return 0; +} + +bool USBSerial::dtr() { + //return _usbLineInfo.lineState & 0x1; + return 0; +} + +bool USBSerial::rts() { + //return _usbLineInfo.lineState & 0x2; + return 0; +} + +#endif diff --git a/cores/arduino/USBSerial.h b/cores/arduino/USBSerial.h new file mode 100644 index 0000000000..ccd646ef6a --- /dev/null +++ b/cores/arduino/USBSerial.h @@ -0,0 +1,101 @@ +/**************************************************************************** + * + * USBSerial core library for Arduino STM32 + HAL + CubeMX (HALMX). + * + * Copyright (c) 2016 by Vassilis Serasidis + * Home: http://www.serasidis.gr + * email: avrsite@yahoo.gr + * + * Arduino_STM32 forum: http://www.stm32duino.com + * + * The USBSerial.h file follows the function prototypes of + * the Arduino CDC.h file that was written by Peter Barrett + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted, provided that the + * above copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR + * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * + ****************************************************************************/ + +#ifndef _SERIAL_USB_H_INCLUDED +#define _SERIAL_USB_H_INCLUDED + +#if defined(SERIAL_USB) && defined(USBCON) +#include "usb_device.h" +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_cdc.h" +#include "usbd_cdc_if.h" + +#include "RingBuffer.h" +#include "Stream.h" +#include "chip.h" + + +//================================================================================ +// Serial over CDC (Serial1 is the physical port) +//================================================================================ +class USBSerial : public Stream{ + + public: + USBSerial(); + void begin(uint32_t baud_count); + void begin(uint32_t baud_count, uint8_t config); + void end(void); + + virtual int available(void); + virtual int availableForWrite(void); + //virtual void accept(void); + virtual int peek(void); + virtual int read(void); + virtual void flush(void); + virtual size_t write(uint8_t c); + virtual size_t write(const uint8_t *buffer, size_t size); + using Print::write; // pull in write(str) from Print + operator bool(); + void CDC_RxHandler(uint8_t* Buf, uint16_t Len); + void CDC_TxHandler(void); + // These return the settings specified by the USB host for the + // serial port. These aren't really used, but are offered here + // in case a sketch wants to act on these settings. + uint32_t baud(); + uint8_t stopbits(); + uint8_t paritytype(); + uint8_t numbits(); + bool dtr(); + bool rts(); + enum { + ONE_STOP_BIT = 0, + ONE_AND_HALF_STOP_BIT = 1, + TWO_STOP_BITS = 2, + }; + enum { + NO_PARITY = 0, + ODD_PARITY = 1, + EVEN_PARITY = 2, + MARK_PARITY = 3, + SPACE_PARITY = 4, + }; + protected: + void init(void); + struct ring_buffer{ + uint8_t buffer[CDC_SERIAL_BUFFER_SIZE]; + volatile uint16_t iHead; + volatile uint16_t iTail; + }; + ring_buffer rx_buffer; + //ring_buffer tx_buffer; + GPIO_InitTypeDef GPIO_InitStruct; +}; + +#endif /* SERIAL_USB */ + +#endif /* _SERIAL_USB_H_INCLUDED */ diff --git a/platform.txt b/platform.txt index d728a87a3d..4abad1d95c 100644 --- a/platform.txt +++ b/platform.txt @@ -125,3 +125,35 @@ tools.stlink_upload.path.linux64={runtime.hardware.path}/tools/linux64 tools.stlink_upload.upload.params.verbose=-d tools.stlink_upload.upload.params.quiet= tools.stlink_upload.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin" + +# Upload using Maple bootloader over DFU +tools.maple_upload.cmd=maple_upload +tools.maple_upload.cmd.windows=maple_upload.bat +tools.maple_upload.path={runtime.hardware.path}/tools/win +tools.maple_upload.path.macosx={runtime.hardware.path}/tools/macosx +tools.maple_upload.path.linux={runtime.hardware.path}/tools/linux +tools.maple_upload.path.linux64={runtime.hardware.path}/tools/linux64 +tools.maple_upload.upload.params.verbose=-d +tools.maple_upload.upload.params.quiet= +tools.maple_upload.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin" + +#Added tool for generic STM32 upload via serial to Serial Port 1 (pins PA9 and PA10) - note. Boot0 line needs to high on board reset to enable upload via serial +# at the end up the upload the program is automatically run, without the board being reset + +tools.serial_upload.cmd=serial_upload +tools.serial_upload.cmd.windows=serial_upload.bat +tools.serial_upload.cmd.macosx=serial_upload +tools.serial_upload.path={runtime.hardware.path}/tools/win +tools.serial_upload.path.macosx={runtime.hardware.path}/tools/macosx +tools.serial_upload.path.linux={runtime.hardware.path}/tools/linux +tools.serial_upload.path.linux64={runtime.hardware.path}/tools/linux64 +tools.serial_upload.upload.params.verbose=-d +tools.serial_upload.upload.params.quiet=n +tools.serial_upload.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin" + +# blackmagic probe upload +tools.bmp_upload.cmd=arm-none-eabi-gdb +tools.bmp_upload.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ +tools.bmp_upload.upload.params.verbose= +tools.bmp_upload.upload.params.quiet=-q --batch-silent +tools.bmp_upload.upload.pattern="{path}{cmd}" -cd "{build.path}" -b {upload.speed} {upload.verbose} -ex "set debug remote 0" -ex "set target-async off" -ex "set remotetimeout 60" -ex "set mem inaccessible-by-default off" -ex "set confirm off" -ex "set height 0" -ex "target extended-remote {serial.port}" -ex "monitor swdp_scan" -ex "attach 1" -ex "x/wx 0x8000004" -ex "monitor erase_mass" -ex "echo 0x8000004 expect 0xffffffff after erase\n" -ex "x/wx 0x8000004" -ex "file {build.project_name}.elf" -ex "load" -ex "x/wx 0x08000004" -ex "tbreak main" -ex "run" -ex "echo \n\n\nUpload finished!" -ex "quit" diff --git a/variants/BLUEPILL_F103C8/PeripheralPins.c b/variants/BLUEPILL_F103C8/PeripheralPins.c new file mode 100644 index 0000000000..57477330a2 --- /dev/null +++ b/variants/BLUEPILL_F103C8/PeripheralPins.c @@ -0,0 +1,195 @@ +/* + ******************************************************************************* + * Copyright (c) 2016, 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 "Arduino.h" +#include "PeripheralPins.h" + +// ===== +// Note: Commented lines are alternative possibilities which are not used per default. +// If you change them, you will have to know what you do +// ===== + + +//*** ADC *** + +const PinMap PinMap_ADC[] = { + {PA0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 + // {PA0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 + {PA1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 + // {PA1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 + {PA2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 + // {PA2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 + {PA3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 + // {PA3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 + {PA4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 + // {PA4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 + {PA5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 + // {PA5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 + {PA6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 + // {PA6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 + {PA7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 + // {PA7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 + {PB0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 + // {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 + {PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 + // {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 + {NC, NC, 0} +}; + +//*** DAC *** + +const PinMap PinMap_DAC[] = { + {NC, NC, 0} +}; + +//*** I2C *** + +const PinMap PinMap_I2C_SDA[] = { + {PB7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {PB9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 + {PB11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_I2C_SCL[] = { + {PB6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {PB8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 + {PB10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {NC, NC, 0} +}; + +//*** PWM *** + +const PinMap PinMap_PWM[] = { + {PA0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM2_CH1 + {PA1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM2_CH2 + {PA2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM2_CH3 + {PA3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM2_CH4 + {PA6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM3_CH1 + // {PA7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 1, 1)}, // TIM1_CH1N - GPIO_PartialRemap_TIM1 + {PA7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM3_CH2 + {PA8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM1_CH1 + {PA9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM1_CH2 + {PA10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM1_CH3 + {PA11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM1_CH4 + {PA15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 1, 0)}, // TIM2_CH1 - GPIO_FullRemap_TIM2 + // {PB0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 2, 1)}, // TIM1_CH2N - GPIO_PartialRemap_TIM1 + {PB0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM3_CH3 + // {PB1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 3, 1)}, // TIM1_CH3N - GPIO_PartialRemap_TIM1 + {PB1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM3_CH4 + {PB3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 2, 0)}, // TIM2_CH2 - GPIO_FullRemap_TIM2 + {PB4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 1, 0)}, // TIM3_CH1 - GPIO_PartialRemap_TIM3 + {PB5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 2, 0)}, // TIM3_CH2 - GPIO_PartialRemap_TIM3 + {PB6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM4_CH1 + {PB7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM4_CH2 + {PB8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM4_CH3 + {PB9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM4_CH4 + {PB10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 3, 0)}, // TIM2_CH3 - GPIO_FullRemap_TIM2 + {PB11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 4, 0)}, // TIM2_CH4 - GPIO_FullRemap_TIM2 + {PB13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM1_CH1N + {PB14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 1)}, // TIM1_CH2N + {PB15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 1)}, // TIM1_CH3N + {NC, NC, 0} +}; + +//*** SERIAL *** + +const PinMap PinMap_UART_TX[] = { + {PA2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 + {PB10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_UART_RX[] = { + {PA3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 + {PB11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_UART_RTS[] = { + {PA1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_UART_CTS[] = { + {PA0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +//*** SPI *** + +const PinMap PinMap_SPI_MOSI[] = { + {PA7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_MISO[] = { + {PA6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_SCLK[] = { + {PA5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_SSEL[] = { + {PA4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +//*** CAN *** + +const PinMap PinMap_CAN_RD[] = { + {PA11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, + {PB8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_RX to PB_9 + {NC, NC, 0} +}; + +const PinMap PinMap_CAN_TD[] = { + {PA12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, + {PB9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_TX to PB_9 + {NC, NC, 0} +}; diff --git a/variants/BLUEPILL_F103C8/bootloader.ld b/variants/BLUEPILL_F103C8/bootloader.ld new file mode 100644 index 0000000000..32b3216f18 --- /dev/null +++ b/variants/BLUEPILL_F103C8/bootloader.ld @@ -0,0 +1,180 @@ +/** + ****************************************************************************** + * @file STM32F103CB_FLASH.h + * @author WI6LABS + * @version V1.0.0 + * @date 22-July-2016 + * @brief Linker script for STM32F103C8 Device with + * 64KByte FLASH, 20KByte 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) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = 0x20005000; /* end of RAM */ +/* Generate a link error if heap and stack don't fit into RAM */ +_Min_Heap_Size = 0x200;; /* required amount of heap */ +_Min_Stack_Size = 0x400;; /* required amount of stack */ + +/* Specify the memory areas */ +MEMORY +{ +FLASH (rx) : ORIGIN = 0x8002000, LENGTH = 56K +RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .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 goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .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 */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _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 left */ + ._user_heap_stack : + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(4); + } >RAM + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/variants/BLUEPILL_F103C8/ldscript.ld b/variants/BLUEPILL_F103C8/ldscript.ld new file mode 100644 index 0000000000..9789ba2d4c --- /dev/null +++ b/variants/BLUEPILL_F103C8/ldscript.ld @@ -0,0 +1,180 @@ +/** + ****************************************************************************** + * @file STM32F103CB_FLASH.h + * @author WI6LABS + * @version V1.0.0 + * @date 22-July-2016 + * @brief Linker script for STM32F103C8 Device with + * 64KByte FLASH, 20KByte 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) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = 0x20005000; /* end of RAM */ +/* Generate a link error if heap and stack don't fit into RAM */ +_Min_Heap_Size = 0x200;; /* required amount of heap */ +_Min_Stack_Size = 0x400;; /* required amount of stack */ + +/* Specify the memory areas */ +MEMORY +{ +FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 64K +RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .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 goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .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 */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _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 left */ + ._user_heap_stack : + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(4); + } >RAM + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/variants/BLUEPILL_F103C8/stm32f1xx_hal_conf.h b/variants/BLUEPILL_F103C8/stm32f1xx_hal_conf.h new file mode 100644 index 0000000000..ed08c3be81 --- /dev/null +++ b/variants/BLUEPILL_F103C8/stm32f1xx_hal_conf.h @@ -0,0 +1,367 @@ +/** + ****************************************************************************** + * @file stm32f1xx_hal_conf.h + * @author MCD Application Team + * @version V1.0.4 + * @date 29-April-2016 + * @brief HAL configuration template file. + * This file should be copied to the application folder and renamed + * to stm32f1xx_hal_conf.h. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F1xx_HAL_CONF_H +#define __STM32F1xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED +#define HAL_ADC_MODULE_ENABLED +//#define HAL_CAN_MODULE_ENABLED +//#define HAL_CEC_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED +//#define HAL_CRC_MODULE_ENABLED +//#define HAL_DAC_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +//#define HAL_ETH_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_GPIO_MODULE_ENABLED +#define HAL_HCD_MODULE_ENABLED +#define HAL_I2C_MODULE_ENABLED +//#define HAL_I2S_MODULE_ENABLED +//#define HAL_IRDA_MODULE_ENABLED +//#define HAL_IWDG_MODULE_ENABLED +//#define HAL_NAND_MODULE_ENABLED +//#define HAL_NOR_MODULE_ENABLED +//#define HAL_PCCARD_MODULE_ENABLED +#define HAL_PCD_MODULE_ENABLED +//#define HAL_PWR_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +//#define HAL_RTC_MODULE_ENABLED +//#define HAL_SD_MODULE_ENABLED +//#define HAL_SMARTCARD_MODULE_ENABLED +#define HAL_SPI_MODULE_ENABLED +//#define HAL_SRAM_MODULE_ENABLED +#define HAL_TIM_MODULE_ENABLED +#define HAL_UART_MODULE_ENABLED +//#define HAL_USART_MODULE_ENABLED +//#define HAL_WWDG_MODULE_ENABLED + +/* ########################## Oscillator Values adaptation ####################*/ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) +#if defined(USE_STM3210C_EVAL) + #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ +#else + #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ +#endif +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ +#endif /* LSE_VALUE */ + + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)0x000F) /*!< tick interrupt priority */ +#define USE_RTOS 0 +#define PREFETCH_ENABLE 1 + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/*#define USE_FULL_ASSERT 1*/ + + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2 +#define MAC_ADDR1 0 +#define MAC_ADDR2 0 +#define MAC_ADDR3 0 +#define MAC_ADDR4 0 +#define MAC_ADDR5 0 + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)8) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848 PHY Address*/ +#define DP83848_PHY_ADDRESS 0x01 +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FF) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF) + +#define PHY_READ_TO ((uint32_t)0x0000FFFF) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFF) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ + +#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */ +#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */ +#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */ + +#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */ +#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */ + +#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */ +#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */ + +#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */ +#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */ + + + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f1xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f1xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f1xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f1xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f1xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f1xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f1xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f1xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f1xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f1xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f1xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f1xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f1xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f1xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f1xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f1xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f1xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f1xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_PCCARD_MODULE_ENABLED + #include "stm32f1xx_hal_pccard.h" +#endif /* HAL_PCCARD_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f1xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f1xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f1xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f1xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f1xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f1xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f1xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f1xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f1xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f1xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f1xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F1xx_HAL_CONF_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/usb/usb_device.c b/variants/BLUEPILL_F103C8/usb/usb_device.c new file mode 100644 index 0000000000..bfd73bce0d --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usb_device.c @@ -0,0 +1,70 @@ +/** + ****************************************************************************** + * @file : USB_DEVICE + * @version : v1.0_Cube + * @brief : This file implements the USB Device + ****************************************************************************** + * + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +/* Includes ------------------------------------------------------------------*/ +#ifdef USBCON + +#include "usb_device.h" +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_cdc.h" +#include "usbd_cdc_if.h" + +/* USB Device Core handle declaration */ +USBD_HandleTypeDef hUsbDeviceFS; + +/* init function */ +void MX_USB_DEVICE_Init(void) +{ + /* Init Device Library,Add Supported Class and Start the library*/ + USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); + + USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC); + + USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS); + + USBD_Start(&hUsbDeviceFS); + +} + +#endif +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/usb/usb_device.h b/variants/BLUEPILL_F103C8/usb/usb_device.h new file mode 100644 index 0000000000..64aa35fccb --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usb_device.h @@ -0,0 +1,69 @@ +/** + ****************************************************************************** + * @file : USB_DEVICE + * @version : v1.0_Cube + * @brief : Header for usb_device file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __usb_device_H +#define __usb_device_H + +#ifdef USBCON + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f1xx.h" +#include "stm32f1xx_hal.h" +#include "usbd_def.h" + +extern USBD_HandleTypeDef hUsbDeviceFS; + +/* USB_Device init function */ +void MX_USB_DEVICE_Init(void); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif /*__usb_device_H */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/usb/usb_device_cdc.c b/variants/BLUEPILL_F103C8/usb/usb_device_cdc.c new file mode 100644 index 0000000000..9ce6bc71c3 --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usb_device_cdc.c @@ -0,0 +1,26 @@ +/* + * + * + * Copyright (C) 2017, STMicroelectronics - All Rights Reserved + * Author: YOUR NAME <> for STMicroelectronics. + * + * License type: GPLv2 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * 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 + * . + */ +#ifdef USBCON + +#include "usbd_cdc.c" + +#endif //USBCON diff --git a/variants/BLUEPILL_F103C8/usb/usbd_cdc_if.c b/variants/BLUEPILL_F103C8/usb/usbd_cdc_if.c new file mode 100644 index 0000000000..15659b15ef --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usbd_cdc_if.c @@ -0,0 +1,325 @@ +/** + ****************************************************************************** + * @file : usbd_cdc_if.c + * @brief : + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +#ifdef USBCON + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_cdc_if.h" +/* USER CODE BEGIN INCLUDE */ + +//#include "variant.h" +/* USER CODE END INCLUDE */ + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_CDC + * @brief usbd core module + * @{ + */ + +/** @defgroup USBD_CDC_Private_TypesDefinitions + * @{ + */ +/* USER CODE BEGIN PRIVATE_TYPES */ +/* USER CODE END PRIVATE_TYPES */ +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Defines + * @{ + */ +/* USER CODE BEGIN PRIVATE_DEFINES */ +/* Define size for the receive and transmit buffer over CDC */ +/* It's up to user to redefine and/or remove those define */ +#define APP_RX_DATA_SIZE CDC_SERIAL_BUFFER_SIZE +#define APP_TX_DATA_SIZE CDC_SERIAL_BUFFER_SIZE +/* USER CODE END PRIVATE_DEFINES */ +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Macros + * @{ + */ +/* USER CODE BEGIN PRIVATE_MACRO */ +/* USER CODE END PRIVATE_MACRO */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Variables + * @{ + */ +/* Create buffer for reception and transmission */ +/* It's up to user to redefine and/or remove those define */ +/* Received Data over USB are stored in this buffer */ +uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; + +/* Send Data over USB CDC are stored in this buffer */ +uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; + +/* USER CODE BEGIN PRIVATE_VARIABLES */ +/* USB handler declaration */ +/* Handle for USB Full Speed IP */ +//USBD_HandleTypeDef *hUsbDevice_0; +/* USER CODE BEGIN PRIVATE_VARIABLES */ +uint8_t dtr_pin = 0; //DTR pin is disabled +/* USER CODE END PRIVATE_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Variables + * @{ + */ + extern USBD_HandleTypeDef hUsbDeviceFS; +/* USER CODE BEGIN EXPORTED_VARIABLES */ +/* USER CODE END EXPORTED_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_FunctionPrototypes + * @{ + */ +static int8_t CDC_Init_FS (void); +static int8_t CDC_DeInit_FS (void); +static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length); +static int8_t CDC_Receive_FS (uint8_t* pbuf, uint32_t *Len); + +/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ +/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ + +/** + * @} + */ + +USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = +{ + CDC_Init_FS, + CDC_DeInit_FS, + CDC_Control_FS, + CDC_Receive_FS +}; + +/* Private functions ---------------------------------------------------------*/ +/** + * @brief CDC_Init_FS + * Initializes the CDC media low layer over the FS USB IP + * @param None + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Init_FS(void) +{ + /* USER CODE BEGIN 3 */ + /* Set Application Buffers */ + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); + USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); + return (USBD_OK); + /* USER CODE END 3 */ +} + +/** + * @brief CDC_DeInit_FS + * DeInitializes the CDC media low layer + * @param None + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_DeInit_FS(void) +{ + /* USER CODE BEGIN 4 */ + return (USBD_OK); + /* USER CODE END 4 */ +} + +/** + * @brief CDC_Control_FS + * Manage the CDC class requests + * @param cmd: Command code + * @param pbuf: Buffer containing command data (request parameters) + * @param length: Number of data to be sent (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length) +{ + /* USER CODE BEGIN 5 */ + switch (cmd) + { + case CDC_SEND_ENCAPSULATED_COMMAND: + + break; + + case CDC_GET_ENCAPSULATED_RESPONSE: + + break; + + case CDC_SET_COMM_FEATURE: + + break; + + case CDC_GET_COMM_FEATURE: + + break; + + case CDC_CLEAR_COMM_FEATURE: + + break; + + /*******************************************************************************/ + /* Line Coding Structure */ + /*-----------------------------------------------------------------------------*/ + /* Offset | Field | Size | Value | Description */ + /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ + /* 4 | bCharFormat | 1 | Number | Stop bits */ + /* 0 - 1 Stop bit */ + /* 1 - 1.5 Stop bits */ + /* 2 - 2 Stop bits */ + /* 5 | bParityType | 1 | Number | Parity */ + /* 0 - None */ + /* 1 - Odd */ + /* 2 - Even */ + /* 3 - Mark */ + /* 4 - Space */ + /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ + /*******************************************************************************/ + case CDC_SET_LINE_CODING: + + break; + + case CDC_GET_LINE_CODING: + + break; + + case CDC_SET_CONTROL_LINE_STATE: + dtr_pin++; //DTR pin is enabled + break; + + case CDC_SEND_BREAK: + + break; + + default: + break; + } + + return (USBD_OK); + /* USER CODE END 5 */ +} + +/** + * @brief CDC_Receive_FS + * Data received over USB OUT endpoint are sent over CDC interface + * through this function. + * + * @note + * This function will block any OUT packet reception on USB endpoint + * untill exiting this function. If you exit this function before transfer + * is complete on CDC interface (ie. using DMA controller) it will result + * in receiving more data while previous ones are still not sent. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len) +{ + /* USER CODE BEGIN 6 */ + /* Four byte is the magic pack "1EAF" that puts the MCU into bootloader. */ + if(*Len >= 4){ + /** + * Check if the incoming contains the string "1EAF". + * If yes, check if the DTR has been set, to put the MCU into the bootloader mode. + */ + if(dtr_pin > 3){ + if((Buf[0] == '1')&&(Buf[1] == 'E')&&(Buf[2] == 'A')&&(Buf[3] == 'F')){ + HAL_NVIC_SystemReset(); + } + dtr_pin = 0; + } + } + + uint16_t len = *Len; + USBSerial_Rx_Handler((uint8_t *)&Buf[0], len); + USBD_CDC_ReceivePacket(&hUsbDeviceFS); + + //USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); + //USBD_CDC_ReceivePacket(&hUsbDeviceFS); + //HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); + return (USBD_OK); + /* USER CODE END 6 */ +} + +/** + * @brief CDC_Transmit_FS + * Data send over USB IN endpoint are sent over CDC interface + * through this function. + * @note + * + * + * @param Buf: Buffer of data to be send + * @param Len: Number of data to be send (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY + */ +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) +{ + uint8_t result = USBD_OK; + /* USER CODE BEGIN 7 */ + USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; + if (hcdc->TxState != 0){ + return USBD_BUSY; + } + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); + result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); + /* USER CODE END 7 */ + return result; +} + +/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ +/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ + +/** + * @} + */ + +/** + * @} + */ + +#endif + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/usb/usbd_cdc_if.h b/variants/BLUEPILL_F103C8/usb/usbd_cdc_if.h new file mode 100644 index 0000000000..02856661f2 --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usbd_cdc_if.h @@ -0,0 +1,129 @@ +/** + ****************************************************************************** + * @file : usbd_cdc_if.h + * @brief : Header for usbd_cdc_if file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CDC_IF_H +#define __USBD_CDC_IF_H + +#ifdef USBCON + +#define CDC_SERIAL_BUFFER_SIZE 128 //USBSerial buffer data length + +#ifdef __cplusplus + extern "C" { +#endif +/* Includes ------------------------------------------------------------------*/ +#include "usbd_cdc.h" +/* USER CODE BEGIN INCLUDE */ +/* USER CODE END INCLUDE */ + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_CDC_IF + * @brief header + * @{ + */ + +/** @defgroup USBD_CDC_IF_Exported_Defines + * @{ + */ +/* USER CODE BEGIN EXPORTED_DEFINES */ +uint8_t CDC_getTransmitterStatus(void); +/* USER CODE END EXPORTED_DEFINES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Types + * @{ + */ +/* USER CODE BEGIN EXPORTED_TYPES */ +/* USER CODE END EXPORTED_TYPES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Macros + * @{ + */ +/* USER CODE BEGIN EXPORTED_MACRO */ +/* USER CODE END EXPORTED_MACRO */ + +/** + * @} + */ + +/** @defgroup USBD_AUDIO_IF_Exported_Variables + * @{ + */ +extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; + +/* USER CODE BEGIN EXPORTED_VARIABLES */ +/* USER CODE END EXPORTED_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype + * @{ + */ +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); + +/* USER CODE BEGIN EXPORTED_FUNCTIONS */ +extern void USBSerial_Rx_Handler(uint8_t *data, uint16_t len); +/* USER CODE END EXPORTED_FUNCTIONS */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + +#endif /* __USBD_CDC_IF_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/usb/usbd_conf.c b/variants/BLUEPILL_F103C8/usb/usbd_conf.c new file mode 100644 index 0000000000..25278996b3 --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usbd_conf.c @@ -0,0 +1,514 @@ +/** + ****************************************************************************** + * @file : usbd_conf.c + * @version : v1.0_Cube + * @brief : This file implements the board support package for the USB device library + ****************************************************************************** + * + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +#ifdef USBCON + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f1xx.h" +#include "stm32f1xx_hal.h" +#include "usbd_def.h" +#include "usbd_core.h" +#include "usbd_cdc.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +PCD_HandleTypeDef hpcd_USB_FS; +void Error_Handler(void); + +/* USER CODE BEGIN 0 */ +/* USER CODE END 0 */ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ +/* USER CODE BEGIN 1 */ +/* USER CODE END 1 */ +void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); + +/******************************************************************************* + LL Driver Callbacks (PCD -> USB Device Library) +*******************************************************************************/ +/* MSP Init */ + +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) +{ + if(pcdHandle->Instance==USB) + { + /* USER CODE BEGIN USB_MspInit 0 */ + + /* USER CODE END USB_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_USB_CLK_ENABLE(); + + /* Peripheral interrupt init */ + HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); + /* USER CODE BEGIN USB_MspInit 1 */ + + /* USER CODE END USB_MspInit 1 */ + } +} + +void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) +{ + if(pcdHandle->Instance==USB) + { + /* USER CODE BEGIN USB_MspDeInit 0 */ + + /* USER CODE END USB_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USB_CLK_DISABLE(); + + /* Peripheral interrupt Deinit*/ + HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); + + /* USER CODE BEGIN USB_MspDeInit 1 */ + + /* USER CODE END USB_MspDeInit 1 */ + } +} + +/** + * @brief Setup Stage callback + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); +} + +/** + * @brief Data Out Stage callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint Number + * @retval None + */ +void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +{ + USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); +} + +/** + * @brief Data In Stage callback.. + * @param hpcd: PCD handle + * @param epnum: Endpoint Number + * @retval None + */ +void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +{ + USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); +} + +/** + * @brief SOF callback. + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); +} + +/** + * @brief Reset callback. + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_SpeedTypeDef speed = USBD_SPEED_FULL; + + /*Set USB Current Speed*/ + switch (hpcd->Init.speed) + { + case PCD_SPEED_FULL: + speed = USBD_SPEED_FULL; + break; + + default: + speed = USBD_SPEED_FULL; + break; + } + USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); + + /*Reset Device*/ + USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); +} + +/** + * @brief Suspend callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +{ + /* Inform USB library that core enters in suspend Mode */ + USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); + /*Enter in STOP mode */ + /* USER CODE BEGIN 2 */ + if (hpcd->Init.low_power_enable) + { + /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */ + SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + } + /* USER CODE END 2 */ +} + +/** + * @brief Resume callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +{ + /* USER CODE BEGIN 3 */ + /* USER CODE END 3 */ + USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); + +} + +/** + * @brief ISOOUTIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint Number + * @retval None + */ +void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +{ + USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); +} + +/** + * @brief ISOINIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint Number + * @retval None + */ +void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +{ + USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); +} + +/** + * @brief ConnectCallback callback. + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); +} + +/** + * @brief Disconnect callback. + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); +} + +/******************************************************************************* + LL Driver Interface (USB Device Library --> PCD) +*******************************************************************************/ +/** + * @brief Initializes the Low Level portion of the Device driver. + * @param pdev: Device handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) +{ + /* Init USB_IP */ + /* Link The driver to the stack */ + hpcd_USB_FS.pData = pdev; + pdev->pData = &hpcd_USB_FS; + + hpcd_USB_FS.Instance = USB; + hpcd_USB_FS.Init.dev_endpoints = 8; + hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_8; + hpcd_USB_FS.Init.low_power_enable = DISABLE; + hpcd_USB_FS.Init.lpm_enable = DISABLE; + hpcd_USB_FS.Init.battery_charging_enable = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) + { + Error_Handler(); + } + + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); + return USBD_OK; +} + +/** + * @brief De-Initializes the Low Level portion of the Device driver. + * @param pdev: Device handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev) +{ + HAL_PCD_DeInit((PCD_HandleTypeDef*)pdev->pData); + return USBD_OK; +} + +/** + * @brief Starts the Low Level portion of the Device driver. + * @param pdev: Device handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) +{ + HAL_PCD_Start((PCD_HandleTypeDef*)pdev->pData); + return USBD_OK; +} + +/** + * @brief Stops the Low Level portion of the Device driver. + * @param pdev: Device handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev) +{ + HAL_PCD_Stop((PCD_HandleTypeDef*) pdev->pData); + return USBD_OK; +} + +/** + * @brief Opens an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @param ep_type: Endpoint Type + * @param ep_mps: Endpoint Max Packet Size + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, + uint8_t ep_addr, + uint8_t ep_type, + uint16_t ep_mps) +{ + HAL_PCD_EP_Open((PCD_HandleTypeDef*) pdev->pData, + ep_addr, + ep_mps, + ep_type); + + return USBD_OK; +} + +/** + * @brief Closes an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_PCD_EP_Close((PCD_HandleTypeDef*) pdev->pData, ep_addr); + return USBD_OK; +} + +/** + * @brief Flushes an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_PCD_EP_Flush((PCD_HandleTypeDef*) pdev->pData, ep_addr); + return USBD_OK; +} + +/** + * @brief Sets a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_PCD_EP_SetStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); + return USBD_OK; +} + +/** + * @brief Clears a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_PCD_EP_ClrStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); + return USBD_OK; +} + +/** + * @brief Returns Stall condition. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval Stall (1: Yes, 0: No) + */ +uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; + + if((ep_addr & 0x80) == 0x80) + { + return hpcd->IN_ep[ep_addr & 0x7F].is_stall; + } + else + { + return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; + } +} +/** + * @brief Assigns a USB address to the device. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr) +{ + HAL_PCD_SetAddress((PCD_HandleTypeDef*) pdev->pData, dev_addr); + return USBD_OK; +} + +/** + * @brief Transmits data over an endpoint. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @param pbuf: Pointer to data to be sent + * @param size: Data size + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, + uint8_t ep_addr, + uint8_t *pbuf, + uint16_t size) +{ + HAL_PCD_EP_Transmit((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); + return USBD_OK; +} + +/** + * @brief Prepares an endpoint for reception. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @param pbuf: Pointer to data to be received + * @param size: Data size + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, + uint8_t ep_addr, + uint8_t *pbuf, + uint16_t size) +{ + HAL_PCD_EP_Receive((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); + return USBD_OK; +} + +/** + * @brief Returns the last transfered packet size. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval Recived Data Size + */ +uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); +} + +/** + * @brief Delays routine for the USB Device Library. + * @param Delay: Delay in ms + * @retval None + */ +void USBD_LL_Delay (uint32_t Delay) +{ + HAL_Delay(Delay); +} + +/** + * @brief static single allocation. + * @param size: size of allocated memory + * @retval None + */ +void *USBD_static_malloc(uint32_t size) +{ + static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ + return mem; +} + +/** + * @brief Dummy memory free + * @param *p pointer to allocated memory address + * @retval None + */ +void USBD_static_free(void *p) +{ + +} + +/** +* @brief Software Device Connection +* @param hpcd: PCD handle +* @param state: connection state (0 : disconnected / 1: connected) +* @retval None +*/ +void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) +{ +/* USER CODE BEGIN 5 */ + if (state == 1) + { + /* Configure Low Connection State */ + + } + else + { + /* Configure High Connection State */ + + } +/* USER CODE END 5 */ +} + +#endif + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/usb/usbd_conf.h b/variants/BLUEPILL_F103C8/usb/usbd_conf.h new file mode 100644 index 0000000000..cb4395444d --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usbd_conf.h @@ -0,0 +1,179 @@ +/** + ****************************************************************************** + * @file : usbd_conf.h + * @version : v1.0_Cube + * @brief : Header for usbd_conf file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CONF__H__ +#define __USBD_CONF__H__ + +#ifdef USBCON + +#ifdef __cplusplus + extern "C" { +#endif +/* Includes ------------------------------------------------------------------*/ +#include +#include +#include +#include "stm32f1xx.h" +#include "stm32f1xx_hal.h" +#include "usbd_def.h" + +/** @addtogroup USBD_OTG_DRIVER + * @{ + */ + +/** @defgroup USBD_CONF + * @brief usb otg low level driver configuration file + * @{ + */ + +/** @defgroup USBD_CONF_Exported_Defines + * @{ + */ + +/*---------- -----------*/ +#define USBD_MAX_NUM_INTERFACES 1 +/*---------- -----------*/ +#define USBD_MAX_NUM_CONFIGURATION 1 +/*---------- -----------*/ +#define USBD_MAX_STR_DESC_SIZ 512 +/*---------- -----------*/ +#define USBD_SUPPORT_USER_STRING 0 +/*---------- -----------*/ +#define USBD_DEBUG_LEVEL 0 +/*---------- -----------*/ +#define USBD_SELF_POWERED 1 +/*---------- -----------*/ +#define USBD_CDC_INTERVAL 1000 +/*---------- -----------*/ +#define MAX_STATIC_ALLOC_SIZE 512 +/****************************************/ +/* #define for FS and HS identification */ +#define DEVICE_FS 0 + +/** @defgroup USBD_Exported_Macros + * @{ + */ + +/* Memory management macros */ +#define USBD_malloc (uint32_t *)USBD_static_malloc +#define USBD_free USBD_static_free +#define USBD_memset /* Not used */ +#define USBD_memcpy /* Not used */ + +#define USBD_Delay HAL_Delay + +/* For footprint reasons and since only one allocation is handled in the HID class + driver, the malloc/free is changed into a static allocation method */ +void *USBD_static_malloc(uint32_t size); +void USBD_static_free(void *p); + +/* DEBUG macros */ +#if (USBD_DEBUG_LEVEL > 0) +#define USBD_UsrLog(...) printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_UsrLog(...) +#endif + + +#if (USBD_DEBUG_LEVEL > 1) + +#define USBD_ErrLog(...) printf("ERROR: ") ;\ + printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_ErrLog(...) +#endif + + +#if (USBD_DEBUG_LEVEL > 2) +#define USBD_DbgLog(...) printf("DEBUG : ") ;\ + printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_DbgLog(...) +#endif + +/** + * @} + */ + + + +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Types + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Variables + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_FunctionsPrototype + * @{ + */ +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif + +#endif /*__USBD_CONF__H__*/ + +/** + * @} + */ + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/usb/usbd_desc.c b/variants/BLUEPILL_F103C8/usb/usbd_desc.c new file mode 100644 index 0000000000..c6a2955c59 --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usbd_desc.c @@ -0,0 +1,300 @@ +/** + ****************************************************************************** + * @file : usbd_desc.c + * @version : v1.0_Cube + * @brief : This file implements the USB Device descriptors + ****************************************************************************** + * + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ +#ifdef USBCON + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_conf.h" + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_DESC + * @brief USBD descriptors module + * @{ + */ + +/** @defgroup USBD_DESC_Private_TypesDefinitions + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Defines + * @{ + */ +#define USBD_VID 1155 +#define USBD_LANGID_STRING 1033 +#define USBD_MANUFACTURER_STRING "STMicroelectronics" +#define USBD_PID_FS 22336 +#define USBD_PRODUCT_STRING_FS "STM32 Virtual ComPort" +#define USBD_SERIALNUMBER_STRING_FS "00000000001A" +#define USBD_CONFIGURATION_STRING_FS "CDC Config" +#define USBD_INTERFACE_STRING_FS "CDC Interface" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0*/ +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Variables + * @{ + */ +uint8_t * USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_ManufacturerStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_ProductStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); + +#ifdef USB_SUPPORT_USER_STRING_DESC +uint8_t * USBD_FS_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx , uint16_t *length); +#endif /* USB_SUPPORT_USER_STRING_DESC */ + +USBD_DescriptorsTypeDef FS_Desc = +{ + USBD_FS_DeviceDescriptor, + USBD_FS_LangIDStrDescriptor, + USBD_FS_ManufacturerStrDescriptor, + USBD_FS_ProductStrDescriptor, + USBD_FS_SerialStrDescriptor, + USBD_FS_ConfigStrDescriptor, + USBD_FS_InterfaceStrDescriptor, +}; + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif +/* USB Standard Device Descriptor */ +__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = + { + 0x12, /*bLength */ + USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ + 0x00, /* bcdUSB */ + 0x02, + 0x02, /*bDeviceClass*/ + 0x02, /*bDeviceSubClass*/ + 0x00, /*bDeviceProtocol*/ + USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ + LOBYTE(USBD_VID), /*idVendor*/ + HIBYTE(USBD_VID), /*idVendor*/ + LOBYTE(USBD_PID_FS), /*idVendor*/ + HIBYTE(USBD_PID_FS), /*idVendor*/ + 0x00, /*bcdDevice rel. 2.00*/ + 0x02, + USBD_IDX_MFC_STR, /*Index of manufacturer string*/ + USBD_IDX_PRODUCT_STR, /*Index of product string*/ + USBD_IDX_SERIAL_STR, /*Index of serial number string*/ + USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ + } ; +/* USB_DeviceDescriptor */ + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif + +/* USB Standard Device Descriptor */ +__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = +{ + USB_LEN_LANGID_STR_DESC, + USB_DESC_TYPE_STRING, + LOBYTE(USBD_LANGID_STRING), + HIBYTE(USBD_LANGID_STRING), +}; + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif +__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_FunctionPrototypes + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Functions + * @{ + */ + +/** +* @brief USBD_FS_DeviceDescriptor +* return the device descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + *length = sizeof(USBD_FS_DeviceDesc); + return USBD_FS_DeviceDesc; +} + +/** +* @brief USBD_FS_LangIDStrDescriptor +* return the LangID string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + *length = sizeof(USBD_LangIDDesc); + return USBD_LangIDDesc; +} + +/** +* @brief USBD_FS_ProductStrDescriptor +* return the product string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_ProductStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + if(speed == 0) + { + USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); + } + else + { + USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** +* @brief USBD_FS_ManufacturerStrDescriptor +* return the manufacturer string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_ManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length); + return USBD_StrDesc; +} + +/** +* @brief USBD_FS_SerialStrDescriptor +* return the serial number string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length); + } + else + { + USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** +* @brief USBD_FS_ConfigStrDescriptor +* return the configuration string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); + } + else + { + USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** +* @brief USBD_HS_InterfaceStrDescriptor +* return the interface string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + if(speed == 0) + { + USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); + } + else + { + USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#endif + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/usb/usbd_desc.h b/variants/BLUEPILL_F103C8/usb/usbd_desc.h new file mode 100644 index 0000000000..521441af6c --- /dev/null +++ b/variants/BLUEPILL_F103C8/usb/usbd_desc.h @@ -0,0 +1,107 @@ +/** + ****************************************************************************** + * @file : usbd_desc.h + * @version : v1.0_Cube + * @brief : Header for usbd_desc file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_DESC__H__ +#define __USBD_DESC__H__ + +#ifdef USBCON + +#ifdef __cplusplus + extern "C" { +#endif +/* Includes ------------------------------------------------------------------*/ +#include "usbd_def.h" + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USB_DESC + * @brief general defines for the usb device library file + * @{ + */ + +/** @defgroup USB_DESC_Exported_Defines + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_TypesDefinitions + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_Variables + * @{ + */ +extern USBD_DescriptorsTypeDef FS_Desc; +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_FunctionsPrototype + * @{ + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif + +#endif /* __USBD_DESC_H */ + +/** + * @} + */ + +/** +* @} +*/ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/BLUEPILL_F103C8/variant.cpp b/variants/BLUEPILL_F103C8/variant.cpp new file mode 100644 index 0000000000..4e92dcac48 --- /dev/null +++ b/variants/BLUEPILL_F103C8/variant.cpp @@ -0,0 +1,201 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Pin number +const PinName digitalPin[] = { + // Right side + PA0, //D0 + PA1, //D1 + PA2, //D2 + PA3, //D3 + PA4, //D4 + PA5, //D5 + PA6, //D6 + PA7, //D7 + PB0, //D8 + PB1, //D9 + PB10, //D10 + PB11, //D11 + // Left side + PB12, //D12 + PB13, //D13 + PB14, //D14 + PB15, //D15 + PA8, //D16 + PA9, //D17 + PA10, //D18 + PA11, //D19 + PA12, //D20 + PA15, //D21 + PB3, //D22 + PB4, //D23 + PB5, //D24 + PB6, //D25 + PB7, //D26 + PB8, //D27 + PB9, //D28 + PC13, //D29 - LED + // Duplicated pins in order to be aligned with PinMap_ADC + PA0, //D30/A0 = D0 + PA1, //D31/A1 = D1 + PA2, //D32/A2 = D2 + PA3, //D33/A3 = D3 + PA4, //D34/A4 = D4 + PA5, //D35/A5 = D5 + PA6, //D36/A6 = D6 + PA7, //D37/A7 = D7 + PB0, //D38/A8 = D8 + PB1 //D39/A9 = D9 +}; + +#ifdef __cplusplus +} +#endif + +/* + * UART objects + */ + +HardwareSerial Serial1(PA10, PA9); +#ifdef ENABLE_SERIAL2 +HardwareSerial Serial2(PA3, PA2); +#endif +#ifdef ENABLE_SERIAL3 +HardwareSerial Serial3(PB11, PB10); +#endif + +#if defined(SERIAL_USB) && defined(USBCON) +USBSerial Serial; //available on PA11/PA12 +#endif + +void serialEvent1() __attribute__((weak)); +void serialEvent1() { } +#ifdef ENABLE_SERIAL2 +void serialEvent2() __attribute__((weak)); +void serialEvent2() { } +#endif +#ifdef ENABLE_SERIAL3 +void serialEvent3() __attribute__((weak)); +void serialEvent3() { } +#endif + +#if defined(SERIAL_USB) && defined(USBCON) +void serialEvent() __attribute__((weak)); +void serialEvent() { } +#endif + +void serialEventRun(void) +{ + if (Serial1.available()) serialEvent1(); +#ifdef ENABLE_SERIAL2 + if (Serial2.available()) serialEvent2(); +#endif +#ifdef ENABLE_SERIAL3 + if (Serial3.available()) serialEvent3(); +#endif + +#if defined(SERIAL_USB) && defined(USBCON) + if (Serial.available()) serialEvent(); +#endif +} + +// ---------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(SERIAL_USB) && defined(USBCON) +void USBSerial_Rx_Handler(uint8_t *data, uint16_t len){ + Serial.CDC_RxHandler(data, len); +} +#endif + +/** + * @brief System Clock Configuration + * The system Clock is configured as follow : + * System Clock source = PLL (HSE) + * SYSCLK(Hz) = 72000000 + * HCLK(Hz) = 72000000 + * AHB Prescaler = 1 + * APB1 Prescaler = 2 + * APB2 Prescaler = 1 + * PLL_Source = HSE + * PLL_Mul = 9 + * Flash Latency(WS) = 2 + * ADC Prescaler = 6 + * USB Prescaler = 1.5 + * @param None + * @retval None + */ +WEAK void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInit; + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.LSEState = RCC_LSE_OFF; + RCC_OscInitStruct.HSIState = RCC_HSI_OFF; + RCC_OscInitStruct.HSICalibrationValue = 16; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; + 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) + { + while(1); + } + + 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) + { + while(1); + } + + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB; + PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + while(1); + } + + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); + + HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); + + /* SysTick_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); +} + +#ifdef __cplusplus +} +#endif diff --git a/variants/BLUEPILL_F103C8/variant.h b/variants/BLUEPILL_F103C8/variant.h new file mode 100644 index 0000000000..769764a4b9 --- /dev/null +++ b/variants/BLUEPILL_F103C8/variant.h @@ -0,0 +1,148 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#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 { + 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, + DEND +}; + +enum { + A_START_AFTER = D29, + A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, + 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 29 +#define LED_GREEN LED_BUILTIN + +//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 4 + +//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 SS1 8 +#define SS2 9 +#define SS3 10 +#define MOSI 7 +#define MISO 6 +#define SCLK 5 +#define SCK SCLK + +//I2C Definitions +#define SDA 26 +#define SCL 25 + +//Timer Definitions +//Do not use timer used by PWM pins when possible. See PinMap_PWM. +#define TIMER_TONE TIM4 +#define TIMER_UART_EMULATED TIM4 + +//Do not use basic timer: OC is required +#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work + +#define DEBUG_UART ((USART_TypeDef *) USART1) + +// Serial Pin Firmata +#define PIN_SERIAL_RX 18 +#define PIN_SERIAL_TX 17 +#define PIN_SERIAL1_RX 3 +#define PIN_SERIAL1_TX 2 +#define PIN_SERIAL2_RX 11 +#define PIN_SERIAL2_TX 10 + +#if defined(SERIAL_USB) && defined(USBCON) +#define USB_DISC_PIN 20 //PA12 = USB Plus (+) pin number. That pin is normally pulled up to 3.3v by a 1.5k resistor +#endif + +#ifdef __cplusplus +} // extern "C" +#endif +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern HardwareSerial Serial1; +extern HardwareSerial Serial2; +extern HardwareSerial Serial3; + +#if defined(SERIAL_USB) && defined(USBCON) +extern USBSerial Serial; +#else +#define Serial Serial1 +#endif + +// 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_USBVIRTUAL Serial +#define SERIAL_PORT_HARDWARE Serial1 +#endif + +#endif /* _VARIANT_ARDUINO_STM32_ */ From 1502e66742a12b3868374bbfbe0c570e7bc3c297 Mon Sep 17 00:00:00 2001 From: fpr Date: Thu, 29 Jun 2017 10:58:27 +0200 Subject: [PATCH 11/30] DISCO_F100RB (STM32VLDiscovery) added. Signed-off-by: fpr --- boards.txt | 17 +- cores/arduino/stm32/stm32_def.h | 5 +- cores/arduino/stm32/stm32_def_build.h | 6 +- variants/DISCO_F100RB/PeripheralPins.c | 206 ++++++++++++ variants/DISCO_F100RB/ldscript.ld | 180 ++++++++++ variants/DISCO_F100RB/stm32f1xx_hal_conf.h | 367 +++++++++++++++++++++ variants/DISCO_F100RB/variant.cpp | 201 +++++++++++ variants/DISCO_F100RB/variant.h | 146 ++++++++ 8 files changed, 1124 insertions(+), 4 deletions(-) create mode 100644 variants/DISCO_F100RB/PeripheralPins.c create mode 100644 variants/DISCO_F100RB/ldscript.ld create mode 100644 variants/DISCO_F100RB/stm32f1xx_hal_conf.h create mode 100644 variants/DISCO_F100RB/variant.cpp create mode 100644 variants/DISCO_F100RB/variant.h diff --git a/boards.txt b/boards.txt index e74d31409f..ed40e91023 100644 --- a/boards.txt +++ b/boards.txt @@ -94,7 +94,6 @@ Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_size=131071 Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_data_size=20479 Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.mcu=cortex-m3 Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.f_cpu=72000000L -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.usb_product="NUCLEO-F103RB" Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.board=NUCLEO_F103RB Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.series=STM32F1xx Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.variant=NUCLEO_F103RB @@ -207,6 +206,22 @@ Disco.build.core=arduino Disco.build.board=Disco Disco.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.enable_Serialx} +#DISCO_F100RB board + +Disco_board.menu.Disco_board.DISCO_F100RB=STM32F100RB-DISCVL +Disco_board.menu.Disco_board.DISCO_F100RB.node=DIS_F100RB +Disco_board.menu.Disco_board.DISCO_F100RB.upload.maximum_size=131071 +Disco_board.menu.Disco_board.DISCO_F100RB.upload.maximum_data_size=8192 +Disco_board.menu.Disco_board.DISCO_F100RB.build.mcu=cortex-m3 +Disco_board.menu.Disco_board.DISCO_F100RB.build.f_cpu=24000000L +Disco_board.menu.Disco_board.DISCO_F100RB.build.board=DISCO_F100RB +Disco_board.menu.Disco_board.DISCO_F100RB.build.series=STM32F1xx +Disco_board.menu.Disco_board.DISCO_F100RB.build.variant=DISCO_F100RB +Disco_board.menu.Disco_board.DISCO_F100RB.build.cmsis_lib_gcc=arm_cortexM3l_math +#To enable Serial1 (USART1 on PA10, PA9) add -DENABLE_SERIAL1 +#To enable Serial2 (USART3 on PB11, PB10) add -DENABLE_SERIAL2 +Disco_board.menu.Disco_board.DISCO_F100RB.build.extra_flags=-DSTM32F100xB + # DISCO_F407VG board # Support: USB HID Disco.menu.board_part_num.DISCO_F407VG=STM32F407G-DISC1 diff --git a/cores/arduino/stm32/stm32_def.h b/cores/arduino/stm32/stm32_def.h index a0a6b09a60..0e4dfd1e6c 100644 --- a/cores/arduino/stm32/stm32_def.h +++ b/cores/arduino/stm32/stm32_def.h @@ -57,7 +57,10 @@ #define I2C1_EV_IRQn I2C1_IRQn #elif defined(STM32F1xx) - +#define DAC1 DAC +#define TIM15_IRQn TIM1_BRK_TIM15_IRQn +#define TIM16_IRQn TIM1_UP_TIM16_IRQn +#define TIM17_IRQn TIM1_TRG_COM_TIM17_IRQn #elif defined(STM32F2xx) #elif defined(STM32F3xx) diff --git a/cores/arduino/stm32/stm32_def_build.h b/cores/arduino/stm32/stm32_def_build.h index 798ae4cd00..d9a891d8a2 100644 --- a/cores/arduino/stm32/stm32_def_build.h +++ b/cores/arduino/stm32/stm32_def_build.h @@ -26,6 +26,10 @@ #define CMSIS_STARTUP_FILE "startup_stm32f091xc.s" #elif defined(STM32F030x8) #define CMSIS_STARTUP_FILE "startup_stm32f030x8.s" +#elif defined(STM32F100xB) +#define CMSIS_STARTUP_FILE "startup_stm32f100xb.s" +#elif defined(STM32F103xB) +#define CMSIS_STARTUP_FILE "startup_stm32f103xb.s" #elif defined(STM32F303xE) #define CMSIS_STARTUP_FILE "startup_stm32f303xe.s" #elif defined(STM32F407xx) @@ -40,8 +44,6 @@ #define CMSIS_STARTUP_FILE "startup_stm32l476xx.s" #elif defined(STM32L432xx) #define CMSIS_STARTUP_FILE "startup_stm32l432xx.s" -#elif defined(STM32F103xB) -#define CMSIS_STARTUP_FILE "startup_stm32f103xb.s" #else #error UNKNOWN CHIP #endif diff --git a/variants/DISCO_F100RB/PeripheralPins.c b/variants/DISCO_F100RB/PeripheralPins.c new file mode 100644 index 0000000000..15b11c4f8e --- /dev/null +++ b/variants/DISCO_F100RB/PeripheralPins.c @@ -0,0 +1,206 @@ +/* + ******************************************************************************* + * Copyright (c) 2016, 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 "Arduino.h" +#include "PeripheralPins.h" + +// ===== +// Note: Commented lines are alternative possibilities which are not used per default. +// If you change them, you will have to know what you do +// ===== + + +//*** ADC *** + +const PinMap PinMap_ADC[] = { + {PA0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 + {PA1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 + {PA2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 + {PA3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 + {PA4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 + {PA5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 + {PA6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 + {PA7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 + {PB0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 + {PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 + {PC0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 + {PC1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 + {PC2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 + {PC3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 + {PC4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 + {PC5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 + {NC, NC, 0} +}; + +//*** DAC *** + +const PinMap PinMap_DAC[] = { + {PA4, DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC_OUT1 + {PA5, DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC_OUT2 + {NC, NC, 0} +}; + +//*** I2C *** + +const PinMap PinMap_I2C_SDA[] = { + {PB7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {PB9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 + {PB11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_I2C_SCL[] = { + {PB6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {PB8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 + {PB10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {NC, NC, 0} +}; + +//*** PWM *** + +const PinMap PinMap_PWM[] = { + {PA0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM2_CH1 + {PA1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM2_CH2 + // {PA2, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM15_CH1 + {PA2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM2_CH3 + // {PA3, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM15_CH2 + {PA3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM2_CH4 + // {PA6, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM16_CH1 + {PA6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM3_CH1 + // {PA7, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM17_CH1 + // {PA7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 1, 1)}, // TIM1_CH1N - GPIO_PartialRemap_TIM1 + {PA7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM3_CH2 + {PA8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM1_CH1 + {PA9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM1_CH2 + {PA10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM1_CH3 + {PA11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM1_CH4 + {PA15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 1, 0)}, // TIM2_CH1 - GPIO_FullRemap_TIM2 + // {PB0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 2, 1)}, // TIM1_CH2N - GPIO_PartialRemap_TIM1 + {PB0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM3_CH3 + // {PB1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 3, 1)}, // TIM1_CH3N - GPIO_PartialRemap_TIM1 + {PB1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM3_CH4 + {PB3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 2, 0)}, // TIM2_CH2 - GPIO_FullRemap_TIM2 + {PB4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 1, 0)}, // TIM3_CH1 - GPIO_PartialRemap_TIM3 + {PB5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 2, 0)}, // TIM3_CH2 - GPIO_PartialRemap_TIM3 + // {PB6, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM16_CH1N + {PB6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM4_CH1 + // {PB7, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM17_CH1N + {PB7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM4_CH2 + // {PB8, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM16_CH1 + {PB8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM4_CH3 + // {PB9, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM17_CH1 + {PB9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM4_CH4 + {PB10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 3, 0)}, // TIM2_CH3 - GPIO_FullRemap_TIM2 + {PB11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 4, 0)}, // TIM2_CH4 - GPIO_FullRemap_TIM2 + {PB13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM1_CH1N + // {PB14, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM15_CH1 + {PB14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 1)}, // TIM1_CH2N + // {PB15, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM15_CH1N + // {PB15, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM15_CH2 + {PB15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 1)}, // TIM1_CH3N + {PC6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 1, 0)}, // TIM3_CH1 - GPIO_FullRemap_TIM3 + {PC7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 2, 0)}, // TIM3_CH2 - GPIO_FullRemap_TIM3 + {PC8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 3, 0)}, // TIM3_CH3 - GPIO_FullRemap_TIM3 + {PC9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 4, 0)}, // TIM3_CH4 - GPIO_FullRemap_TIM3 + {NC, NC, 0} +}; + +//*** SERIAL *** + +const PinMap PinMap_UART_TX[] = { + {PA2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 + {PB10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PC10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 5)}, // GPIO_PartialRemap_USART3 + {NC, NC, 0} +}; + +const PinMap PinMap_UART_RX[] = { + {PA3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 + {PB11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PC11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 5)}, // GPIO_PartialRemap_USART3 + {NC, NC, 0} +}; + +const PinMap PinMap_UART_RTS[] = { + {PA1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_UART_CTS[] = { + {PA0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +//*** SPI *** + +const PinMap PinMap_SPI_MOSI[] = { + {PA7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_MISO[] = { + {PA6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_SCLK[] = { + {PA5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_SSEL[] = { + {PA4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +//*** CAN *** + +const PinMap PinMap_CAN_RD[] = { + {NC, NC, 0} +}; + +const PinMap PinMap_CAN_TD[] = { + {NC, NC, 0} +}; diff --git a/variants/DISCO_F100RB/ldscript.ld b/variants/DISCO_F100RB/ldscript.ld new file mode 100644 index 0000000000..30691dde20 --- /dev/null +++ b/variants/DISCO_F100RB/ldscript.ld @@ -0,0 +1,180 @@ +/** + ****************************************************************************** + * @file STM32F103RB_FLASH.ld + * @author WI6LABS + * @version V1.0.1 + * @date 21-September-2016 + * @brief Linker script for STM32F100RB Device with + * 128KByte FLASH, 8KByte 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) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + + /* Entry Point */ + ENTRY(Reset_Handler) + + /* Highest address of the user mode stack */ + _estack = 0x20002000; /* end of RAM */ + /* Generate a link error if heap and stack don't fit into RAM */ + _Min_Heap_Size = 0x200; /* required amount of heap */ + _Min_Stack_Size = 0x400; /* required amount of stack */ + + /* Specify the memory areas */ + MEMORY + { + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K + } + + /* Define output sections */ + SECTIONS + { + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .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 goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .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 */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _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 left */ + ._user_heap_stack : + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(4); + } >RAM + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } + } diff --git a/variants/DISCO_F100RB/stm32f1xx_hal_conf.h b/variants/DISCO_F100RB/stm32f1xx_hal_conf.h new file mode 100644 index 0000000000..fae1919075 --- /dev/null +++ b/variants/DISCO_F100RB/stm32f1xx_hal_conf.h @@ -0,0 +1,367 @@ +/** + ****************************************************************************** + * @file stm32f1xx_hal_conf.h + * @author MCD Application Team + * @version V1.0.4 + * @date 29-April-2016 + * @brief HAL configuration template file. + * This file should be copied to the application folder and renamed + * to stm32f1xx_hal_conf.h. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F1xx_HAL_CONF_H +#define __STM32F1xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED +#define HAL_ADC_MODULE_ENABLED +//#define HAL_CAN_MODULE_ENABLED +//#define HAL_CEC_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED +//#define HAL_CRC_MODULE_ENABLED +#define HAL_DAC_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +//#define HAL_ETH_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_GPIO_MODULE_ENABLED +//#define HAL_HCD_MODULE_ENABLED +#define HAL_I2C_MODULE_ENABLED +//#define HAL_I2S_MODULE_ENABLED +//#define HAL_IRDA_MODULE_ENABLED +//#define HAL_IWDG_MODULE_ENABLED +//#define HAL_NAND_MODULE_ENABLED +//#define HAL_NOR_MODULE_ENABLED +//#define HAL_PCCARD_MODULE_ENABLED +//#define HAL_PCD_MODULE_ENABLED +//#define HAL_PWR_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +//#define HAL_RTC_MODULE_ENABLED +//#define HAL_SD_MODULE_ENABLED +//#define HAL_SMARTCARD_MODULE_ENABLED +#define HAL_SPI_MODULE_ENABLED +//#define HAL_SRAM_MODULE_ENABLED +#define HAL_TIM_MODULE_ENABLED +#define HAL_UART_MODULE_ENABLED +//#define HAL_USART_MODULE_ENABLED +//#define HAL_WWDG_MODULE_ENABLED + +/* ########################## Oscillator Values adaptation ####################*/ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) +#if defined(USE_STM3210C_EVAL) + #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ +#else + #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ +#endif +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ +#endif /* LSE_VALUE */ + + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)0x000F) /*!< tick interrupt priority */ +#define USE_RTOS 0 +#define PREFETCH_ENABLE 1 + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/*#define USE_FULL_ASSERT 1*/ + + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2 +#define MAC_ADDR1 0 +#define MAC_ADDR2 0 +#define MAC_ADDR3 0 +#define MAC_ADDR4 0 +#define MAC_ADDR5 0 + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)8) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848 PHY Address*/ +#define DP83848_PHY_ADDRESS 0x01 +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FF) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF) + +#define PHY_READ_TO ((uint32_t)0x0000FFFF) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFF) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ + +#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */ +#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */ +#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */ + +#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */ +#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */ + +#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */ +#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */ + +#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */ +#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */ + + + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f1xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f1xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f1xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f1xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f1xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f1xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f1xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f1xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f1xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f1xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f1xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f1xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f1xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f1xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f1xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f1xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f1xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f1xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_PCCARD_MODULE_ENABLED + #include "stm32f1xx_hal_pccard.h" +#endif /* HAL_PCCARD_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f1xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f1xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f1xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f1xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f1xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f1xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f1xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f1xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f1xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f1xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f1xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F1xx_HAL_CONF_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/DISCO_F100RB/variant.cpp b/variants/DISCO_F100RB/variant.cpp new file mode 100644 index 0000000000..1899930540 --- /dev/null +++ b/variants/DISCO_F100RB/variant.cpp @@ -0,0 +1,201 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Pin number following UM0919 table 4,5 and 6 +const PinName digitalPin[] = { +// P1 connector + PC13, //D0 + PC0, //D1 + PC1, //D2 + PC2, //D3 + PC3, //D4 + PA0, //D5 - User button + PA1, //D6 + PA2, //D7 + PA3, //D8 + PA4, //D9 + PA5, //D10 + PA6, //D11 + PA7, //D12 + PC4, //D13 + PC5, //D14 + PB0, //D15 + PB1, //D16 + PB2, //D17 +// P2 connector + PC6, //D18 + PC7, //D19 + PC8, //D20 - LED blue + PC9, //D21 - LED green + PA8, //D22 + PA9, //D23 + PA10, //D24 + PA11, //D25 + PA12, //D26 + PA13, //D27 + PA14, //D28 + PA15, //D29 + PC10, //D30 + PC11, //D31 + PC12, //D32 + PD2, //D33 + PB3, //D34 + PB4, //D35 + PB5, //D36 - I2C SCL + PB6, //D37 - I2C SDA + PB7, //D38 + PB8, //D39 + PB9, //D40 +// P3 connector + PB10, //D41 + PB11, //D42 + PB12, //D43 - SPI SS + PB13, //D44 - SPI SCLK + PB14, //D45 - SPI MISO + PB15, //D46 - SPI MOSI + // Duplicated pins in order to be aligned with PinMap_ADC + PC0, //D47/A0 = D0 + PC1, //D48/A1 = D1 + PC2, //D49/A2 = D2 + PC3, //D50/A3 = D3 + PA0, //D51/A4 = D4 + PA1, //D52/A5 = D5 + PA2, //D53/A6 = D6 + PA3, //D54/A7 = D7 + PA4, //D55/A8 = D8 + PA5, //D56/A9 = D9 + PA6, //D57/A10 = D10 + PA7, //D58/A11 = D11 + PC4, //D59/A12 = D12 + PC5, //D60/A13 = D13 + PB0, //D61/A14 = D14 + PB1 //D62/A15 = D15 +}; + +#ifdef __cplusplus +} +#endif + +/* + * UART objects + */ + + HardwareSerial Serial(PA3, PA2); + #ifdef ENABLE_SERIAL1 + HardwareSerial Serial1(PA10, PA9); + #endif + #ifdef ENABLE_SERIAL2 + HardwareSerial Serial2(PB11, PB10); + #endif + + void serialEvent() __attribute__((weak)); + void serialEvent() { } + #ifdef ENABLE_SERIAL1 + void serialEvent1() __attribute__((weak)); + void serialEvent1() { } + #endif + #ifdef ENABLE_SERIAL2 + void serialEvent2() __attribute__((weak)); + void serialEvent2() { } + #endif + + void serialEventRun(void) + { + if (Serial.available()) serialEvent(); + #ifdef ENABLE_SERIAL1 + if (Serial1.available()) serialEvent1(); + #endif + #ifdef ENABLE_SERIAL2 + if (Serial2.available()) serialEvent2(); + #endif + } + +// ---------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief System Clock Configuration + * The system Clock is configured as follow : + * System Clock source = PLL (HSE) + * SYSCLK(Hz) = 24000000 + * HCLK(Hz) = 24000000 + * AHB Prescaler = 1 + * APB1 Prescaler = 1 + * APB2 Prescaler = 1 + * PLL_Source = HSE + * PLL_Mul = 6 + * Flash Latency(WS) = 0 + * ADC Prescaler = 2 + * @param None + * @retval None + */ +WEAK void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInit; + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = 16; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + while(1); + } + + 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_DIV1; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) + { + while(1); + } + + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; + PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV2; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + while(1); + } + + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); + + HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); + + /* SysTick_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); +} + +#ifdef __cplusplus +} +#endif diff --git a/variants/DISCO_F100RB/variant.h b/variants/DISCO_F100RB/variant.h new file mode 100644 index 0000000000..c0e826a189 --- /dev/null +++ b/variants/DISCO_F100RB/variant.h @@ -0,0 +1,146 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#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 { + 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, + DEND + }; + + enum { + A_START_AFTER = D46, + A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, + A10, A11, A12, A13, A14, A15, + 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 21 +#define LED_GREEN LED_BUILTIN +#define LED_BLUE 20 + +//On-board user button +#define USER_BTN 5 + +//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 43 + +//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 SS1 40 +#define SS2 41 +#define SS3 42 +#define MOSI 46 +#define MISO 45 +#define SCLK 44 +#define SCK SCLK + +//I2C Definitions +#define SDA 38 +#define SCL 37 + +//Timer Definitions +//Do not use timer used by PWM pins when possible. See PinMap_PWM. +#define TIMER_TONE TIM15 +#define TIMER_UART_EMULATED TIM16 + +//Do not use basic timer: OC is required +#define TIMER_SERVO TIM17 //TODO: advanced-control timers don't work + +#define DEBUG_UART ((USART_TypeDef *) USART2) + +// Serial Pin Firmata +#define PIN_SERIAL_RX 8 +#define PIN_SERIAL_TX 7 +#define PIN_SERIAL1_RX 24 +#define PIN_SERIAL1_TX 23 +#define PIN_SERIAL2_RX 42 +#define PIN_SERIAL2_TX 41 + +#ifdef __cplusplus +} // extern "C" +#endif +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + + #ifdef __cplusplus + extern HardwareSerial Serial; + extern HardwareSerial Serial1; + extern HardwareSerial Serial2; + + // 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_ */ From d7e5ff82dffc181f632f3c80ae0f359d0cc38393 Mon Sep 17 00:00:00 2001 From: fpr Date: Thu, 29 Jun 2017 13:12:29 +0200 Subject: [PATCH 12/30] Maple Mini STM32F103CB added. Signed-off-by: fpr --- boards.txt | 35 +- variants/MAPLEMINI_F103CB/PeripheralPins.c | 195 +++++++ variants/MAPLEMINI_F103CB/bootloader.ld | 180 ++++++ .../MAPLEMINI_F103CB/bootloader_original.ld | 180 ++++++ variants/MAPLEMINI_F103CB/ldscript.ld | 180 ++++++ .../MAPLEMINI_F103CB/stm32f1xx_hal_conf.h | 367 +++++++++++++ variants/MAPLEMINI_F103CB/usb/usb_device.c | 70 +++ variants/MAPLEMINI_F103CB/usb/usb_device.h | 69 +++ .../MAPLEMINI_F103CB/usb/usb_device_cdc.c | 26 + variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.c | 325 +++++++++++ variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.h | 129 +++++ variants/MAPLEMINI_F103CB/usb/usbd_conf.c | 514 ++++++++++++++++++ variants/MAPLEMINI_F103CB/usb/usbd_conf.h | 179 ++++++ variants/MAPLEMINI_F103CB/usb/usbd_desc.c | 300 ++++++++++ variants/MAPLEMINI_F103CB/usb/usbd_desc.h | 107 ++++ variants/MAPLEMINI_F103CB/variant.cpp | 206 +++++++ variants/MAPLEMINI_F103CB/variant.h | 151 +++++ 17 files changed, 3209 insertions(+), 4 deletions(-) create mode 100644 variants/MAPLEMINI_F103CB/PeripheralPins.c create mode 100644 variants/MAPLEMINI_F103CB/bootloader.ld create mode 100644 variants/MAPLEMINI_F103CB/bootloader_original.ld create mode 100644 variants/MAPLEMINI_F103CB/ldscript.ld create mode 100644 variants/MAPLEMINI_F103CB/stm32f1xx_hal_conf.h create mode 100644 variants/MAPLEMINI_F103CB/usb/usb_device.c create mode 100644 variants/MAPLEMINI_F103CB/usb/usb_device.h create mode 100644 variants/MAPLEMINI_F103CB/usb/usb_device_cdc.c create mode 100644 variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.c create mode 100644 variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.h create mode 100644 variants/MAPLEMINI_F103CB/usb/usbd_conf.c create mode 100644 variants/MAPLEMINI_F103CB/usb/usbd_conf.h create mode 100644 variants/MAPLEMINI_F103CB/usb/usbd_desc.c create mode 100644 variants/MAPLEMINI_F103CB/usb/usbd_desc.h create mode 100644 variants/MAPLEMINI_F103CB/variant.cpp create mode 100644 variants/MAPLEMINI_F103CB/variant.h diff --git a/boards.txt b/boards.txt index ed40e91023..c41bd8e483 100644 --- a/boards.txt +++ b/boards.txt @@ -290,13 +290,40 @@ Other_board.menu.Other_board.BLUEPILL_F103C8.build.cmsis_lib_gcc=arm_cortexM3l_m #To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' #To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2 #To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3 -Other_board.menu.Other_board.BLUEPILL_F103C8.build.extra_flags=-DSTM32F103xB {build.usb_flags} -DSERIAL_USB -DUSBCON "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" {build.upload_flags} +Other_board.menu.Other_board.BLUEPILL_F103C8.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" + +# MAPLEMINI_F103CB board + +Other_board.menu.Other_board.MAPLEMINI_F103CB=MapleMini F103CB +Other_board.menu.Other_board.MAPLEMINI_F103CB.node=NODE_F103CB +Other_board.menu.Other_board.MAPLEMINI_F103CB.upload.maximum_size=131072 +Other_board.menu.Other_board.MAPLEMINI_F103CB.upload.maximum_data_size=20480 +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.mcu=cortex-m3 +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.f_cpu=72000000L +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.usb_product="MAPLEMINI-F103CB" +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.board=MAPLEMINI_F103CB +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.series=STM32F1xx +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.variant=MAPLEMINI_F103CB +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.cmsis_lib_gcc=arm_cortexM3l_math +#To enable USB add '-DUSBCON' +#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' +#To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2 +#To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3 +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" + +Other_board.menu.upload_method.DFUUploadMethod1=Maple bootloader (original version for Maple boards) +Other_board.menu.upload_method.DFUUploadMethod1.upload.protocol=maple_dfu +Other_board.menu.upload_method.DFUUploadMethod1.upload.tool=maple_upload +Other_board.menu.upload_method.DFUUploadMethod1.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x5000 +Other_board.menu.upload_method.DFUUploadMethod1.build.ldscript=bootloader_original.ld +Other_board.menu.upload_method.DFUUploadMethod1.upload.usbID=1EAF:0003 +Other_board.menu.upload_method.DFUUploadMethod1.upload.altID=1 Other_board.menu.upload_method.DFUUploadMethod=STM32duino bootloader Other_board.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu Other_board.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload -Other_board.menu.upload_method.DFUUploadMethod.build.upload_flags=-DVECT_TAB_OFFSET=0x2000 +Other_board.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x2000 Other_board.menu.upload_method.DFUUploadMethod.build.ldscript=bootloader.ld Other_board.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 Other_board.menu.upload_method.DFUUploadMethod.upload.altID=2 @@ -304,7 +331,7 @@ Other_board.menu.upload_method.DFUUploadMethod.upload.altID=2 Other_board.menu.upload_method.STLinkMethod=STLink Other_board.menu.upload_method.STLinkMethod.upload.protocol=STLink Other_board.menu.upload_method.STLinkMethod.upload.tool=stlink_upload -Other_board.menu.upload_method.STLinkMethod.build.upload_flags= +Other_board.menu.upload_method.STLinkMethod.build.upload_flags=-DSERIAL_USB Other_board.menu.upload_method.serialMethod=Serial Other_board.menu.upload_method.serialMethod.upload.protocol=maple_serial @@ -315,7 +342,7 @@ Other_board.menu.upload_method.BMPMethod=BMP (Black Magic Probe) Other_board.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp Other_board.menu.upload_method.BMPMethod.upload.tool=bmp_upload Other_board.menu.upload_method.BMPMethod.upload.speed=230400 -Other_board.menu.upload_method.BMPMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG +Other_board.menu.upload_method.BMPMethod.build.upload_flags= ################################################################################ diff --git a/variants/MAPLEMINI_F103CB/PeripheralPins.c b/variants/MAPLEMINI_F103CB/PeripheralPins.c new file mode 100644 index 0000000000..57477330a2 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/PeripheralPins.c @@ -0,0 +1,195 @@ +/* + ******************************************************************************* + * Copyright (c) 2016, 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 "Arduino.h" +#include "PeripheralPins.h" + +// ===== +// Note: Commented lines are alternative possibilities which are not used per default. +// If you change them, you will have to know what you do +// ===== + + +//*** ADC *** + +const PinMap PinMap_ADC[] = { + {PA0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 + // {PA0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 + {PA1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 + // {PA1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 + {PA2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 + // {PA2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 + {PA3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 + // {PA3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 + {PA4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 + // {PA4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 + {PA5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 + // {PA5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 + {PA6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 + // {PA6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 + {PA7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 + // {PA7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 + {PB0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 + // {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 + {PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 + // {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 + {NC, NC, 0} +}; + +//*** DAC *** + +const PinMap PinMap_DAC[] = { + {NC, NC, 0} +}; + +//*** I2C *** + +const PinMap PinMap_I2C_SDA[] = { + {PB7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {PB9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 + {PB11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_I2C_SCL[] = { + {PB6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {PB8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 + {PB10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, + {NC, NC, 0} +}; + +//*** PWM *** + +const PinMap PinMap_PWM[] = { + {PA0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM2_CH1 + {PA1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM2_CH2 + {PA2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM2_CH3 + {PA3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM2_CH4 + {PA6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM3_CH1 + // {PA7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 1, 1)}, // TIM1_CH1N - GPIO_PartialRemap_TIM1 + {PA7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM3_CH2 + {PA8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM1_CH1 + {PA9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM1_CH2 + {PA10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM1_CH3 + {PA11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM1_CH4 + {PA15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 1, 0)}, // TIM2_CH1 - GPIO_FullRemap_TIM2 + // {PB0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 2, 1)}, // TIM1_CH2N - GPIO_PartialRemap_TIM1 + {PB0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM3_CH3 + // {PB1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 3, 1)}, // TIM1_CH3N - GPIO_PartialRemap_TIM1 + {PB1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM3_CH4 + {PB3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 2, 0)}, // TIM2_CH2 - GPIO_FullRemap_TIM2 + {PB4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 1, 0)}, // TIM3_CH1 - GPIO_PartialRemap_TIM3 + {PB5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 2, 0)}, // TIM3_CH2 - GPIO_PartialRemap_TIM3 + {PB6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM4_CH1 + {PB7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM4_CH2 + {PB8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM4_CH3 + {PB9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM4_CH4 + {PB10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 3, 0)}, // TIM2_CH3 - GPIO_FullRemap_TIM2 + {PB11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 4, 0)}, // TIM2_CH4 - GPIO_FullRemap_TIM2 + {PB13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM1_CH1N + {PB14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 1)}, // TIM1_CH2N + {PB15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 1)}, // TIM1_CH3N + {NC, NC, 0} +}; + +//*** SERIAL *** + +const PinMap PinMap_UART_TX[] = { + {PA2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 + {PB10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_UART_RX[] = { + {PA3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 + {PB11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_UART_RTS[] = { + {PA1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_UART_CTS[] = { + {PA0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +//*** SPI *** + +const PinMap PinMap_SPI_MOSI[] = { + {PA7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_MISO[] = { + {PA6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_SCLK[] = { + {PA5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PB3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +const PinMap PinMap_SPI_SSEL[] = { + {PA4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {PA15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 + {PB12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, + {NC, NC, 0} +}; + +//*** CAN *** + +const PinMap PinMap_CAN_RD[] = { + {PA11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, + {PB8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_RX to PB_9 + {NC, NC, 0} +}; + +const PinMap PinMap_CAN_TD[] = { + {PA12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, + {PB9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_TX to PB_9 + {NC, NC, 0} +}; diff --git a/variants/MAPLEMINI_F103CB/bootloader.ld b/variants/MAPLEMINI_F103CB/bootloader.ld new file mode 100644 index 0000000000..21b5f7a954 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/bootloader.ld @@ -0,0 +1,180 @@ +/** + ****************************************************************************** + * @file STM32F103CB_FLASH.h + * @author WI6LABS + * @version V1.0.0 + * @date 22-July-2016 + * @brief Linker script for STM32F103CB Device with + * 120KByte FLASH, 20KByte 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) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = 0x20005000; /* end of RAM */ +/* Generate a link error if heap and stack don't fit into RAM */ +_Min_Heap_Size = 0x200;; /* required amount of heap */ +_Min_Stack_Size = 0x400;; /* required amount of stack */ + +/* Specify the memory areas */ +MEMORY +{ +FLASH (rx) : ORIGIN = 0x8002000, LENGTH = 120K +RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .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 goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .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 */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _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 left */ + ._user_heap_stack : + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(4); + } >RAM + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/variants/MAPLEMINI_F103CB/bootloader_original.ld b/variants/MAPLEMINI_F103CB/bootloader_original.ld new file mode 100644 index 0000000000..4925122b67 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/bootloader_original.ld @@ -0,0 +1,180 @@ +/** + ****************************************************************************** + * @file STM32F103CB_FLASH.h + * @author WI6LABS + * @version V1.0.0 + * @date 22-July-2016 + * @brief Linker script for STM32F103CB Device with + * 120KByte FLASH, 20KByte 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) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = 0x20005000; /* end of RAM */ +/* Generate a link error if heap and stack don't fit into RAM */ +_Min_Heap_Size = 0x200;; /* required amount of heap */ +_Min_Stack_Size = 0x400;; /* required amount of stack */ + +/* Specify the memory areas */ +MEMORY +{ +FLASH (rx) : ORIGIN = 0x8005000, LENGTH = 108K +RAM (xrw) : ORIGIN = 0x20000C00, LENGTH = 17K +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .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 goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .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 */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _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 left */ + ._user_heap_stack : + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(4); + } >RAM + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/variants/MAPLEMINI_F103CB/ldscript.ld b/variants/MAPLEMINI_F103CB/ldscript.ld new file mode 100644 index 0000000000..dd4c2ba010 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/ldscript.ld @@ -0,0 +1,180 @@ +/** + ****************************************************************************** + * @file STM32F103CB_FLASH.h + * @author WI6LABS + * @version V1.0.0 + * @date 22-July-2016 + * @brief Linker script for STM32F103CB Device with + * 128KByte FLASH, 20KByte 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) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = 0x20005000; /* end of RAM */ +/* Generate a link error if heap and stack don't fit into RAM */ +_Min_Heap_Size = 0x200;; /* required amount of heap */ +_Min_Stack_Size = 0x400;; /* required amount of stack */ + +/* Specify the memory areas */ +MEMORY +{ +FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K +RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .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 goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .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 */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _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 left */ + ._user_heap_stack : + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(4); + } >RAM + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/variants/MAPLEMINI_F103CB/stm32f1xx_hal_conf.h b/variants/MAPLEMINI_F103CB/stm32f1xx_hal_conf.h new file mode 100644 index 0000000000..ed08c3be81 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/stm32f1xx_hal_conf.h @@ -0,0 +1,367 @@ +/** + ****************************************************************************** + * @file stm32f1xx_hal_conf.h + * @author MCD Application Team + * @version V1.0.4 + * @date 29-April-2016 + * @brief HAL configuration template file. + * This file should be copied to the application folder and renamed + * to stm32f1xx_hal_conf.h. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2016 STMicroelectronics

+ * + * 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F1xx_HAL_CONF_H +#define __STM32F1xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED +#define HAL_ADC_MODULE_ENABLED +//#define HAL_CAN_MODULE_ENABLED +//#define HAL_CEC_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED +//#define HAL_CRC_MODULE_ENABLED +//#define HAL_DAC_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +//#define HAL_ETH_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_GPIO_MODULE_ENABLED +#define HAL_HCD_MODULE_ENABLED +#define HAL_I2C_MODULE_ENABLED +//#define HAL_I2S_MODULE_ENABLED +//#define HAL_IRDA_MODULE_ENABLED +//#define HAL_IWDG_MODULE_ENABLED +//#define HAL_NAND_MODULE_ENABLED +//#define HAL_NOR_MODULE_ENABLED +//#define HAL_PCCARD_MODULE_ENABLED +#define HAL_PCD_MODULE_ENABLED +//#define HAL_PWR_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +//#define HAL_RTC_MODULE_ENABLED +//#define HAL_SD_MODULE_ENABLED +//#define HAL_SMARTCARD_MODULE_ENABLED +#define HAL_SPI_MODULE_ENABLED +//#define HAL_SRAM_MODULE_ENABLED +#define HAL_TIM_MODULE_ENABLED +#define HAL_UART_MODULE_ENABLED +//#define HAL_USART_MODULE_ENABLED +//#define HAL_WWDG_MODULE_ENABLED + +/* ########################## Oscillator Values adaptation ####################*/ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) +#if defined(USE_STM3210C_EVAL) + #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ +#else + #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ +#endif +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ +#endif /* LSE_VALUE */ + + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)0x000F) /*!< tick interrupt priority */ +#define USE_RTOS 0 +#define PREFETCH_ENABLE 1 + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/*#define USE_FULL_ASSERT 1*/ + + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2 +#define MAC_ADDR1 0 +#define MAC_ADDR2 0 +#define MAC_ADDR3 0 +#define MAC_ADDR4 0 +#define MAC_ADDR5 0 + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)8) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848 PHY Address*/ +#define DP83848_PHY_ADDRESS 0x01 +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FF) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF) + +#define PHY_READ_TO ((uint32_t)0x0000FFFF) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFF) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ + +#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */ +#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */ +#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */ + +#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */ +#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */ + +#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */ +#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */ + +#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */ +#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */ + + + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f1xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f1xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f1xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f1xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f1xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f1xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f1xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f1xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f1xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f1xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f1xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f1xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f1xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f1xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f1xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f1xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f1xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f1xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_PCCARD_MODULE_ENABLED + #include "stm32f1xx_hal_pccard.h" +#endif /* HAL_PCCARD_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f1xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f1xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f1xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f1xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f1xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f1xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f1xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f1xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f1xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f1xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f1xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F1xx_HAL_CONF_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/usb/usb_device.c b/variants/MAPLEMINI_F103CB/usb/usb_device.c new file mode 100644 index 0000000000..bfd73bce0d --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usb_device.c @@ -0,0 +1,70 @@ +/** + ****************************************************************************** + * @file : USB_DEVICE + * @version : v1.0_Cube + * @brief : This file implements the USB Device + ****************************************************************************** + * + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +/* Includes ------------------------------------------------------------------*/ +#ifdef USBCON + +#include "usb_device.h" +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_cdc.h" +#include "usbd_cdc_if.h" + +/* USB Device Core handle declaration */ +USBD_HandleTypeDef hUsbDeviceFS; + +/* init function */ +void MX_USB_DEVICE_Init(void) +{ + /* Init Device Library,Add Supported Class and Start the library*/ + USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); + + USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC); + + USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS); + + USBD_Start(&hUsbDeviceFS); + +} + +#endif +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/usb/usb_device.h b/variants/MAPLEMINI_F103CB/usb/usb_device.h new file mode 100644 index 0000000000..64aa35fccb --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usb_device.h @@ -0,0 +1,69 @@ +/** + ****************************************************************************** + * @file : USB_DEVICE + * @version : v1.0_Cube + * @brief : Header for usb_device file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __usb_device_H +#define __usb_device_H + +#ifdef USBCON + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f1xx.h" +#include "stm32f1xx_hal.h" +#include "usbd_def.h" + +extern USBD_HandleTypeDef hUsbDeviceFS; + +/* USB_Device init function */ +void MX_USB_DEVICE_Init(void); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif /*__usb_device_H */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/usb/usb_device_cdc.c b/variants/MAPLEMINI_F103CB/usb/usb_device_cdc.c new file mode 100644 index 0000000000..9ce6bc71c3 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usb_device_cdc.c @@ -0,0 +1,26 @@ +/* + * + * + * Copyright (C) 2017, STMicroelectronics - All Rights Reserved + * Author: YOUR NAME <> for STMicroelectronics. + * + * License type: GPLv2 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * 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 + * . + */ +#ifdef USBCON + +#include "usbd_cdc.c" + +#endif //USBCON diff --git a/variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.c b/variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.c new file mode 100644 index 0000000000..15659b15ef --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.c @@ -0,0 +1,325 @@ +/** + ****************************************************************************** + * @file : usbd_cdc_if.c + * @brief : + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +#ifdef USBCON + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_cdc_if.h" +/* USER CODE BEGIN INCLUDE */ + +//#include "variant.h" +/* USER CODE END INCLUDE */ + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_CDC + * @brief usbd core module + * @{ + */ + +/** @defgroup USBD_CDC_Private_TypesDefinitions + * @{ + */ +/* USER CODE BEGIN PRIVATE_TYPES */ +/* USER CODE END PRIVATE_TYPES */ +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Defines + * @{ + */ +/* USER CODE BEGIN PRIVATE_DEFINES */ +/* Define size for the receive and transmit buffer over CDC */ +/* It's up to user to redefine and/or remove those define */ +#define APP_RX_DATA_SIZE CDC_SERIAL_BUFFER_SIZE +#define APP_TX_DATA_SIZE CDC_SERIAL_BUFFER_SIZE +/* USER CODE END PRIVATE_DEFINES */ +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Macros + * @{ + */ +/* USER CODE BEGIN PRIVATE_MACRO */ +/* USER CODE END PRIVATE_MACRO */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Variables + * @{ + */ +/* Create buffer for reception and transmission */ +/* It's up to user to redefine and/or remove those define */ +/* Received Data over USB are stored in this buffer */ +uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; + +/* Send Data over USB CDC are stored in this buffer */ +uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; + +/* USER CODE BEGIN PRIVATE_VARIABLES */ +/* USB handler declaration */ +/* Handle for USB Full Speed IP */ +//USBD_HandleTypeDef *hUsbDevice_0; +/* USER CODE BEGIN PRIVATE_VARIABLES */ +uint8_t dtr_pin = 0; //DTR pin is disabled +/* USER CODE END PRIVATE_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Variables + * @{ + */ + extern USBD_HandleTypeDef hUsbDeviceFS; +/* USER CODE BEGIN EXPORTED_VARIABLES */ +/* USER CODE END EXPORTED_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_FunctionPrototypes + * @{ + */ +static int8_t CDC_Init_FS (void); +static int8_t CDC_DeInit_FS (void); +static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length); +static int8_t CDC_Receive_FS (uint8_t* pbuf, uint32_t *Len); + +/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ +/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ + +/** + * @} + */ + +USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = +{ + CDC_Init_FS, + CDC_DeInit_FS, + CDC_Control_FS, + CDC_Receive_FS +}; + +/* Private functions ---------------------------------------------------------*/ +/** + * @brief CDC_Init_FS + * Initializes the CDC media low layer over the FS USB IP + * @param None + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Init_FS(void) +{ + /* USER CODE BEGIN 3 */ + /* Set Application Buffers */ + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); + USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); + return (USBD_OK); + /* USER CODE END 3 */ +} + +/** + * @brief CDC_DeInit_FS + * DeInitializes the CDC media low layer + * @param None + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_DeInit_FS(void) +{ + /* USER CODE BEGIN 4 */ + return (USBD_OK); + /* USER CODE END 4 */ +} + +/** + * @brief CDC_Control_FS + * Manage the CDC class requests + * @param cmd: Command code + * @param pbuf: Buffer containing command data (request parameters) + * @param length: Number of data to be sent (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length) +{ + /* USER CODE BEGIN 5 */ + switch (cmd) + { + case CDC_SEND_ENCAPSULATED_COMMAND: + + break; + + case CDC_GET_ENCAPSULATED_RESPONSE: + + break; + + case CDC_SET_COMM_FEATURE: + + break; + + case CDC_GET_COMM_FEATURE: + + break; + + case CDC_CLEAR_COMM_FEATURE: + + break; + + /*******************************************************************************/ + /* Line Coding Structure */ + /*-----------------------------------------------------------------------------*/ + /* Offset | Field | Size | Value | Description */ + /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ + /* 4 | bCharFormat | 1 | Number | Stop bits */ + /* 0 - 1 Stop bit */ + /* 1 - 1.5 Stop bits */ + /* 2 - 2 Stop bits */ + /* 5 | bParityType | 1 | Number | Parity */ + /* 0 - None */ + /* 1 - Odd */ + /* 2 - Even */ + /* 3 - Mark */ + /* 4 - Space */ + /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ + /*******************************************************************************/ + case CDC_SET_LINE_CODING: + + break; + + case CDC_GET_LINE_CODING: + + break; + + case CDC_SET_CONTROL_LINE_STATE: + dtr_pin++; //DTR pin is enabled + break; + + case CDC_SEND_BREAK: + + break; + + default: + break; + } + + return (USBD_OK); + /* USER CODE END 5 */ +} + +/** + * @brief CDC_Receive_FS + * Data received over USB OUT endpoint are sent over CDC interface + * through this function. + * + * @note + * This function will block any OUT packet reception on USB endpoint + * untill exiting this function. If you exit this function before transfer + * is complete on CDC interface (ie. using DMA controller) it will result + * in receiving more data while previous ones are still not sent. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len) +{ + /* USER CODE BEGIN 6 */ + /* Four byte is the magic pack "1EAF" that puts the MCU into bootloader. */ + if(*Len >= 4){ + /** + * Check if the incoming contains the string "1EAF". + * If yes, check if the DTR has been set, to put the MCU into the bootloader mode. + */ + if(dtr_pin > 3){ + if((Buf[0] == '1')&&(Buf[1] == 'E')&&(Buf[2] == 'A')&&(Buf[3] == 'F')){ + HAL_NVIC_SystemReset(); + } + dtr_pin = 0; + } + } + + uint16_t len = *Len; + USBSerial_Rx_Handler((uint8_t *)&Buf[0], len); + USBD_CDC_ReceivePacket(&hUsbDeviceFS); + + //USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); + //USBD_CDC_ReceivePacket(&hUsbDeviceFS); + //HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); + return (USBD_OK); + /* USER CODE END 6 */ +} + +/** + * @brief CDC_Transmit_FS + * Data send over USB IN endpoint are sent over CDC interface + * through this function. + * @note + * + * + * @param Buf: Buffer of data to be send + * @param Len: Number of data to be send (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY + */ +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) +{ + uint8_t result = USBD_OK; + /* USER CODE BEGIN 7 */ + USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; + if (hcdc->TxState != 0){ + return USBD_BUSY; + } + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); + result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); + /* USER CODE END 7 */ + return result; +} + +/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ +/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ + +/** + * @} + */ + +/** + * @} + */ + +#endif + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.h b/variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.h new file mode 100644 index 0000000000..02856661f2 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usbd_cdc_if.h @@ -0,0 +1,129 @@ +/** + ****************************************************************************** + * @file : usbd_cdc_if.h + * @brief : Header for usbd_cdc_if file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CDC_IF_H +#define __USBD_CDC_IF_H + +#ifdef USBCON + +#define CDC_SERIAL_BUFFER_SIZE 128 //USBSerial buffer data length + +#ifdef __cplusplus + extern "C" { +#endif +/* Includes ------------------------------------------------------------------*/ +#include "usbd_cdc.h" +/* USER CODE BEGIN INCLUDE */ +/* USER CODE END INCLUDE */ + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_CDC_IF + * @brief header + * @{ + */ + +/** @defgroup USBD_CDC_IF_Exported_Defines + * @{ + */ +/* USER CODE BEGIN EXPORTED_DEFINES */ +uint8_t CDC_getTransmitterStatus(void); +/* USER CODE END EXPORTED_DEFINES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Types + * @{ + */ +/* USER CODE BEGIN EXPORTED_TYPES */ +/* USER CODE END EXPORTED_TYPES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Macros + * @{ + */ +/* USER CODE BEGIN EXPORTED_MACRO */ +/* USER CODE END EXPORTED_MACRO */ + +/** + * @} + */ + +/** @defgroup USBD_AUDIO_IF_Exported_Variables + * @{ + */ +extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; + +/* USER CODE BEGIN EXPORTED_VARIABLES */ +/* USER CODE END EXPORTED_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype + * @{ + */ +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); + +/* USER CODE BEGIN EXPORTED_FUNCTIONS */ +extern void USBSerial_Rx_Handler(uint8_t *data, uint16_t len); +/* USER CODE END EXPORTED_FUNCTIONS */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + +#endif /* __USBD_CDC_IF_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/usb/usbd_conf.c b/variants/MAPLEMINI_F103CB/usb/usbd_conf.c new file mode 100644 index 0000000000..25278996b3 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usbd_conf.c @@ -0,0 +1,514 @@ +/** + ****************************************************************************** + * @file : usbd_conf.c + * @version : v1.0_Cube + * @brief : This file implements the board support package for the USB device library + ****************************************************************************** + * + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +#ifdef USBCON + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f1xx.h" +#include "stm32f1xx_hal.h" +#include "usbd_def.h" +#include "usbd_core.h" +#include "usbd_cdc.h" +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +PCD_HandleTypeDef hpcd_USB_FS; +void Error_Handler(void); + +/* USER CODE BEGIN 0 */ +/* USER CODE END 0 */ + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ +/* USER CODE BEGIN 1 */ +/* USER CODE END 1 */ +void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); + +/******************************************************************************* + LL Driver Callbacks (PCD -> USB Device Library) +*******************************************************************************/ +/* MSP Init */ + +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) +{ + if(pcdHandle->Instance==USB) + { + /* USER CODE BEGIN USB_MspInit 0 */ + + /* USER CODE END USB_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_USB_CLK_ENABLE(); + + /* Peripheral interrupt init */ + HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); + /* USER CODE BEGIN USB_MspInit 1 */ + + /* USER CODE END USB_MspInit 1 */ + } +} + +void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) +{ + if(pcdHandle->Instance==USB) + { + /* USER CODE BEGIN USB_MspDeInit 0 */ + + /* USER CODE END USB_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USB_CLK_DISABLE(); + + /* Peripheral interrupt Deinit*/ + HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); + + /* USER CODE BEGIN USB_MspDeInit 1 */ + + /* USER CODE END USB_MspDeInit 1 */ + } +} + +/** + * @brief Setup Stage callback + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); +} + +/** + * @brief Data Out Stage callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint Number + * @retval None + */ +void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +{ + USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); +} + +/** + * @brief Data In Stage callback.. + * @param hpcd: PCD handle + * @param epnum: Endpoint Number + * @retval None + */ +void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +{ + USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); +} + +/** + * @brief SOF callback. + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); +} + +/** + * @brief Reset callback. + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_SpeedTypeDef speed = USBD_SPEED_FULL; + + /*Set USB Current Speed*/ + switch (hpcd->Init.speed) + { + case PCD_SPEED_FULL: + speed = USBD_SPEED_FULL; + break; + + default: + speed = USBD_SPEED_FULL; + break; + } + USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); + + /*Reset Device*/ + USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); +} + +/** + * @brief Suspend callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +{ + /* Inform USB library that core enters in suspend Mode */ + USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); + /*Enter in STOP mode */ + /* USER CODE BEGIN 2 */ + if (hpcd->Init.low_power_enable) + { + /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */ + SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + } + /* USER CODE END 2 */ +} + +/** + * @brief Resume callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +{ + /* USER CODE BEGIN 3 */ + /* USER CODE END 3 */ + USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); + +} + +/** + * @brief ISOOUTIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint Number + * @retval None + */ +void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +{ + USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); +} + +/** + * @brief ISOINIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint Number + * @retval None + */ +void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +{ + USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); +} + +/** + * @brief ConnectCallback callback. + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); +} + +/** + * @brief Disconnect callback. + * @param hpcd: PCD handle + * @retval None + */ +void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +{ + USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); +} + +/******************************************************************************* + LL Driver Interface (USB Device Library --> PCD) +*******************************************************************************/ +/** + * @brief Initializes the Low Level portion of the Device driver. + * @param pdev: Device handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) +{ + /* Init USB_IP */ + /* Link The driver to the stack */ + hpcd_USB_FS.pData = pdev; + pdev->pData = &hpcd_USB_FS; + + hpcd_USB_FS.Instance = USB; + hpcd_USB_FS.Init.dev_endpoints = 8; + hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_8; + hpcd_USB_FS.Init.low_power_enable = DISABLE; + hpcd_USB_FS.Init.lpm_enable = DISABLE; + hpcd_USB_FS.Init.battery_charging_enable = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) + { + Error_Handler(); + } + + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); + return USBD_OK; +} + +/** + * @brief De-Initializes the Low Level portion of the Device driver. + * @param pdev: Device handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev) +{ + HAL_PCD_DeInit((PCD_HandleTypeDef*)pdev->pData); + return USBD_OK; +} + +/** + * @brief Starts the Low Level portion of the Device driver. + * @param pdev: Device handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) +{ + HAL_PCD_Start((PCD_HandleTypeDef*)pdev->pData); + return USBD_OK; +} + +/** + * @brief Stops the Low Level portion of the Device driver. + * @param pdev: Device handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev) +{ + HAL_PCD_Stop((PCD_HandleTypeDef*) pdev->pData); + return USBD_OK; +} + +/** + * @brief Opens an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @param ep_type: Endpoint Type + * @param ep_mps: Endpoint Max Packet Size + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, + uint8_t ep_addr, + uint8_t ep_type, + uint16_t ep_mps) +{ + HAL_PCD_EP_Open((PCD_HandleTypeDef*) pdev->pData, + ep_addr, + ep_mps, + ep_type); + + return USBD_OK; +} + +/** + * @brief Closes an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_PCD_EP_Close((PCD_HandleTypeDef*) pdev->pData, ep_addr); + return USBD_OK; +} + +/** + * @brief Flushes an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_PCD_EP_Flush((PCD_HandleTypeDef*) pdev->pData, ep_addr); + return USBD_OK; +} + +/** + * @brief Sets a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_PCD_EP_SetStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); + return USBD_OK; +} + +/** + * @brief Clears a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_PCD_EP_ClrStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); + return USBD_OK; +} + +/** + * @brief Returns Stall condition. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval Stall (1: Yes, 0: No) + */ +uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; + + if((ep_addr & 0x80) == 0x80) + { + return hpcd->IN_ep[ep_addr & 0x7F].is_stall; + } + else + { + return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; + } +} +/** + * @brief Assigns a USB address to the device. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr) +{ + HAL_PCD_SetAddress((PCD_HandleTypeDef*) pdev->pData, dev_addr); + return USBD_OK; +} + +/** + * @brief Transmits data over an endpoint. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @param pbuf: Pointer to data to be sent + * @param size: Data size + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, + uint8_t ep_addr, + uint8_t *pbuf, + uint16_t size) +{ + HAL_PCD_EP_Transmit((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); + return USBD_OK; +} + +/** + * @brief Prepares an endpoint for reception. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @param pbuf: Pointer to data to be received + * @param size: Data size + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, + uint8_t ep_addr, + uint8_t *pbuf, + uint16_t size) +{ + HAL_PCD_EP_Receive((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); + return USBD_OK; +} + +/** + * @brief Returns the last transfered packet size. + * @param pdev: Device handle + * @param ep_addr: Endpoint Number + * @retval Recived Data Size + */ +uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); +} + +/** + * @brief Delays routine for the USB Device Library. + * @param Delay: Delay in ms + * @retval None + */ +void USBD_LL_Delay (uint32_t Delay) +{ + HAL_Delay(Delay); +} + +/** + * @brief static single allocation. + * @param size: size of allocated memory + * @retval None + */ +void *USBD_static_malloc(uint32_t size) +{ + static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ + return mem; +} + +/** + * @brief Dummy memory free + * @param *p pointer to allocated memory address + * @retval None + */ +void USBD_static_free(void *p) +{ + +} + +/** +* @brief Software Device Connection +* @param hpcd: PCD handle +* @param state: connection state (0 : disconnected / 1: connected) +* @retval None +*/ +void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) +{ +/* USER CODE BEGIN 5 */ + if (state == 1) + { + /* Configure Low Connection State */ + + } + else + { + /* Configure High Connection State */ + + } +/* USER CODE END 5 */ +} + +#endif + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/usb/usbd_conf.h b/variants/MAPLEMINI_F103CB/usb/usbd_conf.h new file mode 100644 index 0000000000..cb4395444d --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usbd_conf.h @@ -0,0 +1,179 @@ +/** + ****************************************************************************** + * @file : usbd_conf.h + * @version : v1.0_Cube + * @brief : Header for usbd_conf file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CONF__H__ +#define __USBD_CONF__H__ + +#ifdef USBCON + +#ifdef __cplusplus + extern "C" { +#endif +/* Includes ------------------------------------------------------------------*/ +#include +#include +#include +#include "stm32f1xx.h" +#include "stm32f1xx_hal.h" +#include "usbd_def.h" + +/** @addtogroup USBD_OTG_DRIVER + * @{ + */ + +/** @defgroup USBD_CONF + * @brief usb otg low level driver configuration file + * @{ + */ + +/** @defgroup USBD_CONF_Exported_Defines + * @{ + */ + +/*---------- -----------*/ +#define USBD_MAX_NUM_INTERFACES 1 +/*---------- -----------*/ +#define USBD_MAX_NUM_CONFIGURATION 1 +/*---------- -----------*/ +#define USBD_MAX_STR_DESC_SIZ 512 +/*---------- -----------*/ +#define USBD_SUPPORT_USER_STRING 0 +/*---------- -----------*/ +#define USBD_DEBUG_LEVEL 0 +/*---------- -----------*/ +#define USBD_SELF_POWERED 1 +/*---------- -----------*/ +#define USBD_CDC_INTERVAL 1000 +/*---------- -----------*/ +#define MAX_STATIC_ALLOC_SIZE 512 +/****************************************/ +/* #define for FS and HS identification */ +#define DEVICE_FS 0 + +/** @defgroup USBD_Exported_Macros + * @{ + */ + +/* Memory management macros */ +#define USBD_malloc (uint32_t *)USBD_static_malloc +#define USBD_free USBD_static_free +#define USBD_memset /* Not used */ +#define USBD_memcpy /* Not used */ + +#define USBD_Delay HAL_Delay + +/* For footprint reasons and since only one allocation is handled in the HID class + driver, the malloc/free is changed into a static allocation method */ +void *USBD_static_malloc(uint32_t size); +void USBD_static_free(void *p); + +/* DEBUG macros */ +#if (USBD_DEBUG_LEVEL > 0) +#define USBD_UsrLog(...) printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_UsrLog(...) +#endif + + +#if (USBD_DEBUG_LEVEL > 1) + +#define USBD_ErrLog(...) printf("ERROR: ") ;\ + printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_ErrLog(...) +#endif + + +#if (USBD_DEBUG_LEVEL > 2) +#define USBD_DbgLog(...) printf("DEBUG : ") ;\ + printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_DbgLog(...) +#endif + +/** + * @} + */ + + + +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Types + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Variables + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_FunctionsPrototype + * @{ + */ +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif + +#endif /*__USBD_CONF__H__*/ + +/** + * @} + */ + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/usb/usbd_desc.c b/variants/MAPLEMINI_F103CB/usb/usbd_desc.c new file mode 100644 index 0000000000..c6a2955c59 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usbd_desc.c @@ -0,0 +1,300 @@ +/** + ****************************************************************************** + * @file : usbd_desc.c + * @version : v1.0_Cube + * @brief : This file implements the USB Device descriptors + ****************************************************************************** + * + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ +#ifdef USBCON + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_conf.h" + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_DESC + * @brief USBD descriptors module + * @{ + */ + +/** @defgroup USBD_DESC_Private_TypesDefinitions + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Defines + * @{ + */ +#define USBD_VID 1155 +#define USBD_LANGID_STRING 1033 +#define USBD_MANUFACTURER_STRING "STMicroelectronics" +#define USBD_PID_FS 22336 +#define USBD_PRODUCT_STRING_FS "STM32 Virtual ComPort" +#define USBD_SERIALNUMBER_STRING_FS "00000000001A" +#define USBD_CONFIGURATION_STRING_FS "CDC Config" +#define USBD_INTERFACE_STRING_FS "CDC Interface" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0*/ +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Variables + * @{ + */ +uint8_t * USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_ManufacturerStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_ProductStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); +uint8_t * USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length); + +#ifdef USB_SUPPORT_USER_STRING_DESC +uint8_t * USBD_FS_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx , uint16_t *length); +#endif /* USB_SUPPORT_USER_STRING_DESC */ + +USBD_DescriptorsTypeDef FS_Desc = +{ + USBD_FS_DeviceDescriptor, + USBD_FS_LangIDStrDescriptor, + USBD_FS_ManufacturerStrDescriptor, + USBD_FS_ProductStrDescriptor, + USBD_FS_SerialStrDescriptor, + USBD_FS_ConfigStrDescriptor, + USBD_FS_InterfaceStrDescriptor, +}; + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif +/* USB Standard Device Descriptor */ +__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = + { + 0x12, /*bLength */ + USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ + 0x00, /* bcdUSB */ + 0x02, + 0x02, /*bDeviceClass*/ + 0x02, /*bDeviceSubClass*/ + 0x00, /*bDeviceProtocol*/ + USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ + LOBYTE(USBD_VID), /*idVendor*/ + HIBYTE(USBD_VID), /*idVendor*/ + LOBYTE(USBD_PID_FS), /*idVendor*/ + HIBYTE(USBD_PID_FS), /*idVendor*/ + 0x00, /*bcdDevice rel. 2.00*/ + 0x02, + USBD_IDX_MFC_STR, /*Index of manufacturer string*/ + USBD_IDX_PRODUCT_STR, /*Index of product string*/ + USBD_IDX_SERIAL_STR, /*Index of serial number string*/ + USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ + } ; +/* USB_DeviceDescriptor */ + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif + +/* USB Standard Device Descriptor */ +__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = +{ + USB_LEN_LANGID_STR_DESC, + USB_DESC_TYPE_STRING, + LOBYTE(USBD_LANGID_STRING), + HIBYTE(USBD_LANGID_STRING), +}; + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif +__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_FunctionPrototypes + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Functions + * @{ + */ + +/** +* @brief USBD_FS_DeviceDescriptor +* return the device descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + *length = sizeof(USBD_FS_DeviceDesc); + return USBD_FS_DeviceDesc; +} + +/** +* @brief USBD_FS_LangIDStrDescriptor +* return the LangID string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + *length = sizeof(USBD_LangIDDesc); + return USBD_LangIDDesc; +} + +/** +* @brief USBD_FS_ProductStrDescriptor +* return the product string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_ProductStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + if(speed == 0) + { + USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); + } + else + { + USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** +* @brief USBD_FS_ManufacturerStrDescriptor +* return the manufacturer string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_ManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length); + return USBD_StrDesc; +} + +/** +* @brief USBD_FS_SerialStrDescriptor +* return the serial number string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length); + } + else + { + USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** +* @brief USBD_FS_ConfigStrDescriptor +* return the configuration string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); + } + else + { + USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** +* @brief USBD_HS_InterfaceStrDescriptor +* return the interface string descriptor +* @param speed : current device speed +* @param length : pointer to data length variable +* @retval pointer to descriptor buffer +*/ +uint8_t * USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length) +{ + if(speed == 0) + { + USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); + } + else + { + USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#endif + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/usb/usbd_desc.h b/variants/MAPLEMINI_F103CB/usb/usbd_desc.h new file mode 100644 index 0000000000..521441af6c --- /dev/null +++ b/variants/MAPLEMINI_F103CB/usb/usbd_desc.h @@ -0,0 +1,107 @@ +/** + ****************************************************************************** + * @file : usbd_desc.h + * @version : v1.0_Cube + * @brief : Header for usbd_desc file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * 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. + * + ****************************************************************************** +*/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_DESC__H__ +#define __USBD_DESC__H__ + +#ifdef USBCON + +#ifdef __cplusplus + extern "C" { +#endif +/* Includes ------------------------------------------------------------------*/ +#include "usbd_def.h" + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USB_DESC + * @brief general defines for the usb device library file + * @{ + */ + +/** @defgroup USB_DESC_Exported_Defines + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_TypesDefinitions + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_Variables + * @{ + */ +extern USBD_DescriptorsTypeDef FS_Desc; +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_FunctionsPrototype + * @{ + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif + +#endif /* __USBD_DESC_H */ + +/** + * @} + */ + +/** +* @} +*/ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/MAPLEMINI_F103CB/variant.cpp b/variants/MAPLEMINI_F103CB/variant.cpp new file mode 100644 index 0000000000..a1a5849fc4 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/variant.cpp @@ -0,0 +1,206 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Pin number following http://wiki.stm32duino.com/index.php?title=Maple_Mini_pin_mapping +const PinName digitalPin[] = { +// Right side + PB11, //D0 + PB10, //D1 + PB2, //D2 + PB0, //D3 + PA7, //D4 + PA6, //D5 + PA5, //D6 + PA4, //D7 + PA3, //D8 + PA2, //D9 + PA1, //D10 + PA0, //D11 + PC15, //D12 + PC14, //D13 + PC13, //D14 +// Left side + PB7, //D15 + PB6, //D16 + PB5, //D17 + PB4, //D18 + PB3, //D19 + PA15, //D20 + PA14, //D21 + PA13, //D22 + PA12, //D23 + PA11, //D24 + PA10, //D25 + PA9, //D26 + PA8, //D27 + PB15, //D28 + PB14, //D29 + PB13, //D30 + PB12, //D31 +// Other + PB8, //D32 - User buttons + PB1, //D33 - LED + PB9, //D34 +// Duplicated pins in order to be aligned with PinMap_ADC + PB0, //D35/A0 = D3 + PA7, //D36/A1 = D4 + PA6, //D37/A2 = D5 + PA5, //D38/A3 = D6 + PA4, //D39/A4 = D7 + PA3, //D40/A5 = D8 + PA2, //D41/A6 = D9 + PA1, //D42/A7 = D10 + PA0 //D43/A8 = D11 +}; + +#ifdef __cplusplus +} +#endif + +/* + * UART objects + */ + +HardwareSerial Serial1(PA10, PA9); +#ifdef ENABLE_SERIAL2 +HardwareSerial Serial2(PA3, PA2); +#endif +#ifdef ENABLE_SERIAL3 +HardwareSerial Serial3(PB11, PB10); +#endif + +#if defined(SERIAL_USB) && defined(USBCON) +USBSerial Serial; //available on PA11/PA12 +#endif + +void serialEvent1() __attribute__((weak)); +void serialEvent1() { } +#ifdef ENABLE_SERIAL2 +void serialEvent2() __attribute__((weak)); +void serialEvent2() { } +#endif +#ifdef ENABLE_SERIAL3 +void serialEvent3() __attribute__((weak)); +void serialEvent3() { } +#endif + +#if defined(SERIAL_USB) && defined(USBCON) +void serialEvent() __attribute__((weak)); +void serialEvent() { } +#endif + +void serialEventRun(void) +{ + if (Serial1.available()) serialEvent1(); +#ifdef ENABLE_SERIAL2 + if (Serial2.available()) serialEvent2(); +#endif +#ifdef ENABLE_SERIAL3 + if (Serial3.available()) serialEvent3(); +#endif + +#if defined(SERIAL_USB) && defined(USBCON) + if (Serial.available()) serialEvent(); +#endif +} + +// ---------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(SERIAL_USB) && defined(USBCON) +void USBSerial_Rx_Handler(uint8_t *data, uint16_t len){ + Serial.CDC_RxHandler(data, len); +} +#endif + +/** + * @brief System Clock Configuration + * The system Clock is configured as follow : + * System Clock source = PLL (HSE) + * SYSCLK(Hz) = 72000000 + * HCLK(Hz) = 72000000 + * AHB Prescaler = 1 + * APB1 Prescaler = 2 + * APB2 Prescaler = 1 + * PLL_Source = HSE + * PLL_Mul = 9 + * Flash Latency(WS) = 2 + * ADC Prescaler = 6 + * USB Prescaler = 1.5 + * @param None + * @retval None + */ +WEAK void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInit; + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.LSEState = RCC_LSE_OFF; + RCC_OscInitStruct.HSIState = RCC_HSI_OFF; + RCC_OscInitStruct.HSICalibrationValue = 16; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; + 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) + { + while(1); + } + + 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) + { + while(1); + } + + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB; + PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + while(1); + } + + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); + + HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); + + /* SysTick_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); +} + +#ifdef __cplusplus +} +#endif diff --git a/variants/MAPLEMINI_F103CB/variant.h b/variants/MAPLEMINI_F103CB/variant.h new file mode 100644 index 0000000000..c4ee664fa5 --- /dev/null +++ b/variants/MAPLEMINI_F103CB/variant.h @@ -0,0 +1,151 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#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 { + 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, + DEND +}; + +enum { + A_START_AFTER = D34, + A0, A1, A2, A3, A4, A5, A6, A7, A8, + 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 33 +#define LED_GREEN LED_BUILTIN + +//On-board user button +#define USER_BTN 32 + +//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 7 + +//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 SS1 8 +#define SS2 9 +#define SS3 10 +#define MOSI 6 +#define MISO 5 +#define SCLK 4 +#define SCK SCLK + +//I2C Definitions +#define SDA 0 +#define SCL 1 + +//Timer Definitions +//Do not use timer used by PWM pins when possible. See PinMap_PWM. +#define TIMER_TONE TIM4 +#define TIMER_UART_EMULATED TIM4 + +//Do not use basic timer: OC is required +#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work + +#define DEBUG_UART ((USART_TypeDef *) USART1) + +// Serial Pin Firmata +#define PIN_SERIAL_RX 25 +#define PIN_SERIAL_TX 26 +#define PIN_SERIAL1_RX 8 +#define PIN_SERIAL1_TX 9 +#define PIN_SERIAL2_RX 0 +#define PIN_SERIAL2_TX 1 + +#if defined(SERIAL_USB) && defined(USBCON) && !defined(USB_DISC_PIN) +#define USB_DISC_PIN 34 + +#ifdef __cplusplus +} // extern "C" +#endif +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern HardwareSerial Serial1; +extern HardwareSerial Serial2; +extern HardwareSerial Serial3; + +#if defined(SERIAL_USB) && defined(USBCON) +extern USBSerial Serial; +#else +#define Serial Serial1 +#endif + +// 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_USBVIRTUAL Serial +#define SERIAL_PORT_HARDWARE Serial1 +#endif + +#endif /* _VARIANT_ARDUINO_STM32_ */ From b3d9dffa127e51049694c30c61d5aa346310a8bc Mon Sep 17 00:00:00 2001 From: fpr Date: Fri, 30 Jun 2017 11:34:08 +0200 Subject: [PATCH 13/30] DAC1 replaced by DAC and timer IRQ definitions moved to the right place Signed-off-by: fpr --- cores/arduino/stm32/stm32_def.h | 5 +---- cores/arduino/stm32/timer.h | 6 +++--- variants/DISCO_F100RB/PeripheralPins.c | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/cores/arduino/stm32/stm32_def.h b/cores/arduino/stm32/stm32_def.h index 0e4dfd1e6c..a0a6b09a60 100644 --- a/cores/arduino/stm32/stm32_def.h +++ b/cores/arduino/stm32/stm32_def.h @@ -57,10 +57,7 @@ #define I2C1_EV_IRQn I2C1_IRQn #elif defined(STM32F1xx) -#define DAC1 DAC -#define TIM15_IRQn TIM1_BRK_TIM15_IRQn -#define TIM16_IRQn TIM1_UP_TIM16_IRQn -#define TIM17_IRQn TIM1_TRG_COM_TIM17_IRQn + #elif defined(STM32F2xx) #elif defined(STM32F3xx) diff --git a/cores/arduino/stm32/timer.h b/cores/arduino/stm32/timer.h index a64e5be94d..a73ea80383 100644 --- a/cores/arduino/stm32/timer.h +++ b/cores/arduino/stm32/timer.h @@ -127,17 +127,17 @@ struct timer_s{ #endif #endif #if defined(TIM15_BASE) && !defined(TIM15_IRQn) -#if defined(STM32F3xx) || defined(STM32L4xx) +#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx) #define TIM15_IRQn TIM1_BRK_TIM15_IRQn #endif #endif #if defined(TIM16_BASE) && !defined(TIM16_IRQn) -#if defined(STM32F3xx) || defined(STM32L4xx) +#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx) #define TIM16_IRQn TIM1_UP_TIM16_IRQn #endif #endif #if defined(TIM17_BASE) && !defined(TIM17_IRQn) -#if defined(STM32F3xx) || defined(STM32L4xx) +#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx) #define TIM17_IRQn TIM1_TRG_COM_TIM17_IRQn #endif #endif diff --git a/variants/DISCO_F100RB/PeripheralPins.c b/variants/DISCO_F100RB/PeripheralPins.c index 15b11c4f8e..9daca60c7c 100644 --- a/variants/DISCO_F100RB/PeripheralPins.c +++ b/variants/DISCO_F100RB/PeripheralPins.c @@ -61,8 +61,8 @@ const PinMap PinMap_ADC[] = { //*** DAC *** const PinMap PinMap_DAC[] = { - {PA4, DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC_OUT1 - {PA5, DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC_OUT2 + {PA4, DAC, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC_OUT1 + {PA5, DAC, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC_OUT2 {NC, NC, 0} }; From c11863eb3af221fab80c5724779e400f4f1d0834 Mon Sep 17 00:00:00 2001 From: fpr Date: Fri, 30 Jun 2017 11:40:20 +0200 Subject: [PATCH 14/30] Aligns configuration with master Signed-off-by: fpr --- variants/BLUEPILL_F103C8/PeripheralPins.c | 34 +++++++++------------- variants/DISCO_F100RB/PeripheralPins.c | 30 +++++++++---------- variants/MAPLEMINI_F103CB/PeripheralPins.c | 34 +++++++++------------- 3 files changed, 43 insertions(+), 55 deletions(-) diff --git a/variants/BLUEPILL_F103C8/PeripheralPins.c b/variants/BLUEPILL_F103C8/PeripheralPins.c index 57477330a2..8b8270bc3b 100644 --- a/variants/BLUEPILL_F103C8/PeripheralPins.c +++ b/variants/BLUEPILL_F103C8/PeripheralPins.c @@ -59,13 +59,7 @@ const PinMap PinMap_ADC[] = { // {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 {PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 // {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 - {NC, NC, 0} -}; - -//*** DAC *** - -const PinMap PinMap_DAC[] = { - {NC, NC, 0} + {NC, NP, 0} }; //*** I2C *** @@ -74,14 +68,14 @@ const PinMap PinMap_I2C_SDA[] = { {PB7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, {PB9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 {PB11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_I2C_SCL[] = { {PB6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, {PB8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 {PB10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** PWM *** @@ -115,7 +109,7 @@ const PinMap PinMap_PWM[] = { {PB13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM1_CH1N {PB14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 1)}, // TIM1_CH2N {PB15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 1)}, // TIM1_CH3N - {NC, NC, 0} + {NC, NP, 0} }; //*** SERIAL *** @@ -125,7 +119,7 @@ const PinMap PinMap_UART_TX[] = { {PA9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 {PB10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_RX[] = { @@ -133,21 +127,21 @@ const PinMap PinMap_UART_RX[] = { {PA10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 {PB11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_RTS[] = { {PA1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_CTS[] = { {PA0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** SPI *** @@ -156,28 +150,28 @@ const PinMap PinMap_SPI_MOSI[] = { {PA7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_MISO[] = { {PA6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_SCLK[] = { {PA5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_SSEL[] = { {PA4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** CAN *** @@ -185,11 +179,11 @@ const PinMap PinMap_SPI_SSEL[] = { const PinMap PinMap_CAN_RD[] = { {PA11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, {PB8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_RX to PB_9 - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_CAN_TD[] = { {PA12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, {PB9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_TX to PB_9 - {NC, NC, 0} + {NC, NP, 0} }; diff --git a/variants/DISCO_F100RB/PeripheralPins.c b/variants/DISCO_F100RB/PeripheralPins.c index 9daca60c7c..dd47832481 100644 --- a/variants/DISCO_F100RB/PeripheralPins.c +++ b/variants/DISCO_F100RB/PeripheralPins.c @@ -55,7 +55,7 @@ const PinMap PinMap_ADC[] = { {PC3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 {PC4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 {PC5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 - {NC, NC, 0} + {NC, NP, 0} }; //*** DAC *** @@ -63,7 +63,7 @@ const PinMap PinMap_ADC[] = { const PinMap PinMap_DAC[] = { {PA4, DAC, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC_OUT1 {PA5, DAC, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC_OUT2 - {NC, NC, 0} + {NC, NP, 0} }; //*** I2C *** @@ -72,14 +72,14 @@ const PinMap PinMap_I2C_SDA[] = { {PB7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, {PB9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 {PB11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_I2C_SCL[] = { {PB6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, {PB8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 {PB10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** PWM *** @@ -128,7 +128,7 @@ const PinMap PinMap_PWM[] = { {PC7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 2, 0)}, // TIM3_CH2 - GPIO_FullRemap_TIM3 {PC8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 3, 0)}, // TIM3_CH3 - GPIO_FullRemap_TIM3 {PC9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 4, 0)}, // TIM3_CH4 - GPIO_FullRemap_TIM3 - {NC, NC, 0} + {NC, NP, 0} }; //*** SERIAL *** @@ -139,7 +139,7 @@ const PinMap PinMap_UART_TX[] = { {PB6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 {PB10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PC10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 5)}, // GPIO_PartialRemap_USART3 - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_RX[] = { @@ -148,21 +148,21 @@ const PinMap PinMap_UART_RX[] = { {PB7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 {PB11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PC11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 5)}, // GPIO_PartialRemap_USART3 - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_RTS[] = { {PA1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_CTS[] = { {PA0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** SPI *** @@ -171,36 +171,36 @@ const PinMap PinMap_SPI_MOSI[] = { {PA7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_MISO[] = { {PA6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_SCLK[] = { {PA5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_SSEL[] = { {PA4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** CAN *** const PinMap PinMap_CAN_RD[] = { - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_CAN_TD[] = { - {NC, NC, 0} + {NC, NP, 0} }; diff --git a/variants/MAPLEMINI_F103CB/PeripheralPins.c b/variants/MAPLEMINI_F103CB/PeripheralPins.c index 57477330a2..8b8270bc3b 100644 --- a/variants/MAPLEMINI_F103CB/PeripheralPins.c +++ b/variants/MAPLEMINI_F103CB/PeripheralPins.c @@ -59,13 +59,7 @@ const PinMap PinMap_ADC[] = { // {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 {PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 // {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 - {NC, NC, 0} -}; - -//*** DAC *** - -const PinMap PinMap_DAC[] = { - {NC, NC, 0} + {NC, NP, 0} }; //*** I2C *** @@ -74,14 +68,14 @@ const PinMap PinMap_I2C_SDA[] = { {PB7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, {PB9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 {PB11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_I2C_SCL[] = { {PB6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, {PB8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 {PB10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** PWM *** @@ -115,7 +109,7 @@ const PinMap PinMap_PWM[] = { {PB13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 1)}, // TIM1_CH1N {PB14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 1)}, // TIM1_CH2N {PB15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 1)}, // TIM1_CH3N - {NC, NC, 0} + {NC, NP, 0} }; //*** SERIAL *** @@ -125,7 +119,7 @@ const PinMap PinMap_UART_TX[] = { {PA9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 {PB10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_RX[] = { @@ -133,21 +127,21 @@ const PinMap PinMap_UART_RX[] = { {PA10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 {PB11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_RTS[] = { {PA1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_CTS[] = { {PA0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** SPI *** @@ -156,28 +150,28 @@ const PinMap PinMap_SPI_MOSI[] = { {PA7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_MISO[] = { {PA6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_SCLK[] = { {PA5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_SSEL[] = { {PA4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** CAN *** @@ -185,11 +179,11 @@ const PinMap PinMap_SPI_SSEL[] = { const PinMap PinMap_CAN_RD[] = { {PA11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, {PB8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_RX to PB_9 - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_CAN_TD[] = { {PA12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, {PB9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_TX to PB_9 - {NC, NC, 0} + {NC, NP, 0} }; From 4e41cd1a19d529de3a4e9322d47b172cc5748f4f Mon Sep 17 00:00:00 2001 From: fpr Date: Fri, 30 Jun 2017 11:44:35 +0200 Subject: [PATCH 15/30] Fixes compilation error with Maple mini board Signed-off-by: fpr --- variants/MAPLEMINI_F103CB/variant.h | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/MAPLEMINI_F103CB/variant.h b/variants/MAPLEMINI_F103CB/variant.h index c4ee664fa5..7df730c1e9 100644 --- a/variants/MAPLEMINI_F103CB/variant.h +++ b/variants/MAPLEMINI_F103CB/variant.h @@ -110,6 +110,7 @@ enum { #if defined(SERIAL_USB) && defined(USBCON) && !defined(USB_DISC_PIN) #define USB_DISC_PIN 34 +#endif #ifdef __cplusplus } // extern "C" From 80fbf704f44553be1e7cb1463ad31c4c3ad0324f Mon Sep 17 00:00:00 2001 From: fpr Date: Fri, 30 Jun 2017 11:53:30 +0200 Subject: [PATCH 16/30] STM32F1xx flag reordered Signed-off-by: fpr --- cores/arduino/stm32/analog.c | 10 +++------- cores/arduino/stm32/uart.c | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cores/arduino/stm32/analog.c b/cores/arduino/stm32/analog.c index 67e4f41444..f93ec976d2 100644 --- a/cores/arduino/stm32/analog.c +++ b/cores/arduino/stm32/analog.c @@ -564,19 +564,15 @@ uint16_t adc_read_value(PinName pin) #ifndef STM32F1xx AdcHandle.Init.ClockPrescaler = ADC_CLOCK_DIV; /* Asynchronous clock mode, input ADC clock divided */ AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; /* 12-bit resolution for converted data */ + AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */ + AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */ + AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */ #endif AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* Right-alignment for converted data */ AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */ -#ifndef STM32F1xx - AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */ -#endif AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */ AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */ -#ifndef STM32F1xx - AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */ - AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */ -#endif AdcHandle.State = HAL_ADC_STATE_RESET; #if defined (STM32F0xx) || defined (STM32L0xx) AdcHandle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */ diff --git a/cores/arduino/stm32/uart.c b/cores/arduino/stm32/uart.c index c244844231..24fa03acd1 100644 --- a/cores/arduino/stm32/uart.c +++ b/cores/arduino/stm32/uart.c @@ -528,7 +528,7 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) { volatile uint32_t tmpval; -#if defined(STM32F4xx) || defined(STM32F1xx) +#if defined(STM32F1xx) || defined(STM32F4xx) if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) { tmpval = huart->Instance->DR; // Clear PE flag } else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) { From 1182fd5adbf25e5c1c131afbd9e3b2c39c103e28 Mon Sep 17 00:00:00 2001 From: fpr Date: Fri, 30 Jun 2017 12:07:35 +0200 Subject: [PATCH 17/30] Fixes compilation error: Error_Handler do not exist any more Signed-off-by: fpr --- variants/BLUEPILL_F103C8/usb/usbd_conf.c | 3 +-- variants/MAPLEMINI_F103CB/usb/usbd_conf.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/variants/BLUEPILL_F103C8/usb/usbd_conf.c b/variants/BLUEPILL_F103C8/usb/usbd_conf.c index 25278996b3..a523d7887c 100644 --- a/variants/BLUEPILL_F103C8/usb/usbd_conf.c +++ b/variants/BLUEPILL_F103C8/usb/usbd_conf.c @@ -45,7 +45,6 @@ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ PCD_HandleTypeDef hpcd_USB_FS; -void Error_Handler(void); /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ @@ -267,7 +266,7 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) hpcd_USB_FS.Init.battery_charging_enable = DISABLE; if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) { - Error_Handler(); + while(1); } HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); diff --git a/variants/MAPLEMINI_F103CB/usb/usbd_conf.c b/variants/MAPLEMINI_F103CB/usb/usbd_conf.c index 25278996b3..a523d7887c 100644 --- a/variants/MAPLEMINI_F103CB/usb/usbd_conf.c +++ b/variants/MAPLEMINI_F103CB/usb/usbd_conf.c @@ -45,7 +45,6 @@ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ PCD_HandleTypeDef hpcd_USB_FS; -void Error_Handler(void); /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ @@ -267,7 +266,7 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) hpcd_USB_FS.Init.battery_charging_enable = DISABLE; if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) { - Error_Handler(); + while(1); } HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); From bd70f52086f8ece9601908e014c5460b9f15f0f4 Mon Sep 17 00:00:00 2001 From: fpr Date: Mon, 3 Jul 2017 09:50:39 +0200 Subject: [PATCH 18/30] Fixes issue on ADC value: calibration function wasn't called Signed-off-by: fpr --- cores/arduino/stm32/analog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/stm32/analog.c b/cores/arduino/stm32/analog.c index f93ec976d2..3a0a8ea24e 100644 --- a/cores/arduino/stm32/analog.c +++ b/cores/arduino/stm32/analog.c @@ -615,9 +615,9 @@ uint16_t adc_read_value(PinName pin) return 0; } -#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32L4xx) +#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || defined (STM32L4xx) /*##-2.1- Calibrate ADC then Start the conversion process ####################*/ -#if defined (STM32F0xx) +#if defined (STM32F0xx) || defined (STM32F1xx) if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK) #else if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK) From bec19f158c08f7cacaa83ba5f6f9bb5971cea5fb Mon Sep 17 00:00:00 2001 From: fpr Date: Mon, 3 Jul 2017 09:57:29 +0200 Subject: [PATCH 19/30] Aligns configuration of variant Nucleo-F103RB Signed-off-by: fpr --- variants/NUCLEO_F103RB/PeripheralPins.c | 34 ++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/variants/NUCLEO_F103RB/PeripheralPins.c b/variants/NUCLEO_F103RB/PeripheralPins.c index 627c715850..a04c59ef2a 100644 --- a/variants/NUCLEO_F103RB/PeripheralPins.c +++ b/variants/NUCLEO_F103RB/PeripheralPins.c @@ -71,13 +71,7 @@ const PinMap PinMap_ADC[] = { // {PC4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 {PC5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 // {PC5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 - {NC, NC, 0} -}; - -//*** DAC *** - -const PinMap PinMap_DAC[] = { - {NC, NC, 0} + {NC, NP, 0} }; //*** I2C *** @@ -86,14 +80,14 @@ const PinMap PinMap_I2C_SDA[] = { {PB7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, {PB9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 {PB11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_I2C_SCL[] = { {PB6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, {PB8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 2)}, // GPIO_Remap_I2C1 {PB10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** PWM *** @@ -131,7 +125,7 @@ const PinMap PinMap_PWM[] = { {PC7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 2, 0)}, // TIM3_CH2 - GPIO_FullRemap_TIM3 {PC8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 3, 0)}, // TIM3_CH3 - GPIO_FullRemap_TIM3 {PC9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 9, 4, 0)}, // TIM3_CH4 - GPIO_FullRemap_TIM3 - {NC, NC, 0} + {NC, NP, 0} }; //*** SERIAL *** @@ -142,7 +136,7 @@ const PinMap PinMap_UART_TX[] = { {PB6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 {PB10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PC10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 5)}, // GPIO_PartialRemap_USART3 - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_RX[] = { @@ -151,21 +145,21 @@ const PinMap PinMap_UART_RX[] = { {PB7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 3)}, // GPIO_Remap_USART1 {PB11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PC11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 5)}, // GPIO_PartialRemap_USART3 - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_RTS[] = { {PA1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_UART_CTS[] = { {PA0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** SPI *** @@ -174,28 +168,28 @@ const PinMap PinMap_SPI_MOSI[] = { {PA7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_MISO[] = { {PA6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_SCLK[] = { {PA5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PB3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_SPI_SSEL[] = { {PA4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, {PA15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 1)}, // GPIO_Remap_SPI1 {PB12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, - {NC, NC, 0} + {NC, NP, 0} }; //*** CAN *** @@ -203,11 +197,11 @@ const PinMap PinMap_SPI_SSEL[] = { const PinMap PinMap_CAN_RD[] = { {PA11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, {PB8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_RX to PB_9 - {NC, NC, 0} + {NC, NP, 0} }; const PinMap PinMap_CAN_TD[] = { {PA12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)}, {PB9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 10)}, // Remap CAN_TX to PB_9 - {NC, NC, 0} + {NC, NP, 0} }; From dcae4b8020bbe55af3795ce3ce47ef1c8cd6dc9e Mon Sep 17 00:00:00 2001 From: fpr Date: Mon, 3 Jul 2017 10:01:37 +0200 Subject: [PATCH 20/30] Extra include path moved to the right place Signed-off-by: fpr --- boards.txt | 4 ++-- platform.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/boards.txt b/boards.txt index c41bd8e483..ef9063b325 100644 --- a/boards.txt +++ b/boards.txt @@ -290,7 +290,7 @@ Other_board.menu.Other_board.BLUEPILL_F103C8.build.cmsis_lib_gcc=arm_cortexM3l_m #To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' #To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2 #To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3 -Other_board.menu.Other_board.BLUEPILL_F103C8.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" +Other_board.menu.Other_board.BLUEPILL_F103C8.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON # MAPLEMINI_F103CB board @@ -309,7 +309,7 @@ Other_board.menu.Other_board.MAPLEMINI_F103CB.build.cmsis_lib_gcc=arm_cortexM3l_ #To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' #To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2 #To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3 -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" +Other_board.menu.Other_board.MAPLEMINI_F103CB.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON Other_board.menu.upload_method.DFUUploadMethod1=Maple bootloader (original version for Maple boards) diff --git a/platform.txt b/platform.txt index 4abad1d95c..4f4d5dc26f 100644 --- a/platform.txt +++ b/platform.txt @@ -10,7 +10,7 @@ version=1.0.0 # STM compile variables # ---------------------- -compiler.stm.extra_include="-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc/" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src/" "-I{build.system.path}/{build.series}/" "-I{build.variant.path}/usb" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" +compiler.stm.extra_include="-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc/" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src/" "-I{build.system.path}/{build.series}/" "-I{build.variant.path}/usb" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" # "-I{build.system.path}/Drivers/BSP/Components" "-I{build.system.path}/Middlewares/Third_Party/FatFs/src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc" From 0df66421368ec3354e74dd1daf47aaa9b717d95e Mon Sep 17 00:00:00 2001 From: fpr Date: Mon, 3 Jul 2017 10:32:09 +0200 Subject: [PATCH 21/30] Tab replaced by space Signed-off-by: fpr --- variants/DISCO_F100RB/variant.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/variants/DISCO_F100RB/variant.h b/variants/DISCO_F100RB/variant.h index c0e826a189..b8d15a58e6 100644 --- a/variants/DISCO_F100RB/variant.h +++ b/variants/DISCO_F100RB/variant.h @@ -64,9 +64,9 @@ extern "C"{ #define PWM_MAX_DUTY_CYCLE 255 //On-board LED pin number -#define LED_BUILTIN 21 -#define LED_GREEN LED_BUILTIN -#define LED_BLUE 20 +#define LED_BUILTIN 21 +#define LED_GREEN LED_BUILTIN +#define LED_BLUE 20 //On-board user button #define USER_BTN 5 From ab26c434535871dbe04bcfafa133c9a35db92f15 Mon Sep 17 00:00:00 2001 From: fpr Date: Mon, 3 Jul 2017 10:35:05 +0200 Subject: [PATCH 22/30] BluePill pin mapping reordered Signed-off-by: fpr --- variants/BLUEPILL_F103C8/variant.cpp | 73 +++++++++++++++------------- variants/BLUEPILL_F103C8/variant.h | 21 ++++---- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/variants/BLUEPILL_F103C8/variant.cpp b/variants/BLUEPILL_F103C8/variant.cpp index 4e92dcac48..e4c365304f 100644 --- a/variants/BLUEPILL_F103C8/variant.cpp +++ b/variants/BLUEPILL_F103C8/variant.cpp @@ -22,9 +22,8 @@ extern "C" { #endif -// Pin number +// Pin number following https://github.com/stm32duino/Arduino_Core_STM32F1/blob/master/variants/STM32F103C_BluePill/variant.h const PinName digitalPin[] = { - // Right side PA0, //D0 PA1, //D1 PA2, //D2 @@ -33,40 +32,44 @@ const PinName digitalPin[] = { PA5, //D5 PA6, //D6 PA7, //D7 - PB0, //D8 - PB1, //D9 - PB10, //D10 - PB11, //D11 - // Left side - PB12, //D12 - PB13, //D13 - PB14, //D14 - PB15, //D15 - PA8, //D16 - PA9, //D17 - PA10, //D18 - PA11, //D19 - PA12, //D20 - PA15, //D21 - PB3, //D22 - PB4, //D23 - PB5, //D24 - PB6, //D25 - PB7, //D26 - PB8, //D27 - PB9, //D28 - PC13, //D29 - LED + PA8, //D8 + PA9, //D9 + PA10, //D10 + PA11, //D11 + PA12, //D12 + PA13, //D13 + PA14, //D14 + PA15, //D15 + PB0, //D16 + PB1, //D17 + PB2, //D18 + PB3, //D19 + PB4, //D20 + PB5, //D21 + PB6, //D22 + PB7, //D23 + PB8, //D24 + PB9, //D25 + PB10, //D26 + PB11, //D27 + PB12, //D28 + PB13, //D29 + PB14, //D30 + PB15, //D31 + PC13, //D32 - LED + PC14, //D33 + PC15, //D34 // Duplicated pins in order to be aligned with PinMap_ADC - PA0, //D30/A0 = D0 - PA1, //D31/A1 = D1 - PA2, //D32/A2 = D2 - PA3, //D33/A3 = D3 - PA4, //D34/A4 = D4 - PA5, //D35/A5 = D5 - PA6, //D36/A6 = D6 - PA7, //D37/A7 = D7 - PB0, //D38/A8 = D8 - PB1 //D39/A9 = D9 + PA0, //D35/A0 = D0 + PA1, //D36/A1 = D1 + PA2, //D37/A2 = D2 + PA3, //D38/A3 = D3 + PA4, //D39/A4 = D4 + PA5, //D40/A5 = D5 + PA6, //D41/A6 = D6 + PA7, //D42/A7 = D7 + PB0, //D43/A8 = D8 + PB1 //D44/A9 = D9 }; #ifdef __cplusplus diff --git a/variants/BLUEPILL_F103C8/variant.h b/variants/BLUEPILL_F103C8/variant.h index 769764a4b9..08bba93be4 100644 --- a/variants/BLUEPILL_F103C8/variant.h +++ b/variants/BLUEPILL_F103C8/variant.h @@ -41,11 +41,12 @@ enum { 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, DEND }; enum { - A_START_AFTER = D29, + A_START_AFTER = D34, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, AEND }; @@ -60,8 +61,8 @@ enum { #define PWM_MAX_DUTY_CYCLE 255 //On-board LED pin number -#define LED_BUILTIN 29 -#define LED_GREEN LED_BUILTIN +#define LED_BUILTIN 32 +#define LED_GREEN LED_BUILTIN //SPI definitions //define 16 channels. As many channel as digital IOs @@ -83,8 +84,8 @@ enum { #define SCK SCLK //I2C Definitions -#define SDA 26 -#define SCL 25 +#define SDA 23 +#define SCL 22 //Timer Definitions //Do not use timer used by PWM pins when possible. See PinMap_PWM. @@ -97,15 +98,15 @@ enum { #define DEBUG_UART ((USART_TypeDef *) USART1) // Serial Pin Firmata -#define PIN_SERIAL_RX 18 -#define PIN_SERIAL_TX 17 +#define PIN_SERIAL_RX 10 +#define PIN_SERIAL_TX 9 #define PIN_SERIAL1_RX 3 #define PIN_SERIAL1_TX 2 -#define PIN_SERIAL2_RX 11 -#define PIN_SERIAL2_TX 10 +#define PIN_SERIAL2_RX 27 +#define PIN_SERIAL2_TX 26 #if defined(SERIAL_USB) && defined(USBCON) -#define USB_DISC_PIN 20 //PA12 = USB Plus (+) pin number. That pin is normally pulled up to 3.3v by a 1.5k resistor +#define USB_DISC_PIN 12 //PA12 = USB Plus (+) pin number. That pin is normally pulled up to 3.3v by a 1.5k resistor #endif #ifdef __cplusplus From e23f252036c09eac7a8e2beb8f2d3cd15f677a21 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 5 Jul 2017 14:33:44 +0200 Subject: [PATCH 23/30] Fix warning for unused variable Signed-off-by: Frederic.Pillon --- libraries/Wire/Wire.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index de5d201e34..48f5c9dece 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -131,6 +131,9 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres } endTransmission(false); } +#else + UNUSED(iaddress); + UNUSED(isize); #endif /* !STM32F1xx */ // clamp to buffer length From 5894c101fd27fd9ab6bb7b4277a0a3d0bb444a37 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 5 Jul 2017 14:57:58 +0200 Subject: [PATCH 24/30] Align commented lines Signed-off-by: Frederic.Pillon --- variants/NUCLEO_F103RB/PeripheralPins.c | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/variants/NUCLEO_F103RB/PeripheralPins.c b/variants/NUCLEO_F103RB/PeripheralPins.c index a04c59ef2a..d2ea564e3c 100644 --- a/variants/NUCLEO_F103RB/PeripheralPins.c +++ b/variants/NUCLEO_F103RB/PeripheralPins.c @@ -40,37 +40,37 @@ const PinMap PinMap_ADC[] = { {PA0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 - // {PA0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 +// {PA0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 {PA1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 - // {PA1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 +// {PA1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 {PA2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 - // {PA2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 +// {PA2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 {PA3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 - // {PA3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 +// {PA3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 {PA4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 - // {PA4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 +// {PA4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 {PA5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 - // {PA5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 +// {PA5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 {PA6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 - // {PA6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 +// {PA6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 {PA7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 - // {PA7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 +// {PA7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 {PB0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 - // {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 +// {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 {PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 - // {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 +// {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 {PC0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 - // {PC0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 +// {PC0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 {PC1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 - // {PC1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 +// {PC1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 {PC2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 - // {PC2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 +// {PC2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 {PC3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 - // {PC3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 +// {PC3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 {PC4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 - // {PC4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 +// {PC4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 {PC5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 - // {PC5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 +// {PC5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 {NC, NP, 0} }; @@ -98,16 +98,16 @@ const PinMap PinMap_PWM[] = { {PA2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM2_CH3 {PA3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM2_CH4 {PA6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM3_CH1 - // {PA7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 1, 1)}, // TIM1_CH1N - GPIO_PartialRemap_TIM1 +// {PA7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 1, 1)}, // TIM1_CH1N - GPIO_PartialRemap_TIM1 {PA7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM3_CH2 {PA8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM1_CH1 {PA9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM1_CH2 {PA10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM1_CH3 {PA11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM1_CH4 {PA15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 1, 0)}, // TIM2_CH1 - GPIO_FullRemap_TIM2 - // {PB0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 2, 1)}, // TIM1_CH2N - GPIO_PartialRemap_TIM1 +// {PB0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 2, 1)}, // TIM1_CH2N - GPIO_PartialRemap_TIM1 {PB0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM3_CH3 - // {PB1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 3, 1)}, // TIM1_CH3N - GPIO_PartialRemap_TIM1 +// {PB1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 3, 1)}, // TIM1_CH3N - GPIO_PartialRemap_TIM1 {PB1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM3_CH4 {PB3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 8, 2, 0)}, // TIM2_CH2 - GPIO_FullRemap_TIM2 {PB4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 7, 1, 0)}, // TIM3_CH1 - GPIO_PartialRemap_TIM3 From 3ffb5fda7693002369d56649f794c566ad96317b Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 5 Jul 2017 15:00:16 +0200 Subject: [PATCH 25/30] Fix for firmata Remove STLink Rx/TX from Ax and comment in PinMap arrays other than UARTyx one. Signed-off-by: Frederic.Pillon --- variants/NUCLEO_F103RB/PeripheralPins.c | 8 ++++---- variants/NUCLEO_F103RB/variant.cpp | 16 +++++++--------- variants/NUCLEO_F103RB/variant.h | 5 ++--- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/variants/NUCLEO_F103RB/PeripheralPins.c b/variants/NUCLEO_F103RB/PeripheralPins.c index d2ea564e3c..c0aceead20 100644 --- a/variants/NUCLEO_F103RB/PeripheralPins.c +++ b/variants/NUCLEO_F103RB/PeripheralPins.c @@ -43,9 +43,9 @@ const PinMap PinMap_ADC[] = { // {PA0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 {PA1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 // {PA1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 - {PA2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 +// {PA2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 - STLink Tx // {PA2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 - {PA3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 +// {PA3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 - STLink Rx // {PA3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 {PA4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 // {PA4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 @@ -95,8 +95,8 @@ const PinMap PinMap_I2C_SCL[] = { const PinMap PinMap_PWM[] = { {PA0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM2_CH1 {PA1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM2_CH2 - {PA2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM2_CH3 - {PA3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM2_CH4 +// {PA2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 3, 0)}, // TIM2_CH3 - STLink Rx +// {PA3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 4, 0)}, // TIM2_CH4 - STLink Tx {PA6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 1, 0)}, // TIM3_CH1 // {PA7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 6, 1, 1)}, // TIM1_CH1N - GPIO_PartialRemap_TIM1 {PA7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, 0, 2, 0)}, // TIM3_CH2 diff --git a/variants/NUCLEO_F103RB/variant.cpp b/variants/NUCLEO_F103RB/variant.cpp index 7b99fa029c..4d2e9d2672 100644 --- a/variants/NUCLEO_F103RB/variant.cpp +++ b/variants/NUCLEO_F103RB/variant.cpp @@ -82,15 +82,13 @@ const PinName digitalPin[] = { PC1, //D50/A4 PC0, //D51/A5 // Duplicated pins in order to be aligned with PinMap_ADC - PA3, //D52/A6 = D0 - PA2, //D53/A7 = D1 - PA7, //D54/A8 = D11 - PA6, //D55/A9 = D12 - PA5, //D56/A10 = D13 - PC2, //D57/A11 = D28 - PC3, //D58/A12 = D29 - PB1, //D59/A13 = D41 - PC4, //D60/A14 = D45 + PA7, //D52/A6 = D11 + PA6, //D53/A7 = D12 + PA5, //D54/A8 = D13 + PC2, //D55/A9 = D28 + PC3, //D56/A10 = D29 + PB1, //D57/A11 = D41 + PC4 //D58/A12 = D45 }; #ifdef __cplusplus diff --git a/variants/NUCLEO_F103RB/variant.h b/variants/NUCLEO_F103RB/variant.h index de339a1ec0..d678ed4447 100644 --- a/variants/NUCLEO_F103RB/variant.h +++ b/variants/NUCLEO_F103RB/variant.h @@ -42,15 +42,14 @@ enum { 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, + D50, D51, D52, D53, D54, D55, D56, D57, D58, DEND }; enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, A14, + A10, A11, A12, AEND }; From 2130c91e39270e440afd4221701d947e6299eb2a Mon Sep 17 00:00:00 2001 From: fpr Date: Thu, 6 Jul 2017 11:17:30 +0200 Subject: [PATCH 26/30] Use F_CPU defined in board.txt Signed-off-by: fpr --- system/STM32F1xx/system_stm32f1xx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/system/STM32F1xx/system_stm32f1xx.c b/system/STM32F1xx/system_stm32f1xx.c index e78886bc51..4f32ca5beb 100644 --- a/system/STM32F1xx/system_stm32f1xx.c +++ b/system/STM32F1xx/system_stm32f1xx.c @@ -133,11 +133,7 @@ /******************************************************************************* * Clock Definitions *******************************************************************************/ -#if defined(STM32F100xB) ||defined(STM32F100xE) - uint32_t SystemCoreClock = 24000000; /*!< System Clock Frequency (Core Clock) */ -#else /*!< HSI Selected as System Clock source */ - uint32_t SystemCoreClock = 72000000; /*!< System Clock Frequency (Core Clock) */ -#endif +uint32_t SystemCoreClock = F_CPU; /*!< System Clock Frequency (Core Clock) */ const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; From dbb5571e12146972ce2f560e5360681fb823ae73 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 5 Jul 2017 16:47:25 +0200 Subject: [PATCH 27/30] Fix size in boards.txt for Nucleo F103RB Signed-off-by: Frederic.Pillon --- boards.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boards.txt b/boards.txt index ef9063b325..52599770ae 100644 --- a/boards.txt +++ b/boards.txt @@ -90,8 +90,8 @@ Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.cmsis_lib_gcc=arm_cortexM0l_ma Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB=Nucleo F103RB Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.node="NODE_F103RB,NUCLEO" -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_size=131071 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_data_size=20479 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_size=131072 +Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_data_size=20480 Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.mcu=cortex-m3 Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.f_cpu=72000000L Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.board=NUCLEO_F103RB From 1bcfddddf8cabbe89c652ffd237e64c703f2e589 Mon Sep 17 00:00:00 2001 From: fpr Date: Thu, 6 Jul 2017 11:56:57 +0200 Subject: [PATCH 28/30] Allow VECT_TAB_OFFSET to be override Signed-off-by: fpr --- system/STM32F1xx/system_stm32f1xx.c | 152 ++++++++++++++-------------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/system/STM32F1xx/system_stm32f1xx.c b/system/STM32F1xx/system_stm32f1xx.c index 4f32ca5beb..a582b704d1 100644 --- a/system/STM32F1xx/system_stm32f1xx.c +++ b/system/STM32F1xx/system_stm32f1xx.c @@ -5,19 +5,19 @@ * @version V4.1.0 * @date 29-April-2016 * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. - * - * 1. This file provides two functions and one global variable to be called from + * + * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier - * factors, AHB/APBx prescalers and Flash settings). - * This function is called at startup just after reset and + * factors, AHB/APBx prescalers and Flash settings). + * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used - * by the user application to setup the SysTick + * by the user application to setup the SysTick * timer or configure other parameters. - * + * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. @@ -27,11 +27,11 @@ * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on - * the product used), refer to "HSE_VALUE". + * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. - * + * ****************************************************************************** * @attention * @@ -68,8 +68,8 @@ /** @addtogroup stm32f1xx_system * @{ - */ - + */ + /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ @@ -92,7 +92,7 @@ * @{ */ -#if !defined (HSE_VALUE) +#if !defined (HSE_VALUE) #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ @@ -102,16 +102,18 @@ This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ -/*!< Uncomment the following line if you need to use external SRAM */ +/*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in - Internal SRAM. */ + Internal SRAM. */ /* #define VECT_TAB_SRAM */ -#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field. +#ifndef VECT_TAB_OFFSET +#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ +#endif /** @@ -148,7 +150,7 @@ const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM - static void SystemInit_ExtMemCtl(void); + static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ @@ -162,7 +164,7 @@ const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @brief Setup the microcontroller system - * Initialize the Embedded Flash Interface, the PLL and update the + * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None @@ -179,8 +181,8 @@ void SystemInit (void) RCC->CFGR &= (uint32_t)0xF8FF0000; #else RCC->CFGR &= (uint32_t)0xF0FF0000; -#endif /* STM32F105xC */ - +#endif /* STM32F105xC */ + /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= (uint32_t)0xFEF6FFFF; @@ -204,23 +206,23 @@ void SystemInit (void) RCC->CIR = 0x009F0000; /* Reset CFGR2 register */ - RCC->CFGR2 = 0x00000000; + RCC->CFGR2 = 0x00000000; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000; #endif /* STM32F105xC */ - + #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM - SystemInit_ExtMemCtl(); + SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ -#endif +#endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ -#endif +#endif } /** @@ -228,31 +230,31 @@ void SystemInit (void) * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. - * + * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration - * based on this variable will be incorrect. - * - * @note - The system frequency computed by this function is not the real - * frequency in the chip. It is calculated based on the predefined + * based on this variable will be incorrect. + * + * @note - The system frequency computed by this function is not the real + * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: - * + * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) - * + * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) - * - * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) + * + * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. - * + * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations - * in voltage and temperature. - * + * in voltage and temperature. + * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. - * + * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None @@ -269,10 +271,10 @@ void SystemCoreClockUpdate (void) #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0; #endif /* STM32F100xB or STM32F100xE */ - + /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; - + switch (tmp) { case 0x00: /* HSI used as system clock */ @@ -286,10 +288,10 @@ void SystemCoreClockUpdate (void) /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; - -#if !defined(STM32F105xC) && !defined(STM32F107xC) + +#if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18) + 2; - + if (pllsource == 0x00) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ @@ -300,7 +302,7 @@ void SystemCoreClockUpdate (void) #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; /* HSE oscillator clock selected as PREDIV1 clock entry */ - SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; + SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) @@ -315,16 +317,16 @@ void SystemCoreClockUpdate (void) } #else pllmull = pllmull >> 18; - + if (pllmull != 0x0D) { pllmull += 2; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ - pllmull = 13 / 2; + pllmull = 13 / 2; } - + if (pllsource == 0x00) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ @@ -332,61 +334,61 @@ void SystemCoreClockUpdate (void) } else {/* PREDIV1 selected as PLL clock entry */ - + /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; - + if (prediv1source == 0) - { + { /* HSE oscillator clock selected as PREDIV1 clock entry */ - SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; + SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ - + /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1; - pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2; - SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; + pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2; + SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } -#endif /* STM32F105xC */ +#endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } - + /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; /* HCLK clock frequency */ - SystemCoreClock >>= tmp; + SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** - * @brief Setup the external memory controller. Called in startup_stm32f1xx.s + * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None - */ + */ #ifdef DATA_IN_ExtSRAM /** - * @brief Setup the external memory controller. + * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None - */ -void SystemInit_ExtMemCtl(void) + */ +void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; - /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is + /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ @@ -394,36 +396,36 @@ void SystemInit_ExtMemCtl(void) /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); - + /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0; - + /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); - + /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ -/*---------------- NOE and NWE configuration --------------------------------*/ +/*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ - - GPIOD->CRL = 0x44BB44BB; + + GPIOD->CRL = 0x44BB44BB; GPIOD->CRH = 0xBBBBBBBB; - GPIOE->CRL = 0xB44444BB; + GPIOE->CRL = 0xB44444BB; GPIOE->CRH = 0xBBBBBBBB; - GPIOF->CRL = 0x44BBBBBB; + GPIOF->CRL = 0x44BBBBBB; GPIOF->CRH = 0xBBBB4444; - GPIOG->CRL = 0x44BBBBBB; + GPIOG->CRL = 0x44BBBBBB; GPIOG->CRH = 0x444B4B44; - -/*---------------- FSMC Configuration ---------------------------------------*/ + +/*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ - + FSMC_Bank1->BTCR[4] = 0x00001091; FSMC_Bank1->BTCR[5] = 0x00110212; } @@ -437,8 +439,8 @@ void SystemInit_ExtMemCtl(void) /** * @} */ - + /** * @} - */ + */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From 295c6683d6d57afaaa8f1ceb2a67a6053e353cee Mon Sep 17 00:00:00 2001 From: fpr Date: Thu, 6 Jul 2017 12:06:33 +0200 Subject: [PATCH 29/30] Add USB IRQHandler for BluePill and MapleMini variants Signed-off-by: fpr --- variants/BLUEPILL_F103C8/usb/usbd_conf.c | 9 +++++++++ variants/MAPLEMINI_F103CB/usb/usbd_conf.c | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/variants/BLUEPILL_F103C8/usb/usbd_conf.c b/variants/BLUEPILL_F103C8/usb/usbd_conf.c index a523d7887c..aed399bd8b 100644 --- a/variants/BLUEPILL_F103C8/usb/usbd_conf.c +++ b/variants/BLUEPILL_F103C8/usb/usbd_conf.c @@ -242,6 +242,15 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); } +/** + * @brief This function handles USB global interrupt request. + * @param None + * @retval None + */ +void USB_LP_CAN1_RX0_IRQHandler(void) { + HAL_PCD_IRQHandler(&hpcd_USB_FS); +} + /******************************************************************************* LL Driver Interface (USB Device Library --> PCD) *******************************************************************************/ diff --git a/variants/MAPLEMINI_F103CB/usb/usbd_conf.c b/variants/MAPLEMINI_F103CB/usb/usbd_conf.c index a523d7887c..aed399bd8b 100644 --- a/variants/MAPLEMINI_F103CB/usb/usbd_conf.c +++ b/variants/MAPLEMINI_F103CB/usb/usbd_conf.c @@ -242,6 +242,15 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); } +/** + * @brief This function handles USB global interrupt request. + * @param None + * @retval None + */ +void USB_LP_CAN1_RX0_IRQHandler(void) { + HAL_PCD_IRQHandler(&hpcd_USB_FS); +} + /******************************************************************************* LL Driver Interface (USB Device Library --> PCD) *******************************************************************************/ From a81b1e360d42f5d7ab344a94e44c9b47d51d11b1 Mon Sep 17 00:00:00 2001 From: fpr Date: Tue, 11 Jul 2017 14:57:58 +0200 Subject: [PATCH 30/30] Update boards configuration with the new menu Signed-off-by: fpr --- boards.txt | 207 ++++++++++++++++++++++++++--------------------------- 1 file changed, 102 insertions(+), 105 deletions(-) diff --git a/boards.txt b/boards.txt index 52599770ae..4f230abe74 100644 --- a/boards.txt +++ b/boards.txt @@ -87,20 +87,18 @@ Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.variant=NUCLEO_F091RC Nucleo_64.menu.board_part_num.NUCLEO_F091RC.build.cmsis_lib_gcc=arm_cortexM0l_math # NUCLEO_F103RB board - -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB=Nucleo F103RB -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.node="NODE_F103RB,NUCLEO" -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_size=131072 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.upload.maximum_data_size=20480 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.mcu=cortex-m3 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.f_cpu=72000000L -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.board=NUCLEO_F103RB -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.series=STM32F1xx -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.variant=NUCLEO_F103RB -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.cmsis_lib_gcc=arm_cortexM3l_math -#To enable Serial1 (USART1 on PA10, PA9) add -DENABLE_SERIAL1 -#To enable Serial2 (USART3 on PC11, PC10) add -DENABLE_SERIAL2 -Nucleo_64.menu.Nucleo_64_board.NUCLEO_F103RB.build.extra_flags=-DSTM32F103xB +# Support: Serial1 (USART1 on PA10, PA9) and Serial2 (USART3 on PC11, PC10) +Nucleo_64.menu.board_part_num.NUCLEO_F103RB=Nucleo F103RB +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.node="NODE_F103RB,NUCLEO" +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.upload.maximum_size=131072 +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.upload.maximum_data_size=20480 +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.mcu=cortex-m3 +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.f_cpu=72000000L +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.board=NUCLEO_F103RB +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.series=STM32F1xx +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.product_line=STM32F103xB +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.variant=NUCLEO_F103RB +Nucleo_64.menu.board_part_num.NUCLEO_F103RB.build.cmsis_lib_gcc=arm_cortexM3l_math # NUCLEO_F303RE board # Support: Serial1 (USART1 on PA10, PA9) and Serial2 (USART2 on PA1, PA0) @@ -145,7 +143,6 @@ Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.product_line=STM32L476xx Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.variant=NUCLEO_L476RG Nucleo_64.menu.board_part_num.NUCLEO_L476RG.build.cmsis_lib_gcc=arm_cortexM4l_math - # Upload menu Nucleo_64.menu.upload_method.MassStorageMethod=Mass Storage Nucleo_64.menu.upload_method.MassStorageMethod.upload.protocol= @@ -207,20 +204,18 @@ Disco.build.board=Disco Disco.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.enable_Serialx} #DISCO_F100RB board - -Disco_board.menu.Disco_board.DISCO_F100RB=STM32F100RB-DISCVL -Disco_board.menu.Disco_board.DISCO_F100RB.node=DIS_F100RB -Disco_board.menu.Disco_board.DISCO_F100RB.upload.maximum_size=131071 -Disco_board.menu.Disco_board.DISCO_F100RB.upload.maximum_data_size=8192 -Disco_board.menu.Disco_board.DISCO_F100RB.build.mcu=cortex-m3 -Disco_board.menu.Disco_board.DISCO_F100RB.build.f_cpu=24000000L -Disco_board.menu.Disco_board.DISCO_F100RB.build.board=DISCO_F100RB -Disco_board.menu.Disco_board.DISCO_F100RB.build.series=STM32F1xx -Disco_board.menu.Disco_board.DISCO_F100RB.build.variant=DISCO_F100RB -Disco_board.menu.Disco_board.DISCO_F100RB.build.cmsis_lib_gcc=arm_cortexM3l_math -#To enable Serial1 (USART1 on PA10, PA9) add -DENABLE_SERIAL1 -#To enable Serial2 (USART3 on PB11, PB10) add -DENABLE_SERIAL2 -Disco_board.menu.Disco_board.DISCO_F100RB.build.extra_flags=-DSTM32F100xB +# Support: Serial1 (USART1 on PA10, PA9) and Serial2 (USART3 on PB11, PB10) +Disco.menu.board_part_num.DISCO_F100RB=STM32F100RB-DISCVL +Disco.menu.board_part_num.DISCO_F100RB.node=DIS_F100RB +Disco.menu.board_part_num.DISCO_F100RB.upload.maximum_size=131071 +Disco.menu.board_part_num.DISCO_F100RB.upload.maximum_data_size=8192 +Disco.menu.board_part_num.DISCO_F100RB.build.mcu=cortex-m3 +Disco.menu.board_part_num.DISCO_F100RB.build.f_cpu=24000000L +Disco.menu.board_part_num.DISCO_F100RB.build.board=DISCO_F100RB +Disco.menu.board_part_num.DISCO_F100RB.build.series=STM32F1xx +Disco.menu.board_part_num.DISCO_F100RB.build.product_line=STM32F100xB +Disco.menu.board_part_num.DISCO_F100RB.build.variant=DISCO_F100RB +Disco.menu.board_part_num.DISCO_F100RB.build.cmsis_lib_gcc=arm_cortexM3l_math # DISCO_F407VG board # Support: USB HID @@ -259,91 +254,79 @@ Disco.menu.upload_method.STLinkMethod=STLink Disco.menu.upload_method.STLinkMethod.upload.protocol=STLink Disco.menu.upload_method.STLinkMethod.upload.tool=stlink_upload - ################################################################################ # Other boards -Other_board.name=Other +Other.name=Other -Other_board.build.vid=0x0483 -Other_board.build.pid=0x5711 -Other_board.vid.0=0x0483 -Other_board.pid.0=0x5711 +Other.build.vid=0x0483 +Other.build.pid=0x5711 +Other.vid.0=0x0483 +Other.pid.0=0x5711 -Other_board.build.core=arduino -Other_board.build.board=Other_board +Other.build.core=arduino +Other.build.board=Other +Other.build.extra_flags=-D{build.product_line} {build.upload_flags} {build.enable_usb} {build.enable_Serialx} # BLUEPILL_F103C8 board - -Other_board.menu.Other_board.BLUEPILL_F103C8=BluePill F103C8 -Other_board.menu.Other_board.BLUEPILL_F103C8.node=NODE_F103C8 -Other_board.menu.Other_board.BLUEPILL_F103C8.upload.maximum_size=65536 -Other_board.menu.Other_board.BLUEPILL_F103C8.upload.maximum_data_size=20480 -Other_board.menu.Other_board.BLUEPILL_F103C8.build.mcu=cortex-m3 -Other_board.menu.Other_board.BLUEPILL_F103C8.build.f_cpu=72000000L -Other_board.menu.Other_board.BLUEPILL_F103C8.build.usb_product="BLUEPILL-F103C8" -Other_board.menu.Other_board.BLUEPILL_F103C8.build.board=BLUEPILL_F103C8 -Other_board.menu.Other_board.BLUEPILL_F103C8.build.series=STM32F1xx -Other_board.menu.Other_board.BLUEPILL_F103C8.build.variant=BLUEPILL_F103C8 -Other_board.menu.Other_board.BLUEPILL_F103C8.build.cmsis_lib_gcc=arm_cortexM3l_math -#To enable USB add '-DUSBCON' -#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' -#To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2 -#To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3 -Other_board.menu.Other_board.BLUEPILL_F103C8.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON +# Support: USB HID, Serial2 (USART2 on PA3, PA2) and Serial3 (USART3 on PB11, PB10) +Other.menu.board_part_num.BLUEPILL_F103C8=BluePill F103C8 +Other.menu.board_part_num.BLUEPILL_F103C8.node=NODE_F103C8 +Other.menu.board_part_num.BLUEPILL_F103C8.upload.maximum_size=65536 +Other.menu.board_part_num.BLUEPILL_F103C8.upload.maximum_data_size=20480 +Other.menu.board_part_num.BLUEPILL_F103C8.build.mcu=cortex-m3 +Other.menu.board_part_num.BLUEPILL_F103C8.build.f_cpu=72000000L +Other.menu.board_part_num.BLUEPILL_F103C8.build.board=BLUEPILL_F103C8 +Other.menu.board_part_num.BLUEPILL_F103C8.build.series=STM32F1xx +Other.menu.board_part_num.BLUEPILL_F103C8.build.product_line=STM32F103xB +Other.menu.board_part_num.BLUEPILL_F103C8.build.variant=BLUEPILL_F103C8 +Other.menu.board_part_num.BLUEPILL_F103C8.build.cmsis_lib_gcc=arm_cortexM3l_math # MAPLEMINI_F103CB board - -Other_board.menu.Other_board.MAPLEMINI_F103CB=MapleMini F103CB -Other_board.menu.Other_board.MAPLEMINI_F103CB.node=NODE_F103CB -Other_board.menu.Other_board.MAPLEMINI_F103CB.upload.maximum_size=131072 -Other_board.menu.Other_board.MAPLEMINI_F103CB.upload.maximum_data_size=20480 -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.mcu=cortex-m3 -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.f_cpu=72000000L -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.usb_product="MAPLEMINI-F103CB" -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.board=MAPLEMINI_F103CB -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.series=STM32F1xx -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.variant=MAPLEMINI_F103CB -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.cmsis_lib_gcc=arm_cortexM3l_math -#To enable USB add '-DUSBCON' -#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE' -#To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2 -#To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3 -Other_board.menu.Other_board.MAPLEMINI_F103CB.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON - - -Other_board.menu.upload_method.DFUUploadMethod1=Maple bootloader (original version for Maple boards) -Other_board.menu.upload_method.DFUUploadMethod1.upload.protocol=maple_dfu -Other_board.menu.upload_method.DFUUploadMethod1.upload.tool=maple_upload -Other_board.menu.upload_method.DFUUploadMethod1.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x5000 -Other_board.menu.upload_method.DFUUploadMethod1.build.ldscript=bootloader_original.ld -Other_board.menu.upload_method.DFUUploadMethod1.upload.usbID=1EAF:0003 -Other_board.menu.upload_method.DFUUploadMethod1.upload.altID=1 - -Other_board.menu.upload_method.DFUUploadMethod=STM32duino bootloader -Other_board.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu -Other_board.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload -Other_board.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x2000 -Other_board.menu.upload_method.DFUUploadMethod.build.ldscript=bootloader.ld -Other_board.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 -Other_board.menu.upload_method.DFUUploadMethod.upload.altID=2 - -Other_board.menu.upload_method.STLinkMethod=STLink -Other_board.menu.upload_method.STLinkMethod.upload.protocol=STLink -Other_board.menu.upload_method.STLinkMethod.upload.tool=stlink_upload -Other_board.menu.upload_method.STLinkMethod.build.upload_flags=-DSERIAL_USB - -Other_board.menu.upload_method.serialMethod=Serial -Other_board.menu.upload_method.serialMethod.upload.protocol=maple_serial -Other_board.menu.upload_method.serialMethod.upload.tool=serial_upload -Other_board.menu.upload_method.serialMethod.build.upload_flags= - -Other_board.menu.upload_method.BMPMethod=BMP (Black Magic Probe) -Other_board.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp -Other_board.menu.upload_method.BMPMethod.upload.tool=bmp_upload -Other_board.menu.upload_method.BMPMethod.upload.speed=230400 -Other_board.menu.upload_method.BMPMethod.build.upload_flags= - +# Support: USB HID, Serial2 (USART2 on PA3, PA2) and Serial3 (USART3 on PB11, PB10) +Other.menu.board_part_num.MAPLEMINI_F103CB=MapleMini F103CB +Other.menu.board_part_num.MAPLEMINI_F103CB.node=NODE_F103CB +Other.menu.board_part_num.MAPLEMINI_F103CB.upload.maximum_size=131072 +Other.menu.board_part_num.MAPLEMINI_F103CB.upload.maximum_data_size=20480 +Other.menu.board_part_num.MAPLEMINI_F103CB.build.mcu=cortex-m3 +Other.menu.board_part_num.MAPLEMINI_F103CB.build.f_cpu=72000000L +Other.menu.board_part_num.MAPLEMINI_F103CB.build.board=MAPLEMINI_F103CB +Other.menu.board_part_num.MAPLEMINI_F103CB.build.series=STM32F1xx +Other.menu.board_part_num.MAPLEMINI_F103CB.build.product_line=STM32F103xB +Other.menu.board_part_num.MAPLEMINI_F103CB.build.variant=MAPLEMINI_F103CB +Other.menu.board_part_num.MAPLEMINI_F103CB.build.cmsis_lib_gcc=arm_cortexM3l_math + +Other.menu.upload_method.DFUUploadMethod1=Maple bootloader (original version for Maple boards) +Other.menu.upload_method.DFUUploadMethod1.upload.protocol=maple_dfu +Other.menu.upload_method.DFUUploadMethod1.upload.tool=maple_upload +Other.menu.upload_method.DFUUploadMethod1.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x5000 +Other.menu.upload_method.DFUUploadMethod1.build.ldscript=bootloader_original.ld +Other.menu.upload_method.DFUUploadMethod1.upload.usbID=1EAF:0003 +Other.menu.upload_method.DFUUploadMethod1.upload.altID=1 + +Other.menu.upload_method.DFUUploadMethod=STM32duino bootloader +Other.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu +Other.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload +Other.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x2000 +Other.menu.upload_method.DFUUploadMethod.build.ldscript=bootloader.ld +Other.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 +Other.menu.upload_method.DFUUploadMethod.upload.altID=2 + +Other.menu.upload_method.STLinkMethod=STLink +Other.menu.upload_method.STLinkMethod.upload.protocol=STLink +Other.menu.upload_method.STLinkMethod.upload.tool=stlink_upload +Other.menu.upload_method.STLinkMethod.build.upload_flags=-DSERIAL_USB + +Other.menu.upload_method.serialMethod=Serial +Other.menu.upload_method.serialMethod.upload.protocol=maple_serial +Other.menu.upload_method.serialMethod.upload.tool=serial_upload +Other.menu.upload_method.serialMethod.build.upload_flags= + +Other.menu.upload_method.BMPMethod=BMP (Black Magic Probe) +Other.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp +Other.menu.upload_method.BMPMethod.upload.tool=bmp_upload +Other.menu.upload_method.BMPMethod.upload.speed=230400 +Other.menu.upload_method.BMPMethod.build.upload_flags= ################################################################################ # Serialx activation @@ -379,6 +362,14 @@ Disco.menu.Other_serial.enable_Serial1.build.enable_Serialx=-DENABLE_SERIAL1 Disco.menu.Other_serial.enable_Serial2=Serial2 (if available) Disco.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2 +Other.menu.Other_serial.enable_Serial=None +Other.menu.Other_serial.enable_SerialAll=All +Other.menu.Other_serial.enable_SerialAll.build.enable_Serialx=-DENABLE_SERIAL2 -DENABLE_SERIAL2 +Other.menu.Other_serial.enable_Serial2=Serial2 (if available) +Other.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2 +Other.menu.Other_serial.enable_Serial3=Serial3 (if available) +Other.menu.Other_serial.enable_Serial3.build.enable_Serialx=-DENABLE_SERIAL3 + # USB connectivity Nucleo_144.menu.USB_interface.enable_USB=None Nucleo_144.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available) @@ -403,3 +394,9 @@ Disco.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available Disco.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE Disco.menu.USB_interface.enable_CDC=CDC (if available) Disco.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS + +Other.menu.USB_interface.enable_USB=None +Other.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available) +Other.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE +Other.menu.USB_interface.enable_CDC=CDC (if available) +Other.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS