From 3919b69d6af383f5b2b9a75af144c04ebee123f6 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 12 Mar 2020 17:34:26 +0100 Subject: [PATCH 1/3] Add HAL and CMSIS patch Signed-off-by: Frederic Pillon --- .gitattributes | 1 + ...MP1-Review-HAL-default-configuration.patch | 26 ++++ ...enerate-Start-only-once-Stop-is-fini.patch | 146 ++++++++++++++++++ ...enerate-Start-only-once-Stop-is-fini.patch | 146 ++++++++++++++++++ ...CC_USART3-definition-for-STM32F412Cx.patch | 104 +++++++++++++ ...enerate-Start-only-once-Stop-is-fini.patch | 146 ++++++++++++++++++ .../HAL/G0/0001-G0-Fix-HAL-definition.patch | 29 ++++ ...ild-issue-introduce-in-HAL-version-v.patch | 38 +++++ ...enerate-Start-only-once-Stop-is-fini.patch | 146 ++++++++++++++++++ 9 files changed, 782 insertions(+) create mode 100644 CI/utils/patch/CMSIS/MP1/0001-MP1-Review-HAL-default-configuration.patch create mode 100644 CI/utils/patch/HAL/F1/0001-F1-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch create mode 100644 CI/utils/patch/HAL/F2/0001-F2-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch create mode 100644 CI/utils/patch/HAL/F4/0001-F4-Fix-HAL_RCC_USART3-definition-for-STM32F412Cx.patch create mode 100644 CI/utils/patch/HAL/F4/0001-F4-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch create mode 100644 CI/utils/patch/HAL/G0/0001-G0-Fix-HAL-definition.patch create mode 100644 CI/utils/patch/HAL/G4/0001-G4-Fix-LL-FMC-build-issue-introduce-in-HAL-version-v.patch create mode 100644 CI/utils/patch/HAL/L1/0001-L1-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch diff --git a/.gitattributes b/.gitattributes index 1283f63835..97c0d7d583 100644 --- a/.gitattributes +++ b/.gitattributes @@ -26,6 +26,7 @@ *.md text eol=lf *.MD text eol=lf *.old text eol=lf +*.patch text eol=lf *.pde text eol=lf *.properties text eol=lf *.py text eol=lf diff --git a/CI/utils/patch/CMSIS/MP1/0001-MP1-Review-HAL-default-configuration.patch b/CI/utils/patch/CMSIS/MP1/0001-MP1-Review-HAL-default-configuration.patch new file mode 100644 index 0000000000..55b55b3eda --- /dev/null +++ b/CI/utils/patch/CMSIS/MP1/0001-MP1-Review-HAL-default-configuration.patch @@ -0,0 +1,26 @@ +From 01b39c624995928905b99b3ce211482d27d0d1bc Mon Sep 17 00:00:00 2001 +From: Bumsik Kim +Date: Sat, 12 Oct 2019 21:50:30 +0900 +Subject: [PATCH 1/1] [MP1] Review HAL default configuration + +--- + .../Device/ST/STM32MP1xx/Include/stm32mp1xx.h | 6 +- + .../STM32MP1xx/stm32mp1xx_hal_conf_default.h | 89 ++++++++++--------- + 2 files changed, 49 insertions(+), 46 deletions(-) + +diff --git a/system/Drivers/CMSIS/Device/ST/STM32MP1xx/Include/stm32mp1xx.h b/system/Drivers/CMSIS/Device/ST/STM32MP1xx/Include/stm32mp1xx.h +index 10395b51..528b9b91 100644 +--- a/system/Drivers/CMSIS/Device/ST/STM32MP1xx/Include/stm32mp1xx.h ++++ b/system/Drivers/CMSIS/Device/ST/STM32MP1xx/Include/stm32mp1xx.h +@@ -197,7 +197,7 @@ typedef enum + */ + + #if defined (USE_HAL_DRIVER) +- #include "stm32mp1xx_hal_conf.h" ++ #include "stm32mp1xx_hal.h" + #endif /* USE_HAL_DRIVER */ + + +-- +2.25.1.windows.1 + diff --git a/CI/utils/patch/HAL/F1/0001-F1-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch b/CI/utils/patch/HAL/F1/0001-F1-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch new file mode 100644 index 0000000000..1350923187 --- /dev/null +++ b/CI/utils/patch/HAL/F1/0001-F1-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch @@ -0,0 +1,146 @@ +From 4aba75ec152a2d2c65d07c1912da9eb4ea08be2e Mon Sep 17 00:00:00 2001 +From: Alexandre Bourdiol +Date: Mon, 27 Jan 2020 18:23:15 +0100 +Subject: [PATCH 1/1] [F1] I2C HAL fix: generate Start only once Stop is + finished + +--- + .../Src/stm32f1xx_hal_i2c.c | 87 ++++++++++++++++++- + 1 file changed, 86 insertions(+), 1 deletion(-) + +diff --git a/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c b/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c +index 6e74e699..fc108e0b 100644 +--- a/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c ++++ b/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c +@@ -3492,6 +3492,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3591,6 +3612,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3757,6 +3799,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_ + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3882,6 +3945,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -4565,7 +4649,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA + UNUSED(DevAddress); + + /* Abort Master transfer during Receive or Transmit process */ +- if (hi2c->Mode == HAL_I2C_MODE_MASTER) ++ if ((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET) && (hi2c->Mode == HAL_I2C_MODE_MASTER)) + { + /* Process Locked */ + __HAL_LOCK(hi2c); +@@ -4596,6 +4680,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA + { + /* Wrong usage of abort function */ + /* This function should be used only in case of abort monitored by master device */ ++ /* Or periphal is not in busy state, mean there is no active sequence to be abort */ + return HAL_ERROR; + } + } +-- +2.25.1.windows.1 + diff --git a/CI/utils/patch/HAL/F2/0001-F2-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch b/CI/utils/patch/HAL/F2/0001-F2-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch new file mode 100644 index 0000000000..a4d01c0818 --- /dev/null +++ b/CI/utils/patch/HAL/F2/0001-F2-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch @@ -0,0 +1,146 @@ +From d5815c606105adc2d390f9bac704934c923ea674 Mon Sep 17 00:00:00 2001 +From: Alexandre Bourdiol +Date: Tue, 28 Jan 2020 09:37:52 +0100 +Subject: [PATCH 1/1] [F2] I2C HAL fix: generate Start only once Stop is + finished + +--- + .../Src/stm32f2xx_hal_i2c.c | 87 ++++++++++++++++++- + 1 file changed, 86 insertions(+), 1 deletion(-) + +diff --git a/system/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_i2c.c b/system/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_i2c.c +index a8bcf8c5..4c7b5483 100644 +--- a/system/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_i2c.c ++++ b/system/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_i2c.c +@@ -3428,6 +3428,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3527,6 +3548,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3693,6 +3735,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_ + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3818,6 +3881,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -4501,7 +4585,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA + UNUSED(DevAddress); + + /* Abort Master transfer during Receive or Transmit process */ +- if (hi2c->Mode == HAL_I2C_MODE_MASTER) ++ if ((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET) && (hi2c->Mode == HAL_I2C_MODE_MASTER)) + { + /* Process Locked */ + __HAL_LOCK(hi2c); +@@ -4532,6 +4616,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA + { + /* Wrong usage of abort function */ + /* This function should be used only in case of abort monitored by master device */ ++ /* Or periphal is not in busy state, mean there is no active sequence to be abort */ + return HAL_ERROR; + } + } +-- +2.25.1.windows.1 + diff --git a/CI/utils/patch/HAL/F4/0001-F4-Fix-HAL_RCC_USART3-definition-for-STM32F412Cx.patch b/CI/utils/patch/HAL/F4/0001-F4-Fix-HAL_RCC_USART3-definition-for-STM32F412Cx.patch new file mode 100644 index 0000000000..bc446005de --- /dev/null +++ b/CI/utils/patch/HAL/F4/0001-F4-Fix-HAL_RCC_USART3-definition-for-STM32F412Cx.patch @@ -0,0 +1,104 @@ +From e1ff95c19abc965bb733a3a2f8f3b837762ba415 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon +Date: Fri, 6 Mar 2020 16:12:44 +0100 +Subject: [PATCH 1/1] [F4] Fix HAL_RCC_USART3 definition for STM32F412Cx + +Signed-off-by: Frederic Pillon +--- + .../Inc/stm32f4xx_hal_rcc_ex.h | 17 ----------------- + 1 file changed, 17 deletions(-) + +diff --git a/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h b/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h +index 7b47f81a..7eb36cde 100644 +--- a/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h ++++ b/system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h +@@ -4969,7 +4969,6 @@ typedef struct + tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_RTCAPBEN);\ + UNUSED(tmpreg); \ + } while(0U) +-#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_USART3_CLK_ENABLE() do { \ + __IO uint32_t tmpreg = 0x00U; \ + SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\ +@@ -4977,8 +4976,6 @@ typedef struct + tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\ + UNUSED(tmpreg); \ + } while(0U) +-#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */ +- + #if defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_UART4_CLK_ENABLE() do { \ + __IO uint32_t tmpreg = 0x00U; \ +@@ -5098,9 +5095,7 @@ typedef struct + #endif /* STM32F413xx || STM32F423xx */ + #define __HAL_RCC_RTCAPB_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_RTCAPBEN)) + #define __HAL_RCC_SPI3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_SPI3EN)) +-#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_USART3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART3EN)) +-#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */ + #if defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_UART4_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_UART4EN)) + #define __HAL_RCC_UART5_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_UART5EN)) +@@ -5140,9 +5135,7 @@ typedef struct + #endif /* STM32F413xx || STM32F423xx */ + #define __HAL_RCC_RTCAPB_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_RTCAPBEN)) != RESET) + #define __HAL_RCC_SPI3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_SPI3EN)) != RESET) +-#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_USART3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART3EN)) != RESET) +-#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx | STM32F423xx */ + #if defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_UART4_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_UART4EN)) != RESET) + #define __HAL_RCC_UART5_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_UART5EN)) != RESET) +@@ -5171,9 +5164,7 @@ typedef struct + #endif /* STM32F413xx || STM32F423xx */ + #define __HAL_RCC_RTCAPB_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_RTCAPBEN)) == RESET) + #define __HAL_RCC_SPI3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_SPI3EN)) == RESET) +-#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_USART3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART3EN)) == RESET) +-#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx | STM32F423xx */ + #if defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_UART4_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_UART4EN)) == RESET) + #define __HAL_RCC_UART5_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_UART5EN)) == RESET) +@@ -5445,9 +5436,7 @@ typedef struct + #define __HAL_RCC_LPTIM1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_LPTIM1RST)) + #endif /* STM32F413xx || STM32F423xx */ + #define __HAL_RCC_SPI3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_SPI3RST)) +-#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_USART3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART3RST)) +-#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */ + #if defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_UART4_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_UART4RST)) + #define __HAL_RCC_UART5_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_UART5RST)) +@@ -5475,9 +5464,7 @@ typedef struct + #define __HAL_RCC_LPTIM1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_LPTIM1RST)) + #endif /* STM32F413xx || STM32F423xx */ + #define __HAL_RCC_SPI3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_SPI3RST)) +-#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_USART3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART3RST)) +-#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */ + #if defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_UART4_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_UART4RST)) + #define __HAL_RCC_UART5_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_UART5RST)) +@@ -5633,9 +5620,7 @@ typedef struct + #endif /* STM32F413xx || STM32F423xx */ + #define __HAL_RCC_RTCAPB_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_RTCAPBLPEN)) + #define __HAL_RCC_SPI3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_SPI3LPEN)) +-#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_USART3_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_USART3LPEN)) +-#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */ + #if defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_UART4_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_UART4LPEN)) + #define __HAL_RCC_UART5_CLK_SLEEP_ENABLE() (RCC->APB1LPENR |= (RCC_APB1LPENR_UART5LPEN)) +@@ -5664,9 +5649,7 @@ typedef struct + #endif /* STM32F413xx || STM32F423xx */ + #define __HAL_RCC_RTCAPB_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_RTCAPBLPEN)) + #define __HAL_RCC_SPI3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_SPI3LPEN)) +-#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_USART3_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_USART3LPEN)) +-#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */ + #if defined(STM32F413xx) || defined(STM32F423xx) + #define __HAL_RCC_UART4_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_UART4LPEN)) + #define __HAL_RCC_UART5_CLK_SLEEP_DISABLE() (RCC->APB1LPENR &= ~(RCC_APB1LPENR_UART5LPEN)) +-- +2.25.1.windows.1 + diff --git a/CI/utils/patch/HAL/F4/0001-F4-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch b/CI/utils/patch/HAL/F4/0001-F4-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch new file mode 100644 index 0000000000..00e9233218 --- /dev/null +++ b/CI/utils/patch/HAL/F4/0001-F4-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch @@ -0,0 +1,146 @@ +From 71d1bf079cd7327a2a8433f303ecaa032581ae68 Mon Sep 17 00:00:00 2001 +From: Alexandre Bourdiol +Date: Tue, 28 Jan 2020 09:38:07 +0100 +Subject: [PATCH 1/1] [F4] I2C HAL fix: generate Start only once Stop is + finished + +--- + .../Src/stm32f4xx_hal_i2c.c | 87 ++++++++++++++++++- + 1 file changed, 86 insertions(+), 1 deletion(-) + +diff --git a/system/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c b/system/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c +index 8bb84169..7f311a85 100644 +--- a/system/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c ++++ b/system/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c +@@ -3438,6 +3438,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3537,6 +3558,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3703,6 +3745,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_ + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3828,6 +3891,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -4511,7 +4595,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA + UNUSED(DevAddress); + + /* Abort Master transfer during Receive or Transmit process */ +- if (hi2c->Mode == HAL_I2C_MODE_MASTER) ++ if ((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET) && (hi2c->Mode == HAL_I2C_MODE_MASTER)) + { + /* Process Locked */ + __HAL_LOCK(hi2c); +@@ -4542,6 +4626,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA + { + /* Wrong usage of abort function */ + /* This function should be used only in case of abort monitored by master device */ ++ /* Or periphal is not in busy state, mean there is no active sequence to be abort */ + return HAL_ERROR; + } + } +-- +2.25.1.windows.1 + diff --git a/CI/utils/patch/HAL/G0/0001-G0-Fix-HAL-definition.patch b/CI/utils/patch/HAL/G0/0001-G0-Fix-HAL-definition.patch new file mode 100644 index 0000000000..2a01f01422 --- /dev/null +++ b/CI/utils/patch/HAL/G0/0001-G0-Fix-HAL-definition.patch @@ -0,0 +1,29 @@ +From 094df96e87da0370f30012eba4458f8765796522 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon +Date: Fri, 10 Jan 2020 17:42:33 +0100 +Subject: [PATCH 1/1] [G0] Fix HAL definition + +PWR_WAKEUP_PIN5 should be defined only if PWR_CR3_EWUP5 is defined + +Signed-off-by: Frederic Pillon +--- + system/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_pwr.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/system/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_pwr.h b/system/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_pwr.h +index 65e25db6..79819d60 100644 +--- a/system/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_pwr.h ++++ b/system/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_pwr.h +@@ -133,7 +133,9 @@ typedef struct + #define PWR_WAKEUP_PIN1 PWR_CR3_EWUP1 /*!< Wakeup pin 1 (with high level detection) */ + #define PWR_WAKEUP_PIN2 PWR_CR3_EWUP2 /*!< Wakeup pin 2 (with high level detection) */ + #define PWR_WAKEUP_PIN4 PWR_CR3_EWUP4 /*!< Wakeup pin 4 (with high level detection) */ ++#if defined(PWR_CR3_EWUP5) + #define PWR_WAKEUP_PIN5 PWR_CR3_EWUP5 /*!< Wakeup pin 5 (with high level detection) */ ++#endif + #define PWR_WAKEUP_PIN6 PWR_CR3_EWUP6 /*!< Wakeup pin 6 (with high level detection) */ + #define PWR_WAKEUP_PIN1_HIGH PWR_CR3_EWUP1 /*!< Wakeup pin 1 (with high level detection) */ + #define PWR_WAKEUP_PIN2_HIGH PWR_CR3_EWUP2 /*!< Wakeup pin 2 (with high level detection) */ +-- +2.25.1.windows.1 + diff --git a/CI/utils/patch/HAL/G4/0001-G4-Fix-LL-FMC-build-issue-introduce-in-HAL-version-v.patch b/CI/utils/patch/HAL/G4/0001-G4-Fix-LL-FMC-build-issue-introduce-in-HAL-version-v.patch new file mode 100644 index 0000000000..0fd157734f --- /dev/null +++ b/CI/utils/patch/HAL/G4/0001-G4-Fix-LL-FMC-build-issue-introduce-in-HAL-version-v.patch @@ -0,0 +1,38 @@ +From d7d9cd95fe4cf23e3ed5aadd8023bfcae40303f1 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon +Date: Sat, 4 Apr 2020 15:00:12 +0200 +Subject: [PATCH 1/1] [G4] Fix LL FMC build issue introduce in HAL version + v1.1.1 + +Guard have been removed while they should not. + +Signed-off-by: Frederic Pillon +--- + system/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_fmc.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/system/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_fmc.c b/system/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_fmc.c +index 12439fe3..6272a9d7 100644 +--- a/system/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_fmc.c ++++ b/system/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_fmc.c +@@ -63,7 +63,7 @@ + * @brief FMC driver modules + * @{ + */ +- ++#if defined (HAL_SRAM_MODULE_ENABLED) || defined(HAL_NOR_MODULE_ENABLED) || defined(HAL_NAND_MODULE_ENABLED) + /* Private typedef -----------------------------------------------------------*/ + /* Private define ------------------------------------------------------------*/ + +@@ -766,7 +766,7 @@ HAL_StatusTypeDef FMC_NAND_GetECC(FMC_NAND_TypeDef *Device, uint32_t *ECCval, ui + /** + * @} + */ +- ++#endif /* HAL_SRAM_MODULE_ENABLED || HAL_NOR_MODULE_ENABLED || HAL_NAND_MODULE_ENABLED */ + /** + * @} + */ +-- +2.25.1.windows.1 + diff --git a/CI/utils/patch/HAL/L1/0001-L1-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch b/CI/utils/patch/HAL/L1/0001-L1-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch new file mode 100644 index 0000000000..12a4bfcf15 --- /dev/null +++ b/CI/utils/patch/HAL/L1/0001-L1-I2C-HAL-fix-generate-Start-only-once-Stop-is-fini.patch @@ -0,0 +1,146 @@ +From 709dbc26c6fa3c8265a5cf1a7164e721261e07c2 Mon Sep 17 00:00:00 2001 +From: Alexandre Bourdiol +Date: Tue, 28 Jan 2020 09:38:45 +0100 +Subject: [PATCH 1/1] [L1] I2C HAL fix: generate Start only once Stop is + finished + +--- + .../Src/stm32l1xx_hal_i2c.c | 87 ++++++++++++++++++- + 1 file changed, 86 insertions(+), 1 deletion(-) + +diff --git a/system/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_i2c.c b/system/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_i2c.c +index 8152a9a6..dd90a236 100644 +--- a/system/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_i2c.c ++++ b/system/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_i2c.c +@@ -3416,6 +3416,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3515,6 +3536,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3681,6 +3723,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_ + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -3798,6 +3861,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16 + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); + } + ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ ++ /* Wait until STOP flag is reset */ ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); ++ do ++ { ++ count--; ++ if (count == 0U) ++ { ++ hi2c->PreviousState = I2C_STATE_NONE; ++ hi2c->State = HAL_I2C_STATE_READY; ++ hi2c->Mode = HAL_I2C_MODE_NONE; ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; ++ ++ /* Process Unlocked */ ++ __HAL_UNLOCK(hi2c); ++ ++ return HAL_ERROR; ++ } ++ } ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); ++ + /* Process Locked */ + __HAL_LOCK(hi2c); + +@@ -4465,7 +4549,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA + UNUSED(DevAddress); + + /* Abort Master transfer during Receive or Transmit process */ +- if (hi2c->Mode == HAL_I2C_MODE_MASTER) ++ if ((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET) && (hi2c->Mode == HAL_I2C_MODE_MASTER)) + { + /* Process Locked */ + __HAL_LOCK(hi2c); +@@ -4496,6 +4580,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA + { + /* Wrong usage of abort function */ + /* This function should be used only in case of abort monitored by master device */ ++ /* Or periphal is not in busy state, mean there is no active sequence to be abort */ + return HAL_ERROR; + } + } +-- +2.25.1.windows.1 + From 506d261cd2dc23568ce6ee2f2a91a53b8b628d24 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 19 Mar 2020 16:46:19 +0100 Subject: [PATCH 2/3] Port gen_wrapper from bash to python Signed-off-by: Frederic Pillon --- CI/utils/stm32wrapper.py | 291 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 291 insertions(+) create mode 100644 CI/utils/stm32wrapper.py diff --git a/CI/utils/stm32wrapper.py b/CI/utils/stm32wrapper.py new file mode 100644 index 0000000000..25f4a3dad8 --- /dev/null +++ b/CI/utils/stm32wrapper.py @@ -0,0 +1,291 @@ +import argparse +import glob +import re +import os +from stm32common import createFolder, deleteFolder, genSTM32List + +script_path = os.path.dirname(os.path.abspath(__file__)) +home = os.path.expanduser("~") +# Base path +core_path = os.path.abspath(os.path.join(script_path, "..", "..")) +SrcWrapper_path = "" +HALDrivers_path = "" +CMSIS_Device_ST_path = "" +CMSIS_DSP_lib_path = "" + +# CMSIS outside of the core. Can be updated by arg +CMSIS_path = os.path.abspath( + os.path.join(core_path, "..", "ArduinoModule-CMSIS", "CMSIS_5") +) +CMSIS_DSPSrc_path = "" + +# Out sources files +HALoutSrc_path = "" +LLoutSrc_path = "" +CMSIS_DSP_outSrc_path = "" + +# Out include files +LLoutInc_path = "" + +# Out startup files +CMSIS_Startupfile = "" + +all_LL_file = "stm32yyxx_ll.h" + +stm32_series = [] + + +def checkConfig(arg_core, arg_cmsis): + global core_path + global CMSIS_path + global CMSIS_DSPSrc_path + global SrcWrapper_path + global HALDrivers_path + global CMSIS_Device_ST_path + global CMSIS_DSP_lib_path + global CMSIS_DSP_outSrc_path + global CMSIS_Startupfile + global HALoutSrc_path + global LLoutSrc_path + global LLoutInc_path + + if arg_core is not None: + core_path = arg_core + CMSIS_path = os.path.abspath( + os.path.join(core_path, "..", "ArduinoModule-CMSIS", "CMSIS_5") + ) + + if not os.path.isdir(core_path): + print("Could not find " + core_path) + exit(1) + + SrcWrapper_path = os.path.join(core_path, "libraries", "SrcWrapper") + HALDrivers_path = os.path.join(core_path, "system", "Drivers") + CMSIS_Device_ST_path = os.path.join( + core_path, "system", "Drivers", "CMSIS", "Device", "ST" + ) + CMSIS_DSP_lib_path = os.path.join(core_path, "libraries", "CMSIS_DSP") + CMSIS_DSP_outSrc_path = os.path.join(CMSIS_DSP_lib_path, "src") + CMSIS_Startupfile = os.path.join( + core_path, "cores", "arduino", "stm32", "stm32_def_build.h" + ) + + HALoutSrc_path = os.path.join(SrcWrapper_path, "src", "HAL") + LLoutSrc_path = os.path.join(SrcWrapper_path, "src", "LL") + LLoutInc_path = os.path.join(core_path, "cores", "arduino", "stm32", "LL") + + if arg_cmsis is not None: + CMSIS_path = arg_cmsis + CMSIS_DSPSrc_path = os.path.join(CMSIS_path, "CMSIS", "DSP", "Source") + + +# Add some pragma to ll header files to avoid several warnings +# which will be corrected along Cube update +def print_LL_header(open_file, name): + upper = name.upper().replace(".", "_") + open_file.write( + """#ifndef _{0}_ +#define _{0}_ +/* LL raised several warnings, ignore them */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored \"-Wunused-parameter\" +#pragma GCC diagnostic ignored \"-Wstrict-aliasing\" + +""".format( + upper + ) + ) + + +def printCMSISStartup(log): + filelist = glob.glob( + os.path.join( + CMSIS_Device_ST_path, "STM32*", "Source", "Templates", "gcc", "startup_*.s", + ) + ) + if len(filelist): + if log: + print("Number of startup files: %i" % len(filelist)) + out_file = open(CMSIS_Startupfile, "w", newline="\n") + # Header + out_file.write( + """#ifndef _STM32_DEF_BUILD_ +#define _STM32_DEF_BUILD_ + +#if !defined(CMSIS_STARTUP_FILE) && !defined(CUSTOM_STARTUP_FILE) +""" + ) + # File name + fn = os.path.basename(filelist.pop(0)) + valueline = re.split("_|\\.", fn) + upper = valueline[1].upper().replace("X", "x") + out_file.write( + """ #if defined({}) + #define CMSIS_STARTUP_FILE \"{}\" +""".format( + upper, fn + ) + ) + if len(filelist): + for fp in filelist: + # File name + fn = os.path.basename(fp) + valueline = re.split("_|\\.", fn) + upper = ( + valueline[1].upper().replace("X", "x").replace("MP15xx", "MP1xx") + ) + out_file.write( + """ #elif defined({}) + #define CMSIS_STARTUP_FILE \"{}\" +""".format( + upper, fn + ) + ) + # footer + out_file.write( + """ #else + #error UNKNOWN CHIP + #endif +#else + #warning \"No CMSIS startup file defined, custom one should be used\" +#endif /* !CMSIS_STARTUP_FILE && !CUSTOM_STARTUP_FILE */ +#endif /* _STM32_DEF_BUILD_ */ +""" + ) + out_file.close() + else: + if log: + print("No startup files found!") + + +def wrap(arg_core, arg_cmsis, log): + global stm32_series + # check config have to be done first + checkConfig(arg_core, arg_cmsis) + stm32_series = genSTM32List(HALDrivers_path, "") + + # Remove old file + deleteFolder(HALoutSrc_path) + createFolder(HALoutSrc_path) + deleteFolder(LLoutSrc_path) + createFolder(LLoutSrc_path) + deleteFolder(LLoutInc_path) + createFolder(LLoutInc_path) + if os.path.isfile(CMSIS_Startupfile): + os.remove(CMSIS_Startupfile) + full_ll_list = [] + # Search all files for each series + for serie in stm32_series: + src = os.path.join(HALDrivers_path, "STM32" + serie + "xx_HAL_Driver", "Src") + inc = os.path.join(HALDrivers_path, "STM32" + serie + "xx_HAL_Driver", "Inc") + + if os.path.exists(src): + if log: + print("Generating for " + serie + "...") + lower = serie.lower() + # Generate stm32yyxx_[hal|ll]*.c file + filelist = glob.glob(os.path.join(src, "stm32" + lower + "xx_*.c")) + for fp in filelist: + if "_template" in fp: + continue + outp = HALoutSrc_path + # File name + fn = os.path.basename(fp) + if "_ll_" in fn: + outp = LLoutSrc_path + # Compute generic file name with path + gp = os.path.join(outp, fn.replace(lower, "yy")) + out_file = open(gp, "a", newline="\n") + # Amend file name under serie switch + out_file.write("#ifdef STM32" + serie + "xx\n") + out_file.write(' #include "' + fn + '"\n') + out_file.write("#endif\n") + out_file.close() + # Generate stm32yyxx_ll_*.h file + filelist = glob.glob(os.path.join(inc, "stm32" + lower + "xx_ll_*.h")) + for fp in filelist: + outp = LLoutInc_path + # File name + fn = os.path.basename(fp) + # Compute generic file name + gn = fn.replace(lower, "yy") + # with path + gp = os.path.join(outp, gn) + out_file = open(gp, "a", newline="\n") + if os.path.getsize(gp) == 0: + print_LL_header(out_file, gn) + # Amend full LL header file + full_ll_list.append(gn) + # Amend file name under serie switch + out_file.write("#ifdef STM32" + serie + "xx\n") + out_file.write(' #include "' + fn + '"\n') + out_file.write("#endif\n") + out_file.close() + if log: + print("done") + + # Filter full LL header file + full_ll_file = open(os.path.join(LLoutInc_path, all_LL_file), "w", newline="\n") + print_LL_header(full_ll_file, all_LL_file) + full_ll_file.write("/* Include Low Layers drivers */\n") + full_ll_list = sorted(set(full_ll_list)) + for hn in full_ll_list: + full_ll_file.write('#include "' + hn + '"\n') + full_ll_file.close() + + # Search all LL header files to end guard + filelist = glob.glob(os.path.join(LLoutInc_path, "stm32yyxx_ll*.h")) + for fp in filelist: + out_file = open(fp, "a", newline="\n") + upper = os.path.basename(fp).upper().replace(".", "_") + out_file.write("#pragma GCC diagnostic pop\n") + out_file.write("#endif /* _" + upper + "_ */\n") + out_file.close() + + # CMSIS startup files + printCMSISStartup(log) + + # CMSIS DSP C source file + if not os.path.isdir(CMSIS_path): + print("Could not find " + CMSIS_path) + print("CMSIS DSP generation skipped.") + else: + # Delete all subfolders + deleteFolder(os.path.join(CMSIS_DSP_outSrc_path, "*")) + dirlist = [] + for root, dirs, files in os.walk(CMSIS_DSPSrc_path): + for file in files: + if file.endswith(".c"): + dirlist.append(root.replace(CMSIS_DSPSrc_path, "")[1:]) + dirlist = sorted(set(dirlist)) + for dn in dirlist: + fdn = os.path.join(CMSIS_DSP_outSrc_path, dn) + if not os.path.isdir(fdn): + createFolder(fdn) + out_file = open(os.path.join(fdn, dn + ".c"), "w", newline="\n") + out_file.write('#include "../Source/{0}/{0}.c"\n'.format(dn)) + out_file.close() + return 0 + + +if __name__ == "__main__": + # Parser + wrapparser = argparse.ArgumentParser( + description="Generate all wrappers files need by the STM32 core (HAL, LL, CMSIS, ...)" + ) + wrapparser.add_argument( + "-c", + "--core", + metavar="core_path", + help="Root path of the STM32 core. Default: " + core_path, + ) + wrapparser.add_argument( + "-s", + "--cmsis", + metavar="cmsis_path", + help="Root path of the CMSIS. Default: " + CMSIS_path, + ) + + wrapargs = wrapparser.parse_args() + + wrap(wrapargs.core, wrapargs.cmsis, True) From 92d12a79b6652dfbe5e7561ead1c7aeea11fd0e2 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 25 Feb 2020 16:31:26 +0100 Subject: [PATCH 3/3] Add script to update HAL drivers and CMSIS devices from STM32cube released on GitHub Signed-off-by: Frederic Pillon --- .gitignore | 1 + CI/utils/stm32common.py | 44 ++++ CI/utils/stm32update.py | 531 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 576 insertions(+) create mode 100644 CI/utils/stm32common.py create mode 100644 CI/utils/stm32update.py diff --git a/.gitignore b/.gitignore index dcb5ca83ae..09c3fe77c7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ astyle.out boards.local.txt platform.local.txt path_config.json +update_config.json # Backup *.bak diff --git a/CI/utils/stm32common.py b/CI/utils/stm32common.py new file mode 100644 index 0000000000..45e2adaab1 --- /dev/null +++ b/CI/utils/stm32common.py @@ -0,0 +1,44 @@ +import os +import re +import shutil + + +# Create a folder if not exists +def createFolder(path): + try: + if not os.path.exists(path): + os.makedirs(path) + except OSError: + print("Error: Creating directory. " + path) + + +# Delete targeted folder recursively +def deleteFolder(path): + if os.path.isdir(path): + shutil.rmtree(path, ignore_errors=True) + + +# copy src folder recursively to dest +def copyFolder(src, dest, ign_patt=set()): + try: + if os.path.isdir(src): + shutil.copytree(src, dest, ignore=shutil.ignore_patterns(*ign_patt)) + except OSError as e: + print("Error: Folder %s not copied. %s" % src, e) + + +def genSTM32List(path, pattern): + stm32_list = [] # Serie + dir_pattern = re.compile("^STM32(.*)xx_HAL_Driver$", re.IGNORECASE) + + if pattern is not None: + serie_pattern = re.compile(pattern, re.IGNORECASE) + else: + serie_pattern = re.compile(".*", re.IGNORECASE) + + for file in os.listdir(path): + res = dir_pattern.match(file) + if res and serie_pattern.search(res.group(1)): + stm32_list.append(res.group(1)) + stm32_list.sort() + return stm32_list diff --git a/CI/utils/stm32update.py b/CI/utils/stm32update.py new file mode 100644 index 0000000000..685d9effdc --- /dev/null +++ b/CI/utils/stm32update.py @@ -0,0 +1,531 @@ +import argparse +import collections +import fileinput +import json +import os +from packaging import version +import re +import subprocess +import sys +from urllib.parse import urljoin +import stm32wrapper +from stm32common import createFolder, deleteFolder, copyFolder, genSTM32List + +if sys.platform.startswith("win32"): + from colorama import init + + init(autoreset=True) + +script_path = os.path.dirname(os.path.abspath(__file__)) +home = os.path.expanduser("~") +path_config_filename = "update_config.json" + +# GitHub +gh_st = "https://github.com/STMicroelectronics/" +gh_core = "https://github.com/stm32duino/Arduino_Core_STM32.git" +repo_generic_name = "STM32Cube" +repo_core_name = "Arduino_Core_STM32" +repo_local_path = os.path.join(home, "STM32Cube_repo") + +# From +# Relative to repo path +hal_src_path = "Drivers" +cmsis_src_path = os.path.join("Drivers", "CMSIS", "Device", "ST") +# To +hal_dest_path = os.path.join("system", "Drivers") +cmsis_dest_path = os.path.join("system", "Drivers", "CMSIS", "Device", "ST") + +stm32_list = [] # Serie +cube_versions = collections.OrderedDict() # key: serie name, value: cube version +cube_HAL_versions = collections.OrderedDict() # key: serie name, value: HAL version +cube_CMSIS_versions = collections.OrderedDict() # key: serie name, value: CMSIS version +core_HAL_versions = collections.OrderedDict() # key: serie name, value: HAL version +core_CMSIS_versions = collections.OrderedDict() # key: serie name, value: CMSIS version + +# MD to update +md_CMSIS_path = "STM32YYxx_CMSIS_version.md" +md_HAL_path = "STM32YYxx_HAL_Driver_version.md" + +# Format +out_format_Header = "| {:^22} | {:^31} | {:^31} |" +out_subheader = "| {:^4} | {:^7} | {:^8} | {:^8} | {:^1} | {:^8} | {:^8} | {:^1} |" +out_format = "| {:^12} | {:^7} | {:^8} | {:^8} | {:^1} | {:^8} | {:^8} | {:^1} |" +out_separator = "-" * 70 + + +def create_config(): + global repo_local_path + + # Create a Json file for a better path management + print( + "'{}' file created. Please check the configuration.".format( + os.path.join(script_path, path_config_filename) + ) + ) + path_config_file = open(path_config_filename, "w") + path_config_file.write(json.dumps({"REPO_LOCAL_PATH": repo_local_path}, indent=2)) + path_config_file.close() + exit(1) + + +def checkConfig(): + global repo_local_path + global hal_dest_path + global cmsis_dest_path + global md_HAL_path + global md_CMSIS_path + if os.path.isfile(os.path.join(script_path, path_config_filename)): + try: + path_config_file = open( + os.path.join(script_path, path_config_filename), "r" + ) + path_config = json.load(path_config_file) + # Common path + repo_local_path = path_config["REPO_LOCAL_PATH"] + path_config_file.close() + hal_dest_path = os.path.join(repo_local_path, repo_core_name, hal_dest_path) + md_HAL_path = os.path.join(hal_dest_path, md_HAL_path) + cmsis_dest_path = os.path.join( + repo_local_path, repo_core_name, cmsis_dest_path + ) + md_CMSIS_path = os.path.join(cmsis_dest_path, md_CMSIS_path) + except IOError: + print("Failed to open " + path_config_file) + else: + create_config() + createFolder(repo_local_path) + + +def updateCoreRepo(): + # Handle core repo + repo_path = os.path.join(repo_local_path, repo_core_name) + print("Updating " + repo_core_name + "...") + if os.path.exists(repo_path): + # Get new tags from the remote + git_cmds = [ + ["git", "-C", repo_path, "clean", "-fdx"], + ["git", "-C", repo_path, "fetch"], + ["git", "-C", repo_path, "reset", "--hard", "origin/master"], + ] + else: + # Clone it as it does not exists yet + git_cmds = [["git", "-C", repo_local_path, "clone", gh_core]] + try: + for cmd in git_cmds: + subprocess.check_output(cmd).decode("utf-8") + except subprocess.CalledProcessError as e: + print("Failed command: ") + print(e.cmd) + sys.exit(e.returncode) + + +def updateSTRepo(): + # Handle STM32Cube repo + for serie in stm32_list: + repo_name = repo_generic_name + serie + repo_path = os.path.join(repo_local_path, repo_name) + gh_STM32Cube = urljoin(gh_st, repo_name + ".git") + print("Updating " + repo_name + "...") + if os.path.exists(repo_path): + # Get new tags from the remote + git_cmds = [ + ["git", "-C", repo_path, "clean", "-fdx"], + ["git", "-C", repo_path, "fetch", "--tags"], + ["git", "-C", repo_path, "reset", "--hard", "origin/master"], + ] + else: + # Clone it as it does not exists yet + git_cmds = [["git", "-C", repo_local_path, "clone", gh_STM32Cube]] + try: + for cmd in git_cmds: + subprocess.check_output(cmd).decode("utf-8") + except subprocess.CalledProcessError as e: + print("Failed command: ") + print(e.cmd) + sys.exit(e.returncode) + latestTag(serie, repo_name, repo_path) + checkVersion(serie, repo_path) + + +def latestTag(serie, repo_name, repo_path): + global cube_versions + # Checkout the latest tag + try: + sha1_id = ( + subprocess.check_output( + ["git", "-C", repo_path, "rev-list", "--tags", "--max-count=1"] + ) + .decode("utf-8") + .strip() + ) + version_tag = ( + subprocess.check_output( + ["git", "-C", repo_path, "describe", "--tags", sha1_id] + ) + .decode("utf-8") + .strip() + ) + subprocess.check_output( + ["git", "-C", repo_path, "checkout", version_tag], stderr=subprocess.DEVNULL + ) + cube_versions[serie] = version_tag + # print("Latest tagged version available for " + repo_name + " is " + version_tag) + except subprocess.CalledProcessError as e: + print("Failed command: ") + print(e.cmd) + sys.exit(e.returncode) + + +def parseVersion(path): + main_found = False + sub1_found = False + sub2_found = False + if "HAL" in path: + main_pattern = re.compile(r"HAL_VERSION_MAIN.*0x([\dA-Fa-f]+)") + sub1_pattern = re.compile(r"HAL_VERSION_SUB1.*0x([\dA-Fa-f]+)") + sub2_pattern = re.compile(r"HAL_VERSION_SUB2.*0x([\dA-Fa-f]+)") + else: + main_pattern = re.compile( + r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_MAIN.*0x([\dA-Fa-f]+)" + ) + sub1_pattern = re.compile( + r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_SUB1.*0x([\dA-Fa-f]+)" + ) + sub2_pattern = re.compile( + r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_SUB2.*0x([\dA-Fa-f]+)" + ) + + for i, line in enumerate(open(path, encoding="utf8", errors="ignore")): + for match in re.finditer(main_pattern, line): + VERSION_MAIN = int(match.group(1), 16) + main_found = True + for match in re.finditer(sub1_pattern, line): + VERSION_SUB1 = int(match.group(1), 16) + sub1_found = True + for match in re.finditer(sub2_pattern, line): + VERSION_SUB2 = int(match.group(1), 16) + sub2_found = True + if main_found and sub1_found and sub2_found: + break + else: + print("Could not find the full version in " + path) + if main_found: + print("main version found: {}".format(VERSION_MAIN)) + VERSION_MAIN = "FF" + if sub1_found: + print("sub1 version found: {}".format(VERSION_SUB1)) + VERSION_SUB1 = "FF" + if sub2_found: + print("sub2 version found: {}".format(VERSION_SUB2)) + VERSION_SUB2 = "FF" + return "{}.{}.{}".format(VERSION_MAIN, VERSION_SUB1, VERSION_SUB2) + + +def checkVersion(serie, repo_path): + lserie = serie.lower() + userie = serie.upper() + HAL_file = os.path.join( + repo_path, + hal_src_path, + "STM32{}xx_HAL_Driver".format(userie), + "Src", + "stm32{}xx_hal.c".format(lserie), + ) + cube_HAL_versions[serie] = parseVersion(HAL_file) + HAL_file = os.path.join( + hal_dest_path, + "STM32{}xx_HAL_Driver".format(userie), + "Src", + "stm32{}xx_hal.c".format(lserie), + ) + core_HAL_versions[serie] = parseVersion(HAL_file) + + CMSIS_file = os.path.join( + repo_path, + cmsis_src_path, + "STM32{}xx".format(userie), + "Include", + "stm32{}xx.h".format(lserie), + ) + cube_CMSIS_versions[serie] = parseVersion(CMSIS_file) + CMSIS_file = os.path.join( + cmsis_dest_path, + "STM32{}xx".format(userie), + "Include", + "stm32{}xx.h".format(lserie), + ) + core_CMSIS_versions[serie] = parseVersion(CMSIS_file) + + # print("STM32Cube" + serie + " HAL version: " + cube_HAL_versions[serie]) + # print("STM32Core " + serie + " HAL version: " + core_HAL_versions[serie]) + # print("STM32Cube" + serie + " CMSIS version: " + cube_CMSIS_versions[serie]) + # print("STM32Core " + serie + " CMSIS version: " + core_CMSIS_versions[serie]) + + +def printVersion(): + print(out_separator) + print( + (out_format_Header).format( + "\033[1mCube Release\033[0m", + "\033[1mHAL version\033[0m", + "\033[1mCMSIS Version\033[0m", + ) + ) + print( + (out_subheader).format( + "Name", "Version", "Current", "New", "?", "Current", "New", "?" + ) + ) + print(out_separator) + for serie in stm32_list: + core_HAL_version = core_HAL_versions[serie] + cube_HAL_version = cube_HAL_versions[serie] + core_CMSIS_version = core_CMSIS_versions[serie] + cube_CMSIS_version = cube_CMSIS_versions[serie] + if version.parse(core_HAL_version) < version.parse(cube_HAL_version): + updateHAL = "\033[1;32m+\033[0m" + elif version.parse(core_HAL_version) == version.parse(cube_HAL_version): + updateHAL = "\033[1;34m=\033[0m" + else: + updateHAL = "\033[1;31m-\033[0m" + if version.parse(core_CMSIS_version) < version.parse(cube_CMSIS_version): + updateCMSIS = "\033[1;32m+\033[0m" + elif version.parse(core_CMSIS_version) == version.parse(cube_CMSIS_version): + updateCMSIS = "\033[1;34m=\033[0m" + else: + updateCMSIS = "\033[1;31m-\033[0m" + print( + (out_format).format( + "\033[1m{}\033[0m".format(serie), + cube_versions[serie], + core_HAL_version, + cube_HAL_version, + updateHAL, + core_CMSIS_version, + cube_CMSIS_version, + updateCMSIS, + ) + ) + print(out_separator) + + +# Commit files without trailing space +def commitFiles(repo_path, commit_msg): + try: + # Check if there is something to commit + status = subprocess.check_output( + ["git", "-C", repo_path, "status", "--untracked-files", "--short"] + ) + if not status: + return + # Staged all files: new, modified and deleted + subprocess.check_output( + ["git", "-C", repo_path, "add", "--all"], stderr=subprocess.DEVNULL + ) + # Commit all stage files with signoff and message + subprocess.check_output( + [ + "git", + "-C", + repo_path, + "commit", + "--all", + "--signoff", + "--message=" + commit_msg, + ], + stderr=subprocess.DEVNULL, + ) + # Remove trailing space + subprocess.check_output( + ["git", "-C", repo_path, "rebase", "--whitespace=fix", "HEAD~1"], + stderr=subprocess.DEVNULL, + ) + except subprocess.CalledProcessError as e: + print("Failed command: ") + print(e.cmd) + sys.exit(e.returncode) + + +# Apply all patches found for the dedicated serie +def applyPatch(serie, HAL_updated, CMSIS_updated, repo_path): + # First check if some patch need to be applied + patch_path = os.path.join(script_path, "patch") + patch_list = [] + if HAL_updated: + HAL_patch_path = os.path.join(patch_path, "HAL", serie) + if os.path.isdir(HAL_patch_path): + for file in os.listdir(HAL_patch_path): + if file.endswith(".patch"): + patch_list.append(os.path.join(HAL_patch_path, file)) + if CMSIS_updated: + CMSIS_patch_path = os.path.join(patch_path, "CMSIS", serie) + if os.path.isdir(CMSIS_patch_path): + for file in os.listdir(CMSIS_patch_path): + if file.endswith(".patch"): + patch_list.append(os.path.join(CMSIS_patch_path, file)) + + if len(patch_list): + patch_failed = [] + print( + "Apply {} patch{} for {}".format( + len(patch_list), "" if len(patch_list) == 1 else "es", serie + ) + ) + for patch in patch_list: + try: + # Test the patch before apply it + status = subprocess.check_output( + ["git", "-C", repo_path, "apply", "--check", patch], + stderr=subprocess.STDOUT, + ) + if status: + # print("patch {} can't be applied".format(patch)) + patch_failed.append([patch, status]) + continue + # Apply the patch + status = subprocess.check_output( + [ + "git", + "-C", + repo_path, + "am", + "--keep-non-patch", + "--quiet", + "--signoff", + patch, + ] + ) + except subprocess.CalledProcessError as e: + patch_failed.append([patch, e.cmd, e.output.decode("utf-8")]) + # print("Failed command: {}".format(e.cmd)) + if len(patch_failed): + for fp in patch_failed: + print( + "Failed to apply {}:\n{}{}".format( + fp[0], fp[1], "" if len(fp) == 2 else "\n--> {}".format(fp[2]) + ) + ) + + +def updateCore(): + for serie in stm32_list: + cube_name = repo_generic_name + serie + cube_path = os.path.join(repo_local_path, cube_name) + core_path = os.path.join(repo_local_path, repo_core_name) + core_HAL_version = core_HAL_versions[serie] + cube_HAL_version = cube_HAL_versions[serie] + core_CMSIS_version = core_CMSIS_versions[serie] + cube_CMSIS_version = cube_CMSIS_versions[serie] + cube_version = cube_versions[serie] + regexmd = re.compile(rf"(STM32{serie}:\s+)\d+.\d+.\d+") + HAL_updated = False + CMSIS_updated = False + hal_commit_msg = """[{0}] Update STM32{0}xx HAL Drivers to v{1} + +Included in STM32Cube{0} FW {2}""".format( + serie, cube_HAL_version, cube_version + ) + cmsis_commit_msg = """[{0}] Update STM32{0}xx CMSIS Drivers to v{1} + +Included in STM32Cube{0} FW {2}""".format( + serie, cube_CMSIS_version, cube_version + ) + wrapper_commit_msg = "[{}] Update wrapped files".format(serie) + + # Update HAL part if needed + if version.parse(core_HAL_version) < version.parse(cube_HAL_version): + print( + "Update " + + serie + + " HAL from version " + + core_HAL_version + + " to " + + cube_HAL_version + ) + # First delete old HAL version + HAL_serie_core_path = os.path.join( + core_path, hal_dest_path, "STM32{}xx_HAL_Driver".format(serie) + ) + deleteFolder(HAL_serie_core_path) + # Copy new one + HAL_serie_cube_path = os.path.join( + cube_path, hal_src_path, "STM32{}xx_HAL_Driver".format(serie) + ) + copyFolder(HAL_serie_cube_path, HAL_serie_core_path, {"*.chm"}) + # Update MD file + for line in fileinput.input(md_HAL_path, inplace=True): + line = regexmd.sub(rf"\g<1>{cube_HAL_version}", line) + print(line, end="") + # Commit all HAL files + commitFiles(core_path, hal_commit_msg) + HAL_updated = True + + if version.parse(core_CMSIS_version) < version.parse(cube_CMSIS_version): + print( + "Update " + + serie + + " CMSIS from version " + + core_CMSIS_version + + " to " + + cube_CMSIS_version + ) + # First delete CMSIS folder + CMSIS_serie_dest_path = os.path.join( + core_path, cmsis_dest_path, "STM32{}xx".format(serie.upper()) + ) + deleteFolder(CMSIS_serie_dest_path) + # Copy new one + CMSIS_serie_cube_path = os.path.join( + cube_path, cmsis_src_path, "STM32{}xx".format(serie.upper()) + ) + copyFolder(CMSIS_serie_cube_path, CMSIS_serie_dest_path, {"iar", "arm"}) + # Update MD file + for line in fileinput.input(md_CMSIS_path, inplace=True): + line = regexmd.sub(rf"\g<1>{cube_CMSIS_version}", line) + print(line, end="") + # Commit all CMSIS files + commitFiles(core_path, cmsis_commit_msg) + CMSIS_updated = True + + if HAL_updated or CMSIS_updated: + # Generate all wrapper files + # Assuming the ArduinoModule-CMSIS repo available + # at the same root level than the core + print("Update {} wrapped files".format(serie)) + if stm32wrapper.wrap(core_path, None, False) == 0: + commitFiles(core_path, wrapper_commit_msg) + # Apply all related patch if any + applyPatch(serie, HAL_updated, CMSIS_updated, core_path) + + +# Parser +upparser = argparse.ArgumentParser( + description="Update HAL drivers and CMSIS devices from STM32cube released on GitHub" +) + +upparser.add_argument( + "-c", "--check", help="Check versions. Default all.", action="store_true" +) +upparser.add_argument( + "-s", "--serie", metavar="pattern", help="Pattern of the STM32 serie(s) to update" +) + +upargs = upparser.parse_args() + + +def main(): + global stm32_list + # check config have to be done first + checkConfig() + updateCoreRepo() + stm32_list = genSTM32List(hal_dest_path, upargs.serie) + updateSTRepo() + + if upargs.check: + printVersion() + else: + updateCore() + + +if __name__ == "__main__": + main()