From 116b1c28b1f8001bae3197ba30d91c0e0ab3e743 Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Wed, 24 Jul 2019 12:03:21 +0200 Subject: [PATCH 01/11] Added Generic flight controllers Sub menu Added basic Afroflight Rev 5 boards --- boards.txt | 118 +++++++++ variants/AFROFLIGHT_F103CB/PeripheralPins.c | 276 ++++++++++++++++++++ variants/AFROFLIGHT_F103CB/PinNamesVar.h | 30 +++ variants/AFROFLIGHT_F103CB/ldscript.ld | 188 +++++++++++++ variants/AFROFLIGHT_F103CB/variant.cpp | 179 +++++++++++++ variants/AFROFLIGHT_F103CB/variant.h | 185 +++++++++++++ 6 files changed, 976 insertions(+) create mode 100644 variants/AFROFLIGHT_F103CB/PeripheralPins.c create mode 100644 variants/AFROFLIGHT_F103CB/PinNamesVar.h create mode 100644 variants/AFROFLIGHT_F103CB/ldscript.ld create mode 100644 variants/AFROFLIGHT_F103CB/variant.cpp create mode 100644 variants/AFROFLIGHT_F103CB/variant.h diff --git a/boards.txt b/boards.txt index 64705ef95d..c2600249f9 100644 --- a/boards.txt +++ b/boards.txt @@ -1102,6 +1102,77 @@ RAK.menu.upload_method.dfuMethod.upload.tool=stm32CubeProg 3dprinter.menu.upload_method.dfuMethod.upload.options=-g 3dprinter.menu.upload_method.dfuMethod.upload.tool=stm32CubeProg + +############################### +# Genericflight Flight Controllers + +Genericflight.name=Generic flight controllers + + +Genericflight.build.vid=0x0483 +Genericflight.build.core=arduino +Genericflight.build.board=Genericflight +Genericflight.build.mcu=cortex-m3 +Genericflight.build.series=STM32F1xx +Genericflight.build.cmsis_lib_gcc=arm_cortexM3l_math +Genericflight.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} {build.bootloader_flags} + + + +# AfroFlight Rev5 +Genericflight.menu.pnum.AFROFLIGHT_F103CB=Afro Flight Rev5 +Genericflight.menu.pnum.AFROFLIGHT_F103CB.upload.maximum_size=131072 +Genericflight.menu.pnum.AFROFLIGHT_F103CB.upload.maximum_data_size=20480 +Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.board=AFROFLIGHT_F103CB +Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.series=STM32F1xx +Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.product_line=STM32F103xB +Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.variant=AFROFLIGHT_F103CB + + + +# Upload menu + +Genericflight.menu.upload_method.swdMethod=STM32CubeProgrammer (SWD) +Genericflight.menu.upload_method.swdMethod.upload.protocol=0 +Genericflight.menu.upload_method.swdMethod.upload.options=-g +Genericflight.menu.upload_method.swdMethod.upload.tool=stm32CubeProg + +Genericflight.menu.upload_method.serialMethod=STM32CubeProgrammer (Serial) +Genericflight.menu.upload_method.serialMethod.upload.protocol=1 +Genericflight.menu.upload_method.serialMethod.upload.options={serial.port.file} -s +Genericflight.menu.upload_method.serialMethod.upload.tool=stm32CubeProg + +Genericflight.menu.upload_method.dfuMethod=STM32CubeProgrammer (DFU) +Genericflight.menu.upload_method.dfuMethod.upload.protocol=2 +Genericflight.menu.upload_method.dfuMethod.upload.options=-g +Genericflight.menu.upload_method.dfuMethod.upload.tool=stm32CubeProg + +Genericflight.menu.upload_method.bmpMethod=BMP (Black Magic Probe) +Genericflight.menu.upload_method.bmpMethod.upload.protocol=gdb_bmp +Genericflight.menu.upload_method.bmpMethod.upload.tool=bmp_upload + +Genericflight.menu.upload_method.hidMethod=HID Bootloader 2.2 +Genericflight.menu.upload_method.hidMethod.upload.protocol=hid22 +Genericflight.menu.upload_method.hidMethod.upload.tool=hid_upload +Genericflight.menu.upload_method.hidMethod.build.flash_offset=0x800 +Genericflight.menu.upload_method.hidMethod.build.bootloader_flags=-DBL_HID -DVECT_TAB_OFFSET={build.flash_offset} + +Genericflight.menu.upload_method.dfu2Method=Maple DFU Bootloader 2.0 +Genericflight.menu.upload_method.dfu2Method.upload.protocol=maple +Genericflight.menu.upload_method.dfu2Method.upload.tool=maple_upload +Genericflight.menu.upload_method.dfu2Method.upload.usbID=1EAF:0003 +Genericflight.menu.upload_method.dfu2Method.upload.altID=2 +Genericflight.menu.upload_method.dfu2Method.build.flash_offset=0x2000 +Genericflight.menu.upload_method.dfu2Method.build.bootloader_flags=-DBL_LEGACY_LEAF -DVECT_TAB_OFFSET={build.flash_offset} + +Genericflight.menu.upload_method.dfuoMethod=Maple DFU Bootloader original +Genericflight.menu.upload_method.dfuoMethod.upload.protocol=maple +Genericflight.menu.upload_method.dfuoMethod.upload.tool=maple_upload +Genericflight.menu.upload_method.dfuoMethod.upload.usbID=1EAF:0003 +Genericflight.menu.upload_method.dfuoMethod.upload.altID=1 +Genericflight.menu.upload_method.dfuoMethod.build.flash_offset=0x5000 +Genericflight.menu.upload_method.dfuoMethod.build.bootloader_flags=-DBL_LEGACY_LEAF -DVECT_TAB_OFFSET={build.flash_offset} + ################################################################################ # Serialx activation Nucleo_144.menu.xserial.generic=Enabled (generic 'Serial') @@ -1170,6 +1241,12 @@ RAK.menu.xserial.disabled.build.xSerial= 3dprinter.menu.xserial.disabled=Disabled (no Serial support) 3dprinter.menu.xserial.disabled.build.xSerial= +Genericflight.menu.xserial.generic=Enabled (generic 'Serial') +Genericflight.menu.xserial.none=Enabled (no generic 'Serial') +Genericflight.menu.xserial.none.build.xSerial=-DHAL_UART_MODULE_ENABLED -DHWSERIAL_NONE +Genericflight.menu.xserial.disabled=Disabled (no Serial support) +Genericflight.menu.xserial.disabled.build.xSerial= + # USB connectivity Nucleo_144.menu.usb.none=None Nucleo_144.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART) @@ -1284,6 +1361,19 @@ Sparky.menu.xusb.HSFS.build.usb_speed=-DUSE_USB_HS -DUSE_USB_HS_IN_FS 3dprinter.menu.xusb.HSFS=High Speed in Full Speed mode 3dprinter.menu.xusb.HSFS.build.usb_speed=-DUSE_USB_HS -DUSE_USB_HS_IN_FS +Genericflight.menu.usb.none=None +Genericflight.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART) +Genericflight.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC +Genericflight.menu.usb.CDC=CDC (no generic 'Serial') +Genericflight.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB +Genericflight.menu.usb.HID=HID (keyboard and mouse) +Genericflight.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE +Genericflight.menu.xusb.FS=Low/Full Speed +Genericflight.menu.xusb.HS=High Speed +Genericflight.menu.xusb.HS.build.usb_speed=-DUSE_USB_HS +Genericflight.menu.xusb.HSFS=High Speed in Full Speed mode +Genericflight.menu.xusb.HSFS.build.usb_speed=-DUSE_USB_HS -DUSE_USB_HS_IN_FS + # Optimizations Nucleo_144.menu.opt.osstd=Smallest (-Os default) Nucleo_144.menu.opt.oslto=Smallest (-Os) with LTO @@ -1485,6 +1575,24 @@ RAK.menu.opt.ogstd.build.flags.optimize=-g -Og 3dprinter.menu.opt.ogstd=Debug (-g) 3dprinter.menu.opt.ogstd.build.flags.optimize=-g -Og +Genericflight.menu.opt.osstd=Smallest (-Os default) +Genericflight.menu.opt.oslto=Smallest (-Os) with LTO +Genericflight.menu.opt.oslto.build.flags.optimize=-Os -flto +Genericflight.menu.opt.o1std=Fast (-O1) +Genericflight.menu.opt.o1std.build.flags.optimize=-O1 +Genericflight.menu.opt.o1lto=Fast (-O1) with LTO +Genericflight.menu.opt.o1lto.build.flags.optimize=-O1 -flto +Genericflight.menu.opt.o2std=Faster (-O2) +Genericflight.menu.opt.o2std.build.flags.optimize=-O2 +Genericflight.menu.opt.o2lto=Faster (-O2) with LTO +Genericflight.menu.opt.o2lto.build.flags.optimize=-O2 -flto +Genericflight.menu.opt.o3std=Fastest (-O3) +Genericflight.menu.opt.o3std.build.flags.optimize=-O3 +Genericflight.menu.opt.o3lto=Fastest (-O3) with LTO +Genericflight.menu.opt.o3lto.build.flags.optimize=-O3 -flto +Genericflight.menu.opt.ogstd=Debug (-g) +Genericflight.menu.opt.ogstd.build.flags.optimize=-g -Og + # C Runtime Library Nucleo_144.menu.rtlib.nano=Newlib Nano (default) Nucleo_144.menu.rtlib.nanofp=Newlib Nano + Float Printf @@ -1595,3 +1703,13 @@ RAK.menu.rtlib.full.build.flags.ldspecs= 3dprinter.menu.rtlib.nanofps.build.flags.ldspecs=--specs=nano.specs -u _printf_float -u _scanf_float 3dprinter.menu.rtlib.full=Newlib Standard 3dprinter.menu.rtlib.full.build.flags.ldspecs= + +Genericflight.menu.rtlib.nano=Newlib Nano (default) +Genericflight.menu.rtlib.nanofp=Newlib Nano + Float Printf +Genericflight.menu.rtlib.nanofp.build.flags.ldspecs=--specs=nano.specs -u _printf_float +Genericflight.menu.rtlib.nanofs=Newlib Nano + Float Scanf +Genericflight.menu.rtlib.nanofs.build.flags.ldspecs=--specs=nano.specs -u _scanf_float +Genericflight.menu.rtlib.nanofps=Newlib Nano + Float Printf/Scanf +Genericflight.menu.rtlib.nanofps.build.flags.ldspecs=--specs=nano.specs -u _printf_float -u _scanf_float +Genericflight.menu.rtlib.full=Newlib Standard +Genericflight.menu.rtlib.full.build.flags.ldspecs= diff --git a/variants/AFROFLIGHT_F103CB/PeripheralPins.c b/variants/AFROFLIGHT_F103CB/PeripheralPins.c new file mode 100644 index 0000000000..2cceb9c59e --- /dev/null +++ b/variants/AFROFLIGHT_F103CB/PeripheralPins.c @@ -0,0 +1,276 @@ +/* + ******************************************************************************* + * Copyright (c) 2019, 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. + ******************************************************************************* + * Automatically generated from STM32F103C(4-6)|(8-B)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)}, // ADC1_IN0 + // {PA_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 + {PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 + // {PA_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 + {PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 + // {PA_2, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 + {PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 + // {PA_3, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 + {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 + // {PA_4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 + {PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 + // {PA_5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 + {PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 + // {PA_6, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 + {PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 + // {PA_7, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 + {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 + // {PB_0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 + {PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 + // {PB_1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 + {NC, NP, 0} +}; +#endif + +//*** No DAC *** + +//*** I2C *** + +#ifdef HAL_I2C_MODULE_ENABLED +WEAK const PinMap PinMap_I2C_SDA[] = { + {PB_7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE)}, + {PB_9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_I2C1_ENABLE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE)}, +#endif + {NC, NP, 0} +}; +#endif + +#ifdef HAL_I2C_MODULE_ENABLED +WEAK const PinMap PinMap_I2C_SCL[] = { + {PB_6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE)}, + {PB_8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_I2C1_ENABLE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE)}, +#endif + {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, AFIO_NONE, 1, 0)}, // TIM2_CH1 + // {PA_0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_2, 1, 0)}, // TIM2_CH1 + {PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 2, 0)}, // TIM2_CH2 + // {PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_2, 2, 0)}, // TIM2_CH2 + {PA_2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 3, 0)}, // TIM2_CH3 + // {PA_2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_1, 3, 0)}, // TIM2_CH3 + {PA_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 4, 0)}, // TIM2_CH4 + // {PA_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_1, 4, 0)}, // TIM2_CH4 + {PA_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 1, 0)}, // TIM3_CH1 + // {PA_7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM1_PARTIAL, 1, 1)}, // TIM1_CH1N + {PA_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 2, 0)}, // TIM3_CH2 + {PA_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 1, 0)}, // TIM1_CH1 + // {PA_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM1_PARTIAL, 1, 0)}, // TIM1_CH1 + {PA_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 2, 0)}, // TIM1_CH2 + // {PA_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM1_PARTIAL, 2, 0)}, // TIM1_CH2 + {PA_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 3, 0)}, // TIM1_CH3 + // {PA_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM1_PARTIAL, 3, 0)}, // TIM1_CH3 + {PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 4, 0)}, // TIM1_CH4 + // {PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM1_PARTIAL, 4, 0)}, // TIM1_CH4 + // {PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_1, 1, 0)}, // TIM2_CH1 + {PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_ENABLE, 1, 0)}, // TIM2_CH1 + // {PB_0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM1_PARTIAL, 2, 1)}, // TIM1_CH2N + {PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 3, 0)}, // TIM3_CH3 + // {PB_0, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM3_PARTIAL, 3, 0)}, // TIM3_CH3 + // {PB_1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM1_PARTIAL, 3, 1)}, // TIM1_CH3N + {PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 4, 0)}, // TIM3_CH4 + // {PB_1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM3_PARTIAL, 4, 0)}, // TIM3_CH4 + // {PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_1, 2, 0)}, // TIM2_CH2 + {PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_ENABLE, 2, 0)}, // TIM2_CH2 + {PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM3_PARTIAL, 1, 0)}, // TIM3_CH1 + {PB_5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM3_PARTIAL, 2, 0)}, // TIM3_CH2 +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 1, 0)}, // TIM4_CH1 + {PB_7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 2, 0)}, // TIM4_CH2 + {PB_8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 3, 0)}, // TIM4_CH3 + {PB_9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 4, 0)}, // TIM4_CH4 +#endif + // {PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_2, 3, 0)}, // TIM2_CH3 + {PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_ENABLE, 3, 0)}, // TIM2_CH3 + // {PB_11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_2, 4, 0)}, // TIM2_CH4 + {PB_11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_ENABLE, 4, 0)}, // TIM2_CH4 + {PB_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 1, 1)}, // TIM1_CH1N + {PB_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 2, 1)}, // TIM1_CH2N + {PB_15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 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, AFIO_NONE)}, + {PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, + {PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_USART1_ENABLE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, +#endif + {NC, NP, 0} +}; +#endif + +#ifdef HAL_UART_MODULE_ENABLED +WEAK const PinMap PinMap_UART_RX[] = { + {PA_3, USART2, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_NONE)}, + {PA_10, USART1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_NONE)}, + {PB_7, USART1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_USART1_ENABLE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_11, USART3, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_NONE)}, +#endif + {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, AFIO_NONE)}, + {PA_12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, + // {PB_14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_USART3_PARTIAL)}, +#endif + {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, AFIO_NONE)}, + {PA_11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, + // {PB_13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_USART3_PARTIAL)}, +#endif + {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, AFIO_NONE)}, + {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_SPI1_ENABLE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, +#endif + {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, AFIO_NONE)}, + {PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_SPI1_ENABLE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, +#endif + {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, AFIO_NONE)}, + {PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_SPI1_ENABLE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, +#endif + {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, AFIO_NONE)}, + {PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_SPI1_ENABLE)}, +#ifndef ARDUINO_BLUEPILL_F103C6 + {PB_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, +#endif + {NC, NP, 0} +}; +#endif + +//*** CAN *** + +#ifdef HAL_CAN_MODULE_ENABLED +WEAK const PinMap PinMap_CAN_RD[] = { + {PA_11, CAN1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, AFIO_NONE)}, + {PB_8, CAN1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, AFIO_CAN1_2)}, + {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, AFIO_NONE)}, + {PB_9, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, AFIO_CAN1_2)}, + {NC, NP, 0} +}; +#endif + +//*** No ETHERNET *** + +//*** No QUADSPI *** + +//*** USB *** + +#ifdef HAL_PCD_MODULE_ENABLED +WEAK const PinMap PinMap_USB[] = { + {PA_11, USB, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, AFIO_NONE)}, // USB_DM + {PA_12, USB, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, AFIO_NONE)}, // USB_DP + {NC, NP, 0} +}; +#endif + +//*** No USB_OTG_FS *** + +//*** No USB_OTG_HS *** diff --git a/variants/AFROFLIGHT_F103CB/PinNamesVar.h b/variants/AFROFLIGHT_F103CB/PinNamesVar.h new file mode 100644 index 0000000000..f7fb9d83a4 --- /dev/null +++ b/variants/AFROFLIGHT_F103CB/PinNamesVar.h @@ -0,0 +1,30 @@ +/* SYS_WKUP */ +#ifdef PWR_WAKEUP_PIN1 +SYS_WKUP1 = PA_0, +#endif +#ifdef PWR_WAKEUP_PIN2 +SYS_WKUP2 = NC, +#endif +#ifdef PWR_WAKEUP_PIN3 +SYS_WKUP3 = NC, +#endif +#ifdef PWR_WAKEUP_PIN4 +SYS_WKUP4 = NC, +#endif +#ifdef PWR_WAKEUP_PIN5 +SYS_WKUP5 = NC, +#endif +#ifdef PWR_WAKEUP_PIN6 +SYS_WKUP6 = NC, +#endif +#ifdef PWR_WAKEUP_PIN7 +SYS_WKUP7 = NC, +#endif +#ifdef PWR_WAKEUP_PIN8 +SYS_WKUP8 = NC, +#endif +/* USB */ +#ifdef USBCON +USB_DM = PA_11, +USB_DP = PA_12, +#endif diff --git a/variants/AFROFLIGHT_F103CB/ldscript.ld b/variants/AFROFLIGHT_F103CB/ldscript.ld new file mode 100644 index 0000000000..ab2c04d4ab --- /dev/null +++ b/variants/AFROFLIGHT_F103CB/ldscript.ld @@ -0,0 +1,188 @@ +/* +***************************************************************************** +** + +** File : ldscript.ld +** +** Abstract : Linker script for STM32F103C(8-B)Tx Device with +** 32/64/128KByte FLASH, 10/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. +** +** Target : STMicroelectronics STM32 +** +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +***************************************************************************** +** @attention +** +**

© COPYRIGHT(c) 2014 Ac6

+** +** 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 Ac6 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 = 0x20000000 + LD_MAX_DATA_SIZE; /* 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 = LD_MAX_DATA_SIZE +FLASH (rx) : ORIGIN = 0x8000000 + LD_FLASH_OFFSET, LENGTH = LD_MAX_SIZE - LD_FLASH_OFFSET +} + +/* 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): + { + . = 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(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} + + diff --git a/variants/AFROFLIGHT_F103CB/variant.cpp b/variants/AFROFLIGHT_F103CB/variant.cpp new file mode 100644 index 0000000000..b77ac35469 --- /dev/null +++ b/variants/AFROFLIGHT_F103CB/variant.cpp @@ -0,0 +1,179 @@ +/* + ******************************************************************************* + * Copyright (c) 2018, 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 "pins_arduino.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Pin number +const PinName digitalPin[] = { + /* USB connector on the top, MCU side */ + /* Left Side */ + PB_9, //D0 + PB_8, //D1 + PB_7, //D2 + PB_6, //D3 + PB_5, //D4 + PB_4, //D5 + PB_3, //D6 + PA_15, //D7 + PA_12, //D8 - USB DP + PA_11, //D9 - USB DM + PA_10, //D10 + PA_9, //D11 + PA_8, //D12 + PB_15, //D13 + PB_14, //D14 + PB_13, //D15 + PB_12, //D16 - LED Blackpill + /* Right side */ + PC_13, //D17 - LED Bluepill + PC_14, //D18 + PC_15, //D19 + PA_0, //D20/A0 + PA_1, //D21/A1 + PA_2, //D22/A2 + PA_3, //D23/A3 + PA_4, //D24/A4 + PA_5, //D25/A5 + PA_6, //D26/A6 + PA_7, //D27/A7 + PB_0, //D28/A8 + PB_1, //D29/A9 + PB_10, //D30 + PB_11, //D31 + PB_2, //D32 - BOOT1 + PA_13, //D33 - SWDI0 + PA_14, //D34 - SWCLK +}; + +#ifdef __cplusplus +} +#endif + +// ---------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#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; + + /* Initializes the CPU, AHB and APB busses clocks * / + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + while (1); + } + + /* Initializes the CPU, AHB and APB busses clocks * / + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK + | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { + 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); + } +}*/ +//Board has 12mhz xtal, iám currenlty using HSI internal xtal , i've not figured settings for external 12mhz +RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInit; + + /* Initializes the CPU, AHB and APB busses clocks */ + 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) { + Error_Handler(); + } + + /* Initializes the CPU, AHB and APB busses clocks */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK + | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { + Error_Handler(); + } + + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; + PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { + Error_Handler(); + } +} +#ifdef __cplusplus +} +#endif diff --git a/variants/AFROFLIGHT_F103CB/variant.h b/variants/AFROFLIGHT_F103CB/variant.h new file mode 100644 index 0000000000..cba2e5781f --- /dev/null +++ b/variants/AFROFLIGHT_F103CB/variant.h @@ -0,0 +1,185 @@ +/* + ******************************************************************************* + * Copyright (c) 2018, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +#ifndef _VARIANT_ARDUINO_STM32_ +#define _VARIANT_ARDUINO_STM32_ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/*---------------------------------------------------------------------------- + * Pins + *----------------------------------------------------------------------------*/ + +// Bluepill USB connector on the top, MCU side - Blackpill USB connector on bottom, MCU Side (pins are reversed vertically for Arduino Ananlog pin correct sequence. +// Left Side +#define PB9 0 +#define PB8 1 +#define PB7 2 +#define PB6 3 +#define PB5 4 +#define PB4 5 +#define PB3 6 +#define PA15 7 +#define PA12 8 // USB DP +#define PA11 9 // USB DM +#define PA10 10 +#define PA9 11 +#define PA8 12 +#define PB15 13 +#define PB14 14 +#define PB13 15 +#define PB12 16 // LED Blackpill +// Right side +#define PC13 17 // LED Bluepill +#define PC14 18 +#define PC15 19 +#define PA0 20 // A0 +#define PA1 21 // A1 +#define PA2 22 // A2 +#define PA3 23 // A3 +#define PA4 24 // A4 Board voltage ADC +#define PA5 25 // A5 +#define PA6 26 // A6 +#define PA7 27 // A7 +#define PB0 28 // A8 +#define PB1 29 // A9 +#define PB10 30 +#define PB11 31 +// Other +#define PB2 32 // BOOT1 +#define PA13 33 // SWDI0 +#define PA14 34 // SWCLK + +// This must be a literal +#define NUM_DIGITAL_PINS 35 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS +#define NUM_ANALOG_INPUTS 10 +#define NUM_ANALOG_FIRST 20 + +// On-board LED pin number +#ifdef ARDUINO_BLUEPILL_F103C8 +#define LED_BUILTIN PC13 +#else +#define LED_BUILTIN PB4 +#endif +#define LED_GREEN PB3 +#define LED_RED LED_BUILTIN + + +// SPI Definitions +#define PIN_SPI_SS PA4 +#define PIN_SPI_MOSI PA7 +#define PIN_SPI_MISO PA6 +#define PIN_SPI_SCK PA5 + +// I2C Definitions +//#define PIN_WIRE_SDA PB7 +//#define PIN_WIRE_SCL PB6 +//On afroflight Rev 5 it's on i2c port 2 that MPU6050 is connected too +#define PIN_WIRE_SDA PB11 +#define PIN_WIRE_SCL PB10 + + //Wire.setSDA(PB11); + //Wire.setSCL(PB10); +// Timer Definitions +// Do not use timer used by PWM pins when possible. See PinMap_PWM. +#define TIMER_TONE TIM3 + +// Do not use basic timer: OC is required +#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work + +// UART Definitions +#define SERIAL_UART_INSTANCE 1 +// Default pin used for 'Serial' instance +// Mandatory for Firmata +#define PIN_SERIAL_RX PA10 +#define PIN_SERIAL_TX PA9 + +#define MPU_I2C_SDA PB11; +#define MPU_I2C_SCL PB10; +#define MPU_ADDR 0x68; +#define MPU_INT PB13; +/* + * RC_CH1 T2C1 PA0 + * RC_CH2 T2C2 PA1 + * RC_CH3 T2C3/UA2_TX PA2 + * RC_CH4 T2C4/UA2_RX PA3 + * RC_CH5 T3C1 PA6 + * RC_CH6 T3C2 PA7 + * RC_CH7 T3C3 PB0 + * RC_CH8 T3C4 PB1 + * + * PWM1 T1C1 PA8 + * PMW2 T1C4 PA11 + * PMW3 T4C1 PB6 + * PMW4 T4C2 PB7 + * PMW5 T4C3 PB8 + * PMW6 T4C4 PB9 + * SONAR_INT PA15 + * GPIO_BOTTOM PB5 + * TELEM_OUT PA13 //warning, you loose SWD access when using this pin , bootloader via uart is required after + * + * Power ADC ADC12_IN4 PA4 connected to 6 pin header Battery voltage in via resistor devider + * ACC_INT PA5 // Connected to Intterupt pin of MMA84520 accelerometer I2C + * + * MAG_DRD PB12; //connected to HMC5883L compass I2C + * BEEP PA12; //connected to Beep out transistor on 6 pin header + * + */ + +#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 Serial1 +#endif + +#endif /* _VARIANT_ARDUINO_STM32_ */ From 92559b88263c022ee33e8f956186ef57aac2d75a Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Wed, 24 Jul 2019 17:31:19 +0200 Subject: [PATCH 02/11] fixed style issues --- variants/AFROFLIGHT_F103CB/variant.cpp | 38 +----------------- variants/AFROFLIGHT_F103CB/variant.h | 53 +++++++++++++------------- 2 files changed, 27 insertions(+), 64 deletions(-) diff --git a/variants/AFROFLIGHT_F103CB/variant.cpp b/variants/AFROFLIGHT_F103CB/variant.cpp index b77ac35469..a44be179f7 100644 --- a/variants/AFROFLIGHT_F103CB/variant.cpp +++ b/variants/AFROFLIGHT_F103CB/variant.cpp @@ -104,44 +104,8 @@ extern "C" { */ WEAK void SystemClock_Config(void) { - /* - RCC_OscInitTypeDef RCC_OscInitStruct; - RCC_ClkInitTypeDef RCC_ClkInitStruct; - RCC_PeriphCLKInitTypeDef PeriphClkInit; - - /* Initializes the CPU, AHB and APB busses clocks * / - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - while (1); - } - - /* Initializes the CPU, AHB and APB busses clocks * / - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK - | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { - 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); - } -}*/ //Board has 12mhz xtal, iám currenlty using HSI internal xtal , i've not figured settings for external 12mhz -RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; diff --git a/variants/AFROFLIGHT_F103CB/variant.h b/variants/AFROFLIGHT_F103CB/variant.h index cba2e5781f..da82a06dae 100644 --- a/variants/AFROFLIGHT_F103CB/variant.h +++ b/variants/AFROFLIGHT_F103CB/variant.h @@ -91,7 +91,7 @@ extern "C" { #define LED_BUILTIN PB4 #endif #define LED_GREEN PB3 -#define LED_RED LED_BUILTIN +#define LED_RED LED_BUILTIN // SPI Definitions @@ -104,11 +104,10 @@ extern "C" { //#define PIN_WIRE_SDA PB7 //#define PIN_WIRE_SCL PB6 //On afroflight Rev 5 it's on i2c port 2 that MPU6050 is connected too -#define PIN_WIRE_SDA PB11 -#define PIN_WIRE_SCL PB10 +#define PIN_WIRE_SDA PB11 +#define PIN_WIRE_SCL PB10 + - //Wire.setSDA(PB11); - //Wire.setSCL(PB10); // Timer Definitions // Do not use timer used by PWM pins when possible. See PinMap_PWM. #define TIMER_TONE TIM3 @@ -128,30 +127,30 @@ extern "C" { #define MPU_ADDR 0x68; #define MPU_INT PB13; /* - * RC_CH1 T2C1 PA0 - * RC_CH2 T2C2 PA1 - * RC_CH3 T2C3/UA2_TX PA2 - * RC_CH4 T2C4/UA2_RX PA3 - * RC_CH5 T3C1 PA6 - * RC_CH6 T3C2 PA7 - * RC_CH7 T3C3 PB0 - * RC_CH8 T3C4 PB1 - * - * PWM1 T1C1 PA8 - * PMW2 T1C4 PA11 - * PMW3 T4C1 PB6 - * PMW4 T4C2 PB7 - * PMW5 T4C3 PB8 - * PMW6 T4C4 PB9 - * SONAR_INT PA15 - * GPIO_BOTTOM PB5 - * TELEM_OUT PA13 //warning, you loose SWD access when using this pin , bootloader via uart is required after + * RC_CH1 T2C1 PA0 + * RC_CH2 T2C2 PA1 + * RC_CH3 T2C3/UA2_TX PA2 + * RC_CH4 T2C4/UA2_RX PA3 + * RC_CH5 T3C1 PA6 + * RC_CH6 T3C2 PA7 + * RC_CH7 T3C3 PB0 + * RC_CH8 T3C4 PB1 + * + * PWM1 T1C1 PA8 + * PMW2 T1C4 PA11 + * PMW3 T4C1 PB6 + * PMW4 T4C2 PB7 + * PMW5 T4C3 PB8 + * PMW6 T4C4 PB9 + * SONAR_INT PA15 + * GPIO_BOTTOM PB5 + * TELEM_OUT PA13//warning, you loose SWD access when using this pin , bootloader via uart is required after * - * Power ADC ADC12_IN4 PA4 connected to 6 pin header Battery voltage in via resistor devider - * ACC_INT PA5 // Connected to Intterupt pin of MMA84520 accelerometer I2C + * BAT_ADC PA4 //Connected to 6 pin header Battery voltage in via resistor divider + * ACC_INT PA5 //Connected to Intterupt pin of MMA84520 accelerometer I2C * - * MAG_DRD PB12; //connected to HMC5883L compass I2C - * BEEP PA12; //connected to Beep out transistor on 6 pin header + * MAG_DRD PB12; //Connected to HMC5883L compass I2C + * BEEP PA12; //Connected to Beep out transistor on 6 pin header * */ From c839580ebe361b2912a61dbe7a4da32d1ac4b673 Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Thu, 22 Aug 2019 22:34:21 +0200 Subject: [PATCH 03/11] Update variants/AFROFLIGHT_F103CB/PeripheralPins.c Co-Authored-By: Frederic Pillon --- variants/AFROFLIGHT_F103CB/PeripheralPins.c | 1 - 1 file changed, 1 deletion(-) diff --git a/variants/AFROFLIGHT_F103CB/PeripheralPins.c b/variants/AFROFLIGHT_F103CB/PeripheralPins.c index 2cceb9c59e..f89f7e07c7 100644 --- a/variants/AFROFLIGHT_F103CB/PeripheralPins.c +++ b/variants/AFROFLIGHT_F103CB/PeripheralPins.c @@ -150,7 +150,6 @@ WEAK const PinMap PinMap_UART_TX[] = { {PA_2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_USART1_ENABLE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, #endif {NC, NP, 0} From 8dd0927825bf202612b86f69aa75ca8e97407ed7 Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Thu, 22 Aug 2019 22:34:37 +0200 Subject: [PATCH 04/11] Update variants/AFROFLIGHT_F103CB/PeripheralPins.c Co-Authored-By: Frederic Pillon --- variants/AFROFLIGHT_F103CB/PeripheralPins.c | 1 - 1 file changed, 1 deletion(-) diff --git a/variants/AFROFLIGHT_F103CB/PeripheralPins.c b/variants/AFROFLIGHT_F103CB/PeripheralPins.c index f89f7e07c7..7d3c6f140b 100644 --- a/variants/AFROFLIGHT_F103CB/PeripheralPins.c +++ b/variants/AFROFLIGHT_F103CB/PeripheralPins.c @@ -131,7 +131,6 @@ WEAK const PinMap PinMap_PWM[] = { {PB_7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 2, 0)}, // TIM4_CH2 {PB_8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 3, 0)}, // TIM4_CH3 {PB_9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 4, 0)}, // TIM4_CH4 -#endif // {PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_2, 3, 0)}, // TIM2_CH3 {PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_ENABLE, 3, 0)}, // TIM2_CH3 // {PB_11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_PARTIAL_2, 4, 0)}, // TIM2_CH4 From 4fe9f830f04a847997fc0655d934434b994d47e7 Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Thu, 22 Aug 2019 22:34:47 +0200 Subject: [PATCH 05/11] Update variants/AFROFLIGHT_F103CB/variant.cpp Co-Authored-By: Frederic Pillon --- variants/AFROFLIGHT_F103CB/variant.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/AFROFLIGHT_F103CB/variant.cpp b/variants/AFROFLIGHT_F103CB/variant.cpp index a44be179f7..30abde0fed 100644 --- a/variants/AFROFLIGHT_F103CB/variant.cpp +++ b/variants/AFROFLIGHT_F103CB/variant.cpp @@ -137,7 +137,7 @@ WEAK void SystemClock_Config(void) if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } -} +} #ifdef __cplusplus } #endif From 349d9370823c0f03711c6a61c10a543b321ff65e Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Thu, 22 Aug 2019 22:34:59 +0200 Subject: [PATCH 06/11] Update variants/AFROFLIGHT_F103CB/variant.h Co-Authored-By: Frederic Pillon --- variants/AFROFLIGHT_F103CB/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/AFROFLIGHT_F103CB/variant.h b/variants/AFROFLIGHT_F103CB/variant.h index da82a06dae..08fed88250 100644 --- a/variants/AFROFLIGHT_F103CB/variant.h +++ b/variants/AFROFLIGHT_F103CB/variant.h @@ -144,7 +144,7 @@ extern "C" { * PMW6 T4C4 PB9 * SONAR_INT PA15 * GPIO_BOTTOM PB5 - * TELEM_OUT PA13//warning, you loose SWD access when using this pin , bootloader via uart is required after + * TELEM_OUT PA13 // Warning, SWD access is lost when using this pin, bootloader via uart is required after * * BAT_ADC PA4 //Connected to 6 pin header Battery voltage in via resistor divider * ACC_INT PA5 //Connected to Intterupt pin of MMA84520 accelerometer I2C From 24ffd658e7a18daddf9420ab2d777a808defd51c Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Thu, 22 Aug 2019 22:35:11 +0200 Subject: [PATCH 07/11] Update variants/AFROFLIGHT_F103CB/variant.h Co-Authored-By: Frederic Pillon --- variants/AFROFLIGHT_F103CB/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/AFROFLIGHT_F103CB/variant.h b/variants/AFROFLIGHT_F103CB/variant.h index 08fed88250..c5733d8290 100644 --- a/variants/AFROFLIGHT_F103CB/variant.h +++ b/variants/AFROFLIGHT_F103CB/variant.h @@ -146,7 +146,7 @@ extern "C" { * GPIO_BOTTOM PB5 * TELEM_OUT PA13 // Warning, SWD access is lost when using this pin, bootloader via uart is required after * - * BAT_ADC PA4 //Connected to 6 pin header Battery voltage in via resistor divider + * BAT_ADC PA4 // Connected to 6 pin header Battery voltage in via resistor divider * ACC_INT PA5 //Connected to Intterupt pin of MMA84520 accelerometer I2C * * MAG_DRD PB12; //Connected to HMC5883L compass I2C From 9905fd72c506a9c5e64eb0c956df02158cbdff86 Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Thu, 22 Aug 2019 22:35:19 +0200 Subject: [PATCH 08/11] Update variants/AFROFLIGHT_F103CB/variant.h Co-Authored-By: Frederic Pillon --- variants/AFROFLIGHT_F103CB/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/AFROFLIGHT_F103CB/variant.h b/variants/AFROFLIGHT_F103CB/variant.h index c5733d8290..ed68c84064 100644 --- a/variants/AFROFLIGHT_F103CB/variant.h +++ b/variants/AFROFLIGHT_F103CB/variant.h @@ -148,7 +148,7 @@ extern "C" { * * BAT_ADC PA4 // Connected to 6 pin header Battery voltage in via resistor divider * ACC_INT PA5 //Connected to Intterupt pin of MMA84520 accelerometer I2C - * + * * MAG_DRD PB12; //Connected to HMC5883L compass I2C * BEEP PA12; //Connected to Beep out transistor on 6 pin header * From d700d4c90df994a3125968610c45f51569626e16 Mon Sep 17 00:00:00 2001 From: darkspr1te Date: Thu, 22 Aug 2019 22:35:27 +0200 Subject: [PATCH 09/11] Update variants/AFROFLIGHT_F103CB/variant.h Co-Authored-By: Frederic Pillon --- variants/AFROFLIGHT_F103CB/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/AFROFLIGHT_F103CB/variant.h b/variants/AFROFLIGHT_F103CB/variant.h index ed68c84064..4eb69af993 100644 --- a/variants/AFROFLIGHT_F103CB/variant.h +++ b/variants/AFROFLIGHT_F103CB/variant.h @@ -151,7 +151,7 @@ extern "C" { * * MAG_DRD PB12; //Connected to HMC5883L compass I2C * BEEP PA12; //Connected to Beep out transistor on 6 pin header - * + * */ #ifdef __cplusplus From 66b821bae2d02772a4bc5403d90b9938a60152ad Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 23 Aug 2019 09:59:31 +0200 Subject: [PATCH 10/11] Clean up Signed-off-by: Frederic.Pillon --- boards.txt | 6 -- variants/AFROFLIGHT_F103CB/PeripheralPins.c | 20 ----- variants/AFROFLIGHT_F103CB/variant.cpp | 25 ++---- variants/AFROFLIGHT_F103CB/variant.h | 89 +++++++++------------ 4 files changed, 43 insertions(+), 97 deletions(-) diff --git a/boards.txt b/boards.txt index c2600249f9..7c4bdb1a9f 100644 --- a/boards.txt +++ b/boards.txt @@ -1108,7 +1108,6 @@ RAK.menu.upload_method.dfuMethod.upload.tool=stm32CubeProg Genericflight.name=Generic flight controllers - Genericflight.build.vid=0x0483 Genericflight.build.core=arduino Genericflight.build.board=Genericflight @@ -1117,8 +1116,6 @@ Genericflight.build.series=STM32F1xx Genericflight.build.cmsis_lib_gcc=arm_cortexM3l_math Genericflight.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} {build.bootloader_flags} - - # AfroFlight Rev5 Genericflight.menu.pnum.AFROFLIGHT_F103CB=Afro Flight Rev5 Genericflight.menu.pnum.AFROFLIGHT_F103CB.upload.maximum_size=131072 @@ -1128,10 +1125,7 @@ Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.series=STM32F1xx Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.product_line=STM32F103xB Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.variant=AFROFLIGHT_F103CB - - # Upload menu - Genericflight.menu.upload_method.swdMethod=STM32CubeProgrammer (SWD) Genericflight.menu.upload_method.swdMethod.upload.protocol=0 Genericflight.menu.upload_method.swdMethod.upload.options=-g diff --git a/variants/AFROFLIGHT_F103CB/PeripheralPins.c b/variants/AFROFLIGHT_F103CB/PeripheralPins.c index 7d3c6f140b..2d554ce6c7 100644 --- a/variants/AFROFLIGHT_F103CB/PeripheralPins.c +++ b/variants/AFROFLIGHT_F103CB/PeripheralPins.c @@ -73,9 +73,7 @@ WEAK const PinMap PinMap_ADC[] = { WEAK const PinMap PinMap_I2C_SDA[] = { {PB_7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE)}, {PB_9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_I2C1_ENABLE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE)}, -#endif {NC, NP, 0} }; #endif @@ -84,9 +82,7 @@ WEAK const PinMap PinMap_I2C_SDA[] = { WEAK const PinMap PinMap_I2C_SCL[] = { {PB_6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE)}, {PB_8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_I2C1_ENABLE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE)}, -#endif {NC, NP, 0} }; #endif @@ -126,7 +122,6 @@ WEAK const PinMap PinMap_PWM[] = { {PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM2_ENABLE, 2, 0)}, // TIM2_CH2 {PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM3_PARTIAL, 1, 0)}, // TIM3_CH1 {PB_5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_TIM3_PARTIAL, 2, 0)}, // TIM3_CH2 -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 1, 0)}, // TIM4_CH1 {PB_7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 2, 0)}, // TIM4_CH2 {PB_8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE, 3, 0)}, // TIM4_CH3 @@ -150,7 +145,6 @@ WEAK const PinMap PinMap_UART_TX[] = { {PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_USART1_ENABLE)}, {PB_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, -#endif {NC, NP, 0} }; #endif @@ -160,9 +154,7 @@ WEAK const PinMap PinMap_UART_RX[] = { {PA_3, USART2, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_NONE)}, {PA_10, USART1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_NONE)}, {PB_7, USART1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_USART1_ENABLE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_11, USART3, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, AFIO_NONE)}, -#endif {NC, NP, 0} }; #endif @@ -171,10 +163,8 @@ WEAK const PinMap PinMap_UART_RX[] = { WEAK const PinMap PinMap_UART_RTS[] = { {PA_1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PA_12, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, // {PB_14, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_USART3_PARTIAL)}, -#endif {NC, NP, 0} }; #endif @@ -183,10 +173,8 @@ WEAK const PinMap PinMap_UART_RTS[] = { WEAK const PinMap PinMap_UART_CTS[] = { {PA_0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PA_11, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, // {PB_13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_USART3_PARTIAL)}, -#endif {NC, NP, 0} }; #endif @@ -197,9 +185,7 @@ WEAK const PinMap PinMap_UART_CTS[] = { WEAK const PinMap PinMap_SPI_MOSI[] = { {PA_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_SPI1_ENABLE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, -#endif {NC, NP, 0} }; #endif @@ -208,9 +194,7 @@ WEAK const PinMap PinMap_SPI_MOSI[] = { WEAK const PinMap PinMap_SPI_MISO[] = { {PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_SPI1_ENABLE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, -#endif {NC, NP, 0} }; #endif @@ -219,9 +203,7 @@ WEAK const PinMap PinMap_SPI_MISO[] = { WEAK const PinMap PinMap_SPI_SCLK[] = { {PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_SPI1_ENABLE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, -#endif {NC, NP, 0} }; #endif @@ -230,9 +212,7 @@ WEAK const PinMap PinMap_SPI_SCLK[] = { WEAK const PinMap PinMap_SPI_SSEL[] = { {PA_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, {PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_SPI1_ENABLE)}, -#ifndef ARDUINO_BLUEPILL_F103C6 {PB_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)}, -#endif {NC, NP, 0} }; #endif diff --git a/variants/AFROFLIGHT_F103CB/variant.cpp b/variants/AFROFLIGHT_F103CB/variant.cpp index 30abde0fed..c5ccb9e3fb 100644 --- a/variants/AFROFLIGHT_F103CB/variant.cpp +++ b/variants/AFROFLIGHT_F103CB/variant.cpp @@ -35,8 +35,6 @@ extern "C" { // Pin number const PinName digitalPin[] = { - /* USB connector on the top, MCU side */ - /* Left Side */ PB_9, //D0 PB_8, //D1 PB_7, //D2 @@ -45,17 +43,16 @@ const PinName digitalPin[] = { PB_4, //D5 PB_3, //D6 PA_15, //D7 - PA_12, //D8 - USB DP - PA_11, //D9 - USB DM + PA_12, //D8 + PA_11, //D9 PA_10, //D10 PA_9, //D11 PA_8, //D12 PB_15, //D13 PB_14, //D14 PB_13, //D15 - PB_12, //D16 - LED Blackpill - /* Right side */ - PC_13, //D17 - LED Bluepill + PB_12, //D16 + PC_13, //D17 PC_14, //D18 PC_15, //D19 PA_0, //D20/A0 @@ -87,24 +84,12 @@ extern "C" { /** * @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) { -//Board has 12mhz xtal, iám currenlty using HSI internal xtal , i've not figured settings for external 12mhz + // Board has external 12MHz Xtal, currenlty using HSI internal Xtal RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; diff --git a/variants/AFROFLIGHT_F103CB/variant.h b/variants/AFROFLIGHT_F103CB/variant.h index 4eb69af993..92cd63bc0e 100644 --- a/variants/AFROFLIGHT_F103CB/variant.h +++ b/variants/AFROFLIGHT_F103CB/variant.h @@ -38,27 +38,24 @@ extern "C" { * Pins *----------------------------------------------------------------------------*/ -// Bluepill USB connector on the top, MCU side - Blackpill USB connector on bottom, MCU Side (pins are reversed vertically for Arduino Ananlog pin correct sequence. -// Left Side #define PB9 0 #define PB8 1 #define PB7 2 #define PB6 3 #define PB5 4 -#define PB4 5 -#define PB3 6 +#define PB4 5 // LED0 +#define PB3 6 // LED1 #define PA15 7 -#define PA12 8 // USB DP -#define PA11 9 // USB DM +#define PA12 8 +#define PA11 9 #define PA10 10 #define PA9 11 #define PA8 12 #define PB15 13 #define PB14 14 #define PB13 15 -#define PB12 16 // LED Blackpill -// Right side -#define PC13 17 // LED Bluepill +#define PB12 16 +#define PC13 17 #define PC14 18 #define PC15 19 #define PA0 20 // A0 @@ -85,14 +82,10 @@ extern "C" { #define NUM_ANALOG_FIRST 20 // On-board LED pin number -#ifdef ARDUINO_BLUEPILL_F103C8 -#define LED_BUILTIN PC13 -#else -#define LED_BUILTIN PB4 -#endif -#define LED_GREEN PB3 -#define LED_RED LED_BUILTIN +#define LED0 PB4 +#define LED1 PB3 +#define LED_BUILTIN LED0 // SPI Definitions #define PIN_SPI_SS PA4 @@ -101,19 +94,13 @@ extern "C" { #define PIN_SPI_SCK PA5 // I2C Definitions -//#define PIN_WIRE_SDA PB7 -//#define PIN_WIRE_SCL PB6 //On afroflight Rev 5 it's on i2c port 2 that MPU6050 is connected too -#define PIN_WIRE_SDA PB11 -#define PIN_WIRE_SCL PB10 - +#define PIN_WIRE_SDA PB11 +#define PIN_WIRE_SCL PB10 // Timer Definitions -// Do not use timer used by PWM pins when possible. See PinMap_PWM. #define TIMER_TONE TIM3 - -// Do not use basic timer: OC is required -#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work +#define TIMER_SERVO TIM2 // UART Definitions #define SERIAL_UART_INSTANCE 1 @@ -122,38 +109,38 @@ extern "C" { #define PIN_SERIAL_RX PA10 #define PIN_SERIAL_TX PA9 -#define MPU_I2C_SDA PB11; -#define MPU_I2C_SCL PB10; -#define MPU_ADDR 0x68; -#define MPU_INT PB13; +#define MPU_I2C_SDA PB11 +#define MPU_I2C_SCL PB10 +#define MPU_ADDR 0x68 +#define MPU_INT PB13 /* - * RC_CH1 T2C1 PA0 - * RC_CH2 T2C2 PA1 - * RC_CH3 T2C3/UA2_TX PA2 - * RC_CH4 T2C4/UA2_RX PA3 - * RC_CH5 T3C1 PA6 - * RC_CH6 T3C2 PA7 - * RC_CH7 T3C3 PB0 - * RC_CH8 T3C4 PB1 + * RC_CH1 T2C1 PA0 + * RC_CH2 T2C2 PA1 + * RC_CH3 T2C3/UA2_TX PA2 + * RC_CH4 T2C4/UA2_RX PA3 + * RC_CH5 T3C1 PA6 + * RC_CH6 T3C2 PA7 + * RC_CH7 T3C3 PB0 + * RC_CH8 T3C4 PB1 * - * PWM1 T1C1 PA8 - * PMW2 T1C4 PA11 - * PMW3 T4C1 PB6 - * PMW4 T4C2 PB7 - * PMW5 T4C3 PB8 - * PMW6 T4C4 PB9 - * SONAR_INT PA15 - * GPIO_BOTTOM PB5 - * TELEM_OUT PA13 // Warning, SWD access is lost when using this pin, bootloader via uart is required after + * PWM1 T1C1 PA8 + * PMW2 T1C4 PA11 + * PMW3 T4C1 PB6 + * PMW4 T4C2 PB7 + * PMW5 T4C3 PB8 + * PMW6 T4C4 PB9 + * SONAR_INT PA15 + * GPIO_BOTTOM PB5 + * TELEM_OUT PA13 // Warning, SWD access is lost when using this pin, bootloader via uart is required after * - * BAT_ADC PA4 // Connected to 6 pin header Battery voltage in via resistor divider - * ACC_INT PA5 //Connected to Intterupt pin of MMA84520 accelerometer I2C + * BAT_ADC PA4 // Connected to 6 pin header Battery voltage in via resistor divider + * ACC_INT PA5 // Connected to Intterupt pin of MMA84520 accelerometer I2C * - * MAG_DRD PB12; //Connected to HMC5883L compass I2C - * BEEP PA12; //Connected to Beep out transistor on 6 pin header + * MAG_DRD PB12 //Connected to HMC5883L compass I2C + * BEEP PA12 //Connected to Beep out transistor on 6 pin header * */ - + #ifdef __cplusplus } // extern "C" #endif From b80381b3058bcee803fd6c71c3cf02a5b9008b14 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Mon, 26 Aug 2019 11:05:02 +0200 Subject: [PATCH 11/11] Handle 8 and 12 MHz HSE values Signed-off-by: Frederic.Pillon --- boards.txt | 10 +++++++-- variants/AFROFLIGHT_F103CB/variant.cpp | 30 ++++++++++++++------------ variants/AFROFLIGHT_F103CB/variant.h | 4 ++++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/boards.txt b/boards.txt index 7c4bdb1a9f..19faa5e8c4 100644 --- a/boards.txt +++ b/boards.txt @@ -1117,14 +1117,20 @@ Genericflight.build.cmsis_lib_gcc=arm_cortexM3l_math Genericflight.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} {build.bootloader_flags} # AfroFlight Rev5 -Genericflight.menu.pnum.AFROFLIGHT_F103CB=Afro Flight Rev5 +Genericflight.menu.pnum.AFROFLIGHT_F103CB=Afro Flight Rev5 (8MHz) Genericflight.menu.pnum.AFROFLIGHT_F103CB.upload.maximum_size=131072 Genericflight.menu.pnum.AFROFLIGHT_F103CB.upload.maximum_data_size=20480 Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.board=AFROFLIGHT_F103CB -Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.series=STM32F1xx Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.product_line=STM32F103xB Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.variant=AFROFLIGHT_F103CB +Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M=Afro Flight Rev5 (12MHz) +Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.upload.maximum_size=131072 +Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.upload.maximum_data_size=20480 +Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.build.board=AFROFLIGHT_F103CB_12M +Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.build.product_line=STM32F103xB +Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.build.variant=AFROFLIGHT_F103CB + # Upload menu Genericflight.menu.upload_method.swdMethod=STM32CubeProgrammer (SWD) Genericflight.menu.upload_method.swdMethod.upload.protocol=0 diff --git a/variants/AFROFLIGHT_F103CB/variant.cpp b/variants/AFROFLIGHT_F103CB/variant.cpp index c5ccb9e3fb..12aa21bd93 100644 --- a/variants/AFROFLIGHT_F103CB/variant.cpp +++ b/variants/AFROFLIGHT_F103CB/variant.cpp @@ -89,25 +89,28 @@ extern "C" { */ WEAK void SystemClock_Config(void) { - // Board has external 12MHz Xtal, currenlty using HSI internal Xtal - RCC_OscInitTypeDef RCC_OscInitStruct; - RCC_ClkInitTypeDef RCC_ClkInitStruct; - RCC_PeriphCLKInitTypeDef PeriphClkInit; + RCC_OscInitTypeDef RCC_OscInitStruct = {}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {}; /* Initializes the CPU, AHB and APB busses clocks */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = 16; 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; +#ifdef ARDUINO_AFROFLIGHT_F103CB_12M + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; +#else /* 8 MHz */ + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; +#endif if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } - /* Initializes the CPU, AHB and APB busses clocks */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK - | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.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; @@ -116,9 +119,8 @@ WEAK void SystemClock_Config(void) if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } - - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; - PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } diff --git a/variants/AFROFLIGHT_F103CB/variant.h b/variants/AFROFLIGHT_F103CB/variant.h index 92cd63bc0e..fd47503575 100644 --- a/variants/AFROFLIGHT_F103CB/variant.h +++ b/variants/AFROFLIGHT_F103CB/variant.h @@ -141,6 +141,10 @@ extern "C" { * */ +#ifdef ARDUINO_AFROFLIGHT_F103CB_12M +#define HSE_VALUE 12000000U /*!< Value of the External oscillator in Hz */ +#endif + #ifdef __cplusplus } // extern "C" #endif