You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2022/11/08 19:04:57 UTC

[GitHub] [mynewt-core] apache-mynewt-bot commented on pull request #2910: Add initial STM32H723ZG MCU support

apache-mynewt-bot commented on PR #2910:
URL: https://github.com/apache/mynewt-core/pull/2910#issuecomment-1307696190

   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### hw/bsp/nucleo-h723zg/include/bsp/stm32h7xx_hal_conf.h
   <details>
   
   ```diff
   @@ -1,22 +1,22 @@
    /**
   -  ******************************************************************************
   -  * @file    stm32h7xx_hal_conf_template.h
   -  * @author  MCD Application Team
   -  * @brief   HAL configuration template file.
   -  *          This file should be copied to the application folder and renamed
   -  *          to stm32h7xx_hal_conf.h.
   -  ******************************************************************************
   -  * @attention
   -  *
   -  * Copyright (c) 2017 STMicroelectronics.
   -  * All rights reserved.
   -  *
   -  * This software is licensed under terms that can be found in the LICENSE file
   -  * in the root directory of this software component.
   -  * If no LICENSE file comes with this software, it is provided AS-IS.
   -  *
   -  ******************************************************************************
   -  */
   + ******************************************************************************
   + * @file    stm32h7xx_hal_conf_template.h
   + * @author  MCD Application Team
   + * @brief   HAL configuration template file.
   + *          This file should be copied to the application folder and renamed
   + *          to stm32h7xx_hal_conf.h.
   + ******************************************************************************
   + * @attention
   + *
   + * Copyright (c) 2017 STMicroelectronics.
   + * All rights reserved.
   + *
   + * This software is licensed under terms that can be found in the LICENSE file
   + * in the root directory of this software component.
   + * If no LICENSE file comes with this software, it is provided AS-IS.
   + *
   + ******************************************************************************
   + */
    
    /* Define to prevent recursive inclusion -------------------------------------*/
    #ifndef __STM32H7xx_HAL_CONF_H
   @@ -31,8 +31,8 @@
    
    /* ########################## Module Selection ############################## */
    /**
   -  * @brief This is the list of modules to be used in the HAL driver
   -  */
   + * @brief This is the list of modules to be used in the HAL driver
   + */
    #define HAL_MODULE_ENABLED
    #define HAL_ADC_MODULE_ENABLED
    #define HAL_CEC_MODULE_ENABLED
   @@ -90,10 +90,10 @@
    
    /* ########################## Oscillator Values adaptation ####################*/
    /**
   -  * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
   -  *        This value is used by the RCC HAL module to compute the system frequency
   -  *        (when HSE is used as system clock source, directly or through the PLL).
   -  */
   + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
   + *        This value is used by the RCC HAL module to compute the system frequency
   + *        (when HSE is used as system clock source, directly or through the PLL).
   + */
    #if !defined  (HSE_VALUE)
    #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
    #endif /* HSE_VALUE */
   @@ -103,26 +103,26 @@
    #endif /* HSE_STARTUP_TIMEOUT */
    
    /**
   -  * @brief Internal  oscillator (CSI) default value.
   -  *        This value is the default CSI value after Reset.
   -  */
   + * @brief Internal  oscillator (CSI) default value.
   + *        This value is the default CSI value after Reset.
   + */
    #if !defined  (CSI_VALUE)
    #define CSI_VALUE    ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
    #endif /* CSI_VALUE */
    
    /**
   -  * @brief Internal High Speed oscillator (HSI) value.
   -  *        This value is used by the RCC HAL module to compute the system frequency
   -  *        (when HSI is used as system clock source, directly or through the PLL).
   -  */
   + * @brief Internal High Speed oscillator (HSI) value.
   + *        This value is used by the RCC HAL module to compute the system frequency
   + *        (when HSI is used as system clock source, directly or through the PLL).
   + */
    #if !defined  (HSI_VALUE)
    #define HSI_VALUE    ((uint32_t)64000000) /*!< Value of the Internal oscillator in Hz*/
    #endif /* HSI_VALUE */
    
    /**
   -  * @brief External Low Speed oscillator (LSE) value.
   -  *        This value is used by the UART, RTC HAL module to compute the system frequency
   -  */
   + * @brief External Low Speed oscillator (LSE) value.
   + *        This value is used by the UART, RTC HAL module to compute the system frequency
   + */
    #if !defined  (LSE_VALUE)
    #define LSE_VALUE    ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/
    #endif /* LSE_VALUE */
   @@ -139,10 +139,10 @@
                                                  in voltage and temperature.*/
    
    /**
   -  * @brief External clock source for I2S peripheral
   -  *        This value is used by the I2S HAL module to compute the I2S clock source
   -  *        frequency, this source is inserted directly through I2S_CKIN pad.
   -  */
   + * @brief External clock source for I2S peripheral
   + *        This value is used by the I2S HAL module to compute the I2S clock source
   + *        frequency, this source is inserted directly through I2S_CKIN pad.
   + */
    #if !defined  (EXTERNAL_CLOCK_VALUE)
    #define EXTERNAL_CLOCK_VALUE    12288000U /*!< Value of the External clock in Hz*/
    #endif /* EXTERNAL_CLOCK_VALUE */
   @@ -152,8 +152,8 @@
    
    /* ########################### System Configuration ######################### */
    /**
   -  * @brief This is the HAL system configuration section
   -  */
   + * @brief This is the HAL system configuration section
   + */
    #define  VDD_VALUE                    3300UL /*!< Value of VDD in mv */
    #define  TICK_INT_PRIORITY            ((uint32_t)0x0F) /*!< tick interrupt priority */
    #define  USE_RTOS                     0
   @@ -173,16 +173,16 @@
    
    /* ########################## Assert Selection ############################## */
    /**
   -  * @brief Uncomment the line below to expanse the "assert_param" macro in the
   -  *        HAL drivers code
   -  */
   + * @brief Uncomment the line below to expanse the "assert_param" macro in the
   + *        HAL drivers code
   + */
    /* #define USE_FULL_ASSERT    1 */
    
    
    /* Includes ------------------------------------------------------------------*/
    /**
   -  * @brief Include module's header file
   -  */
   + * @brief Include module's header file
   + */
    
    #ifdef HAL_RCC_MODULE_ENABLED
    #include "stm32h7xx_hal_rcc.h"
   @@ -400,16 +400,16 @@
    /* Exported macro ------------------------------------------------------------*/
    #ifdef  USE_FULL_ASSERT
    /**
   -  * @brief  The assert_param macro is used for function's parameters check.
   -  * @param  expr: If expr is false, it calls assert_failed function
   -  *         which reports the name of the source file and the source
   -  *         line number of the call that failed.
   -  *         If expr is true, it returns no value.
   -  * @retval None
   -  */
   + * @brief  The assert_param macro is used for function's parameters check.
   + * @param  expr: If expr is false, it calls assert_failed function
   + *         which reports the name of the source file and the source
   + *         line number of the call that failed.
   + *         If expr is true, it returns no value.
   + * @retval None
   + */
      #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
    /* Exported functions ------------------------------------------------------- */
   -  void assert_failed(uint8_t* file, uint32_t line);
   +void assert_failed(uint8_t * file, uint32_t line);
    #else
    #define assert_param(expr) ((void)0U)
    #endif /* USE_FULL_ASSERT */
   ```
   
   </details>
   
   #### hw/bsp/nucleo-h723zg/src/hal_bsp.c
   <details>
   
   ```diff
   @@ -219,9 +219,9 @@
    #endif
    
    static const struct hal_flash *flash_devs[] = {
   -        [0] = &stm32_flash_dev,
   +    [0] = &stm32_flash_dev,
    #if MYNEWT_VAL(SPIFLASH)
   -        [1] = &spiflash_dev.hal,
   +    [1] = &spiflash_dev.hal,
    #endif
    };
    
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32h7xx/include/mcu/stm32h7_bsp.h
   <details>
   
   ```diff
   @@ -46,7 +46,7 @@
     * Internal API for stm32f7xx mcu specific code.
     */
    int hal_gpio_init_af(int pin, uint8_t af_type, enum hal_gpio_pull pull, uint8_t
   -od);
   +                     od);
    
    struct hal_flash;
    extern struct hal_flash stm32f7_flash_dev;
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32h7xx/src/clock_stm32h7xx.c
   <details>
   
   ```diff
   @@ -55,9 +55,9 @@
        SCB_EnableICache();
    #endif
    
   -   /*
   -    *  Supply configuration update enable
   -    */
   +    /*
   +     *  Supply configuration update enable
   +     */
        HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
    
        /*
   @@ -67,7 +67,7 @@
         * datasheet.
         */
        __HAL_PWR_VOLTAGESCALING_CONFIG(MYNEWT_VAL(STM32_CLOCK_VOLTAGESCALING_CONFIG));
   -    while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
   +    while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
    
        osc_init.OscillatorType = RCC_OSCILLATORTYPE_NONE;
    
   @@ -123,7 +123,7 @@
        osc_init.HSICalibrationValue = MYNEWT_VAL(STM32_CLOCK_HSI_CALIBRATION);
    
    #if MYNEWT_VAL(STM32_CLOCK_HSI) && \
   -        !IS_RCC_HSICALIBRATION_VALUE(MYNEWT_VAL(STM32_CLOCK_HSI_CALIBRATION))
   +    !IS_RCC_HSICALIBRATION_VALUE(MYNEWT_VAL(STM32_CLOCK_HSI_CALIBRATION))
    #error "Invalid HSI calibration value"
    #endif
    #endif
   @@ -211,20 +211,17 @@
         * TODO: this three ifs should be a preprocessor directives, but due to type casting in ST header file it is not possible
         * If it will be fixed by the ST in the future, than it can be changed to preprocessor directives
         */
   -    if (!IS_RCC_HCLK(MYNEWT_VAL(STM32_CLOCK_AHB_DIVIDER)))
   -    {
   +    if (!IS_RCC_HCLK(MYNEWT_VAL(STM32_CLOCK_AHB_DIVIDER))) {
            /* ERROR: AHB clock divider is invalid */
            assert(0);
        }
    
   -    if (!IS_RCC_PCLK1(MYNEWT_VAL_STM32_CLOCK_APB1_DIVIDER))
   -    {
   +    if (!IS_RCC_PCLK1(MYNEWT_VAL_STM32_CLOCK_APB1_DIVIDER)) {
            /* ERROR: APB1 clock divider is invalid */
            assert(0);
        }
    
   -    if (!IS_RCC_PCLK1(MYNEWT_VAL_STM32_CLOCK_APB2_DIVIDER))
   -    {
   +    if (!IS_RCC_PCLK1(MYNEWT_VAL_STM32_CLOCK_APB2_DIVIDER)) {
            /* Error "APB2 clock divider is invalid" */
            assert(0);
        }
   @@ -267,7 +264,7 @@
    #endif
    
    #if ART_ACCLERATOR_ENABLE
   -   __HAL_FLASH_ART_ENABLE();
   +    __HAL_FLASH_ART_ENABLE();
    #endif
    
    #if PREFETCH_ENABLE
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32h7xx/src/hal_timer_freq.c
   <details>
   
   ```diff
   @@ -81,7 +81,7 @@
        case (uintptr_t)TIM20:
    #endif
            freq = HAL_RCC_GetPCLK2Freq();
   -        div  = stm32_hal_timer_abp_clk_div(clocks.APB2CLKDivider);
   +        div = stm32_hal_timer_abp_clk_div(clocks.APB2CLKDivider);
            break;
    
    #ifdef TIM2
   @@ -113,7 +113,7 @@
        case (uintptr_t)TIM14:
    #endif
            freq = HAL_RCC_GetPCLK1Freq();
   -        div  = stm32_hal_timer_abp_clk_div(clocks.APB1CLKDivider);
   +        div = stm32_hal_timer_abp_clk_div(clocks.APB1CLKDivider);
            break;
    
        default:
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32h7xx/src/system_stm32h7xx.c
   <details>
   
   ```diff
   @@ -1,55 +1,55 @@
    /**
   -  ******************************************************************************
   -  * @file    system_stm32f7xx.c
   -  * @author  MCD Application Team
   -  * @version V1.2.0
   -  * @date    30-December-2016
   -  * @brief   CMSIS Cortex-M7 Device Peripheral Access Layer System Source File.
   -  *
   -  *   This file provides two functions and one global variable to be called from 
   -  *   user application:
   -  *      - SystemInit(): This function is called at startup just after reset and 
   -  *                      before branch to main program. This call is made inside
   -  *                      the "startup_stm32f7xx.s" file.
   -  *
   -  *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
   -  *                                  by the user application to setup the SysTick 
   -  *                                  timer or configure other parameters.
   -  *
   -  *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
   -  *                                 be called whenever the core clock is changed
   -  *                                 during program execution.
   -  *
   -  *
   -  ******************************************************************************
   -  * @attention
   -  *
   -  * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
   -  *
   -  * Redistribution and use in source and binary forms, with or without modification,
   -  * are permitted provided that the following conditions are met:
   -  *   1. Redistributions of source code must retain the above copyright notice,
   -  *      this list of conditions and the following disclaimer.
   -  *   2. Redistributions in binary form must reproduce the above copyright notice,
   -  *      this list of conditions and the following disclaimer in the documentation
   -  *      and/or other materials provided with the distribution.
   -  *   3. Neither the name of STMicroelectronics nor the names of its contributors
   -  *      may be used to endorse or promote products derived from this software
   -  *      without specific prior written permission.
   -  *
   -  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   -  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   -  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   -  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
   -  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   -  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   -  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   -  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   -  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   -  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   -  *
   -  ******************************************************************************
   -  */
   + ******************************************************************************
   + * @file    system_stm32f7xx.c
   + * @author  MCD Application Team
   + * @version V1.2.0
   + * @date    30-December-2016
   + * @brief   CMSIS Cortex-M7 Device Peripheral Access Layer System Source File.
   + *
   + *   This file provides two functions and one global variable to be called from
   + *   user application:
   + *      - SystemInit(): This function is called at startup just after reset and
   + *                      before branch to main program. This call is made inside
   + *                      the "startup_stm32f7xx.s" file.
   + *
   + *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
   + *                                  by the user application to setup the SysTick
   + *                                  timer or configure other parameters.
   + *
   + *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
   + *                                 be called whenever the core clock is changed
   + *                                 during program execution.
   + *
   + *
   + ******************************************************************************
   + * @attention
   + *
   + * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
   + *
   + * Redistribution and use in source and binary forms, with or without modification,
   + * are permitted provided that the following conditions are met:
   + *   1. Redistributions of source code must retain the above copyright notice,
   + *      this list of conditions and the following disclaimer.
   + *   2. Redistributions in binary form must reproduce the above copyright notice,
   + *      this list of conditions and the following disclaimer in the documentation
   + *      and/or other materials provided with the distribution.
   + *   3. Neither the name of STMicroelectronics nor the names of its contributors
   + *      may be used to endorse or promote products derived from this software
   + *      without specific prior written permission.
   + *
   + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
   + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   + *
   + ******************************************************************************
   + */
    
    #include "bsp/stm32h7xx_hal_conf.h"
    #include "stm32h7xx.h"
   @@ -58,35 +58,36 @@
    /* This variable is updated in three ways:
        1) by calling CMSIS function SystemCoreClockUpdate()
        2) by calling HAL API function HAL_RCC_GetHCLKFreq()
   -    3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 
   +    3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
           Note: If you use this function to configure the system clock; then there
                 is no need to call the 2 first functions listed above, since SystemCoreClock
                 variable is updated automatically.
   -*/
   + */
    uint32_t SystemCoreClock = 64000000;
    uint32_t SystemD2Clock = 64000000;
   -const  uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
   +const uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
    /*
     * XXX BSP specific
     */
    void SystemClock_Config(void);
    
    /**
   -  * @brief  Setup the microcontroller system
   -  *         Initialize the Embedded Flash Interface, the PLL and update the 
   -  *         SystemFrequency variable.
   -  * @param  None
   -  * @retval None
   -  */
   -void SystemInit(void)
   + * @brief  Setup the microcontroller system
   + *         Initialize the Embedded Flash Interface, the PLL and update the
   + *         SystemFrequency variable.
   + * @param  None
   + * @retval None
   + */
   +void
   +SystemInit(void)
    {
        /*
         * FPU settings
         */
    
        #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
   -        /* set CP10 and CP11 Full Access */
   -        SCB->CPACR |= ((3UL << 10 * 2) | (3UL << 11 * 2));
   +    /* set CP10 and CP11 Full Access */
   +    SCB->CPACR |= ((3UL << 10 * 2) | (3UL << 11 * 2));
        #endif
    
        /*
   @@ -103,23 +104,23 @@
        RCC->CR &= 0xEAF6ED7FU;
    
        #if defined(D3_SRAM_BASE)
   -        /* Reset D1CFGR register */
   -        RCC->D1CFGR = 0x00000000;
   -
   -        /* Reset D2CFGR register */
   -        RCC->D2CFGR = 0x00000000;
   -
   -        /* Reset D3CFGR register */
   -        RCC->D3CFGR = 0x00000000;
   +    /* Reset D1CFGR register */
   +    RCC->D1CFGR = 0x00000000;
   +
   +    /* Reset D2CFGR register */
   +    RCC->D2CFGR = 0x00000000;
   +
   +    /* Reset D3CFGR register */
   +    RCC->D3CFGR = 0x00000000;
        #else
   -        /* Reset CDCFGR1 register */
   -      RCC->CDCFGR1 = 0x00000000;
   -
   -      /* Reset CDCFGR2 register */
   -      RCC->CDCFGR2 = 0x00000000;
   -
   -      /* Reset SRDCFGR register */
   -      RCC->SRDCFGR = 0x00000000;
   +    /* Reset CDCFGR1 register */
   +    RCC->CDCFGR1 = 0x00000000;
   +
   +    /* Reset CDCFGR2 register */
   +    RCC->CDCFGR2 = 0x00000000;
   +
   +    /* Reset SRDCFGR register */
   +    RCC->SRDCFGR = 0x00000000;
        #endif
    
        /* Reset PLLCKSELR register */
   @@ -158,39 +159,40 @@
    }
    
    /**
   -   * @brief  Update SystemCoreClock variable according to Clock Register Values.
   -  *         The SystemCoreClock variable contains the core clock (HCLK), it can
   -  *         be used by the user application to setup the SysTick timer or configure
   -  *         other parameters.
   -  *
   -  * @note   Each time the core clock (HCLK) changes, this function must be called
   -  *         to update SystemCoreClock variable value. Otherwise, any configuration
   -  *         based on this variable will be incorrect.
   -  *
   -  * @note   - The system frequency computed by this function is not the real
   -  *           frequency in the chip. It is calculated based on the predefined
   -  *           constant and the selected clock source:
   -  *
   -  *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
   -  *
   -  *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
   -  *
   -  *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
   -  *             or HSI_VALUE(*) multiplied/divided by the PLL factors.
   -  *
   -  *         (*) HSI_VALUE is a constant defined in stm32f7xx_hal_conf.h file (default value
   -  *             16 MHz) but the real value may vary depending on the variations
   -  *             in voltage and temperature.
   -  *
   -  *         (**) HSE_VALUE is a constant defined in stm32f7xx_hal_conf.h file (default value
   -  *              25 MHz), user has to ensure that HSE_VALUE is same as the real
   -  *              frequency of the crystal used. Otherwise, this function may
   -  *              have wrong result.
   -  *
   -  *         - The result of this function could be not correct when using fractional
   -  *           value for HSE crystal.
   -  */
   -void SystemCoreClockUpdate (void)
   + * @brief  Update SystemCoreClock variable according to Clock Register Values.
   + *         The SystemCoreClock variable contains the core clock (HCLK), it can
   + *         be used by the user application to setup the SysTick timer or configure
   + *         other parameters.
   + *
   + * @note   Each time the core clock (HCLK) changes, this function must be called
   + *         to update SystemCoreClock variable value. Otherwise, any configuration
   + *         based on this variable will be incorrect.
   + *
   + * @note   - The system frequency computed by this function is not the real
   + *           frequency in the chip. It is calculated based on the predefined
   + *           constant and the selected clock source:
   + *
   + *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
   + *
   + *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
   + *
   + *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
   + *             or HSI_VALUE(*) multiplied/divided by the PLL factors.
   + *
   + *         (*) HSI_VALUE is a constant defined in stm32f7xx_hal_conf.h file (default value
   + *             16 MHz) but the real value may vary depending on the variations
   + *             in voltage and temperature.
   + *
   + *         (**) HSE_VALUE is a constant defined in stm32f7xx_hal_conf.h file (default value
   + *              25 MHz), user has to ensure that HSE_VALUE is same as the real
   + *              frequency of the crystal used. Otherwise, this function may
   + *              have wrong result.
   + *
   + *         - The result of this function could be not correct when using fractional
   + *           value for HSE crystal.
   + */
   +void
   +SystemCoreClockUpdate(void)
    {
        uint32_t pllp, pllsource, pllm, pllfracen, hsivalue, tmp;
        uint32_t common_system_clock;
   @@ -199,66 +201,65 @@
    
        /* Get SYSCLK source -------------------------------------------------------*/
    
   -    switch (RCC->CFGR & RCC_CFGR_SWS)
   -    {
   -        case RCC_CFGR_SWS_HSI:  /* HSI used as system clock source */
   -            common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
   -            break;
   -
   -        case RCC_CFGR_SWS_CSI:  /* CSI used as system clock  source */
   -            common_system_clock = CSI_VALUE;
   -            break;
   -
   -        case RCC_CFGR_SWS_HSE:  /* HSE used as system clock  source */
   -            common_system_clock = HSE_VALUE;
   -            break;
   -
   -        case RCC_CFGR_SWS_PLL1:  /* PLL1 used as system clock  source */
   -
   -            /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
   -            SYSCLK = PLL_VCO / PLLR
   -            */
   -            pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
   -            pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4)  ;
   -            pllfracen = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos);
   -            fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
   -
   -            if (pllm != 0U)
   -            {
   -                switch (pllsource)
   -                {
   -                    case RCC_PLLCKSELR_PLLSRC_HSI:  /* HSI used as PLL clock source */
   -
   -                        hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
   -                        pllvco = ( (float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
   -
   -                        break;
   -
   -                    case RCC_PLLCKSELR_PLLSRC_CSI:  /* CSI used as PLL clock source */
   -                        pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
   -                        break;
   -
   -                    case RCC_PLLCKSELR_PLLSRC_HSE:  /* HSE used as PLL clock source */
   -                        pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
   -                        break;
   -
   -                    default:
   -                        hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
   -                        pllvco = ((float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
   -                        break;
   -                }
   -                pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U ) ;
   -                common_system_clock =  (uint32_t)(float_t)(pllvco/(float_t)pllp);
   +    switch (RCC->CFGR & RCC_CFGR_SWS) {
   +    case RCC_CFGR_SWS_HSI:      /* HSI used as system clock source */
   +        common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
   +        break;
   +
   +    case RCC_CFGR_SWS_CSI:      /* CSI used as system clock  source */
   +        common_system_clock = CSI_VALUE;
   +        break;
   +
   +    case RCC_CFGR_SWS_HSE:      /* HSE used as system clock  source */
   +        common_system_clock = HSE_VALUE;
   +        break;
   +
   +    case RCC_CFGR_SWS_PLL1:      /* PLL1 used as system clock  source */
   +
   +        /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
   +           SYSCLK = PLL_VCO / PLLR
   +         */
   +        pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
   +        pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4);
   +        pllfracen = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos);
   +        fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
   +
   +        if (pllm != 0U) {
   +            switch (pllsource) {
   +            case RCC_PLLCKSELR_PLLSRC_HSI:          /* HSI used as PLL clock source */
   +
   +                hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
   +                pllvco = ((float_t)hsivalue / (float_t)pllm) *
   +                         ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1);
   +
   +                break;
   +
   +            case RCC_PLLCKSELR_PLLSRC_CSI:          /* CSI used as PLL clock source */
   +                pllvco = ((float_t)CSI_VALUE / (float_t)pllm) *
   +                         ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1);
   +                break;
   +
   +            case RCC_PLLCKSELR_PLLSRC_HSE:          /* HSE used as PLL clock source */
   +                pllvco = ((float_t)HSE_VALUE / (float_t)pllm) *
   +                         ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1);
   +                break;
   +
   +            default:
   +                hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
   +                pllvco = ((float_t)hsivalue / (float_t)pllm) *
   +                         ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1);
   +                break;
                }
   -            else
   -            {
   -                common_system_clock = 0U;
   -            }
   -            break;
   -
   -        default:
   -            common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
   -            break;
   +            pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U);
   +            common_system_clock = (uint32_t)(float_t)(pllvco/(float_t)pllp);
   +        } else {
   +            common_system_clock = 0U;
   +        }
   +        break;
   +
   +    default:
   +        common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
   +        break;
        }
    
        /* Compute SystemClock frequency --------------------------------------------------*/
   @@ -269,16 +270,19 @@
        common_system_clock >>= tmp;
    
        /* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency  */
   -    SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
   +    SystemD2Clock =
   +        (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
    
    #else
        tmp = D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE)>> RCC_CDCFGR1_CDCPRE_Pos];
    
   -  /* common_system_clock frequency : CM7 CPU frequency  */
   -  common_system_clock >>= tmp;
   -
   -  /* SystemD2Clock frequency : AXI and AHBs Clock frequency  */
   -  SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
   +    /* common_system_clock frequency : CM7 CPU frequency  */
   +    common_system_clock >>= tmp;
   +
   +    /* SystemD2Clock frequency : AXI and AHBs Clock frequency  */
   +    SystemD2Clock =
   +        (common_system_clock >>
   +         ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
    
    #endif
    
   @@ -295,151 +299,150 @@
    
    #if defined (DATA_IN_ExtSDRAM)
    /**
   -  * @brief  Setup the external memory controller.
   -  *         Called in startup_stm32f7xx.s before jump to main.
   -  *         This function configures the external memories (SDRAM)
   -  *         This SDRAM will be used as program data memory (including heap and stack).
   -  * @param  None
   -  * @retval None
   -  */
   -void SystemInit_ExtMemCtl(void)
   + * @brief  Setup the external memory controller.
   + *         Called in startup_stm32f7xx.s before jump to main.
   + *         This function configures the external memories (SDRAM)
   + *         This SDRAM will be used as program data memory (including heap and stack).
   + * @param  None
   + * @retval None
   + */
   +void
   +SystemInit_ExtMemCtl(void)
    {
   -  register uint32_t tmpreg = 0, timeout = 0xFFFF;
   -  register __IO uint32_t index;
   -
   -  /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and GPIOH interface
   -  clock */
   -  RCC->AHB1ENR |= 0x000000FC;
   -
   -  /* Connect PCx pins to FMC Alternate function */
   -  GPIOC->AFR[0]  = 0x0000C000;
   -  GPIOC->AFR[1]  = 0x00000000;
   -  /* Configure PCx pins in Alternate function mode */
   -  GPIOC->MODER   = 0x00000080;
   -  /* Configure PCx pins speed to 50 MHz */
   -  GPIOC->OSPEEDR = 0x00000080;
   -  /* Configure PCx pins Output type to push-pull */
   -  GPIOC->OTYPER  = 0x00000000;
   -  /* No pull-up, pull-down for PCx pins */
   -  GPIOC->PUPDR   = 0x00000040;
   -
   -  /* Connect PDx pins to FMC Alternate function */
   -  GPIOD->AFR[0]  = 0x000000CC;
   -  GPIOD->AFR[1]  = 0xCC000CCC;
   -  /* Configure PDx pins in Alternate function mode */
   -  GPIOD->MODER   = 0xA02A000A;
   -  /* Configure PDx pins speed to 50 MHz */
   -  GPIOD->OSPEEDR = 0xA02A000A;
   -  /* Configure PDx pins Output type to push-pull */
   -  GPIOD->OTYPER  = 0x00000000;
   -  /* No pull-up, pull-down for PDx pins */
   -  GPIOD->PUPDR   = 0x50150005;
   -
   -  /* Connect PEx pins to FMC Alternate function */
   -  GPIOE->AFR[0]  = 0xC00000CC;
   -  GPIOE->AFR[1]  = 0xCCCCCCCC;
   -  /* Configure PEx pins in Alternate function mode */
   -  GPIOE->MODER   = 0xAAAA800A;
   -  /* Configure PEx pins speed to 50 MHz */
   -  GPIOE->OSPEEDR = 0xAAAA800A;
   -  /* Configure PEx pins Output type to push-pull */
   -  GPIOE->OTYPER  = 0x00000000;
   -  /* No pull-up, pull-down for PEx pins */
   -  GPIOE->PUPDR   = 0x55554005;
   -
   -  /* Connect PFx pins to FMC Alternate function */
   -  GPIOF->AFR[0]  = 0x00CCCCCC;
   -  GPIOF->AFR[1]  = 0xCCCCC000;
   -  /* Configure PFx pins in Alternate function mode */
   -  GPIOF->MODER   = 0xAA800AAA;
   -  /* Configure PFx pins speed to 50 MHz */
   -  GPIOF->OSPEEDR = 0xAA800AAA;
   -  /* Configure PFx pins Output type to push-pull */
   -  GPIOF->OTYPER  = 0x00000000;
   -  /* No pull-up, pull-down for PFx pins */
   -  GPIOF->PUPDR   = 0x55400555;
   -
   -  /* Connect PGx pins to FMC Alternate function */
   -  GPIOG->AFR[0]  = 0x00CC00CC;
   -  GPIOG->AFR[1]  = 0xC000000C;
   -  /* Configure PGx pins in Alternate function mode */
   -  GPIOG->MODER   = 0x80020A0A;
   -  /* Configure PGx pins speed to 50 MHz */
   -  GPIOG->OSPEEDR = 0x80020A0A;
   -  /* Configure PGx pins Output type to push-pull */
   -  GPIOG->OTYPER  = 0x00000000;
   -  /* No pull-up, pull-down for PGx pins */
   -  GPIOG->PUPDR   = 0x40010505;
   -
   -  /* Connect PHx pins to FMC Alternate function */
   -  GPIOH->AFR[0]  = 0x00C0C000;
   -  GPIOH->AFR[1]  = 0x00000000;
   -  /* Configure PHx pins in Alternate function mode */
   -  GPIOH->MODER   = 0x00000880;
   -  /* Configure PHx pins speed to 50 MHz */
   -  GPIOH->OSPEEDR = 0x00000880;
   -  /* Configure PHx pins Output type to push-pull */
   -  GPIOH->OTYPER  = 0x00000000;
   -  /* No pull-up, pull-down for PHx pins */
   -  GPIOH->PUPDR   = 0x00000440;
   -
   -  /* Enable the FMC interface clock */
   -  RCC->AHB3ENR |= 0x00000001;
   -
   -  /* Configure and enable SDRAM bank1 */
   -  FMC_Bank5_6->SDCR[0]  = 0x00001954;
   -  FMC_Bank5_6->SDTR[0]  = 0x01115351;
   -
   -  /* SDRAM initialization sequence */
   -  /* Clock enable command */
   -  FMC_Bank5_6->SDCMR = 0x00000011;
   -  tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   -  while((tmpreg != 0) && (timeout-- > 0))
   -  {
   +    register uint32_t tmpreg = 0, timeout = 0xFFFF;
   +    register __IO uint32_t index;
   +
   +    /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and GPIOH interface
   +       clock */
   +    RCC->AHB1ENR |= 0x000000FC;
   +
   +    /* Connect PCx pins to FMC Alternate function */
   +    GPIOC->AFR[0] = 0x0000C000;
   +    GPIOC->AFR[1] = 0x00000000;
   +    /* Configure PCx pins in Alternate function mode */
   +    GPIOC->MODER = 0x00000080;
   +    /* Configure PCx pins speed to 50 MHz */
   +    GPIOC->OSPEEDR = 0x00000080;
   +    /* Configure PCx pins Output type to push-pull */
   +    GPIOC->OTYPER = 0x00000000;
   +    /* No pull-up, pull-down for PCx pins */
   +    GPIOC->PUPDR = 0x00000040;
   +
   +    /* Connect PDx pins to FMC Alternate function */
   +    GPIOD->AFR[0] = 0x000000CC;
   +    GPIOD->AFR[1] = 0xCC000CCC;
   +    /* Configure PDx pins in Alternate function mode */
   +    GPIOD->MODER = 0xA02A000A;
   +    /* Configure PDx pins speed to 50 MHz */
   +    GPIOD->OSPEEDR = 0xA02A000A;
   +    /* Configure PDx pins Output type to push-pull */
   +    GPIOD->OTYPER = 0x00000000;
   +    /* No pull-up, pull-down for PDx pins */
   +    GPIOD->PUPDR = 0x50150005;
   +
   +    /* Connect PEx pins to FMC Alternate function */
   +    GPIOE->AFR[0] = 0xC00000CC;
   +    GPIOE->AFR[1] = 0xCCCCCCCC;
   +    /* Configure PEx pins in Alternate function mode */
   +    GPIOE->MODER = 0xAAAA800A;
   +    /* Configure PEx pins speed to 50 MHz */
   +    GPIOE->OSPEEDR = 0xAAAA800A;
   +    /* Configure PEx pins Output type to push-pull */
   +    GPIOE->OTYPER = 0x00000000;
   +    /* No pull-up, pull-down for PEx pins */
   +    GPIOE->PUPDR = 0x55554005;
   +
   +    /* Connect PFx pins to FMC Alternate function */
   +    GPIOF->AFR[0] = 0x00CCCCCC;
   +    GPIOF->AFR[1] = 0xCCCCC000;
   +    /* Configure PFx pins in Alternate function mode */
   +    GPIOF->MODER = 0xAA800AAA;
   +    /* Configure PFx pins speed to 50 MHz */
   +    GPIOF->OSPEEDR = 0xAA800AAA;
   +    /* Configure PFx pins Output type to push-pull */
   +    GPIOF->OTYPER = 0x00000000;
   +    /* No pull-up, pull-down for PFx pins */
   +    GPIOF->PUPDR = 0x55400555;
   +
   +    /* Connect PGx pins to FMC Alternate function */
   +    GPIOG->AFR[0] = 0x00CC00CC;
   +    GPIOG->AFR[1] = 0xC000000C;
   +    /* Configure PGx pins in Alternate function mode */
   +    GPIOG->MODER = 0x80020A0A;
   +    /* Configure PGx pins speed to 50 MHz */
   +    GPIOG->OSPEEDR = 0x80020A0A;
   +    /* Configure PGx pins Output type to push-pull */
   +    GPIOG->OTYPER = 0x00000000;
   +    /* No pull-up, pull-down for PGx pins */
   +    GPIOG->PUPDR = 0x40010505;
   +
   +    /* Connect PHx pins to FMC Alternate function */
   +    GPIOH->AFR[0] = 0x00C0C000;
   +    GPIOH->AFR[1] = 0x00000000;
   +    /* Configure PHx pins in Alternate function mode */
   +    GPIOH->MODER = 0x00000880;
   +    /* Configure PHx pins speed to 50 MHz */
   +    GPIOH->OSPEEDR = 0x00000880;
   +    /* Configure PHx pins Output type to push-pull */
   +    GPIOH->OTYPER = 0x00000000;
   +    /* No pull-up, pull-down for PHx pins */
   +    GPIOH->PUPDR = 0x00000440;
   +
   +    /* Enable the FMC interface clock */
   +    RCC->AHB3ENR |= 0x00000001;
   +
   +    /* Configure and enable SDRAM bank1 */
   +    FMC_Bank5_6->SDCR[0] = 0x00001954;
   +    FMC_Bank5_6->SDTR[0] = 0x01115351;
   +
   +    /* SDRAM initialization sequence */
   +    /* Clock enable command */
   +    FMC_Bank5_6->SDCMR = 0x00000011;
        tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   -  }
   -
   -  /* Delay */
   -  for (index = 0; index<1000; index++);
   -
   -  /* PALL command */
   -  FMC_Bank5_6->SDCMR = 0x00000012;
   -  timeout = 0xFFFF;
   -  while((tmpreg != 0) && (timeout-- > 0))
   -  {
   -    tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   -  }
   -
   -  /* Auto refresh command */
   -  FMC_Bank5_6->SDCMR = 0x000000F3;
   -  timeout = 0xFFFF;
   -  while((tmpreg != 0) && (timeout-- > 0))
   -  {
   -    tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   -  }
   -
   -  /* MRD register program */
   -  FMC_Bank5_6->SDCMR = 0x00044014;
   -  timeout = 0xFFFF;
   -  while((tmpreg != 0) && (timeout-- > 0))
   -  {
   -    tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   -  }
   -
   -  /* Set refresh count */
   -  tmpreg = FMC_Bank5_6->SDRTR;
   -  FMC_Bank5_6->SDRTR = (tmpreg | (0x0000050C<<1));
   -
   -  /* Disable write protection */
   -  tmpreg = FMC_Bank5_6->SDCR[0];
   -  FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
   -
   -  /*
   -   * Disable the FMC bank1 (enabled after reset).
   -   * This, prevents CPU speculation access on this bank which blocks the use of FMC during
   -   * 24us. During this time the others FMC master (such as LTDC) cannot use it!
   -   */
   -  FMC_Bank1->BTCR[0] = 0x000030d2;
   +    while ((tmpreg != 0) && (timeout-- > 0)) {
   +        tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   +    }
   +
   +    /* Delay */
   +    for (index = 0; index < 1000; index++) {
   +        ;
   +    }
   +
   +    /* PALL command */
   +    FMC_Bank5_6->SDCMR = 0x00000012;
   +    timeout = 0xFFFF;
   +    while ((tmpreg != 0) && (timeout-- > 0)) {
   +        tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   +    }
   +
   +    /* Auto refresh command */
   +    FMC_Bank5_6->SDCMR = 0x000000F3;
   +    timeout = 0xFFFF;
   +    while ((tmpreg != 0) && (timeout-- > 0)) {
   +        tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   +    }
   +
   +    /* MRD register program */
   +    FMC_Bank5_6->SDCMR = 0x00044014;
   +    timeout = 0xFFFF;
   +    while ((tmpreg != 0) && (timeout-- > 0)) {
   +        tmpreg = FMC_Bank5_6->SDSR & 0x00000020;
   +    }
   +
   +    /* Set refresh count */
   +    tmpreg = FMC_Bank5_6->SDRTR;
   +    FMC_Bank5_6->SDRTR = (tmpreg | (0x0000050C<<1));
   +
   +    /* Disable write protection */
   +    tmpreg = FMC_Bank5_6->SDCR[0];
   +    FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF);
   +
   +    /*
   +     * Disable the FMC bank1 (enabled after reset).
   +     * This, prevents CPU speculation access on this bank which blocks the use of FMC during
   +     * 24us. During this time the others FMC master (such as LTDC) cannot use it!
   +     */
   +    FMC_Bank1->BTCR[0] = 0x000030d2;
    }
    #endif /* DATA_IN_ExtSDRAM */
    
   ```
   
   </details>
   
   #### hw/mcu/stm/stm32_common/src/stm32_driver_mod_spi.c
   <details>
   
   ```diff
   @@ -56,94 +57,92 @@
    #if defined(STM32L152xC)
    #include "stm32l1xx_hal.h"
    
   -HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi)
   -{
   -  /* Check the SPI handle allocation */
   -  if (hspi == NULL)
   -  {
   -    return HAL_ERROR;
   -  }
   -
   -  /* Check the parameters */
   -  assert_param(IS_SPI_ALL_INSTANCE(hspi->Instance));
   -  assert_param(IS_SPI_MODE(hspi->Init.Mode));
   -  assert_param(IS_SPI_DATASIZE(hspi->Init.DataSize));
   -  assert_param(IS_SPI_CPOL(hspi->Init.CLKPolarity));
   -  assert_param(IS_SPI_CPHA(hspi->Init.CLKPhase));
   -  assert_param(IS_SPI_NSS(hspi->Init.NSS));
   -  assert_param(IS_SPI_BAUDRATE_PRESCALER(hspi->Init.BaudRatePrescaler));
   -  assert_param(IS_SPI_FIRST_BIT(hspi->Init.FirstBit));
   -
   -  hspi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
   -  hspi->Init.CRCPolynomial = 1;
   -
   -  if (hspi->State == HAL_SPI_STATE_RESET)
   -  {
   -    /* Allocate lock resource and initialize it */
   -    hspi->Lock = HAL_UNLOCKED;
   -
   -    /* Init the low level hardware : GPIO, CLOCK, NVIC... */
   -    HAL_SPI_MspInit(hspi);
   -  }
   -
   -  hspi->State = HAL_SPI_STATE_BUSY;
   -
   -  /* Disble the selected SPI peripheral */
   -  __HAL_SPI_DISABLE(hspi);
   -
   -  /*----------------------- SPIx CR1 & CR2 Configuration ---------------------*/
   -  /* Configure : SPI Mode, Communication Mode, Data size, Clock polarity and phase, NSS management,
   -  Communication speed, First bit and CRC calculation state */
   -  hspi->Instance->CR1 = (hspi->Init.Mode | hspi->Init.Direction | hspi->Init.DataSize |
   -                         hspi->Init.CLKPolarity | hspi->Init.CLKPhase | (hspi->Init.NSS & SPI_CR1_SSM) |
   -                         hspi->Init.BaudRatePrescaler | hspi->Init.FirstBit  | hspi->Init.CRCCalculation);
   -
   -  /* Configure : NSS management */
   -  hspi->Instance->CR2 = (((hspi->Init.NSS >> 16U) & SPI_CR2_SSOE) | hspi->Init.TIMode);
   -
   -  /*---------------------------- SPIx CRCPOLY Configuration ------------------*/
   -  /* Configure : CRC Polynomial */
   -  hspi->Instance->CRCPR = hspi->Init.CRCPolynomial;
   +HAL_StatusTypeDef
   +HAL_SPI_Init(SPI_HandleTypeDef *hspi)
   +{
   +    /* Check the SPI handle allocation */
   +    if (hspi == NULL) {
   +        return HAL_ERROR;
   +    }
   +
   +    /* Check the parameters */
   +    assert_param(IS_SPI_ALL_INSTANCE(hspi->Instance));
   +    assert_param(IS_SPI_MODE(hspi->Init.Mode));
   +    assert_param(IS_SPI_DATASIZE(hspi->Init.DataSize));
   +    assert_param(IS_SPI_CPOL(hspi->Init.CLKPolarity));
   +    assert_param(IS_SPI_CPHA(hspi->Init.CLKPhase));
   +    assert_param(IS_SPI_NSS(hspi->Init.NSS));
   +    assert_param(IS_SPI_BAUDRATE_PRESCALER(hspi->Init.BaudRatePrescaler));
   +    assert_param(IS_SPI_FIRST_BIT(hspi->Init.FirstBit));
   +
   +    hspi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
   +    hspi->Init.CRCPolynomial = 1;
   +
   +    if (hspi->State == HAL_SPI_STATE_RESET) {
   +        /* Allocate lock resource and initialize it */
   +        hspi->Lock = HAL_UNLOCKED;
   +
   +        /* Init the low level hardware : GPIO, CLOCK, NVIC... */
   +        HAL_SPI_MspInit(hspi);
   +    }
   +
   +    hspi->State = HAL_SPI_STATE_BUSY;
   +
   +    /* Disble the selected SPI peripheral */
   +    __HAL_SPI_DISABLE(hspi);
   +
   +    /*----------------------- SPIx CR1 & CR2 Configuration ---------------------*/
   +    /* Configure : SPI Mode, Communication Mode, Data size, Clock polarity and phase, NSS management,
   +       Communication speed, First bit and CRC calculation state */
   +    hspi->Instance->CR1 = (hspi->Init.Mode | hspi->Init.Direction | hspi->Init.DataSize |
   +                           hspi->Init.CLKPolarity | hspi->Init.CLKPhase | (hspi->Init.NSS & SPI_CR1_SSM) |
   +                           hspi->Init.BaudRatePrescaler | hspi->Init.FirstBit  | hspi->Init.CRCCalculation);
   +
   +    /* Configure : NSS management */
   +    hspi->Instance->CR2 = (((hspi->Init.NSS >> 16U) & SPI_CR2_SSOE) | hspi->Init.TIMode);
   +
   +    /*---------------------------- SPIx CRCPOLY Configuration ------------------*/
   +    /* Configure : CRC Polynomial */
   +    hspi->Instance->CRCPR = hspi->Init.CRCPolynomial;
    
    #if defined(SPI_I2SCFGR_I2SMOD)
   -  /* Activate the SPI mode (Make sure that I2SMOD bit in I2SCFGR register is reset) */
   -  CLEAR_BIT(hspi->Instance->I2SCFGR, SPI_I2SCFGR_I2SMOD);
   -#endif
   -
   -  hspi->ErrorCode = HAL_SPI_ERROR_NONE;
   -  hspi->State = HAL_SPI_STATE_READY;
   -
   -  return HAL_OK;
   +    /* Activate the SPI mode (Make sure that I2SMOD bit in I2SCFGR register is reset) */
   +    CLEAR_BIT(hspi->Instance->I2SCFGR, SPI_I2SCFGR_I2SMOD);
   +#endif
   +
   +    hspi->ErrorCode = HAL_SPI_ERROR_NONE;
   +    hspi->State = HAL_SPI_STATE_READY;
   +
   +    return HAL_OK;
    }
    #endif
    
    #if (!MYNEWT_VAL(MCU_STM32H7) | !SPI_HAS_FIFO)
    static HAL_StatusTypeDef
   -SPI_WaitFlagStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Flag, uint32_t State, uint32_t Timeout, uint32_t Tickstart)
   -{
   -  while((((hspi->Instance->SR & Flag) == (Flag)) ? SET : RESET) != State) {
   -    if(Timeout != HAL_MAX_DELAY)
   -    {
   -      if((Timeout == 0U) || ((HAL_GetTick()-Tickstart) >= Timeout))
   -      {
   -        /* Disable the SPI and reset the CRC: the CRC value should be cleared
   -        on both master and slave sides in order to resynchronize the master
   -        and slave for their respective CRC calculation */
   -
   -        /* Disable TXE, RXNE and ERR interrupts for the interrupt process */
   -        __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
   -
   -        hspi->State= HAL_SPI_STATE_READY;
   -
   -        /* Process Unlocked */
   -        __HAL_UNLOCK(hspi);
   -
   -        return HAL_TIMEOUT;
   -      }
   -    }
   -  }
   -
   -  return HAL_OK;
   +SPI_WaitFlagStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Flag, uint32_t State, uint32_t Timeout,
   +                              uint32_t Tickstart)
   +{
   +    while ((((hspi->Instance->SR & Flag) == (Flag)) ? SET : RESET) != State) {
   +        if (Timeout != HAL_MAX_DELAY) {
   +            if ((Timeout == 0U) || ((HAL_GetTick()-Tickstart) >= Timeout)) {
   +                /* Disable the SPI and reset the CRC: the CRC value should be cleared
   +                   on both master and slave sides in order to resynchronize the master
   +                   and slave for their respective CRC calculation */
   +
   +                /* Disable TXE, RXNE and ERR interrupts for the interrupt process */
   +                __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
   +
   +                hspi->State = HAL_SPI_STATE_READY;
   +
   +                /* Process Unlocked */
   +                __HAL_UNLOCK(hspi);
   +
   +                return HAL_TIMEOUT;
   +            }
   +        }
   +    }
   +
   +    return HAL_OK;
    }
    #endif
    
   @@ -151,621 +150,580 @@
    static HAL_StatusTypeDef
    SPI_CheckFlag_BSY(SPI_HandleTypeDef *hspi, uint32_t Timeout, uint32_t Tickstart)
    {
   -  /* Control the BSY flag */
   -  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_BSY, RESET, Timeout, Tickstart) != HAL_OK) {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -    return HAL_TIMEOUT;
   -  }
   -  return HAL_OK;
   -}
   -#endif
   -
   -#if SPI_HAS_FIFO
   -static HAL_StatusTypeDef SPI_WaitFifoStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Fifo, uint32_t State,
   -                                                       uint32_t Timeout, uint32_t Tickstart)
   -{
   -  __IO uint8_t tmpreg;
   -
   -  while ((hspi->Instance->SR & Fifo) != State)
   -  {
   +    /* Control the BSY flag */
   +    if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_BSY, RESET, Timeout, Tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +        return HAL_TIMEOUT;
   +    }
   +    return HAL_OK;
   +}
   +#endif
   +
   +#if SPI_HAS_FIFO
   +static HAL_StatusTypeDef
   +SPI_WaitFifoStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Fifo, uint32_t State,
   +                              uint32_t Timeout, uint32_t Tickstart)
   +{
   +    __IO uint8_t tmpreg;
   +
   +    while ((hspi->Instance->SR & Fifo) != State) {
    #if !MYNEWT_VAL(MCU_STM32H7)
   -    if ((Fifo == SPI_SR_FRLVL) && (State == SPI_FRLVL_EMPTY))
   -    {
   -      tmpreg = *((__IO uint8_t *)&hspi->Instance->DR);
   -      /* To avoid GCC warning */
   -      UNUSED(tmpreg);
   -    }
   +        if ((Fifo == SPI_SR_FRLVL) && (State == SPI_FRLVL_EMPTY)) {
   +            tmpreg = *((__IO uint8_t *)&hspi->Instance->DR);
   +            /* To avoid GCC warning */
   +            UNUSED(tmpreg);
   +        }
    #else
   -    if ((Fifo == SPI_SR_RXPLVL) && (State == SPI_RX_FIFO_0PACKET))
   -    {
   -     tmpreg = *((__IO uint8_t *)&hspi->Instance->RXDR);
   -     /* To avoid GCC warning */
   -     UNUSED(tmpreg);
   -    }
   -#endif
   -
   -    if (Timeout != HAL_MAX_DELAY)
   -    {
   -      /* TODO: handle HAL_GetTick overflow */
   -      if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) >= Timeout))
   -      {
   -        /* Disable the SPI and reset the CRC: the CRC value should be cleared
   -           on both master and slave sides in order to resynchronize the master
   -           and slave for their respective CRC calculation */
   -
   -        /* Disable TXE, RXNE and ERR interrupts for the interrupt process */
   -        __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
   -
   +        if ((Fifo == SPI_SR_RXPLVL) && (State == SPI_RX_FIFO_0PACKET)) {
   +            tmpreg = *((__IO uint8_t *)&hspi->Instance->RXDR);
   +            /* To avoid GCC warning */
   +            UNUSED(tmpreg);
   +        }
   +#endif
   +
   +        if (Timeout != HAL_MAX_DELAY) {
   +            /* TODO: handle HAL_GetTick overflow */
   +            if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) >= Timeout)) {
   +                /* Disable the SPI and reset the CRC: the CRC value should be cleared
   +                   on both master and slave sides in order to resynchronize the master
   +                   and slave for their respective CRC calculation */
   +
   +                /* Disable TXE, RXNE and ERR interrupts for the interrupt process */
   +                __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
   +
   +                hspi->State = HAL_SPI_STATE_READY;
   +
   +                /* Process Unlocked */
   +                __HAL_UNLOCK(hspi);
   +
   +                return HAL_TIMEOUT;
   +            }
   +        }
   +    }
   +
   +    return HAL_OK;
   +}
   +
   +static HAL_StatusTypeDef
   +SPI_EndRxTxTransaction(SPI_HandleTypeDef *hspi, uint32_t Timeout, uint32_t Tickstart)
   +{
   +#if !MYNEWT_VAL(MCU_STM32H7)
   +    /* Control if the TX fifo is empty */
   +    if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FTLVL, SPI_FTLVL_EMPTY, Timeout, Tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +        return HAL_TIMEOUT;
   +    }
   +
   +    /* Control the BSY flag */
   +    if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_BSY, RESET, Timeout, Tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +        return HAL_TIMEOUT;
   +    }
   +#else
   +    /* Control if the TX fifo is empty */
   +    if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_TXC, SPI_SR_TXC, Timeout, Tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +        return HAL_TIMEOUT;
   +    }
   +#endif
   +    /* Control if the RX fifo is empty */
   +    if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_EMPTY, Timeout, Tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +        return HAL_TIMEOUT;
   +    }
   +    return HAL_OK;
   +}
   +
   +static HAL_StatusTypeDef
   +SPI_EndTxTransaction(SPI_HandleTypeDef *hspi, uint32_t Timeout, uint32_t Tickstart)
   +{
   +#if !MYNEWT_VAL(MCU_STM32H7)
   +    /* Control if the TX fifo is empty */
   +    if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FTLVL, SPI_FTLVL_EMPTY, Timeout, Tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +        return HAL_TIMEOUT;
   +    }
   +#else
   +    /* Control if the TX fifo is empty */
   +    if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_TXC, SPI_SR_TXC, Timeout, Tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +        return HAL_TIMEOUT;
   +    }
   +#endif
   +    return HAL_OK;
   +}
   +#endif
   +
   +static void
   +SPI_CloseTx_ISR(SPI_HandleTypeDef *hspi)
   +{
   +    uint32_t tickstart = 0U;
   +    __IO uint32_t count = SPI_DEFAULT_TIMEOUT * (SystemCoreClock / 24U / 1000U);
   +
   +    /* Init tickstart for timeout management*/
   +    tickstart = HAL_GetTick();
   +    (void)count;
   +
   +#if !SPI_HAS_FIFO
   +    /* Wait until TXE flag is set */
   +    do{
   +        if (count-- == 0U) {
   +            SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +            break;
   +        }
   +    }while((hspi->Instance->SR & SPI_FLAG_TXE) == RESET);
   +#endif
   +
   +    /* Disable TXE and ERR interrupt */
   +    __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_ERR));
   +
   +#if SPI_HAS_FIFO
   +    if (SPI_EndTxTransaction(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +    }
   +#else
   +    /* Check Busy flag */
   +    if (SPI_CheckFlag_BSY(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +    }
   +#endif
   +
   +    /* Clear overrun flag in 2 Lines communication mode because received is not read */
   +    __HAL_SPI_CLEAR_OVRFLAG(hspi);
   +
   +    hspi->State = HAL_SPI_STATE_READY;
   +    if (hspi->ErrorCode != HAL_SPI_ERROR_NONE) {
   +        HAL_SPI_ErrorCallback(hspi);
   +    } else {
   +        HAL_SPI_TxCpltCallback(hspi);
   +    }
   +}
   +
   +static void
   +SPI_CloseRxTx_ISR(SPI_HandleTypeDef *hspi)
   +{
   +    uint32_t tickstart = 0U;
   +    __IO uint32_t count = SPI_DEFAULT_TIMEOUT * (SystemCoreClock / 24U / 1000U);
   +    tickstart = HAL_GetTick();
   +
   +    /* Disable ERR interrupt */
   +    __HAL_SPI_DISABLE_IT(hspi, SPI_IT_ERR);
   +
   +#if SPI_HAS_FIFO
   +    (void)count;
   +    if (SPI_EndRxTxTransaction(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +    }
   +#else
   +    /* Wait until TXE flag is set */
   +    do{
   +        if (count-- == 0U) {
   +            SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +            break;
   +        }
   +    }while((hspi->Instance->SR & SPI_FLAG_TXE) == RESET);
   +
   +    /* Check the end of the transaction */
   +    if (SPI_CheckFlag_BSY(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) {
   +        SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   +    }
   +
   +    /* Clear overrun flag in 2 Lines communication mode because received is not read */
   +    __HAL_SPI_CLEAR_OVRFLAG(hspi);
   +#endif
   +
   +    if (hspi->ErrorCode == HAL_SPI_ERROR_NONE) {
   +        if (hspi->State == HAL_SPI_STATE_BUSY_RX) {
   +            hspi->State = HAL_SPI_STATE_READY;
   +            HAL_SPI_RxCpltCallback(hspi);
   +        } else {
   +            hspi->State = HAL_SPI_STATE_READY;
   +            HAL_SPI_TxRxCpltCallback(hspi);
   +        }
   +    } else {
            hspi->State = HAL_SPI_STATE_READY;
   -
   -        /* Process Unlocked */
   -        __HAL_UNLOCK(hspi);
   -
   -        return HAL_TIMEOUT;
   -      }
   -    }
   -  }
   -
   -  return HAL_OK;
   -}
   -
   -static HAL_StatusTypeDef SPI_EndRxTxTransaction(SPI_HandleTypeDef *hspi, uint32_t Timeout, uint32_t Tickstart)
   -{
   -#if !MYNEWT_VAL(MCU_STM32H7)
   -  /* Control if the TX fifo is empty */
   -  if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FTLVL, SPI_FTLVL_EMPTY, Timeout, Tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -    return HAL_TIMEOUT;
   -  }
   -
   -  /* Control the BSY flag */
   -  if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_BSY, RESET, Timeout, Tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -    return HAL_TIMEOUT;
   -  }
   -#else
   -  /* Control if the TX fifo is empty */
   -  if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_TXC, SPI_SR_TXC, Timeout, Tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -    return HAL_TIMEOUT;
   -  }
   -#endif
   -  /* Control if the RX fifo is empty */
   -  if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_EMPTY, Timeout, Tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -    return HAL_TIMEOUT;
   -  }
   -  return HAL_OK;
   -}
   -
   -static HAL_StatusTypeDef SPI_EndTxTransaction(SPI_HandleTypeDef *hspi, uint32_t Timeout, uint32_t Tickstart)
   -{
   -#if !MYNEWT_VAL(MCU_STM32H7)
   -  /* Control if the TX fifo is empty */
   -  if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FTLVL, SPI_FTLVL_EMPTY, Timeout, Tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -    return HAL_TIMEOUT;
   -  }
   -#else
   -  /* Control if the TX fifo is empty */
   -  if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_TXC, SPI_SR_TXC, Timeout, Tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -    return HAL_TIMEOUT;
   -  }
   -#endif
   -  return HAL_OK;
   -}
   -#endif
   -
   -static void SPI_CloseTx_ISR(SPI_HandleTypeDef *hspi)
   -{
   -  uint32_t tickstart = 0U;
   -  __IO uint32_t count = SPI_DEFAULT_TIMEOUT * (SystemCoreClock / 24U / 1000U);
   -
   -  /* Init tickstart for timeout management*/
   -  tickstart = HAL_GetTick();
   -  (void)count;
   -
   -#if !SPI_HAS_FIFO
   -  /* Wait until TXE flag is set */
   -  do
   -  {
   -    if(count-- == 0U)
   -    {
   -      SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -      break;
   -    }
   -  }
   -  while((hspi->Instance->SR & SPI_FLAG_TXE) == RESET);
   -#endif
   -
   -  /* Disable TXE and ERR interrupt */
   -  __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_ERR));
   -
   -#if SPI_HAS_FIFO
   -  if (SPI_EndTxTransaction(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -  }
   -#else
   -  /* Check Busy flag */
   -  if(SPI_CheckFlag_BSY(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -  }
   -#endif
   -
   -  /* Clear overrun flag in 2 Lines communication mode because received is not read */
   -  __HAL_SPI_CLEAR_OVRFLAG(hspi);
   -
   -  hspi->State = HAL_SPI_STATE_READY;
   -  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
   -  {
   -    HAL_SPI_ErrorCallback(hspi);
   -  }
   -  else
   -  {
   -    HAL_SPI_TxCpltCallback(hspi);
   -  }
   -}
   -
   -static void SPI_CloseRxTx_ISR(SPI_HandleTypeDef *hspi)
   -{
   -  uint32_t tickstart = 0U;
   -  __IO uint32_t count = SPI_DEFAULT_TIMEOUT * (SystemCoreClock / 24U / 1000U);
   -  tickstart = HAL_GetTick();
   -
   -  /* Disable ERR interrupt */
   -  __HAL_SPI_DISABLE_IT(hspi, SPI_IT_ERR);
   -
   -#if SPI_HAS_FIFO
   -  (void)count;
   -  if (SPI_EndRxTxTransaction(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -  }
   -#else
   -  /* Wait until TXE flag is set */
   -  do
   -  {
   -    if(count-- == 0U)
   -    {
   -      SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -      break;
   -    }
   -  }
   -  while((hspi->Instance->SR & SPI_FLAG_TXE) == RESET);
   -
   -  /* Check the end of the transaction */
   -  if(SPI_CheckFlag_BSY(hspi, SPI_DEFAULT_TIMEOUT, tickstart)!=HAL_OK)
   -  {
   -    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_FLAG);
   -  }
   -
   -  /* Clear overrun flag in 2 Lines communication mode because received is not read */
   -  __HAL_SPI_CLEAR_OVRFLAG(hspi);
   -#endif
   -
   -  if(hspi->ErrorCode == HAL_SPI_ERROR_NONE)
   -  {
   -    if(hspi->State == HAL_SPI_STATE_BUSY_RX)
   -    {
   -      hspi->State = HAL_SPI_STATE_READY;
   -      HAL_SPI_RxCpltCallback(hspi);
   -    }
   -    else
   -    {
   -      hspi->State = HAL_SPI_STATE_READY;
   -      HAL_SPI_TxRxCpltCallback(hspi);
   -    }
   -  }
   -  else
   -  {
   -    hspi->State = HAL_SPI_STATE_READY;
   -    HAL_SPI_ErrorCallback(hspi);
   -  }
   -}
   -
   -/**
   -  * @brief  Rx 8-bit handler for Transmit and Receive in Interrupt mode.
   -  * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   -  *               the configuration information for SPI module.
   -  * @retval None
   -  */
   -static void SPI_2linesRxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
   -{
   -  if (hspi->Init.Mode == SPI_MODE_MASTER) {
   -    *hspi->pRxBuffPtr++ = *((__IO uint8_t *)&hspi->Instance->RXDR);
   +        HAL_SPI_ErrorCallback(hspi);
   +    }
   +}
   +
   +/**
   + * @brief  Rx 8-bit handler for Transmit and Receive in Interrupt mode.
   + * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   + *               the configuration information for SPI module.
   + * @retval None
   + */
   +static void
   +SPI_2linesRxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
   +{
   +    if (hspi->Init.Mode == SPI_MODE_MASTER) {
   +        *hspi->pRxBuffPtr++ = *((__IO uint8_t *)&hspi->Instance->RXDR);
   +        hspi->RxXferCount--;
   +    } else {
   +        /*FIXME: this block below is probably not required... */
   +#if SPI_HAS_FIFO
   +        /* Receive data in packing mode */
   +        if (hspi->RxXferCount > 1U) {
   +            *((uint16_t *)hspi->pRxBuffPtr) = hspi->Instance->RXDR;
   +            hspi->pRxBuffPtr += sizeof(uint16_t);
   +            hspi->RxXferCount -= 2U;
   +        } else {
   +            /* Receive data in 8 Bit mode */
   +#endif
   +        *hspi->pRxBuffPtr++ = *((__IO uint8_t *)&hspi->Instance->RXDR);
   +        hspi->RxXferCount--;
   +#if SPI_HAS_FIFO
   +    }
   +#endif
   +    }
   +
   +    /* check end of the reception */
   +    if (hspi->RxXferCount == 0U) {
   +        /* Disable RXNE interrupt */
   +        __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_RXNE | SPI_IT_ERR));
   +
   +        if (hspi->TxXferCount == 0U) {
   +            SPI_CloseRxTx_ISR(hspi);
   +        }
   +    }
   +}
   +
   +/**
   + * @brief  Tx 8-bit handler for Transmit and Receive in Interrupt mode.
   + * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   + *               the configuration information for SPI module.
   + * @retval None
   + */
   +static void
   +SPI_2linesTxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
   +{
   +#if SPI_HAS_FIFO
   +    /* Transmit data in packing Bit mode */
   +    if (hspi->TxXferCount >= 2U) {
   +        hspi->Instance->TXDR = *((uint16_t *)hspi->pTxBuffPtr);
   +        hspi->pTxBuffPtr += sizeof(uint16_t);
   +        hspi->TxXferCount -= 2U;
   +    }
   +    /* Transmit data in 8 Bit mode */
   +    else {
   +#endif
   +    *(__IO uint8_t *)&hspi->Instance->TXDR = (*hspi->pTxBuffPtr++);
   +    hspi->TxXferCount--;
   +#if SPI_HAS_FIFO
   +}
   +#endif
   +
   +    /* check the end of the transmission */
   +    if (hspi->TxXferCount == 0U) {
   +        /* Disable TXE interrupt */
   +        __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXE);
   +
   +        if (hspi->RxXferCount == 0U) {
   +            SPI_CloseRxTx_ISR(hspi);
   +        }
   +    }
   +}
   +
   +/**
   + * @brief  Rx 16-bit handler for Transmit and Receive in Interrupt mode.
   + * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   + *               the configuration information for SPI module.
   + * @retval None
   + *
   + * @note:  Copied verbatim from STM32Cube
   + */
   +static void
   +SPI_2linesRxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
   +{
   +    /* Receive data in 16 Bit mode */
   +    *((uint16_t *)hspi->pRxBuffPtr) = hspi->Instance->RXDR;
   +    hspi->pRxBuffPtr += sizeof(uint16_t);
        hspi->RxXferCount--;
   -  } else {
   -    //FIXME: this block below is probably not required...
   -#if SPI_HAS_FIFO
   -    /* Receive data in packing mode */
   -    if (hspi->RxXferCount > 1U) {
   -      *((uint16_t *)hspi->pRxBuffPtr) = hspi->Instance->RXDR;
   -      hspi->pRxBuffPtr += sizeof(uint16_t);
   -      hspi->RxXferCount -= 2U;
   -    } else {
   -      /* Receive data in 8 Bit mode */
   -#endif
   -      *hspi->pRxBuffPtr++ = *((__IO uint8_t *)&hspi->Instance->RXDR);
   -      hspi->RxXferCount--;
   -#if SPI_HAS_FIFO
   -    }
   -#endif
   -  }
   -
   -  /* check end of the reception */
   -  if(hspi->RxXferCount == 0U)
   -  {
   -    /* Disable RXNE interrupt */
   -    __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_RXNE | SPI_IT_ERR));
   -
   -    if(hspi->TxXferCount == 0U)
   -    {
   -      SPI_CloseRxTx_ISR(hspi);
   -    }
   -  }
   -}
   -
   -/**
   -  * @brief  Tx 8-bit handler for Transmit and Receive in Interrupt mode.
   -  * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   -  *               the configuration information for SPI module.
   -  * @retval None
   -  */
   -static void SPI_2linesTxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
   -{
   -#if SPI_HAS_FIFO
   -  /* Transmit data in packing Bit mode */
   -  if (hspi->TxXferCount >= 2U)
   -  {
   +
   +    if (hspi->RxXferCount == 0U) {
   +        /* Disable RXNE interrupt */
   +        __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE);
   +
   +        if (hspi->TxXferCount == 0U) {
   +            SPI_CloseRxTx_ISR(hspi);
   +        }
   +    }
   +}
   +
   +/**
   + * @brief  Tx 16-bit handler for Transmit and Receive in Interrupt mode.
   + * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   + *               the configuration information for SPI module.
   + * @retval None
   + */
   +static void
   +SPI_2linesTxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
   +{
   +    /* Transmit data in 16 Bit mode */
        hspi->Instance->TXDR = *((uint16_t *)hspi->pTxBuffPtr);
        hspi->pTxBuffPtr += sizeof(uint16_t);
   -    hspi->TxXferCount -= 2U;
   -  }
   -  /* Transmit data in 8 Bit mode */
   -  else
   -  {
   +    hspi->TxXferCount--;
   +
   +    if (hspi->TxXferCount == 0U) {
   +        /* Disable TXE interrupt */
   +        __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXE);
   +
   +        if (hspi->RxXferCount == 0U) {
   +            SPI_CloseRxTx_ISR(hspi);
   +        }
   +    }
   +}
   +
   +/**
   + * @brief  Handle the data 8-bit transmit in Interrupt mode.
   + * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   + *               the configuration information for SPI module.
   + * @retval None
   + */
   +static void
   +SPI_TxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
   +{
   +#if SPI_HAS_FIFO
   +    /* Transmit data in packing Bit mode */
   +    if (hspi->TxXferCount >= 2U) {
   +        hspi->Instance->TXDR = *((uint16_t *)hspi->pTxBuffPtr);
   +        hspi->pTxBuffPtr += sizeof(uint16_t);
   +        hspi->TxXferCount -= 2U;
   +    } else {
    #endif
        *(__IO uint8_t *)&hspi->Instance->TXDR = (*hspi->pTxBuffPtr++);
        hspi->TxXferCount--;
    #if SPI_HAS_FIFO
   -  }
   -#endif
   -
   -  /* check the end of the transmission */
   -  if(hspi->TxXferCount == 0U)
   -  {
   -    /* Disable TXE interrupt */
   -    __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXE);
   -
   -    if(hspi->RxXferCount == 0U)
   -    {
   -      SPI_CloseRxTx_ISR(hspi);
   -    }
   -  }
   -}
   -
   -/**
   -  * @brief  Rx 16-bit handler for Transmit and Receive in Interrupt mode.
   -  * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   -  *               the configuration information for SPI module.
   -  * @retval None
   -  *
   -  * @note:  Copied verbatim from STM32Cube
   -  */
   -static void SPI_2linesRxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
   -{
   -  /* Receive data in 16 Bit mode */
   -  *((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->RXDR;
   -  hspi->pRxBuffPtr += sizeof(uint16_t);
   -  hspi->RxXferCount--;
   -
   -  if(hspi->RxXferCount == 0U)
   -  {
   -    /* Disable RXNE interrupt */
   -    __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE);
   -
   -    if(hspi->TxXferCount == 0U)
   -    {
   -      SPI_CloseRxTx_ISR(hspi);
   -    }
   -  }
   -}
   -
   -/**
   -  * @brief  Tx 16-bit handler for Transmit and Receive in Interrupt mode.
   -  * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   -  *               the configuration information for SPI module.
   -  * @retval None
   -  */
   -static void SPI_2linesTxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
   -{
   -  /* Transmit data in 16 Bit mode */
   -  hspi->Instance->TXDR = *((uint16_t *)hspi->pTxBuffPtr);
   -  hspi->pTxBuffPtr += sizeof(uint16_t);
   -  hspi->TxXferCount--;
   -
   -  if(hspi->TxXferCount == 0U)
   -  {
   -    /* Disable TXE interrupt */
   -    __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXE);
   -
   -    if(hspi->RxXferCount == 0U)
   -    {
   -      SPI_CloseRxTx_ISR(hspi);
   -    }
   -  }
   -}
   -
   -/**
   -  * @brief  Handle the data 8-bit transmit in Interrupt mode.
   -  * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   -  *               the configuration information for SPI module.
   -  * @retval None
   -  */
   -static void SPI_TxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
   -{
   -#if SPI_HAS_FIFO
   -  /* Transmit data in packing Bit mode */
   -  if (hspi->TxXferCount >= 2U) {
   +}
   +#endif
   +
   +    if (hspi->TxXferCount == 0U) {
   +        SPI_CloseTx_ISR(hspi);
   +    }
   +}
   +
   +/**
   + * @brief  Handle the data 16-bit transmit in Interrupt mode.
   + * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   + *               the configuration information for SPI module.
   + * @retval None
   + */
   +static void
   +SPI_TxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
   +{
   +    /* Transmit data in 16 Bit mode */
        hspi->Instance->TXDR = *((uint16_t *)hspi->pTxBuffPtr);
        hspi->pTxBuffPtr += sizeof(uint16_t);
   -    hspi->TxXferCount -= 2U;
   -  } else {
   -#endif
   -    *(__IO uint8_t *)&hspi->Instance->TXDR = (*hspi->pTxBuffPtr++);
        hspi->TxXferCount--;
   -#if SPI_HAS_FIFO
   -  }
   -#endif
   -
   -  if(hspi->TxXferCount == 0U)
   -  {
   -    SPI_CloseTx_ISR(hspi);
   -  }
   -}
   -
   -/**
   -  * @brief  Handle the data 16-bit transmit in Interrupt mode.
   -  * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   -  *               the configuration information for SPI module.
   -  * @retval None
   -  */
   -static void SPI_TxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
   -{
   -  /* Transmit data in 16 Bit mode */
   -  hspi->Instance->TXDR = *((uint16_t *)hspi->pTxBuffPtr);
   -  hspi->pTxBuffPtr += sizeof(uint16_t);
   -  hspi->TxXferCount--;
   -
   -  if(hspi->TxXferCount == 0U)
   -  {
   -    SPI_CloseTx_ISR(hspi);
   -  }
   -}
   -
   -/**
   -  * Transmit an amount of data in non-blocking mode with Interrupt.
   -  *
   -  * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   -  *               the configuration information for SPI module.
   -  * @param  pData pointer to data buffer
   -  * @param  Size amount of data to be sent
   -  * @retval HAL status
   -  */
   -HAL_StatusTypeDef HAL_SPI_Transmit_IT_Custom(SPI_HandleTypeDef *hspi, uint8_t *pData,
   -        uint16_t Size)
   -{
   -  HAL_StatusTypeDef errorcode = HAL_OK;
   -
   -  /* Process Locked */
   -  __HAL_LOCK(hspi);
   -
   -  errorcode = HAL_SPI_QueueTransmit(hspi, pData, Size);
   -  if (errorcode) {
   -      goto error;
   -  }
   -
   -  /* Enable TXE interrupt */
   -  __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE));
   -
   -  /* Check if the SPI is already enabled */
   -  if ((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE) {
   -    __HAL_SPI_ENABLE(hspi);
   -  }
   -
   -error :
   -  __HAL_UNLOCK(hspi);
   -  return errorcode;
   -}
   -
   -HAL_StatusTypeDef HAL_SPI_QueueTransmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
   -{
   -  HAL_StatusTypeDef errorcode = HAL_OK;
   -
   -  if((pData == NULL) || (Size == 0))
   -  {
   -    errorcode = HAL_ERROR;
   -    goto error;
   -  }
   -
   -  if(hspi->State != HAL_SPI_STATE_READY)
   -  {
   -    errorcode = HAL_BUSY;
   -    goto error;
   -  }
   -
   -  /* Set the transaction information */
   -  hspi->State       = HAL_SPI_STATE_BUSY_TX;
   -  hspi->ErrorCode   = HAL_SPI_ERROR_NONE;
   -  hspi->pTxBuffPtr  = (uint8_t *)pData;
   -  hspi->TxXferSize  = Size;
   -  hspi->TxXferCount = Size;
   -
   -  /* Init field not used in handle to zero */
   -  hspi->pRxBuffPtr  = (uint8_t *)NULL;
   -  hspi->RxXferSize  = 0U;
   -  hspi->RxXferCount = 0U;
   -  hspi->RxISR       = NULL;
   -
   -  /* Set the function for IT treatment */
   -  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT )
   -  {
   -    hspi->TxISR = SPI_TxISR_16BIT;
   -  }
   -  else
   -  {
   -    hspi->TxISR = SPI_TxISR_8BIT;
   -  }
   +
   +    if (hspi->TxXferCount == 0U) {
   +        SPI_CloseTx_ISR(hspi);
   +    }
   +}
   +
   +/**
   + * Transmit an amount of data in non-blocking mode with Interrupt.
   + *
   + * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   + *               the configuration information for SPI module.
   + * @param  pData pointer to data buffer
   + * @param  Size amount of data to be sent
   + * @retval HAL status
   + */
   +HAL_StatusTypeDef
   +HAL_SPI_Transmit_IT_Custom(SPI_HandleTypeDef *hspi, uint8_t *pData,
   +                           uint16_t Size)
   +{
   +    HAL_StatusTypeDef errorcode = HAL_OK;
   +
   +    /* Process Locked */
   +    __HAL_LOCK(hspi);
   +
   +    errorcode = HAL_SPI_QueueTransmit(hspi, pData, Size);
   +    if (errorcode) {
   +        goto error;
   +    }
   +
   +    /* Enable TXE interrupt */
   +    __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE));
   +
   +    /* Check if the SPI is already enabled */
   +    if ((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE) {
   +        __HAL_SPI_ENABLE(hspi);
   +    }
   +
   +error:
   +    __HAL_UNLOCK(hspi);
   +    return errorcode;
   +}
   +
   +HAL_StatusTypeDef
   +HAL_SPI_QueueTransmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
   +{
   +    HAL_StatusTypeDef errorcode = HAL_OK;
   +
   +    if ((pData == NULL) || (Size == 0)) {
   +        errorcode = HAL_ERROR;
   +        goto error;
   +    }
   +
   +    if (hspi->State != HAL_SPI_STATE_READY) {
   +        errorcode = HAL_BUSY;
   +        goto error;
   +    }
   +
   +    /* Set the transaction information */
   +    hspi->State = HAL_SPI_STATE_BUSY_TX;
   +    hspi->ErrorCode = HAL_SPI_ERROR_NONE;
   +    hspi->pTxBuffPtr = (uint8_t *)pData;
   +    hspi->TxXferSize = Size;
   +    hspi->TxXferCount = Size;
   +
   +    /* Init field not used in handle to zero */
   +    hspi->pRxBuffPtr = (uint8_t *)NULL;
   +    hspi->RxXferSize = 0U;
   +    hspi->RxXferCount = 0U;
   +    hspi->RxISR = NULL;
   +
   +    /* Set the function for IT treatment */
   +    if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) {
   +        hspi->TxISR = SPI_TxISR_16BIT;
   +    } else {
   +        hspi->TxISR = SPI_TxISR_8BIT;
   +    }
    
    #if 0 /* MYNEWT: TODO */
   -  /* Enable TXE interrupt */
   -  __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE));
   -#endif
   -
   -  /* MYNEWT: in slave mode write 1st byte to DR */
   +    /* Enable TXE interrupt */
   +    __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE));
   +#endif
   +
   +    /* MYNEWT: in slave mode write 1st byte to DR */
    #if !MYNEWT_VAL(MCU_STM32H7)
   -  if ((hspi->Instance->CR1 & SPI_CR1_MSTR) == 0) {
   -      hspi->TxISR(hspi);
   -  }
   +    if ((hspi->Instance->CR1 & SPI_CR1_MSTR) == 0) {
   +        hspi->TxISR(hspi);
   +    }
    #else
   -  if ((hspi->Instance->CFG2 & SPI_CFG2_MASTER) == 0) {
   -      hspi->TxISR(hspi);
   -  }
   +    if ((hspi->Instance->CFG2 & SPI_CFG2_MASTER) == 0) {
   +        hspi->TxISR(hspi);
   +    }
    #endif
    
    #if 0 /* MYNEWT: TODO */
   -  /* Check if the SPI is already enabled */
   -  if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
   -  {
   -    /* Enable SPI peripheral */
   -    __HAL_SPI_ENABLE(hspi);
   -  }
   -#endif
   -
   -error :
   -  return errorcode;
   -}
   -
   -/**
   -  * Transmit and Receive an amount of data in non-blocking mode with Interrupt.
   -  *
   -  * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   -  *               the configuration information for SPI module.
   -  * @param  pTxData pointer to transmission data buffer
   -  * @param  pRxData pointer to reception data buffer
   -  * @param  Size amount of data to be sent and received
   -  * @retval HAL status
   -  */
   -HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT_Custom(SPI_HandleTypeDef *hspi,
   -        uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
   -{
   -  HAL_StatusTypeDef errorcode = HAL_OK;
   -
   -  /* Process locked */
   -  __HAL_LOCK(hspi);
   -
   -  errorcode = HAL_SPI_Slave_Queue_TransmitReceive(hspi, pTxData, pRxData, Size);
   -  if (errorcode) {
   -      goto error;
   -  }
   -
   -  /* Enable TXE, RXNE and ERR interrupt */
   -  __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
   -
   -  /* Check if the SPI is already enabled */
   -  if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
   -  {
   -    /* Enable SPI peripheral */
   -    __HAL_SPI_ENABLE(hspi);
   -  }
   +    /* Check if the SPI is already enabled */
   +    if ((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE) {
   +        /* Enable SPI peripheral */
   +        __HAL_SPI_ENABLE(hspi);
   +    }
   +#endif
    
    error:
   -  /* Process Unlocked */
   -  __HAL_UNLOCK(hspi);
   -  return errorcode;
   -}
   -
   -HAL_StatusTypeDef HAL_SPI_Slave_Queue_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
   -{
   -  uint32_t tmp = 0U, tmp1 = 0U;
   -  HAL_StatusTypeDef errorcode = HAL_OK;
   -
   -  tmp  = hspi->State;
   -  tmp1 = hspi->Init.Mode;
   -
   -  if(!((tmp == HAL_SPI_STATE_READY) || ((tmp1 == SPI_MODE_MASTER) && (tmp == HAL_SPI_STATE_BUSY_RX))))
   -  {
   -    errorcode = HAL_BUSY;
   -    goto error;
   -  }
   -
   -  if((pTxData == NULL ) || (pRxData == NULL ) || (Size == 0))
   -  {
   -    errorcode = HAL_ERROR;
   -    goto error;
   -  }
   -
   -  /* Don't overwrite in case of HAL_SPI_STATE_BUSY_RX */
   -  if(hspi->State == HAL_SPI_STATE_READY)
   -  {
   -    hspi->State = HAL_SPI_STATE_BUSY_TX_RX;
   -  }
   -
   -  /* Set the transaction information */
   -  hspi->ErrorCode   = HAL_SPI_ERROR_NONE;
   -  hspi->pTxBuffPtr  = (uint8_t *)pTxData;
   -  hspi->TxXferSize  = Size;
   -  hspi->TxXferCount = Size;
   -  hspi->pRxBuffPtr  = (uint8_t *)pRxData;
   -  hspi->RxXferSize  = Size;
   -  hspi->RxXferCount = Size;
   -
   -  /* Set the function for IT treatment */
   -  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT )
   -  {
   -    hspi->RxISR     = SPI_2linesRxISR_16BIT;
   -    hspi->TxISR     = SPI_2linesTxISR_16BIT;
   -  }
   -  else
   -  {
   -    hspi->RxISR     = SPI_2linesRxISR_8BIT;
   -    hspi->TxISR     = SPI_2linesTxISR_8BIT;
   -  }
   -
   -  /* Enable TXE, RXNE and ERR interrupt */
   -  //__HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
   -
   -  /* MYNEWT: in slave mode write 1st byte to DR */
   +    return errorcode;
   +}
   +
   +/**
   + * Transmit and Receive an amount of data in non-blocking mode with Interrupt.
   + *
   + * @param  hspi pointer to a SPI_HandleTypeDef structure that contains
   + *               the configuration information for SPI module.
   + * @param  pTxData pointer to transmission data buffer
   + * @param  pRxData pointer to reception data buffer
   + * @param  Size amount of data to be sent and received
   + * @retval HAL status
   + */
   +HAL_StatusTypeDef
   +HAL_SPI_TransmitReceive_IT_Custom(SPI_HandleTypeDef *hspi,
   +                                  uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
   +{
   +    HAL_StatusTypeDef errorcode = HAL_OK;
   +
   +    /* Process locked */
   +    __HAL_LOCK(hspi);
   +
   +    errorcode = HAL_SPI_Slave_Queue_TransmitReceive(hspi, pTxData, pRxData, Size);
   +    if (errorcode) {
   +        goto error;
   +    }
   +
   +    /* Enable TXE, RXNE and ERR interrupt */
   +    __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
   +
   +    /* Check if the SPI is already enabled */
   +    if ((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE) {
   +        /* Enable SPI peripheral */
   +        __HAL_SPI_ENABLE(hspi);
   +    }
   +
   +error:
   +    /* Process Unlocked */
   +    __HAL_UNLOCK(hspi);
   +    return errorcode;
   +}
   +
   +HAL_StatusTypeDef
   +HAL_SPI_Slave_Queue_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
   +{
   +    uint32_t tmp = 0U, tmp1 = 0U;
   +    HAL_StatusTypeDef errorcode = HAL_OK;
   +
   +    tmp = hspi->State;
   +    tmp1 = hspi->Init.Mode;
   +
   +    if (!((tmp == HAL_SPI_STATE_READY) || ((tmp1 == SPI_MODE_MASTER) && (tmp == HAL_SPI_STATE_BUSY_RX)))) {
   +        errorcode = HAL_BUSY;
   +        goto error;
   +    }
   +
   +    if ((pTxData == NULL) || (pRxData == NULL) || (Size == 0)) {
   +        errorcode = HAL_ERROR;
   +        goto error;
   +    }
   +
   +    /* Don't overwrite in case of HAL_SPI_STATE_BUSY_RX */
   +    if (hspi->State == HAL_SPI_STATE_READY) {
   +        hspi->State = HAL_SPI_STATE_BUSY_TX_RX;
   +    }
   +
   +    /* Set the transaction information */
   +    hspi->ErrorCode = HAL_SPI_ERROR_NONE;
   +    hspi->pTxBuffPtr = (uint8_t *)pTxData;
   +    hspi->TxXferSize = Size;
   +    hspi->TxXferCount = Size;
   +    hspi->pRxBuffPtr = (uint8_t *)pRxData;
   +    hspi->RxXferSize = Size;
   +    hspi->RxXferCount = Size;
   +
   +    /* Set the function for IT treatment */
   +    if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) {
   +        hspi->RxISR = SPI_2linesRxISR_16BIT;
   +        hspi->TxISR = SPI_2linesTxISR_16BIT;
   +    } else {
   +        hspi->RxISR = SPI_2linesRxISR_8BIT;
   +        hspi->TxISR = SPI_2linesTxISR_8BIT;
   +    }
   +
   +    /* Enable TXE, RXNE and ERR interrupt */
   +    /*__HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR)); */
   +
   +    /* MYNEWT: in slave mode write 1st byte to DR */
    #if !MYNEWT_VAL(MCU_STM32H7)
   -  if ((hspi->Instance->CR1 & SPI_CR1_MSTR) == 0) {
   -      hspi->TxISR(hspi);
   -  }
   +    if ((hspi->Instance->CR1 & SPI_CR1_MSTR) == 0) {
   +        hspi->TxISR(hspi);
   +    }
    #else
   -  if ((hspi->Instance->CFG2 & SPI_CFG2_MASTER) == 0) {
   -      hspi->TxISR(hspi);
   -  }
   +    if ((hspi->Instance->CFG2 & SPI_CFG2_MASTER) == 0) {
   +        hspi->TxISR(hspi);
   +    }
    #endif
    
    #if 0
   -  /* Check if the SPI is already enabled */
   -  if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
   -  {
   -    /* Enable SPI peripheral */
   -    __HAL_SPI_ENABLE(hspi);
   -  }
   -#endif
   -
   -error :
   -  return errorcode;
   +    /* Check if the SPI is already enabled */
   +    if ((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE) {
   +        /* Enable SPI peripheral */
   +        __HAL_SPI_ENABLE(hspi);
   +    }
   +#endif
   +
   +error:
   +    return errorcode;
    }
    
    /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
   ```
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org