├── _htmresc ├── favicon.png └── st_logo_2020.png ├── .github ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE.md ├── Interfaces ├── Patterns │ ├── platform.h │ ├── ENGI BYTES │ │ ├── engibytes_interface.h │ │ └── engibytes_interface.c │ ├── IWDG │ │ ├── iwdg_interface.h │ │ └── iwdg_interface.c │ ├── SYSTEM MEMORY │ │ ├── systemmemory_interface.h │ │ └── systemmemory_interface.c │ ├── OTP │ │ ├── otp_interface.h │ │ └── otp_interface.c │ ├── RAM │ │ ├── ram_interface.h │ │ └── ram_interface.c │ ├── USB │ │ ├── usb_interface.h │ │ └── usb_interface.c │ ├── OPTION BYTES │ │ ├── optionbytes_interface.h │ │ └── optionbytes_interface.c │ ├── COMMON │ │ ├── common_interface.h │ │ └── common_interface.c │ ├── USART │ │ ├── usart_interface.h │ │ └── usart_interface.c │ ├── FDCAN │ │ ├── fdcan_interface.h │ │ └── fdcan_interface.c │ ├── I3C │ │ └── i3c_interface.h │ ├── FLASH │ │ └── flash_interface.h │ ├── SPI │ │ └── spi_interface.h │ ├── I2C │ │ └── i2c_interface.h │ ├── openbootloader_conf.h │ └── interfaces_conf.h └── Templates │ ├── platform.h │ ├── ENGI BYTES │ ├── engibytes_interface.h │ └── engibytes_interface.c │ ├── IWDG │ ├── iwdg_interface.h │ └── iwdg_interface.c │ ├── SYSTEM MEMORY │ ├── systemmemory_interface.h │ └── systemmemory_interface.c │ ├── OTP │ ├── otp_interface.h │ └── otp_interface.c │ ├── RAM │ ├── ram_interface.h │ └── ram_interface.c │ ├── USB │ ├── usb_interface.h │ └── usb_interface.c │ ├── OPTION BYTES │ ├── optionbytes_interface.h │ └── optionbytes_interface.c │ ├── COMMON │ ├── common_interface.h │ └── common_interface.c │ ├── USART │ ├── usart_interface.h │ └── usart_interface.c │ ├── FDCAN │ ├── fdcan_interface.h │ └── fdcan_interface.c │ ├── I3C │ ├── i3c_interface.h │ └── i3c_interface.c │ ├── FLASH │ └── flash_interface.h │ ├── SPI │ ├── spi_interface.h │ └── spi_interface.c │ ├── I2C │ ├── i2c_interface.h │ └── i2c_interface.c │ ├── openbootloader_conf.h │ └── interfaces_conf.h ├── Modules ├── USB │ ├── openbl_usb_cmd.h │ └── openbl_usb_cmd.c ├── I3C │ └── openbl_i3c_cmd.h ├── SPI │ └── openbl_spi_cmd.h ├── USART │ └── openbl_usart_cmd.h ├── CAN │ └── openbl_can_cmd.h ├── FDCAN │ └── openbl_fdcan_cmd.h ├── I2C │ └── openbl_i2c_cmd.h └── Mem │ └── openbl_mem.h ├── SECURITY.md ├── CONTRIBUTING.md ├── CODE_OF_CONDUCT.md ├── LICENSE.md ├── README.md └── Core └── openbl_core.h /_htmresc/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STMicroelectronics/stm32-mw-openbl/HEAD/_htmresc/favicon.png -------------------------------------------------------------------------------- /_htmresc/st_logo_2020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STMicroelectronics/stm32-mw-openbl/HEAD/_htmresc/st_logo_2020.png -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## IMPORTANT INFORMATION 2 | 3 | ### Contributor License Agreement (CLA) 4 | * The Pull Request feature will be considered by STMicroelectronics after the signature of a **Contributor License Agreement (CLA)** by the submitter. 5 | * If you did not sign such agreement, please follow the steps mentioned in the [CONTRIBUTING.md](../CONTRIBUTING.md#2-pull-requests) file. 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Issue report' 3 | about: 'Create a report to help us improve the quality of our software' 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | --- 8 | 9 | **Caution** 10 | 11 | The Issues are strictly limited to reporting problems encountered or proposing enhancements with the software provided within this repository. 12 | For any other aspect related to the microcontroller itself, the boards, the ecosystem, or other aspects in general, please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md#3-support-requests-and-questions) guide. 13 | 14 | **Describe the set-up** 15 | 16 | * The board (either ST RPN reference or your custom board) 17 | * IDE or at least the compiler and its version 18 | 19 | **Describe the bug (skip if none)** 20 | 21 | A clear and concise description of what the bug is. 22 | 23 | **How to reproduce the bug (skip if none)** 24 | 25 | 1. Indicate the global behavior of your application project 26 | 2. List the modules that you suspect to be the cause of the problem (Drivers, BSP, MW...) 27 | 3. Describe the use case that generates the problem 28 | 4. How we can reproduce the problem 29 | 30 | 31 | **Additional context** 32 | 33 | If you have a first analysis, an enhancement, a fix or a patch, thank you to share your proposal. 34 | 35 | **Screenshots** 36 | 37 | If applicable, add screenshots to help explain your problem. 38 | -------------------------------------------------------------------------------- /Interfaces/Patterns/platform.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file platform.h 4 | * @author MCD Application Team 5 | * @brief Header for patterns 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef PLATFORM_H 21 | #define PLATFORM_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32g0xx_hal.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Exported macro ------------------------------------------------------------*/ 33 | /* Exported functions ------------------------------------------------------- */ 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /* __cplusplus */ 38 | 39 | #endif /* PLATFORM_H */ 40 | -------------------------------------------------------------------------------- /Interfaces/Templates/platform.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file platform.h 4 | * @author MCD Application Team 5 | * @brief Header for patterns 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef PLATFORM_H 21 | #define PLATFORM_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32g0xx_hal.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Exported macro ------------------------------------------------------------*/ 33 | /* Exported functions ------------------------------------------------------- */ 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /* __cplusplus */ 38 | 39 | #endif /* PLATFORM_H */ 40 | -------------------------------------------------------------------------------- /Interfaces/Patterns/ENGI BYTES/engibytes_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file engibytes_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for engibytes_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef ENGIBYTES_INTERFACE_H 21 | #define ENGIBYTES_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | uint8_t OPENBL_EB_Read(uint32_t Address); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* ENGIBYTES_INTERFACE_H */ 39 | -------------------------------------------------------------------------------- /Interfaces/Patterns/IWDG/iwdg_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file iwdg_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for iwdg_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef IWDG_INTERFACE_H 21 | #define IWDG_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | void OPENBL_IWDG_Configuration(void); 33 | void OPENBL_IWDG_Refresh(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* IWDG_INTERFACE_H */ 40 | -------------------------------------------------------------------------------- /Interfaces/Templates/ENGI BYTES/engibytes_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file engibytes_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for engibytes_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef ENGIBYTES_INTERFACE_H 21 | #define ENGIBYTES_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | uint8_t OPENBL_EB_Read(uint32_t Address); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* ENGIBYTES_INTERFACE_H */ 39 | -------------------------------------------------------------------------------- /Interfaces/Templates/IWDG/iwdg_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file iwdg_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for iwdg_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef IWDG_INTERFACE_H 21 | #define IWDG_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | void OPENBL_IWDG_Configuration(void); 33 | void OPENBL_IWDG_Refresh(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* IWDG_INTERFACE_H */ 40 | -------------------------------------------------------------------------------- /Interfaces/Patterns/SYSTEM MEMORY/systemmemory_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file systemmemory_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for systemmemory_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef SYSTEMMEMORY_INTERFACE_H 21 | #define SYSTEMMEMORY_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | uint8_t OPENBL_ICP_Read(uint32_t Address); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* SYSTEMMEMORY_INTERFACE_H */ 39 | -------------------------------------------------------------------------------- /Interfaces/Templates/SYSTEM MEMORY/systemmemory_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file systemmemory_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for systemmemory_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef SYSTEMMEMORY_INTERFACE_H 21 | #define SYSTEMMEMORY_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | uint8_t OPENBL_ICP_Read(uint32_t Address); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* SYSTEMMEMORY_INTERFACE_H */ 39 | -------------------------------------------------------------------------------- /Interfaces/Patterns/OTP/otp_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file otp_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for otp_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OTP_INTERFACE_H 21 | #define OTP_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | uint8_t OPENBL_OTP_Read(uint32_t Address); 33 | void OPENBL_OTP_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* OPTIONBYTES_INTERFACE_H */ 40 | -------------------------------------------------------------------------------- /Interfaces/Templates/OTP/otp_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file otp_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for otp_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OTP_INTERFACE_H 21 | #define OTP_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | uint8_t OPENBL_OTP_Read(uint32_t Address); 33 | void OPENBL_OTP_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* OPTIONBYTES_INTERFACE_H */ 40 | -------------------------------------------------------------------------------- /Modules/USB/openbl_usb_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_usb_cmd.h 4 | * @author MCD Application Team 5 | * @brief Contains USB protocol commands 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* Define to prevent recursive inclusion -------------------------------------*/ 19 | #ifndef OPENBL_USB_CMD_H 20 | #define OPENBL_USB_CMD_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif /* __cplusplus */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "openbl_core.h" 28 | 29 | uint16_t OPENBL_USB_EraseMemory(uint32_t Add); 30 | void OPENBL_USB_WriteMemory(uint8_t *pSrc, uint8_t *pDest, uint32_t Length); 31 | uint8_t *OPENBL_USB_ReadMemory(uint8_t *pSrc, uint8_t *pDest, uint32_t Length); 32 | void OPENBL_USB_Jump(uint32_t Address); 33 | void OPENBL_USB_WriteProtect(uint8_t *pBuffer, uint32_t Length); 34 | void OPENBL_USB_WriteUnprotect(void); 35 | void OPENBL_USB_ReadProtect(void); 36 | void OPENBL_USB_ReadUnprotect(void); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif /* __cplusplus */ 41 | 42 | #endif /* OPENBL_USB_CMD_H */ 43 | -------------------------------------------------------------------------------- /Interfaces/Patterns/RAM/ram_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ram_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for ram_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef RAM_INTERFACE_H 21 | #define RAM_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | void OPENBL_RAM_JumpToAddress(uint32_t Address); 33 | uint8_t OPENBL_RAM_Read(uint32_t Address); 34 | void OPENBL_RAM_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* RAM_INTERFACE_H */ 41 | -------------------------------------------------------------------------------- /Interfaces/Templates/RAM/ram_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ram_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for ram_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef RAM_INTERFACE_H 21 | #define RAM_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | void OPENBL_RAM_JumpToAddress(uint32_t Address); 33 | uint8_t OPENBL_RAM_Read(uint32_t Address); 34 | void OPENBL_RAM_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* RAM_INTERFACE_H */ 41 | -------------------------------------------------------------------------------- /Interfaces/Patterns/USB/usb_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_interface.h 4 | * @author MCD Application Team 5 | * @brief Contains USB protocol commands 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef USB_INTERFACE_H 21 | #define USB_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "platform.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Exported macro ------------------------------------------------------------*/ 33 | /* Exported functions ------------------------------------------------------- */ 34 | void OPENBL_USB_Configuration(void); 35 | void OPENBL_USB_DeInit(void); 36 | uint8_t OPENBL_USB_ProtocolDetection(void); 37 | uint32_t OPENBL_USB_GetPage(uint32_t Address); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* USB_INTERFACE_H */ 44 | -------------------------------------------------------------------------------- /Interfaces/Templates/USB/usb_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_interface.h 4 | * @author MCD Application Team 5 | * @brief Contains USB protocol commands 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef USB_INTERFACE_H 21 | #define USB_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "platform.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Exported macro ------------------------------------------------------------*/ 33 | /* Exported functions ------------------------------------------------------- */ 34 | void OPENBL_USB_Configuration(void); 35 | void OPENBL_USB_DeInit(void); 36 | uint8_t OPENBL_USB_ProtocolDetection(void); 37 | uint32_t OPENBL_USB_GetPage(uint32_t Address); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* USB_INTERFACE_H */ 44 | -------------------------------------------------------------------------------- /Interfaces/Patterns/OPTION BYTES/optionbytes_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file optionbytes_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for optionbytes_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPTIONBYTES_INTERFACE_H 21 | #define OPTIONBYTES_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | uint8_t OPENBL_OB_Read(uint32_t Address); 33 | void OPENBL_OB_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 34 | void OPENBL_OB_Launch(void); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* OPTIONBYTES_INTERFACE_H */ 41 | -------------------------------------------------------------------------------- /Interfaces/Templates/OPTION BYTES/optionbytes_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file optionbytes_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for optionbytes_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPTIONBYTES_INTERFACE_H 21 | #define OPTIONBYTES_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | uint8_t OPENBL_OB_Read(uint32_t Address); 33 | void OPENBL_OB_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 34 | void OPENBL_OB_Launch(void); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* OPTIONBYTES_INTERFACE_H */ 41 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Report potential product security vulnerabilities 2 | 3 | ST places a high priority on security, and our Product Security Incident 4 | Response Team (PSIRT) is committed to rapidly addressing potential security 5 | vulnerabilities affecting our products. PSIRT's long history and vast experience 6 | in security allows ST to perform clear analyses and provide appropriate guidance 7 | on mitigations and solutions when applicable. 8 | 9 | If you wish to report potential security vulnerabilities regarding our products, 10 | **please do not report them through public GitHub issues.** Instead, we 11 | encourage you to report them to our ST PSIRT following the process described at: 12 | **https://www.st.com/content/st_com/en/security/report-vulnerabilities.html** 13 | 14 | ### IMPORTANT - READ CAREFULLY: 15 | 16 | STMicroelectronics International N.V., on behalf of itself, its affiliates and 17 | subsidiaries, (collectively “ST”) takes all potential security vulnerability 18 | reports or other related communications (“Report(s)”) seriously. In order to 19 | review Your Report (the terms “You” and “Yours” include your employer, and all 20 | affiliates, subsidiaries and related persons or entities) and take actions as 21 | deemed appropriate, ST requires that we have the rights and Your permission to 22 | do so. 23 | 24 | As such, by submitting Your Report to ST, You agree that You have the right to 25 | do so, and You grant to ST the rights to use the Report for purposes related to 26 | security vulnerability analysis, testing, correction, patching, reporting and 27 | any other related purpose or function. 28 | 29 | By submitting Your Report, You agree that ST’s 30 | [Privacy Policy](https://www.st.com/content/st_com/en/common/privacy-portal.html) 31 | applies to all related communications. 32 | -------------------------------------------------------------------------------- /Interfaces/Patterns/COMMON/common_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file common_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for common_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef COMMON_INTERFACE_H 21 | #define COMMON_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | typedef void (*Function_Pointer)(void); 30 | 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Exported macro ------------------------------------------------------------*/ 33 | /* Exported functions ------------------------------------------------------- */ 34 | void Common_SetMsp(uint32_t TopOfMainStack); 35 | void Common_EnableIrq(void); 36 | void Common_DisableIrq(void); 37 | FlagStatus Common_GetProtectionStatus(void); 38 | void Common_SetPostProcessingCallback(Function_Pointer Callback); 39 | void Common_StartPostProcessing(void); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* COMMON_INTERFACE_H */ 46 | -------------------------------------------------------------------------------- /Interfaces/Templates/COMMON/common_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file common_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for common_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef COMMON_INTERFACE_H 21 | #define COMMON_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | typedef void (*Function_Pointer)(void); 30 | 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Exported macro ------------------------------------------------------------*/ 33 | /* Exported functions ------------------------------------------------------- */ 34 | void Common_SetMsp(uint32_t TopOfMainStack); 35 | void Common_EnableIrq(void); 36 | void Common_DisableIrq(void); 37 | FlagStatus Common_GetProtectionStatus(void); 38 | void Common_SetPostProcessingCallback(Function_Pointer Callback); 39 | void Common_StartPostProcessing(void); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* COMMON_INTERFACE_H */ 46 | -------------------------------------------------------------------------------- /Interfaces/Templates/IWDG/iwdg_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file iwdg_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains IWDG HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "main.h" 22 | #include "iwdg_interface.h" 23 | 24 | /* Private typedef -----------------------------------------------------------*/ 25 | /* Private define ------------------------------------------------------------*/ 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* Private variables ---------------------------------------------------------*/ 28 | static IWDG_HandleTypeDef IWDGHandle; 29 | 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Private functions ---------------------------------------------------------*/ 32 | /* Exported functions --------------------------------------------------------*/ 33 | 34 | /** 35 | * @brief This function is used to configure the watchdog. 36 | * @retval None. 37 | */ 38 | void OPENBL_IWDG_Configuration(void) 39 | { 40 | } 41 | 42 | /** 43 | * @brief This function is used to refresh the watchdog. 44 | * @retval None. 45 | */ 46 | void OPENBL_IWDG_Refresh(void) 47 | { 48 | } 49 | -------------------------------------------------------------------------------- /Interfaces/Patterns/USART/usart_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usart_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for usart_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef USART_INTERFACE_H 21 | #define USART_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "openbl_core.h" 30 | 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions ------------------------------------------------------- */ 35 | void OPENBL_USART_Configuration(void); 36 | void OPENBL_USART_DeInit(void); 37 | uint8_t OPENBL_USART_ProtocolDetection(void); 38 | 39 | uint8_t OPENBL_USART_GetCommandOpcode(void); 40 | uint8_t OPENBL_USART_ReadByte(void); 41 | void OPENBL_USART_SendByte(uint8_t Byte); 42 | void OPENBL_USART_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* USART_INTERFACE_H */ 49 | -------------------------------------------------------------------------------- /Interfaces/Templates/USART/usart_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usart_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for usart_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef USART_INTERFACE_H 21 | #define USART_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "openbl_core.h" 30 | 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions ------------------------------------------------------- */ 35 | void OPENBL_USART_Configuration(void); 36 | void OPENBL_USART_DeInit(void); 37 | uint8_t OPENBL_USART_ProtocolDetection(void); 38 | 39 | uint8_t OPENBL_USART_GetCommandOpcode(void); 40 | uint8_t OPENBL_USART_ReadByte(void); 41 | void OPENBL_USART_SendByte(uint8_t Byte); 42 | void OPENBL_USART_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* USART_INTERFACE_H */ 49 | -------------------------------------------------------------------------------- /Interfaces/Patterns/FDCAN/fdcan_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file fdcan_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for fdcan_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef FDCAN_INTERFACE_H 21 | #define FDCAN_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "openbl_core.h" 30 | 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions ------------------------------------------------------- */ 35 | void OPENBL_FDCAN_Configuration(void); 36 | void OPENBL_FDCAN_DeInit(void); 37 | uint8_t OPENBL_FDCAN_ProtocolDetection(void); 38 | 39 | uint8_t OPENBL_FDCAN_GetCommandOpcode(void); 40 | uint8_t OPENBL_FDCAN_ReadByte(void); 41 | void OPENBL_FDCAN_ReadBytes(uint8_t *Buffer, uint32_t BufferSize); 42 | void OPENBL_FDCAN_SendByte(uint8_t Byte); 43 | void OPENBL_FDCAN_SendBytes(uint8_t *Buffer, uint32_t BufferSize); 44 | void OPENBL_FDCAN_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *Frame); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* FDCAN_INTERFACE_H */ 51 | -------------------------------------------------------------------------------- /Interfaces/Templates/FDCAN/fdcan_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file fdcan_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for fdcan_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef FDCAN_INTERFACE_H 21 | #define FDCAN_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "openbl_core.h" 30 | 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions ------------------------------------------------------- */ 35 | void OPENBL_FDCAN_Configuration(void); 36 | void OPENBL_FDCAN_DeInit(void); 37 | uint8_t OPENBL_FDCAN_ProtocolDetection(void); 38 | 39 | uint8_t OPENBL_FDCAN_GetCommandOpcode(void); 40 | uint8_t OPENBL_FDCAN_ReadByte(void); 41 | void OPENBL_FDCAN_ReadBytes(uint8_t *Buffer, uint32_t BufferSize); 42 | void OPENBL_FDCAN_SendByte(uint8_t Byte); 43 | void OPENBL_FDCAN_SendBytes(uint8_t *Buffer, uint32_t BufferSize); 44 | void OPENBL_FDCAN_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *Frame); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* FDCAN_INTERFACE_H */ 51 | -------------------------------------------------------------------------------- /Interfaces/Patterns/ENGI BYTES/engibytes_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file engibytes_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains Engi Bytes access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "engibytes_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Exported variables --------------------------------------------------------*/ 32 | OPENBL_MemoryTypeDef EB_Descriptor = 33 | { 34 | EB_START_ADDRESS, 35 | EB_END_ADDRESS, 36 | EB_SIZE, 37 | EB_AREA, 38 | OPENBL_EB_Read, 39 | NULL, 40 | NULL, 41 | NULL, 42 | NULL, 43 | NULL, 44 | NULL 45 | }; 46 | 47 | /* Exported functions --------------------------------------------------------*/ 48 | 49 | /** 50 | * @brief This function is used to read data from a given address. 51 | * @param Address The address to be read. 52 | * @retval Returns the read value. 53 | */ 54 | uint8_t OPENBL_EB_Read(uint32_t Address) 55 | { 56 | return (*(uint8_t *)(Address)); 57 | } 58 | -------------------------------------------------------------------------------- /Interfaces/Templates/ENGI BYTES/engibytes_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file engibytes_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains Engi Bytes access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "engibytes_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Exported variables --------------------------------------------------------*/ 32 | OPENBL_MemoryTypeDef EB_Descriptor = 33 | { 34 | EB_START_ADDRESS, 35 | EB_END_ADDRESS, 36 | EB_SIZE, 37 | EB_AREA, 38 | OPENBL_EB_Read, 39 | NULL, 40 | NULL, 41 | NULL, 42 | NULL, 43 | NULL, 44 | NULL 45 | }; 46 | 47 | /* Exported functions --------------------------------------------------------*/ 48 | 49 | /** 50 | * @brief This function is used to read data from a given address. 51 | * @param Address The address to be read. 52 | * @retval Returns the read value. 53 | */ 54 | uint8_t OPENBL_EB_Read(uint32_t Address) 55 | { 56 | return (*(uint8_t *)(Address)); 57 | } 58 | -------------------------------------------------------------------------------- /Interfaces/Patterns/I3C/i3c_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file i3c_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for i3c_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef I3C_INTERFACE_H 21 | #define I3C_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "common_interface.h" 30 | #include "openbl_core.h" 31 | 32 | /* Exported types ------------------------------------------------------------*/ 33 | /* Exported constants --------------------------------------------------------*/ 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported functions ------------------------------------------------------- */ 36 | void OPENBL_I3C_Configuration(void); 37 | void OPENBL_I3C_DeInit(void); 38 | 39 | uint8_t OPENBL_I3C_ProtocolDetection(void); 40 | uint8_t OPENBL_I3C_GetCommandOpcode(void); 41 | uint8_t OPENBL_I3C_ReadByte(void); 42 | void OPENBL_I3C_SendByte(uint8_t Byte); 43 | void OPENBL_I3C_SendAcknowledgeByte(uint8_t Acknowledge); 44 | void OPENBL_I3C_SendBytes(uint8_t *pBuffer, uint32_t BufferSize); 45 | void OPENBL_I3C_ReadBytes(uint8_t *pBuffer, uint32_t BufferSize); 46 | 47 | void OPENBL_I3C_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *pSpecialCmd); 48 | 49 | void OPENBL_I3C_IRQHandler(void); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif /* __cplusplus */ 54 | 55 | #endif /* I3C_INTERFACE_H */ 56 | -------------------------------------------------------------------------------- /Interfaces/Templates/I3C/i3c_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file i3c_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for i3c_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef I3C_INTERFACE_H 21 | #define I3C_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "common_interface.h" 30 | #include "openbl_core.h" 31 | 32 | /* Exported types ------------------------------------------------------------*/ 33 | /* Exported constants --------------------------------------------------------*/ 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported functions ------------------------------------------------------- */ 36 | void OPENBL_I3C_Configuration(void); 37 | void OPENBL_I3C_DeInit(void); 38 | 39 | uint8_t OPENBL_I3C_ProtocolDetection(void); 40 | uint8_t OPENBL_I3C_GetCommandOpcode(void); 41 | uint8_t OPENBL_I3C_ReadByte(void); 42 | void OPENBL_I3C_SendByte(uint8_t Byte); 43 | void OPENBL_I3C_SendAcknowledgeByte(uint8_t Acknowledge); 44 | void OPENBL_I3C_SendBytes(uint8_t *pBuffer, uint32_t BufferSize); 45 | void OPENBL_I3C_ReadBytes(uint8_t *pBuffer, uint32_t BufferSize); 46 | 47 | void OPENBL_I3C_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd); 48 | 49 | void OPENBL_I3C_IRQHandler(void); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif /* __cplusplus */ 54 | 55 | #endif /* I3C_INTERFACE_H */ 56 | -------------------------------------------------------------------------------- /Modules/I3C/openbl_i3c_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_i3c_cmd.h 4 | * @author MCD Application Team 5 | * @brief Header for openbl_i3c_cmd.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBL_I3C_CMD_H 21 | #define OPENBL_I3C_CMD_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "openbl_core.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | #define OPENBL_I3C_VERSION 0x10U /* Open Bootloader I3C protocol V1.0 */ 33 | 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported variables --------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | OPENBL_CommandsTypeDef *OPENBL_I3C_GetCommandsList(void); 38 | void OPENBL_I3C_SetCommandsList(OPENBL_CommandsTypeDef *pI3cCmd); 39 | void OPENBL_I3C_GetCommand(void); 40 | void OPENBL_I3C_GetVersion(void); 41 | void OPENBL_I3C_GetID(void); 42 | void OPENBL_I3C_ReadMemory(void); 43 | void OPENBL_I3C_WriteMemory(void); 44 | void OPENBL_I3C_Go(void); 45 | void OPENBL_I3C_EraseMemory(void); 46 | void OPENBL_I3C_WriteProtect(void); 47 | void OPENBL_I3C_WriteUnprotect(void); 48 | void OPENBL_I3C_SpecialCommand(void); 49 | void OPENBL_I3C_ExtendedSpecialCommand(void); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* OPENBL_I3C_CMD_H */ 56 | -------------------------------------------------------------------------------- /Interfaces/Templates/SYSTEM MEMORY/systemmemory_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file systemmemory_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains System Memory access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "systemmemory_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Exported variables --------------------------------------------------------*/ 32 | OPENBL_MemoryTypeDef ICP1_Descriptor = 33 | { 34 | ICP1_START_ADDRESS, 35 | ICP1_END_ADDRESS, 36 | (28U * 1024U), 37 | ICP1_AREA, 38 | OPENBL_ICP_Read, 39 | NULL, 40 | NULL, 41 | NULL, 42 | NULL, 43 | NULL, 44 | NULL 45 | }; 46 | 47 | OPENBL_MemoryTypeDef ICP2_Descriptor = 48 | { 49 | ICP2_START_ADDRESS, 50 | ICP2_END_ADDRESS, 51 | (28U * 1024U), 52 | ICP2_AREA, 53 | OPENBL_ICP_Read, 54 | NULL, 55 | NULL, 56 | NULL, 57 | NULL, 58 | NULL, 59 | NULL 60 | }; 61 | 62 | /** 63 | * @brief This function is used to read data from a given address. 64 | * @param Address The address to be read. 65 | * @retval Returns the read value. 66 | */ 67 | uint8_t OPENBL_ICP_Read(uint32_t Address) 68 | { 69 | } 70 | -------------------------------------------------------------------------------- /Interfaces/Patterns/SYSTEM MEMORY/systemmemory_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file systemmemory_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains System Memory access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "systemmemory_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Exported variables --------------------------------------------------------*/ 32 | OPENBL_MemoryTypeDef ICP1_Descriptor = 33 | { 34 | ICP1_START_ADDRESS, 35 | ICP1_END_ADDRESS, 36 | (28U * 1024U), 37 | ICP1_AREA, 38 | OPENBL_ICP_Read, 39 | NULL, 40 | NULL, 41 | NULL, 42 | NULL, 43 | NULL, 44 | NULL 45 | }; 46 | 47 | OPENBL_MemoryTypeDef ICP2_Descriptor = 48 | { 49 | ICP2_START_ADDRESS, 50 | ICP2_END_ADDRESS, 51 | (28U * 1024U), 52 | ICP2_AREA, 53 | OPENBL_ICP_Read, 54 | NULL, 55 | NULL, 56 | NULL, 57 | NULL, 58 | NULL, 59 | NULL 60 | }; 61 | 62 | /** 63 | * @brief This function is used to read data from a given address. 64 | * @param Address The address to be read. 65 | * @retval Returns the read value. 66 | */ 67 | uint8_t OPENBL_ICP_Read(uint32_t Address) 68 | { 69 | return (*(uint8_t *)(Address)); 70 | } 71 | -------------------------------------------------------------------------------- /Modules/SPI/openbl_spi_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_spi_cmd.h 4 | * @author MCD Application Team 5 | * @brief Header for openbl_spi_cmd.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBL_SPI_CMD_H 21 | #define OPENBL_SPI_CMD_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "openbl_core.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | #define OPENBL_SPI_VERSION 0x11U /* Open Bootloader SPI protocol V1.1 */ 33 | 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported variables --------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | OPENBL_CommandsTypeDef *OPENBL_SPI_GetCommandsList(void); 38 | void OPENBL_SPI_SetCommandsList(OPENBL_CommandsTypeDef *pSpiCmd); 39 | void OPENBL_SPI_GetCommand(void); 40 | void OPENBL_SPI_GetVersion(void); 41 | void OPENBL_SPI_GetID(void); 42 | void OPENBL_SPI_ReadMemory(void); 43 | void OPENBL_SPI_WriteMemory(void); 44 | void OPENBL_SPI_Go(void); 45 | void OPENBL_SPI_ReadoutProtect(void); 46 | void OPENBL_SPI_ReadoutUnprotect(void); 47 | void OPENBL_SPI_EraseMemory(void); 48 | void OPENBL_SPI_WriteProtect(void); 49 | void OPENBL_SPI_WriteUnprotect(void); 50 | void OPENBL_SPI_SpecialCommand(void); 51 | void OPENBL_SPI_ExtendedSpecialCommand(void); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif /* __cplusplus */ 56 | 57 | #endif /* OPENBL_SPI_CMD_H */ 58 | -------------------------------------------------------------------------------- /Modules/USART/openbl_usart_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_usart_cmd.h 4 | * @author MCD Application Team 5 | * @brief Header for openbl_usart_cmd.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBL_USART_CMD_H 21 | #define OPENBL_USART_CMD_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "openbl_core.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | #define OPENBL_USART_VERSION 0x31U /* Open Bootloader USART protocol V3.1 */ 33 | 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported variables --------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | OPENBL_CommandsTypeDef *OPENBL_USART_GetCommandsList(void); 38 | void OPENBL_USART_SetCommandsList(OPENBL_CommandsTypeDef *pUsartCmd); 39 | void OPENBL_USART_GetCommand(void); 40 | void OPENBL_USART_GetVersion(void); 41 | void OPENBL_USART_GetID(void); 42 | void OPENBL_USART_ReadMemory(void); 43 | void OPENBL_USART_WriteMemory(void); 44 | void OPENBL_USART_Go(void); 45 | void OPENBL_USART_ReadoutProtect(void); 46 | void OPENBL_USART_ReadoutUnprotect(void); 47 | void OPENBL_USART_EraseMemory(void); 48 | void OPENBL_USART_WriteProtect(void); 49 | void OPENBL_USART_WriteUnprotect(void); 50 | void OPENBL_USART_SpecialCommand(void); 51 | void OPENBL_USART_ExtendedSpecialCommand(void); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif /* __cplusplus */ 56 | 57 | #endif /* OPENBL_USART_CMD_H */ 58 | -------------------------------------------------------------------------------- /Interfaces/Patterns/IWDG/iwdg_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file iwdg_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains IWDG HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "main.h" 22 | #include "iwdg_interface.h" 23 | 24 | /* Private typedef -----------------------------------------------------------*/ 25 | /* Private define ------------------------------------------------------------*/ 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* Private variables ---------------------------------------------------------*/ 28 | static IWDG_HandleTypeDef IWDGHandle; 29 | 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Private functions ---------------------------------------------------------*/ 32 | /* Exported functions --------------------------------------------------------*/ 33 | 34 | /** 35 | * @brief This function is used to configure the watchdog. 36 | * @retval None. 37 | */ 38 | void OPENBL_IWDG_Configuration(void) 39 | { 40 | IWDGHandle.Instance = IWDG; 41 | IWDGHandle.Init.Prescaler = IWDG_PRESCALER_256; 42 | IWDGHandle.Init.Window = IWDG_WINDOW_DISABLE; 43 | IWDGHandle.Init.Reload = IWDG_KEY_RELOAD; 44 | 45 | /* In case the user has enabled the IWDG through HW before entering the Open Bootloader */ 46 | IWDG->KR = IWDG_KEY_WRITE_ACCESS_ENABLE; 47 | IWDG->PR = IWDG_PRESCALER_256; 48 | IWDG->KR = IWDG_KEY_RELOAD; 49 | } 50 | 51 | /** 52 | * @brief This function is used to refresh the watchdog. 53 | * @retval None. 54 | */ 55 | void OPENBL_IWDG_Refresh(void) 56 | { 57 | /* Refresh IWDG: reload counter */ 58 | if (HAL_IWDG_Refresh(&IWDGHandle) != HAL_OK) 59 | { 60 | /* Refresh Error */ 61 | Error_Handler(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Modules/CAN/openbl_can_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_can_cmd.h 4 | * @author MCD Application Team 5 | * @brief Header for openbl_can_cmd.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBL_CAN_CMD_H 21 | #define OPENBL_CAN_CMD_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "openbl_core.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | #define OPENBL_CAN_VERSION 0x10U /* Open Bootloader CAN protocol V1.0 */ 33 | #define CAN_RAM_BUFFER_SIZE 256U /* Size of CAN buffer used to store received data from the host */ 34 | 35 | /* Exported macro ------------------------------------------------------------*/ 36 | /* Exported variables --------------------------------------------------------*/ 37 | extern uint8_t tCanRxData[CAN_RAM_BUFFER_SIZE]; 38 | 39 | /* Exported functions ------------------------------------------------------- */ 40 | OPENBL_CommandsTypeDef *OPENBL_CAN_GetCommandsList(void); 41 | void OPENBL_CAN_SetCommandsList(OPENBL_CommandsTypeDef *pCanCmd); 42 | void OPENBL_CAN_GetCommand(void); 43 | void OPENBL_CAN_GetVersion(void); 44 | void OPENBL_CAN_GetID(void); 45 | void OPENBL_CAN_Speed(void); 46 | void OPENBL_CAN_ReadMemory(void); 47 | void OPENBL_CAN_WriteMemory(void); 48 | void OPENBL_CAN_Go(void); 49 | void OPENBL_CAN_ReadoutProtect(void); 50 | void OPENBL_CAN_ReadoutUnprotect(void); 51 | void OPENBL_CAN_LegacyEraseMemory(void); 52 | void OPENBL_CAN_WriteProtect(void); 53 | void OPENBL_CAN_WriteUnprotect(void); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif /* __cplusplus */ 58 | 59 | #endif /* OPENBL_CAN_CMD_H */ 60 | -------------------------------------------------------------------------------- /Interfaces/Patterns/FLASH/flash_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file flash_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for flash_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef FLASH_INTERFACE_H 21 | #define FLASH_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "common_interface.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | #define FLASH_BUSY_STATE_ENABLED ((uint32_t)0xAAAA0000) 33 | #define FLASH_BUSY_STATE_DISABLED ((uint32_t)0x0000DDDD) 34 | #define PROGRAM_TIMEOUT ((uint32_t)0x00FFFFFF) 35 | 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void OPENBL_FLASH_JumpToAddress(uint32_t Address); 39 | void OPENBL_FLASH_Lock(void); 40 | void OPENBL_FLASH_OB_Unlock(void); 41 | uint8_t OPENBL_FLASH_Read(uint32_t Address); 42 | void OPENBL_FLASH_SetReadOutProtectionLevel(uint32_t Level); 43 | void OPENBL_FLASH_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 44 | void OPENBL_FLASH_Unlock(void); 45 | ErrorStatus OPENBL_FLASH_MassErase(uint8_t *p_Data, uint32_t DataLength); 46 | ErrorStatus OPENBL_FLASH_Erase(uint8_t *p_Data, uint32_t DataLength); 47 | ErrorStatus OPENBL_FLASH_SetWriteProtection(FunctionalState State, uint8_t *ListOfPages, uint32_t Length); 48 | uint32_t OPENBL_FLASH_GetReadOutProtectionLevel(void); 49 | void OPENBL_Enable_BusyState_Flag(void); 50 | void OPENBL_Disable_BusyState_Flag(void); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* FLASH_INTERFACE_H */ 57 | -------------------------------------------------------------------------------- /Interfaces/Templates/FLASH/flash_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file flash_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for flash_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef FLASH_INTERFACE_H 21 | #define FLASH_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "common_interface.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | #define FLASH_BUSY_STATE_ENABLED ((uint32_t)0xAAAA0000) 33 | #define FLASH_BUSY_STATE_DISABLED ((uint32_t)0x0000DDDD) 34 | #define PROGRAM_TIMEOUT ((uint32_t)0x00FFFFFF) 35 | 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void OPENBL_FLASH_JumpToAddress(uint32_t Address); 39 | void OPENBL_FLASH_Lock(void); 40 | void OPENBL_FLASH_OB_Unlock(void); 41 | uint8_t OPENBL_FLASH_Read(uint32_t Address); 42 | void OPENBL_FLASH_SetReadOutProtectionLevel(uint32_t Level); 43 | void OPENBL_FLASH_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 44 | void OPENBL_FLASH_Unlock(void); 45 | ErrorStatus OPENBL_FLASH_MassErase(uint8_t *p_Data, uint32_t DataLength); 46 | ErrorStatus OPENBL_FLASH_Erase(uint8_t *p_Data, uint32_t DataLength); 47 | ErrorStatus OPENBL_FLASH_SetWriteProtection(FunctionalState State, uint8_t *ListOfPages, uint32_t Length); 48 | uint32_t OPENBL_FLASH_GetReadOutProtectionLevel(void); 49 | void OPENBL_Enable_BusyState_Flag(void); 50 | void OPENBL_Disable_BusyState_Flag(void); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* FLASH_INTERFACE_H */ 57 | -------------------------------------------------------------------------------- /Interfaces/Patterns/SPI/spi_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for spi_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef SPI_INTERFACE_H 21 | #define SPI_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "openbl_core.h" 30 | 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions --------------------------------------------------------*/ 35 | void OPENBL_SPI_Configuration(void); 36 | void OPENBL_SPI_DeInit(void); 37 | uint8_t OPENBL_SPI_ProtocolDetection(void); 38 | uint8_t OPENBL_SPI_GetCommandOpcode(void); 39 | void OPENBL_SPI_SendAcknowledgeByte(uint8_t Byte); 40 | void OPENBL_SPI_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd); 41 | 42 | void OPENBL_SPI_EnableBusyState(void); 43 | void OPENBL_SPI_DisableBusyState(void); 44 | 45 | #if defined (__ICCARM__) 46 | __ramfunc uint8_t OPENBL_SPI_ReadByte(void); 47 | __ramfunc void OPENBL_SPI_SendByte(uint8_t Byte); 48 | __ramfunc void OPENBL_SPI_IRQHandler(void); 49 | __ramfunc void OPENBL_SPI_SendBusyByte(void); 50 | #else 51 | __attribute__((section(".ramfunc"))) uint8_t OPENBL_SPI_ReadByte(void); 52 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_SendByte(uint8_t Byte); 53 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_IRQHandler(void); 54 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_SendBusyByte(void); 55 | #endif /* (__ICCARM__) */ 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* SPI_INTERFACE_H */ 62 | -------------------------------------------------------------------------------- /Interfaces/Templates/SPI/spi_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for spi_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef SPI_INTERFACE_H 21 | #define SPI_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "openbl_core.h" 30 | 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions --------------------------------------------------------*/ 35 | void OPENBL_SPI_Configuration(void); 36 | void OPENBL_SPI_DeInit(void); 37 | uint8_t OPENBL_SPI_ProtocolDetection(void); 38 | uint8_t OPENBL_SPI_GetCommandOpcode(void); 39 | void OPENBL_SPI_SendAcknowledgeByte(uint8_t Byte); 40 | void OPENBL_SPI_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd); 41 | 42 | void OPENBL_SPI_EnableBusyState(void); 43 | void OPENBL_SPI_DisableBusyState(void); 44 | 45 | #if defined (__ICCARM__) 46 | __ramfunc uint8_t OPENBL_SPI_ReadByte(void); 47 | __ramfunc void OPENBL_SPI_SendByte(uint8_t Byte); 48 | __ramfunc void OPENBL_SPI_IRQHandler(void); 49 | __ramfunc void OPENBL_SPI_SendBusyByte(void); 50 | #else 51 | __attribute__((section(".ramfunc"))) uint8_t OPENBL_SPI_ReadByte(void); 52 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_SendByte(uint8_t Byte); 53 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_IRQHandler(void); 54 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_SendBusyByte(void); 55 | #endif /* (__ICCARM__) */ 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* SPI_INTERFACE_H */ 62 | -------------------------------------------------------------------------------- /Interfaces/Patterns/I2C/i2c_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file i2c_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for i2c_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef I2C_INTERFACE_H 21 | #define I2C_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "common_interface.h" 30 | #include "openbl_core.h" 31 | 32 | /* Exported types ------------------------------------------------------------*/ 33 | /* Exported constants --------------------------------------------------------*/ 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported functions ------------------------------------------------------- */ 36 | void OPENBL_I2C_Configuration(void); 37 | void OPENBL_I2C_DeInit(void); 38 | uint8_t OPENBL_I2C_ProtocolDetection(void); 39 | 40 | uint8_t OPENBL_I2C_GetCommandOpcode(void); 41 | uint8_t OPENBL_I2C_ReadByte(void); 42 | void OPENBL_I2C_SendByte(uint8_t Byte); 43 | void OPENBL_I2C_WaitAddress(void); 44 | void OPENBL_I2C_SendAcknowledgeByte(uint8_t Byte); 45 | void OPENBL_I2C_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *Frame); 46 | void OPENBL_Enable_BusyState_Sending(void); 47 | void OPENBL_Disable_BusyState_Sending(void); 48 | 49 | #if defined (__ICCARM__) 50 | __ramfunc void OPENBL_I2C_WaitNack(void); 51 | __ramfunc void OPENBL_I2C_WaitStop(void); 52 | __ramfunc void OPENBL_I2C_SendBusyByte(void); 53 | #else 54 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_WaitNack(void); 55 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_WaitStop(void); 56 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_SendBusyByte(void); 57 | #endif /* (__ICCARM__) */ 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* I2C_INTERFACE_H */ 64 | -------------------------------------------------------------------------------- /Interfaces/Templates/I2C/i2c_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file i2c_interface.h 4 | * @author MCD Application Team 5 | * @brief Header for i2c_interface.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef I2C_INTERFACE_H 21 | #define I2C_INTERFACE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | #include "common_interface.h" 30 | #include "openbl_core.h" 31 | 32 | /* Exported types ------------------------------------------------------------*/ 33 | /* Exported constants --------------------------------------------------------*/ 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported functions ------------------------------------------------------- */ 36 | void OPENBL_I2C_Configuration(void); 37 | void OPENBL_I2C_DeInit(void); 38 | uint8_t OPENBL_I2C_ProtocolDetection(void); 39 | 40 | uint8_t OPENBL_I2C_GetCommandOpcode(void); 41 | uint8_t OPENBL_I2C_ReadByte(void); 42 | void OPENBL_I2C_SendByte(uint8_t Byte); 43 | void OPENBL_I2C_WaitAddress(void); 44 | void OPENBL_I2C_SendAcknowledgeByte(uint8_t Byte); 45 | void OPENBL_I2C_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *Frame); 46 | void OPENBL_Enable_BusyState_Sending(void); 47 | void OPENBL_Disable_BusyState_Sending(void); 48 | 49 | #if defined (__ICCARM__) 50 | __ramfunc void OPENBL_I2C_WaitNack(void); 51 | __ramfunc void OPENBL_I2C_WaitStop(void); 52 | __ramfunc void OPENBL_I2C_SendBusyByte(void); 53 | #else 54 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_WaitNack(void); 55 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_WaitStop(void); 56 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_SendBusyByte(void); 57 | #endif /* (__ICCARM__) */ 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* I2C_INTERFACE_H */ 64 | -------------------------------------------------------------------------------- /Modules/FDCAN/openbl_fdcan_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_fdcan_cmd.h 4 | * @author MCD Application Team 5 | * @brief Header for openbl_fdcan_cmd.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBL_FDCAN_CMD_H 21 | #define OPENBL_FDCAN_CMD_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | #define OPENBL_FDCAN_VERSION 0x10U /* Open Bootloader FDCAN protocol V1.0 */ 31 | #define FDCAN_RAM_BUFFER_SIZE 1164U /* Size of FDCAN buffer used to store received data from the host */ 32 | 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported variables --------------------------------------------------------*/ 35 | extern uint8_t TxData[FDCAN_RAM_BUFFER_SIZE]; 36 | extern uint8_t RxData[FDCAN_RAM_BUFFER_SIZE]; 37 | 38 | /* Exported functions ------------------------------------------------------- */ 39 | OPENBL_CommandsTypeDef *OPENBL_FDCAN_GetCommandsList(void); 40 | void OPENBL_FDCAN_SetCommandsList(OPENBL_CommandsTypeDef *pFdcanCmd); 41 | void OPENBL_FDCAN_GetCommand(void); 42 | void OPENBL_FDCAN_GetVersion(void); 43 | void OPENBL_FDCAN_GetID(void); 44 | void OPENBL_FDCAN_ReadMemory(void); 45 | void OPENBL_FDCAN_WriteMemory(void); 46 | void OPENBL_FDCAN_Go(void); 47 | void OPENBL_FDCAN_ReadoutProtect(void); 48 | void OPENBL_FDCAN_ReadoutUnprotect(void); 49 | void OPENBL_FDCAN_EraseMemory(void); 50 | void OPENBL_FDCAN_WriteProtect(void); 51 | void OPENBL_FDCAN_WriteUnprotect(void); 52 | void OPENBL_FDCAN_SpecialCommand(void); 53 | void OPENBL_FDCAN_ExtendedSpecialCommand(void); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif /* __cplusplus */ 58 | 59 | #endif /* OPENBL_FDCAN_CMD_H */ 60 | -------------------------------------------------------------------------------- /Modules/I2C/openbl_i2c_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_i2c_cmd.h 4 | * @author MCD Application Team 5 | * @brief Header for openbl_i2c_cmd.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBL_I2C_CMD_H 21 | #define OPENBL_I2C_CMD_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "openbl_core.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | #define OPENBL_I2C_VERSION 0x12U /* Open Bootloader I2C protocol V1.2 */ 33 | 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported variables --------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | OPENBL_CommandsTypeDef *OPENBL_I2C_GetCommandsList(void); 38 | void OPENBL_I2C_SetCommandsList(OPENBL_CommandsTypeDef *pI2cCmd); 39 | void OPENBL_I2C_GetCommand(void); 40 | void OPENBL_I2C_GetVersion(void); 41 | void OPENBL_I2C_GetID(void); 42 | void OPENBL_I2C_ReadMemory(void); 43 | void OPENBL_I2C_WriteMemory(void); 44 | void OPENBL_I2C_Go(void); 45 | void OPENBL_I2C_ReadoutProtect(void); 46 | void OPENBL_I2C_ReadoutUnprotect(void); 47 | void OPENBL_I2C_EraseMemory(void); 48 | void OPENBL_I2C_WriteProtect(void); 49 | void OPENBL_I2C_WriteUnprotect(void); 50 | void OPENBL_I2C_NonStretchWriteMemory(void); 51 | void OPENBL_I2C_NonStretchEraseMemory(void); 52 | void OPENBL_I2C_NonStretchWriteProtect(void); 53 | void OPENBL_I2C_NonStretchWriteUnprotect(void); 54 | void OPENBL_I2C_NonStretchReadoutProtect(void); 55 | void OPENBL_I2C_NonStretchReadoutUnprotect(void); 56 | void OPENBL_I2C_SpecialCommand(void); 57 | void OPENBL_I2C_ExtendedSpecialCommand(void); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif /* __cplusplus */ 62 | 63 | #endif /* OPENBL_I2C_CMD_H */ 64 | -------------------------------------------------------------------------------- /Interfaces/Templates/USB/usb_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains USB protocol commands 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "usb_interface.h" 22 | #include "app_usbx_device.h" 23 | #include "app_azure_rtos.h" 24 | #include "openbl_core.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | static uint8_t UsbDetected = 0U; 31 | 32 | /* Exported variables --------------------------------------------------------*/ 33 | uint8_t UsbSofDetected = 0U; 34 | 35 | PCD_HandleTypeDef hpcd_USB_OTG_FS; 36 | 37 | /* External variables --------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Exported functions --------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief This function is used to configure USB pins and then initialize the used USB instance. 43 | * @retval None. 44 | */ 45 | void OPENBL_USB_Configuration(void) 46 | { 47 | } 48 | 49 | /** 50 | * @brief This function is used to De-initialize the USB pins and instance. 51 | * @retval None. 52 | */ 53 | void OPENBL_USB_DeInit(void) 54 | { 55 | } 56 | 57 | /** 58 | * @brief This function is used to detect if there is any activity on USB protocol. 59 | * @retval Returns 1 if interface is detected else 0. 60 | */ 61 | uint8_t OPENBL_USB_ProtocolDetection(void) 62 | { 63 | return UsbDetected; 64 | } 65 | 66 | /** 67 | * @brief Gets the page of a given address. 68 | * @param Address Address of the FLASH Memory. 69 | * @retval The page of a given address. 70 | */ 71 | uint32_t OPENBL_USB_GetPage(uint32_t Address) 72 | { 73 | uint32_t page; 74 | 75 | return page; 76 | } 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing guide 2 | 3 | This guide serves as a checklist before contributing to this repository. It mainly focuses on the steps to follow to submit an issue or a pull-request. 4 | 5 | ### 1. Issues 6 | 7 | #### 1.1 Before opening an issue 8 | 9 | Please check the following points before posting an issue: 10 | * Make sure you are using the latest commit (major releases are tagged, but corrections are available as new commits). 11 | * Make sure your issue is a question/feedback/suggestions **related to** the software provided in this repository. Otherwise, please refer to section [3](CONTRIBUTING.md#3.-support-requests-and-questions) below. 12 | * Make sure your issue is not already reported/fixed on GitHub or discussed on a previous issue. 13 | 14 | #### 1.2 Posting the issue 15 | 16 | When you have checked the previous points, create a new report from the **Issues** tab of this repository. A template is available [here](issues/new/choose) to help you report the issue you are facing or the enhancement you would like to propose. 17 | 18 | ### 2. Pull Requests 19 | 20 | #### 2.1 Before opening a pull-request 21 | 22 | STMicrolectronics is happy to receive contributions from the community, based on an initial Contributor License Agreement (CLA) procedure. 23 | 24 | * If you are an individual writing original source code and you are sure **you own the intellectual property**, then you need to sign an Individual [CLA](https://cla.st.com). 25 | * If you work for a company that wants also to allow you to contribute with your work, your company needs to provide a Corporate [CLA](https://cla.st.com) mentioning your GitHub account name. 26 | * If you are not sure that a CLA (Individual or Corporate) has been signed for your GitHub account you can check the [CLA](https://cla.st.com) dedicated page. 27 | 28 | Please note that: 29 | * The Corporate CLA will always take precedence over the Individual CLA. 30 | * One CLA submission is sufficient, for any project proposed by STMicroelectronics. 31 | 32 | #### 2.2 How to proceed 33 | 34 | * We recommend to engage first a communication thru an issue, in order to present your proposal, just to confirm that it corresponds to STMicroelectronics' domain or scope. 35 | * Then fork the project to your GitHub account to further develop your contribution. Please use the latest commit version. 36 | * Please, submit one pull-request per new feature or proposal. This will ease the analysis and the final merge if accepted. 37 | 38 | ### 3. Support requests and questions 39 | 40 | For support requests or any other question related to the product, the tools, the environment, you can submit a post to the **ST Community** on the appropriate topic [page](https://community.st.com/s/topiccatalog). 41 | -------------------------------------------------------------------------------- /Interfaces/Templates/COMMON/common_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file common_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains common functions used by different interfaces 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "flash_interface.h" 22 | #include "openbootloader_conf.h" 23 | #include "common_interface.h" 24 | 25 | /* Private typedef -----------------------------------------------------------*/ 26 | /* Private define ------------------------------------------------------------*/ 27 | /* Private macro -------------------------------------------------------------*/ 28 | /* Private variables ---------------------------------------------------------*/ 29 | static Function_Pointer ResetCallback; 30 | 31 | /* Private function prototypes -----------------------------------------------*/ 32 | /* Private functions ---------------------------------------------------------*/ 33 | /* Exported functions --------------------------------------------------------*/ 34 | 35 | /** 36 | * @brief Assigns the given value to the Main Stack Pointer (MSP). 37 | * @param TopOfMainStack Main Stack Pointer value to set. 38 | * @retval None. 39 | */ 40 | void Common_SetMsp(uint32_t TopOfMainStack) 41 | { 42 | } 43 | 44 | /** 45 | * @brief Enable IRQ Interrupts. 46 | * @retval None. 47 | */ 48 | void Common_EnableIrq(void) 49 | { 50 | } 51 | 52 | /** 53 | * @brief Disable IRQ Interrupts. 54 | * @retval None. 55 | */ 56 | void Common_DisableIrq(void) 57 | { 58 | } 59 | 60 | /** 61 | * @brief Checks whether the target Protection Status is set or not. 62 | * @retval Returns SET if protection is enabled else return RESET. 63 | */ 64 | FlagStatus Common_GetProtectionStatus(void) 65 | { 66 | FlagStatus status; 67 | 68 | return status; 69 | } 70 | 71 | /** 72 | * @brief Register a callback function to be called at the end of commands processing. 73 | * @retval None. 74 | */ 75 | void Common_SetPostProcessingCallback(Function_Pointer Callback) 76 | { 77 | ResetCallback = Callback; 78 | } 79 | 80 | /** 81 | * @brief Start post processing task. 82 | * @retval None. 83 | */ 84 | void Common_StartPostProcessing() 85 | { 86 | } 87 | -------------------------------------------------------------------------------- /Interfaces/Templates/OPTION BYTES/optionbytes_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file optionbytes_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains Option Bytes access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "optionbytes_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Exported variables --------------------------------------------------------*/ 32 | OPENBL_MemoryTypeDef OB_Descriptor = 33 | { 34 | OB_START_ADDRESS, 35 | OB_END_ADDRESS, 36 | OB_SIZE, 37 | OB_AREA, 38 | OPENBL_OB_Read, 39 | OPENBL_OB_Write, 40 | NULL, 41 | NULL, 42 | NULL, 43 | NULL, 44 | NULL 45 | }; 46 | 47 | /* Exported functions --------------------------------------------------------*/ 48 | 49 | /** 50 | * @brief Launch the option byte loading. 51 | * @retval None. 52 | */ 53 | void OPENBL_OB_Launch(void) 54 | { 55 | } 56 | 57 | /** 58 | * @brief This function is used to read data from a given address. 59 | * @param Address The address to be read. 60 | * @retval Returns the read value. 61 | */ 62 | uint8_t OPENBL_OB_Read(uint32_t Address) 63 | { 64 | return (*(uint8_t *)(Address)); 65 | } 66 | 67 | /** 68 | * @brief Write Flash OB keys to unlock the option bytes settings 69 | * @param None 70 | * @retval None 71 | */ 72 | void BL_FLASH_WriteOptKeys(void) 73 | { 74 | } 75 | /** 76 | * @brief This function is used to write data in Option bytes. 77 | * @param Address The address where that data will be written. 78 | * @param Data The data to be written. 79 | * @param DataLength The length of the data to be written. 80 | * @retval None. 81 | */ 82 | void OPENBL_OB_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength) 83 | { 84 | } 85 | -------------------------------------------------------------------------------- /Interfaces/Templates/RAM/ram_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ram_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains RAM access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "openbl_core.h" 25 | #include "ram_interface.h" 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* Private define ------------------------------------------------------------*/ 29 | /* Private macro -------------------------------------------------------------*/ 30 | /* Private variables ---------------------------------------------------------*/ 31 | /* Private function prototypes -----------------------------------------------*/ 32 | /* Exported variables --------------------------------------------------------*/ 33 | OPENBL_MemoryTypeDef RAM_Descriptor = 34 | { 35 | RAM_START_ADDRESS + OPENBL_RAM_SIZE, /* OPENBL_RAM_SIZE is added to protect OpenBootloader RAM area */ 36 | RAM_END_ADDRESS, 37 | RAM_SIZE, 38 | RAM_AREA, 39 | OPENBL_RAM_Read, 40 | OPENBL_RAM_Write, 41 | NULL, 42 | NULL, 43 | OPENBL_RAM_JumpToAddress, 44 | NULL, 45 | NULL 46 | }; 47 | 48 | /* Exported functions --------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief This function is used to read data from a given address. 52 | * @param Address The address to be read. 53 | * @retval Returns the read value. 54 | */ 55 | uint8_t OPENBL_RAM_Read(uint32_t Address) 56 | { 57 | return (*(uint8_t *)(Address)); 58 | } 59 | 60 | /** 61 | * @brief This function is used to write data in RAM memory. 62 | * @param Address The address where that data will be written. 63 | * @param pData The data to be written. 64 | * @param DataLength The length of the data to be written. 65 | * @retval None. 66 | */ 67 | void OPENBL_RAM_Write(uint32_t Address, uint8_t *pData, uint32_t DataLength) 68 | { 69 | } 70 | 71 | /** 72 | * @brief This function is used to jump to a given address. 73 | * @param Address The address where the function will jump. 74 | * @retval None. 75 | */ 76 | void OPENBL_RAM_JumpToAddress(uint32_t Address) 77 | { 78 | } 79 | -------------------------------------------------------------------------------- /Modules/Mem/openbl_mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_mem.h 4 | * @author MCD Application Team 5 | * @brief Header for openbl_mem.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBL_MEM_H 21 | #define OPENBL_MEM_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "openbootloader_conf.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | typedef struct 32 | { 33 | uint32_t StartAddress; 34 | uint32_t EndAddress; 35 | uint32_t Size; 36 | uint32_t Type; 37 | uint8_t (*Read)(uint32_t Address); 38 | void (*Write)(uint32_t Address, uint8_t *Data, uint32_t DataLength); 39 | void (*SetReadoutProtect)(uint32_t State); 40 | ErrorStatus(*SetWriteProtect)(FunctionalState State, uint8_t *Buffer, uint32_t Length); 41 | void (*JumpToAddress)(uint32_t Address); 42 | ErrorStatus(*MassErase)(uint8_t *p_Data, uint32_t DataLength); 43 | ErrorStatus(*Erase)(uint8_t *p_Data, uint32_t DataLength); 44 | } OPENBL_MemoryTypeDef; 45 | 46 | /* Exported constants --------------------------------------------------------*/ 47 | /* Exported macro ------------------------------------------------------------*/ 48 | /* Exported functions ------------------------------------------------------- */ 49 | void OPENBL_MEM_JumpToAddress(uint32_t Address); 50 | void OPENBL_MEM_SetReadOutProtection(uint32_t Address, FunctionalState State); 51 | void OPENBL_MEM_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength); 52 | 53 | uint8_t OPENBL_MEM_Read(uint32_t Address, uint32_t MemoryIndex); 54 | uint32_t OPENBL_MEM_GetAddressArea(uint32_t Address); 55 | uint32_t OPENBL_MEM_GetMemoryIndex(uint32_t Address); 56 | uint8_t OPENBL_MEM_CheckJumpAddress(uint32_t Address); 57 | 58 | ErrorStatus OPENBL_MEM_Erase(uint32_t Address, uint8_t *p_Data, uint32_t DataLength); 59 | ErrorStatus OPENBL_MEM_MassErase(uint32_t Address, uint8_t *p_Data, uint32_t DataLength); 60 | ErrorStatus OPENBL_MEM_RegisterMemory(OPENBL_MemoryTypeDef *Memory); 61 | ErrorStatus OPENBL_MEM_SetWriteProtection(FunctionalState State, uint32_t Address, uint8_t *Buffer, uint32_t Length); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif /* __cplusplus */ 66 | 67 | #endif /* OPENBL_MEM_H */ 68 | -------------------------------------------------------------------------------- /Interfaces/Templates/OTP/otp_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file otp_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains One-time programmable access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "otp_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | /* Private function prototypes -----------------------------------------------*/ 31 | static void OPENBL_OTP_ProgramDoubleWord(uint32_t Address, uint64_t Data); 32 | 33 | /* Exported variables --------------------------------------------------------*/ 34 | OPENBL_MemoryTypeDef OTP_Descriptor = 35 | { 36 | OTP_START_ADDRESS, 37 | OTP_END_ADDRESS, 38 | OTP_BL_SIZE, 39 | OTP_AREA, 40 | OPENBL_OTP_Read, 41 | OPENBL_OTP_Write, 42 | NULL, 43 | NULL, 44 | NULL, 45 | NULL, 46 | NULL 47 | }; 48 | 49 | /* Exported functions --------------------------------------------------------*/ 50 | 51 | /** 52 | * @brief This function is used to read data from a given address. 53 | * @param Address The address to be read. 54 | * @retval Returns the read value. 55 | */ 56 | uint8_t OPENBL_OTP_Read(uint32_t Address) 57 | { 58 | return (*(uint8_t *)(Address)); 59 | } 60 | 61 | /** 62 | * @brief This function is used to write data in OTP. 63 | * @param Address The address where that data will be written. 64 | * @param Data The data to be written. 65 | * @param DataLength The length of the data to be written. 66 | * @retval None. 67 | */ 68 | void OPENBL_OTP_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength) 69 | { 70 | } 71 | 72 | /* Private functions ---------------------------------------------------------*/ 73 | 74 | /** 75 | * @brief Program double word at a specified FLASH address. 76 | * @param Address specifies the address to be programmed. 77 | * @param Data specifies the data to be programmed. 78 | * @retval None. 79 | */ 80 | static void OPENBL_OTP_ProgramDoubleWord(uint32_t Address, uint64_t Data) 81 | { 82 | } 83 | -------------------------------------------------------------------------------- /Interfaces/Patterns/COMMON/common_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file common_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains common functions used by different interfaces 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "flash_interface.h" 22 | #include "openbootloader_conf.h" 23 | #include "common_interface.h" 24 | 25 | /* Private typedef -----------------------------------------------------------*/ 26 | /* Private define ------------------------------------------------------------*/ 27 | /* Private macro -------------------------------------------------------------*/ 28 | /* Private variables ---------------------------------------------------------*/ 29 | static Function_Pointer ResetCallback; 30 | 31 | /* Private function prototypes -----------------------------------------------*/ 32 | /* Private functions ---------------------------------------------------------*/ 33 | /* Exported functions --------------------------------------------------------*/ 34 | 35 | /** 36 | * @brief Assigns the given value to the Main Stack Pointer (MSP). 37 | * @param TopOfMainStack Main Stack Pointer value to set. 38 | * @retval None. 39 | */ 40 | void Common_SetMsp(uint32_t TopOfMainStack) 41 | { 42 | __set_MSP(TopOfMainStack); 43 | } 44 | 45 | /** 46 | * @brief Enable IRQ Interrupts. 47 | * @retval None. 48 | */ 49 | void Common_EnableIrq(void) 50 | { 51 | __enable_irq(); 52 | } 53 | 54 | /** 55 | * @brief Disable IRQ Interrupts. 56 | * @retval None. 57 | */ 58 | void Common_DisableIrq(void) 59 | { 60 | __disable_irq(); 61 | } 62 | 63 | /** 64 | * @brief Checks whether the target Protection Status is set or not. 65 | * @retval Returns SET if protection is enabled else return RESET. 66 | */ 67 | FlagStatus Common_GetProtectionStatus(void) 68 | { 69 | FlagStatus status; 70 | 71 | if (OPENBL_FLASH_GetReadOutProtectionLevel() != RDP_LEVEL_0) 72 | { 73 | status = SET; 74 | } 75 | else 76 | { 77 | status = RESET; 78 | } 79 | 80 | return status; 81 | } 82 | 83 | /** 84 | * @brief Register a callback function to be called at the end of commands processing. 85 | * @retval None. 86 | */ 87 | void Common_SetPostProcessingCallback(Function_Pointer Callback) 88 | { 89 | ResetCallback = Callback; 90 | } 91 | 92 | /** 93 | * @brief Start post processing task. 94 | * @retval None. 95 | */ 96 | void Common_StartPostProcessing() 97 | { 98 | if (ResetCallback != NULL) 99 | { 100 | ResetCallback(); 101 | 102 | /* In case there is no system reset, we must reset the callback */ 103 | ResetCallback = NULL; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team via this [link](https://www.st.com/content/st_com/en/contact-us.html). 59 | All complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4, 71 | available [here](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html). 72 | 73 | For answers to common questions about this code of conduct, refer to the FAQ section [here](https://www.contributor-covenant.org/faq). 74 | -------------------------------------------------------------------------------- /Interfaces/Patterns/OTP/otp_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file otp_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains One-time programmable access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "otp_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | /* Private function prototypes -----------------------------------------------*/ 31 | static void OPENBL_OTP_ProgramDoubleWord(uint32_t Address, uint64_t Data); 32 | 33 | /* Exported variables --------------------------------------------------------*/ 34 | OPENBL_MemoryTypeDef OTP_Descriptor = 35 | { 36 | OTP_START_ADDRESS, 37 | OTP_END_ADDRESS, 38 | OTP_BL_SIZE, 39 | OTP_AREA, 40 | OPENBL_OTP_Read, 41 | OPENBL_OTP_Write, 42 | NULL, 43 | NULL, 44 | NULL, 45 | NULL, 46 | NULL 47 | }; 48 | 49 | /* Exported functions --------------------------------------------------------*/ 50 | 51 | /** 52 | * @brief This function is used to read data from a given address. 53 | * @param Address The address to be read. 54 | * @retval Returns the read value. 55 | */ 56 | uint8_t OPENBL_OTP_Read(uint32_t Address) 57 | { 58 | return (*(uint8_t *)(Address)); 59 | } 60 | 61 | /** 62 | * @brief This function is used to write data in OTP. 63 | * @param Address The address where that data will be written. 64 | * @param Data The data to be written. 65 | * @param DataLength The length of the data to be written. 66 | * @retval None. 67 | */ 68 | void OPENBL_OTP_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength) 69 | { 70 | uint32_t index = 0U; 71 | uint32_t length = DataLength; 72 | 73 | if (length & 7U) 74 | { 75 | length = (length & 0xFFFFFFF8U) + 8U; 76 | } 77 | 78 | /* Unlock the flash memory for write operation */ 79 | HAL_FLASH_Unlock(); 80 | 81 | for (index = 0U; index < length; (index += 8U)) 82 | { 83 | OPENBL_OTP_ProgramDoubleWord((Address + index), (uint64_t)(*((uint64_t *)((uint32_t)Data + index)))); 84 | } 85 | 86 | /* Lock the Flash to disable the flash control register access */ 87 | HAL_FLASH_Lock(); 88 | } 89 | 90 | /* Private functions ---------------------------------------------------------*/ 91 | 92 | /** 93 | * @brief Program double word at a specified FLASH address. 94 | * @param Address specifies the address to be programmed. 95 | * @param Data specifies the data to be programmed. 96 | * @retval None. 97 | */ 98 | static void OPENBL_OTP_ProgramDoubleWord(uint32_t Address, uint64_t Data) 99 | { 100 | HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, Data); 101 | } 102 | -------------------------------------------------------------------------------- /Interfaces/Patterns/RAM/ram_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ram_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains RAM access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "openbl_core.h" 25 | #include "ram_interface.h" 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* Private define ------------------------------------------------------------*/ 29 | /* Private macro -------------------------------------------------------------*/ 30 | /* Private variables ---------------------------------------------------------*/ 31 | /* Private function prototypes -----------------------------------------------*/ 32 | /* Exported variables --------------------------------------------------------*/ 33 | OPENBL_MemoryTypeDef RAM_Descriptor = 34 | { 35 | RAM_START_ADDRESS + OPENBL_RAM_SIZE, /* OPENBL_RAM_SIZE is added to protect OpenBootloader RAM area */ 36 | RAM_END_ADDRESS, 37 | RAM_SIZE, 38 | RAM_AREA, 39 | OPENBL_RAM_Read, 40 | OPENBL_RAM_Write, 41 | NULL, 42 | NULL, 43 | OPENBL_RAM_JumpToAddress, 44 | NULL, 45 | NULL 46 | }; 47 | 48 | /* Exported functions --------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief This function is used to read data from a given address. 52 | * @param Address The address to be read. 53 | * @retval Returns the read value. 54 | */ 55 | uint8_t OPENBL_RAM_Read(uint32_t Address) 56 | { 57 | return (*(uint8_t *)(Address)); 58 | } 59 | 60 | /** 61 | * @brief This function is used to write data in RAM memory. 62 | * @param Address The address where that data will be written. 63 | * @param pData The data to be written. 64 | * @param DataLength The length of the data to be written. 65 | * @retval None. 66 | */ 67 | void OPENBL_RAM_Write(uint32_t Address, uint8_t *pData, uint32_t DataLength) 68 | { 69 | uint32_t index; 70 | uint32_t aligned_length = DataLength; 71 | 72 | if (aligned_length & 0x3) 73 | { 74 | aligned_length = (aligned_length & 0xFCU) + 4U; 75 | } 76 | 77 | for (index = 0U; index < aligned_length; index += 4U) 78 | { 79 | *(__IO uint32_t *)(Address + index) = *(__IO uint32_t *)(pData + index); 80 | } 81 | } 82 | 83 | /** 84 | * @brief This function is used to jump to a given address. 85 | * @param Address The address where the function will jump. 86 | * @retval None. 87 | */ 88 | void OPENBL_RAM_JumpToAddress(uint32_t Address) 89 | { 90 | Function_Pointer jump_to_address; 91 | 92 | /* De-initialize all HW resources used by the Open Bootloader to their reset values */ 93 | OPENBL_DeInit(); 94 | 95 | /* Enable IRQ */ 96 | Common_EnableIrq(); 97 | 98 | jump_to_address = (Function_Pointer)(*(__IO uint32_t *)(Address + 4U)); 99 | 100 | /* Initialize user application's stack pointer */ 101 | Common_SetMsp(*(__IO uint32_t *) Address); 102 | 103 | jump_to_address(); 104 | } 105 | -------------------------------------------------------------------------------- /Interfaces/Templates/USART/usart_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usart_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains USART HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "interfaces_conf.h" 22 | #include "openbl_core.h" 23 | #include "openbl_usart_cmd.h" 24 | #include "usart_interface.h" 25 | #include "iwdg_interface.h" 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* Private define ------------------------------------------------------------*/ 29 | /* Private macro -------------------------------------------------------------*/ 30 | /* Private variables ---------------------------------------------------------*/ 31 | static uint8_t UsartDetected = 0U; 32 | 33 | /* Exported variables --------------------------------------------------------*/ 34 | /* Private function prototypes -----------------------------------------------*/ 35 | static void OPENBL_USART_Init(void); 36 | 37 | /* Private functions ---------------------------------------------------------*/ 38 | 39 | /** 40 | * @brief This function is used to initialize the used USART instance. 41 | * @retval None. 42 | */ 43 | static void OPENBL_USART_Init(void) 44 | { 45 | } 46 | 47 | /* Exported functions --------------------------------------------------------*/ 48 | 49 | /** 50 | * @brief This function is used to configure USART pins and then initialize the used USART instance. 51 | * @retval None. 52 | */ 53 | void OPENBL_USART_Configuration(void) 54 | { 55 | } 56 | 57 | /** 58 | * @brief This function is used to De-initialize the USART pins and instance. 59 | * @retval None. 60 | */ 61 | void OPENBL_USART_DeInit(void) 62 | { 63 | } 64 | 65 | /** 66 | * @brief This function is used to detect if there is any activity on USART protocol. 67 | * @retval Returns 1 if interface is detected else 0. 68 | */ 69 | uint8_t OPENBL_USART_ProtocolDetection(void) 70 | { 71 | return UsartDetected; 72 | } 73 | 74 | /** 75 | * @brief This function is used to get the command opcode from the host. 76 | * @retval Returns the command. 77 | */ 78 | uint8_t OPENBL_USART_GetCommandOpcode(void) 79 | { 80 | uint8_t command_opc = 0x0; 81 | 82 | return command_opc; 83 | } 84 | 85 | /** 86 | * @brief This function is used to read one byte from USART pipe. 87 | * @retval Returns the read byte. 88 | */ 89 | uint8_t OPENBL_USART_ReadByte(void) 90 | { 91 | return LL_USART_ReceiveData8(USARTx); 92 | } 93 | 94 | /** 95 | * @brief This function is used to send one byte through USART pipe. 96 | * @param Byte The byte to be sent. 97 | * @retval None. 98 | */ 99 | void OPENBL_USART_SendByte(uint8_t Byte) 100 | { 101 | } 102 | 103 | /** 104 | * @brief This function is used to process and execute the special commands. 105 | * The user must define the special commands routine here. 106 | * @param SpecialCmd Pointer to the OPENBL_SpecialCmdTypeDef structure. 107 | * @retval Returns NACK status in case of error else returns ACK status. 108 | */ 109 | void OPENBL_USART_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd) 110 | { 111 | } 112 | -------------------------------------------------------------------------------- /Interfaces/Templates/FDCAN/fdcan_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file fdcan_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains FDCAN HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "interfaces_conf.h" 22 | #include "openbl_core.h" 23 | #include "openbl_fdcan_cmd.h" 24 | #include "fdcan_interface.h" 25 | #include "iwdg_interface.h" 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* Private define ------------------------------------------------------------*/ 29 | /* Private macro -------------------------------------------------------------*/ 30 | /* Private variables ---------------------------------------------------------*/ 31 | static FDCAN_HandleTypeDef hfdcan; 32 | static FDCAN_FilterTypeDef sFilterConfig; 33 | static FDCAN_TxHeaderTypeDef TxHeader; 34 | static FDCAN_RxHeaderTypeDef RxHeader; 35 | static uint8_t FdcanDetected = 0U; 36 | 37 | /* Exported variables --------------------------------------------------------*/ 38 | uint8_t TxData[FDCAN_RAM_BUFFER_SIZE]; 39 | uint8_t RxData[FDCAN_RAM_BUFFER_SIZE]; 40 | 41 | /* Private function prototypes -----------------------------------------------*/ 42 | static void OPENBL_FDCAN_Init(void); 43 | 44 | /* Private functions ---------------------------------------------------------*/ 45 | /** 46 | * @brief This function is used to initialize the used FDCAN instance. 47 | * @retval None. 48 | */ 49 | static void OPENBL_FDCAN_Init(void) 50 | { 51 | } 52 | 53 | /* Exported functions --------------------------------------------------------*/ 54 | 55 | /** 56 | * @brief This function is used to configure FDCAN pins and then initialize the used FDCAN instance. 57 | * @retval None. 58 | */ 59 | void OPENBL_FDCAN_Configuration(void) 60 | { 61 | } 62 | 63 | /** 64 | * @brief This function is used to De-initialize the FDCAN pins and instance. 65 | * @retval None. 66 | */ 67 | void OPENBL_FDCAN_DeInit(void) 68 | { 69 | } 70 | 71 | /** 72 | * @brief This function is used to detect if there is any activity on FDCAN protocol. 73 | * @retval Returns 1 if interface is detected else 0.. 74 | */ 75 | uint8_t OPENBL_FDCAN_ProtocolDetection(void) 76 | { 77 | return FdcanDetected; 78 | } 79 | 80 | /** 81 | * @brief This function is used to get the command opcode from the host. 82 | * @retval Returns the command. 83 | */ 84 | uint8_t OPENBL_FDCAN_GetCommandOpcode(void) 85 | { 86 | uint8_t command_opc = 0x0; 87 | 88 | return command_opc; 89 | } 90 | 91 | /** 92 | * @brief This function is used to read one byte from FDCAN pipe. 93 | * @retval Returns the read byte. 94 | */ 95 | uint8_t OPENBL_FDCAN_ReadByte(void) 96 | { 97 | uint8_t byte; 98 | 99 | return byte; 100 | } 101 | 102 | /** 103 | * @brief This function is used to read bytes from FDCAN pipe. 104 | * @retval None. 105 | */ 106 | void OPENBL_FDCAN_ReadBytes(uint8_t *Buffer, uint32_t BufferSize) 107 | { 108 | } 109 | 110 | /** 111 | * @brief This function is used to send one byte through FDCAN pipe. 112 | * @param Byte The byte to be sent. 113 | * @retval None. 114 | */ 115 | void OPENBL_FDCAN_SendByte(uint8_t Byte) 116 | { 117 | } 118 | 119 | /** 120 | * @brief This function is used to send a buffer using FDCAN. 121 | * @param Buffer The data buffer to be sent. 122 | * @param BufferSize The size of the data buffer to be sent. 123 | * @retval None. 124 | */ 125 | void OPENBL_FDCAN_SendBytes(uint8_t *Buffer, uint32_t BufferSize) 126 | { 127 | } 128 | 129 | /** 130 | * @brief This function is used to process and execute the special commands. 131 | * The user must define the special commands routine here. 132 | * @retval Returns NACK status in case of error else returns ACK status. 133 | */ 134 | void OPENBL_FDCAN_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *Frame) 135 | { 136 | } 137 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | SLA0044 Rev5/February 2018 2 | 3 | ## Software license agreement 4 | 5 | ### __ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT__ 6 | 7 | BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE 8 | OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS 9 | INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES 10 | (STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON 11 | BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES 12 | TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. 13 | 14 | Under STMicroelectronics’ intellectual property rights, the redistribution, 15 | reproduction and use in source and binary forms of the software or any part 16 | thereof, with or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | 1. Redistribution of source code (modified or not) must retain any copyright 20 | notice, this list of conditions and the disclaimer set forth below as items 10 21 | and 11. 22 | 23 | 2. Redistributions in binary form, except as embedded into microcontroller or 24 | microprocessor device manufactured by or for STMicroelectronics or a software 25 | update for such device, must reproduce any copyright notice provided with the 26 | binary code, this list of conditions, and the disclaimer set forth below as 27 | items 10 and 11, in documentation and/or other materials provided with the 28 | distribution. 29 | 30 | 3. Neither the name of STMicroelectronics nor the names of other contributors to 31 | this software may be used to endorse or promote products derived from this 32 | software or part thereof without specific written permission. 33 | 34 | 4. This software or any part thereof, including modifications and/or derivative 35 | works of this software, must be used and execute solely and exclusively on or in 36 | combination with a microcontroller or microprocessor device manufactured by or 37 | for STMicroelectronics. 38 | 39 | 5. No use, reproduction or redistribution of this software partially or totally 40 | may be done in any manner that would subject this software to any Open Source 41 | Terms. “Open Source Terms” shall mean any open source license which requires as 42 | part of distribution of software that the source code of such software is 43 | distributed therewith or otherwise made available, or open source license that 44 | substantially complies with the Open Source definition specified at 45 | www.opensource.org and any other comparable open source license such as for 46 | example GNU General Public License (GPL), Eclipse Public License (EPL), Apache 47 | Software License, BSD license or MIT license. 48 | 49 | 6. STMicroelectronics has no obligation to provide any maintenance, support or 50 | updates for the software. 51 | 52 | 7. The software is and will remain the exclusive property of STMicroelectronics 53 | and its licensors. The recipient will not take any action that jeopardizes 54 | STMicroelectronics and its licensors' proprietary rights or acquire any rights 55 | in the software, except the limited rights specified hereunder. 56 | 57 | 8. The recipient shall comply with all applicable laws and regulations affecting 58 | the use of the software or any part thereof including any applicable export 59 | control law or regulation. 60 | 61 | 9. Redistribution and use of this software or any part thereof other than as 62 | permitted under this license is void and will automatically terminate your 63 | rights under this license. 64 | 65 | 10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND 66 | ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 67 | IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 68 | NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE 69 | DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL 70 | STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 71 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 72 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 73 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 74 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 75 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 76 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 77 | 78 | 11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER 79 | EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY 80 | RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. 81 | -------------------------------------------------------------------------------- /Interfaces/Patterns/USB/usb_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains USB protocol commands 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "usb_interface.h" 22 | #include "app_usbx_device.h" 23 | #include "app_azure_rtos.h" 24 | #include "openbl_core.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | static uint8_t UsbDetected = 0U; 31 | 32 | /* Exported variables --------------------------------------------------------*/ 33 | uint8_t UsbSofDetected = 0U; 34 | 35 | PCD_HandleTypeDef hpcd_USB_OTG_FS; 36 | 37 | /* External variables --------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Exported functions --------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief This function is used to configure USB pins and then initialize the used USB instance. 43 | * @retval None. 44 | */ 45 | void OPENBL_USB_Configuration(void) 46 | { 47 | /* Enable the USB GPIO clock */ 48 | __HAL_RCC_GPIOA_CLK_ENABLE(); 49 | 50 | hpcd_USB_OTG_FS.Instance = USB_OTG_FS; 51 | hpcd_USB_OTG_FS.Init.dev_endpoints = 6; 52 | hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED; 53 | hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE; 54 | hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE; 55 | hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE; 56 | hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE; 57 | hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE; 58 | hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE; 59 | 60 | if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK) 61 | { 62 | while (1); 63 | } 64 | 65 | /* Start device USB */ 66 | HAL_PCD_Start(&hpcd_USB_OTG_FS); 67 | } 68 | 69 | /** 70 | * @brief This function is used to De-initialize the USB pins and instance. 71 | * @retval None. 72 | */ 73 | void OPENBL_USB_DeInit(void) 74 | { 75 | /* Only de-initialize the USB if it is not the current detected interface */ 76 | if (UsbDetected == 0U) 77 | { 78 | HAL_PCD_DeInit(&hpcd_USB_OTG_FS); 79 | } 80 | } 81 | 82 | /** 83 | * @brief This function is used to detect if there is any activity on USB protocol. 84 | * @retval Returns 1 if interface is detected else 0. 85 | */ 86 | uint8_t OPENBL_USB_ProtocolDetection(void) 87 | { 88 | if (UsbSofDetected == 1U) 89 | { 90 | UsbDetected = 0U; 91 | 92 | /* Disable the other interfaces */ 93 | OPENBL_InterfacesDeInit(); 94 | 95 | /* The value of the variable "detect" will always be 0 and this is due to the fact that if this function returns 1, 96 | the USB interface will be disabled. 97 | For more details check the comment in the function "OpenBootloader_DetectInterfaceThread" 98 | in file "openbootloader_threadx.c" */ 99 | } 100 | else 101 | { 102 | UsbDetected = 0U; 103 | } 104 | 105 | return UsbDetected; 106 | } 107 | 108 | /** 109 | * @brief Gets the page of a given address. 110 | * @param Address Address of the FLASH Memory. 111 | * @retval The page of a given address. 112 | */ 113 | uint32_t OPENBL_USB_GetPage(uint32_t Address) 114 | { 115 | uint32_t page; 116 | 117 | if (Address < (FLASH_BASE + FLASH_BANK_SIZE)) 118 | { 119 | /* Bank 1 */ 120 | page = (Address - FLASH_BASE) / FLASH_PAGE_SIZE; 121 | } 122 | else 123 | { 124 | /* Bank 2 */ 125 | page = ((Address - (FLASH_BASE + FLASH_BANK_SIZE)) / FLASH_PAGE_SIZE) + 128U; 126 | } 127 | 128 | return page; 129 | } 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Middleware Open Bootloader MCU Component 2 | 3 | ![latest tag](https://img.shields.io/github/v/tag/STMicroelectronics/stm32-mw-openbl.svg?color=brightgreen) 4 | 5 | ## Overview 6 | 7 | **Open Bootloader** is an In-Application programming (IAP) provided in the STM32Cube MCU Packages and GitHub. It is fully compatible with STM32 System Bootloader so that it have the same supported interfaces and commands. It's also using the same Tools such as STM32CubeProgrammer. 8 | 9 | **Open Bootloader** is provided as an example that can be used by any customer who wants to build and customize his own Bootloader starting from a good basis. It allows all possible bootloader operations (Read, write, erase, jump...) into internal (Flash, SRAM, OTP...) or external memory using one of the available communication interfaces (USART, I2C, SPI, USB-DFU, FDCAN...). 10 | 11 | **Open Bootloader** supplies services to the Host (can be STM32CubeProgrammer or another user made host) in order to perform all possible Bootloader operations. 12 | 13 | **Open Bootloader** relies on STM32Cube HAL/LL drivers for hardware system initialization such as the clocks and the communication interfaces configuration. 14 | 15 | **Open Bootloader** code can be loaded at any address of user Flash memory with taking necessary precautions to avoid erasing or corrupting it by error (for example use write protection mechanism). 16 | 17 | **Open Bootloader** is executed by Cortex-M processor on the non-secure domain and uses the following resources: 18 | - Non secure internal flash memory/SRAM1 19 | - Interrupts 20 | - Clocks and power 21 | - Communication interfaces 22 | - GPIOs 23 | - Systick 24 | - IWDG 25 | 26 | **Open Bootloader** can be customized by changing its location (ie. load it in last user Flash sector or other sectors), its supported protocols, its supported interfaces, and its supported operations. 27 | 28 | **Open Bootloader** applications can be found in STM32Cube MCU Packages under the directory `/Projects//Applications/OpenBootloader/`, where `` is the reference of the used board **e.g.**, `B-U585I-IOT02A`. 29 | 30 | ## Documentation 31 | 32 | Since Open Bootloader supports exactly same protocol interfaces as STM32 System Bootloader, following list of documents provide details of how to use each protocol: 33 | - [AN3155](https://www.st.com/resource/en/application_note/CD00264342.pdf): USART protocol used in the STM32 Bootloader 34 | - [AN5405](https://www.st.com/resource/en/application_note/dm00660346.pdf): FDCAN protocol used in the STM32 Bootloader 35 | - [AN4221](https://www.st.com/resource/en/application_note/DM00072315.pdf): I2C protocol used in the STM32 Bootloader 36 | - [AN3156](https://www.st.com/resource/en/application_note/cd00264379.pdf): USB DFU protocol used in the STM32 Bootloader 37 | - [AN4286](https://www.st.com/resource/en/application_note/DM00081379.pdf): SPI protocol used in the STM32 Bootloader 38 | 39 | A useful introductory video series, in six parts, explaining how to use Open Bootloader step by step, can be found here: 40 | - [Part 1](https://www.youtube.com/watch?v=_gejWsAn5kg): Introduction 41 | - [Part 2](https://www.youtube.com/watch?v=kYr7UMieRTo): Using a NUCLEO-G474RE 42 | - [Part 3](https://www.youtube.com/watch?v=JUBac27tOis): Loading an application 43 | - [Part 4](https://www.youtube.com/watch?v=7sMDBSlZ7bU): Adding support for the I2C interface 44 | - [Part 5](https://www.youtube.com/watch?v=rr1W5h94qLU): STLINK-V3SET I2C setup 45 | - [Part 6](https://www.youtube.com/watch?v=IZ6BpDIm6O0): Loading an application over I2C 46 | 47 | ## List of Supported Commands 48 | 49 | All STM32 System Bootloader commands can be supported by Open Bootloader, which includes: 50 | - Get Version 51 | - Get Device ID 52 | - Get Available Command List 53 | - Write Memory 54 | - Read Memory 55 | - Write Protection setting 56 | - Read Protection setting 57 | - Jump to Application 58 | - Flash Erase 59 | - Special Command 60 | - Extended Special Command 61 | 62 | ## How to use 63 | 64 | **Open Bootloader** examples showing how to use this library are available in dedicated repositories, the list of which can be found [here](https://github.com/STMicroelectronics/STM32Cube_MCU_Overall_Offer/blob/master/README.md#stm32cube-middleware-libraries). 65 | 66 | ## Description 67 | 68 | This **stm32-mw-openbl** MCU component repository is one element **common to all** STM32Cube MCU packages, providing the **Open Bootloader MCU Middleware** part. 69 | 70 | ## Release note 71 | 72 | Details about the content of this release are available in the release note [here](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/stm32-mw-openbl/blob/main/Release_Notes.html). 73 | 74 | ## Troubleshooting 75 | 76 | Caution : The issues are strictly limited to submit problems or suggestions related to the software delivered in this repository. 77 | 78 | **For any other question** related to the product, the hardware performance or characteristics, the tools, the environment, you can submit it to the **ST Community** on the STM32 MCUs related [page](https://community.st.com/s/topic/0TO0X000000BSqSWAW/stm32-mcus). 79 | -------------------------------------------------------------------------------- /Interfaces/Templates/I3C/i3c_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file i3c_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains I3C HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "interfaces_conf.h" 22 | 23 | #include "openbl_core.h" 24 | #include "openbl_i3c_cmd.h" 25 | 26 | #include "i3c_interface.h" 27 | #include "iwdg_interface.h" 28 | #include "interfaces_conf.h" 29 | #include "flash_interface.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | #define AVAL_TIMING 0xFFU 34 | #define FREE_TIMING 0x3FU 35 | #define OPENBL_I3C_SYNC_BYTE 0x5AU 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* Private variables ---------------------------------------------------------*/ 39 | __IO uint32_t I3cDetected = 0U; 40 | 41 | /* Exported variables --------------------------------------------------------*/ 42 | /* Private function prototypes -----------------------------------------------*/ 43 | static void OPENBL_I3C_Init(void); 44 | 45 | /* Private functions ---------------------------------------------------------*/ 46 | 47 | /** 48 | * @brief This function is used to initialize the used I3C instance. 49 | * @retval None. 50 | */ 51 | static void OPENBL_I3C_Init(void) 52 | { 53 | } 54 | 55 | /* Exported functions --------------------------------------------------------*/ 56 | 57 | /** 58 | * @brief This function is used to configure I3C PINs and then initialize the used I3C instance. 59 | * @retval None. 60 | */ 61 | void OPENBL_I3C_Configuration(void) 62 | { 63 | } 64 | 65 | /** 66 | * @brief This function is used to De-initialize the I3C PINs and instance. 67 | * @retval None. 68 | */ 69 | void OPENBL_I3C_DeInit(void) 70 | { 71 | } 72 | 73 | /** 74 | * @brief This function is used to detect if there is any activity on I3C protocol. 75 | * @retval Returns 1 if the interface is detected else 0. 76 | */ 77 | uint8_t OPENBL_I3C_ProtocolDetection(void) 78 | { 79 | return I3cDetected; 80 | } 81 | 82 | /** 83 | * @brief This function is used to get the command opcode from the host. 84 | * @retval Returns the command opcode value. 85 | */ 86 | uint8_t OPENBL_I3C_GetCommandOpcode(void) 87 | { 88 | } 89 | 90 | /** 91 | * @brief This function is used to read one byte from I3C pipe. 92 | * @retval Returns the read byte. 93 | */ 94 | uint8_t OPENBL_I3C_ReadByte(void) 95 | { 96 | return LL_I3C_ReceiveData8(I3Cx); 97 | } 98 | 99 | /** 100 | * @brief This function is used to send one byte through I3C pipe. 101 | * @param Byte The byte to be sent. 102 | * @retval None. 103 | */ 104 | void OPENBL_I3C_SendByte(uint8_t Byte) 105 | { 106 | } 107 | 108 | /** 109 | * @brief This function is used to send Acknowledgment. 110 | * @param Acknowledge The acknowledge byte to be sent. 111 | * @retval None. 112 | */ 113 | void OPENBL_I3C_SendAcknowledgeByte(uint8_t Acknowledge) 114 | { 115 | } 116 | 117 | /** 118 | * @brief This function is used to send a buffer using I3C. 119 | * @param pBuffer The buffer that contains the data to be sent. 120 | * @param BufferSize The size of the data to be sent. 121 | * @retval None. 122 | */ 123 | void OPENBL_I3C_SendBytes(uint8_t *pBuffer, uint32_t BufferSize) 124 | { 125 | } 126 | 127 | /** 128 | * @brief This function is used to read bytes from I3C pipe. 129 | * @param pBuffer The buffer that stores the received data. 130 | * @param BufferSize The number of bytes to be read and stored in the receive buffer. 131 | * @retval None. 132 | */ 133 | void OPENBL_I3C_ReadBytes(uint8_t *pBuffer, uint32_t BufferSize) 134 | { 135 | } 136 | 137 | /** 138 | * @brief This function is used to process and execute the special commands. 139 | * The user must define the special commands routine here. 140 | * @param SpecialCmd Pointer to the OPENBL_SpecialCmdTypeDef structure. 141 | * @retval Returns NACK status in case of error else returns ACK status. 142 | */ 143 | void OPENBL_I3C_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd) 144 | { 145 | } 146 | 147 | /** 148 | * @brief Handle I3C interrupt request. This handler is used to detect host communication. 149 | * It is only used during connection phase. 150 | * @retval None. 151 | */ 152 | void OPENBL_I3C_IRQHandler(void) 153 | { 154 | } 155 | -------------------------------------------------------------------------------- /Interfaces/Templates/openbootloader_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbootloader_conf.h 4 | * @author MCD Application Team 5 | * @brief Contains Open Bootloader configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBOOTLOADER_CONF_H 21 | #define OPENBOOTLOADER_CONF_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "platform.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | 33 | /* -------------------------------- Device ID ------------------------------- */ 34 | #define DEVICE_ID_MSB 0x04U /* MSB byte of device ID */ 35 | #define DEVICE_ID_LSB 0x82U /* LSB byte of device ID */ 36 | 37 | /* -------------------------- Definitions for Memories ---------------------- */ 38 | #define FLASH_MEM_SIZE (2048U * 1024U) /* Size of Flash 2 MByte */ 39 | #define FLASH_START_ADDRESS 0x08000000U /* Flash start address */ 40 | #define FLASH_END_ADDRESS (FLASH_BASE + FLASH_MEM_SIZE) /* Flash end address */ 41 | 42 | #define RAM_SIZE (768U * 1024U) /* Size of RAM 768 kByte */ 43 | #define RAM_START_ADDRESS 0x20000000U /* SRAM start address */ 44 | #define RAM_END_ADDRESS (RAM_START_ADDRESS + RAM_SIZE) /* SRAM end address */ 45 | 46 | #define OB_SIZE 432U /* Size of OB 432 Byte */ 47 | #define OB_START_ADDRESS 0x40022050U /* Option bytes registers address */ 48 | #define OB1_START_ADDRESS OB_START_ADDRESS /* Option Bytes 1 start address */ 49 | #define OB2_START_ADDRESS 0x400221E0U /* Option Bytes 2 start address */ 50 | #define OB_END_ADDRESS (OB_START_ADDRESS + OB_SIZE) /* Option bytes end address */ 51 | 52 | #define OTP_SIZE (2U * 1024U) /* Size of OTP 2048 Byte */ 53 | #define OTP_START_ADDRESS 0x08FFF000U /* OTP start address */ 54 | #define OTP_END_ADDRESS (OTP_START_ADDRESS + OTP_SIZE) /* OTP end address */ 55 | 56 | #define ICP_SIZE (35U * 1024U) /* Size of ICP 35 kByte */ 57 | #define ICP_START_ADDRESS 0x0BF97000U /* System memory start address */ 58 | #define ICP_END_ADDRESS (ICP_START_ADDRESS + ICP_SIZE) /* System memory end address */ 59 | 60 | #define EB_SIZE 156U /* Size of Engi bytes 156 Byte */ 61 | #define EB_START_ADDRESS 0x40022400U /* Engi bytes start address */ 62 | #define EB_END_ADDRESS (EB_START_ADDRESS + EB_SIZE) /* Engi bytes end address */ 63 | 64 | #define OPENBL_RAM_SIZE 0x11800U /* RAM used by the Open Bootloader 71680 Bytes */ 65 | 66 | #define OPENBL_DEFAULT_MEM FLASH_START_ADDRESS /* Used for Erase and Write protect CMDs */ 67 | 68 | #define RDP_LEVEL_0 OB_RDP_LEVEL_0 69 | #define RDP_LEVEL_1 OB_RDP_LEVEL_1 70 | #define RDP_LEVEL_2 OB_RDP_LEVEL_2 71 | 72 | #define AREA_ERROR 0x0U /* Error Address Area */ 73 | #define FLASH_AREA 0x1U /* Flash Address Area */ 74 | #define RAM_AREA 0x2U /* RAM Address area */ 75 | #define OB_AREA 0x3U /* Option bytes Address area */ 76 | #define OTP_AREA 0x4U /* OTP Address area */ 77 | #define ICP_AREA 0x5U /* System memory area */ 78 | #define EB_AREA 0x6U /* Engi bytes Address area */ 79 | 80 | #define FLASH_MASS_ERASE 0xFFFF 81 | #define FLASH_BANK1_ERASE 0xFFFE 82 | #define FLASH_BANK2_ERASE 0xFFFD 83 | 84 | #define INTERFACES_SUPPORTED 6U 85 | 86 | /* Exported macro ------------------------------------------------------------*/ 87 | /* Exported functions ------------------------------------------------------- */ 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif /* __cplusplus */ 92 | 93 | #endif /* OPENBOOTLOADER_CONF_H */ 94 | -------------------------------------------------------------------------------- /Interfaces/Patterns/openbootloader_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbootloader_conf.h 4 | * @author MCD Application Team 5 | * @brief Contains Open Bootloader configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBOOTLOADER_CONF_H 21 | #define OPENBOOTLOADER_CONF_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "platform.h" 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | 33 | /* -------------------------------- Device ID ------------------------------- */ 34 | #define DEVICE_ID_MSB 0x04U /* MSB byte of device ID */ 35 | #define DEVICE_ID_LSB 0x82U /* LSB byte of device ID */ 36 | 37 | /* -------------------------- Definitions for Memories ---------------------- */ 38 | #define FLASH_MEM_SIZE (2048U * 1024U) /* Size of Flash 2 MByte */ 39 | #define FLASH_START_ADDRESS 0x08000000U /* Flash start address */ 40 | #define FLASH_END_ADDRESS (FLASH_BASE + FLASH_MEM_SIZE) /* Flash end address */ 41 | 42 | #define RAM_SIZE (768U * 1024U) /* Size of RAM 768 kByte */ 43 | #define RAM_START_ADDRESS 0x20000000U /* SRAM start address */ 44 | #define RAM_END_ADDRESS (RAM_START_ADDRESS + RAM_SIZE) /* SRAM end address */ 45 | 46 | #define OB_SIZE 432U /* Size of OB 432 Byte */ 47 | #define OB_START_ADDRESS 0x40022050U /* Option bytes registers address */ 48 | #define OB1_START_ADDRESS OB_START_ADDRESS /* Option Bytes 1 start address */ 49 | #define OB2_START_ADDRESS 0x400221E0U /* Option Bytes 2 start address */ 50 | #define OB_END_ADDRESS (OB_START_ADDRESS + OB_SIZE) /* Option bytes end address */ 51 | 52 | #define OTP_SIZE (2U * 1024U) /* Size of OTP 2048 Byte */ 53 | #define OTP_START_ADDRESS 0x08FFF000U /* OTP start address */ 54 | #define OTP_END_ADDRESS (OTP_START_ADDRESS + OTP_SIZE) /* OTP end address */ 55 | 56 | #define ICP_SIZE (35U * 1024U) /* Size of ICP 35 kByte */ 57 | #define ICP_START_ADDRESS 0x0BF97000U /* System memory start address */ 58 | #define ICP_END_ADDRESS (ICP_START_ADDRESS + ICP_SIZE) /* System memory end address */ 59 | 60 | #define EB_SIZE 156U /* Size of Engi bytes 156 Byte */ 61 | #define EB_START_ADDRESS 0x40022400U /* Engi bytes start address */ 62 | #define EB_END_ADDRESS (EB_START_ADDRESS + EB_SIZE) /* Engi bytes end address */ 63 | 64 | #define OPENBL_RAM_SIZE 0x11800U /* RAM used by the Open Bootloader 71680 Bytes */ 65 | 66 | #define OPENBL_DEFAULT_MEM FLASH_START_ADDRESS /* Used for Erase and Write protect CMDs */ 67 | 68 | #define RDP_LEVEL_0 OB_RDP_LEVEL_0 69 | #define RDP_LEVEL_1 OB_RDP_LEVEL_1 70 | #define RDP_LEVEL_2 OB_RDP_LEVEL_2 71 | 72 | #define AREA_ERROR 0x0U /* Error Address Area */ 73 | #define FLASH_AREA 0x1U /* Flash Address Area */ 74 | #define RAM_AREA 0x2U /* RAM Address area */ 75 | #define OB_AREA 0x3U /* Option bytes Address area */ 76 | #define OTP_AREA 0x4U /* OTP Address area */ 77 | #define ICP_AREA 0x5U /* System memory area */ 78 | #define EB_AREA 0x6U /* Engi bytes Address area */ 79 | 80 | #define FLASH_MASS_ERASE 0xFFFF 81 | #define FLASH_BANK1_ERASE 0xFFFE 82 | #define FLASH_BANK2_ERASE 0xFFFD 83 | 84 | #define INTERFACES_SUPPORTED 6U 85 | 86 | /* Exported macro ------------------------------------------------------------*/ 87 | /* Exported functions ------------------------------------------------------- */ 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif /* __cplusplus */ 92 | 93 | #endif /* OPENBOOTLOADER_CONF_H */ 94 | -------------------------------------------------------------------------------- /Interfaces/Templates/I2C/i2c_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file i2c_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains I2C HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "interfaces_conf.h" 22 | #include "openbl_core.h" 23 | #include "openbl_i2c_cmd.h" 24 | #include "i2c_interface.h" 25 | #include "iwdg_interface.h" 26 | #include "flash_interface.h" 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* Private define ------------------------------------------------------------*/ 30 | /* Private macro -------------------------------------------------------------*/ 31 | /* Private variables ---------------------------------------------------------*/ 32 | static uint8_t I2cDetected = 0; 33 | 34 | /* Exported variables --------------------------------------------------------*/ 35 | /* Private function prototypes -----------------------------------------------*/ 36 | static void OPENBL_I2C_Init(void); 37 | 38 | /* Private functions ---------------------------------------------------------*/ 39 | 40 | /** 41 | * @brief This function is used to initialize the used I2C instance. 42 | * @retval None. 43 | */ 44 | static void OPENBL_I2C_Init(void) 45 | { 46 | } 47 | 48 | /* Exported functions --------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief This function is used to configure I2C pins and then initialize the used I2C instance. 52 | * @retval None. 53 | */ 54 | void OPENBL_I2C_Configuration(void) 55 | { 56 | } 57 | 58 | /** 59 | * @brief This function is used to De-initialize the I2C pins and instance. 60 | * @retval None. 61 | */ 62 | void OPENBL_I2C_DeInit(void) 63 | { 64 | } 65 | 66 | /** 67 | * @brief This function is used to detect if there is any activity on I2C protocol. 68 | * @retval None. 69 | */ 70 | uint8_t OPENBL_I2C_ProtocolDetection(void) 71 | { 72 | return I2cDetected; 73 | } 74 | 75 | /** 76 | * @brief This function is used to get the command opcode from the host. 77 | * @retval Returns the command. 78 | */ 79 | uint8_t OPENBL_I2C_GetCommandOpcode(void) 80 | { 81 | uint8_t command_opc = 0x0U; 82 | 83 | return command_opc; 84 | } 85 | 86 | /** 87 | * @brief This function is used to read one byte from I2C pipe. 88 | * @retval Returns the read byte. 89 | */ 90 | uint8_t OPENBL_I2C_ReadByte(void) 91 | { 92 | uint32_t timeout = 0U; 93 | 94 | return LL_I2C_ReceiveData8(I2Cx); 95 | } 96 | 97 | /** 98 | * @brief This function is used to send one byte through I2C pipe. 99 | * @param Byte The byte to be sent. 100 | * @retval None. 101 | */ 102 | void OPENBL_I2C_SendByte(uint8_t Byte) 103 | { 104 | } 105 | 106 | /** 107 | * @brief This function is used to wait until the address is matched. 108 | * @retval None. 109 | */ 110 | void OPENBL_I2C_WaitAddress(void) 111 | { 112 | } 113 | 114 | /** 115 | * @brief This function is used to wait until NACK is detected. 116 | * @retval None. 117 | */ 118 | #if defined (__ICCARM__) 119 | __ramfunc void OPENBL_I2C_WaitNack(void) 120 | #else 121 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_WaitNack(void) 122 | #endif /* (__ICCARM__) */ 123 | { 124 | } 125 | 126 | /** 127 | * @brief This function is used to wait until STOP is detected. 128 | * @retval None. 129 | */ 130 | #if defined (__ICCARM__) 131 | __ramfunc void OPENBL_I2C_WaitStop(void) 132 | #else 133 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_WaitStop(void) 134 | #endif /* (__ICCARM__) */ 135 | { 136 | } 137 | 138 | /** 139 | * @brief This function is used to send Acknowledgment. 140 | * @retval None. 141 | */ 142 | void OPENBL_I2C_SendAcknowledgeByte(uint8_t Byte) 143 | { 144 | } 145 | 146 | /** 147 | * @brief This function is used to send busy byte through I2C pipe. 148 | * @param 149 | * @retval None. 150 | */ 151 | #if defined (__ICCARM__) 152 | __ramfunc void OPENBL_I2C_SendBusyByte(void) 153 | #else 154 | __attribute__((section(".ramfunc"))) void OPENBL_I2C_SendBusyByte(void) 155 | #endif /* (__ICCARM__) */ 156 | { 157 | } 158 | 159 | /** 160 | * @brief This function is used to process and execute the special commands. 161 | * The user must define the special commands routine here. 162 | * @param SpecialCmd Pointer to the OPENBL_SpecialCmdTypeDef structure. 163 | * @retval Returns NACK status in case of error else returns ACK status. 164 | */ 165 | void OPENBL_I2C_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd) 166 | { 167 | } 168 | 169 | /** 170 | * @brief This function is used to Set Flash busy state variable to activate busy state sending 171 | * during flash operations 172 | * @retval None. 173 | */ 174 | void OPENBL_Enable_BusyState_Sending(void) 175 | { 176 | } 177 | 178 | /** 179 | * @brief This function is used to disable the send of busy state in I2C non stretch mode. 180 | * @retval None. 181 | */ 182 | void OPENBL_Disable_BusyState_Sending(void) 183 | { 184 | } 185 | -------------------------------------------------------------------------------- /Interfaces/Patterns/interfaces_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file interfaces_conf.h 4 | * @author MCD Application Team 5 | * @brief Contains Interfaces configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef INTERFACES_CONF_H 21 | #define INTERFACES_CONF_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32u5xx_ll_usart.h" 29 | #include "stm32u5xx_ll_i2c.h" 30 | #include "stm32u5xx_ll_spi.h" 31 | 32 | #define MEMORIES_SUPPORTED 7U 33 | 34 | /*-------------------------- Definitions for USART ---------------------------*/ 35 | #define USARTx USART3 36 | #define USARTx_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE() 37 | #define USARTx_CLK_DISABLE() __HAL_RCC_USART3_CLK_DISABLE() 38 | #define USARTx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() 39 | #define USARTx_DEINIT() LL_USART_DeInit(USARTx) 40 | 41 | #define USARTx_TX_PIN GPIO_PIN_8 42 | #define USARTx_TX_GPIO_PORT GPIOD 43 | #define USARTx_RX_PIN GPIO_PIN_9 44 | #define USARTx_RX_GPIO_PORT GPIOD 45 | #define USARTx_ALTERNATE GPIO_AF7_USART3 46 | 47 | /*-------------------------- Definitions for I2C -----------------------------*/ 48 | #define I2Cx I2C2 49 | #define I2Cx_CLK_ENABLE() __HAL_RCC_I2C2_CLK_ENABLE() 50 | #define I2Cx_CLK_DISABLE() __HAL_RCC_I2C2_CLK_DISABLE() 51 | #define I2Cx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() 52 | #define I2Cx_DEINIT() LL_I2C_DeInit(I2Cx) 53 | 54 | #define I2Cx_SCL_PIN GPIO_PIN_4 55 | #define I2Cx_SCL_PIN_PORT GPIOH 56 | #define I2Cx_SDA_PIN GPIO_PIN_5 57 | #define I2Cx_SDA_PIN_PORT GPIOH 58 | #define I2Cx_ALTERNATE GPIO_AF4_I2C2 59 | #define I2C_ADDRESS 0x000000B4U 60 | #define OPENBL_I2C_TIMEOUT 0xFFFFF000U 61 | #define I2C_TIMING 0x00800000U 62 | 63 | /*-------------------------- Definitions for FDCAN ---------------------------*/ 64 | #define FDCANx FDCAN1 65 | #define FDCANx_CLK_ENABLE() __HAL_RCC_FDCAN1_CLK_ENABLE() 66 | #define FDCANx_CLK_DISABLE() __HAL_RCC_FDCAN1_CLK_DISABLE() 67 | #define FDCANx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() 68 | 69 | #define FDCANx_TX_PIN GPIO_PIN_8 70 | #define FDCANx_TX_GPIO_PORT GPIOB 71 | #define FDCANx_TX_AF GPIO_AF9_FDCAN1 72 | #define FDCANx_RX_PIN GPIO_PIN_9 73 | #define FDCANx_RX_GPIO_PORT GPIOB 74 | #define FDCANx_RX_AF GPIO_AF9_FDCAN1 75 | 76 | #define FDCANx_FORCE_RESET() __HAL_RCC_FDCAN1_FORCE_RESET() 77 | #define FDCANx_RELEASE_RESET() __HAL_RCC_FDCAN1_RELEASE_RESET() 78 | 79 | /*--------------------------- Definitions for SPI ----------------------------*/ 80 | #define SPIx SPI1 81 | #define SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE() 82 | #define SPIx_CLK_DISABLE() __HAL_RCC_SPI1_CLK_DISABLE() 83 | #define SPIx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE() 84 | #define SPIx_DEINIT() LL_SPI_DeInit(SPIx) 85 | #define SPIx_IRQ SPI1_IRQn 86 | 87 | #define SPIx_MOSI_PIN GPIO_PIN_15 88 | #define SPIx_MOSI_PIN_PORT GPIOE 89 | #define SPIx_MISO_PIN GPIO_PIN_14 90 | #define SPIx_MISO_PIN_PORT GPIOE 91 | #define SPIx_SCK_PIN GPIO_PIN_13 92 | #define SPIx_SCK_PIN_PORT GPIOE 93 | #define SPIx_NSS_PIN GPIO_PIN_4 94 | #define SPIx_NSS_PIN_PORT GPIOA 95 | #define SPIx_ALTERNATE GPIO_AF5_SPI1 96 | 97 | /*-------------------------- Definitions for I3C -----------------------------*/ 98 | #define I3Cx I3C1 99 | #define I3Cx_CLK_ENABLE() __HAL_RCC_I3C1_CLK_ENABLE() 100 | #define I3Cx_CLK_DISABLE() __HAL_RCC_I3C1_CLK_DISABLE() 101 | #define I3Cx_GPIO_CLK_SCL_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() 102 | #define I3Cx_GPIO_CLK_SDA_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() 103 | #define I3Cx_DEINIT() LL_I3C_DeInit(I3Cx) 104 | #define I3Cx_EV_IRQ I3C1_EV_IRQn 105 | 106 | #define I3Cx_SCL_PIN LL_GPIO_PIN_11 107 | #define I3Cx_SCL_PORT GPIOH 108 | #define I3Cx_SDA_PIN LL_GPIO_PIN_12 109 | #define I3Cx_SDA_PORT GPIOH 110 | #define I3Cx_ALTERNATE LL_GPIO_AF_5 111 | #define OPENBL_I3C_TIMEOUT 0xFFFFF000U 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif /* __cplusplus */ 116 | 117 | #endif /* INTERFACES_CONF_H */ 118 | -------------------------------------------------------------------------------- /Interfaces/Templates/interfaces_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file interfaces_conf.h 4 | * @author MCD Application Team 5 | * @brief Contains Interfaces configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef INTERFACES_CONF_H 21 | #define INTERFACES_CONF_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32u5xx_ll_usart.h" 29 | #include "stm32u5xx_ll_i2c.h" 30 | #include "stm32u5xx_ll_spi.h" 31 | 32 | #define MEMORIES_SUPPORTED 7U 33 | 34 | /*-------------------------- Definitions for USART ---------------------------*/ 35 | #define USARTx USART3 36 | #define USARTx_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE() 37 | #define USARTx_CLK_DISABLE() __HAL_RCC_USART3_CLK_DISABLE() 38 | #define USARTx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() 39 | #define USARTx_DEINIT() LL_USART_DeInit(USARTx) 40 | 41 | #define USARTx_TX_PIN GPIO_PIN_8 42 | #define USARTx_TX_GPIO_PORT GPIOD 43 | #define USARTx_RX_PIN GPIO_PIN_9 44 | #define USARTx_RX_GPIO_PORT GPIOD 45 | #define USARTx_ALTERNATE GPIO_AF7_USART3 46 | 47 | /*-------------------------- Definitions for I2C -----------------------------*/ 48 | #define I2Cx I2C2 49 | #define I2Cx_CLK_ENABLE() __HAL_RCC_I2C2_CLK_ENABLE() 50 | #define I2Cx_CLK_DISABLE() __HAL_RCC_I2C2_CLK_DISABLE() 51 | #define I2Cx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() 52 | #define I2Cx_DEINIT() LL_I2C_DeInit(I2Cx) 53 | 54 | #define I2Cx_SCL_PIN GPIO_PIN_4 55 | #define I2Cx_SCL_PIN_PORT GPIOH 56 | #define I2Cx_SDA_PIN GPIO_PIN_5 57 | #define I2Cx_SDA_PIN_PORT GPIOH 58 | #define I2Cx_ALTERNATE GPIO_AF4_I2C2 59 | #define I2C_ADDRESS 0x000000B4U 60 | #define OPENBL_I2C_TIMEOUT 0xFFFFF000U 61 | #define I2C_TIMING 0x00800000U 62 | 63 | /*-------------------------- Definitions for FDCAN ---------------------------*/ 64 | #define FDCANx FDCAN1 65 | #define FDCANx_CLK_ENABLE() __HAL_RCC_FDCAN1_CLK_ENABLE() 66 | #define FDCANx_CLK_DISABLE() __HAL_RCC_FDCAN1_CLK_DISABLE() 67 | #define FDCANx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() 68 | 69 | #define FDCANx_TX_PIN GPIO_PIN_8 70 | #define FDCANx_TX_GPIO_PORT GPIOB 71 | #define FDCANx_TX_AF GPIO_AF9_FDCAN1 72 | #define FDCANx_RX_PIN GPIO_PIN_9 73 | #define FDCANx_RX_GPIO_PORT GPIOB 74 | #define FDCANx_RX_AF GPIO_AF9_FDCAN1 75 | 76 | #define FDCANx_FORCE_RESET() __HAL_RCC_FDCAN1_FORCE_RESET() 77 | #define FDCANx_RELEASE_RESET() __HAL_RCC_FDCAN1_RELEASE_RESET() 78 | 79 | /*--------------------------- Definitions for SPI ----------------------------*/ 80 | #define SPIx SPI1 81 | #define SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE() 82 | #define SPIx_CLK_DISABLE() __HAL_RCC_SPI1_CLK_DISABLE() 83 | #define SPIx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE() 84 | #define SPIx_DEINIT() LL_SPI_DeInit(SPIx) 85 | #define SPIx_IRQ SPI1_IRQn 86 | 87 | #define SPIx_MOSI_PIN GPIO_PIN_15 88 | #define SPIx_MOSI_PIN_PORT GPIOE 89 | #define SPIx_MISO_PIN GPIO_PIN_14 90 | #define SPIx_MISO_PIN_PORT GPIOE 91 | #define SPIx_SCK_PIN GPIO_PIN_13 92 | #define SPIx_SCK_PIN_PORT GPIOE 93 | #define SPIx_NSS_PIN GPIO_PIN_4 94 | #define SPIx_NSS_PIN_PORT GPIOA 95 | #define SPIx_ALTERNATE GPIO_AF5_SPI1 96 | 97 | /*-------------------------- Definitions for I3C -----------------------------*/ 98 | #define I3Cx I3C1 99 | #define I3Cx_CLK_ENABLE() __HAL_RCC_I3C1_CLK_ENABLE() 100 | #define I3Cx_CLK_DISABLE() __HAL_RCC_I3C1_CLK_DISABLE() 101 | #define I3Cx_GPIO_CLK_SCL_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() 102 | #define I3Cx_GPIO_CLK_SDA_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() 103 | #define I3Cx_DEINIT() LL_I3C_DeInit(I3Cx) 104 | #define I3Cx_EV_IRQ I3C1_EV_IRQn 105 | 106 | #define I3Cx_SCL_PIN LL_GPIO_PIN_11 107 | #define I3Cx_SCL_PORT GPIOH 108 | #define I3Cx_SDA_PIN LL_GPIO_PIN_12 109 | #define I3Cx_SDA_PORT GPIOH 110 | #define I3Cx_ALTERNATE LL_GPIO_AF_5 111 | #define OPENBL_I3C_TIMEOUT 0xFFFFF000U 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif /* __cplusplus */ 116 | 117 | #endif /* INTERFACES_CONF_H */ 118 | -------------------------------------------------------------------------------- /Core/openbl_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_core.h 4 | * @author MCD Application Team 5 | * @brief Header for openbl_core.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef OPENBL_CORE_H 21 | #define OPENBL_CORE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include 29 | 30 | #include "openbootloader_conf.h" 31 | 32 | /* Exported constants --------------------------------------------------------*/ 33 | #define ERROR_COMMAND 0xECU /* Error command */ 34 | #define ACK_BYTE 0x79U /* Acknowledge Byte ID */ 35 | #define NACK_BYTE 0x1FU /* No Acknowledge Byte ID */ 36 | #define BUSY_BYTE 0x76U /* Busy Byte */ 37 | #define SYNC_BYTE 0xA5U /* Synchronization byte */ 38 | #define SPECIAL_CMD_SIZE_BUFFER1 128U /* Special command received data buffer size */ 39 | #define SPECIAL_CMD_SIZE_BUFFER2 1024U /* Special command write data buffer size */ 40 | 41 | /* ---------------------- Open Bootloader Commands ---------------------------*/ 42 | #define CMD_GET_COMMAND 0x00U /* Get commands command */ 43 | #define CMD_GET_VERSION 0x01U /* Get Version command */ 44 | #define CMD_GET_ID 0x02U /* Get ID command */ 45 | #define CMD_SPEED 0x03U /* Speed command */ 46 | #define CMD_READ_MEMORY 0x11U /* Read Memory command */ 47 | #define CMD_WRITE_MEMORY 0x31U /* Write Memory command */ 48 | #define CMD_GO 0x21U /* GO command */ 49 | #define CMD_READ_PROTECT 0x82U /* Readout Protect command */ 50 | #define CMD_READ_UNPROTECT 0x92U /* Readout Unprotect command */ 51 | #define CMD_LEG_ERASE_MEMORY 0x43U /* Erase Memory command */ 52 | #define CMD_EXT_ERASE_MEMORY 0x44U /* Erase Memory command */ 53 | #define CMD_WRITE_PROTECT 0x63U /* Write Protect command */ 54 | #define CMD_WRITE_UNPROTECT 0x73U /* Write Unprotect command */ 55 | #define CMD_NS_WRITE_MEMORY 0x32U /* No Stretch Write Memory command */ 56 | #define CMD_NS_ERASE_MEMORY 0x45U /* No Stretch Erase Memory command */ 57 | #define CMD_NS_WRITE_PROTECT 0x64U /* No Stretch Write Protect command */ 58 | #define CMD_NS_WRITE_UNPROTECT 0x74U /* No Stretch Write Unprotect command */ 59 | #define CMD_NS_READ_PROTECT 0x83U /* No Stretch Read Protect command */ 60 | #define CMD_NS_READ_UNPROTECT 0x93U /* No Stretch Read Unprotect command */ 61 | #define CMD_SPECIAL_COMMAND 0x50U /* Special Command command */ 62 | #define CMD_EXTENDED_SPECIAL_COMMAND 0x51U /* Extended Special Command command */ 63 | #define CMD_CHECKSUM 0xA1U /* Checksum command */ 64 | 65 | /* Exported types ------------------------------------------------------------*/ 66 | typedef struct 67 | { 68 | void (*Init)(void); 69 | void (*DeInit)(void); 70 | uint8_t (*Detection)(void); 71 | uint8_t (*GetCommandOpcode)(void); 72 | void (*SendByte)(uint8_t Byte); 73 | } OPENBL_OpsTypeDef; 74 | 75 | typedef struct 76 | { 77 | void (*GetCommand)(void); 78 | void (*GetVersion)(void); 79 | void (*GetID)(void); 80 | void (*ReadMemory)(void); 81 | void (*WriteMemory)(void); 82 | void (*Go)(void); 83 | void (*ReadoutProtect)(void); 84 | void (*ReadoutUnprotect)(void); 85 | void (*EraseMemory)(void); 86 | void (*WriteProtect)(void); 87 | void (*WriteUnprotect)(void); 88 | void (*NsWriteMemory)(void); 89 | void (*NsEraseMemory)(void); 90 | void (*NsWriteProtect)(void); 91 | void (*NsWriteUnprotect)(void); 92 | void (*NsReadoutProtect)(void); 93 | void (*NsReadoutUnprotect)(void); 94 | void (*Speed)(void); 95 | void (*SpecialCommand)(void); 96 | void (*ExtendedSpecialCommand)(void); 97 | } OPENBL_CommandsTypeDef; 98 | 99 | typedef struct 100 | { 101 | OPENBL_OpsTypeDef *p_Ops; 102 | OPENBL_CommandsTypeDef *p_Cmd; 103 | } OPENBL_HandleTypeDef; 104 | 105 | typedef enum 106 | { 107 | OPENBL_SPECIAL_CMD = 0x1U, 108 | OPENBL_EXTENDED_SPECIAL_CMD = 0x2U 109 | } OPENBL_SpecialCmdTypeTypeDef; 110 | 111 | typedef struct 112 | { 113 | OPENBL_SpecialCmdTypeTypeDef CmdType; 114 | uint16_t OpCode; 115 | uint16_t SizeBuffer1; 116 | uint8_t Buffer1[SPECIAL_CMD_SIZE_BUFFER1]; 117 | uint16_t SizeBuffer2; 118 | uint8_t Buffer2[SPECIAL_CMD_SIZE_BUFFER2]; 119 | } OPENBL_SpecialCmdTypeDef; 120 | 121 | /* Exported macro ------------------------------------------------------------*/ 122 | /* Exported functions --------------------------------------------------------*/ 123 | void OPENBL_Init(void); 124 | void OPENBL_DeInit(void); 125 | void OPENBL_InterfacesDeInit(void); 126 | uint32_t OPENBL_InterfaceDetection(void); 127 | void OPENBL_CommandProcess(void); 128 | ErrorStatus OPENBL_RegisterInterface(OPENBL_HandleTypeDef *Interface); 129 | 130 | #ifdef __cplusplus 131 | } 132 | #endif /* __cplusplus */ 133 | 134 | #endif /* OPENBL_CORE_H */ 135 | -------------------------------------------------------------------------------- /Interfaces/Templates/SPI/spi_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains SPI HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "interfaces_conf.h" 22 | #include "openbl_core.h" 23 | #include "openbl_spi_cmd.h" 24 | #include "spi_interface.h" 25 | #include "iwdg_interface.h" 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* Private define ------------------------------------------------------------*/ 29 | #define SPI_DUMMY_BYTE 0x00U /* Dummy byte */ 30 | #define SPI_SYNC_BYTE 0x5AU /* Synchronization byte */ 31 | #define SPI_BUSY_BYTE 0xA5U /* Busy byte */ 32 | 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | static __IO uint8_t SpiRxNotEmpty = 0U; 36 | static uint8_t SpiDetected = 0U; 37 | 38 | /* Exported variables --------------------------------------------------------*/ 39 | /* Private function prototypes -----------------------------------------------*/ 40 | static void OPENBL_SPI_Init(void); 41 | #if defined (__ICCARM__) 42 | __ramfunc void OPENBL_SPI_ClearFlag_OVR(void); 43 | #else 44 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_ClearFlag_OVR(void); 45 | #endif /* (__ICCARM__) */ 46 | 47 | /* Private functions ---------------------------------------------------------*/ 48 | 49 | /** 50 | * @brief This function is used to initialize the SPI peripheral 51 | * @retval None. 52 | */ 53 | static void OPENBL_SPI_Init(void) 54 | { 55 | } 56 | 57 | /* Exported functions --------------------------------------------------------*/ 58 | 59 | /** 60 | * @brief This function is used to configure SPI pins and then initialize the used SPI instance. 61 | * @retval None. 62 | */ 63 | void OPENBL_SPI_Configuration(void) 64 | { 65 | } 66 | 67 | /** 68 | * @brief This function is used to De-initialize the SPI pins and instance. 69 | * @retval None. 70 | */ 71 | void OPENBL_SPI_DeInit(void) 72 | { 73 | } 74 | 75 | /** 76 | * @brief This function is used to detect if there is any activity on SPI protocol. 77 | * @retval None. 78 | */ 79 | uint8_t OPENBL_SPI_ProtocolDetection(void) 80 | { 81 | return SpiDetected; 82 | } 83 | 84 | /** 85 | * @brief This function is used to get the command opcode from the host. 86 | * @retval Returns the command. 87 | */ 88 | uint8_t OPENBL_SPI_GetCommandOpcode(void) 89 | { 90 | uint8_t command_opc; 91 | 92 | return command_opc; 93 | } 94 | 95 | /** 96 | * @brief This function is used to read one byte from SPI pipe. 97 | * Read operation is synchronized on SPI Rx buffer not empty interrupt. 98 | * @retval Returns the read byte. 99 | */ 100 | #if defined (__ICCARM__) 101 | __ramfunc uint8_t OPENBL_SPI_ReadByte(void) 102 | #else 103 | __attribute__((section(".ramfunc"))) uint8_t OPENBL_SPI_ReadByte(void) 104 | #endif /* (__ICCARM__) */ 105 | { 106 | uint8_t data; 107 | 108 | return data; 109 | } 110 | 111 | /** 112 | * @brief This function is used to send one busy byte each receive interrupt through SPI pipe. 113 | * Read operation is synchronized on SPI Rx buffer not empty interrupt. 114 | * @retval Returns the read byte. 115 | */ 116 | #if defined (__ICCARM__) 117 | __ramfunc void OPENBL_SPI_SendBusyByte(void) 118 | #else 119 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_SendBusyByte(void) 120 | #endif /* (__ICCARM__) */ 121 | { 122 | } 123 | 124 | /** 125 | * @brief This function is used to send one byte through SPI pipe. 126 | * @retval None. 127 | */ 128 | #if defined (__ICCARM__) 129 | __ramfunc void OPENBL_SPI_SendByte(uint8_t Byte) 130 | #else 131 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_SendByte(uint8_t Byte) 132 | #endif /* (__ICCARM__) */ 133 | { 134 | } 135 | 136 | /** 137 | * @brief This function is used to send acknowledge byte through SPI pipe. 138 | * @retval None. 139 | */ 140 | void OPENBL_SPI_SendAcknowledgeByte(uint8_t Byte) 141 | { 142 | } 143 | 144 | /** 145 | * @brief Handle SPI interrupt request. 146 | * @retval None. 147 | */ 148 | #if defined (__ICCARM__) 149 | __ramfunc void OPENBL_SPI_IRQHandler(void) 150 | #else 151 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_IRQHandler(void) 152 | #endif /* (__ICCARM__) */ 153 | { 154 | } 155 | 156 | /** 157 | * @brief This function enables the send of busy state. 158 | * @retval None. 159 | */ 160 | void OPENBL_SPI_EnableBusyState(void) 161 | { 162 | /* Since we are using the underrun configuration, we don't need to enable the busy state */ 163 | } 164 | 165 | /** 166 | * @brief This function disables the send of busy state. 167 | * @retval None. 168 | */ 169 | void OPENBL_SPI_DisableBusyState(void) 170 | { 171 | } 172 | 173 | /** 174 | * @brief Clear overrun error flag 175 | * @note Clearing this flag is done by a read access to the SPIx_DR 176 | * register followed by a read access to the SPIx_SR register 177 | * @retval None 178 | */ 179 | #if defined (__ICCARM__) 180 | __ramfunc void OPENBL_SPI_ClearFlag_OVR(void) 181 | #else 182 | __attribute__((section(".ramfunc"))) void OPENBL_SPI_ClearFlag_OVR(void) 183 | #endif /* (__ICCARM__) */ 184 | { 185 | } 186 | 187 | /** 188 | * @brief This function is used to process and execute the special commands. 189 | * The user must define the special commands routine here. 190 | * @param SpecialCmd Pointer to the OPENBL_SpecialCmdTypeDef structure. 191 | * @retval Returns NACK status in case of error else returns ACK status. 192 | */ 193 | void OPENBL_SPI_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd) 194 | { 195 | } 196 | -------------------------------------------------------------------------------- /Interfaces/Patterns/OPTION BYTES/optionbytes_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file optionbytes_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains Option Bytes access functions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "openbl_mem.h" 22 | #include "app_openbootloader.h" 23 | #include "common_interface.h" 24 | #include "optionbytes_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | /* Private macro -------------------------------------------------------------*/ 29 | /* Private variables ---------------------------------------------------------*/ 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Exported variables --------------------------------------------------------*/ 32 | OPENBL_MemoryTypeDef OB_Descriptor = 33 | { 34 | OB_START_ADDRESS, 35 | OB_END_ADDRESS, 36 | OB_SIZE, 37 | OB_AREA, 38 | OPENBL_OB_Read, 39 | OPENBL_OB_Write, 40 | NULL, 41 | NULL, 42 | NULL, 43 | NULL, 44 | NULL 45 | }; 46 | 47 | /* Exported functions --------------------------------------------------------*/ 48 | 49 | /** 50 | * @brief Launch the option byte loading. 51 | * @retval None. 52 | */ 53 | void OPENBL_OB_Launch(void) 54 | { 55 | /* Set the option start bit */ 56 | HAL_FLASH_OB_Launch(); 57 | 58 | /* Set the option lock bit and Lock the flash */ 59 | HAL_FLASH_OB_Lock(); 60 | HAL_FLASH_Lock(); 61 | } 62 | 63 | /** 64 | * @brief This function is used to read data from a given address. 65 | * @param Address The address to be read. 66 | * @retval Returns the read value. 67 | */ 68 | uint8_t OPENBL_OB_Read(uint32_t Address) 69 | { 70 | return (*(uint8_t *)(Address)); 71 | } 72 | 73 | /** 74 | * @brief Write Flash OB keys to unlock the option bytes settings 75 | * @param None 76 | * @retval None 77 | */ 78 | void BL_FLASH_WriteOptKeys(void) 79 | { 80 | if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET) 81 | { 82 | /* Authorize the FLASH Registers access */ 83 | WRITE_REG(FLASH->KEYR, FLASH_KEY1); 84 | WRITE_REG(FLASH->KEYR, FLASH_KEY2); 85 | } 86 | 87 | if (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) != RESET) 88 | { 89 | /* Authorizes the Option Byte register programming */ 90 | WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1); 91 | WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2); 92 | } 93 | } 94 | /** 95 | * @brief This function is used to write data in Option bytes. 96 | * @param Address The address where that data will be written. 97 | * @param Data The data to be written. 98 | * @param DataLength The length of the data to be written. 99 | * @retval None. 100 | */ 101 | void OPENBL_OB_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength) 102 | { 103 | /* Unlock the FLASH & Option Bytes Registers access */ 104 | HAL_FLASH_Unlock(); 105 | HAL_FLASH_OB_Unlock(); 106 | 107 | /* Clear error programming flags */ 108 | __HAL_FLASH_CLEAR_FLAG(FLASH_SR_ERRORS); 109 | 110 | /* Write RDP Level */ 111 | WRITE_REG(FLASH->OPTR, *(Data)); 112 | 113 | /* Write OPTR */ 114 | if (DataLength >= 4) 115 | { 116 | WRITE_REG(FLASH->OPTR, (*(Data) | (*(Data + 1) << 8) | (*(Data + 2) << 16) | (*(Data + 3) << 24))); 117 | } 118 | 119 | /* Write PCROP1ASR */ 120 | if (DataLength >= 10) 121 | { 122 | WRITE_REG(FLASH->PCROP1ASR, (*(Data + 8) | (*(Data + 9) << 8))); 123 | } 124 | 125 | /* Write PCROP1AER */ 126 | if (DataLength >= 20) 127 | { 128 | WRITE_REG(FLASH->PCROP1AER, (*(Data + 16) | (*(Data + 17) << 8) | (*(Data + 19) << 24))); 129 | } 130 | 131 | /* Write WRP1AR */ 132 | if (DataLength >= 28) 133 | { 134 | WRITE_REG(FLASH->WRP1AR, (*(Data + 24) | (*(Data + 25) << 8) | (*(Data + 26) << 16) | (*(Data + 27) << 24))); 135 | } 136 | 137 | /* Write WRP1BR */ 138 | if (DataLength >= 36) 139 | { 140 | WRITE_REG(FLASH->WRP1BR, (*(Data + 32) | (*(Data + 33) << 8) | (*(Data + 34) << 16) | (*(Data + 35) << 24))); 141 | } 142 | 143 | /* Write PCROP1BSR */ 144 | if (DataLength >= 42) 145 | { 146 | WRITE_REG(FLASH->PCROP1BSR, (*(Data + 40) | (*(Data + 41) << 8))); 147 | } 148 | 149 | /* Write PCROP1BER */ 150 | if (DataLength >= 50) 151 | { 152 | WRITE_REG(FLASH->PCROP1BER, (*(Data + 48) | (*(Data + 49) << 8))); 153 | } 154 | 155 | /* Write PCROP2ASR */ 156 | if (DataLength >= 58) 157 | { 158 | WRITE_REG(FLASH->PCROP2ASR, (*(Data + 56) | (*(Data + 57) << 8))); 159 | } 160 | 161 | /* Write PCROP2AER */ 162 | if (DataLength >= 66) 163 | { 164 | WRITE_REG(FLASH->PCROP2AER, (*(Data + 64) | (*(Data + 65) << 8))); 165 | } 166 | 167 | /* Write WRP2AR */ 168 | if (DataLength >= 76) 169 | { 170 | WRITE_REG(FLASH->WRP2AR, (*(Data + 72) | (*(Data + 73) << 8) | (*(Data + 74) << 16) | (*(Data + 75) << 24))); 171 | } 172 | 173 | /* Write WRP2BR */ 174 | if (DataLength >= 84) 175 | { 176 | WRITE_REG(FLASH->WRP2BR, (*(Data + 80) | (*(Data + 81) << 8) | (*(Data + 82) << 16) | (*(Data + 83) << 24))); 177 | } 178 | 179 | /* Write PCROP2BSR */ 180 | if (DataLength >= 90) 181 | { 182 | WRITE_REG(FLASH->PCROP2BSR, (*(Data + 88) | (*(Data + 89) << 8))); 183 | } 184 | 185 | /* Write PCROP2BER */ 186 | if (DataLength >= 98) 187 | { 188 | WRITE_REG(FLASH->PCROP2BER, (*(Data + 96) | (*(Data + 97) << 8))); 189 | } 190 | 191 | /* Write SECR */ 192 | if (DataLength >= 116) 193 | { 194 | WRITE_REG(FLASH->SECR, (*(Data + 112) | (*(Data + 113) << 8) | (*(Data + 114) << 16) | (*(Data + 115) << 24))); 195 | } 196 | 197 | SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 198 | 199 | /* Register system reset callback */ 200 | Common_SetPostProcessingCallback(OPENBL_OB_Launch); 201 | } 202 | -------------------------------------------------------------------------------- /Modules/USB/openbl_usb_cmd.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file openbl_usb_cmd.c 4 | * @author MCD Application Team 5 | * @brief Contains USB protocol commands 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "openbl_usb_cmd.h" 21 | #include "openbl_mem.h" 22 | #include "openbootloader_conf.h" 23 | #include "usb_interface.h" 24 | #include "common_interface.h" 25 | 26 | /* Private typedef -----------------------------------------------------------*/ 27 | /* Private define ------------------------------------------------------------*/ 28 | #define USB_RAM_BUFFER_SIZE 20U /* Size of USB buffer used to store received data from the host */ 29 | 30 | /* Private macro -------------------------------------------------------------*/ 31 | /* Private variables ---------------------------------------------------------*/ 32 | /* Private macro -------------------------------------------------------------*/ 33 | /* Private variables ---------------------------------------------------------*/ 34 | /* Private function prototypes -----------------------------------------------*/ 35 | 36 | /* Exported functions---------------------------------------------------------*/ 37 | /** 38 | * @brief Erase sector. 39 | * @param Address: Address of sector to be erased. 40 | * @retval 0 if operation is successful, MAL_FAIL else. 41 | */ 42 | uint16_t OPENBL_USB_EraseMemory(uint32_t Address) 43 | { 44 | ErrorStatus error_value; 45 | uint8_t status; 46 | uint32_t numpage; 47 | uint32_t page; 48 | uint8_t usb_ram_buffer[USB_RAM_BUFFER_SIZE]; 49 | uint8_t *ramaddress; 50 | 51 | ramaddress = (uint8_t *) usb_ram_buffer; 52 | numpage = 1; 53 | 54 | *ramaddress = (uint8_t)(numpage & 0x00FFU); 55 | ramaddress++; 56 | 57 | *ramaddress = (uint8_t)((numpage & 0xFF00U) >> 8); 58 | ramaddress++; 59 | 60 | page = OPENBL_USB_GetPage(Address); 61 | 62 | *ramaddress = (uint8_t)(page & 0x00FFU); 63 | ramaddress++; 64 | 65 | *ramaddress = (uint8_t)((page & 0xFF00U) >> 8); 66 | ramaddress++; 67 | 68 | error_value = OPENBL_MEM_Erase(OPENBL_DEFAULT_MEM, (uint8_t *) usb_ram_buffer, USB_RAM_BUFFER_SIZE); 69 | 70 | if (error_value != SUCCESS) 71 | { 72 | status = 1U; 73 | } 74 | else 75 | { 76 | status = 0U; 77 | } 78 | 79 | return status; 80 | } 81 | 82 | /** 83 | * @brief Memory write routine. 84 | * @param pSrc: Pointer to the source buffer. Address to be written to. 85 | * @param pDest: Pointer to the destination buffer. 86 | * @param Length: Number of data to be written (in bytes). 87 | * @retval USBD_OK if operation is successful, MAL_FAIL else. 88 | */ 89 | void OPENBL_USB_WriteMemory(uint8_t *pSrc, uint8_t *pDest, uint32_t Length) 90 | { 91 | uint32_t address; 92 | 93 | address = (uint32_t)pDest[0] | ((uint32_t)pDest[1] << 8) | 94 | ((uint32_t)pDest[2] << 16) | ((uint32_t)pDest[3] << 24); 95 | 96 | OPENBL_MEM_Write(address, pSrc, Length); 97 | 98 | /* Start post processing task if needed */ 99 | Common_StartPostProcessing(); 100 | } 101 | 102 | /** 103 | * @brief Memory read routine. 104 | * @param pSrc: Pointer to the source buffer. Address to be written to. 105 | * @param pDest: Pointer to the destination buffer. 106 | * @param Length: Number of data to be read (in bytes). 107 | * @retval Pointer to the physical address where data should be read. 108 | */ 109 | uint8_t *OPENBL_USB_ReadMemory(uint8_t *pSrc, uint8_t *pDest, uint32_t Length) 110 | { 111 | uint32_t memory_index; 112 | uint32_t address; 113 | uint32_t i; 114 | 115 | address = (uint32_t)pSrc[0] | ((uint32_t)pSrc[1] << 8) | 116 | ((uint32_t)pSrc[2] << 16) | ((uint32_t)pSrc[3] << 24); 117 | 118 | memory_index = OPENBL_MEM_GetMemoryIndex(address); 119 | 120 | for (i = 0; i < Length; i++) 121 | { 122 | pDest[i] = OPENBL_MEM_Read(address, memory_index); 123 | address++; 124 | } 125 | 126 | /* Return a valid address to avoid HardFault */ 127 | return pDest; 128 | } 129 | 130 | /** 131 | * @brief This function is used to jump to the user application. 132 | * @param Address: The jump address. 133 | * @retval None 134 | */ 135 | void OPENBL_USB_Jump(uint32_t Address) 136 | { 137 | uint8_t status; 138 | 139 | /* Check if received address is valid or not */ 140 | status = OPENBL_MEM_CheckJumpAddress(Address); 141 | 142 | if (status == 1U) 143 | { 144 | OPENBL_MEM_JumpToAddress(Address); 145 | } 146 | } 147 | 148 | /** 149 | * @brief Write protect. 150 | * @param pBuffer: A buffer that contains the list of sectors or pages to be protected. 151 | * @param Length: Contains the length of the pBuffer. 152 | * @retval None. 153 | */ 154 | void OPENBL_USB_WriteProtect(uint8_t *pBuffer, uint32_t Length) 155 | { 156 | ErrorStatus error_value; 157 | 158 | error_value = OPENBL_MEM_SetWriteProtection(ENABLE, OPENBL_DEFAULT_MEM, pBuffer, Length); 159 | 160 | if (error_value == SUCCESS) 161 | { 162 | /* Start post processing task if needed */ 163 | Common_StartPostProcessing(); 164 | } 165 | } 166 | 167 | /** 168 | * @brief Write unprotect. 169 | * @retval None. 170 | */ 171 | void OPENBL_USB_WriteUnprotect(void) 172 | { 173 | ErrorStatus error_value; 174 | 175 | error_value = OPENBL_MEM_SetWriteProtection(DISABLE, OPENBL_DEFAULT_MEM, NULL, 0U); 176 | 177 | if (error_value == SUCCESS) 178 | { 179 | /* Start post processing task if needed */ 180 | Common_StartPostProcessing(); 181 | } 182 | } 183 | 184 | /** 185 | * @brief Read protect. 186 | * @retval None. 187 | */ 188 | void OPENBL_USB_ReadProtect(void) 189 | { 190 | /* Enable the read protection */ 191 | OPENBL_MEM_SetReadOutProtection(OPENBL_DEFAULT_MEM, ENABLE); 192 | 193 | /* Start post processing task if needed */ 194 | Common_StartPostProcessing(); 195 | } 196 | 197 | /** 198 | * @brief Read unprotect. 199 | * @retval None. 200 | */ 201 | void OPENBL_USB_ReadUnprotect(void) 202 | { 203 | /* Disable the read protection */ 204 | OPENBL_MEM_SetReadOutProtection(OPENBL_DEFAULT_MEM, DISABLE); 205 | 206 | /* Start post processing task if needed */ 207 | Common_StartPostProcessing(); 208 | } 209 | -------------------------------------------------------------------------------- /Interfaces/Patterns/USART/usart_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usart_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains USART HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "interfaces_conf.h" 22 | #include "openbl_core.h" 23 | #include "openbl_usart_cmd.h" 24 | #include "usart_interface.h" 25 | #include "iwdg_interface.h" 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* Private define ------------------------------------------------------------*/ 29 | #define DEFAULT_USART_BAUDRATE 115200U 30 | 31 | /* Private macro -------------------------------------------------------------*/ 32 | /* Private variables ---------------------------------------------------------*/ 33 | static uint8_t UsartDetected = 0U; 34 | 35 | /* Exported variables --------------------------------------------------------*/ 36 | /* Private function prototypes -----------------------------------------------*/ 37 | static void OPENBL_USART_Init(void); 38 | 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /** 42 | * @brief This function is used to initialize the used USART instance. 43 | * @retval None. 44 | */ 45 | static void OPENBL_USART_Init(void) 46 | { 47 | LL_USART_InitTypeDef USART_InitStruct; 48 | 49 | USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; 50 | USART_InitStruct.BaudRate = DEFAULT_USART_BAUDRATE; 51 | USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_9B; 52 | USART_InitStruct.StopBits = LL_USART_STOPBITS_1; 53 | USART_InitStruct.Parity = LL_USART_PARITY_EVEN; 54 | USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; 55 | USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; 56 | USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; 57 | 58 | if (IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx)) 59 | { 60 | LL_USART_EnableAutoBaudRate(USARTx); 61 | LL_USART_SetAutoBaudRateMode(USARTx, LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME); 62 | } 63 | else 64 | { 65 | LL_USART_DisableAutoBaudRate(USARTx); 66 | USART_InitStruct.BaudRate = DEFAULT_USART_BAUDRATE; 67 | } 68 | 69 | LL_USART_Init(USARTx, &USART_InitStruct); 70 | LL_USART_Enable(USARTx); 71 | } 72 | 73 | /* Exported functions --------------------------------------------------------*/ 74 | 75 | /** 76 | * @brief This function is used to configure USART pins and then initialize the used USART instance. 77 | * @retval None. 78 | */ 79 | void OPENBL_USART_Configuration(void) 80 | { 81 | GPIO_InitTypeDef GPIO_InitStruct; 82 | 83 | /* Enable all resources clocks ---------------------------------------------*/ 84 | /* Enable used GPIOx clocks */ 85 | __HAL_RCC_GPIOA_CLK_ENABLE(); 86 | 87 | /* Enable USART clock */ 88 | __HAL_RCC_USART1_CLK_ENABLE(); 89 | 90 | /* USARTx pins configuration -----------------------------------------------*/ 91 | 92 | GPIO_InitStruct.Pin = USARTx_TX_PIN; 93 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 94 | GPIO_InitStruct.Pull = GPIO_PULLUP; 95 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 96 | GPIO_InitStruct.Alternate = USARTx_ALTERNATE; 97 | HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct); 98 | 99 | GPIO_InitStruct.Pin = USARTx_RX_PIN; 100 | HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct); 101 | 102 | OPENBL_USART_Init(); 103 | } 104 | 105 | /** 106 | * @brief This function is used to De-initialize the USART pins and instance. 107 | * @retval None. 108 | */ 109 | void OPENBL_USART_DeInit(void) 110 | { 111 | /* Only de-initialize the USART if it is not the current detected interface */ 112 | if (UsartDetected == 0U) 113 | { 114 | LL_USART_Disable(USARTx); 115 | 116 | USARTx_CLK_DISABLE(); 117 | } 118 | } 119 | 120 | /** 121 | * @brief This function is used to detect if there is any activity on USART protocol. 122 | * @retval Returns 1 if interface is detected else 0. 123 | */ 124 | uint8_t OPENBL_USART_ProtocolDetection(void) 125 | { 126 | /* Check if the USARTx is addressed */ 127 | if (((USARTx->ISR & LL_USART_ISR_ABRF) != 0) && ((USARTx->ISR & LL_USART_ISR_ABRE) == 0)) 128 | { 129 | /* Read byte in order to flush the 0x7F synchronization byte */ 130 | OPENBL_USART_ReadByte(); 131 | 132 | /* Acknowledge the host */ 133 | OPENBL_USART_SendByte(ACK_BYTE); 134 | 135 | UsartDetected = 1U; 136 | } 137 | else 138 | { 139 | UsartDetected = 0U; 140 | } 141 | 142 | return UsartDetected; 143 | } 144 | 145 | /** 146 | * @brief This function is used to get the command opcode from the host. 147 | * @retval Returns the command. 148 | */ 149 | uint8_t OPENBL_USART_GetCommandOpcode(void) 150 | { 151 | uint8_t command_opc = 0x0; 152 | 153 | /* Get the command opcode */ 154 | command_opc = OPENBL_USART_ReadByte(); 155 | 156 | /* Check the data integrity */ 157 | if ((command_opc ^ OPENBL_USART_ReadByte()) != 0xFF) 158 | { 159 | command_opc = ERROR_COMMAND; 160 | } 161 | 162 | return command_opc; 163 | } 164 | 165 | /** 166 | * @brief This function is used to read one byte from USART pipe. 167 | * @retval Returns the read byte. 168 | */ 169 | uint8_t OPENBL_USART_ReadByte(void) 170 | { 171 | while (!LL_USART_IsActiveFlag_RXNE_RXFNE(USARTx)) 172 | { 173 | OPENBL_IWDG_Refresh(); 174 | } 175 | 176 | return LL_USART_ReceiveData8(USARTx); 177 | } 178 | 179 | /** 180 | * @brief This function is used to send one byte through USART pipe. 181 | * @param Byte The byte to be sent. 182 | * @retval None. 183 | */ 184 | void OPENBL_USART_SendByte(uint8_t Byte) 185 | { 186 | LL_USART_TransmitData8(USARTx, (Byte & 0xFF)); 187 | 188 | while (!LL_USART_IsActiveFlag_TC(USARTx)) 189 | { 190 | } 191 | } 192 | 193 | /** 194 | * @brief This function is used to process and execute the special commands. 195 | * The user must define the special commands routine here. 196 | * @param SpecialCmd Pointer to the OPENBL_SpecialCmdTypeDef structure. 197 | * @retval Returns NACK status in case of error else returns ACK status. 198 | */ 199 | void OPENBL_USART_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *SpecialCmd) 200 | { 201 | switch (SpecialCmd->OpCode) 202 | { 203 | /* Unknown command opcode */ 204 | default: 205 | if (SpecialCmd->CmdType == OPENBL_SPECIAL_CMD) 206 | { 207 | /* Send NULL data size */ 208 | OPENBL_USART_SendByte(0x00U); 209 | OPENBL_USART_SendByte(0x00U); 210 | 211 | /* Send NULL status size */ 212 | OPENBL_USART_SendByte(0x00U); 213 | OPENBL_USART_SendByte(0x00U); 214 | } 215 | else if (SpecialCmd->CmdType == OPENBL_EXTENDED_SPECIAL_CMD) 216 | { 217 | /* Send NULL status size */ 218 | OPENBL_USART_SendByte(0x00U); 219 | OPENBL_USART_SendByte(0x00U); 220 | } 221 | break; 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /Interfaces/Patterns/FDCAN/fdcan_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file fdcan_interface.c 4 | * @author MCD Application Team 5 | * @brief Contains FDCAN HW configuration 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "platform.h" 21 | #include "interfaces_conf.h" 22 | #include "openbl_core.h" 23 | #include "openbl_fdcan_cmd.h" 24 | #include "fdcan_interface.h" 25 | #include "iwdg_interface.h" 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* Private define ------------------------------------------------------------*/ 29 | /* Private macro -------------------------------------------------------------*/ 30 | /* Private variables ---------------------------------------------------------*/ 31 | static FDCAN_HandleTypeDef hfdcan; 32 | static FDCAN_FilterTypeDef sFilterConfig; 33 | static FDCAN_TxHeaderTypeDef TxHeader; 34 | static FDCAN_RxHeaderTypeDef RxHeader; 35 | static uint8_t FdcanDetected = 0U; 36 | 37 | /* Exported variables --------------------------------------------------------*/ 38 | uint8_t TxData[FDCAN_RAM_BUFFER_SIZE]; 39 | uint8_t RxData[FDCAN_RAM_BUFFER_SIZE]; 40 | 41 | /* Private function prototypes -----------------------------------------------*/ 42 | static void OPENBL_FDCAN_Init(void); 43 | 44 | /* Private functions ---------------------------------------------------------*/ 45 | /** 46 | * @brief This function is used to initialize the used FDCAN instance. 47 | * @retval None. 48 | */ 49 | static void OPENBL_FDCAN_Init(void) 50 | { 51 | /* Bit time configuration: 52 | Bit time parameter | Nominal | Data 53 | ---------------------------|--------------|---------------- 54 | fdcan_ker_ck | 20 MHz | 20 MHz 55 | Time_quantum (tq) | 50 ns | 50 ns 56 | Synchronization_segment | 1 tq | 1 tq 57 | Propagation_segment | 23 tq | 1 tq 58 | Phase_segment_1 | 8 tq | 4 tq 59 | Phase_segment_2 | 8 tq | 4 tq 60 | Synchronization_Jump_width | 8 tq | 4 tq 61 | Bit_length | 40 tq = 2 us | 10 tq = 0.5 us 62 | Bit_rate | 0.5 MBit/s | 2 MBit/s 63 | */ 64 | 65 | hfdcan.Instance = FDCANx; 66 | hfdcan.Init.FrameFormat = FDCAN_FRAME_FD_BRS; 67 | hfdcan.Init.Mode = FDCAN_MODE_NORMAL; 68 | hfdcan.Init.AutoRetransmission = ENABLE; 69 | hfdcan.Init.TransmitPause = DISABLE; 70 | hfdcan.Init.ProtocolException = ENABLE; 71 | hfdcan.Init.NominalPrescaler = 0x1; 72 | hfdcan.Init.NominalSyncJumpWidth = 0x10; 73 | hfdcan.Init.NominalTimeSeg1 = 0x3F; 74 | hfdcan.Init.NominalTimeSeg2 = 0x10; 75 | hfdcan.Init.DataPrescaler = 0x1; 76 | hfdcan.Init.DataSyncJumpWidth = 0x4; 77 | hfdcan.Init.DataTimeSeg1 = 0xF; 78 | hfdcan.Init.DataTimeSeg2 = 0x4; 79 | hfdcan.Init.StdFiltersNbr = 1; 80 | hfdcan.Init.ExtFiltersNbr = 0; 81 | hfdcan.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; 82 | 83 | if (HAL_FDCAN_Init(&hfdcan) != HAL_OK) 84 | { 85 | while (1); 86 | } 87 | 88 | /* Configure Rx filter */ 89 | sFilterConfig.IdType = FDCAN_STANDARD_ID; 90 | sFilterConfig.FilterIndex = 0; 91 | sFilterConfig.FilterType = FDCAN_FILTER_MASK; 92 | sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; 93 | sFilterConfig.FilterID1 = 0x111; 94 | sFilterConfig.FilterID2 = 0x7FF; 95 | HAL_FDCAN_ConfigFilter(&hfdcan, &sFilterConfig); 96 | 97 | /* Prepare Tx Header */ 98 | TxHeader.Identifier = 0x111; 99 | TxHeader.IdType = FDCAN_STANDARD_ID; 100 | TxHeader.TxFrameType = FDCAN_DATA_FRAME; 101 | TxHeader.DataLength = FDCAN_DLC_BYTES_64; 102 | TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE; 103 | TxHeader.BitRateSwitch = FDCAN_BRS_ON; 104 | TxHeader.FDFormat = FDCAN_FD_CAN; 105 | TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS; 106 | TxHeader.MessageMarker = 0; 107 | 108 | /* Start the FDCAN module */ 109 | HAL_FDCAN_Start(&hfdcan); 110 | } 111 | 112 | /* Exported functions --------------------------------------------------------*/ 113 | 114 | /** 115 | * @brief This function is used to configure FDCAN pins and then initialize the used FDCAN instance. 116 | * @retval None. 117 | */ 118 | void OPENBL_FDCAN_Configuration(void) 119 | { 120 | /* Enable all resources clocks --------------------------------------------*/ 121 | /* Enable used GPIOx clocks */ 122 | FDCANx_GPIO_CLK_ENABLE(); 123 | 124 | OPENBL_FDCAN_Init(); 125 | } 126 | 127 | /** 128 | * @brief This function is used to De-initialize the FDCAN pins and instance. 129 | * @retval None. 130 | */ 131 | void OPENBL_FDCAN_DeInit(void) 132 | { 133 | /* Only de-initialize the FDCAN if it is not the current detected interface */ 134 | if (FdcanDetected == 0U) 135 | { 136 | FDCANx_FORCE_RESET(); 137 | FDCANx_RELEASE_RESET(); 138 | HAL_GPIO_DeInit(FDCANx_TX_GPIO_PORT, FDCANx_TX_PIN); 139 | HAL_GPIO_DeInit(FDCANx_RX_GPIO_PORT, FDCANx_RX_PIN); 140 | 141 | FDCANx_CLK_DISABLE(); 142 | } 143 | } 144 | 145 | /** 146 | * @brief This function is used to detect if there is any activity on FDCAN protocol. 147 | * @retval Returns 1 if interface is detected else 0.. 148 | */ 149 | uint8_t OPENBL_FDCAN_ProtocolDetection(void) 150 | { 151 | /* check if FIFO 0 receive at least one message */ 152 | if (HAL_FDCAN_GetRxFifoFillLevel(&hfdcan, FDCAN_RX_FIFO0) > 0) 153 | { 154 | FdcanDetected = 1; 155 | } 156 | else 157 | { 158 | FdcanDetected = 0; 159 | } 160 | 161 | return FdcanDetected; 162 | } 163 | 164 | /** 165 | * @brief This function is used to get the command opcode from the host. 166 | * @retval Returns the command. 167 | */ 168 | uint8_t OPENBL_FDCAN_GetCommandOpcode(void) 169 | { 170 | uint8_t command_opc = 0x0; 171 | HAL_StatusTypeDef status = HAL_OK; 172 | 173 | /* check if FIFO 0 receive at least one message */ 174 | while (HAL_FDCAN_GetRxFifoFillLevel(&hfdcan, FDCAN_RX_FIFO0) < 1) 175 | {} 176 | 177 | /* Retrieve Rx messages from RX FIFO0 */ 178 | status = HAL_FDCAN_GetRxMessage(&hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData); 179 | 180 | /* Check for errors */ 181 | if (status == HAL_ERROR) 182 | { 183 | command_opc = ERROR_COMMAND; 184 | } 185 | else 186 | { 187 | command_opc = RxHeader.Identifier; 188 | TxHeader.Identifier = RxHeader.Identifier; 189 | } 190 | 191 | return command_opc; 192 | } 193 | 194 | /** 195 | * @brief This function is used to read one byte from FDCAN pipe. 196 | * @retval Returns the read byte. 197 | */ 198 | uint8_t OPENBL_FDCAN_ReadByte(void) 199 | { 200 | uint8_t byte; 201 | 202 | /* check if FIFO 0 receive at least one message */ 203 | while (HAL_FDCAN_GetRxFifoFillLevel(&hfdcan, FDCAN_RX_FIFO0) < 1) 204 | { 205 | OPENBL_IWDG_Refresh(); 206 | } 207 | 208 | /* Retrieve Rx messages from RX FIFO0 */ 209 | HAL_FDCAN_GetRxMessage(&hfdcan, FDCAN_RX_FIFO0, &RxHeader, &byte); 210 | 211 | return byte; 212 | } 213 | 214 | /** 215 | * @brief This function is used to read bytes from FDCAN pipe. 216 | * @retval None. 217 | */ 218 | void OPENBL_FDCAN_ReadBytes(uint8_t *Buffer, uint32_t BufferSize) 219 | { 220 | /* check if FIFO 0 receive at least one message */ 221 | while (HAL_FDCAN_GetRxFifoFillLevel(&hfdcan, FDCAN_RX_FIFO0) < 1) 222 | { 223 | OPENBL_IWDG_Refresh(); 224 | } 225 | 226 | /* Retrieve Rx messages from RX FIFO0 */ 227 | HAL_FDCAN_GetRxMessage(&hfdcan, FDCAN_RX_FIFO0, &RxHeader, Buffer); 228 | } 229 | 230 | /** 231 | * @brief This function is used to send one byte through FDCAN pipe. 232 | * @param Byte The byte to be sent. 233 | * @retval None. 234 | */ 235 | void OPENBL_FDCAN_SendByte(uint8_t Byte) 236 | { 237 | TxHeader.DataLength = FDCAN_DLC_BYTES_1; 238 | 239 | while (HAL_FDCAN_GetTxFifoFreeLevel(&hfdcan) == 0) 240 | {} 241 | 242 | HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan, &TxHeader, &Byte); 243 | 244 | /* Wait that the data is completely sent (sent FIFO empty) */ 245 | while (((&hfdcan)->Instance->IR & FDCAN_IR_TFE) != FDCAN_IR_TFE) 246 | {} 247 | 248 | /* Clear the complete flag */ 249 | (&hfdcan)->Instance->IR &= FDCAN_IR_TFE; 250 | } 251 | 252 | /** 253 | * @brief This function is used to send a buffer using FDCAN. 254 | * @param Buffer The data buffer to be sent. 255 | * @param BufferSize The size of the data buffer to be sent. 256 | * @retval None. 257 | */ 258 | void OPENBL_FDCAN_SendBytes(uint8_t *Buffer, uint32_t BufferSize) 259 | { 260 | TxHeader.DataLength = BufferSize; 261 | 262 | while (HAL_FDCAN_GetTxFifoFreeLevel(&hfdcan) == 0) 263 | {} 264 | 265 | HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan, &TxHeader, Buffer); 266 | 267 | /* Wait that the data is completely sent (sent FIFO empty) */ 268 | while (((&hfdcan)->Instance->IR & FDCAN_IR_TFE) != FDCAN_IR_TFE) 269 | {} 270 | 271 | /* Clear the complete flag */ 272 | (&hfdcan)->Instance->IR &= FDCAN_IR_TFE; 273 | } 274 | 275 | /** 276 | * @brief This function is used to process and execute the special commands. 277 | * The user must define the special commands routine here. 278 | * @retval Returns NACK status in case of error else returns ACK status. 279 | */ 280 | void OPENBL_FDCAN_SpecialCommandProcess(OPENBL_SpecialCmdTypeDef *Frame) 281 | { 282 | switch (Frame->OpCode) 283 | { 284 | /* Unknown command opcode */ 285 | default: 286 | if (Frame->CmdType == OPENBL_SPECIAL_CMD) 287 | { 288 | /* Send NULL data size */ 289 | TxData[0] = 0x0; 290 | TxData[1] = 0x0; 291 | 292 | /* Send NULL status size */ 293 | TxData[2] = 0x0; 294 | TxData[3] = 0x0; 295 | 296 | OPENBL_FDCAN_SendBytes(TxData, FDCAN_DLC_BYTES_4); 297 | } 298 | else if (Frame->CmdType == OPENBL_EXTENDED_SPECIAL_CMD) 299 | { 300 | /* Send NULL status size */ 301 | TxData[0] = 0x0; 302 | TxData[1] = 0x0; 303 | 304 | OPENBL_FDCAN_SendBytes(TxData, FDCAN_DLC_BYTES_2); 305 | } 306 | break; 307 | } 308 | } 309 | --------------------------------------------------------------------------------