From 240b1ca25c3bdfcc5adb4d97b2f6a2ab3d655fe3 Mon Sep 17 00:00:00 2001 From: seeers Date: Mon, 22 Jun 2020 20:34:52 +0200 Subject: [PATCH 1/8] Add Generic F042Cx --- boards.txt | 24 ++- variants/Generic_F042Cx/PeripheralPins.c | 230 +++++++++++++++++++++++ variants/Generic_F042Cx/PinNamesVar.h | 33 ++++ variants/Generic_F042Cx/ldscript.ld | 200 ++++++++++++++++++++ variants/Generic_F042Cx/variant.cpp | 135 +++++++++++++ variants/Generic_F042Cx/variant.h | 225 ++++++++++++++++++++++ 6 files changed, 846 insertions(+), 1 deletion(-) create mode 100644 variants/Generic_F042Cx/PeripheralPins.c create mode 100644 variants/Generic_F042Cx/PinNamesVar.h create mode 100644 variants/Generic_F042Cx/ldscript.ld create mode 100644 variants/Generic_F042Cx/variant.cpp create mode 100644 variants/Generic_F042Cx/variant.h diff --git a/boards.txt b/boards.txt index 65074d3a9f..e0efffe876 100644 --- a/boards.txt +++ b/boards.txt @@ -807,7 +807,7 @@ GenF0.build.board=GenF0 GenF0.build.mcu=cortex-m0 GenF0.build.series=STM32F0xx GenF0.build.cmsis_lib_gcc=arm_cortexM0l_math -GenF0.build.extra_flags=-D{build.product_line} {build.xSerial} +GenF0.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} # DEMO_F030F4 board GenF0.menu.pnum.DEMO_F030F4=STM32F030F4 Demo board @@ -833,6 +833,14 @@ GenF0.menu.pnum.DEMO_F030F4_HSI.build.board=DEMO_F030F4_HSI GenF0.menu.pnum.DEMO_F030F4_HSI.build.product_line=STM32F030x6 GenF0.menu.pnum.DEMO_F030F4_HSI.build.variant=DEMO_F030F4 +# Generic_F042Cx +GenF0.menu.pnum.Gen_F042Cx=Generic_F042C6 (internal RC oscillator) +GenF0.menu.pnum.Gen_F042Cx.upload.maximum_data_size=6144 +GenF0.menu.pnum.Gen_F042Cx.upload.maximum_size=32768 +GenF0.menu.pnum.Gen_F042Cx.build.board=Gen_F042Cx +GenF0.menu.pnum.Gen_F042Cx.build.product_line=STM32F042x6 +GenF0.menu.pnum.Gen_F042Cx.build.variant=Generic_F042Cx + # Upload menu GenF0.menu.upload_method.swdMethod=STM32CubeProgrammer (SWD) GenF0.menu.upload_method.swdMethod.upload.protocol=0 @@ -2359,6 +2367,20 @@ Nucleo_32.menu.xusb.HS.build.usb_speed=-DUSE_USB_HS Nucleo_32.menu.xusb.HSFS=High Speed in Full Speed mode Nucleo_32.menu.xusb.HSFS.build.usb_speed=-DUSE_USB_HS -DUSE_USB_HS_IN_FS +GenF0.menu.usb.none=None +GenF0.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART) +GenF0.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC +GenF0.menu.usb.CDC=CDC (no generic 'Serial') +GenF0.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB +GenF0.menu.usb.HID=HID (keyboard and mouse) +GenF0.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE +GenF0.menu.xusb.FS=Low/Full Speed +GenF0.menu.xusb.HS=High Speed +GenF0.menu.xusb.HS.build.usb_speed=-DUSE_USB_HS +GenF0.menu.xusb.HSFS=High Speed in Full Speed mode +GenF0.menu.xusb.HSFS.build.usb_speed=-DUSE_USB_HS -DUSE_USB_HS_IN_FS + + Disco.menu.usb.none=None Disco.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART) Disco.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC diff --git a/variants/Generic_F042Cx/PeripheralPins.c b/variants/Generic_F042Cx/PeripheralPins.c new file mode 100644 index 0000000000..fba190e479 --- /dev/null +++ b/variants/Generic_F042Cx/PeripheralPins.c @@ -0,0 +1,230 @@ +/* + ******************************************************************************* + * Copyright (c) 2020, STMicroelectronics + * All rights reserved. + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ******************************************************************************* + * Automatically generated from STM32F042C(4-6)Tx.xml + */ +#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 *** + +#ifdef HAL_ADC_MODULE_ENABLED +WEAK const PinMap PinMap_ADC[] = { + {PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC_IN0 + {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC_IN1 + {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC_IN2 + {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC_IN3 + {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC_IN4 + {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC_IN5 + {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC_IN6 + {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC_IN7 + {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC_IN8 + {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC_IN9 + {NC, NP, 0} +}; +#endif + +//*** No DAC *** + +//*** I2C *** + +#ifdef HAL_I2C_MODULE_ENABLED +WEAK const PinMap PinMap_I2C_SDA[] = { + {PA_10, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, + {PA_12, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF5_I2C1)}, + {PB_7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)}, + {PB_9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)}, + {PB_11, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)}, + {PB_14, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF_NONE)}, + {PF_0, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)}, + {NC, NP, 0} +}; +#endif + +#ifdef HAL_I2C_MODULE_ENABLED +WEAK const PinMap PinMap_I2C_SCL[] = { + {PA_9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, + {PA_11, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF5_I2C1)}, + {PB_6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)}, + {PB_8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)}, + {PB_10, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)}, + {PB_13, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF_NONE)}, + {PF_1, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)}, + {NC, NP, 0} +}; +#endif + +//*** PWM *** + +#ifdef HAL_TIM_MODULE_ENABLED +WEAK const PinMap PinMap_PWM[] = { + {PA_0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 1, 0)}, // TIM2_CH1 + {PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 2, 0)}, // TIM2_CH2 + {PA_2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 3, 0)}, // TIM2_CH3 + {PA_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 4, 0)}, // TIM2_CH4 + {PA_4, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM14, 1, 0)}, // TIM14_CH1 + {PA_5, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 1, 0)}, // TIM2_CH1 + {PA_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 1, 0)}, // TIM3_CH1 + {PA_6, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_TIM16, 1, 0)}, // TIM16_CH1 + {PA_7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 1, 1)}, // TIM1_CH1N + {PA_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 2, 0)}, // TIM3_CH2 + {PA_7, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM14, 1, 0)}, // TIM14_CH1 + {PA_7, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_TIM17, 1, 0)}, // TIM17_CH1 + {PA_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 1, 0)}, // TIM1_CH1 + {PA_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 2, 0)}, // TIM1_CH2 + {PA_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 3, 0)}, // TIM1_CH3 + {PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 4, 0)}, // TIM1_CH4 + {PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 1, 0)}, // TIM2_CH1 + {PB_0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 2, 1)}, // TIM1_CH2N + {PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 3, 0)}, // TIM3_CH3 + {PB_1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 3, 1)}, // TIM1_CH3N + {PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 4, 0)}, // TIM3_CH4 + {PB_1, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM14, 1, 0)}, // TIM14_CH1 + {PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 2, 0)}, // TIM2_CH2 + {PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 1, 0)}, // TIM3_CH1 + {PB_5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 2, 0)}, // TIM3_CH2 + {PB_6, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM16, 1, 1)}, // TIM16_CH1N + {PB_7, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM17, 1, 1)}, // TIM17_CH1N + {PB_8, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM16, 1, 0)}, // TIM16_CH1 + {PB_9, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM17, 1, 0)}, // TIM17_CH1 + {PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 3, 0)}, // TIM2_CH3 + {PB_11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2, 4, 0)}, // TIM2_CH4 + {PB_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 1, 1)}, // TIM1_CH1N + {PB_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 2, 1)}, // TIM1_CH2N + {PB_15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 3, 1)}, // TIM1_CH3N + {NC, NP, 0} +}; +#endif + +//*** SERIAL *** + +#ifdef HAL_UART_MODULE_ENABLED +WEAK const PinMap PinMap_UART_TX[] = { + {PA_2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)}, + {PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)}, + {PA_14, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)}, + {PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)}, + {NC, NP, 0} +}; +#endif + +#ifdef HAL_UART_MODULE_ENABLED +WEAK const PinMap PinMap_UART_RX[] = { + {PA_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)}, + {PA_10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)}, + {PA_15, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)}, + {PB_7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)}, + {NC, NP, 0} +}; +#endif + +#ifdef HAL_UART_MODULE_ENABLED +WEAK const PinMap PinMap_UART_RTS[] = { + {PA_1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)}, + {PA_12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)}, + {NC, NP, 0} +}; +#endif + +#ifdef HAL_UART_MODULE_ENABLED +WEAK const PinMap PinMap_UART_CTS[] = { + {PA_0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)}, + {PA_11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)}, + {NC, NP, 0} +}; +#endif + +//*** SPI *** + +#ifdef HAL_SPI_MODULE_ENABLED +WEAK const PinMap PinMap_SPI_MOSI[] = { + {PA_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, + {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, + {PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI2)}, + {NC, NP, 0} +}; +#endif + +#ifdef HAL_SPI_MODULE_ENABLED +WEAK const PinMap PinMap_SPI_MISO[] = { + {PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, + {PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, + {PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI2)}, + {NC, NP, 0} +}; +#endif + +#ifdef HAL_SPI_MODULE_ENABLED +WEAK const PinMap PinMap_SPI_SCLK[] = { + {PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, + {PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, + {PB_10, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, + {PB_13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI2)}, + {NC, NP, 0} +}; +#endif + +#ifdef HAL_SPI_MODULE_ENABLED +WEAK const PinMap PinMap_SPI_SSEL[] = { + {PA_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, + {PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, + {PB_9, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, + {PB_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI2)}, + {NC, NP, 0} +}; +#endif + +//*** CAN *** + +#ifdef HAL_CAN_MODULE_ENABLED +WEAK const PinMap PinMap_CAN_RD[] = { + {PA_11, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_CAN)}, + {PB_8, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_CAN)}, + {NC, NP, 0} +}; +#endif + +#ifdef HAL_CAN_MODULE_ENABLED +WEAK const PinMap PinMap_CAN_TD[] = { + {PA_12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_CAN)}, + {PB_9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_CAN)}, + {NC, NP, 0} +}; +#endif + +//*** No ETHERNET *** + +//*** No QUADSPI *** + +//*** USB *** + +#ifdef HAL_PCD_MODULE_ENABLED +WEAK const PinMap PinMap_USB[] = { + //{PA_4, USB, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_USB)}, // USB_NOE + {PA_11, USB, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_DM + {PA_12, USB, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_DP + //{PA_13, USB, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_USB)}, // USB_NOE + //{PA_15, USB, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_USB)}, // USB_NOE + {NC, NP, 0} +}; +#endif + +//*** No USB_OTG_FS *** + +//*** No USB_OTG_HS *** + +//*** No SD *** diff --git a/variants/Generic_F042Cx/PinNamesVar.h b/variants/Generic_F042Cx/PinNamesVar.h new file mode 100644 index 0000000000..544dc29cfb --- /dev/null +++ b/variants/Generic_F042Cx/PinNamesVar.h @@ -0,0 +1,33 @@ +/* SYS_WKUP */ +#ifdef PWR_WAKEUP_PIN1 + SYS_WKUP1 = PA_0, +#endif +#ifdef PWR_WAKEUP_PIN2 + SYS_WKUP2 = PC_13, +#endif +#ifdef PWR_WAKEUP_PIN3 + SYS_WKUP3 = NC, +#endif +#ifdef PWR_WAKEUP_PIN4 + SYS_WKUP4 = PA_2, +#endif +#ifdef PWR_WAKEUP_PIN5 + SYS_WKUP5 = NC, +#endif +#ifdef PWR_WAKEUP_PIN6 + SYS_WKUP6 = PB_5, +#endif +#ifdef PWR_WAKEUP_PIN7 + SYS_WKUP7 = PB_15, +#endif +#ifdef PWR_WAKEUP_PIN8 + SYS_WKUP8 = NC, +#endif +/* USB */ +#ifdef USBCON + // USB_NOE = PA_4, + USB_DM = PA_11, + USB_DP = PA_12, +// USB_NOE = PA_13, +// USB_NOE = PA_15, +#endif diff --git a/variants/Generic_F042Cx/ldscript.ld b/variants/Generic_F042Cx/ldscript.ld new file mode 100644 index 0000000000..e55b2a308b --- /dev/null +++ b/variants/Generic_F042Cx/ldscript.ld @@ -0,0 +1,200 @@ +/* +****************************************************************************** +** +** File : LinkerScript.ld +** +** Author : Auto-generated by STM32CubeIDE +** +** Abstract : Linker script for STM32F042C6Tx Device from STM32F0 series +** 32Kbytes FLASH +** 6Kbytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used. +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is without any warranty +** of any kind. +** +***************************************************************************** +** @attention +** +**

© COPYRIGHT(c) 2020 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 = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200 ; /* required amount of heap */ +_Min_Stack_Size = 0x400 ; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 6K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 32K +} + +/* Sections */ +SECTIONS +{ + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/variants/Generic_F042Cx/variant.cpp b/variants/Generic_F042Cx/variant.cpp new file mode 100644 index 0000000000..11babfd106 --- /dev/null +++ b/variants/Generic_F042Cx/variant.cpp @@ -0,0 +1,135 @@ +/* + ******************************************************************************* + * Copyright (c) 2019, STMicroelectronics + * All rights reserved. + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ******************************************************************************* + */ + +#include "pins_arduino.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Digital PinName array +// This array allows to wrap Arduino pin number(Dx or x) +// to STM32 PinName (PX_n) +const PinName digitalPin[] = { +PC_13, // +PF_0, // I2C1_SDA CRS_SYNC I2C1_SDA +PF_1, // I2C1_SCL I2C1_SCL +PA_0, // USART2_CTS TIM2_CH1/TIM2_ETR TSC_G1_IO1 +PA_1, // EVENTOUT USART2_DE/USART2_RTS TIM2_CH2 TSC_G1_IO2 +PA_2, // USART2_TX TIM2_CH3 TSC_G1_IO3 +PA_3, // USART2_RX TIM2_CH4 TSC_G1_IO4 +PA_4, // I2S1_WS/SPI1_NSS USART2_CK USB_NOE TSC_G2_IO1 TIM14_CH1 +PA_5, // I2S1_CK/SPI1_SCK CEC TIM2_CH1/TIM2_ETR TSC_G2_IO2 +PA_6, // I2S1_MCK/SPI1_MISO TIM3_CH1 TIM1_BKIN TSC_G2_IO3 TIM16_CH1 +PA_7, // I2S1_SD/SPI1_MOSI TIM3_CH2 TIM1_CH1N TSC_G2_IO4 TIM14_CH1 TIM17_CH1 +PB_0, // EVENTOUT TIM3_CH3 TIM1_CH2N TSC_G3_IO2 +PB_1, // TIM14_CH1 TIM3_CH4 TIM1_CH3N TSC_G3_IO3 +PB_2, // TSC_G3_IO4 +PB_10, // CEC I2C1_SCL TIM2_CH3 TSC_SYNC SPI2_SCK +PB_11, // EVENTOUT I2C1_SDA TIM2_CH4 +PB_12, // SPI2_NSS EVENTOUT TIM1_BKIN +PB_13, // SPI2_SCK TIM1_CH1N +PB_14, // SPI2_MISO TIM1_CH2N +PB_15, // SPI2_MOSI TIM1_CH3N +PA_8, // RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC +PA_9, // USART1_TX TIM1_CH2 TSC_G4_IO1 I2C1_SCL +PA_10, // TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA +PA_11, // USB_DM EVENTOUT USART1_CTS TIM1_CH4 TSC_G4_IO3 CAN_RX I2C1_SCL +PA_12, // USB_DP EVENTOUT USART1_DE/USART1_RTS TIM1_ETR TSC_G4_IO4 CAN_TX I2C1_SDA +PA_13, // SYS_SWDIO IR_OUT USB_NOE +PA_14, // SYS_SWCLK USART2_TX +PA_15, // I2S1_WS/SPI1_NSS USART2_RX TIM2_CH1/TIM2_ETR EVENTOUT USB_NOE +PB_3, // I2S1_CK/SPI1_SCK EVENTOUT TIM2_CH2 TSC_G5_IO1 +PB_4, // I2S1_MCK/SPI1_MISO TIM3_CH1 EVENTOUT TSC_G5_IO2 TIM17_BKIN +PB_5, // I2S1_SD/SPI1_MOSI TIM3_CH2 TIM16_BKIN I2C1_SMBA +PB_6, // USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 +PB_7, // USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 +PF_11, // +PB_8, // CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX +PB_9 // IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS +}; + +// If analog pins are not contiguous in the digitalPin array: +// Add the analogInputPin array without defining NUM_ANALOG_FIRST +// Analog (Ax) pin number array +// where x is the index to retrieve the digital pin number +const uint32_t analogInputPin[] = { + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10 +}; + +#ifdef __cplusplus +} +#endif + +// ---------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief System Clock Configuration + * @param None + * @retval None + */ +WEAK void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInit; + RCC_CRSInitTypeDef RCC_CRSInitStruct; + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); + + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); + + __HAL_RCC_CRS_CLK_ENABLE(); + + RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; + RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; + RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING; + RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000); + RCC_CRSInitStruct.ErrorLimitValue = 34; + RCC_CRSInitStruct.HSI48CalibrationValue = 32; + HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); + + 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/Generic_F042Cx/variant.h b/variants/Generic_F042Cx/variant.h new file mode 100644 index 0000000000..c1dab41dd4 --- /dev/null +++ b/variants/Generic_F042Cx/variant.h @@ -0,0 +1,225 @@ +/* + ******************************************************************************* + * Copyright (c) 2019, STMicroelectronics + * All rights reserved. + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ******************************************************************************* + */ + +#ifndef _VARIANT_ARDUINO_STM32_ +#define _VARIANT_ARDUINO_STM32_ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/*---------------------------------------------------------------------------- + * Pins + *----------------------------------------------------------------------------*/ + +#define PC13 0 +#define PF0 1 +#define PF1 2 +#define PA0 A0 +#define PA1 A1 +#define PA2 A2 +#define PA3 A3 +#define PA4 A4 +#define PA5 A5 +#define PA6 A6 +#define PA7 A7 +#define PB0 11 +#define PB1 12 +#define PB2 13 +#define PB10 14 +#define PB11 15 +#define PB12 16 +#define PB13 17 +#define PB14 18 +#define PB15 19 +#define PA8 20 +#define PA9 21 +#define PA10 22 +#define PA11 23 +#define PA12 24 +#define PA13 25 +#define PA14 26 +#define PA15 27 +#define PB3 28 +#define PB4 29 +#define PB5 30 +#define PB6 31 +#define PB7 32 +#define PF11 33 +#define PB8 34 +#define PB9 35 + +// This must be a literal +// It is used with preprocessor tests (e.g. #if NUM_DIGITAL_PINS > 3) +// so an enum will not work. +#define NUM_DIGITAL_PINS 36 + +// Allow to define Arduino style alias for analog input pin number --> Ax +// If no analog pin required then NUM_ANALOG_INPUTS could not be defined +// or set to `0` +// All pins are digital, analog inputs are a subset of digital pins. +// This must be a literal +// It is used with preprocessor tests (e.g. #if NUM_ANALOG_INPUTS > 3) +// so an enum will not work. +// !!! +// !!! It must be aligned with the number of analog PinName +// !!! defined in digitalPin[] array in variant.cpp +// !!! +#define NUM_ANALOG_INPUTS 8 + +// They are 2 possibles way to define analog pins: +//------------------------------------------------------------------------------------------- +// - If they are contiguous in the digitalPin array: +// Simply defined `NUM_ANALOG_FIRST` and all pins Ax will be automatically defined. +// It define the digital pin number of the first analog input (i.e. which digital pin is A0) +// First analog pin value (A0) must be greater than or equal to NUM_ANALOG_INPUTS +// This must be a literal with a value less than or equal to MAX_ANALOG_INPUTS +// defined in pin_arduino.h +// #define NUM_ANALOG_FIRST 0 +//------------------------------------OR------------------------------------------------------ +// - If they are not contiguous in the digitalPin array: +// Add an analogInputPin array in the variant.cpp without defining NUM_ANALOG_FIRST +// In that case the defined PYn for analog pin have to define the Ax definition instead of +// index in digitalPin[] array: +// #define PA4 A14 +//------------------------------------------------------------------------------------------- + + +// Below ADC and PWM definitions already done in the core +// Could be redefined here if needed +// ADC resolution is 10 bits +//#define ADC_RESOLUTION 10 + +// PWM resolution +//#define PWM_RESOLUTION 8 +//#define PWM_FREQUENCY 1000 +//#define PWM_MAX_DUTY_CYCLE 255 + +// On-board LED pin number +//#define LED_BUILTIN x +//#define LED_GREEN LED_BUILTIN + +// On-board user button +//#define USER_BTN x + +// Below SPI and I2C definitions already done in the core +// Could be redefined here if differs from the default one +// SPI Definitions +//#define PIN_SPI_SS 10 // Default for Arduino connector compatibility +//#define PIN_SPI_MOSI 11 // Default for Arduino connector compatibility +//#define PIN_SPI_MISO 12 // Default for Arduino connector compatibility +//#define PIN_SPI_SCK 13 // Default for Arduino connector compatibility + +// I2C Definitions +//#define PIN_WIRE_SDA 14 // Default for Arduino connector compatibility +//#define PIN_WIRE_SCL 15 // Default for Arduino connector compatibility + +// I2C timing definitions (optional), avoid time spent to compute if defined +// * I2C_TIMING_SM for Standard Mode (100kHz) +// * I2C_TIMING_FM for Fast Mode (400kHz) +// * I2C_TIMING_FMP for Fast Mode Plus (1000kHz) +//#define I2C_TIMING_SM 0x00000000 +//#define I2C_TIMING_FM 0x00000000 +//#define I2C_TIMING_FMP 0x00000000 + +// Timer Definitions (optional) +// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin +//#define TIMER_TONE TIM6 +//#define TIMER_SERVO TIM7 + +// UART Definitions +// Define here Serial instance number to map on Serial generic name +#define SERIAL_UART_INSTANCE 2 //ex: 2 for Serial2 (USART2) +// DEBUG_UART could be redefined to print on another instance than 'Serial' +//#define DEBUG_UART ((USART_TypeDef *) U(S)ARTX) // ex: USART3 +// DEBUG_UART baudrate, default: 9600 if not defined +//#define DEBUG_UART_BAUDRATE x +// DEBUG_UART Tx pin name, default: the first one found in PinMap_UART_TX for DEBUG_UART +//#define DEBUG_PINNAME_TX PX_n // PinName used for TX + +// Default pin used for 'Serial' instance (ex: ST-Link) +// Mandatory for Firmata +#define PIN_SERIAL_RX PA3 +#define PIN_SERIAL_TX PA2 + +// Optional PIN_SERIALn_RX and PIN_SERIALn_TX where 'n' is the U(S)ART number +// Used when user instanciate a hardware Serial using its peripheral name. +// Example: HardwareSerial mySerial(USART3); +// will use PIN_SERIAL3_RX and PIN_SERIAL3_TX if defined. +//#define PIN_SERIALn_RX x // For U(S)ARTn RX +//#define PIN_SERIALn_TX x // For U(S)ARTn TX +//#define PIN_SERIALLP1_RX x // For LPUART1 RX +//#define PIN_SERIALLP1_TX x // For LPUART1 TX + +// SD card slot Definitions +// SD detect signal can be defined if required +//#define SD_DETECT_PIN x +// SD Read/Write timeout, default value defined in STM32SD library +//#define SD_DATATIMEOUT x + +// USB Vbus sensing. Require to have Vbus pin connected to Vbus signal. +// Warning, pin is different depending on FullSpeed or High Speed mode used +// See AN4879 https://www.st.com/content/st_com/en/search.html#q=AN4879-t=resources-page=1 +//#define USBD_VBUS_DETECTION_ENABLE + +// If the board has external USB pullup (on DP/DM depending on speed) +// that can be controlled using a GPIO pin, define these: +// - If the the pullup is disabled (USB detached) by default, define +// USBD_ATTACH_PIN to the pin that, when written to +// USBD_ATTACH_LEVEL, attaches the pullup. +// - If the the pullup is enabled (attached) by default, define +// USBD_DETACH_PIN to the pin that, when written to +// USBD_DETACH_LEVEL, detaches the pullup. +//#define USBD_ATTACH_PIN x +//#define USBD_ATTACH_LEVEL LOW +//#define USBD_DETACH_PIN x +//#define USBD_DETACH_LEVEL LOW +// +// This indicates that there is an external and fixed 1.5k pullup +// on the D+ line. This define is not normally needed, since a +// fixed pullup is assumed by default. It is only required when +// the USB peripheral has an internal pullup *and* an external +// fixed pullup is present (which is actually a hardware bug, since just +// the internal pullup is sufficient and having two pullups violates the +// USB specification). In this case, defining this forces +// the "write D+ LOW"-trick to be used. In the future, it might also +// disable the internal pullups, but this is not currently implemented. +// #define USBD_FIXED_PULLUP +#ifdef __cplusplus +} // extern "C" +#endif +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#ifdef __cplusplus + // These serial port names are intended to allow libraries and architecture-neutral + // sketches to automatically default to the correct port name for a particular type + // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, + // the first hardware serial port whose RX/TX pins are not dedicated to another use. + // + // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor + // + // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial + // + // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library + // + // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. + // + // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX + // pins are NOT connected to anything by default. + #define SERIAL_PORT_MONITOR Serial + #define SERIAL_PORT_HARDWARE Serial +#endif + +#endif /* _VARIANT_ARDUINO_STM32_ */ From 1fdf77f9876714cbf6f12709c3a98ad9083d4596 Mon Sep 17 00:00:00 2001 From: seeers Date: Tue, 23 Jun 2020 22:08:07 +0200 Subject: [PATCH 2/8] Style cleanup --- variants/Generic_F042Cx/PinNamesVar.h | 6 +- variants/Generic_F042Cx/variant.cpp | 153 +++++++++++++------------- variants/Generic_F042Cx/variant.h | 38 +++---- 3 files changed, 98 insertions(+), 99 deletions(-) diff --git a/variants/Generic_F042Cx/PinNamesVar.h b/variants/Generic_F042Cx/PinNamesVar.h index 544dc29cfb..b8cbd7b0fd 100644 --- a/variants/Generic_F042Cx/PinNamesVar.h +++ b/variants/Generic_F042Cx/PinNamesVar.h @@ -25,9 +25,9 @@ #endif /* USB */ #ifdef USBCON - // USB_NOE = PA_4, + // USB_NOE = PA_4, USB_DM = PA_11, USB_DP = PA_12, -// USB_NOE = PA_13, -// USB_NOE = PA_15, + // USB_NOE = PA_13, + // USB_NOE = PA_15, #endif diff --git a/variants/Generic_F042Cx/variant.cpp b/variants/Generic_F042Cx/variant.cpp index 11babfd106..88aa72edc7 100644 --- a/variants/Generic_F042Cx/variant.cpp +++ b/variants/Generic_F042Cx/variant.cpp @@ -21,42 +21,42 @@ extern "C" { // This array allows to wrap Arduino pin number(Dx or x) // to STM32 PinName (PX_n) const PinName digitalPin[] = { -PC_13, // -PF_0, // I2C1_SDA CRS_SYNC I2C1_SDA -PF_1, // I2C1_SCL I2C1_SCL -PA_0, // USART2_CTS TIM2_CH1/TIM2_ETR TSC_G1_IO1 -PA_1, // EVENTOUT USART2_DE/USART2_RTS TIM2_CH2 TSC_G1_IO2 -PA_2, // USART2_TX TIM2_CH3 TSC_G1_IO3 -PA_3, // USART2_RX TIM2_CH4 TSC_G1_IO4 -PA_4, // I2S1_WS/SPI1_NSS USART2_CK USB_NOE TSC_G2_IO1 TIM14_CH1 -PA_5, // I2S1_CK/SPI1_SCK CEC TIM2_CH1/TIM2_ETR TSC_G2_IO2 -PA_6, // I2S1_MCK/SPI1_MISO TIM3_CH1 TIM1_BKIN TSC_G2_IO3 TIM16_CH1 -PA_7, // I2S1_SD/SPI1_MOSI TIM3_CH2 TIM1_CH1N TSC_G2_IO4 TIM14_CH1 TIM17_CH1 -PB_0, // EVENTOUT TIM3_CH3 TIM1_CH2N TSC_G3_IO2 -PB_1, // TIM14_CH1 TIM3_CH4 TIM1_CH3N TSC_G3_IO3 -PB_2, // TSC_G3_IO4 -PB_10, // CEC I2C1_SCL TIM2_CH3 TSC_SYNC SPI2_SCK -PB_11, // EVENTOUT I2C1_SDA TIM2_CH4 -PB_12, // SPI2_NSS EVENTOUT TIM1_BKIN -PB_13, // SPI2_SCK TIM1_CH1N -PB_14, // SPI2_MISO TIM1_CH2N -PB_15, // SPI2_MOSI TIM1_CH3N -PA_8, // RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC -PA_9, // USART1_TX TIM1_CH2 TSC_G4_IO1 I2C1_SCL -PA_10, // TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA -PA_11, // USB_DM EVENTOUT USART1_CTS TIM1_CH4 TSC_G4_IO3 CAN_RX I2C1_SCL -PA_12, // USB_DP EVENTOUT USART1_DE/USART1_RTS TIM1_ETR TSC_G4_IO4 CAN_TX I2C1_SDA -PA_13, // SYS_SWDIO IR_OUT USB_NOE -PA_14, // SYS_SWCLK USART2_TX -PA_15, // I2S1_WS/SPI1_NSS USART2_RX TIM2_CH1/TIM2_ETR EVENTOUT USB_NOE -PB_3, // I2S1_CK/SPI1_SCK EVENTOUT TIM2_CH2 TSC_G5_IO1 -PB_4, // I2S1_MCK/SPI1_MISO TIM3_CH1 EVENTOUT TSC_G5_IO2 TIM17_BKIN -PB_5, // I2S1_SD/SPI1_MOSI TIM3_CH2 TIM16_BKIN I2C1_SMBA -PB_6, // USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 -PB_7, // USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 -PF_11, // -PB_8, // CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX -PB_9 // IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS + PC_13, // + PF_0, // I2C1_SDA CRS_SYNC I2C1_SDA + PF_1, // I2C1_SCL I2C1_SCL + PA_0, // USART2_CTS TIM2_CH1/TIM2_ETR TSC_G1_IO1 + PA_1, // EVENTOUT USART2_DE/USART2_RTS TIM2_CH2 TSC_G1_IO2 + PA_2, // USART2_TX TIM2_CH3 TSC_G1_IO3 + PA_3, // USART2_RX TIM2_CH4 TSC_G1_IO4 + PA_4, // I2S1_WS/SPI1_NSS USART2_CK USB_NOE TSC_G2_IO1 TIM14_CH1 + PA_5, // I2S1_CK/SPI1_SCK CEC TIM2_CH1/TIM2_ETR TSC_G2_IO2 + PA_6, // I2S1_MCK/SPI1_MISO TIM3_CH1 TIM1_BKIN TSC_G2_IO3 TIM16_CH1 + PA_7, // I2S1_SD/SPI1_MOSI TIM3_CH2 TIM1_CH1N TSC_G2_IO4 TIM14_CH1 TIM17_CH1 + PB_0, // EVENTOUT TIM3_CH3 TIM1_CH2N TSC_G3_IO2 + PB_1, // TIM14_CH1 TIM3_CH4 TIM1_CH3N TSC_G3_IO3 + PB_2, // TSC_G3_IO4 + PB_10, // CEC I2C1_SCL TIM2_CH3 TSC_SYNC SPI2_SCK + PB_11, // EVENTOUT I2C1_SDA TIM2_CH4 + PB_12, // SPI2_NSS EVENTOUT TIM1_BKIN + PB_13, // SPI2_SCK TIM1_CH1N + PB_14, // SPI2_MISO TIM1_CH2N + PB_15, // SPI2_MOSI TIM1_CH3N + PA_8, // RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC + PA_9, // USART1_TX TIM1_CH2 TSC_G4_IO1 I2C1_SCL + PA_10, // TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA + PA_11, // USB_DM EVENTOUT USART1_CTS TIM1_CH4 TSC_G4_IO3 CAN_RX I2C1_SCL + PA_12, // USB_DP EVENTOUT USART1_DE/USART1_RTS TIM1_ETR TSC_G4_IO4 CAN_TX I2C1_SDA + PA_13, // SYS_SWDIO IR_OUT USB_NOE + PA_14, // SYS_SWCLK USART2_TX + PA_15, // I2S1_WS/SPI1_NSS USART2_RX TIM2_CH1/TIM2_ETR EVENTOUT USB_NOE + PB_3, // I2S1_CK/SPI1_SCK EVENTOUT TIM2_CH2 TSC_G5_IO1 + PB_4, // I2S1_MCK/SPI1_MISO TIM3_CH1 EVENTOUT TSC_G5_IO2 TIM17_BKIN + PB_5, // I2S1_SD/SPI1_MOSI TIM3_CH2 TIM16_BKIN I2C1_SMBA + PB_6, // USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 + PB_7, // USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 + PF_11, // + PB_8, // CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX + PB_9 // IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS }; // If analog pins are not contiguous in the digitalPin array: @@ -64,14 +64,14 @@ PB_9 // IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS // Analog (Ax) pin number array // where x is the index to retrieve the digital pin number const uint32_t analogInputPin[] = { - 3, - 4, + 3, + 4, 5, 6, 7, - 8, + 8, 9, - 10 + 10 }; #ifdef __cplusplus @@ -91,43 +91,42 @@ extern "C" { */ WEAK void SystemClock_Config(void) { - RCC_OscInitTypeDef RCC_OscInitStruct; - RCC_ClkInitTypeDef RCC_ClkInitStruct; - RCC_PeriphCLKInitTypeDef PeriphClkInit; - RCC_CRSInitTypeDef RCC_CRSInitStruct; - - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; - RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - HAL_RCC_OscConfig(&RCC_OscInitStruct); - - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); - - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; - PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; - HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); - - __HAL_RCC_CRS_CLK_ENABLE(); - - RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; - RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; - RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING; - RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000); - RCC_CRSInitStruct.ErrorLimitValue = 34; - RCC_CRSInitStruct.HSI48CalibrationValue = 32; - HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); - - HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); - - HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); - - /* SysTick_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInit; + RCC_CRSInitTypeDef RCC_CRSInitStruct; + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); + + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); + + __HAL_RCC_CRS_CLK_ENABLE(); + + RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; + RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; + RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING; + RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000); + RCC_CRSInitStruct.ErrorLimitValue = 34; + RCC_CRSInitStruct.HSI48CalibrationValue = 32; + HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); + + 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 diff --git a/variants/Generic_F042Cx/variant.h b/variants/Generic_F042Cx/variant.h index c1dab41dd4..30cc13fa37 100644 --- a/variants/Generic_F042Cx/variant.h +++ b/variants/Generic_F042Cx/variant.h @@ -25,38 +25,38 @@ extern "C" { #define PC13 0 #define PF0 1 #define PF1 2 -#define PA0 A0 -#define PA1 A1 -#define PA2 A2 -#define PA3 A3 -#define PA4 A4 -#define PA5 A5 -#define PA6 A6 -#define PA7 A7 -#define PB0 11 -#define PB1 12 -#define PB2 13 +#define PA0 A0 +#define PA1 A1 +#define PA2 A2 +#define PA3 A3 +#define PA4 A4 +#define PA5 A5 +#define PA6 A6 +#define PA7 A7 +#define PB0 11 +#define PB1 12 +#define PB2 13 #define PB10 14 #define PB11 15 #define PB12 16 #define PB13 17 #define PB14 18 #define PB15 19 -#define PA8 20 -#define PA9 21 +#define PA8 20 +#define PA9 21 #define PA10 22 #define PA11 23 #define PA12 24 #define PA13 25 #define PA14 26 #define PA15 27 -#define PB3 28 -#define PB4 29 -#define PB5 30 -#define PB6 31 -#define PB7 32 +#define PB3 28 +#define PB4 29 +#define PB5 30 +#define PB6 31 +#define PB7 32 #define PF11 33 -#define PB8 34 +#define PB8 34 #define PB9 35 // This must be a literal From 1a4775c8065932d62cf2330e920ebb3b4061e082 Mon Sep 17 00:00:00 2001 From: seeers Date: Tue, 23 Jun 2020 22:19:45 +0200 Subject: [PATCH 3/8] more style cleanup --- variants/Generic_F042Cx/variant.cpp | 76 ++++++++++++++--------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/variants/Generic_F042Cx/variant.cpp b/variants/Generic_F042Cx/variant.cpp index 88aa72edc7..ee44de4d51 100644 --- a/variants/Generic_F042Cx/variant.cpp +++ b/variants/Generic_F042Cx/variant.cpp @@ -22,41 +22,41 @@ extern "C" { // to STM32 PinName (PX_n) const PinName digitalPin[] = { PC_13, // - PF_0, // I2C1_SDA CRS_SYNC I2C1_SDA - PF_1, // I2C1_SCL I2C1_SCL - PA_0, // USART2_CTS TIM2_CH1/TIM2_ETR TSC_G1_IO1 - PA_1, // EVENTOUT USART2_DE/USART2_RTS TIM2_CH2 TSC_G1_IO2 - PA_2, // USART2_TX TIM2_CH3 TSC_G1_IO3 - PA_3, // USART2_RX TIM2_CH4 TSC_G1_IO4 - PA_4, // I2S1_WS/SPI1_NSS USART2_CK USB_NOE TSC_G2_IO1 TIM14_CH1 - PA_5, // I2S1_CK/SPI1_SCK CEC TIM2_CH1/TIM2_ETR TSC_G2_IO2 - PA_6, // I2S1_MCK/SPI1_MISO TIM3_CH1 TIM1_BKIN TSC_G2_IO3 TIM16_CH1 - PA_7, // I2S1_SD/SPI1_MOSI TIM3_CH2 TIM1_CH1N TSC_G2_IO4 TIM14_CH1 TIM17_CH1 - PB_0, // EVENTOUT TIM3_CH3 TIM1_CH2N TSC_G3_IO2 - PB_1, // TIM14_CH1 TIM3_CH4 TIM1_CH3N TSC_G3_IO3 - PB_2, // TSC_G3_IO4 - PB_10, // CEC I2C1_SCL TIM2_CH3 TSC_SYNC SPI2_SCK - PB_11, // EVENTOUT I2C1_SDA TIM2_CH4 - PB_12, // SPI2_NSS EVENTOUT TIM1_BKIN - PB_13, // SPI2_SCK TIM1_CH1N - PB_14, // SPI2_MISO TIM1_CH2N - PB_15, // SPI2_MOSI TIM1_CH3N - PA_8, // RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC - PA_9, // USART1_TX TIM1_CH2 TSC_G4_IO1 I2C1_SCL - PA_10, // TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA - PA_11, // USB_DM EVENTOUT USART1_CTS TIM1_CH4 TSC_G4_IO3 CAN_RX I2C1_SCL - PA_12, // USB_DP EVENTOUT USART1_DE/USART1_RTS TIM1_ETR TSC_G4_IO4 CAN_TX I2C1_SDA - PA_13, // SYS_SWDIO IR_OUT USB_NOE - PA_14, // SYS_SWCLK USART2_TX - PA_15, // I2S1_WS/SPI1_NSS USART2_RX TIM2_CH1/TIM2_ETR EVENTOUT USB_NOE - PB_3, // I2S1_CK/SPI1_SCK EVENTOUT TIM2_CH2 TSC_G5_IO1 - PB_4, // I2S1_MCK/SPI1_MISO TIM3_CH1 EVENTOUT TSC_G5_IO2 TIM17_BKIN - PB_5, // I2S1_SD/SPI1_MOSI TIM3_CH2 TIM16_BKIN I2C1_SMBA - PB_6, // USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 - PB_7, // USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 - PF_11, // - PB_8, // CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX - PB_9 // IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS + PF_0, //I2C1_SDA CRS_SYNC I2C1_SDA + PF_1, //I2C1_SCL I2C1_SCL + PA_0, //USART2_CTS TIM2_CH1/TIM2_ETR TSC_G1_IO1 + PA_1, //EVENTOUT USART2_DE/USART2_RTS TIM2_CH2 TSC_G1_IO2 + PA_2, //USART2_TX TIM2_CH3 TSC_G1_IO3 + PA_3, //USART2_RX TIM2_CH4 TSC_G1_IO4 + PA_4, //I2S1_WS/SPI1_NSS USART2_CK USB_NOE TSC_G2_IO1 TIM14_CH1 + PA_5, //I2S1_CK/SPI1_SCK CEC TIM2_CH1/TIM2_ETR TSC_G2_IO2 + PA_6, //I2S1_MCK/SPI1_MISO TIM3_CH1 TIM1_BKIN TSC_G2_IO3 TIM16_CH1 + PA_7, //I2S1_SD/SPI1_MOSI TIM3_CH2 TIM1_CH1N TSC_G2_IO4 TIM14_CH1 TIM17_CH1 + PB_0, //EVENTOUT TIM3_CH3 TIM1_CH2N TSC_G3_IO2 + PB_1, //TIM14_CH1 TIM3_CH4 TIM1_CH3N TSC_G3_IO3 + PB_2, //TSC_G3_IO4 + PB_10, //CEC I2C1_SCL TIM2_CH3 TSC_SYNC SPI2_SCK + PB_11, //EVENTOUT I2C1_SDA TIM2_CH4 + PB_12, //SPI2_NSS EVENTOUT TIM1_BKIN + PB_13, //SPI2_SCK TIM1_CH1N + PB_14, //SPI2_MISO TIM1_CH2N + PB_15, //SPI2_MOSI TIM1_CH3N + PA_8, //RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC + PA_9, //USART1_TX TIM1_CH2 TSC_G4_IO1 I2C1_SCL + PA_10, //TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA + PA_11, //USB_DM EVENTOUT USART1_CTS TIM1_CH4 TSC_G4_IO3 CAN_RX I2C1_SCL + PA_12, //USB_DP EVENTOUT USART1_DE/USART1_RTS TIM1_ETR TSC_G4_IO4 CAN_TX I2C1_SDA + PA_13, //SYS_SWDIO IR_OUT USB_NOE + PA_14, //SYS_SWCLK USART2_TX + PA_15, //I2S1_WS/SPI1_NSS USART2_RX TIM2_CH1/TIM2_ETR EVENTOUT USB_NOE + PB_3, //I2S1_CK/SPI1_SCK EVENTOUT TIM2_CH2 TSC_G5_IO1 + PB_4, //I2S1_MCK/SPI1_MISO TIM3_CH1 EVENTOUT TSC_G5_IO2 TIM17_BKIN + PB_5, //I2S1_SD/SPI1_MOSI TIM3_CH2 TIM16_BKIN I2C1_SMBA + PB_6, //USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 + PB_7, //USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 + PF_11, // + PB_8, //CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX + PB_9 //IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS }; // If analog pins are not contiguous in the digitalPin array: @@ -101,7 +101,7 @@ WEAK void SystemClock_Config(void) RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; HAL_RCC_OscConfig(&RCC_OscInitStruct); - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; @@ -116,12 +116,12 @@ WEAK void SystemClock_Config(void) RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING; - RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000); + RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000); RCC_CRSInitStruct.ErrorLimitValue = 34; RCC_CRSInitStruct.HSI48CalibrationValue = 32; HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); - HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); From 5eb89f8febe277333c7a18ff863b044ed4f597b9 Mon Sep 17 00:00:00 2001 From: seeers Date: Tue, 23 Jun 2020 22:22:38 +0200 Subject: [PATCH 4/8] more style cleanup --- variants/Generic_F042Cx/variant.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/variants/Generic_F042Cx/variant.cpp b/variants/Generic_F042Cx/variant.cpp index ee44de4d51..25bb948ab6 100644 --- a/variants/Generic_F042Cx/variant.cpp +++ b/variants/Generic_F042Cx/variant.cpp @@ -28,12 +28,12 @@ const PinName digitalPin[] = { PA_1, //EVENTOUT USART2_DE/USART2_RTS TIM2_CH2 TSC_G1_IO2 PA_2, //USART2_TX TIM2_CH3 TSC_G1_IO3 PA_3, //USART2_RX TIM2_CH4 TSC_G1_IO4 - PA_4, //I2S1_WS/SPI1_NSS USART2_CK USB_NOE TSC_G2_IO1 TIM14_CH1 - PA_5, //I2S1_CK/SPI1_SCK CEC TIM2_CH1/TIM2_ETR TSC_G2_IO2 + PA_4, //I2S1_WS/SPI1_NSS USART2_CK USB_NOE TSC_G2_IO1 TIM14_CH1 + PA_5, //I2S1_CK/SPI1_SCK CEC TIM2_CH1/TIM2_ETR TSC_G2_IO2 PA_6, //I2S1_MCK/SPI1_MISO TIM3_CH1 TIM1_BKIN TSC_G2_IO3 TIM16_CH1 PA_7, //I2S1_SD/SPI1_MOSI TIM3_CH2 TIM1_CH1N TSC_G2_IO4 TIM14_CH1 TIM17_CH1 - PB_0, //EVENTOUT TIM3_CH3 TIM1_CH2N TSC_G3_IO2 - PB_1, //TIM14_CH1 TIM3_CH4 TIM1_CH3N TSC_G3_IO3 + PB_0, //EVENTOUT TIM3_CH3 TIM1_CH2N TSC_G3_IO2 + PB_1, //TIM14_CH1 TIM3_CH4 TIM1_CH3N TSC_G3_IO3 PB_2, //TSC_G3_IO4 PB_10, //CEC I2C1_SCL TIM2_CH3 TSC_SYNC SPI2_SCK PB_11, //EVENTOUT I2C1_SDA TIM2_CH4 @@ -41,9 +41,9 @@ const PinName digitalPin[] = { PB_13, //SPI2_SCK TIM1_CH1N PB_14, //SPI2_MISO TIM1_CH2N PB_15, //SPI2_MOSI TIM1_CH3N - PA_8, //RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC + PA_8, //RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC PA_9, //USART1_TX TIM1_CH2 TSC_G4_IO1 I2C1_SCL - PA_10, //TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA + PA_10, //TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA PA_11, //USB_DM EVENTOUT USART1_CTS TIM1_CH4 TSC_G4_IO3 CAN_RX I2C1_SCL PA_12, //USB_DP EVENTOUT USART1_DE/USART1_RTS TIM1_ETR TSC_G4_IO4 CAN_TX I2C1_SDA PA_13, //SYS_SWDIO IR_OUT USB_NOE @@ -55,7 +55,7 @@ const PinName digitalPin[] = { PB_6, //USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 PB_7, //USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 PF_11, // - PB_8, //CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX + PB_8, //CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX PB_9 //IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS }; From 90a36718843a47365ab371ee4374a34a8130bb56 Mon Sep 17 00:00:00 2001 From: seeers Date: Thu, 25 Jun 2020 21:52:19 +0200 Subject: [PATCH 5/8] Final Style cleanup. Reorder Pins --- variants/Generic_F042Cx/variant.cpp | 46 ++++---- variants/Generic_F042Cx/variant.h | 156 +++------------------------- 2 files changed, 38 insertions(+), 164 deletions(-) diff --git a/variants/Generic_F042Cx/variant.cpp b/variants/Generic_F042Cx/variant.cpp index 25bb948ab6..79116320d1 100644 --- a/variants/Generic_F042Cx/variant.cpp +++ b/variants/Generic_F042Cx/variant.cpp @@ -21,9 +21,6 @@ extern "C" { // This array allows to wrap Arduino pin number(Dx or x) // to STM32 PinName (PX_n) const PinName digitalPin[] = { - PC_13, // - PF_0, //I2C1_SDA CRS_SYNC I2C1_SDA - PF_1, //I2C1_SCL I2C1_SCL PA_0, //USART2_CTS TIM2_CH1/TIM2_ETR TSC_G1_IO1 PA_1, //EVENTOUT USART2_DE/USART2_RTS TIM2_CH2 TSC_G1_IO2 PA_2, //USART2_TX TIM2_CH3 TSC_G1_IO3 @@ -32,31 +29,34 @@ const PinName digitalPin[] = { PA_5, //I2S1_CK/SPI1_SCK CEC TIM2_CH1/TIM2_ETR TSC_G2_IO2 PA_6, //I2S1_MCK/SPI1_MISO TIM3_CH1 TIM1_BKIN TSC_G2_IO3 TIM16_CH1 PA_7, //I2S1_SD/SPI1_MOSI TIM3_CH2 TIM1_CH1N TSC_G2_IO4 TIM14_CH1 TIM17_CH1 + PA_8, //RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC + PA_9, //USART1_TX TIM1_CH2 TSC_G4_IO1 I2C1_SCL + PA_10, //TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA + PA_11, //USB_DM EVENTOUT USART1_CTS TIM1_CH4 TSC_G4_IO3 CAN_RX I2C1_SCL + PA_12, //USB_DP EVENTOUT USART1_DE/USART1_RTS TIM1_ETR TSC_G4_IO4 CAN_TX I2C1_SDA + PA_13, //SYS_SWDIO IR_OUT USB_NOE + PA_14, //SYS_SWCLK USART2_TX + PA_15, //I2S1_WS/SPI1_NSS USART2_RX TIM2_CH1/TIM2_ETR EVENTOUT USB_NOE PB_0, //EVENTOUT TIM3_CH3 TIM1_CH2N TSC_G3_IO2 PB_1, //TIM14_CH1 TIM3_CH4 TIM1_CH3N TSC_G3_IO3 PB_2, //TSC_G3_IO4 + PB_3, //I2S1_CK/SPI1_SCK EVENTOUT TIM2_CH2 TSC_G5_IO1 + PB_4, //I2S1_MCK/SPI1_MISO TIM3_CH1 EVENTOUT TSC_G5_IO2 TIM17_BKIN + PB_5, //I2S1_SD/SPI1_MOSI TIM3_CH2 TIM16_BKIN I2C1_SMBA + PB_6, //USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 + PB_7, //USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 + PB_8, //CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX + PB_9 //IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS PB_10, //CEC I2C1_SCL TIM2_CH3 TSC_SYNC SPI2_SCK PB_11, //EVENTOUT I2C1_SDA TIM2_CH4 PB_12, //SPI2_NSS EVENTOUT TIM1_BKIN PB_13, //SPI2_SCK TIM1_CH1N PB_14, //SPI2_MISO TIM1_CH2N PB_15, //SPI2_MOSI TIM1_CH3N - PA_8, //RCC_MCO USART1_CK TIM1_CH1 EVENTOUT CRS_SYNC - PA_9, //USART1_TX TIM1_CH2 TSC_G4_IO1 I2C1_SCL - PA_10, //TIM17_BKIN USART1_RX TIM1_CH3 TSC_G4_IO2 I2C1_SDA - PA_11, //USB_DM EVENTOUT USART1_CTS TIM1_CH4 TSC_G4_IO3 CAN_RX I2C1_SCL - PA_12, //USB_DP EVENTOUT USART1_DE/USART1_RTS TIM1_ETR TSC_G4_IO4 CAN_TX I2C1_SDA - PA_13, //SYS_SWDIO IR_OUT USB_NOE - PA_14, //SYS_SWCLK USART2_TX - PA_15, //I2S1_WS/SPI1_NSS USART2_RX TIM2_CH1/TIM2_ETR EVENTOUT USB_NOE - PB_3, //I2S1_CK/SPI1_SCK EVENTOUT TIM2_CH2 TSC_G5_IO1 - PB_4, //I2S1_MCK/SPI1_MISO TIM3_CH1 EVENTOUT TSC_G5_IO2 TIM17_BKIN - PB_5, //I2S1_SD/SPI1_MOSI TIM3_CH2 TIM16_BKIN I2C1_SMBA - PB_6, //USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 - PB_7, //USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 - PF_11, // - PB_8, //CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX - PB_9 //IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS + PC_13, // + PF_0, //I2C1_SDA CRS_SYNC I2C1_SDA + PF_1, //I2C1_SCL I2C1_SCL + PF_11, // }; // If analog pins are not contiguous in the digitalPin array: @@ -64,14 +64,14 @@ const PinName digitalPin[] = { // Analog (Ax) pin number array // where x is the index to retrieve the digital pin number const uint32_t analogInputPin[] = { + 0, + 1, + 2, 3, 4, 5, 6, - 7, - 8, - 9, - 10 + 7 }; #ifdef __cplusplus diff --git a/variants/Generic_F042Cx/variant.h b/variants/Generic_F042Cx/variant.h index 30cc13fa37..f99923cdf2 100644 --- a/variants/Generic_F042Cx/variant.h +++ b/variants/Generic_F042Cx/variant.h @@ -22,9 +22,6 @@ extern "C" { * Pins *----------------------------------------------------------------------------*/ -#define PC13 0 -#define PF0 1 -#define PF1 2 #define PA0 A0 #define PA1 A1 #define PA2 A2 @@ -33,15 +30,6 @@ extern "C" { #define PA5 A5 #define PA6 A6 #define PA7 A7 -#define PB0 11 -#define PB1 12 -#define PB2 13 -#define PB10 14 -#define PB11 15 -#define PB12 16 -#define PB13 17 -#define PB14 18 -#define PB15 19 #define PA8 20 #define PA9 21 #define PA10 22 @@ -50,151 +38,37 @@ extern "C" { #define PA13 25 #define PA14 26 #define PA15 27 +#define PB0 11 +#define PB1 12 +#define PB2 13 #define PB3 28 #define PB4 29 #define PB5 30 #define PB6 31 #define PB7 32 -#define PF11 33 #define PB8 34 #define PB9 35 +#define PB10 14 +#define PB11 15 +#define PB12 16 +#define PB13 17 +#define PB14 18 +#define PB15 19 +#define PC13 0 +#define PF0 1 +#define PF1 2 +#define PF11 33 -// This must be a literal -// It is used with preprocessor tests (e.g. #if NUM_DIGITAL_PINS > 3) -// so an enum will not work. -#define NUM_DIGITAL_PINS 36 -// Allow to define Arduino style alias for analog input pin number --> Ax -// If no analog pin required then NUM_ANALOG_INPUTS could not be defined -// or set to `0` -// All pins are digital, analog inputs are a subset of digital pins. -// This must be a literal -// It is used with preprocessor tests (e.g. #if NUM_ANALOG_INPUTS > 3) -// so an enum will not work. -// !!! -// !!! It must be aligned with the number of analog PinName -// !!! defined in digitalPin[] array in variant.cpp -// !!! +#define NUM_DIGITAL_PINS 36 #define NUM_ANALOG_INPUTS 8 -// They are 2 possibles way to define analog pins: -//------------------------------------------------------------------------------------------- -// - If they are contiguous in the digitalPin array: -// Simply defined `NUM_ANALOG_FIRST` and all pins Ax will be automatically defined. -// It define the digital pin number of the first analog input (i.e. which digital pin is A0) -// First analog pin value (A0) must be greater than or equal to NUM_ANALOG_INPUTS -// This must be a literal with a value less than or equal to MAX_ANALOG_INPUTS -// defined in pin_arduino.h -// #define NUM_ANALOG_FIRST 0 -//------------------------------------OR------------------------------------------------------ -// - If they are not contiguous in the digitalPin array: -// Add an analogInputPin array in the variant.cpp without defining NUM_ANALOG_FIRST -// In that case the defined PYn for analog pin have to define the Ax definition instead of -// index in digitalPin[] array: -// #define PA4 A14 -//------------------------------------------------------------------------------------------- - - -// Below ADC and PWM definitions already done in the core -// Could be redefined here if needed -// ADC resolution is 10 bits -//#define ADC_RESOLUTION 10 - -// PWM resolution -//#define PWM_RESOLUTION 8 -//#define PWM_FREQUENCY 1000 -//#define PWM_MAX_DUTY_CYCLE 255 - -// On-board LED pin number -//#define LED_BUILTIN x -//#define LED_GREEN LED_BUILTIN - -// On-board user button -//#define USER_BTN x - -// Below SPI and I2C definitions already done in the core -// Could be redefined here if differs from the default one -// SPI Definitions -//#define PIN_SPI_SS 10 // Default for Arduino connector compatibility -//#define PIN_SPI_MOSI 11 // Default for Arduino connector compatibility -//#define PIN_SPI_MISO 12 // Default for Arduino connector compatibility -//#define PIN_SPI_SCK 13 // Default for Arduino connector compatibility - -// I2C Definitions -//#define PIN_WIRE_SDA 14 // Default for Arduino connector compatibility -//#define PIN_WIRE_SCL 15 // Default for Arduino connector compatibility - -// I2C timing definitions (optional), avoid time spent to compute if defined -// * I2C_TIMING_SM for Standard Mode (100kHz) -// * I2C_TIMING_FM for Fast Mode (400kHz) -// * I2C_TIMING_FMP for Fast Mode Plus (1000kHz) -//#define I2C_TIMING_SM 0x00000000 -//#define I2C_TIMING_FM 0x00000000 -//#define I2C_TIMING_FMP 0x00000000 - -// Timer Definitions (optional) -// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin -//#define TIMER_TONE TIM6 -//#define TIMER_SERVO TIM7 - // UART Definitions -// Define here Serial instance number to map on Serial generic name -#define SERIAL_UART_INSTANCE 2 //ex: 2 for Serial2 (USART2) -// DEBUG_UART could be redefined to print on another instance than 'Serial' -//#define DEBUG_UART ((USART_TypeDef *) U(S)ARTX) // ex: USART3 -// DEBUG_UART baudrate, default: 9600 if not defined -//#define DEBUG_UART_BAUDRATE x -// DEBUG_UART Tx pin name, default: the first one found in PinMap_UART_TX for DEBUG_UART -//#define DEBUG_PINNAME_TX PX_n // PinName used for TX +#define SERIAL_UART_INSTANCE 2 -// Default pin used for 'Serial' instance (ex: ST-Link) -// Mandatory for Firmata #define PIN_SERIAL_RX PA3 #define PIN_SERIAL_TX PA2 -// Optional PIN_SERIALn_RX and PIN_SERIALn_TX where 'n' is the U(S)ART number -// Used when user instanciate a hardware Serial using its peripheral name. -// Example: HardwareSerial mySerial(USART3); -// will use PIN_SERIAL3_RX and PIN_SERIAL3_TX if defined. -//#define PIN_SERIALn_RX x // For U(S)ARTn RX -//#define PIN_SERIALn_TX x // For U(S)ARTn TX -//#define PIN_SERIALLP1_RX x // For LPUART1 RX -//#define PIN_SERIALLP1_TX x // For LPUART1 TX - -// SD card slot Definitions -// SD detect signal can be defined if required -//#define SD_DETECT_PIN x -// SD Read/Write timeout, default value defined in STM32SD library -//#define SD_DATATIMEOUT x - -// USB Vbus sensing. Require to have Vbus pin connected to Vbus signal. -// Warning, pin is different depending on FullSpeed or High Speed mode used -// See AN4879 https://www.st.com/content/st_com/en/search.html#q=AN4879-t=resources-page=1 -//#define USBD_VBUS_DETECTION_ENABLE - -// If the board has external USB pullup (on DP/DM depending on speed) -// that can be controlled using a GPIO pin, define these: -// - If the the pullup is disabled (USB detached) by default, define -// USBD_ATTACH_PIN to the pin that, when written to -// USBD_ATTACH_LEVEL, attaches the pullup. -// - If the the pullup is enabled (attached) by default, define -// USBD_DETACH_PIN to the pin that, when written to -// USBD_DETACH_LEVEL, detaches the pullup. -//#define USBD_ATTACH_PIN x -//#define USBD_ATTACH_LEVEL LOW -//#define USBD_DETACH_PIN x -//#define USBD_DETACH_LEVEL LOW -// -// This indicates that there is an external and fixed 1.5k pullup -// on the D+ line. This define is not normally needed, since a -// fixed pullup is assumed by default. It is only required when -// the USB peripheral has an internal pullup *and* an external -// fixed pullup is present (which is actually a hardware bug, since just -// the internal pullup is sufficient and having two pullups violates the -// USB specification). In this case, defining this forces -// the "write D+ LOW"-trick to be used. In the future, it might also -// disable the internal pullups, but this is not currently implemented. -// #define USBD_FIXED_PULLUP #ifdef __cplusplus } // extern "C" #endif From 7fa16000537cb47bc63d16679912a99556809597 Mon Sep 17 00:00:00 2001 From: seeers Date: Fri, 26 Jun 2020 21:36:58 +0200 Subject: [PATCH 6/8] changed pin order --- variants/Generic_F042Cx/variant.h | 56 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/variants/Generic_F042Cx/variant.h b/variants/Generic_F042Cx/variant.h index f99923cdf2..79387a8783 100644 --- a/variants/Generic_F042Cx/variant.h +++ b/variants/Generic_F042Cx/variant.h @@ -30,34 +30,34 @@ extern "C" { #define PA5 A5 #define PA6 A6 #define PA7 A7 -#define PA8 20 -#define PA9 21 -#define PA10 22 -#define PA11 23 -#define PA12 24 -#define PA13 25 -#define PA14 26 -#define PA15 27 -#define PB0 11 -#define PB1 12 -#define PB2 13 -#define PB3 28 -#define PB4 29 -#define PB5 30 -#define PB6 31 -#define PB7 32 -#define PB8 34 -#define PB9 35 -#define PB10 14 -#define PB11 15 -#define PB12 16 -#define PB13 17 -#define PB14 18 -#define PB15 19 -#define PC13 0 -#define PF0 1 -#define PF1 2 -#define PF11 33 +#define PA8 8 +#define PA9 9 +#define PA10 10 +#define PA11 11 +#define PA12 12 +#define PA13 13 +#define PA14 14 +#define PA15 15 +#define PB0 16 +#define PB1 17 +#define PB2 18 +#define PB3 19 +#define PB4 20 +#define PB5 21 +#define PB6 22 +#define PB7 23 +#define PB8 24 +#define PB9 25 +#define PB10 26 +#define PB11 27 +#define PB12 28 +#define PB13 29 +#define PB14 30 +#define PB15 31 +#define PC13 32 +#define PF0 33 +#define PF1 34 +#define PF11 35 #define NUM_DIGITAL_PINS 36 From afd97da5bb7e5ba32a3f6052609e88957821b44a Mon Sep 17 00:00:00 2001 From: seeers Date: Fri, 26 Jun 2020 22:09:46 +0200 Subject: [PATCH 7/8] fixed missing comma --- variants/Generic_F042Cx/variant.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/Generic_F042Cx/variant.cpp b/variants/Generic_F042Cx/variant.cpp index 79116320d1..13d0082b16 100644 --- a/variants/Generic_F042Cx/variant.cpp +++ b/variants/Generic_F042Cx/variant.cpp @@ -46,7 +46,7 @@ const PinName digitalPin[] = { PB_6, //USART1_TX I2C1_SCL TIM16_CH1N TSC_G5_IO3 PB_7, //USART1_RX I2C1_SDA TIM17_CH1N TSC_G5_IO4 PB_8, //CEC I2C1_SCL TIM16_CH1 TSC_SYNC CAN_RX - PB_9 //IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS + PB_9, //IR_OUT I2C1_SDA TIM17_CH1 EVENTOUT CAN_TX SPI2_NSS PB_10, //CEC I2C1_SCL TIM2_CH3 TSC_SYNC SPI2_SCK PB_11, //EVENTOUT I2C1_SDA TIM2_CH4 PB_12, //SPI2_NSS EVENTOUT TIM1_BKIN From c647db8c32dc9c3820bd0d0bebf771dd06f14464 Mon Sep 17 00:00:00 2001 From: seeers Date: Sun, 5 Jul 2020 14:44:29 +0200 Subject: [PATCH 8/8] removed wrong comma --- variants/Generic_F042Cx/variant.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/Generic_F042Cx/variant.cpp b/variants/Generic_F042Cx/variant.cpp index 13d0082b16..b16cca4e89 100644 --- a/variants/Generic_F042Cx/variant.cpp +++ b/variants/Generic_F042Cx/variant.cpp @@ -56,7 +56,7 @@ const PinName digitalPin[] = { PC_13, // PF_0, //I2C1_SDA CRS_SYNC I2C1_SDA PF_1, //I2C1_SCL I2C1_SCL - PF_11, // + PF_11 // }; // If analog pins are not contiguous in the digitalPin array: