diff --git a/firmware/boards/f1_dual_rev1/openblt/Makefile b/firmware/boards/f1_dual_rev1/openblt/Makefile new file mode 100644 index 0000000..0dc436a --- /dev/null +++ b/firmware/boards/f1_dual_rev1/openblt/Makefile @@ -0,0 +1,3 @@ +BOARD?=f1_dual_rev1 + +include ../../f1_common/openblt/Makefile diff --git a/firmware/boards/f1_dual_rev1/openblt/blt_conf.h b/firmware/boards/f1_dual_rev1/openblt/blt_conf.h new file mode 100644 index 0000000..b1e0232 --- /dev/null +++ b/firmware/boards/f1_dual_rev1/openblt/blt_conf.h @@ -0,0 +1,166 @@ +#ifndef BLT_CONF_H +#define BLT_CONF_H + +/**************************************************************************************** +* C P U D R I V E R C O N F I G U R A T I O N +****************************************************************************************/ +/* To properly initialize the baudrate clocks of the communication interface, typically + * the speed of the crystal oscillator and/or the speed at which the system runs is + * needed. Set these through configurables BOOT_CPU_XTAL_SPEED_KHZ and + * BOOT_CPU_SYSTEM_SPEED_KHZ, respectively. To enable data exchange with the host that is + * not dependent on the targets architecture, the byte ordering needs to be known. + * Setting BOOT_CPU_BYTE_ORDER_MOTOROLA to 1 selects big endian mode and 0 selects + * little endian mode. + * + * Set BOOT_CPU_USER_PROGRAM_START_HOOK to 1 if you would like a hook function to be + * called the moment the user program is about to be started. This could be used to + * de-initialize application specific parts, for example to stop blinking an LED, etc. + */ +/** \brief Frequency of the external crystal oscillator. */ +#define BOOT_CPU_XTAL_SPEED_KHZ (8000) +/** \brief Desired system speed. */ +#define BOOT_CPU_SYSTEM_SPEED_KHZ (48000) +/** \brief Motorola or Intel style byte ordering. */ +#define BOOT_CPU_BYTE_ORDER_MOTOROLA (0) +/** \brief Enable/disable hook function call right before user program start. */ +#define BOOT_CPU_USER_PROGRAM_START_HOOK (0) + + +/**************************************************************************************** +* C O M M U N I C A T I O N I N T E R F A C E C O N F I G U R A T I O N +****************************************************************************************/ +/* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE + * configurable to 1. Configurable BOOT_COM_CAN_BAUDRATE selects the communication speed + * in bits/second. Two CAN messages are reserved for communication with the host. The + * message identifier for sending data from the target to the host is configured with + * BOOT_COM_CAN_TXMSG_ID. The one for receiving data from the host is configured with + * BOOT_COM_CAN_RXMSG_ID. Note that an extended 29-bit CAN identifier is configured by + * OR-ing with mask 0x80000000. The maximum amount of data bytes in a message for data + * transmission and reception is set through BOOT_COM_CAN_TX_MAX_DATA and + * BOOT_COM_CAN_RX_MAX_DATA, respectively. It is common for a microcontroller to have more + * than 1 CAN controller on board. The zero-based BOOT_COM_CAN_CHANNEL_INDEX selects the + * CAN controller channel. + * + */ +/** \brief Enable/disable CAN transport layer. */ +#define BOOT_COM_CAN_ENABLE (1) +/** \brief Configure the desired CAN baudrate. */ +#define BOOT_COM_CAN_BAUDRATE (500000) +/** \brief Configure CAN message ID target->host. */ +#define BOOT_COM_CAN_TX_MSG_ID (0x7E1 /*| 0x80000000*/) +/** \brief Configure number of bytes in the target->host CAN message. */ +#define BOOT_COM_CAN_TX_MAX_DATA (8) +/** \brief Configure CAN message ID host->target. */ +#define BOOT_COM_CAN_RX_MSG_ID (0x667 /*| 0x80000000*/) +/** \brief Configure number of bytes in the host->target CAN message. */ +#define BOOT_COM_CAN_RX_MAX_DATA (8) +/** \brief Select the desired CAN peripheral as a zero based index. */ +#define BOOT_COM_CAN_CHANNEL_INDEX (0) + +/* The RS232 communication interface is selected by setting the BOOT_COM_RS232_ENABLE + * configurable to 1. Configurable BOOT_COM_RS232_BAUDRATE selects the communication speed + * in bits/second. The maximum amount of data bytes in a message for data transmission + * and reception is set through BOOT_COM_RS232_TX_MAX_DATA and BOOT_COM_RS232_RX_MAX_DATA, + * respectively. It is common for a microcontroller to have more than 1 UART interface + * on board. The zero-based BOOT_COM_RS232_CHANNEL_INDEX selects the UART interface. + * + */ +/** \brief Enable/disable UART transport layer. */ +#define BOOT_COM_RS232_ENABLE (1) +/** \brief Configure the desired communication speed. */ +#define BOOT_COM_RS232_BAUDRATE (115200) +/** \brief Configure number of bytes in the target->host data packet. */ +#define BOOT_COM_RS232_TX_MAX_DATA (64) +/** \brief Configure number of bytes in the host->target data packet. */ +#define BOOT_COM_RS232_RX_MAX_DATA (64) +/** \brief Select the desired UART peripheral as a zero based index. */ +#define BOOT_COM_RS232_CHANNEL_INDEX (0) + + +/**************************************************************************************** +* B A C K D O O R E N T R Y C O N F I G U R A T I O N +****************************************************************************************/ +/* It is possible to implement an application specific method to force the bootloader to + * stay active after a reset. Such a backdoor entry into the bootloader is desired in + * situations where the user program does not run properly and therefore cannot + * reactivate the bootloader. By enabling these hook functions, the application can + * implement the backdoor, which overrides the default backdoor entry that is programmed + * into the bootloader. When desired for security purposes, these hook functions can + * also be implemented in a way that disables the backdoor entry altogether. + */ +/** \brief Enable/disable the backdoor override hook functions. */ +#define BOOT_BACKDOOR_HOOKS_ENABLE (0) + + +/**************************************************************************************** +* N O N - V O L A T I L E M E M O R Y D R I V E R C O N F I G U R A T I O N +****************************************************************************************/ +/* The NVM driver typically supports erase and program operations of the internal memory + * present on the microcontroller. Through these hook functions the NVM driver can be + * extended to support additional memory types such as external flash memory and serial + * eeproms. The size of the internal memory in kilobytes is specified with configurable + * BOOT_NVM_SIZE_KB. If desired the internal checksum writing and verification method can + * be overridden with a application specific method by enabling configuration switch + * BOOT_NVM_CHECKSUM_HOOKS_ENABLE. + */ +/** \brief Enable/disable the NVM hook function for supporting additional memory devices. */ +#define BOOT_NVM_HOOKS_ENABLE (0) +/** \brief Configure the size of the default memory device (typically flash EEPROM). */ +#define BOOT_NVM_SIZE_KB (256) +/** \brief Enable/disable hooks functions to override the user program checksum handling. */ +#define BOOT_NVM_CHECKSUM_HOOKS_ENABLE (0) + + +/**************************************************************************************** +* F L A S H M E M O R Y D R I V E R C O N F I G U R A T I O N +****************************************************************************************/ +/** \brief This microcontroller has a smaller vector table then the default STM32F1xx + * project as assumed in the bootloader's core. This means the user program has + * a different checksum location, because this one is added at the end of the + * user program's vector table. + */ +#define BOOT_FLASH_VECTOR_TABLE_CS_OFFSET (0x1c) +/** \brief Enable support for a custom flash layout table. It is located in + * flash_layout.c. This was done because the default flashLayout[] table + * in the bootloader's core has more flash memory reserved for the bootloader + * than is needed for this demo. + */ +#define BOOT_FLASH_CUSTOM_LAYOUT_ENABLE (1) + + +/**************************************************************************************** +* W A T C H D O G D R I V E R C O N F I G U R A T I O N +****************************************************************************************/ +/* The COP driver cannot be configured internally in the bootloader, because its use + * and configuration is application specific. The bootloader does need to service the + * watchdog in case it is used. When the application requires the use of a watchdog, + * set BOOT_COP_HOOKS_ENABLE to be able to initialize and service the watchdog through + * hook functions. + */ +/** \brief Enable/disable the hook functions for controlling the watchdog. */ +#define BOOT_COP_HOOKS_ENABLE (1) + + +/**************************************************************************************** +* S E E D / K E Y S E C U R I T Y C O N F I G U R A T I O N +****************************************************************************************/ +/* A security mechanism can be enabled in the bootloader's XCP module by setting configu- + * rable BOOT_XCP_SEED_KEY_ENABLE to 1. Before any memory erase or programming + * operations can be performed, access to this resource need to be unlocked. + * In the Microboot settings on tab "XCP Protection" you need to specify a DLL that + * implements the unlocking algorithm. The demo programs are configured for the (simple) + * algorithm in "libseednkey.dll". The source code for this DLL is available so it can be + * customized to your needs. + * During the unlock sequence, Microboot requests a seed from the bootloader, which is in + * the format of a byte array. Using this seed the unlock algorithm in the DLL computes + * a key, which is also a byte array, and sends this back to the bootloader. The + * bootloader then verifies this key to determine if programming and erase operations are + * permitted. + * After enabling this feature the hook functions XcpGetSeedHook() and XcpVerifyKeyHook() + * are called by the bootloader to obtain the seed and to verify the key, respectively. + */ +#define BOOT_XCP_SEED_KEY_ENABLE (0) + + +#endif /* BLT_CONF_H */ +/*********************************** end of blt_conf.h *********************************/ diff --git a/firmware/boards/f1_dual_rev1/openblt/flash_layout.c b/firmware/boards/f1_dual_rev1/openblt/flash_layout.c new file mode 100644 index 0000000..efc1af7 --- /dev/null +++ b/firmware/boards/f1_dual_rev1/openblt/flash_layout.c @@ -0,0 +1,156 @@ +/** \brief Array wit the layout of the flash memory. + * \details Also controls what part of the flash memory is reserved for the bootloader. + * If the bootloader size changes, the reserved sectors for the bootloader + * might need adjustment to make sure the bootloader doesn't get overwritten. + */ + +/* STM32F103RCT6 - high-density device with 256 Kb of flash = 128 pages of 2Kb */ +static const tFlashSector flashLayout[] = +{ + /* space is reserved for a bootloader configuration with all supported communication + * interfaces enabled. when for example only UART is needed, than the space required + * for the bootloader can be made a lot smaller here. + */ + /* { 0x08000000, 0x00800 }, flash sector 0 - reserved for bootloader */ + /* { 0x08000800, 0x00800 }, flash sector 1 - reserved for bootloader */ + /* { 0x08001000, 0x00800 }, flash sector 2 - reserved for bootloader */ + /* { 0x08001800, 0x00800 }, flash sector 3 - reserved for bootloader */ + { 0x08002000, 0x00800 }, /* flash sector 4 - 2kb */ + { 0x08002800, 0x00800 }, /* flash sector 5 - 2kb */ + { 0x08003000, 0x00800 }, /* flash sector 6 - 2kb */ + { 0x08003800, 0x00800 }, /* flash sector 7 - 2kb */ +#if (BOOT_NVM_SIZE_KB > 16) + { 0x08004000, 0x00800 }, /* flash sector 8 - 2kb */ + { 0x08004800, 0x00800 }, /* flash sector 9 - 2kb */ + { 0x08005000, 0x00800 }, /* flash sector 10 - 2kb */ + { 0x08005800, 0x00800 }, /* flash sector 11 - 2kb */ + { 0x08006000, 0x00800 }, /* flash sector 12 - 2kb */ + { 0x08006800, 0x00800 }, /* flash sector 13 - 2kb */ + { 0x08007000, 0x00800 }, /* flash sector 14 - 2kb */ + { 0x08007800, 0x00800 }, /* flash sector 15 - 2kb */ +#endif +#if (BOOT_NVM_SIZE_KB > 32) + { 0x08008000, 0x00800 }, /* flash sector 16 - 2kb */ + { 0x08008800, 0x00800 }, /* flash sector 17 - 2kb */ + { 0x08009000, 0x00800 }, /* flash sector 18 - 2kb */ + { 0x08009800, 0x00800 }, /* flash sector 19 - 2kb */ + { 0x0800a000, 0x00800 }, /* flash sector 20 - 2kb */ + { 0x0800a800, 0x00800 }, /* flash sector 21 - 2kb */ + { 0x0800b000, 0x00800 }, /* flash sector 22 - 2kb */ + { 0x0800b800, 0x00800 }, /* flash sector 23 - 2kb */ + { 0x0800c000, 0x00800 }, /* flash sector 24 - 2kb */ + { 0x0800c800, 0x00800 }, /* flash sector 25 - 2kb */ + { 0x0800d000, 0x00800 }, /* flash sector 26 - 2kb */ + { 0x0800d800, 0x00800 }, /* flash sector 27 - 2kb */ + { 0x0800e000, 0x00800 }, /* flash sector 28 - 2kb */ + { 0x0800e800, 0x00800 }, /* flash sector 29 - 2kb */ + { 0x0800f000, 0x00800 }, /* flash sector 30 - 2kb */ + { 0x0800f800, 0x00800 }, /* flash sector 31 - 2kb */ +#endif +#if (BOOT_NVM_SIZE_KB > 64) + { 0x08010000, 0x00800 }, /* flash sector 32 - 2kb */ + { 0x08010800, 0x00800 }, /* flash sector 33 - 2kb */ + { 0x08011000, 0x00800 }, /* flash sector 34 - 2kb */ + { 0x08011800, 0x00800 }, /* flash sector 35 - 2kb */ + { 0x08012000, 0x00800 }, /* flash sector 36 - 2kb */ + { 0x08012800, 0x00800 }, /* flash sector 37 - 2kb */ + { 0x08013000, 0x00800 }, /* flash sector 38 - 2kb */ + { 0x08013800, 0x00800 }, /* flash sector 39 - 2kb */ + { 0x08014000, 0x00800 }, /* flash sector 40 - 2kb */ + { 0x08014800, 0x00800 }, /* flash sector 41 - 2kb */ + { 0x08015000, 0x00800 }, /* flash sector 42 - 2kb */ + { 0x08015800, 0x00800 }, /* flash sector 43 - 2kb */ + { 0x08016000, 0x00800 }, /* flash sector 44 - 2kb */ + { 0x08016800, 0x00800 }, /* flash sector 45 - 2kb */ + { 0x08017000, 0x00800 }, /* flash sector 46 - 2kb */ + { 0x08017800, 0x00800 }, /* flash sector 47 - 2kb */ + { 0x08018000, 0x00800 }, /* flash sector 48 - 2kb */ + { 0x08018800, 0x00800 }, /* flash sector 49 - 2kb */ + { 0x08019000, 0x00800 }, /* flash sector 50 - 2kb */ + { 0x08019800, 0x00800 }, /* flash sector 51 - 2kb */ + { 0x0801a000, 0x00800 }, /* flash sector 52 - 2kb */ + { 0x0801a800, 0x00800 }, /* flash sector 53 - 2kb */ + { 0x0801b000, 0x00800 }, /* flash sector 54 - 2kb */ + { 0x0801b800, 0x00800 }, /* flash sector 55 - 2kb */ + { 0x0801c000, 0x00800 }, /* flash sector 56 - 2kb */ + { 0x0801c800, 0x00800 }, /* flash sector 57 - 2kb */ + { 0x0801d000, 0x00800 }, /* flash sector 58 - 2kb */ + { 0x0801d800, 0x00800 }, /* flash sector 59 - 2kb */ + { 0x0801e000, 0x00800 }, /* flash sector 60 - 2kb */ + { 0x0801e800, 0x00800 }, /* flash sector 61 - 2kb */ + { 0x0801f000, 0x00800 }, /* flash sector 62 - 2kb */ + { 0x0801f800, 0x00800 }, /* flash sector 63 - 2kb */ +#endif +#if (BOOT_NVM_SIZE_KB > 128) + { 0x08020000, 0x00800 }, /* flash sector 64 - 2kb */ + { 0x08020800, 0x00800 }, /* flash sector 65 - 2kb */ + { 0x08021000, 0x00800 }, /* flash sector 66 - 2kb */ + { 0x08021800, 0x00800 }, /* flash sector 67 - 2kb */ + { 0x08022000, 0x00800 }, /* flash sector 68 - 2kb */ + { 0x08022800, 0x00800 }, /* flash sector 69 - 2kb */ + { 0x08023000, 0x00800 }, /* flash sector 70 - 2kb */ + { 0x08023800, 0x00800 }, /* flash sector 71 - 2kb */ + { 0x08024000, 0x00800 }, /* flash sector 72 - 2kb */ + { 0x08024800, 0x00800 }, /* flash sector 73 - 2kb */ + { 0x08025000, 0x00800 }, /* flash sector 74 - 2kb */ + { 0x08025800, 0x00800 }, /* flash sector 75 - 2kb */ + { 0x08026000, 0x00800 }, /* flash sector 76 - 2kb */ + { 0x08026800, 0x00800 }, /* flash sector 77 - 2kb */ + { 0x08027000, 0x00800 }, /* flash sector 78 - 2kb */ + { 0x08027800, 0x00800 }, /* flash sector 79 - 2kb */ + { 0x08028000, 0x00800 }, /* flash sector 80 - 2kb */ + { 0x08028800, 0x00800 }, /* flash sector 81 - 2kb */ + { 0x08029000, 0x00800 }, /* flash sector 82 - 2kb */ + { 0x08029800, 0x00800 }, /* flash sector 83 - 2kb */ + { 0x0802a000, 0x00800 }, /* flash sector 84 - 2kb */ + { 0x0802a800, 0x00800 }, /* flash sector 85 - 2kb */ + { 0x0802b000, 0x00800 }, /* flash sector 86 - 2kb */ + { 0x0802b800, 0x00800 }, /* flash sector 87 - 2kb */ + { 0x0802c000, 0x00800 }, /* flash sector 88 - 2kb */ + { 0x0802c800, 0x00800 }, /* flash sector 89 - 2kb */ + { 0x0802d000, 0x00800 }, /* flash sector 90 - 2kb */ + { 0x0802d800, 0x00800 }, /* flash sector 91 - 2kb */ + { 0x0802e000, 0x00800 }, /* flash sector 92 - 2kb */ + { 0x0802e800, 0x00800 }, /* flash sector 93 - 2kb */ + { 0x0802f000, 0x00800 }, /* flash sector 94 - 2kb */ + { 0x0802f800, 0x00800 }, /* flash sector 95 - 2kb */ + { 0x08030000, 0x00800 }, /* flash sector 96 - 2kb */ + { 0x08030800, 0x00800 }, /* flash sector 97 - 2kb */ + { 0x08031000, 0x00800 }, /* flash sector 98 - 2kb */ + { 0x08031800, 0x00800 }, /* flash sector 99 - 2kb */ + { 0x08032000, 0x00800 }, /* flash sector 100 - 2kb */ + { 0x08032800, 0x00800 }, /* flash sector 101 - 2kb */ + { 0x08033000, 0x00800 }, /* flash sector 102 - 2kb */ + { 0x08033800, 0x00800 }, /* flash sector 103 - 2kb */ + { 0x08034000, 0x00800 }, /* flash sector 104 - 2kb */ + { 0x08034800, 0x00800 }, /* flash sector 105 - 2kb */ + { 0x08035000, 0x00800 }, /* flash sector 106 - 2kb */ + { 0x08035800, 0x00800 }, /* flash sector 107 - 2kb */ + { 0x08036000, 0x00800 }, /* flash sector 108 - 2kb */ + { 0x08036800, 0x00800 }, /* flash sector 109 - 2kb */ + { 0x08037000, 0x00800 }, /* flash sector 110 - 2kb */ + { 0x08037800, 0x00800 }, /* flash sector 111 - 2kb */ + { 0x08038000, 0x00800 }, /* flash sector 112 - 2kb */ + { 0x08038800, 0x00800 }, /* flash sector 113 - 2kb */ + { 0x08039000, 0x00800 }, /* flash sector 114 - 2kb */ + { 0x08039800, 0x00800 }, /* flash sector 115 - 2kb */ + { 0x0803a000, 0x00800 }, /* flash sector 116 - 2kb */ + { 0x0803a800, 0x00800 }, /* flash sector 117 - 2kb */ + { 0x0803b000, 0x00800 }, /* flash sector 118 - 2kb */ + { 0x0803b800, 0x00800 }, /* flash sector 119 - 2kb */ + { 0x0803c000, 0x00800 }, /* flash sector 120 - 2kb */ + { 0x0803c800, 0x00800 }, /* flash sector 121 - 2kb */ + { 0x0803d000, 0x00800 }, /* flash sector 122 - 2kb */ + { 0x0803d800, 0x00800 }, /* flash sector 123 - 2kb */ + { 0x0803e000, 0x00800 }, /* flash sector 124 - 2kb */ + { 0x0803e800, 0x00800 }, /* flash sector 125 - 2kb */ + { 0x0803f000, 0x00800 }, /* flash sector 126 - 2kb */ + { 0x0803f800, 0x00800 }, /* flash sector 127 - 2kb */ +#endif +#if (BOOT_NVM_SIZE_KB > 256) +#error "BOOT_NVM_SIZE_KB > 256 is currently not supported." +#endif +}; + + +/*********************************** end of flash_layout.c *****************************/ diff --git a/firmware/boards/f1_dual_rev1/openblt/main.c b/firmware/boards/f1_dual_rev1/openblt/main.c new file mode 100644 index 0000000..0c8d087 --- /dev/null +++ b/firmware/boards/f1_dual_rev1/openblt/main.c @@ -0,0 +1,207 @@ +/**************************************************************************************** +* Include files +****************************************************************************************/ +#include "boot.h" /* bootloader generic header */ +#include "stm32f1xx.h" /* STM32 registers and drivers */ +#include "stm32f1xx_ll_rcc.h" /* STM32 LL RCC header */ +#include "stm32f1xx_ll_bus.h" /* STM32 LL BUS header */ +#include "stm32f1xx_ll_system.h" /* STM32 LL SYSTEM header */ +#include "stm32f1xx_ll_utils.h" /* STM32 LL UTILS header */ +#include "stm32f1xx_ll_usart.h" /* STM32 LL USART header */ +#include "stm32f1xx_ll_gpio.h" /* STM32 LL GPIO header */ + +#include "io_pins.h" + +/**************************************************************************************** +* Function prototypes +****************************************************************************************/ +static void Init(void); +static void SystemClock_Config(void); + + +/************************************************************************************//** +** \brief This is the entry point for the bootloader application and is called +** by the reset interrupt vector after the C-startup routines executed. +** \return Program return code. +** +****************************************************************************************/ +int main(void) +{ + /* initialize the microcontroller */ + Init(); + /* initialize the bootloader */ + BootInit(); + + /* start the infinite program loop */ + while (1) + { + /* run the bootloader task */ + BootTask(); + } + + /* program should never get here */ + return 0; +} /*** end of main ***/ + + +/************************************************************************************//** +** \brief Initializes the microcontroller. +** \return none. +** +****************************************************************************************/ +static void Init(void) +{ + /* HAL library initialization */ + HAL_Init(); + /* configure system clock */ + SystemClock_Config(); +} /*** end of Init ***/ + +/************************************************************************************//** +** \brief System Clock Configuration. This code was created by CubeMX and configures +** the system clock to match the configuration in the bootloader's +** configuration (blt_conf.h), specifically the macros: +** BOOT_CPU_SYSTEM_SPEED_KHZ and BOOT_CPU_XTAL_SPEED_KHZ. +** Note that the Lower Layer drivers were selected in CubeMX for the RCC +** subsystem. +** \return none. +** +****************************************************************************************/ +static void SystemClock_Config(void) +{ + /* Set flash latency. */ + LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); + if (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_2) + { + /* Error setting flash latency. */ + ASSERT_RT(BLT_FALSE); + } + + /* Enable the HSE clock. */ + LL_RCC_HSE_Enable(); + /* Wait till HSE is ready. */ + while (LL_RCC_HSE_IsReady() != 1) + { + ; + } + + /* Configure and enable the PLL. */ + /* 48MHz max */ + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_2, LL_RCC_PLL_MUL_12); + LL_RCC_PLL_Enable(); + + /* Wait till PLL is ready. */ + while (LL_RCC_PLL_IsReady() != 1) + { + ; + } + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + + /* Wait till System clock is ready. */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + ; + } + /* Update the system clock speed setting. */ + LL_SetSystemCoreClock(BOOT_CPU_SYSTEM_SPEED_KHZ * 1000u); +} /*** end of SystemClock_Config ***/ + + +/************************************************************************************//** +** \brief Initializes the Global MSP. This function is called from HAL_Init() +** function to perform system level initialization (GPIOs, clock, DMA, +** interrupt). +** \return none. +** +****************************************************************************************/ +void HAL_MspInit(void) +{ + LL_GPIO_InitTypeDef GPIO_InitStruct; + + /* AFIO and PWR clock enable. */ + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); + + /* GPIO ports clock enable. */ + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); + +#if (BOOT_COM_RS232_ENABLE > 0) + /* UART clock enable. */ + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); + /* UART TX and RX GPIO pin configuration. */ + GPIO_InitStruct.Pin = LL_UART_TX_PIN; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + LL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct); + GPIO_InitStruct.Pin = LL_UART_RX_PIN; + GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING; + GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; + LL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct); +#endif + +#if (BOOT_COM_CAN_ENABLE > 0) + /* CAN clock enable. */ + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_CAN1); + /* CAN TX and RX GPIO pin configuration. */ + GPIO_InitStruct.Pin = LL_CAN_TX_PIN; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; + LL_GPIO_Init(CAN_GPIO_PORT, &GPIO_InitStruct); + GPIO_InitStruct.Pin = LL_CAN_RX_PIN; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; + LL_GPIO_Init(CAN_GPIO_PORT, &GPIO_InitStruct); +#endif + +#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0) + /* Configure GPIO pin for (optional) backdoor entry input. */ + GPIO_InitStruct.Pin = LL_GPIO_PIN_13; + GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); +#endif +} /*** end of HAL_MspInit ***/ + + +/************************************************************************************//** +** \brief DeInitializes the Global MSP. This function is called from HAL_DeInit() +** function to perform system level de-initialization (GPIOs, clock, DMA, +** interrupt). +** \return none. +** +****************************************************************************************/ +void HAL_MspDeInit(void) +{ + /* Reset the RCC clock configuration to the default reset state. */ + LL_RCC_DeInit(); + + /* Deinit used GPIOs. */ + LL_GPIO_DeInit(GPIOB); + LL_GPIO_DeInit(GPIOA); + +#if (BOOT_COM_CAN_ENABLE > 0) + /* CAN clock disable. */ + LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_CAN1); +#endif + +#if (BOOT_COM_RS232_ENABLE > 0) + /* UART clock disable. */ + LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_USART1); +#endif + + /* GPIO ports clock disable. */ + LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_GPIOB); + LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_GPIOA); + + /* AFIO and PWR clock disable. */ + LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_PWR); + LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_AFIO); +} /*** end of HAL_MspDeInit ***/ + + +/*********************************** end of main.c *************************************/ diff --git a/firmware/boards/f1_dual_rev1/openblt/startup_stm32f103xb.s b/firmware/boards/f1_dual_rev1/openblt/startup_stm32f103xb.s new file mode 100644 index 0000000..1bdd524 --- /dev/null +++ b/firmware/boards/f1_dual_rev1/openblt/startup_stm32f103xb.s @@ -0,0 +1,379 @@ +/** + *************** (C) COPYRIGHT 2017 STMicroelectronics ************************ + * @file startup_stm32f103xb.s + * @author MCD Application Team + * @version V4.2.0 + * @date 31-March-2017 + * @brief STM32F103xB Devices vector table for Atollic toolchain. + * This module performs: + * - Set the initial SP + * - Set the initial PC == Reset_Handler, + * - Set the vector table entries with the exceptions ISR address + * - Configure the clock system + * - Branches to main in the C library (which eventually + * calls main()). + * After Reset the Cortex-M3 processor is in Thread mode, + * priority is Privileged, and the Stack is set to Main. + ****************************************************************************** + * + *