| @@ -0,0 +1,18 @@ | |||
| { | |||
| "workspace": { | |||
| "path": "${workspaceFolder}\\PLSR\\PLSR\\EWARM\\Project.eww" | |||
| }, | |||
| "workspaces": { | |||
| "${workspaceFolder}\\PLSR\\PLSR\\EWARM\\Project.eww": { | |||
| "configs": { | |||
| "${workspaceFolder}\\PLSR\\PLSR\\EWARM\\test.1.ewp": "test.1" | |||
| }, | |||
| "selected": { | |||
| "path": "${workspaceFolder}\\PLSR\\PLSR\\EWARM\\test.1.ewp" | |||
| } | |||
| } | |||
| }, | |||
| "workbench": { | |||
| "path": "E:\\Software\\IAR" | |||
| } | |||
| } | |||
| @@ -0,0 +1,19 @@ | |||
| # PLSR | |||
| ## PLSR含义 | |||
| PLSR(Pulse Linear Speed Running):脉冲指令控制功能. | |||
| 用于控制步进/伺服电机输出多段可配置脉冲,支持加减速,方向控制,段跳转,模式切换. | |||
| ### 原理 | |||
| 控制一个点击运动多少步,以什么速度运动,并在运行过程中支持速度变化或段切换. | |||
| #### 最小单位'段' | |||
| > 一段表示一个配置好的脉冲控制阶段: | |||
| > 1. 频率 | |||
| > 2. 个数(可正,可负) | |||
| > 3. 跳转指令(下一段,或结束) | |||
| > 如一个电机 | |||
| @@ -0,0 +1,18 @@ | |||
| { | |||
| "workspace": { | |||
| "path": "${workspaceFolder}\\PLSR\\PLSR\\EWARM\\Project.eww" | |||
| }, | |||
| "workspaces": { | |||
| "${workspaceFolder}\\PLSR\\PLSR\\EWARM\\Project.eww": { | |||
| "configs": { | |||
| "${workspaceFolder}\\PLSR\\PLSR\\EWARM\\test.1.ewp": "test.1" | |||
| }, | |||
| "selected": { | |||
| "path": "${workspaceFolder}\\PLSR\\PLSR\\EWARM\\test.1.ewp" | |||
| } | |||
| } | |||
| }, | |||
| "workbench": { | |||
| "path": "E:\\Software\\IAR" | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| { | |||
| "configurations": [ | |||
| { | |||
| "name": "windows-gcc-x64", | |||
| "includePath": [ | |||
| "${workspaceFolder}/**" | |||
| ], | |||
| "compilerPath": "D:/Toolchain/mingw/bin/gcc.exe", | |||
| "cStandard": "${default}", | |||
| "cppStandard": "${default}", | |||
| "intelliSenseMode": "windows-gcc-x64", | |||
| "compilerArgs": [ | |||
| "" | |||
| ] | |||
| } | |||
| ], | |||
| "version": 4 | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| { | |||
| "workspace": { | |||
| "path": "${workspaceFolder}\\EWARM\\Project.eww" | |||
| }, | |||
| "workspaces": { | |||
| "${workspaceFolder}\\EWARM\\Project.eww": { | |||
| "configs": { | |||
| "${workspaceFolder}\\EWARM\\test.1.ewp": "test.1" | |||
| }, | |||
| "selected": { | |||
| "path": "${workspaceFolder}\\EWARM\\test.1.ewp" | |||
| } | |||
| } | |||
| }, | |||
| "workbench": { | |||
| "path": "D:\\IAR" | |||
| } | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| { | |||
| "version": "0.2.0", | |||
| "configurations": [ | |||
| { | |||
| "name": "C/C++ Runner: Debug Session", | |||
| "type": "cppdbg", | |||
| "request": "launch", | |||
| "args": [], | |||
| "stopAtEntry": false, | |||
| "externalConsole": true, | |||
| "cwd": "d:/project/Plsr_Project/test.1/Core/Src", | |||
| "program": "d:/project/Plsr_Project/test.1/Core/Src/build/Debug/outDebug", | |||
| "MIMode": "gdb", | |||
| "miDebuggerPath": "gdb", | |||
| "setupCommands": [ | |||
| { | |||
| "description": "Enable pretty-printing for gdb", | |||
| "text": "-enable-pretty-printing", | |||
| "ignoreFailures": true | |||
| } | |||
| ] | |||
| } | |||
| ] | |||
| } | |||
| @@ -0,0 +1,59 @@ | |||
| { | |||
| "C_Cpp_Runner.cCompilerPath": "gcc", | |||
| "C_Cpp_Runner.cppCompilerPath": "g++", | |||
| "C_Cpp_Runner.debuggerPath": "gdb", | |||
| "C_Cpp_Runner.cStandard": "", | |||
| "C_Cpp_Runner.cppStandard": "", | |||
| "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat", | |||
| "C_Cpp_Runner.useMsvc": false, | |||
| "C_Cpp_Runner.warnings": [ | |||
| "-Wall", | |||
| "-Wextra", | |||
| "-Wpedantic", | |||
| "-Wshadow", | |||
| "-Wformat=2", | |||
| "-Wcast-align", | |||
| "-Wconversion", | |||
| "-Wsign-conversion", | |||
| "-Wnull-dereference" | |||
| ], | |||
| "C_Cpp_Runner.msvcWarnings": [ | |||
| "/W4", | |||
| "/permissive-", | |||
| "/w14242", | |||
| "/w14287", | |||
| "/w14296", | |||
| "/w14311", | |||
| "/w14826", | |||
| "/w44062", | |||
| "/w44242", | |||
| "/w14905", | |||
| "/w14906", | |||
| "/w14263", | |||
| "/w44265", | |||
| "/w14928" | |||
| ], | |||
| "C_Cpp_Runner.enableWarnings": true, | |||
| "C_Cpp_Runner.warningsAsError": false, | |||
| "C_Cpp_Runner.compilerArgs": [], | |||
| "C_Cpp_Runner.linkerArgs": [], | |||
| "C_Cpp_Runner.includePaths": [], | |||
| "C_Cpp_Runner.includeSearch": [ | |||
| "*", | |||
| "**/*" | |||
| ], | |||
| "C_Cpp_Runner.excludeSearch": [ | |||
| "**/build", | |||
| "**/build/**", | |||
| "**/.*", | |||
| "**/.*/**", | |||
| "**/.vscode", | |||
| "**/.vscode/**" | |||
| ], | |||
| "C_Cpp_Runner.useAddressSanitizer": false, | |||
| "C_Cpp_Runner.useUndefinedSanitizer": false, | |||
| "C_Cpp_Runner.useLeakSanitizer": false, | |||
| "C_Cpp_Runner.showCompilationTime": false, | |||
| "C_Cpp_Runner.useLinkTimeOptimization": false, | |||
| "C_Cpp_Runner.msvcSecureNoWarnings": false | |||
| } | |||
| @@ -0,0 +1,52 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file dma.h | |||
| * @brief This file contains all the function prototypes for | |||
| * the dma.c file | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||
| #ifndef __DMA_H__ | |||
| #define __DMA_H__ | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "main.h" | |||
| /* DMA memory to memory transfer handles -------------------------------------*/ | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| /* USER CODE BEGIN Private defines */ | |||
| /* USER CODE END Private defines */ | |||
| void MX_DMA_Init(void); | |||
| /* USER CODE BEGIN Prototypes */ | |||
| /* USER CODE END Prototypes */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __DMA_H__ */ | |||
| @@ -0,0 +1,49 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file gpio.h | |||
| * @brief This file contains all the function prototypes for | |||
| * the gpio.c file | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||
| #ifndef __GPIO_H__ | |||
| #define __GPIO_H__ | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "main.h" | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| /* USER CODE BEGIN Private defines */ | |||
| /* USER CODE END Private defines */ | |||
| void MX_GPIO_Init(void); | |||
| /* USER CODE BEGIN Prototypes */ | |||
| /* USER CODE END Prototypes */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /*__ GPIO_H__ */ | |||
| @@ -0,0 +1,69 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file : main.h | |||
| * @brief : Header for main.c file. | |||
| * This file contains the common defines of the application. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||
| #ifndef __MAIN_H | |||
| #define __MAIN_H | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "stm32f4xx_hal.h" | |||
| /* Private includes ----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| /* Exported types ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN ET */ | |||
| /* USER CODE END ET */ | |||
| /* Exported constants --------------------------------------------------------*/ | |||
| /* USER CODE BEGIN EC */ | |||
| /* USER CODE END EC */ | |||
| /* Exported macro ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN EM */ | |||
| /* USER CODE END EM */ | |||
| /* Exported functions prototypes ---------------------------------------------*/ | |||
| void Error_Handler(void); | |||
| /* USER CODE BEGIN EFP */ | |||
| /* USER CODE END EFP */ | |||
| /* Private defines -----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Private defines */ | |||
| /* USER CODE END Private defines */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __MAIN_H */ | |||
| @@ -0,0 +1,495 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file stm32f4xx_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 stm32f4xx_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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||
| #ifndef __STM32F4xx_HAL_CONF_H | |||
| #define __STM32F4xx_HAL_CONF_H | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* Exported types ------------------------------------------------------------*/ | |||
| /* Exported constants --------------------------------------------------------*/ | |||
| /* ########################## Module Selection ############################## */ | |||
| /** | |||
| * @brief This is the list of modules to be used in the HAL driver | |||
| */ | |||
| #define HAL_MODULE_ENABLED | |||
| /* #define HAL_CRYP_MODULE_ENABLED */ | |||
| /* #define HAL_ADC_MODULE_ENABLED */ | |||
| /* #define HAL_CAN_MODULE_ENABLED */ | |||
| /* #define HAL_CRC_MODULE_ENABLED */ | |||
| /* #define HAL_CAN_LEGACY_MODULE_ENABLED */ | |||
| /* #define HAL_DAC_MODULE_ENABLED */ | |||
| /* #define HAL_DCMI_MODULE_ENABLED */ | |||
| /* #define HAL_DMA2D_MODULE_ENABLED */ | |||
| /* #define HAL_ETH_MODULE_ENABLED */ | |||
| /* #define HAL_ETH_LEGACY_MODULE_ENABLED */ | |||
| /* #define HAL_NAND_MODULE_ENABLED */ | |||
| /* #define HAL_NOR_MODULE_ENABLED */ | |||
| /* #define HAL_PCCARD_MODULE_ENABLED */ | |||
| /* #define HAL_SRAM_MODULE_ENABLED */ | |||
| /* #define HAL_SDRAM_MODULE_ENABLED */ | |||
| /* #define HAL_HASH_MODULE_ENABLED */ | |||
| /* #define HAL_I2C_MODULE_ENABLED */ | |||
| /* #define HAL_I2S_MODULE_ENABLED */ | |||
| /* #define HAL_IWDG_MODULE_ENABLED */ | |||
| /* #define HAL_LTDC_MODULE_ENABLED */ | |||
| /* #define HAL_RNG_MODULE_ENABLED */ | |||
| /* #define HAL_RTC_MODULE_ENABLED */ | |||
| /* #define HAL_SAI_MODULE_ENABLED */ | |||
| /* #define HAL_SD_MODULE_ENABLED */ | |||
| /* #define HAL_MMC_MODULE_ENABLED */ | |||
| /* #define HAL_SPI_MODULE_ENABLED */ | |||
| #define HAL_TIM_MODULE_ENABLED | |||
| #define HAL_UART_MODULE_ENABLED | |||
| /* #define HAL_USART_MODULE_ENABLED */ | |||
| /* #define HAL_IRDA_MODULE_ENABLED */ | |||
| /* #define HAL_SMARTCARD_MODULE_ENABLED */ | |||
| /* #define HAL_SMBUS_MODULE_ENABLED */ | |||
| /* #define HAL_WWDG_MODULE_ENABLED */ | |||
| /* #define HAL_PCD_MODULE_ENABLED */ | |||
| /* #define HAL_HCD_MODULE_ENABLED */ | |||
| /* #define HAL_DSI_MODULE_ENABLED */ | |||
| /* #define HAL_QSPI_MODULE_ENABLED */ | |||
| /* #define HAL_QSPI_MODULE_ENABLED */ | |||
| /* #define HAL_CEC_MODULE_ENABLED */ | |||
| /* #define HAL_FMPI2C_MODULE_ENABLED */ | |||
| /* #define HAL_FMPSMBUS_MODULE_ENABLED */ | |||
| /* #define HAL_SPDIFRX_MODULE_ENABLED */ | |||
| /* #define HAL_DFSDM_MODULE_ENABLED */ | |||
| /* #define HAL_LPTIM_MODULE_ENABLED */ | |||
| #define HAL_GPIO_MODULE_ENABLED | |||
| #define HAL_EXTI_MODULE_ENABLED | |||
| #define HAL_DMA_MODULE_ENABLED | |||
| #define HAL_RCC_MODULE_ENABLED | |||
| #define HAL_FLASH_MODULE_ENABLED | |||
| #define HAL_PWR_MODULE_ENABLED | |||
| #define HAL_CORTEX_MODULE_ENABLED | |||
| /* ########################## HSE/HSI 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). | |||
| */ | |||
| #if !defined (HSE_VALUE) | |||
| #define HSE_VALUE 12000000U /*!< Value of the External oscillator in Hz */ | |||
| #endif /* HSE_VALUE */ | |||
| #if !defined (HSE_STARTUP_TIMEOUT) | |||
| #define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */ | |||
| #endif /* HSE_STARTUP_TIMEOUT */ | |||
| /** | |||
| * @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)16000000U) /*!< Value of the Internal oscillator in Hz*/ | |||
| #endif /* HSI_VALUE */ | |||
| /** | |||
| * @brief Internal Low Speed oscillator (LSI) value. | |||
| */ | |||
| #if !defined (LSI_VALUE) | |||
| #define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/ | |||
| #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz | |||
| The real value may vary depending on the variations | |||
| in voltage and temperature.*/ | |||
| /** | |||
| * @brief External Low Speed oscillator (LSE) value. | |||
| */ | |||
| #if !defined (LSE_VALUE) | |||
| #define LSE_VALUE 32768U /*!< Value of the External Low Speed oscillator in Hz */ | |||
| #endif /* LSE_VALUE */ | |||
| #if !defined (LSE_STARTUP_TIMEOUT) | |||
| #define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */ | |||
| #endif /* LSE_STARTUP_TIMEOUT */ | |||
| /** | |||
| * @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 audio frequency in Hz*/ | |||
| #endif /* EXTERNAL_CLOCK_VALUE */ | |||
| /* Tip: To avoid modifying this file each time you need to use different HSE, | |||
| === you can define the HSE value in your toolchain compiler preprocessor. */ | |||
| /* ########################### System Configuration ######################### */ | |||
| /** | |||
| * @brief This is the HAL system configuration section | |||
| */ | |||
| #define VDD_VALUE 3300U /*!< Value of VDD in mv */ | |||
| #define TICK_INT_PRIORITY 5U /*!< tick interrupt priority */ | |||
| #define USE_RTOS 0U | |||
| #define PREFETCH_ENABLE 1U | |||
| #define INSTRUCTION_CACHE_ENABLE 1U | |||
| #define DATA_CACHE_ENABLE 1U | |||
| #define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */ | |||
| #define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */ | |||
| #define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */ | |||
| #define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */ | |||
| #define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */ | |||
| #define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */ | |||
| #define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */ | |||
| #define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */ | |||
| #define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */ | |||
| #define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */ | |||
| #define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */ | |||
| #define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */ | |||
| #define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */ | |||
| #define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U /* FMPI2C register callback disabled */ | |||
| #define USE_HAL_FMPSMBUS_REGISTER_CALLBACKS 0U /* FMPSMBUS register callback disabled */ | |||
| #define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */ | |||
| #define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */ | |||
| #define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */ | |||
| #define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */ | |||
| #define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */ | |||
| #define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */ | |||
| #define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */ | |||
| #define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */ | |||
| #define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */ | |||
| #define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */ | |||
| #define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */ | |||
| #define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */ | |||
| #define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */ | |||
| #define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */ | |||
| #define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */ | |||
| #define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */ | |||
| #define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */ | |||
| #define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */ | |||
| #define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */ | |||
| #define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ | |||
| #define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ | |||
| #define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */ | |||
| #define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */ | |||
| #define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ | |||
| /* ########################## Assert Selection ############################## */ | |||
| /** | |||
| * @brief Uncomment the line below to expanse the "assert_param" macro in the | |||
| * HAL drivers code | |||
| */ | |||
| /* #define USE_FULL_ASSERT 1U */ | |||
| /* ################## Ethernet peripheral configuration ##################### */ | |||
| /* Section 1 : Ethernet peripheral configuration */ | |||
| /* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ | |||
| #define MAC_ADDR0 2U | |||
| #define MAC_ADDR1 0U | |||
| #define MAC_ADDR2 0U | |||
| #define MAC_ADDR3 0U | |||
| #define MAC_ADDR4 0U | |||
| #define MAC_ADDR5 0U | |||
| /* Definition of the Ethernet driver buffers size and count */ | |||
| #define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ | |||
| #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ | |||
| #define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ | |||
| #define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ | |||
| /* Section 2: PHY configuration section */ | |||
| /* DP83848_PHY_ADDRESS Address*/ | |||
| #define DP83848_PHY_ADDRESS | |||
| /* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ | |||
| #define PHY_RESET_DELAY 0x000000FFU | |||
| /* PHY Configuration delay */ | |||
| #define PHY_CONFIG_DELAY 0x00000FFFU | |||
| #define PHY_READ_TO 0x0000FFFFU | |||
| #define PHY_WRITE_TO 0x0000FFFFU | |||
| /* Section 3: Common PHY Registers */ | |||
| #define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */ | |||
| #define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */ | |||
| #define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ | |||
| #define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ | |||
| #define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ | |||
| #define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ | |||
| #define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ | |||
| #define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ | |||
| #define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ | |||
| #define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ | |||
| #define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ | |||
| #define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ | |||
| #define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ | |||
| #define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ | |||
| #define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ | |||
| /* Section 4: Extended PHY Registers */ | |||
| #define PHY_SR ((uint16_t)) /*!< PHY status register Offset */ | |||
| #define PHY_SPEED_STATUS ((uint16_t)) /*!< PHY Speed mask */ | |||
| #define PHY_DUPLEX_STATUS ((uint16_t)) /*!< PHY Duplex mask */ | |||
| /* ################## SPI peripheral configuration ########################## */ | |||
| /* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver | |||
| * Activated: CRC code is present inside driver | |||
| * Deactivated: CRC code cleaned from driver | |||
| */ | |||
| #define USE_SPI_CRC 0U | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| /** | |||
| * @brief Include module's header file | |||
| */ | |||
| #ifdef HAL_RCC_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_rcc.h" | |||
| #endif /* HAL_RCC_MODULE_ENABLED */ | |||
| #ifdef HAL_GPIO_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_gpio.h" | |||
| #endif /* HAL_GPIO_MODULE_ENABLED */ | |||
| #ifdef HAL_EXTI_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_exti.h" | |||
| #endif /* HAL_EXTI_MODULE_ENABLED */ | |||
| #ifdef HAL_DMA_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_dma.h" | |||
| #endif /* HAL_DMA_MODULE_ENABLED */ | |||
| #ifdef HAL_CORTEX_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_cortex.h" | |||
| #endif /* HAL_CORTEX_MODULE_ENABLED */ | |||
| #ifdef HAL_ADC_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_adc.h" | |||
| #endif /* HAL_ADC_MODULE_ENABLED */ | |||
| #ifdef HAL_CAN_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_can.h" | |||
| #endif /* HAL_CAN_MODULE_ENABLED */ | |||
| #ifdef HAL_CAN_LEGACY_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_can_legacy.h" | |||
| #endif /* HAL_CAN_LEGACY_MODULE_ENABLED */ | |||
| #ifdef HAL_CRC_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_crc.h" | |||
| #endif /* HAL_CRC_MODULE_ENABLED */ | |||
| #ifdef HAL_CRYP_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_cryp.h" | |||
| #endif /* HAL_CRYP_MODULE_ENABLED */ | |||
| #ifdef HAL_DMA2D_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_dma2d.h" | |||
| #endif /* HAL_DMA2D_MODULE_ENABLED */ | |||
| #ifdef HAL_DAC_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_dac.h" | |||
| #endif /* HAL_DAC_MODULE_ENABLED */ | |||
| #ifdef HAL_DCMI_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_dcmi.h" | |||
| #endif /* HAL_DCMI_MODULE_ENABLED */ | |||
| #ifdef HAL_ETH_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_eth.h" | |||
| #endif /* HAL_ETH_MODULE_ENABLED */ | |||
| #ifdef HAL_ETH_LEGACY_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_eth_legacy.h" | |||
| #endif /* HAL_ETH_LEGACY_MODULE_ENABLED */ | |||
| #ifdef HAL_FLASH_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_flash.h" | |||
| #endif /* HAL_FLASH_MODULE_ENABLED */ | |||
| #ifdef HAL_SRAM_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_sram.h" | |||
| #endif /* HAL_SRAM_MODULE_ENABLED */ | |||
| #ifdef HAL_NOR_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_nor.h" | |||
| #endif /* HAL_NOR_MODULE_ENABLED */ | |||
| #ifdef HAL_NAND_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_nand.h" | |||
| #endif /* HAL_NAND_MODULE_ENABLED */ | |||
| #ifdef HAL_PCCARD_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_pccard.h" | |||
| #endif /* HAL_PCCARD_MODULE_ENABLED */ | |||
| #ifdef HAL_SDRAM_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_sdram.h" | |||
| #endif /* HAL_SDRAM_MODULE_ENABLED */ | |||
| #ifdef HAL_HASH_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_hash.h" | |||
| #endif /* HAL_HASH_MODULE_ENABLED */ | |||
| #ifdef HAL_I2C_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_i2c.h" | |||
| #endif /* HAL_I2C_MODULE_ENABLED */ | |||
| #ifdef HAL_SMBUS_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_smbus.h" | |||
| #endif /* HAL_SMBUS_MODULE_ENABLED */ | |||
| #ifdef HAL_I2S_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_i2s.h" | |||
| #endif /* HAL_I2S_MODULE_ENABLED */ | |||
| #ifdef HAL_IWDG_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_iwdg.h" | |||
| #endif /* HAL_IWDG_MODULE_ENABLED */ | |||
| #ifdef HAL_LTDC_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_ltdc.h" | |||
| #endif /* HAL_LTDC_MODULE_ENABLED */ | |||
| #ifdef HAL_PWR_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_pwr.h" | |||
| #endif /* HAL_PWR_MODULE_ENABLED */ | |||
| #ifdef HAL_RNG_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_rng.h" | |||
| #endif /* HAL_RNG_MODULE_ENABLED */ | |||
| #ifdef HAL_RTC_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_rtc.h" | |||
| #endif /* HAL_RTC_MODULE_ENABLED */ | |||
| #ifdef HAL_SAI_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_sai.h" | |||
| #endif /* HAL_SAI_MODULE_ENABLED */ | |||
| #ifdef HAL_SD_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_sd.h" | |||
| #endif /* HAL_SD_MODULE_ENABLED */ | |||
| #ifdef HAL_SPI_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_spi.h" | |||
| #endif /* HAL_SPI_MODULE_ENABLED */ | |||
| #ifdef HAL_TIM_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_tim.h" | |||
| #endif /* HAL_TIM_MODULE_ENABLED */ | |||
| #ifdef HAL_UART_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_uart.h" | |||
| #endif /* HAL_UART_MODULE_ENABLED */ | |||
| #ifdef HAL_USART_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_usart.h" | |||
| #endif /* HAL_USART_MODULE_ENABLED */ | |||
| #ifdef HAL_IRDA_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_irda.h" | |||
| #endif /* HAL_IRDA_MODULE_ENABLED */ | |||
| #ifdef HAL_SMARTCARD_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_smartcard.h" | |||
| #endif /* HAL_SMARTCARD_MODULE_ENABLED */ | |||
| #ifdef HAL_WWDG_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_wwdg.h" | |||
| #endif /* HAL_WWDG_MODULE_ENABLED */ | |||
| #ifdef HAL_PCD_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_pcd.h" | |||
| #endif /* HAL_PCD_MODULE_ENABLED */ | |||
| #ifdef HAL_HCD_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_hcd.h" | |||
| #endif /* HAL_HCD_MODULE_ENABLED */ | |||
| #ifdef HAL_DSI_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_dsi.h" | |||
| #endif /* HAL_DSI_MODULE_ENABLED */ | |||
| #ifdef HAL_QSPI_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_qspi.h" | |||
| #endif /* HAL_QSPI_MODULE_ENABLED */ | |||
| #ifdef HAL_CEC_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_cec.h" | |||
| #endif /* HAL_CEC_MODULE_ENABLED */ | |||
| #ifdef HAL_FMPI2C_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_fmpi2c.h" | |||
| #endif /* HAL_FMPI2C_MODULE_ENABLED */ | |||
| #ifdef HAL_FMPSMBUS_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_fmpsmbus.h" | |||
| #endif /* HAL_FMPSMBUS_MODULE_ENABLED */ | |||
| #ifdef HAL_SPDIFRX_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_spdifrx.h" | |||
| #endif /* HAL_SPDIFRX_MODULE_ENABLED */ | |||
| #ifdef HAL_DFSDM_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_dfsdm.h" | |||
| #endif /* HAL_DFSDM_MODULE_ENABLED */ | |||
| #ifdef HAL_LPTIM_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_lptim.h" | |||
| #endif /* HAL_LPTIM_MODULE_ENABLED */ | |||
| #ifdef HAL_MMC_MODULE_ENABLED | |||
| #include "stm32f4xx_hal_mmc.h" | |||
| #endif /* HAL_MMC_MODULE_ENABLED */ | |||
| /* 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 | |||
| */ | |||
| #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) | |||
| /* Exported functions ------------------------------------------------------- */ | |||
| void assert_failed(uint8_t* file, uint32_t line); | |||
| #else | |||
| #define assert_param(expr) ((void)0U) | |||
| #endif /* USE_FULL_ASSERT */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __STM32F4xx_HAL_CONF_H */ | |||
| @@ -0,0 +1,71 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file stm32f4xx_it.h | |||
| * @brief This file contains the headers of the interrupt handlers. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||
| #ifndef __STM32F4xx_IT_H | |||
| #define __STM32F4xx_IT_H | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* Private includes ----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| /* Exported types ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN ET */ | |||
| /* USER CODE END ET */ | |||
| /* Exported constants --------------------------------------------------------*/ | |||
| /* USER CODE BEGIN EC */ | |||
| /* USER CODE END EC */ | |||
| /* Exported macro ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN EM */ | |||
| /* USER CODE END EM */ | |||
| /* Exported functions prototypes ---------------------------------------------*/ | |||
| void NMI_Handler(void); | |||
| void HardFault_Handler(void); | |||
| void MemManage_Handler(void); | |||
| void BusFault_Handler(void); | |||
| void UsageFault_Handler(void); | |||
| void SVC_Handler(void); | |||
| void DebugMon_Handler(void); | |||
| void PendSV_Handler(void); | |||
| void SysTick_Handler(void); | |||
| void TIM1_UP_TIM10_IRQHandler(void); | |||
| void USART1_IRQHandler(void); | |||
| void TIM6_DAC_IRQHandler(void); | |||
| void DMA2_Stream2_IRQHandler(void); | |||
| void DMA2_Stream7_IRQHandler(void); | |||
| /* USER CODE BEGIN EFP */ | |||
| /* USER CODE END EFP */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __STM32F4xx_IT_H */ | |||
| @@ -0,0 +1,255 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file tim.h | |||
| * @brief This file contains all the function prototypes for | |||
| * the tim.c file | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||
| #ifndef __TIM_H__ | |||
| #define __TIM_H__ | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "main.h" | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| extern TIM_HandleTypeDef htim2; | |||
| extern TIM_HandleTypeDef htim6; | |||
| extern TIM_HandleTypeDef htim10; | |||
| extern TIM_HandleTypeDef htim11; | |||
| extern TIM_HandleTypeDef htim13; | |||
| extern TIM_HandleTypeDef htim14; | |||
| /* USER CODE BEGIN Private defines */ | |||
| // PLSR系统配置参数 | |||
| #define PLSR_MAX_SECTIONS 10 // 最大段数 | |||
| #define PLSR_PWM_FREQ_MIN 1 // 最小PWM频率 1Hz | |||
| #define PLSR_PWM_FREQ_MAX 100000 // 最大PWM频率 100kHz | |||
| #define PLSR_PWM_FREQ_DEFAULT 1000 // 默认PWM频率 1kHz | |||
| #define PLSR_DUTY_CYCLE 50 // 初始占空比 50% | |||
| // PWM输出引脚定义 (仅PF6) | |||
| #define PLSR_PWM_PIN GPIO_PIN_6 // PF6 - TIM10_CH1 | |||
| #define PLSR_PWM_PORT GPIOF | |||
| // 硬件计数器定义 (使用TIM2作为硬件计数器) | |||
| #define PLSR_COUNTER_PIN GPIO_PIN_5 // PA5 - TIM2_CH1 (外部时钟输入) | |||
| #define PLSR_COUNTER_PORT GPIOA | |||
| // 等待条件类型枚举 | |||
| typedef enum { | |||
| PLSR_WAIT_PLUSEEND = 0, // 脉冲发送完成 | |||
| PLSR_WAIT_TIME = 1, // 等待时间 | |||
| PLSR_WAIT_CONDITION = 2, // 等待条件 | |||
| PLSR_WAIT_ACT_TIME = 3, // ACT时间 | |||
| PLSR_WAIT_EXT_EVENT = 4, // 外部事件 | |||
| PLSR_WAIT_EXT_OR_END = 5 // 外部事件或结束 | |||
| } PLSR_WaitType_t; | |||
| // 加减速算法枚举 | |||
| typedef enum { | |||
| PLSR_ACCEL_LINEAR = 0, // 线性加减速 | |||
| PLSR_ACCEL_CURVE = 1, // 曲线加减速 | |||
| PLSR_ACCEL_SINE = 2 // 正弦加减速 | |||
| } PLSR_AccelAlgorithm_t; | |||
| // 运行状态枚举 | |||
| typedef enum { | |||
| PLSR_STATE_IDLE = 0, // 空闲状态 | |||
| PLSR_STATE_ACCEL = 1, // 加速状态 | |||
| PLSR_STATE_CONST = 2, // 匀速状态 | |||
| PLSR_STATE_DECEL = 3, // 减速状态 | |||
| PLSR_STATE_WAIT = 4, // 等待状态 | |||
| PLSR_STATE_STOP = 5 // 停止状态 | |||
| } PLSR_RunState_t; | |||
| // 路径状态枚举 | |||
| typedef enum { | |||
| PLSR_ROUTE_IDLE = 0, // 路径空闲 | |||
| PLSR_ROUTE_RUNNING = 1, // 路径运行中 | |||
| PLSR_ROUTE_COMPLETED = 2, // 路径完成 | |||
| PLSR_ROUTE_ERROR = 3 // 路径错误 | |||
| } PLSR_RouteState_t; | |||
| // 段状态枚举 | |||
| typedef enum { | |||
| PLSR_SECTION_IDLE = 0, // 段空闲 | |||
| PLSR_SECTION_RUNNING = 1, // 段运行中 | |||
| PLSR_SECTION_COMPLETED = 2 // 段完成 | |||
| } PLSR_SectionState_t; | |||
| // 运行模式枚举 | |||
| typedef enum { | |||
| PLSR_MODE_RELATIVE = 0, // 相对模式 | |||
| PLSR_MODE_ABSOLUTE = 1 // 绝对模式 | |||
| } PLSR_Mode_t; | |||
| // 方向枚举 | |||
| typedef enum { | |||
| PLSR_DIR_FORWARD = 0, // 正向 | |||
| PLSR_DIR_REVERSE = 1 // 反向 | |||
| } PLSR_Direction_t; | |||
| /* USER CODE END Private defines */ | |||
| void MX_TIM2_Init(void); | |||
| void MX_TIM6_Init(void); | |||
| void MX_TIM10_Init(void); | |||
| void MX_TIM11_Init(void); | |||
| void MX_TIM13_Init(void); | |||
| void MX_TIM14_Init(void); | |||
| void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); | |||
| // PLSR等待条件结构体 | |||
| typedef struct { | |||
| PLSR_WaitType_t wait_type; // 等待条件类型 | |||
| uint32_t wait_time_ms; // 等待时间(ms) | |||
| uint32_t act_time_ms; // ACT时间(ms) | |||
| uint8_t condition_flag; // 条件标志 | |||
| uint8_t ext_event_flag; // 外部事件标志 | |||
| } PLSR_WaitCondition_t; | |||
| // PLSR加减速配置结构体 | |||
| typedef struct { | |||
| uint32_t accel_time_ms; // 加速时间(ms) | |||
| uint32_t decel_time_ms; // 减速时间(ms) | |||
| PLSR_AccelAlgorithm_t accel_algorithm; // 加减速算法 | |||
| } PLSR_AccelConfig_t; | |||
| // PLSR段配置结构体 | |||
| typedef struct { | |||
| uint8_t section_num; // 段号(1-10) | |||
| uint32_t target_freq; // 目标频率(Hz) | |||
| uint32_t target_pulse; // 目标脉冲数 | |||
| uint8_t next_section; // 下一段号(0表示结束) | |||
| PLSR_SectionState_t section_state; // 段状态 | |||
| PLSR_AccelConfig_t accel_config; // 加减速配置 | |||
| PLSR_WaitCondition_t wait_condition; // 等待条件 | |||
| } PLSR_SectionConfig_t; | |||
| // PLSR路径控制结构体 | |||
| typedef struct { | |||
| PLSR_RouteState_t route_state; // 路径状态 | |||
| uint8_t current_section_num; // 当前段号 | |||
| uint32_t current_freq; // 当前频率 | |||
| uint32_t target_freq; // 目标频率 | |||
| uint32_t pulse_count; // 当前脉冲计数 | |||
| uint32_t start_freq; // 起始频率 | |||
| uint32_t end_freq; // 结束频率 | |||
| uint8_t output_port; // 输出端口选择 | |||
| PLSR_Mode_t mode; // 模式(相对/绝对) | |||
| PLSR_Direction_t direction; // 方向 | |||
| // 运行状态参数 | |||
| PLSR_RunState_t run_state; // 运行状态 | |||
| uint32_t accel_step_count; // 加速步数计数 | |||
| uint32_t decel_step_count; // 减速步数计数 | |||
| uint32_t const_pulse_count; // 匀速脉冲计数 | |||
| uint32_t freq_step; // 频率步长 | |||
| uint32_t wait_start_tick; // 等待开始时间 | |||
| uint32_t act_start_tick; // ACT开始时间 | |||
| PLSR_SectionConfig_t section[PLSR_MAX_SECTIONS]; // 段配置数组 | |||
| } PLSR_RouteConfig_t; | |||
| // 默认参数定义 | |||
| #define PLSR_DEFAULT_STEP_FREQ_US 1000 // 默认TIM6更新频率1000微秒(1ms) | |||
| #define PLSR_DEFAULT_ACCEL_TIME_MS 100 // 默认加速时间100ms | |||
| #define PLSR_DEFAULT_DECEL_TIME_MS 100 // 默认减速时间100ms | |||
| #define PLSR_DEFAULT_ACT_TIME_MS 200 // 默认ACT时间200ms | |||
| #define PLSR_DEFAULT_WAIT_TIME_MS 200 // 默认等待时间200ms | |||
| #define PLSR_DEFAULT_START_SECTION 0 // 默认起始段编号 | |||
| // 基础PWM函数 | |||
| // ==================== PLSR PWM控制函数 ==================== | |||
| void PLSR_PWM_Init(void); | |||
| void PLSR_PWM_Start(void); | |||
| void PLSR_PWM_Stop(void); | |||
| void PLSR_PWM_SetFrequency(uint32_t frequency); | |||
| uint8_t PLSR_PWM_IsRunning(void); | |||
| // ==================== PLSR计数器控制函数 ==================== | |||
| uint32_t PLSR_Counter_GetCount(void); | |||
| void PLSR_Counter_Reset(void); | |||
| void PLSR_Counter_SetTarget(uint32_t target); | |||
| uint32_t PLSR_Counter_GetTarget(void); | |||
| // ==================== PLSR TIM6频率配置函数 ==================== | |||
| void PLSR_TIM6_SetUpdateFreq(uint32_t freq_us); | |||
| uint32_t PLSR_TIM6_GetUpdateFreq(void); | |||
| void PLSR_TIM6_Start(void); | |||
| void PLSR_TIM6_Stop(void); | |||
| // ==================== PLSR路径控制函数 ==================== | |||
| void PLSR_Route_Init(PLSR_RouteConfig_t* route); //<路径初始化 | |||
| void PLSR_Route_Start(PLSR_RouteConfig_t* route); //<路径开始 | |||
| void PLSR_Route_Stop(PLSR_RouteConfig_t* route); //<路径停止 | |||
| void PLSR_Section_Process(PLSR_RouteConfig_t* route); //<段处理 | |||
| // ==================== PLSR段控制函数 ==================== | |||
| void PLSR_Section_Init(PLSR_SectionConfig_t* section, uint8_t section_num); | |||
| void PLSR_Section_SwitchNext(PLSR_RouteConfig_t* route); | |||
| uint8_t PLSR_Section_CheckWaitCondition(PLSR_RouteConfig_t* route); | |||
| void PLSR_Section_CalculateConstPulse(PLSR_RouteConfig_t* route); | |||
| // ==================== PLSR加减速算法函数 ==================== | |||
| float PLSR_Accel_CalculateLinear(float progress); | |||
| float PLSR_Accel_CalculateCurve(float progress); | |||
| float PLSR_Accel_CalculateSine(float progress); | |||
| void PLSR_Accel_Process(PLSR_RouteConfig_t* route); | |||
| void PLSR_Accel_UpdateFrequency(PLSR_RouteConfig_t* route); | |||
| // ==================== PLSR等待条件处理函数 ==================== | |||
| void PLSR_Wait_StartTimer(PLSR_RouteConfig_t* route); | |||
| uint8_t PLSR_Wait_CheckTimeCondition(PLSR_RouteConfig_t* route); | |||
| uint8_t PLSR_Wait_CheckActTime(PLSR_RouteConfig_t* route); | |||
| uint8_t PLSR_Wait_CheckExtEvent(PLSR_RouteConfig_t* route); | |||
| void PLSR_SetExtEvent(uint8_t flag); | |||
| void PLSR_ClearExtEvent(void); | |||
| void PLSR_SetSectionCondition(PLSR_RouteConfig_t* route, uint8_t section_num, uint8_t flag); | |||
| // ==================== PLSR系统函数 ==================== | |||
| uint32_t PLSR_GetSystemTick(void); | |||
| uint32_t PLSR_PWM_GetFrequency(void); | |||
| void PLSR_PWM_SetDutyCycle(uint8_t duty_percent); | |||
| // ==================== PLSR全局变量声明 ==================== | |||
| extern PLSR_RouteConfig_t g_plsr_route; // 全局PLSR路径控制结构体 | |||
| extern uint32_t g_plsr_system_tick; // 系统时钟计数器 | |||
| extern uint8_t g_plsr_ext_event_flag; // 外部事件标志 | |||
| /* USER CODE END Prototypes */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __TIM_H__ */ | |||
| @@ -0,0 +1,52 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file usart.h | |||
| * @brief This file contains all the function prototypes for | |||
| * the usart.c file | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||
| #ifndef __USART_H__ | |||
| #define __USART_H__ | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "main.h" | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| extern UART_HandleTypeDef huart1; | |||
| /* USER CODE BEGIN Private defines */ | |||
| /* USER CODE END Private defines */ | |||
| void MX_USART1_UART_Init(void); | |||
| /* USER CODE BEGIN Prototypes */ | |||
| /* USER CODE END Prototypes */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __USART_H__ */ | |||
| @@ -0,0 +1,58 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file dma.c | |||
| * @brief This file provides code for the configuration | |||
| * of all the requested memory to memory DMA transfers. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "dma.h" | |||
| /* USER CODE BEGIN 0 */ | |||
| /* USER CODE END 0 */ | |||
| /*----------------------------------------------------------------------------*/ | |||
| /* Configure DMA */ | |||
| /*----------------------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN 1 */ | |||
| /* USER CODE END 1 */ | |||
| /** | |||
| * Enable DMA controller clock | |||
| */ | |||
| void MX_DMA_Init(void) | |||
| { | |||
| /* DMA controller clock enable */ | |||
| __HAL_RCC_DMA2_CLK_ENABLE(); | |||
| /* DMA interrupt init */ | |||
| /* DMA2_Stream2_IRQn interrupt configuration */ | |||
| HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0); | |||
| HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); | |||
| /* DMA2_Stream7_IRQn interrupt configuration */ | |||
| HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 0, 0); | |||
| HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn); | |||
| } | |||
| /* USER CODE BEGIN 2 */ | |||
| /* USER CODE END 2 */ | |||
| @@ -0,0 +1,67 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file gpio.c | |||
| * @brief This file provides code for the configuration | |||
| * of all used GPIO pins. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "gpio.h" | |||
| /* USER CODE BEGIN 0 */ | |||
| /* USER CODE END 0 */ | |||
| /*----------------------------------------------------------------------------*/ | |||
| /* Configure GPIO */ | |||
| /*----------------------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN 1 */ | |||
| /* USER CODE END 1 */ | |||
| /** Configure pins as | |||
| * Analog | |||
| * Input | |||
| * Output | |||
| * EVENT_OUT | |||
| * EXTI | |||
| */ | |||
| void MX_GPIO_Init(void) | |||
| { | |||
| GPIO_InitTypeDef GPIO_InitStruct = {0}; | |||
| /* GPIO Ports Clock Enable */ | |||
| __HAL_RCC_GPIOB_CLK_ENABLE(); | |||
| __HAL_RCC_GPIOA_CLK_ENABLE(); | |||
| __HAL_RCC_GPIOH_CLK_ENABLE(); | |||
| __HAL_RCC_GPIOF_CLK_ENABLE(); | |||
| /*Configure GPIO pin Output Level */ | |||
| HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6|GPIO_PIN_8, GPIO_PIN_RESET); | |||
| /*Configure GPIO pins : PF6 PF8 */ | |||
| GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_8; | |||
| GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |||
| GPIO_InitStruct.Pull = GPIO_NOPULL; | |||
| GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | |||
| HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); | |||
| } | |||
| /* USER CODE BEGIN 2 */ | |||
| /* USER CODE END 2 */ | |||
| @@ -0,0 +1,293 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file : main.c | |||
| * @brief : Main program body | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "main.h" | |||
| #include "gpio.h" | |||
| /* Private includes ----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Includes */ | |||
| #include "ucos_ii.h" | |||
| #include "app_cfg.h" | |||
| #include "tim.h" | |||
| #include "usart.h" | |||
| #include "dma.h" | |||
| /* USER CODE END Includes */ | |||
| /* Private typedef -----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PTD */ | |||
| /* USER CODE END PTD */ | |||
| /* Private define ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PD */ | |||
| /* USER CODE END PD */ | |||
| /* Private macro -------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PM */ | |||
| /* USER CODE END PM */ | |||
| /* Private variables ---------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PV */ | |||
| /* 任务堆栈定义 */ | |||
| static OS_STK StartupTaskStk[APP_CFG_STARTUP_TASK_STK_SIZE]; | |||
| static OS_STK LedTaskStk[APP_CFG_LED_TASK_STK_SIZE]; | |||
| static OS_STK KeyTaskStk[APP_CFG_KEY_TASK_STK_SIZE]; | |||
| // 全局加速配置 | |||
| //static PLSR_AccelProfile_t motor_profile; | |||
| /* 任务函数声明 */ | |||
| static void StartupTask(void *p_arg); | |||
| static void LedTask(void *p_arg); | |||
| static void KeyTask(void *p_arg); | |||
| /* USER CODE END PV */ | |||
| /* Private function prototypes -----------------------------------------------*/ | |||
| void SystemClock_Config(void); | |||
| /* USER CODE BEGIN PFP */ | |||
| /* USER CODE END PFP */ | |||
| /* Private user code ---------------------------------------------------------*/ | |||
| /* USER CODE BEGIN 0 */ | |||
| /* USER CODE END 0 */ | |||
| /** | |||
| * @brief The application entry point. | |||
| * @retval int | |||
| */ | |||
| int main(void) | |||
| { | |||
| /* USER CODE BEGIN 1 */ | |||
| INT8U err; | |||
| /* USER CODE END 1 */ | |||
| /* MCU Configuration--------------------------------------------------------*/ | |||
| /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ | |||
| HAL_Init(); | |||
| /* USER CODE BEGIN Init */ | |||
| /* USER CODE END Init */ | |||
| /* Configure the system clock */ | |||
| SystemClock_Config(); | |||
| /* USER CODE BEGIN SysInit */ | |||
| /* USER CODE END SysInit */ | |||
| /* Initialize all configured peripherals */ | |||
| //MX_GPIO_Init(); | |||
| MX_USART1_UART_Init(); | |||
| MX_DMA_Init(); | |||
| PLSR_PWM_Init(); | |||
| /* USER CODE BEGIN 2 */ | |||
| /* 初始化uC/OS-II */ | |||
| OSInit(); | |||
| /* 创建启动任务 */ | |||
| err = OSTaskCreateExt(StartupTask, | |||
| (void *)0, | |||
| &StartupTaskStk[APP_CFG_STARTUP_TASK_STK_SIZE - 1], | |||
| APP_CFG_STARTUP_TASK_PRIO, | |||
| APP_CFG_STARTUP_TASK_PRIO, | |||
| &StartupTaskStk[0], | |||
| APP_CFG_STARTUP_TASK_STK_SIZE, | |||
| (void *)0, | |||
| OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); | |||
| if (err != OS_ERR_NONE) { | |||
| /* 任务创建失败处理 */ | |||
| while(1); | |||
| } | |||
| // /* 启动uC/OS-II */ | |||
| OSStart(); | |||
| /* USER CODE END 2 */ | |||
| /* Infinite loop */ | |||
| /* USER CODE BEGIN WHILE */ | |||
| while (1) | |||
| { | |||
| /* USER CODE END WHILE */ | |||
| /* USER CODE BEGIN 3 */ | |||
| } | |||
| /* USER CODE END 3 */ | |||
| } | |||
| /** | |||
| * @brief System Clock Configuration | |||
| * @retval None | |||
| */ | |||
| void SystemClock_Config(void) | |||
| { | |||
| RCC_OscInitTypeDef RCC_OscInitStruct = {0}; | |||
| RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; | |||
| /** Configure the main internal regulator output voltage | |||
| */ | |||
| __HAL_RCC_PWR_CLK_ENABLE(); | |||
| __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); | |||
| /** Initializes the RCC Oscillators according to the specified parameters | |||
| * in the RCC_OscInitTypeDef structure. | |||
| */ | |||
| RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |||
| RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |||
| RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |||
| RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |||
| RCC_OscInitStruct.PLL.PLLM = 6; | |||
| RCC_OscInitStruct.PLL.PLLN = 168; | |||
| RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | |||
| RCC_OscInitStruct.PLL.PLLQ = 4; | |||
| if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) | |||
| { | |||
| Error_Handler(); | |||
| } | |||
| /** Initializes the CPU, AHB and APB buses clocks | |||
| */ | |||
| RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK | |||
| |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; | |||
| RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |||
| RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |||
| RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; | |||
| RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; | |||
| if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) | |||
| { | |||
| Error_Handler(); | |||
| } | |||
| } | |||
| /* USER CODE BEGIN 4 */ | |||
| static void StartupTask(void *p_arg) | |||
| { | |||
| INT8U err; | |||
| (void)p_arg; | |||
| /* 初始化SysTick */ | |||
| OS_CPU_SysTickInitFreq(SystemCoreClock); | |||
| /* 启用统计任务 */ | |||
| #if OS_TASK_STAT_EN > 0u | |||
| OSStatInit(); | |||
| #endif | |||
| /* 创建启动任务 */ | |||
| err = OSTaskCreateExt(LedTask, | |||
| (void *)0, | |||
| &LedTaskStk[APP_CFG_LED_TASK_STK_SIZE - 1], | |||
| APP_CFG_LED_TASK_PRIO, | |||
| APP_CFG_LED_TASK_PRIO, | |||
| &LedTaskStk[0], | |||
| APP_CFG_LED_TASK_STK_SIZE, | |||
| (void *)0, | |||
| OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); | |||
| /* 创建启动任务 */ | |||
| err = OSTaskCreateExt(KeyTask, | |||
| (void *)0, | |||
| &KeyTaskStk[APP_CFG_KEY_TASK_STK_SIZE - 1], | |||
| APP_CFG_KEY_TASK_PRIO, | |||
| APP_CFG_KEY_TASK_PRIO, | |||
| &KeyTaskStk[0], | |||
| APP_CFG_KEY_TASK_STK_SIZE, | |||
| (void *)0, | |||
| OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); | |||
| if (err != OS_ERR_NONE) { | |||
| /* 任务创建失败处理 */ | |||
| while(1); | |||
| } | |||
| /* 启动任务完成,删除自身 */ | |||
| OSTaskDel(OS_PRIO_SELF); | |||
| } | |||
| static void LedTask(void *p_arg) | |||
| { | |||
| (void)p_arg; | |||
| uint8_t data = 0; | |||
| while (1) | |||
| { | |||
| if(HAL_UART_Receive(&huart1, &data, sizeof(data), 10) != HAL_OK) | |||
| { | |||
| // 接收超时或错误处理 | |||
| HAL_UART_Transmit(&huart1, (uint8_t *)"Receive Error\r\n", 15, 10); | |||
| } | |||
| else | |||
| { | |||
| HAL_UART_Transmit(&huart1, &data, sizeof(data), 10); | |||
| } | |||
| OSTimeDlyHMSM(0, 0, 0, 10); /* 延时10ms */ | |||
| } | |||
| } | |||
| static void KeyTask(void *p_arg) | |||
| { | |||
| (void)p_arg; | |||
| while (1) { | |||
| for(int i = 0;i < 15;i++) | |||
| { | |||
| PLSR_PWM_SetFrequency(i); | |||
| OSTimeDlyHMSM(0, 0, 0, 500); /* 延时10ms */ | |||
| } | |||
| OSTimeDlyHMSM(0, 0, 0, 10); /* 延时10ms */ | |||
| } | |||
| } | |||
| /* USER CODE END 4 */ | |||
| // HAL_TIM_PeriodElapsedCallback函数已移至timer.c文件中统一管理 | |||
| /** | |||
| * @brief This function is executed in case of error occurrence. | |||
| * @retval None | |||
| */ | |||
| void Error_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN Error_Handler_Debug */ | |||
| /* User can add his own implementation to report the HAL error return state */ | |||
| __disable_irq(); | |||
| while (1) | |||
| { | |||
| } | |||
| /* USER CODE END Error_Handler_Debug */ | |||
| } | |||
| #ifdef USE_FULL_ASSERT | |||
| /** | |||
| * @brief Reports the name of the source file and the source line number | |||
| * where the assert_param error has occurred. | |||
| * @param file: pointer to the source file name | |||
| * @param line: assert_param error line source number | |||
| * @retval None | |||
| */ | |||
| void assert_failed(uint8_t *file, uint32_t line) | |||
| { | |||
| /* USER CODE BEGIN 6 */ | |||
| /* User can add his own implementation to report the file name and line number, | |||
| ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |||
| /* USER CODE END 6 */ | |||
| } | |||
| #endif /* USE_FULL_ASSERT */ | |||
| @@ -0,0 +1,84 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file stm32f4xx_hal_msp.c | |||
| * @brief This file provides code for the MSP Initialization | |||
| * and de-Initialization codes. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "main.h" | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| /* Private typedef -----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN TD */ | |||
| /* USER CODE END TD */ | |||
| /* Private define ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Define */ | |||
| /* USER CODE END Define */ | |||
| /* Private macro -------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Macro */ | |||
| /* USER CODE END Macro */ | |||
| /* Private variables ---------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PV */ | |||
| /* USER CODE END PV */ | |||
| /* Private function prototypes -----------------------------------------------*/ | |||
| /* USER CODE BEGIN PFP */ | |||
| /* USER CODE END PFP */ | |||
| /* External functions --------------------------------------------------------*/ | |||
| /* USER CODE BEGIN ExternalFunctions */ | |||
| /* USER CODE END ExternalFunctions */ | |||
| /* USER CODE BEGIN 0 */ | |||
| /* USER CODE END 0 */ | |||
| /** | |||
| * Initializes the Global MSP. | |||
| */ | |||
| void HAL_MspInit(void) | |||
| { | |||
| /* USER CODE BEGIN MspInit 0 */ | |||
| /* USER CODE END MspInit 0 */ | |||
| __HAL_RCC_SYSCFG_CLK_ENABLE(); | |||
| __HAL_RCC_PWR_CLK_ENABLE(); | |||
| /* System interrupt init*/ | |||
| /* PendSV_IRQn interrupt configuration */ | |||
| HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); | |||
| /* USER CODE BEGIN MspInit 1 */ | |||
| /* USER CODE END MspInit 1 */ | |||
| } | |||
| /* USER CODE BEGIN 1 */ | |||
| /* USER CODE END 1 */ | |||
| @@ -0,0 +1,128 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file stm32f4xx_hal_timebase_tim.c | |||
| * @brief HAL time base based on the hardware TIM. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "stm32f4xx_hal.h" | |||
| #include "stm32f4xx_hal_tim.h" | |||
| /* Private typedef -----------------------------------------------------------*/ | |||
| /* Private define ------------------------------------------------------------*/ | |||
| /* Private macro -------------------------------------------------------------*/ | |||
| /* Private variables ---------------------------------------------------------*/ | |||
| TIM_HandleTypeDef htim1; | |||
| /* Private function prototypes -----------------------------------------------*/ | |||
| /* Private functions ---------------------------------------------------------*/ | |||
| /** | |||
| * @brief This function configures the TIM1 as a time base source. | |||
| * The time source is configured to have 1ms time base with a dedicated | |||
| * Tick interrupt priority. | |||
| * @note This function is called automatically at the beginning of program after | |||
| * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). | |||
| * @param TickPriority: Tick interrupt priority. | |||
| * @retval HAL status | |||
| */ | |||
| HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) | |||
| { | |||
| RCC_ClkInitTypeDef clkconfig; | |||
| uint32_t uwTimclock = 0U; | |||
| uint32_t uwPrescalerValue = 0U; | |||
| uint32_t pFLatency; | |||
| HAL_StatusTypeDef status; | |||
| /* Enable TIM1 clock */ | |||
| __HAL_RCC_TIM1_CLK_ENABLE(); | |||
| /* Get clock configuration */ | |||
| HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); | |||
| /* Compute TIM1 clock */ | |||
| uwTimclock = 2*HAL_RCC_GetPCLK2Freq(); | |||
| /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ | |||
| uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); | |||
| /* Initialize TIM1 */ | |||
| htim1.Instance = TIM1; | |||
| /* Initialize TIMx peripheral as follow: | |||
| * Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. | |||
| * Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. | |||
| * ClockDivision = 0 | |||
| * Counter direction = Up | |||
| */ | |||
| htim1.Init.Period = (1000000U / 1000U) - 1U; | |||
| htim1.Init.Prescaler = uwPrescalerValue; | |||
| htim1.Init.ClockDivision = 0; | |||
| htim1.Init.CounterMode = TIM_COUNTERMODE_UP; | |||
| htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; | |||
| status = HAL_TIM_Base_Init(&htim1); | |||
| if (status == HAL_OK) | |||
| { | |||
| /* Start the TIM time Base generation in interrupt mode */ | |||
| status = HAL_TIM_Base_Start_IT(&htim1); | |||
| if (status == HAL_OK) | |||
| { | |||
| /* Enable the TIM1 global Interrupt */ | |||
| HAL_NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn); | |||
| /* Configure the SysTick IRQ priority */ | |||
| if (TickPriority < (1UL << __NVIC_PRIO_BITS)) | |||
| { | |||
| /* Configure the TIM IRQ priority */ | |||
| HAL_NVIC_SetPriority(TIM1_UP_TIM10_IRQn, TickPriority, 0U); | |||
| uwTickPrio = TickPriority; | |||
| } | |||
| else | |||
| { | |||
| status = HAL_ERROR; | |||
| } | |||
| } | |||
| } | |||
| /* Return function status */ | |||
| return status; | |||
| } | |||
| /** | |||
| * @brief Suspend Tick increment. | |||
| * @note Disable the tick increment by disabling TIM1 update interrupt. | |||
| * @param None | |||
| * @retval None | |||
| */ | |||
| void HAL_SuspendTick(void) | |||
| { | |||
| /* Disable TIM1 update Interrupt */ | |||
| __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); | |||
| } | |||
| /** | |||
| * @brief Resume Tick increment. | |||
| * @note Enable the tick increment by Enabling TIM1 update interrupt. | |||
| * @param None | |||
| * @retval None | |||
| */ | |||
| void HAL_ResumeTick(void) | |||
| { | |||
| /* Enable TIM1 Update interrupt */ | |||
| __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); | |||
| } | |||
| @@ -0,0 +1,281 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file stm32f4xx_it.c | |||
| * @brief Interrupt Service Routines. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "main.h" | |||
| #include "stm32f4xx_it.h" | |||
| /* Private includes ----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Includes */ | |||
| #include "ucos_ii.h" | |||
| /* USER CODE END Includes */ | |||
| /* Private typedef -----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN TD */ | |||
| /* USER CODE END TD */ | |||
| /* Private define ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PD */ | |||
| /* USER CODE END PD */ | |||
| /* Private macro -------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PM */ | |||
| /* USER CODE END PM */ | |||
| /* Private variables ---------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PV */ | |||
| /* External variables --------------------------------------------------------*/ | |||
| extern TIM_HandleTypeDef htim6; | |||
| extern TIM_HandleTypeDef htim10; | |||
| extern DMA_HandleTypeDef hdma_usart1_rx; | |||
| extern DMA_HandleTypeDef hdma_usart1_tx; | |||
| extern UART_HandleTypeDef huart1; | |||
| extern TIM_HandleTypeDef htim1; | |||
| /* USER CODE END PV */ | |||
| /* Private function prototypes -----------------------------------------------*/ | |||
| /* USER CODE BEGIN PFP */ | |||
| /* USER CODE END PFP */ | |||
| /* Private user code ---------------------------------------------------------*/ | |||
| /* USER CODE BEGIN 0 */ | |||
| /* USER CODE END 0 */ | |||
| /* External variables --------------------------------------------------------*/ | |||
| /* USER CODE BEGIN EV */ | |||
| /* USER CODE END EV */ | |||
| /******************************************************************************/ | |||
| /* Cortex-M4 Processor Interruption and Exception Handlers */ | |||
| /******************************************************************************/ | |||
| /** | |||
| * @brief This function handles Non maskable interrupt. | |||
| */ | |||
| void NMI_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ | |||
| /* USER CODE END NonMaskableInt_IRQn 0 */ | |||
| /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ | |||
| while (1) | |||
| { | |||
| } | |||
| /* USER CODE END NonMaskableInt_IRQn 1 */ | |||
| } | |||
| /** | |||
| * @brief This function handles Hard fault interrupt. | |||
| */ | |||
| void HardFault_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN HardFault_IRQn 0 */ | |||
| /* USER CODE END HardFault_IRQn 0 */ | |||
| while (1) | |||
| { | |||
| /* USER CODE BEGIN W1_HardFault_IRQn 0 */ | |||
| /* USER CODE END W1_HardFault_IRQn 0 */ | |||
| } | |||
| } | |||
| /** | |||
| * @brief This function handles Memory management fault. | |||
| */ | |||
| void MemManage_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN MemoryManagement_IRQn 0 */ | |||
| /* USER CODE END MemoryManagement_IRQn 0 */ | |||
| while (1) | |||
| { | |||
| /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ | |||
| /* USER CODE END W1_MemoryManagement_IRQn 0 */ | |||
| } | |||
| } | |||
| /** | |||
| * @brief This function handles Pre-fetch fault, memory access fault. | |||
| */ | |||
| void BusFault_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN BusFault_IRQn 0 */ | |||
| /* USER CODE END BusFault_IRQn 0 */ | |||
| while (1) | |||
| { | |||
| /* USER CODE BEGIN W1_BusFault_IRQn 0 */ | |||
| /* USER CODE END W1_BusFault_IRQn 0 */ | |||
| } | |||
| } | |||
| /** | |||
| * @brief This function handles Undefined instruction or illegal state. | |||
| */ | |||
| void UsageFault_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN UsageFault_IRQn 0 */ | |||
| /* USER CODE END UsageFault_IRQn 0 */ | |||
| while (1) | |||
| { | |||
| /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ | |||
| /* USER CODE END W1_UsageFault_IRQn 0 */ | |||
| } | |||
| } | |||
| /** | |||
| * @brief This function handles System service call via SWI instruction. | |||
| */ | |||
| void SVC_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN SVCall_IRQn 0 */ | |||
| /* USER CODE END SVCall_IRQn 0 */ | |||
| /* USER CODE BEGIN SVCall_IRQn 1 */ | |||
| /* USER CODE END SVCall_IRQn 1 */ | |||
| } | |||
| /** | |||
| * @brief This function handles Debug monitor. | |||
| */ | |||
| void DebugMon_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN DebugMonitor_IRQn 0 */ | |||
| /* USER CODE END DebugMonitor_IRQn 0 */ | |||
| /* USER CODE BEGIN DebugMonitor_IRQn 1 */ | |||
| /* USER CODE END DebugMonitor_IRQn 1 */ | |||
| } | |||
| /** | |||
| * @brief This function handles Pendable request for system service. | |||
| */ | |||
| void PendSV_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN PendSV_IRQn 0 */ | |||
| /* USER CODE END PendSV_IRQn 0 */ | |||
| /* USER CODE BEGIN PendSV_IRQn 1 */ | |||
| OS_CPU_PendSVHandler(); | |||
| /* USER CODE END PendSV_IRQn 1 */ | |||
| } | |||
| /** | |||
| * @brief This function handles System tick timer. | |||
| */ | |||
| void SysTick_Handler(void) | |||
| { | |||
| /* USER CODE BEGIN SysTick_IRQn 0 */ | |||
| /* USER CODE END SysTick_IRQn 0 */ | |||
| /* USER CODE BEGIN SysTick_IRQn 1 */ | |||
| OS_CPU_SysTickHandler(); | |||
| /* USER CODE END SysTick_IRQn 1 */ | |||
| } | |||
| /******************************************************************************/ | |||
| /* STM32F4xx Peripheral Interrupt Handlers */ | |||
| /* Add here the Interrupt Handlers for the used peripherals. */ | |||
| /* For the available peripheral interrupt handler names, */ | |||
| /* please refer to the startup file (startup_stm32f4xx.s). */ | |||
| /******************************************************************************/ | |||
| /** | |||
| * @brief This function handles TIM1 update interrupt and TIM10 global interrupt. | |||
| */ | |||
| void TIM1_UP_TIM10_IRQHandler(void) | |||
| { | |||
| /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */ | |||
| /* USER CODE END TIM1_UP_TIM10_IRQn 0 */ | |||
| HAL_TIM_IRQHandler(&htim1); | |||
| HAL_TIM_IRQHandler(&htim10); | |||
| /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */ | |||
| /* USER CODE END TIM1_UP_TIM10_IRQn 1 */ | |||
| } | |||
| /** | |||
| * @brief This function handles USART1 global interrupt. | |||
| */ | |||
| void USART1_IRQHandler(void) | |||
| { | |||
| /* USER CODE BEGIN USART1_IRQn 0 */ | |||
| /* USER CODE END USART1_IRQn 0 */ | |||
| HAL_UART_IRQHandler(&huart1); | |||
| /* USER CODE BEGIN USART1_IRQn 1 */ | |||
| /* USER CODE END USART1_IRQn 1 */ | |||
| } | |||
| /** | |||
| * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts. | |||
| */ | |||
| void TIM6_DAC_IRQHandler(void) | |||
| { | |||
| /* USER CODE BEGIN TIM6_DAC_IRQn 0 */ | |||
| /* USER CODE END TIM6_DAC_IRQn 0 */ | |||
| HAL_TIM_IRQHandler(&htim6); | |||
| /* USER CODE BEGIN TIM6_DAC_IRQn 1 */ | |||
| /* USER CODE END TIM6_DAC_IRQn 1 */ | |||
| } | |||
| /** | |||
| * @brief This function handles DMA2 stream2 global interrupt. | |||
| */ | |||
| void DMA2_Stream2_IRQHandler(void) | |||
| { | |||
| /* USER CODE BEGIN DMA2_Stream2_IRQn 0 */ | |||
| /* USER CODE END DMA2_Stream2_IRQn 0 */ | |||
| HAL_DMA_IRQHandler(&hdma_usart1_rx); | |||
| /* USER CODE BEGIN DMA2_Stream2_IRQn 1 */ | |||
| /* USER CODE END DMA2_Stream2_IRQn 1 */ | |||
| } | |||
| /** | |||
| * @brief This function handles DMA2 stream7 global interrupt. | |||
| */ | |||
| void DMA2_Stream7_IRQHandler(void) | |||
| { | |||
| /* USER CODE BEGIN DMA2_Stream7_IRQn 0 */ | |||
| /* USER CODE END DMA2_Stream7_IRQn 0 */ | |||
| HAL_DMA_IRQHandler(&hdma_usart1_tx); | |||
| /* USER CODE BEGIN DMA2_Stream7_IRQn 1 */ | |||
| /* USER CODE END DMA2_Stream7_IRQn 1 */ | |||
| } | |||
| /* USER CODE BEGIN 1 */ | |||
| /* USER CODE END 1 */ | |||
| @@ -0,0 +1,747 @@ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file system_stm32f4xx.c | |||
| * @author MCD Application Team | |||
| * @brief CMSIS Cortex-M4 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_stm32f4xx.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 | |||
| * | |||
| * 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /** @addtogroup CMSIS | |||
| * @{ | |||
| */ | |||
| /** @addtogroup stm32f4xx_system | |||
| * @{ | |||
| */ | |||
| /** @addtogroup STM32F4xx_System_Private_Includes | |||
| * @{ | |||
| */ | |||
| #include "stm32f4xx.h" | |||
| #if !defined (HSE_VALUE) | |||
| #define HSE_VALUE ((uint32_t)12000000) /*!< Default value of the External oscillator in Hz */ | |||
| #endif /* HSE_VALUE */ | |||
| #if !defined (HSI_VALUE) | |||
| #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ | |||
| #endif /* HSI_VALUE */ | |||
| /** | |||
| * @} | |||
| */ | |||
| /** @addtogroup STM32F4xx_System_Private_TypesDefinitions | |||
| * @{ | |||
| */ | |||
| /** | |||
| * @} | |||
| */ | |||
| /** @addtogroup STM32F4xx_System_Private_Defines | |||
| * @{ | |||
| */ | |||
| /************************* Miscellaneous Configuration ************************/ | |||
| /*!< Uncomment the following line if you need to use external SRAM or SDRAM as data memory */ | |||
| #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)\ | |||
| || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ | |||
| || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) | |||
| /* #define DATA_IN_ExtSRAM */ | |||
| #endif /* STM32F40xxx || STM32F41xxx || STM32F42xxx || STM32F43xxx || STM32F469xx || STM32F479xx ||\ | |||
| STM32F412Zx || STM32F412Vx */ | |||
| #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ | |||
| || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) | |||
| /* #define DATA_IN_ExtSDRAM */ | |||
| #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\ | |||
| STM32F479xx */ | |||
| /* Note: Following vector table addresses must be defined in line with linker | |||
| configuration. */ | |||
| /*!< Uncomment the following line if you need to relocate the vector table | |||
| anywhere in Flash or Sram, else the vector table is kept at the automatic | |||
| remap of boot address selected */ | |||
| /* #define USER_VECT_TAB_ADDRESS */ | |||
| #if defined(USER_VECT_TAB_ADDRESS) | |||
| /*!< Uncomment the following line if you need to relocate your vector Table | |||
| in Sram else user remap will be done in Flash. */ | |||
| /* #define VECT_TAB_SRAM */ | |||
| #if defined(VECT_TAB_SRAM) | |||
| #define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field. | |||
| This value must be a multiple of 0x200. */ | |||
| #else | |||
| #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. | |||
| This value must be a multiple of 0x200. */ | |||
| #endif /* VECT_TAB_SRAM */ | |||
| #if !defined(VECT_TAB_OFFSET) | |||
| #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table offset field. | |||
| This value must be a multiple of 0x200. */ | |||
| #endif /* VECT_TAB_OFFSET */ | |||
| #endif /* USER_VECT_TAB_ADDRESS */ | |||
| /******************************************************************************/ | |||
| /** | |||
| * @} | |||
| */ | |||
| /** @addtogroup STM32F4xx_System_Private_Macros | |||
| * @{ | |||
| */ | |||
| /** | |||
| * @} | |||
| */ | |||
| /** @addtogroup STM32F4xx_System_Private_Variables | |||
| * @{ | |||
| */ | |||
| /* 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 | |||
| 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 = 16000000; | |||
| const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; | |||
| const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; | |||
| /** | |||
| * @} | |||
| */ | |||
| /** @addtogroup STM32F4xx_System_Private_FunctionPrototypes | |||
| * @{ | |||
| */ | |||
| #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM) | |||
| static void SystemInit_ExtMemCtl(void); | |||
| #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */ | |||
| /** | |||
| * @} | |||
| */ | |||
| /** @addtogroup STM32F4xx_System_Private_Functions | |||
| * @{ | |||
| */ | |||
| /** | |||
| * @brief Setup the microcontroller system | |||
| * Initialize the FPU setting, vector table location and External memory | |||
| * configuration. | |||
| * @param None | |||
| * @retval None | |||
| */ | |||
| void SystemInit(void) | |||
| { | |||
| /* FPU settings ------------------------------------------------------------*/ | |||
| #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) | |||
| SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ | |||
| #endif | |||
| #if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM) | |||
| SystemInit_ExtMemCtl(); | |||
| #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */ | |||
| /* Configure the Vector Table location -------------------------------------*/ | |||
| #if defined(USER_VECT_TAB_ADDRESS) | |||
| SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ | |||
| #endif /* USER_VECT_TAB_ADDRESS */ | |||
| } | |||
| /** | |||
| * @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 stm32f4xx_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 stm32f4xx_hal_conf.h file (its value | |||
| * depends on the application requirements), 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. | |||
| * | |||
| * @param None | |||
| * @retval None | |||
| */ | |||
| void SystemCoreClockUpdate(void) | |||
| { | |||
| uint32_t tmp, pllvco, pllp, pllsource, pllm; | |||
| /* Get SYSCLK source -------------------------------------------------------*/ | |||
| tmp = RCC->CFGR & RCC_CFGR_SWS; | |||
| switch (tmp) | |||
| { | |||
| case 0x00: /* HSI used as system clock source */ | |||
| SystemCoreClock = HSI_VALUE; | |||
| break; | |||
| case 0x04: /* HSE used as system clock source */ | |||
| SystemCoreClock = HSE_VALUE; | |||
| break; | |||
| case 0x08: /* PLL used as system clock source */ | |||
| /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N | |||
| SYSCLK = PLL_VCO / PLL_P | |||
| */ | |||
| pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22; | |||
| pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM; | |||
| if (pllsource != 0) | |||
| { | |||
| /* HSE used as PLL clock source */ | |||
| pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); | |||
| } | |||
| else | |||
| { | |||
| /* HSI used as PLL clock source */ | |||
| pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); | |||
| } | |||
| pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2; | |||
| SystemCoreClock = pllvco/pllp; | |||
| break; | |||
| default: | |||
| SystemCoreClock = HSI_VALUE; | |||
| break; | |||
| } | |||
| /* Compute HCLK frequency --------------------------------------------------*/ | |||
| /* Get HCLK prescaler */ | |||
| tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; | |||
| /* HCLK frequency */ | |||
| SystemCoreClock >>= tmp; | |||
| } | |||
| #if defined (DATA_IN_ExtSRAM) && defined (DATA_IN_ExtSDRAM) | |||
| #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ | |||
| || defined(STM32F469xx) || defined(STM32F479xx) | |||
| /** | |||
| * @brief Setup the external memory controller. | |||
| * Called in startup_stm32f4xx.s before jump to main. | |||
| * This function configures the external memories (SRAM/SDRAM) | |||
| * This SRAM/SDRAM will be used as program data memory (including heap and stack). | |||
| * @param None | |||
| * @retval None | |||
| */ | |||
| void SystemInit_ExtMemCtl(void) | |||
| { | |||
| __IO uint32_t tmp = 0x00; | |||
| register uint32_t tmpreg = 0, timeout = 0xFFFF; | |||
| register __IO uint32_t index; | |||
| /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface clock */ | |||
| RCC->AHB1ENR |= 0x000001F8; | |||
| /* Delay after an RCC peripheral clock enabling */ | |||
| tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN); | |||
| /* Connect PDx pins to FMC Alternate function */ | |||
| GPIOD->AFR[0] = 0x00CCC0CC; | |||
| GPIOD->AFR[1] = 0xCCCCCCCC; | |||
| /* Configure PDx pins in Alternate function mode */ | |||
| GPIOD->MODER = 0xAAAA0A8A; | |||
| /* Configure PDx pins speed to 100 MHz */ | |||
| GPIOD->OSPEEDR = 0xFFFF0FCF; | |||
| /* Configure PDx pins Output type to push-pull */ | |||
| GPIOD->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PDx pins */ | |||
| GPIOD->PUPDR = 0x00000000; | |||
| /* Connect PEx pins to FMC Alternate function */ | |||
| GPIOE->AFR[0] = 0xC00CC0CC; | |||
| GPIOE->AFR[1] = 0xCCCCCCCC; | |||
| /* Configure PEx pins in Alternate function mode */ | |||
| GPIOE->MODER = 0xAAAA828A; | |||
| /* Configure PEx pins speed to 100 MHz */ | |||
| GPIOE->OSPEEDR = 0xFFFFC3CF; | |||
| /* Configure PEx pins Output type to push-pull */ | |||
| GPIOE->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PEx pins */ | |||
| GPIOE->PUPDR = 0x00000000; | |||
| /* Connect PFx pins to FMC Alternate function */ | |||
| GPIOF->AFR[0] = 0xCCCCCCCC; | |||
| GPIOF->AFR[1] = 0xCCCCCCCC; | |||
| /* 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 = 0x00000000; | |||
| /* Connect PGx pins to FMC Alternate function */ | |||
| GPIOG->AFR[0] = 0xCCCCCCCC; | |||
| GPIOG->AFR[1] = 0xCCCCCCCC; | |||
| /* Configure PGx pins in Alternate function mode */ | |||
| GPIOG->MODER = 0xAAAAAAAA; | |||
| /* Configure PGx pins speed to 50 MHz */ | |||
| GPIOG->OSPEEDR = 0xAAAAAAAA; | |||
| /* Configure PGx pins Output type to push-pull */ | |||
| GPIOG->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PGx pins */ | |||
| GPIOG->PUPDR = 0x00000000; | |||
| /* Connect PHx pins to FMC Alternate function */ | |||
| GPIOH->AFR[0] = 0x00C0CC00; | |||
| GPIOH->AFR[1] = 0xCCCCCCCC; | |||
| /* Configure PHx pins in Alternate function mode */ | |||
| GPIOH->MODER = 0xAAAA08A0; | |||
| /* Configure PHx pins speed to 50 MHz */ | |||
| GPIOH->OSPEEDR = 0xAAAA08A0; | |||
| /* Configure PHx pins Output type to push-pull */ | |||
| GPIOH->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PHx pins */ | |||
| GPIOH->PUPDR = 0x00000000; | |||
| /* Connect PIx pins to FMC Alternate function */ | |||
| GPIOI->AFR[0] = 0xCCCCCCCC; | |||
| GPIOI->AFR[1] = 0x00000CC0; | |||
| /* Configure PIx pins in Alternate function mode */ | |||
| GPIOI->MODER = 0x0028AAAA; | |||
| /* Configure PIx pins speed to 50 MHz */ | |||
| GPIOI->OSPEEDR = 0x0028AAAA; | |||
| /* Configure PIx pins Output type to push-pull */ | |||
| GPIOI->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PIx pins */ | |||
| GPIOI->PUPDR = 0x00000000; | |||
| /*-- FMC Configuration -------------------------------------------------------*/ | |||
| /* Enable the FMC interface clock */ | |||
| RCC->AHB3ENR |= 0x00000001; | |||
| /* Delay after an RCC peripheral clock enabling */ | |||
| tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN); | |||
| FMC_Bank5_6->SDCR[0] = 0x000019E4; | |||
| 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)) | |||
| { | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| } | |||
| /* Delay */ | |||
| for (index = 0; index<1000; index++); | |||
| /* PALL command */ | |||
| FMC_Bank5_6->SDCMR = 0x00000012; | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| timeout = 0xFFFF; | |||
| while((tmpreg != 0) && (timeout-- > 0)) | |||
| { | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| } | |||
| /* Auto refresh command */ | |||
| FMC_Bank5_6->SDCMR = 0x00000073; | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| timeout = 0xFFFF; | |||
| while((tmpreg != 0) && (timeout-- > 0)) | |||
| { | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| } | |||
| /* MRD register program */ | |||
| FMC_Bank5_6->SDCMR = 0x00046014; | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| 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 | (0x0000027C<<1)); | |||
| /* Disable write protection */ | |||
| tmpreg = FMC_Bank5_6->SDCR[0]; | |||
| FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF); | |||
| #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) | |||
| /* Configure and enable Bank1_SRAM2 */ | |||
| FMC_Bank1->BTCR[2] = 0x00001011; | |||
| FMC_Bank1->BTCR[3] = 0x00000201; | |||
| FMC_Bank1E->BWTR[2] = 0x0fffffff; | |||
| #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ | |||
| #if defined(STM32F469xx) || defined(STM32F479xx) | |||
| /* Configure and enable Bank1_SRAM2 */ | |||
| FMC_Bank1->BTCR[2] = 0x00001091; | |||
| FMC_Bank1->BTCR[3] = 0x00110212; | |||
| FMC_Bank1E->BWTR[2] = 0x0fffffff; | |||
| #endif /* STM32F469xx || STM32F479xx */ | |||
| (void)(tmp); | |||
| } | |||
| #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ | |||
| #elif defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM) | |||
| /** | |||
| * @brief Setup the external memory controller. | |||
| * Called in startup_stm32f4xx.s before jump to main. | |||
| * This function configures the external memories (SRAM/SDRAM) | |||
| * This SRAM/SDRAM will be used as program data memory (including heap and stack). | |||
| * @param None | |||
| * @retval None | |||
| */ | |||
| void SystemInit_ExtMemCtl(void) | |||
| { | |||
| __IO uint32_t tmp = 0x00; | |||
| #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ | |||
| || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) | |||
| #if defined (DATA_IN_ExtSDRAM) | |||
| register uint32_t tmpreg = 0, timeout = 0xFFFF; | |||
| register __IO uint32_t index; | |||
| #if defined(STM32F446xx) | |||
| /* Enable GPIOA, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG interface | |||
| clock */ | |||
| RCC->AHB1ENR |= 0x0000007D; | |||
| #else | |||
| /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface | |||
| clock */ | |||
| RCC->AHB1ENR |= 0x000001F8; | |||
| #endif /* STM32F446xx */ | |||
| /* Delay after an RCC peripheral clock enabling */ | |||
| tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN); | |||
| #if defined(STM32F446xx) | |||
| /* Connect PAx pins to FMC Alternate function */ | |||
| GPIOA->AFR[0] |= 0xC0000000; | |||
| GPIOA->AFR[1] |= 0x00000000; | |||
| /* Configure PDx pins in Alternate function mode */ | |||
| GPIOA->MODER |= 0x00008000; | |||
| /* Configure PDx pins speed to 50 MHz */ | |||
| GPIOA->OSPEEDR |= 0x00008000; | |||
| /* Configure PDx pins Output type to push-pull */ | |||
| GPIOA->OTYPER |= 0x00000000; | |||
| /* No pull-up, pull-down for PDx pins */ | |||
| GPIOA->PUPDR |= 0x00000000; | |||
| /* Connect PCx pins to FMC Alternate function */ | |||
| GPIOC->AFR[0] |= 0x00CC0000; | |||
| GPIOC->AFR[1] |= 0x00000000; | |||
| /* Configure PDx pins in Alternate function mode */ | |||
| GPIOC->MODER |= 0x00000A00; | |||
| /* Configure PDx pins speed to 50 MHz */ | |||
| GPIOC->OSPEEDR |= 0x00000A00; | |||
| /* Configure PDx pins Output type to push-pull */ | |||
| GPIOC->OTYPER |= 0x00000000; | |||
| /* No pull-up, pull-down for PDx pins */ | |||
| GPIOC->PUPDR |= 0x00000000; | |||
| #endif /* STM32F446xx */ | |||
| /* 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 = 0x00000000; | |||
| /* 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 = 0x00000000; | |||
| /* Connect PFx pins to FMC Alternate function */ | |||
| GPIOF->AFR[0] = 0xCCCCCCCC; | |||
| GPIOF->AFR[1] = 0xCCCCCCCC; | |||
| /* 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 = 0x00000000; | |||
| /* Connect PGx pins to FMC Alternate function */ | |||
| GPIOG->AFR[0] = 0xCCCCCCCC; | |||
| GPIOG->AFR[1] = 0xCCCCCCCC; | |||
| /* Configure PGx pins in Alternate function mode */ | |||
| GPIOG->MODER = 0xAAAAAAAA; | |||
| /* Configure PGx pins speed to 50 MHz */ | |||
| GPIOG->OSPEEDR = 0xAAAAAAAA; | |||
| /* Configure PGx pins Output type to push-pull */ | |||
| GPIOG->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PGx pins */ | |||
| GPIOG->PUPDR = 0x00000000; | |||
| #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ | |||
| || defined(STM32F469xx) || defined(STM32F479xx) | |||
| /* Connect PHx pins to FMC Alternate function */ | |||
| GPIOH->AFR[0] = 0x00C0CC00; | |||
| GPIOH->AFR[1] = 0xCCCCCCCC; | |||
| /* Configure PHx pins in Alternate function mode */ | |||
| GPIOH->MODER = 0xAAAA08A0; | |||
| /* Configure PHx pins speed to 50 MHz */ | |||
| GPIOH->OSPEEDR = 0xAAAA08A0; | |||
| /* Configure PHx pins Output type to push-pull */ | |||
| GPIOH->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PHx pins */ | |||
| GPIOH->PUPDR = 0x00000000; | |||
| /* Connect PIx pins to FMC Alternate function */ | |||
| GPIOI->AFR[0] = 0xCCCCCCCC; | |||
| GPIOI->AFR[1] = 0x00000CC0; | |||
| /* Configure PIx pins in Alternate function mode */ | |||
| GPIOI->MODER = 0x0028AAAA; | |||
| /* Configure PIx pins speed to 50 MHz */ | |||
| GPIOI->OSPEEDR = 0x0028AAAA; | |||
| /* Configure PIx pins Output type to push-pull */ | |||
| GPIOI->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PIx pins */ | |||
| GPIOI->PUPDR = 0x00000000; | |||
| #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ | |||
| /*-- FMC Configuration -------------------------------------------------------*/ | |||
| /* Enable the FMC interface clock */ | |||
| RCC->AHB3ENR |= 0x00000001; | |||
| /* Delay after an RCC peripheral clock enabling */ | |||
| tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN); | |||
| /* Configure and enable SDRAM bank1 */ | |||
| #if defined(STM32F446xx) | |||
| FMC_Bank5_6->SDCR[0] = 0x00001954; | |||
| #else | |||
| FMC_Bank5_6->SDCR[0] = 0x000019E4; | |||
| #endif /* STM32F446xx */ | |||
| 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)) | |||
| { | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| } | |||
| /* Delay */ | |||
| for (index = 0; index<1000; index++); | |||
| /* PALL command */ | |||
| FMC_Bank5_6->SDCMR = 0x00000012; | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| timeout = 0xFFFF; | |||
| while((tmpreg != 0) && (timeout-- > 0)) | |||
| { | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| } | |||
| /* Auto refresh command */ | |||
| #if defined(STM32F446xx) | |||
| FMC_Bank5_6->SDCMR = 0x000000F3; | |||
| #else | |||
| FMC_Bank5_6->SDCMR = 0x00000073; | |||
| #endif /* STM32F446xx */ | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| timeout = 0xFFFF; | |||
| while((tmpreg != 0) && (timeout-- > 0)) | |||
| { | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| } | |||
| /* MRD register program */ | |||
| #if defined(STM32F446xx) | |||
| FMC_Bank5_6->SDCMR = 0x00044014; | |||
| #else | |||
| FMC_Bank5_6->SDCMR = 0x00046014; | |||
| #endif /* STM32F446xx */ | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| timeout = 0xFFFF; | |||
| while((tmpreg != 0) && (timeout-- > 0)) | |||
| { | |||
| tmpreg = FMC_Bank5_6->SDSR & 0x00000020; | |||
| } | |||
| /* Set refresh count */ | |||
| tmpreg = FMC_Bank5_6->SDRTR; | |||
| #if defined(STM32F446xx) | |||
| FMC_Bank5_6->SDRTR = (tmpreg | (0x0000050C<<1)); | |||
| #else | |||
| FMC_Bank5_6->SDRTR = (tmpreg | (0x0000027C<<1)); | |||
| #endif /* STM32F446xx */ | |||
| /* Disable write protection */ | |||
| tmpreg = FMC_Bank5_6->SDCR[0]; | |||
| FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF); | |||
| #endif /* DATA_IN_ExtSDRAM */ | |||
| #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */ | |||
| #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)\ | |||
| || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)\ | |||
| || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) | |||
| #if defined(DATA_IN_ExtSRAM) | |||
| /*-- GPIOs Configuration -----------------------------------------------------*/ | |||
| /* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */ | |||
| RCC->AHB1ENR |= 0x00000078; | |||
| /* Delay after an RCC peripheral clock enabling */ | |||
| tmp = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIODEN); | |||
| /* Connect PDx pins to FMC Alternate function */ | |||
| GPIOD->AFR[0] = 0x00CCC0CC; | |||
| GPIOD->AFR[1] = 0xCCCCCCCC; | |||
| /* Configure PDx pins in Alternate function mode */ | |||
| GPIOD->MODER = 0xAAAA0A8A; | |||
| /* Configure PDx pins speed to 100 MHz */ | |||
| GPIOD->OSPEEDR = 0xFFFF0FCF; | |||
| /* Configure PDx pins Output type to push-pull */ | |||
| GPIOD->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PDx pins */ | |||
| GPIOD->PUPDR = 0x00000000; | |||
| /* Connect PEx pins to FMC Alternate function */ | |||
| GPIOE->AFR[0] = 0xC00CC0CC; | |||
| GPIOE->AFR[1] = 0xCCCCCCCC; | |||
| /* Configure PEx pins in Alternate function mode */ | |||
| GPIOE->MODER = 0xAAAA828A; | |||
| /* Configure PEx pins speed to 100 MHz */ | |||
| GPIOE->OSPEEDR = 0xFFFFC3CF; | |||
| /* Configure PEx pins Output type to push-pull */ | |||
| GPIOE->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PEx pins */ | |||
| GPIOE->PUPDR = 0x00000000; | |||
| /* Connect PFx pins to FMC Alternate function */ | |||
| GPIOF->AFR[0] = 0x00CCCCCC; | |||
| GPIOF->AFR[1] = 0xCCCC0000; | |||
| /* Configure PFx pins in Alternate function mode */ | |||
| GPIOF->MODER = 0xAA000AAA; | |||
| /* Configure PFx pins speed to 100 MHz */ | |||
| GPIOF->OSPEEDR = 0xFF000FFF; | |||
| /* Configure PFx pins Output type to push-pull */ | |||
| GPIOF->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PFx pins */ | |||
| GPIOF->PUPDR = 0x00000000; | |||
| /* Connect PGx pins to FMC Alternate function */ | |||
| GPIOG->AFR[0] = 0x00CCCCCC; | |||
| GPIOG->AFR[1] = 0x000000C0; | |||
| /* Configure PGx pins in Alternate function mode */ | |||
| GPIOG->MODER = 0x00085AAA; | |||
| /* Configure PGx pins speed to 100 MHz */ | |||
| GPIOG->OSPEEDR = 0x000CAFFF; | |||
| /* Configure PGx pins Output type to push-pull */ | |||
| GPIOG->OTYPER = 0x00000000; | |||
| /* No pull-up, pull-down for PGx pins */ | |||
| GPIOG->PUPDR = 0x00000000; | |||
| /*-- FMC/FSMC Configuration --------------------------------------------------*/ | |||
| /* Enable the FMC/FSMC interface clock */ | |||
| RCC->AHB3ENR |= 0x00000001; | |||
| #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) | |||
| /* Delay after an RCC peripheral clock enabling */ | |||
| tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN); | |||
| /* Configure and enable Bank1_SRAM2 */ | |||
| FMC_Bank1->BTCR[2] = 0x00001011; | |||
| FMC_Bank1->BTCR[3] = 0x00000201; | |||
| FMC_Bank1E->BWTR[2] = 0x0fffffff; | |||
| #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ | |||
| #if defined(STM32F469xx) || defined(STM32F479xx) | |||
| /* Delay after an RCC peripheral clock enabling */ | |||
| tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN); | |||
| /* Configure and enable Bank1_SRAM2 */ | |||
| FMC_Bank1->BTCR[2] = 0x00001091; | |||
| FMC_Bank1->BTCR[3] = 0x00110212; | |||
| FMC_Bank1E->BWTR[2] = 0x0fffffff; | |||
| #endif /* STM32F469xx || STM32F479xx */ | |||
| #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx)\ | |||
| || defined(STM32F412Zx) || defined(STM32F412Vx) | |||
| /* Delay after an RCC peripheral clock enabling */ | |||
| tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FSMCEN); | |||
| /* Configure and enable Bank1_SRAM2 */ | |||
| FSMC_Bank1->BTCR[2] = 0x00001011; | |||
| FSMC_Bank1->BTCR[3] = 0x00000201; | |||
| FSMC_Bank1E->BWTR[2] = 0x0FFFFFFF; | |||
| #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F412Zx || STM32F412Vx */ | |||
| #endif /* DATA_IN_ExtSRAM */ | |||
| #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\ | |||
| STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Vx */ | |||
| (void)(tmp); | |||
| } | |||
| #endif /* DATA_IN_ExtSRAM && DATA_IN_ExtSDRAM */ | |||
| /** | |||
| * @} | |||
| */ | |||
| /** | |||
| * @} | |||
| */ | |||
| /** | |||
| * @} | |||
| */ | |||
| @@ -0,0 +1,162 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file usart.c | |||
| * @brief This file provides code for the configuration | |||
| * of the USART instances. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * Copyright (c) 2025 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. | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "usart.h" | |||
| /* USER CODE BEGIN 0 */ | |||
| /* USER CODE END 0 */ | |||
| UART_HandleTypeDef huart1; | |||
| DMA_HandleTypeDef hdma_usart1_rx; | |||
| DMA_HandleTypeDef hdma_usart1_tx; | |||
| /* USART1 init function */ | |||
| void MX_USART1_UART_Init(void) | |||
| { | |||
| /* USER CODE BEGIN USART1_Init 0 */ | |||
| /* USER CODE END USART1_Init 0 */ | |||
| /* USER CODE BEGIN USART1_Init 1 */ | |||
| /* USER CODE END USART1_Init 1 */ | |||
| huart1.Instance = USART1; | |||
| huart1.Init.BaudRate = 19200; | |||
| huart1.Init.WordLength = UART_WORDLENGTH_9B; | |||
| huart1.Init.StopBits = UART_STOPBITS_1; | |||
| huart1.Init.Parity = UART_PARITY_ODD; | |||
| huart1.Init.Mode = UART_MODE_TX_RX; | |||
| huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |||
| huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |||
| if (HAL_UART_Init(&huart1) != HAL_OK) | |||
| { | |||
| Error_Handler(); | |||
| } | |||
| /* USER CODE BEGIN USART1_Init 2 */ | |||
| HAL_UART_MspInit(&huart1); | |||
| /* USER CODE END USART1_Init 2 */ | |||
| } | |||
| void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) | |||
| { | |||
| GPIO_InitTypeDef GPIO_InitStruct = {0}; | |||
| if(uartHandle->Instance==USART1) | |||
| { | |||
| /* USER CODE BEGIN USART1_MspInit 0 */ | |||
| /* USER CODE END USART1_MspInit 0 */ | |||
| /* USART1 clock enable */ | |||
| __HAL_RCC_USART1_CLK_ENABLE(); | |||
| __HAL_RCC_GPIOA_CLK_ENABLE(); | |||
| /**USART1 GPIO Configuration | |||
| PA10 ------> USART1_RX | |||
| PA9 ------> USART1_TX | |||
| */ | |||
| GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_9; | |||
| GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | |||
| GPIO_InitStruct.Pull = GPIO_NOPULL; | |||
| GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | |||
| GPIO_InitStruct.Alternate = GPIO_AF7_USART1; | |||
| HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |||
| /* USART1 DMA Init */ | |||
| /* USART1_RX Init */ | |||
| hdma_usart1_rx.Instance = DMA2_Stream2; | |||
| hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4; | |||
| hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; | |||
| hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |||
| hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; | |||
| hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; | |||
| hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |||
| hdma_usart1_rx.Init.Mode = DMA_NORMAL; | |||
| hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; | |||
| hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |||
| if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK) | |||
| { | |||
| Error_Handler(); | |||
| } | |||
| __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart1_rx); | |||
| /* USART1_TX Init */ | |||
| hdma_usart1_tx.Instance = DMA2_Stream7; | |||
| hdma_usart1_tx.Init.Channel = DMA_CHANNEL_4; | |||
| hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; | |||
| hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE; | |||
| hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE; | |||
| hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; | |||
| hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |||
| hdma_usart1_tx.Init.Mode = DMA_NORMAL; | |||
| hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW; | |||
| hdma_usart1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |||
| if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK) | |||
| { | |||
| Error_Handler(); | |||
| } | |||
| __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx); | |||
| /* USART1 interrupt Init */ | |||
| HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); | |||
| HAL_NVIC_EnableIRQ(USART1_IRQn); | |||
| /* USER CODE BEGIN USART1_MspInit 1 */ | |||
| /* USER CODE END USART1_MspInit 1 */ | |||
| } | |||
| } | |||
| void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) | |||
| { | |||
| if(uartHandle->Instance==USART1) | |||
| { | |||
| /* USER CODE BEGIN USART1_MspDeInit 0 */ | |||
| /* USER CODE END USART1_MspDeInit 0 */ | |||
| /* Peripheral clock disable */ | |||
| __HAL_RCC_USART1_CLK_DISABLE(); | |||
| /**USART1 GPIO Configuration | |||
| PA10 ------> USART1_RX | |||
| PA9 ------> USART1_TX | |||
| */ | |||
| HAL_GPIO_DeInit(GPIOA, GPIO_PIN_10|GPIO_PIN_9); | |||
| /* USART1 DMA DeInit */ | |||
| HAL_DMA_DeInit(uartHandle->hdmarx); | |||
| HAL_DMA_DeInit(uartHandle->hdmatx); | |||
| /* USART1 interrupt Deinit */ | |||
| HAL_NVIC_DisableIRQ(USART1_IRQn); | |||
| /* USER CODE BEGIN USART1_MspDeInit 1 */ | |||
| /* USER CODE END USART1_MspDeInit 1 */ | |||
| } | |||
| } | |||
| /* USER CODE BEGIN 1 */ | |||
| /* USER CODE END 1 */ | |||
| @@ -0,0 +1,411 @@ | |||
| /****************************************************************************** | |||
| * @file cachel1_armv7.h | |||
| * @brief CMSIS Level 1 Cache API for Armv7-M and later | |||
| * @version V1.0.1 | |||
| * @date 19. April 2021 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2020-2021 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef ARM_CACHEL1_ARMV7_H | |||
| #define ARM_CACHEL1_ARMV7_H | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_CacheFunctions Cache Functions | |||
| \brief Functions that configure Instruction and Data cache. | |||
| @{ | |||
| */ | |||
| /* Cache Size ID Register Macros */ | |||
| #define CCSIDR_WAYS(x) (((x) & SCB_CCSIDR_ASSOCIATIVITY_Msk) >> SCB_CCSIDR_ASSOCIATIVITY_Pos) | |||
| #define CCSIDR_SETS(x) (((x) & SCB_CCSIDR_NUMSETS_Msk ) >> SCB_CCSIDR_NUMSETS_Pos ) | |||
| #ifndef __SCB_DCACHE_LINE_SIZE | |||
| #define __SCB_DCACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ | |||
| #endif | |||
| #ifndef __SCB_ICACHE_LINE_SIZE | |||
| #define __SCB_ICACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ | |||
| #endif | |||
| /** | |||
| \brief Enable I-Cache | |||
| \details Turns on I-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_EnableICache (void) | |||
| { | |||
| #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) | |||
| if (SCB->CCR & SCB_CCR_IC_Msk) return; /* return if ICache is already enabled */ | |||
| __DSB(); | |||
| __ISB(); | |||
| SCB->ICIALLU = 0UL; /* invalidate I-Cache */ | |||
| __DSB(); | |||
| __ISB(); | |||
| SCB->CCR |= (uint32_t)SCB_CCR_IC_Msk; /* enable I-Cache */ | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Disable I-Cache | |||
| \details Turns off I-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_DisableICache (void) | |||
| { | |||
| #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) | |||
| __DSB(); | |||
| __ISB(); | |||
| SCB->CCR &= ~(uint32_t)SCB_CCR_IC_Msk; /* disable I-Cache */ | |||
| SCB->ICIALLU = 0UL; /* invalidate I-Cache */ | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Invalidate I-Cache | |||
| \details Invalidates I-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_InvalidateICache (void) | |||
| { | |||
| #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) | |||
| __DSB(); | |||
| __ISB(); | |||
| SCB->ICIALLU = 0UL; | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief I-Cache Invalidate by address | |||
| \details Invalidates I-Cache for the given address. | |||
| I-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. | |||
| I-Cache memory blocks which are part of given address + given size are invalidated. | |||
| \param[in] addr address | |||
| \param[in] isize size of memory block (in number of bytes) | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_InvalidateICache_by_Addr (volatile void *addr, int32_t isize) | |||
| { | |||
| #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) | |||
| if ( isize > 0 ) { | |||
| int32_t op_size = isize + (((uint32_t)addr) & (__SCB_ICACHE_LINE_SIZE - 1U)); | |||
| uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_ICACHE_LINE_SIZE - 1U) */; | |||
| __DSB(); | |||
| do { | |||
| SCB->ICIMVAU = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ | |||
| op_addr += __SCB_ICACHE_LINE_SIZE; | |||
| op_size -= __SCB_ICACHE_LINE_SIZE; | |||
| } while ( op_size > 0 ); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Enable D-Cache | |||
| \details Turns on D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_EnableDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| if (SCB->CCR & SCB_CCR_DC_Msk) return; /* return if DCache is already enabled */ | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* invalidate D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | | |||
| ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| SCB->CCR |= (uint32_t)SCB_CCR_DC_Msk; /* enable D-Cache */ | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Disable D-Cache | |||
| \details Turns off D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_DisableDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| SCB->CCR &= ~(uint32_t)SCB_CCR_DC_Msk; /* disable D-Cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* clean & invalidate D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | | |||
| ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Invalidate D-Cache | |||
| \details Invalidates D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_InvalidateDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* invalidate D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | | |||
| ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Clean D-Cache | |||
| \details Cleans D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_CleanDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* clean D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCCSW = (((sets << SCB_DCCSW_SET_Pos) & SCB_DCCSW_SET_Msk) | | |||
| ((ways << SCB_DCCSW_WAY_Pos) & SCB_DCCSW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Clean & Invalidate D-Cache | |||
| \details Cleans and Invalidates D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_CleanInvalidateDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* clean & invalidate D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | | |||
| ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief D-Cache Invalidate by address | |||
| \details Invalidates D-Cache for the given address. | |||
| D-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. | |||
| D-Cache memory blocks which are part of given address + given size are invalidated. | |||
| \param[in] addr address | |||
| \param[in] dsize size of memory block (in number of bytes) | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_InvalidateDCache_by_Addr (volatile void *addr, int32_t dsize) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| if ( dsize > 0 ) { | |||
| int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); | |||
| uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; | |||
| __DSB(); | |||
| do { | |||
| SCB->DCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ | |||
| op_addr += __SCB_DCACHE_LINE_SIZE; | |||
| op_size -= __SCB_DCACHE_LINE_SIZE; | |||
| } while ( op_size > 0 ); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| } | |||
| /** | |||
| \brief D-Cache Clean by address | |||
| \details Cleans D-Cache for the given address | |||
| D-Cache is cleaned starting from a 32 byte aligned address in 32 byte granularity. | |||
| D-Cache memory blocks which are part of given address + given size are cleaned. | |||
| \param[in] addr address | |||
| \param[in] dsize size of memory block (in number of bytes) | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_CleanDCache_by_Addr (volatile void *addr, int32_t dsize) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| if ( dsize > 0 ) { | |||
| int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); | |||
| uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; | |||
| __DSB(); | |||
| do { | |||
| SCB->DCCMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ | |||
| op_addr += __SCB_DCACHE_LINE_SIZE; | |||
| op_size -= __SCB_DCACHE_LINE_SIZE; | |||
| } while ( op_size > 0 ); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| } | |||
| /** | |||
| \brief D-Cache Clean and Invalidate by address | |||
| \details Cleans and invalidates D_Cache for the given address | |||
| D-Cache is cleaned and invalidated starting from a 32 byte aligned address in 32 byte granularity. | |||
| D-Cache memory blocks which are part of given address + given size are cleaned and invalidated. | |||
| \param[in] addr address (aligned to 32-byte boundary) | |||
| \param[in] dsize size of memory block (in number of bytes) | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_CleanInvalidateDCache_by_Addr (volatile void *addr, int32_t dsize) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| if ( dsize > 0 ) { | |||
| int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); | |||
| uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; | |||
| __DSB(); | |||
| do { | |||
| SCB->DCCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ | |||
| op_addr += __SCB_DCACHE_LINE_SIZE; | |||
| op_size -= __SCB_DCACHE_LINE_SIZE; | |||
| } while ( op_size > 0 ); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| } | |||
| /*@} end of CMSIS_Core_CacheFunctions */ | |||
| #endif /* ARM_CACHEL1_ARMV7_H */ | |||
| @@ -0,0 +1,888 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_armcc.h | |||
| * @brief CMSIS compiler ARMCC (Arm Compiler 5) header file | |||
| * @version V5.3.2 | |||
| * @date 27. May 2021 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2021 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef __CMSIS_ARMCC_H | |||
| #define __CMSIS_ARMCC_H | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677) | |||
| #error "Please use Arm Compiler Toolchain V4.0.677 or later!" | |||
| #endif | |||
| /* CMSIS compiler control architecture macros */ | |||
| #if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \ | |||
| (defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) ) | |||
| #define __ARM_ARCH_6M__ 1 | |||
| #endif | |||
| #if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) | |||
| #define __ARM_ARCH_7M__ 1 | |||
| #endif | |||
| #if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) | |||
| #define __ARM_ARCH_7EM__ 1 | |||
| #endif | |||
| /* __ARM_ARCH_8M_BASE__ not applicable */ | |||
| /* __ARM_ARCH_8M_MAIN__ not applicable */ | |||
| /* __ARM_ARCH_8_1M_MAIN__ not applicable */ | |||
| /* CMSIS compiler control DSP macros */ | |||
| #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| #define __ARM_FEATURE_DSP 1 | |||
| #endif | |||
| /* CMSIS compiler specific defines */ | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE __inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static __inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE static __forceinline | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __declspec(noreturn) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed)) | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT __packed struct | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #define __PACKED_UNION __packed union | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x))) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| #define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr))) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| #define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr))) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #define __RESTRICT __restrict | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #define __COMPILER_BARRIER() __memory_changed() | |||
| #endif | |||
| /* ######################### Startup and Lowlevel Init ######################## */ | |||
| #ifndef __PROGRAM_START | |||
| #define __PROGRAM_START __main | |||
| #endif | |||
| #ifndef __INITIAL_SP | |||
| #define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit | |||
| #endif | |||
| #ifndef __STACK_LIMIT | |||
| #define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base | |||
| #endif | |||
| #ifndef __VECTOR_TABLE | |||
| #define __VECTOR_TABLE __Vectors | |||
| #endif | |||
| #ifndef __VECTOR_TABLE_ATTRIBUTE | |||
| #define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET"))) | |||
| #endif | |||
| /* ########################## Core Instruction Access ######################### */ | |||
| /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface | |||
| Access to dedicated instructions | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief No Operation | |||
| \details No Operation does nothing. This instruction can be used for code alignment purposes. | |||
| */ | |||
| #define __NOP __nop | |||
| /** | |||
| \brief Wait For Interrupt | |||
| \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. | |||
| */ | |||
| #define __WFI __wfi | |||
| /** | |||
| \brief Wait For Event | |||
| \details Wait For Event is a hint instruction that permits the processor to enter | |||
| a low-power state until one of a number of events occurs. | |||
| */ | |||
| #define __WFE __wfe | |||
| /** | |||
| \brief Send Event | |||
| \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. | |||
| */ | |||
| #define __SEV __sev | |||
| /** | |||
| \brief Instruction Synchronization Barrier | |||
| \details Instruction Synchronization Barrier flushes the pipeline in the processor, | |||
| so that all instructions following the ISB are fetched from cache or memory, | |||
| after the instruction has been completed. | |||
| */ | |||
| #define __ISB() __isb(0xF) | |||
| /** | |||
| \brief Data Synchronization Barrier | |||
| \details Acts as a special kind of Data Memory Barrier. | |||
| It completes when all explicit memory accesses before this instruction complete. | |||
| */ | |||
| #define __DSB() __dsb(0xF) | |||
| /** | |||
| \brief Data Memory Barrier | |||
| \details Ensures the apparent order of the explicit memory operations before | |||
| and after the instruction, without ensuring their completion. | |||
| */ | |||
| #define __DMB() __dmb(0xF) | |||
| /** | |||
| \brief Reverse byte order (32 bit) | |||
| \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #define __REV __rev | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #ifndef __NO_EMBEDDED_ASM | |||
| __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) | |||
| { | |||
| rev16 r0, r0 | |||
| bx lr | |||
| } | |||
| #endif | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #ifndef __NO_EMBEDDED_ASM | |||
| __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value) | |||
| { | |||
| revsh r0, r0 | |||
| bx lr | |||
| } | |||
| #endif | |||
| /** | |||
| \brief Rotate Right in unsigned value (32 bit) | |||
| \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. | |||
| \param [in] op1 Value to rotate | |||
| \param [in] op2 Number of Bits to rotate | |||
| \return Rotated value | |||
| */ | |||
| #define __ROR __ror | |||
| /** | |||
| \brief Breakpoint | |||
| \details Causes the processor to enter Debug state. | |||
| Debug tools can use this to investigate system state when the instruction at a particular address is reached. | |||
| \param [in] value is ignored by the processor. | |||
| If required, a debugger can use it to store additional information about the breakpoint. | |||
| */ | |||
| #define __BKPT(value) __breakpoint(value) | |||
| /** | |||
| \brief Reverse bit order of value | |||
| \details Reverses the bit order of the given value. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| #define __RBIT __rbit | |||
| #else | |||
| __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) | |||
| { | |||
| uint32_t result; | |||
| uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ | |||
| result = value; /* r will be reversed bits of v; first get LSB of v */ | |||
| for (value >>= 1U; value != 0U; value >>= 1U) | |||
| { | |||
| result <<= 1U; | |||
| result |= value & 1U; | |||
| s--; | |||
| } | |||
| result <<= s; /* shift when v's highest bits are zero */ | |||
| return result; | |||
| } | |||
| #endif | |||
| /** | |||
| \brief Count leading zeros | |||
| \details Counts the number of leading zeros of a data value. | |||
| \param [in] value Value to count the leading zeros | |||
| \return number of leading zeros in value | |||
| */ | |||
| #define __CLZ __clz | |||
| #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| /** | |||
| \brief LDR Exclusive (8 bit) | |||
| \details Executes a exclusive LDR instruction for 8 bit value. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint8_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief LDR Exclusive (16 bit) | |||
| \details Executes a exclusive LDR instruction for 16 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint16_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief LDR Exclusive (32 bit) | |||
| \details Executes a exclusive LDR instruction for 32 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint32_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (8 bit) | |||
| \details Executes a exclusive STR instruction for 8 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXB(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (16 bit) | |||
| \details Executes a exclusive STR instruction for 16 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXH(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (32 bit) | |||
| \details Executes a exclusive STR instruction for 32 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXW(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief Remove the exclusive lock | |||
| \details Removes the exclusive lock which is created by LDREX. | |||
| */ | |||
| #define __CLREX __clrex | |||
| /** | |||
| \brief Signed Saturate | |||
| \details Saturates a signed value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (1..32) | |||
| \return Saturated value | |||
| */ | |||
| #define __SSAT __ssat | |||
| /** | |||
| \brief Unsigned Saturate | |||
| \details Saturates an unsigned value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (0..31) | |||
| \return Saturated value | |||
| */ | |||
| #define __USAT __usat | |||
| /** | |||
| \brief Rotate Right with Extend (32 bit) | |||
| \details Moves each bit of a bitstring right by one bit. | |||
| The carry input is shifted in at the left end of the bitstring. | |||
| \param [in] value Value to rotate | |||
| \return Rotated value | |||
| */ | |||
| #ifndef __NO_EMBEDDED_ASM | |||
| __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) | |||
| { | |||
| rrx r0, r0 | |||
| bx lr | |||
| } | |||
| #endif | |||
| /** | |||
| \brief LDRT Unprivileged (8 bit) | |||
| \details Executes a Unprivileged LDRT instruction for 8 bit value. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint8_t at (*ptr) | |||
| */ | |||
| #define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr)) | |||
| /** | |||
| \brief LDRT Unprivileged (16 bit) | |||
| \details Executes a Unprivileged LDRT instruction for 16 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint16_t at (*ptr) | |||
| */ | |||
| #define __LDRHT(ptr) ((uint16_t) __ldrt(ptr)) | |||
| /** | |||
| \brief LDRT Unprivileged (32 bit) | |||
| \details Executes a Unprivileged LDRT instruction for 32 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint32_t at (*ptr) | |||
| */ | |||
| #define __LDRT(ptr) ((uint32_t ) __ldrt(ptr)) | |||
| /** | |||
| \brief STRT Unprivileged (8 bit) | |||
| \details Executes a Unprivileged STRT instruction for 8 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| */ | |||
| #define __STRBT(value, ptr) __strt(value, ptr) | |||
| /** | |||
| \brief STRT Unprivileged (16 bit) | |||
| \details Executes a Unprivileged STRT instruction for 16 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| */ | |||
| #define __STRHT(value, ptr) __strt(value, ptr) | |||
| /** | |||
| \brief STRT Unprivileged (32 bit) | |||
| \details Executes a Unprivileged STRT instruction for 32 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| */ | |||
| #define __STRT(value, ptr) __strt(value, ptr) | |||
| #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ | |||
| /** | |||
| \brief Signed Saturate | |||
| \details Saturates a signed value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (1..32) | |||
| \return Saturated value | |||
| */ | |||
| __attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) | |||
| { | |||
| if ((sat >= 1U) && (sat <= 32U)) | |||
| { | |||
| const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); | |||
| const int32_t min = -1 - max ; | |||
| if (val > max) | |||
| { | |||
| return max; | |||
| } | |||
| else if (val < min) | |||
| { | |||
| return min; | |||
| } | |||
| } | |||
| return val; | |||
| } | |||
| /** | |||
| \brief Unsigned Saturate | |||
| \details Saturates an unsigned value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (0..31) | |||
| \return Saturated value | |||
| */ | |||
| __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) | |||
| { | |||
| if (sat <= 31U) | |||
| { | |||
| const uint32_t max = ((1U << sat) - 1U); | |||
| if (val > (int32_t)max) | |||
| { | |||
| return max; | |||
| } | |||
| else if (val < 0) | |||
| { | |||
| return 0U; | |||
| } | |||
| } | |||
| return (uint32_t)val; | |||
| } | |||
| #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ | |||
| /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ | |||
| /* ########################### Core Function Access ########################### */ | |||
| /** \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Enable IRQ Interrupts | |||
| \details Enables IRQ interrupts by clearing special-purpose register PRIMASK. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| /* intrinsic void __enable_irq(); */ | |||
| /** | |||
| \brief Disable IRQ Interrupts | |||
| \details Disables IRQ interrupts by setting special-purpose register PRIMASK. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| /* intrinsic void __disable_irq(); */ | |||
| /** | |||
| \brief Get Control Register | |||
| \details Returns the content of the Control Register. | |||
| \return Control Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_CONTROL(void) | |||
| { | |||
| register uint32_t __regControl __ASM("control"); | |||
| return(__regControl); | |||
| } | |||
| /** | |||
| \brief Set Control Register | |||
| \details Writes the given value to the Control Register. | |||
| \param [in] control Control Register value to set | |||
| */ | |||
| __STATIC_INLINE void __set_CONTROL(uint32_t control) | |||
| { | |||
| register uint32_t __regControl __ASM("control"); | |||
| __regControl = control; | |||
| __ISB(); | |||
| } | |||
| /** | |||
| \brief Get IPSR Register | |||
| \details Returns the content of the IPSR Register. | |||
| \return IPSR Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_IPSR(void) | |||
| { | |||
| register uint32_t __regIPSR __ASM("ipsr"); | |||
| return(__regIPSR); | |||
| } | |||
| /** | |||
| \brief Get APSR Register | |||
| \details Returns the content of the APSR Register. | |||
| \return APSR Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_APSR(void) | |||
| { | |||
| register uint32_t __regAPSR __ASM("apsr"); | |||
| return(__regAPSR); | |||
| } | |||
| /** | |||
| \brief Get xPSR Register | |||
| \details Returns the content of the xPSR Register. | |||
| \return xPSR Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_xPSR(void) | |||
| { | |||
| register uint32_t __regXPSR __ASM("xpsr"); | |||
| return(__regXPSR); | |||
| } | |||
| /** | |||
| \brief Get Process Stack Pointer | |||
| \details Returns the current value of the Process Stack Pointer (PSP). | |||
| \return PSP Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_PSP(void) | |||
| { | |||
| register uint32_t __regProcessStackPointer __ASM("psp"); | |||
| return(__regProcessStackPointer); | |||
| } | |||
| /** | |||
| \brief Set Process Stack Pointer | |||
| \details Assigns the given value to the Process Stack Pointer (PSP). | |||
| \param [in] topOfProcStack Process Stack Pointer value to set | |||
| */ | |||
| __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) | |||
| { | |||
| register uint32_t __regProcessStackPointer __ASM("psp"); | |||
| __regProcessStackPointer = topOfProcStack; | |||
| } | |||
| /** | |||
| \brief Get Main Stack Pointer | |||
| \details Returns the current value of the Main Stack Pointer (MSP). | |||
| \return MSP Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_MSP(void) | |||
| { | |||
| register uint32_t __regMainStackPointer __ASM("msp"); | |||
| return(__regMainStackPointer); | |||
| } | |||
| /** | |||
| \brief Set Main Stack Pointer | |||
| \details Assigns the given value to the Main Stack Pointer (MSP). | |||
| \param [in] topOfMainStack Main Stack Pointer value to set | |||
| */ | |||
| __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) | |||
| { | |||
| register uint32_t __regMainStackPointer __ASM("msp"); | |||
| __regMainStackPointer = topOfMainStack; | |||
| } | |||
| /** | |||
| \brief Get Priority Mask | |||
| \details Returns the current state of the priority mask bit from the Priority Mask Register. | |||
| \return Priority Mask value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_PRIMASK(void) | |||
| { | |||
| register uint32_t __regPriMask __ASM("primask"); | |||
| return(__regPriMask); | |||
| } | |||
| /** | |||
| \brief Set Priority Mask | |||
| \details Assigns the given value to the Priority Mask Register. | |||
| \param [in] priMask Priority Mask | |||
| */ | |||
| __STATIC_INLINE void __set_PRIMASK(uint32_t priMask) | |||
| { | |||
| register uint32_t __regPriMask __ASM("primask"); | |||
| __regPriMask = (priMask); | |||
| } | |||
| #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| /** | |||
| \brief Enable FIQ | |||
| \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| #define __enable_fault_irq __enable_fiq | |||
| /** | |||
| \brief Disable FIQ | |||
| \details Disables FIQ interrupts by setting special-purpose register FAULTMASK. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| #define __disable_fault_irq __disable_fiq | |||
| /** | |||
| \brief Get Base Priority | |||
| \details Returns the current value of the Base Priority register. | |||
| \return Base Priority register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_BASEPRI(void) | |||
| { | |||
| register uint32_t __regBasePri __ASM("basepri"); | |||
| return(__regBasePri); | |||
| } | |||
| /** | |||
| \brief Set Base Priority | |||
| \details Assigns the given value to the Base Priority register. | |||
| \param [in] basePri Base Priority value to set | |||
| */ | |||
| __STATIC_INLINE void __set_BASEPRI(uint32_t basePri) | |||
| { | |||
| register uint32_t __regBasePri __ASM("basepri"); | |||
| __regBasePri = (basePri & 0xFFU); | |||
| } | |||
| /** | |||
| \brief Set Base Priority with condition | |||
| \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, | |||
| or the new value increases the BASEPRI priority level. | |||
| \param [in] basePri Base Priority value to set | |||
| */ | |||
| __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) | |||
| { | |||
| register uint32_t __regBasePriMax __ASM("basepri_max"); | |||
| __regBasePriMax = (basePri & 0xFFU); | |||
| } | |||
| /** | |||
| \brief Get Fault Mask | |||
| \details Returns the current value of the Fault Mask register. | |||
| \return Fault Mask register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_FAULTMASK(void) | |||
| { | |||
| register uint32_t __regFaultMask __ASM("faultmask"); | |||
| return(__regFaultMask); | |||
| } | |||
| /** | |||
| \brief Set Fault Mask | |||
| \details Assigns the given value to the Fault Mask register. | |||
| \param [in] faultMask Fault Mask value to set | |||
| */ | |||
| __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) | |||
| { | |||
| register uint32_t __regFaultMask __ASM("faultmask"); | |||
| __regFaultMask = (faultMask & (uint32_t)1U); | |||
| } | |||
| #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ | |||
| /** | |||
| \brief Get FPSCR | |||
| \details Returns the current value of the Floating Point Status/Control register. | |||
| \return Floating Point Status/Control register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_FPSCR(void) | |||
| { | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| register uint32_t __regfpscr __ASM("fpscr"); | |||
| return(__regfpscr); | |||
| #else | |||
| return(0U); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Set FPSCR | |||
| \details Assigns the given value to the Floating Point Status/Control register. | |||
| \param [in] fpscr Floating Point Status/Control value to set | |||
| */ | |||
| __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) | |||
| { | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| register uint32_t __regfpscr __ASM("fpscr"); | |||
| __regfpscr = (fpscr); | |||
| #else | |||
| (void)fpscr; | |||
| #endif | |||
| } | |||
| /*@} end of CMSIS_Core_RegAccFunctions */ | |||
| /* ################### Compiler specific Intrinsics ########################### */ | |||
| /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics | |||
| Access to dedicated SIMD instructions | |||
| @{ | |||
| */ | |||
| #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| #define __SADD8 __sadd8 | |||
| #define __QADD8 __qadd8 | |||
| #define __SHADD8 __shadd8 | |||
| #define __UADD8 __uadd8 | |||
| #define __UQADD8 __uqadd8 | |||
| #define __UHADD8 __uhadd8 | |||
| #define __SSUB8 __ssub8 | |||
| #define __QSUB8 __qsub8 | |||
| #define __SHSUB8 __shsub8 | |||
| #define __USUB8 __usub8 | |||
| #define __UQSUB8 __uqsub8 | |||
| #define __UHSUB8 __uhsub8 | |||
| #define __SADD16 __sadd16 | |||
| #define __QADD16 __qadd16 | |||
| #define __SHADD16 __shadd16 | |||
| #define __UADD16 __uadd16 | |||
| #define __UQADD16 __uqadd16 | |||
| #define __UHADD16 __uhadd16 | |||
| #define __SSUB16 __ssub16 | |||
| #define __QSUB16 __qsub16 | |||
| #define __SHSUB16 __shsub16 | |||
| #define __USUB16 __usub16 | |||
| #define __UQSUB16 __uqsub16 | |||
| #define __UHSUB16 __uhsub16 | |||
| #define __SASX __sasx | |||
| #define __QASX __qasx | |||
| #define __SHASX __shasx | |||
| #define __UASX __uasx | |||
| #define __UQASX __uqasx | |||
| #define __UHASX __uhasx | |||
| #define __SSAX __ssax | |||
| #define __QSAX __qsax | |||
| #define __SHSAX __shsax | |||
| #define __USAX __usax | |||
| #define __UQSAX __uqsax | |||
| #define __UHSAX __uhsax | |||
| #define __USAD8 __usad8 | |||
| #define __USADA8 __usada8 | |||
| #define __SSAT16 __ssat16 | |||
| #define __USAT16 __usat16 | |||
| #define __UXTB16 __uxtb16 | |||
| #define __UXTAB16 __uxtab16 | |||
| #define __SXTB16 __sxtb16 | |||
| #define __SXTAB16 __sxtab16 | |||
| #define __SMUAD __smuad | |||
| #define __SMUADX __smuadx | |||
| #define __SMLAD __smlad | |||
| #define __SMLADX __smladx | |||
| #define __SMLALD __smlald | |||
| #define __SMLALDX __smlaldx | |||
| #define __SMUSD __smusd | |||
| #define __SMUSDX __smusdx | |||
| #define __SMLSD __smlsd | |||
| #define __SMLSDX __smlsdx | |||
| #define __SMLSLD __smlsld | |||
| #define __SMLSLDX __smlsldx | |||
| #define __SEL __sel | |||
| #define __QADD __qadd | |||
| #define __QSUB __qsub | |||
| #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ | |||
| ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) | |||
| #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ | |||
| ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) | |||
| #define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \ | |||
| ((int64_t)(ARG3) << 32U) ) >> 32U)) | |||
| #define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2)) | |||
| #define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3)) | |||
| #endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ | |||
| /*@} end of group CMSIS_SIMD_intrinsics */ | |||
| #endif /* __CMSIS_ARMCC_H */ | |||
| @@ -0,0 +1,283 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_compiler.h | |||
| * @brief CMSIS compiler generic header file | |||
| * @version V5.1.0 | |||
| * @date 09. October 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef __CMSIS_COMPILER_H | |||
| #define __CMSIS_COMPILER_H | |||
| #include <stdint.h> | |||
| /* | |||
| * Arm Compiler 4/5 | |||
| */ | |||
| #if defined ( __CC_ARM ) | |||
| #include "cmsis_armcc.h" | |||
| /* | |||
| * Arm Compiler 6.6 LTM (armclang) | |||
| */ | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100) | |||
| #include "cmsis_armclang_ltm.h" | |||
| /* | |||
| * Arm Compiler above 6.10.1 (armclang) | |||
| */ | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) | |||
| #include "cmsis_armclang.h" | |||
| /* | |||
| * GNU Compiler | |||
| */ | |||
| #elif defined ( __GNUC__ ) | |||
| #include "cmsis_gcc.h" | |||
| /* | |||
| * IAR Compiler | |||
| */ | |||
| #elif defined ( __ICCARM__ ) | |||
| #include <cmsis_iccarm.h> | |||
| /* | |||
| * TI Arm Compiler | |||
| */ | |||
| #elif defined ( __TI_ARM__ ) | |||
| #include <cmsis_ccs.h> | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __attribute__((noreturn)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed)) | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT struct __attribute__((packed)) | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #define __PACKED_UNION union __attribute__((packed)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| struct __attribute__((packed)) T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #define __RESTRICT __restrict | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| /* | |||
| * TASKING Compiler | |||
| */ | |||
| #elif defined ( __TASKING__ ) | |||
| /* | |||
| * The CMSIS functions have been implemented as intrinsics in the compiler. | |||
| * Please use "carm -?i" to get an up to date list of all intrinsics, | |||
| * Including the CMSIS ones. | |||
| */ | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __attribute__((noreturn)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __packed__ | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT struct __packed__ | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #define __PACKED_UNION union __packed__ | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| struct __packed__ T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __align(x) | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. | |||
| #define __RESTRICT | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| /* | |||
| * COSMIC Compiler | |||
| */ | |||
| #elif defined ( __CSMC__ ) | |||
| #include <cmsis_csm.h> | |||
| #ifndef __ASM | |||
| #define __ASM _asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| // NO RETURN is automatically detected hence no warning here | |||
| #define __NO_RETURN | |||
| #endif | |||
| #ifndef __USED | |||
| #warning No compiler specific solution for __USED. __USED is ignored. | |||
| #define __USED | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __weak | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED @packed | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT @packed struct | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #define __PACKED_UNION @packed union | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| @packed struct T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. | |||
| #define __ALIGNED(x) | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. | |||
| #define __RESTRICT | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| #else | |||
| #error Unknown compiler. | |||
| #endif | |||
| #endif /* __CMSIS_COMPILER_H */ | |||
| @@ -0,0 +1,39 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_version.h | |||
| * @brief CMSIS Core(M) Version definitions | |||
| * @version V5.0.5 | |||
| * @date 02. February 2022 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2022 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef __CMSIS_VERSION_H | |||
| #define __CMSIS_VERSION_H | |||
| /* CMSIS Version definitions */ | |||
| #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ | |||
| #define __CM_CMSIS_VERSION_SUB ( 6U) /*!< [15:0] CMSIS Core(M) sub version */ | |||
| #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ | |||
| __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ | |||
| #endif | |||
| @@ -0,0 +1,952 @@ | |||
| /**************************************************************************//** | |||
| * @file core_cm0.h | |||
| * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File | |||
| * @version V5.0.8 | |||
| * @date 21. August 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef __CORE_CM0_H_GENERIC | |||
| #define __CORE_CM0_H_GENERIC | |||
| #include <stdint.h> | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /** | |||
| \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions | |||
| CMSIS violates the following MISRA-C:2004 rules: | |||
| \li Required Rule 8.5, object/function definition in header file.<br> | |||
| Function definitions in header files are used to allow 'inlining'. | |||
| \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br> | |||
| Unions are used for effective representation of core registers. | |||
| \li Advisory Rule 19.7, Function-like macro defined.<br> | |||
| Function-like macros are used to allow more efficient code. | |||
| */ | |||
| /******************************************************************************* | |||
| * CMSIS definitions | |||
| ******************************************************************************/ | |||
| /** | |||
| \ingroup Cortex_M0 | |||
| @{ | |||
| */ | |||
| #include "cmsis_version.h" | |||
| /* CMSIS CM0 definitions */ | |||
| #define __CM0_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ | |||
| #define __CM0_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ | |||
| #define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16U) | \ | |||
| __CM0_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ | |||
| #define __CORTEX_M (0U) /*!< Cortex-M Core */ | |||
| /** __FPU_USED indicates whether an FPU is used or not. | |||
| This core does not support an FPU at all | |||
| */ | |||
| #define __FPU_USED 0U | |||
| #if defined ( __CC_ARM ) | |||
| #if defined __TARGET_FPU_VFP | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) | |||
| #if defined __ARM_FP | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __GNUC__ ) | |||
| #if defined (__VFP_FP__) && !defined(__SOFTFP__) | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __ICCARM__ ) | |||
| #if defined __ARMVFP__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __TI_ARM__ ) | |||
| #if defined __TI_VFP_SUPPORT__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __TASKING__ ) | |||
| #if defined __FPU_VFP__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __CSMC__ ) | |||
| #if ( __CSMC__ & 0x400U) | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #endif | |||
| #include "cmsis_compiler.h" /* CMSIS compiler specific defines */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __CORE_CM0_H_GENERIC */ | |||
| #ifndef __CMSIS_GENERIC | |||
| #ifndef __CORE_CM0_H_DEPENDANT | |||
| #define __CORE_CM0_H_DEPENDANT | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* check device defines and use defaults */ | |||
| #if defined __CHECK_DEVICE_DEFINES | |||
| #ifndef __CM0_REV | |||
| #define __CM0_REV 0x0000U | |||
| #warning "__CM0_REV not defined in device header file; using default!" | |||
| #endif | |||
| #ifndef __NVIC_PRIO_BITS | |||
| #define __NVIC_PRIO_BITS 2U | |||
| #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" | |||
| #endif | |||
| #ifndef __Vendor_SysTickConfig | |||
| #define __Vendor_SysTickConfig 0U | |||
| #warning "__Vendor_SysTickConfig not defined in device header file; using default!" | |||
| #endif | |||
| #endif | |||
| /* IO definitions (access restrictions to peripheral registers) */ | |||
| /** | |||
| \defgroup CMSIS_glob_defs CMSIS Global Defines | |||
| <strong>IO Type Qualifiers</strong> are used | |||
| \li to specify the access to peripheral variables. | |||
| \li for automatic generation of peripheral register debug information. | |||
| */ | |||
| #ifdef __cplusplus | |||
| #define __I volatile /*!< Defines 'read only' permissions */ | |||
| #else | |||
| #define __I volatile const /*!< Defines 'read only' permissions */ | |||
| #endif | |||
| #define __O volatile /*!< Defines 'write only' permissions */ | |||
| #define __IO volatile /*!< Defines 'read / write' permissions */ | |||
| /* following defines should be used for structure members */ | |||
| #define __IM volatile const /*! Defines 'read only' structure member permissions */ | |||
| #define __OM volatile /*! Defines 'write only' structure member permissions */ | |||
| #define __IOM volatile /*! Defines 'read / write' structure member permissions */ | |||
| /*@} end of group Cortex_M0 */ | |||
| /******************************************************************************* | |||
| * Register Abstraction | |||
| Core Register contain: | |||
| - Core Register | |||
| - Core NVIC Register | |||
| - Core SCB Register | |||
| - Core SysTick Register | |||
| ******************************************************************************/ | |||
| /** | |||
| \defgroup CMSIS_core_register Defines and Type Definitions | |||
| \brief Type definitions and defines for Cortex-M processor based devices. | |||
| */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_CORE Status and Control Registers | |||
| \brief Core Register type definitions. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Union type to access the Application Program Status Register (APSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */ | |||
| uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ | |||
| uint32_t C:1; /*!< bit: 29 Carry condition code flag */ | |||
| uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ | |||
| uint32_t N:1; /*!< bit: 31 Negative condition code flag */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } APSR_Type; | |||
| /* APSR Register Definitions */ | |||
| #define APSR_N_Pos 31U /*!< APSR: N Position */ | |||
| #define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */ | |||
| #define APSR_Z_Pos 30U /*!< APSR: Z Position */ | |||
| #define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */ | |||
| #define APSR_C_Pos 29U /*!< APSR: C Position */ | |||
| #define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */ | |||
| #define APSR_V_Pos 28U /*!< APSR: V Position */ | |||
| #define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */ | |||
| /** | |||
| \brief Union type to access the Interrupt Program Status Register (IPSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ | |||
| uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } IPSR_Type; | |||
| /* IPSR Register Definitions */ | |||
| #define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */ | |||
| #define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */ | |||
| /** | |||
| \brief Union type to access the Special-Purpose Program Status Registers (xPSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ | |||
| uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ | |||
| uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ | |||
| uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */ | |||
| uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ | |||
| uint32_t C:1; /*!< bit: 29 Carry condition code flag */ | |||
| uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ | |||
| uint32_t N:1; /*!< bit: 31 Negative condition code flag */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } xPSR_Type; | |||
| /* xPSR Register Definitions */ | |||
| #define xPSR_N_Pos 31U /*!< xPSR: N Position */ | |||
| #define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */ | |||
| #define xPSR_Z_Pos 30U /*!< xPSR: Z Position */ | |||
| #define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */ | |||
| #define xPSR_C_Pos 29U /*!< xPSR: C Position */ | |||
| #define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */ | |||
| #define xPSR_V_Pos 28U /*!< xPSR: V Position */ | |||
| #define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */ | |||
| #define xPSR_T_Pos 24U /*!< xPSR: T Position */ | |||
| #define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ | |||
| #define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ | |||
| #define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ | |||
| /** | |||
| \brief Union type to access the Control Registers (CONTROL). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t _reserved0:1; /*!< bit: 0 Reserved */ | |||
| uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ | |||
| uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } CONTROL_Type; | |||
| /* CONTROL Register Definitions */ | |||
| #define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ | |||
| #define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ | |||
| /*@} end of group CMSIS_CORE */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) | |||
| \brief Type definitions for the NVIC Registers | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ | |||
| uint32_t RESERVED0[31U]; | |||
| __IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ | |||
| uint32_t RESERVED1[31U]; | |||
| __IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ | |||
| uint32_t RESERVED2[31U]; | |||
| __IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ | |||
| uint32_t RESERVED3[31U]; | |||
| uint32_t RESERVED4[64U]; | |||
| __IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */ | |||
| } NVIC_Type; | |||
| /*@} end of group CMSIS_NVIC */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SCB System Control Block (SCB) | |||
| \brief Type definitions for the System Control Block Registers | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Control Block (SCB). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ | |||
| __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ | |||
| uint32_t RESERVED0; | |||
| __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ | |||
| __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ | |||
| __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ | |||
| uint32_t RESERVED1; | |||
| __IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ | |||
| __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ | |||
| } SCB_Type; | |||
| /* SCB CPUID Register Definitions */ | |||
| #define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */ | |||
| #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ | |||
| #define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */ | |||
| #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ | |||
| #define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */ | |||
| #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ | |||
| #define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */ | |||
| #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ | |||
| #define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */ | |||
| #define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */ | |||
| /* SCB Interrupt Control State Register Definitions */ | |||
| #define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */ | |||
| #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ | |||
| #define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */ | |||
| #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ | |||
| #define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */ | |||
| #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ | |||
| #define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */ | |||
| #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ | |||
| #define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */ | |||
| #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ | |||
| #define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */ | |||
| #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ | |||
| #define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */ | |||
| #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ | |||
| #define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */ | |||
| #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ | |||
| #define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */ | |||
| #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ | |||
| /* SCB Application Interrupt and Reset Control Register Definitions */ | |||
| #define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */ | |||
| #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ | |||
| #define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */ | |||
| #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ | |||
| #define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */ | |||
| #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ | |||
| #define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */ | |||
| #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ | |||
| #define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */ | |||
| #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ | |||
| /* SCB System Control Register Definitions */ | |||
| #define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */ | |||
| #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ | |||
| #define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */ | |||
| #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ | |||
| #define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */ | |||
| #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ | |||
| /* SCB Configuration Control Register Definitions */ | |||
| #define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */ | |||
| #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ | |||
| #define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */ | |||
| #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ | |||
| /* SCB System Handler Control and State Register Definitions */ | |||
| #define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ | |||
| #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ | |||
| /*@} end of group CMSIS_SCB */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SysTick System Tick Timer (SysTick) | |||
| \brief Type definitions for the System Timer Registers. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Timer (SysTick). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ | |||
| __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ | |||
| __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ | |||
| __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ | |||
| } SysTick_Type; | |||
| /* SysTick Control / Status Register Definitions */ | |||
| #define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */ | |||
| #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ | |||
| #define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */ | |||
| #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ | |||
| #define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */ | |||
| #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ | |||
| #define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */ | |||
| #define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */ | |||
| /* SysTick Reload Register Definitions */ | |||
| #define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */ | |||
| #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */ | |||
| /* SysTick Current Register Definitions */ | |||
| #define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */ | |||
| #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */ | |||
| /* SysTick Calibration Register Definitions */ | |||
| #define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */ | |||
| #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ | |||
| #define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */ | |||
| #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ | |||
| #define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */ | |||
| #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */ | |||
| /*@} end of group CMSIS_SysTick */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) | |||
| \brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor. | |||
| Therefore they are not covered by the Cortex-M0 header file. | |||
| @{ | |||
| */ | |||
| /*@} end of group CMSIS_CoreDebug */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_core_bitfield Core register bit field macros | |||
| \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk). | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Mask and shift a bit field value for use in a register bit range. | |||
| \param[in] field Name of the register bit field. | |||
| \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. | |||
| \return Masked and shifted value. | |||
| */ | |||
| #define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) | |||
| /** | |||
| \brief Mask and shift a register value to extract a bit filed value. | |||
| \param[in] field Name of the register bit field. | |||
| \param[in] value Value of register. This parameter is interpreted as an uint32_t type. | |||
| \return Masked and shifted bit field value. | |||
| */ | |||
| #define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) | |||
| /*@} end of group CMSIS_core_bitfield */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_core_base Core Definitions | |||
| \brief Definitions for base addresses, unions, and structures. | |||
| @{ | |||
| */ | |||
| /* Memory mapping of Core Hardware */ | |||
| #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ | |||
| #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ | |||
| #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ | |||
| #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ | |||
| #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ | |||
| #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ | |||
| #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ | |||
| /*@} */ | |||
| /******************************************************************************* | |||
| * Hardware Abstraction Layer | |||
| Core Function Interface contains: | |||
| - Core NVIC Functions | |||
| - Core SysTick Functions | |||
| - Core Register Access Functions | |||
| ******************************************************************************/ | |||
| /** | |||
| \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference | |||
| */ | |||
| /* ########################## NVIC functions #################################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_NVICFunctions NVIC Functions | |||
| \brief Functions that manage interrupts and exceptions via the NVIC. | |||
| @{ | |||
| */ | |||
| #ifdef CMSIS_NVIC_VIRTUAL | |||
| #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE | |||
| #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" | |||
| #endif | |||
| #include CMSIS_NVIC_VIRTUAL_HEADER_FILE | |||
| #else | |||
| #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping | |||
| #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping | |||
| #define NVIC_EnableIRQ __NVIC_EnableIRQ | |||
| #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ | |||
| #define NVIC_DisableIRQ __NVIC_DisableIRQ | |||
| #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ | |||
| #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ | |||
| #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ | |||
| /*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M0 */ | |||
| #define NVIC_SetPriority __NVIC_SetPriority | |||
| #define NVIC_GetPriority __NVIC_GetPriority | |||
| #define NVIC_SystemReset __NVIC_SystemReset | |||
| #endif /* CMSIS_NVIC_VIRTUAL */ | |||
| #ifdef CMSIS_VECTAB_VIRTUAL | |||
| #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE | |||
| #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" | |||
| #endif | |||
| #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE | |||
| #else | |||
| #define NVIC_SetVector __NVIC_SetVector | |||
| #define NVIC_GetVector __NVIC_GetVector | |||
| #endif /* (CMSIS_VECTAB_VIRTUAL) */ | |||
| #define NVIC_USER_IRQ_OFFSET 16 | |||
| /* The following EXC_RETURN values are saved the LR on exception entry */ | |||
| #define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */ | |||
| #define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */ | |||
| #define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */ | |||
| /* Interrupt Priorities are WORD accessible only under Armv6-M */ | |||
| /* The following MACROS handle generation of the register offset and byte masks */ | |||
| #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL) | |||
| #define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) ) | |||
| #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) ) | |||
| #define __NVIC_SetPriorityGrouping(X) (void)(X) | |||
| #define __NVIC_GetPriorityGrouping() (0U) | |||
| /** | |||
| \brief Enable Interrupt | |||
| \details Enables a device specific interrupt in the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| __COMPILER_BARRIER(); | |||
| NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| __COMPILER_BARRIER(); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Interrupt Enable status | |||
| \details Returns a device specific interrupt enable status from the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \return 0 Interrupt is not enabled. | |||
| \return 1 Interrupt is enabled. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); | |||
| } | |||
| else | |||
| { | |||
| return(0U); | |||
| } | |||
| } | |||
| /** | |||
| \brief Disable Interrupt | |||
| \details Disables a device specific interrupt in the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Pending Interrupt | |||
| \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \return 0 Interrupt status is not pending. | |||
| \return 1 Interrupt status is pending. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); | |||
| } | |||
| else | |||
| { | |||
| return(0U); | |||
| } | |||
| } | |||
| /** | |||
| \brief Set Pending Interrupt | |||
| \details Sets the pending bit of a device specific interrupt in the NVIC pending register. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| } | |||
| } | |||
| /** | |||
| \brief Clear Pending Interrupt | |||
| \details Clears the pending bit of a device specific interrupt in the NVIC pending register. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| } | |||
| } | |||
| /** | |||
| \brief Set Interrupt Priority | |||
| \details Sets the priority of a device specific interrupt or a processor exception. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \param [in] priority Priority to set. | |||
| \note The priority cannot be set for every processor exception. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | | |||
| (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); | |||
| } | |||
| else | |||
| { | |||
| SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | | |||
| (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Interrupt Priority | |||
| \details Reads the priority of a device specific interrupt or a processor exception. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \return Interrupt Priority. | |||
| Value is aligned automatically to the implemented priority bits of the microcontroller. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); | |||
| } | |||
| else | |||
| { | |||
| return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); | |||
| } | |||
| } | |||
| /** | |||
| \brief Encode Priority | |||
| \details Encodes the priority for an interrupt with the given priority group, | |||
| preemptive priority value, and subpriority value. | |||
| In case of a conflict between priority grouping and available | |||
| priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. | |||
| \param [in] PriorityGroup Used priority group. | |||
| \param [in] PreemptPriority Preemptive priority value (starting from 0). | |||
| \param [in] SubPriority Subpriority value (starting from 0). | |||
| \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority(). | |||
| */ | |||
| __STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) | |||
| { | |||
| uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ | |||
| uint32_t PreemptPriorityBits; | |||
| uint32_t SubPriorityBits; | |||
| PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); | |||
| SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); | |||
| return ( | |||
| ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | | |||
| ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) | |||
| ); | |||
| } | |||
| /** | |||
| \brief Decode Priority | |||
| \details Decodes an interrupt priority value with a given priority group to | |||
| preemptive priority value and subpriority value. | |||
| In case of a conflict between priority grouping and available | |||
| priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. | |||
| \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority(). | |||
| \param [in] PriorityGroup Used priority group. | |||
| \param [out] pPreemptPriority Preemptive priority value (starting from 0). | |||
| \param [out] pSubPriority Subpriority value (starting from 0). | |||
| */ | |||
| __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority) | |||
| { | |||
| uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ | |||
| uint32_t PreemptPriorityBits; | |||
| uint32_t SubPriorityBits; | |||
| PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); | |||
| SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); | |||
| *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); | |||
| *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL); | |||
| } | |||
| /** | |||
| \brief Set Interrupt Vector | |||
| \details Sets an interrupt vector in SRAM based interrupt vector table. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| Address 0 must be mapped to SRAM. | |||
| \param [in] IRQn Interrupt number | |||
| \param [in] vector Address of interrupt handler function | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) | |||
| { | |||
| uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */ | |||
| *(vectors + (int32_t)IRQn) = vector; /* use pointer arithmetic to access vector */ | |||
| /* ARM Application Note 321 states that the M0 does not require the architectural barrier */ | |||
| } | |||
| /** | |||
| \brief Get Interrupt Vector | |||
| \details Reads an interrupt vector from interrupt vector table. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \return Address of interrupt handler function | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) | |||
| { | |||
| uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */ | |||
| return *(vectors + (int32_t)IRQn); /* use pointer arithmetic to access vector */ | |||
| } | |||
| /** | |||
| \brief System Reset | |||
| \details Initiates a system reset request to reset the MCU. | |||
| */ | |||
| __NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) | |||
| { | |||
| __DSB(); /* Ensure all outstanding memory accesses included | |||
| buffered write are completed before reset */ | |||
| SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | | |||
| SCB_AIRCR_SYSRESETREQ_Msk); | |||
| __DSB(); /* Ensure completion of memory access */ | |||
| for(;;) /* wait until reset */ | |||
| { | |||
| __NOP(); | |||
| } | |||
| } | |||
| /*@} end of CMSIS_Core_NVICFunctions */ | |||
| /* ########################## FPU functions #################################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_FpuFunctions FPU Functions | |||
| \brief Function that provides FPU type. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief get FPU type | |||
| \details returns the FPU type | |||
| \returns | |||
| - \b 0: No FPU | |||
| - \b 1: Single precision FPU | |||
| - \b 2: Double + Single precision FPU | |||
| */ | |||
| __STATIC_INLINE uint32_t SCB_GetFPUType(void) | |||
| { | |||
| return 0U; /* No FPU */ | |||
| } | |||
| /*@} end of CMSIS_Core_FpuFunctions */ | |||
| /* ################################## SysTick function ############################################ */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_SysTickFunctions SysTick Functions | |||
| \brief Functions that configure the System. | |||
| @{ | |||
| */ | |||
| #if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) | |||
| /** | |||
| \brief System Tick Configuration | |||
| \details Initializes the System Timer and its interrupt, and starts the System Tick Timer. | |||
| Counter is in free running mode to generate periodic interrupts. | |||
| \param [in] ticks Number of ticks between two interrupts. | |||
| \return 0 Function succeeded. | |||
| \return 1 Function failed. | |||
| \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the | |||
| function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b> | |||
| must contain a vendor-specific implementation of this function. | |||
| */ | |||
| __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) | |||
| { | |||
| if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) | |||
| { | |||
| return (1UL); /* Reload value impossible */ | |||
| } | |||
| SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ | |||
| NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ | |||
| SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ | |||
| SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | | |||
| SysTick_CTRL_TICKINT_Msk | | |||
| SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ | |||
| return (0UL); /* Function successful */ | |||
| } | |||
| #endif | |||
| /*@} end of CMSIS_Core_SysTickFunctions */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __CORE_CM0_H_DEPENDANT */ | |||
| #endif /* __CMSIS_GENERIC */ | |||
| @@ -0,0 +1,979 @@ | |||
| /**************************************************************************//** | |||
| * @file core_cm1.h | |||
| * @brief CMSIS Cortex-M1 Core Peripheral Access Layer Header File | |||
| * @version V1.0.1 | |||
| * @date 12. November 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef __CORE_CM1_H_GENERIC | |||
| #define __CORE_CM1_H_GENERIC | |||
| #include <stdint.h> | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /** | |||
| \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions | |||
| CMSIS violates the following MISRA-C:2004 rules: | |||
| \li Required Rule 8.5, object/function definition in header file.<br> | |||
| Function definitions in header files are used to allow 'inlining'. | |||
| \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br> | |||
| Unions are used for effective representation of core registers. | |||
| \li Advisory Rule 19.7, Function-like macro defined.<br> | |||
| Function-like macros are used to allow more efficient code. | |||
| */ | |||
| /******************************************************************************* | |||
| * CMSIS definitions | |||
| ******************************************************************************/ | |||
| /** | |||
| \ingroup Cortex_M1 | |||
| @{ | |||
| */ | |||
| #include "cmsis_version.h" | |||
| /* CMSIS CM1 definitions */ | |||
| #define __CM1_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ | |||
| #define __CM1_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ | |||
| #define __CM1_CMSIS_VERSION ((__CM1_CMSIS_VERSION_MAIN << 16U) | \ | |||
| __CM1_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ | |||
| #define __CORTEX_M (1U) /*!< Cortex-M Core */ | |||
| /** __FPU_USED indicates whether an FPU is used or not. | |||
| This core does not support an FPU at all | |||
| */ | |||
| #define __FPU_USED 0U | |||
| #if defined ( __CC_ARM ) | |||
| #if defined __TARGET_FPU_VFP | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) | |||
| #if defined __ARM_FP | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __GNUC__ ) | |||
| #if defined (__VFP_FP__) && !defined(__SOFTFP__) | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __ICCARM__ ) | |||
| #if defined __ARMVFP__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __TI_ARM__ ) | |||
| #if defined __TI_VFP_SUPPORT__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __TASKING__ ) | |||
| #if defined __FPU_VFP__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __CSMC__ ) | |||
| #if ( __CSMC__ & 0x400U) | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #endif | |||
| #include "cmsis_compiler.h" /* CMSIS compiler specific defines */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __CORE_CM1_H_GENERIC */ | |||
| #ifndef __CMSIS_GENERIC | |||
| #ifndef __CORE_CM1_H_DEPENDANT | |||
| #define __CORE_CM1_H_DEPENDANT | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* check device defines and use defaults */ | |||
| #if defined __CHECK_DEVICE_DEFINES | |||
| #ifndef __CM1_REV | |||
| #define __CM1_REV 0x0100U | |||
| #warning "__CM1_REV not defined in device header file; using default!" | |||
| #endif | |||
| #ifndef __NVIC_PRIO_BITS | |||
| #define __NVIC_PRIO_BITS 2U | |||
| #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" | |||
| #endif | |||
| #ifndef __Vendor_SysTickConfig | |||
| #define __Vendor_SysTickConfig 0U | |||
| #warning "__Vendor_SysTickConfig not defined in device header file; using default!" | |||
| #endif | |||
| #endif | |||
| /* IO definitions (access restrictions to peripheral registers) */ | |||
| /** | |||
| \defgroup CMSIS_glob_defs CMSIS Global Defines | |||
| <strong>IO Type Qualifiers</strong> are used | |||
| \li to specify the access to peripheral variables. | |||
| \li for automatic generation of peripheral register debug information. | |||
| */ | |||
| #ifdef __cplusplus | |||
| #define __I volatile /*!< Defines 'read only' permissions */ | |||
| #else | |||
| #define __I volatile const /*!< Defines 'read only' permissions */ | |||
| #endif | |||
| #define __O volatile /*!< Defines 'write only' permissions */ | |||
| #define __IO volatile /*!< Defines 'read / write' permissions */ | |||
| /* following defines should be used for structure members */ | |||
| #define __IM volatile const /*! Defines 'read only' structure member permissions */ | |||
| #define __OM volatile /*! Defines 'write only' structure member permissions */ | |||
| #define __IOM volatile /*! Defines 'read / write' structure member permissions */ | |||
| /*@} end of group Cortex_M1 */ | |||
| /******************************************************************************* | |||
| * Register Abstraction | |||
| Core Register contain: | |||
| - Core Register | |||
| - Core NVIC Register | |||
| - Core SCB Register | |||
| - Core SysTick Register | |||
| ******************************************************************************/ | |||
| /** | |||
| \defgroup CMSIS_core_register Defines and Type Definitions | |||
| \brief Type definitions and defines for Cortex-M processor based devices. | |||
| */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_CORE Status and Control Registers | |||
| \brief Core Register type definitions. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Union type to access the Application Program Status Register (APSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */ | |||
| uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ | |||
| uint32_t C:1; /*!< bit: 29 Carry condition code flag */ | |||
| uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ | |||
| uint32_t N:1; /*!< bit: 31 Negative condition code flag */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } APSR_Type; | |||
| /* APSR Register Definitions */ | |||
| #define APSR_N_Pos 31U /*!< APSR: N Position */ | |||
| #define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */ | |||
| #define APSR_Z_Pos 30U /*!< APSR: Z Position */ | |||
| #define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */ | |||
| #define APSR_C_Pos 29U /*!< APSR: C Position */ | |||
| #define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */ | |||
| #define APSR_V_Pos 28U /*!< APSR: V Position */ | |||
| #define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */ | |||
| /** | |||
| \brief Union type to access the Interrupt Program Status Register (IPSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ | |||
| uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } IPSR_Type; | |||
| /* IPSR Register Definitions */ | |||
| #define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */ | |||
| #define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */ | |||
| /** | |||
| \brief Union type to access the Special-Purpose Program Status Registers (xPSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ | |||
| uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ | |||
| uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ | |||
| uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */ | |||
| uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ | |||
| uint32_t C:1; /*!< bit: 29 Carry condition code flag */ | |||
| uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ | |||
| uint32_t N:1; /*!< bit: 31 Negative condition code flag */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } xPSR_Type; | |||
| /* xPSR Register Definitions */ | |||
| #define xPSR_N_Pos 31U /*!< xPSR: N Position */ | |||
| #define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */ | |||
| #define xPSR_Z_Pos 30U /*!< xPSR: Z Position */ | |||
| #define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */ | |||
| #define xPSR_C_Pos 29U /*!< xPSR: C Position */ | |||
| #define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */ | |||
| #define xPSR_V_Pos 28U /*!< xPSR: V Position */ | |||
| #define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */ | |||
| #define xPSR_T_Pos 24U /*!< xPSR: T Position */ | |||
| #define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ | |||
| #define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ | |||
| #define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ | |||
| /** | |||
| \brief Union type to access the Control Registers (CONTROL). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t _reserved0:1; /*!< bit: 0 Reserved */ | |||
| uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ | |||
| uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } CONTROL_Type; | |||
| /* CONTROL Register Definitions */ | |||
| #define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ | |||
| #define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ | |||
| /*@} end of group CMSIS_CORE */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) | |||
| \brief Type definitions for the NVIC Registers | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ | |||
| uint32_t RESERVED0[31U]; | |||
| __IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ | |||
| uint32_t RSERVED1[31U]; | |||
| __IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ | |||
| uint32_t RESERVED2[31U]; | |||
| __IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ | |||
| uint32_t RESERVED3[31U]; | |||
| uint32_t RESERVED4[64U]; | |||
| __IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */ | |||
| } NVIC_Type; | |||
| /*@} end of group CMSIS_NVIC */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SCB System Control Block (SCB) | |||
| \brief Type definitions for the System Control Block Registers | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Control Block (SCB). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ | |||
| __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ | |||
| uint32_t RESERVED0; | |||
| __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ | |||
| __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ | |||
| __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ | |||
| uint32_t RESERVED1; | |||
| __IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ | |||
| __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ | |||
| } SCB_Type; | |||
| /* SCB CPUID Register Definitions */ | |||
| #define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */ | |||
| #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ | |||
| #define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */ | |||
| #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ | |||
| #define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */ | |||
| #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ | |||
| #define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */ | |||
| #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ | |||
| #define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */ | |||
| #define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */ | |||
| /* SCB Interrupt Control State Register Definitions */ | |||
| #define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */ | |||
| #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ | |||
| #define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */ | |||
| #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ | |||
| #define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */ | |||
| #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ | |||
| #define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */ | |||
| #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ | |||
| #define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */ | |||
| #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ | |||
| #define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */ | |||
| #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ | |||
| #define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */ | |||
| #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ | |||
| #define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */ | |||
| #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ | |||
| #define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */ | |||
| #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ | |||
| /* SCB Application Interrupt and Reset Control Register Definitions */ | |||
| #define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */ | |||
| #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ | |||
| #define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */ | |||
| #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ | |||
| #define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */ | |||
| #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ | |||
| #define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */ | |||
| #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ | |||
| #define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */ | |||
| #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ | |||
| /* SCB System Control Register Definitions */ | |||
| #define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */ | |||
| #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ | |||
| #define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */ | |||
| #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ | |||
| #define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */ | |||
| #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ | |||
| /* SCB Configuration Control Register Definitions */ | |||
| #define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */ | |||
| #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ | |||
| #define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */ | |||
| #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ | |||
| /* SCB System Handler Control and State Register Definitions */ | |||
| #define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ | |||
| #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ | |||
| /*@} end of group CMSIS_SCB */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB) | |||
| \brief Type definitions for the System Control and ID Register not in the SCB | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Control and ID Register not in the SCB. | |||
| */ | |||
| typedef struct | |||
| { | |||
| uint32_t RESERVED0[2U]; | |||
| __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ | |||
| } SCnSCB_Type; | |||
| /* Auxiliary Control Register Definitions */ | |||
| #define SCnSCB_ACTLR_ITCMUAEN_Pos 4U /*!< ACTLR: Instruction TCM Upper Alias Enable Position */ | |||
| #define SCnSCB_ACTLR_ITCMUAEN_Msk (1UL << SCnSCB_ACTLR_ITCMUAEN_Pos) /*!< ACTLR: Instruction TCM Upper Alias Enable Mask */ | |||
| #define SCnSCB_ACTLR_ITCMLAEN_Pos 3U /*!< ACTLR: Instruction TCM Lower Alias Enable Position */ | |||
| #define SCnSCB_ACTLR_ITCMLAEN_Msk (1UL << SCnSCB_ACTLR_ITCMLAEN_Pos) /*!< ACTLR: Instruction TCM Lower Alias Enable Mask */ | |||
| /*@} end of group CMSIS_SCnotSCB */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SysTick System Tick Timer (SysTick) | |||
| \brief Type definitions for the System Timer Registers. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Timer (SysTick). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ | |||
| __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ | |||
| __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ | |||
| __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ | |||
| } SysTick_Type; | |||
| /* SysTick Control / Status Register Definitions */ | |||
| #define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */ | |||
| #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ | |||
| #define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */ | |||
| #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ | |||
| #define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */ | |||
| #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ | |||
| #define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */ | |||
| #define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */ | |||
| /* SysTick Reload Register Definitions */ | |||
| #define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */ | |||
| #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */ | |||
| /* SysTick Current Register Definitions */ | |||
| #define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */ | |||
| #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */ | |||
| /* SysTick Calibration Register Definitions */ | |||
| #define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */ | |||
| #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ | |||
| #define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */ | |||
| #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ | |||
| #define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */ | |||
| #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */ | |||
| /*@} end of group CMSIS_SysTick */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) | |||
| \brief Cortex-M1 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor. | |||
| Therefore they are not covered by the Cortex-M1 header file. | |||
| @{ | |||
| */ | |||
| /*@} end of group CMSIS_CoreDebug */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_core_bitfield Core register bit field macros | |||
| \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk). | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Mask and shift a bit field value for use in a register bit range. | |||
| \param[in] field Name of the register bit field. | |||
| \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. | |||
| \return Masked and shifted value. | |||
| */ | |||
| #define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) | |||
| /** | |||
| \brief Mask and shift a register value to extract a bit filed value. | |||
| \param[in] field Name of the register bit field. | |||
| \param[in] value Value of register. This parameter is interpreted as an uint32_t type. | |||
| \return Masked and shifted bit field value. | |||
| */ | |||
| #define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) | |||
| /*@} end of group CMSIS_core_bitfield */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_core_base Core Definitions | |||
| \brief Definitions for base addresses, unions, and structures. | |||
| @{ | |||
| */ | |||
| /* Memory mapping of Core Hardware */ | |||
| #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ | |||
| #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ | |||
| #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ | |||
| #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ | |||
| #define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */ | |||
| #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ | |||
| #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ | |||
| #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ | |||
| /*@} */ | |||
| /******************************************************************************* | |||
| * Hardware Abstraction Layer | |||
| Core Function Interface contains: | |||
| - Core NVIC Functions | |||
| - Core SysTick Functions | |||
| - Core Register Access Functions | |||
| ******************************************************************************/ | |||
| /** | |||
| \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference | |||
| */ | |||
| /* ########################## NVIC functions #################################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_NVICFunctions NVIC Functions | |||
| \brief Functions that manage interrupts and exceptions via the NVIC. | |||
| @{ | |||
| */ | |||
| #ifdef CMSIS_NVIC_VIRTUAL | |||
| #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE | |||
| #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" | |||
| #endif | |||
| #include CMSIS_NVIC_VIRTUAL_HEADER_FILE | |||
| #else | |||
| #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping | |||
| #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping | |||
| #define NVIC_EnableIRQ __NVIC_EnableIRQ | |||
| #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ | |||
| #define NVIC_DisableIRQ __NVIC_DisableIRQ | |||
| #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ | |||
| #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ | |||
| #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ | |||
| /*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M1 */ | |||
| #define NVIC_SetPriority __NVIC_SetPriority | |||
| #define NVIC_GetPriority __NVIC_GetPriority | |||
| #define NVIC_SystemReset __NVIC_SystemReset | |||
| #endif /* CMSIS_NVIC_VIRTUAL */ | |||
| #ifdef CMSIS_VECTAB_VIRTUAL | |||
| #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE | |||
| #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" | |||
| #endif | |||
| #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE | |||
| #else | |||
| #define NVIC_SetVector __NVIC_SetVector | |||
| #define NVIC_GetVector __NVIC_GetVector | |||
| #endif /* (CMSIS_VECTAB_VIRTUAL) */ | |||
| #define NVIC_USER_IRQ_OFFSET 16 | |||
| /* The following EXC_RETURN values are saved the LR on exception entry */ | |||
| #define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */ | |||
| #define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */ | |||
| #define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */ | |||
| /* Interrupt Priorities are WORD accessible only under Armv6-M */ | |||
| /* The following MACROS handle generation of the register offset and byte masks */ | |||
| #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL) | |||
| #define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) ) | |||
| #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) ) | |||
| #define __NVIC_SetPriorityGrouping(X) (void)(X) | |||
| #define __NVIC_GetPriorityGrouping() (0U) | |||
| /** | |||
| \brief Enable Interrupt | |||
| \details Enables a device specific interrupt in the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| __COMPILER_BARRIER(); | |||
| NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| __COMPILER_BARRIER(); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Interrupt Enable status | |||
| \details Returns a device specific interrupt enable status from the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \return 0 Interrupt is not enabled. | |||
| \return 1 Interrupt is enabled. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); | |||
| } | |||
| else | |||
| { | |||
| return(0U); | |||
| } | |||
| } | |||
| /** | |||
| \brief Disable Interrupt | |||
| \details Disables a device specific interrupt in the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Pending Interrupt | |||
| \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \return 0 Interrupt status is not pending. | |||
| \return 1 Interrupt status is pending. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); | |||
| } | |||
| else | |||
| { | |||
| return(0U); | |||
| } | |||
| } | |||
| /** | |||
| \brief Set Pending Interrupt | |||
| \details Sets the pending bit of a device specific interrupt in the NVIC pending register. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| } | |||
| } | |||
| /** | |||
| \brief Clear Pending Interrupt | |||
| \details Clears the pending bit of a device specific interrupt in the NVIC pending register. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| } | |||
| } | |||
| /** | |||
| \brief Set Interrupt Priority | |||
| \details Sets the priority of a device specific interrupt or a processor exception. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \param [in] priority Priority to set. | |||
| \note The priority cannot be set for every processor exception. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | | |||
| (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); | |||
| } | |||
| else | |||
| { | |||
| SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | | |||
| (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Interrupt Priority | |||
| \details Reads the priority of a device specific interrupt or a processor exception. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \return Interrupt Priority. | |||
| Value is aligned automatically to the implemented priority bits of the microcontroller. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); | |||
| } | |||
| else | |||
| { | |||
| return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); | |||
| } | |||
| } | |||
| /** | |||
| \brief Encode Priority | |||
| \details Encodes the priority for an interrupt with the given priority group, | |||
| preemptive priority value, and subpriority value. | |||
| In case of a conflict between priority grouping and available | |||
| priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. | |||
| \param [in] PriorityGroup Used priority group. | |||
| \param [in] PreemptPriority Preemptive priority value (starting from 0). | |||
| \param [in] SubPriority Subpriority value (starting from 0). | |||
| \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority(). | |||
| */ | |||
| __STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) | |||
| { | |||
| uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ | |||
| uint32_t PreemptPriorityBits; | |||
| uint32_t SubPriorityBits; | |||
| PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); | |||
| SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); | |||
| return ( | |||
| ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | | |||
| ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) | |||
| ); | |||
| } | |||
| /** | |||
| \brief Decode Priority | |||
| \details Decodes an interrupt priority value with a given priority group to | |||
| preemptive priority value and subpriority value. | |||
| In case of a conflict between priority grouping and available | |||
| priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. | |||
| \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority(). | |||
| \param [in] PriorityGroup Used priority group. | |||
| \param [out] pPreemptPriority Preemptive priority value (starting from 0). | |||
| \param [out] pSubPriority Subpriority value (starting from 0). | |||
| */ | |||
| __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority) | |||
| { | |||
| uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ | |||
| uint32_t PreemptPriorityBits; | |||
| uint32_t SubPriorityBits; | |||
| PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); | |||
| SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); | |||
| *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); | |||
| *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL); | |||
| } | |||
| /** | |||
| \brief Set Interrupt Vector | |||
| \details Sets an interrupt vector in SRAM based interrupt vector table. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| Address 0 must be mapped to SRAM. | |||
| \param [in] IRQn Interrupt number | |||
| \param [in] vector Address of interrupt handler function | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) | |||
| { | |||
| uint32_t *vectors = (uint32_t *)0x0U; | |||
| vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; | |||
| /* ARM Application Note 321 states that the M1 does not require the architectural barrier */ | |||
| } | |||
| /** | |||
| \brief Get Interrupt Vector | |||
| \details Reads an interrupt vector from interrupt vector table. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \return Address of interrupt handler function | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) | |||
| { | |||
| uint32_t *vectors = (uint32_t *)0x0U; | |||
| return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; | |||
| } | |||
| /** | |||
| \brief System Reset | |||
| \details Initiates a system reset request to reset the MCU. | |||
| */ | |||
| __NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) | |||
| { | |||
| __DSB(); /* Ensure all outstanding memory accesses included | |||
| buffered write are completed before reset */ | |||
| SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | | |||
| SCB_AIRCR_SYSRESETREQ_Msk); | |||
| __DSB(); /* Ensure completion of memory access */ | |||
| for(;;) /* wait until reset */ | |||
| { | |||
| __NOP(); | |||
| } | |||
| } | |||
| /*@} end of CMSIS_Core_NVICFunctions */ | |||
| /* ########################## FPU functions #################################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_FpuFunctions FPU Functions | |||
| \brief Function that provides FPU type. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief get FPU type | |||
| \details returns the FPU type | |||
| \returns | |||
| - \b 0: No FPU | |||
| - \b 1: Single precision FPU | |||
| - \b 2: Double + Single precision FPU | |||
| */ | |||
| __STATIC_INLINE uint32_t SCB_GetFPUType(void) | |||
| { | |||
| return 0U; /* No FPU */ | |||
| } | |||
| /*@} end of CMSIS_Core_FpuFunctions */ | |||
| /* ################################## SysTick function ############################################ */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_SysTickFunctions SysTick Functions | |||
| \brief Functions that configure the System. | |||
| @{ | |||
| */ | |||
| #if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) | |||
| /** | |||
| \brief System Tick Configuration | |||
| \details Initializes the System Timer and its interrupt, and starts the System Tick Timer. | |||
| Counter is in free running mode to generate periodic interrupts. | |||
| \param [in] ticks Number of ticks between two interrupts. | |||
| \return 0 Function succeeded. | |||
| \return 1 Function failed. | |||
| \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the | |||
| function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b> | |||
| must contain a vendor-specific implementation of this function. | |||
| */ | |||
| __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) | |||
| { | |||
| if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) | |||
| { | |||
| return (1UL); /* Reload value impossible */ | |||
| } | |||
| SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ | |||
| NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ | |||
| SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ | |||
| SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | | |||
| SysTick_CTRL_TICKINT_Msk | | |||
| SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ | |||
| return (0UL); /* Function successful */ | |||
| } | |||
| #endif | |||
| /*@} end of CMSIS_Core_SysTickFunctions */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __CORE_CM1_H_DEPENDANT */ | |||
| #endif /* __CMSIS_GENERIC */ | |||
| @@ -0,0 +1,275 @@ | |||
| /****************************************************************************** | |||
| * @file mpu_armv7.h | |||
| * @brief CMSIS MPU API for Armv7-M MPU | |||
| * @version V5.1.2 | |||
| * @date 25. May 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2017-2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef ARM_MPU_ARMV7_H | |||
| #define ARM_MPU_ARMV7_H | |||
| #define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes | |||
| #define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes | |||
| #define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes | |||
| #define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes | |||
| #define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes | |||
| #define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte | |||
| #define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes | |||
| #define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes | |||
| #define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes | |||
| #define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes | |||
| #define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes | |||
| #define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes | |||
| #define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes | |||
| #define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes | |||
| #define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes | |||
| #define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte | |||
| #define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes | |||
| #define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes | |||
| #define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes | |||
| #define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes | |||
| #define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes | |||
| #define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes | |||
| #define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes | |||
| #define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes | |||
| #define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes | |||
| #define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte | |||
| #define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes | |||
| #define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes | |||
| #define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access | |||
| #define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only | |||
| #define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only | |||
| #define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access | |||
| #define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only | |||
| #define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access | |||
| /** MPU Region Base Address Register Value | |||
| * | |||
| * \param Region The region to be configured, number 0 to 15. | |||
| * \param BaseAddress The base address for the region. | |||
| */ | |||
| #define ARM_MPU_RBAR(Region, BaseAddress) \ | |||
| (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \ | |||
| ((Region) & MPU_RBAR_REGION_Msk) | \ | |||
| (MPU_RBAR_VALID_Msk)) | |||
| /** | |||
| * MPU Memory Access Attributes | |||
| * | |||
| * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. | |||
| * \param IsShareable Region is shareable between multiple bus masters. | |||
| * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. | |||
| * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. | |||
| */ | |||
| #define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \ | |||
| ((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \ | |||
| (((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \ | |||
| (((IsCacheable) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \ | |||
| (((IsBufferable) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk)) | |||
| /** | |||
| * MPU Region Attribute and Size Register Value | |||
| * | |||
| * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. | |||
| * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. | |||
| * \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_. | |||
| * \param SubRegionDisable Sub-region disable field. | |||
| * \param Size Region size of the region to be configured, for example 4K, 8K. | |||
| */ | |||
| #define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \ | |||
| ((((DisableExec) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \ | |||
| (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \ | |||
| (((AccessAttributes) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk))) | \ | |||
| (((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \ | |||
| (((Size) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \ | |||
| (((MPU_RASR_ENABLE_Msk)))) | |||
| /** | |||
| * MPU Region Attribute and Size Register Value | |||
| * | |||
| * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. | |||
| * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. | |||
| * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. | |||
| * \param IsShareable Region is shareable between multiple bus masters. | |||
| * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. | |||
| * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. | |||
| * \param SubRegionDisable Sub-region disable field. | |||
| * \param Size Region size of the region to be configured, for example 4K, 8K. | |||
| */ | |||
| #define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \ | |||
| ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size) | |||
| /** | |||
| * MPU Memory Access Attribute for strongly ordered memory. | |||
| * - TEX: 000b | |||
| * - Shareable | |||
| * - Non-cacheable | |||
| * - Non-bufferable | |||
| */ | |||
| #define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U) | |||
| /** | |||
| * MPU Memory Access Attribute for device memory. | |||
| * - TEX: 000b (if shareable) or 010b (if non-shareable) | |||
| * - Shareable or non-shareable | |||
| * - Non-cacheable | |||
| * - Bufferable (if shareable) or non-bufferable (if non-shareable) | |||
| * | |||
| * \param IsShareable Configures the device memory as shareable or non-shareable. | |||
| */ | |||
| #define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U)) | |||
| /** | |||
| * MPU Memory Access Attribute for normal memory. | |||
| * - TEX: 1BBb (reflecting outer cacheability rules) | |||
| * - Shareable or non-shareable | |||
| * - Cacheable or non-cacheable (reflecting inner cacheability rules) | |||
| * - Bufferable or non-bufferable (reflecting inner cacheability rules) | |||
| * | |||
| * \param OuterCp Configures the outer cache policy. | |||
| * \param InnerCp Configures the inner cache policy. | |||
| * \param IsShareable Configures the memory as shareable or non-shareable. | |||
| */ | |||
| #define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) >> 1U), ((InnerCp) & 1U)) | |||
| /** | |||
| * MPU Memory Access Attribute non-cacheable policy. | |||
| */ | |||
| #define ARM_MPU_CACHEP_NOCACHE 0U | |||
| /** | |||
| * MPU Memory Access Attribute write-back, write and read allocate policy. | |||
| */ | |||
| #define ARM_MPU_CACHEP_WB_WRA 1U | |||
| /** | |||
| * MPU Memory Access Attribute write-through, no write allocate policy. | |||
| */ | |||
| #define ARM_MPU_CACHEP_WT_NWA 2U | |||
| /** | |||
| * MPU Memory Access Attribute write-back, no write allocate policy. | |||
| */ | |||
| #define ARM_MPU_CACHEP_WB_NWA 3U | |||
| /** | |||
| * Struct for a single MPU Region | |||
| */ | |||
| typedef struct { | |||
| uint32_t RBAR; //!< The region base address register value (RBAR) | |||
| uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR | |||
| } ARM_MPU_Region_t; | |||
| /** Enable the MPU. | |||
| * \param MPU_Control Default access permissions for unconfigured regions. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) | |||
| { | |||
| __DMB(); | |||
| MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| /** Disable the MPU. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Disable(void) | |||
| { | |||
| __DMB(); | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| /** Clear and disable the given MPU region. | |||
| * \param rnr Region number to be cleared. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) | |||
| { | |||
| MPU->RNR = rnr; | |||
| MPU->RASR = 0U; | |||
| } | |||
| /** Configure an MPU region. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rasr Value for RASR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) | |||
| { | |||
| MPU->RBAR = rbar; | |||
| MPU->RASR = rasr; | |||
| } | |||
| /** Configure the given MPU region. | |||
| * \param rnr Region number to be configured. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rasr Value for RASR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) | |||
| { | |||
| MPU->RNR = rnr; | |||
| MPU->RBAR = rbar; | |||
| MPU->RASR = rasr; | |||
| } | |||
| /** Memcpy with strictly ordered memory access, e.g. used by code in ARM_MPU_Load(). | |||
| * \param dst Destination data is copied to. | |||
| * \param src Source data is copied from. | |||
| * \param len Amount of data words to be copied. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) | |||
| { | |||
| uint32_t i; | |||
| for (i = 0U; i < len; ++i) | |||
| { | |||
| dst[i] = src[i]; | |||
| } | |||
| } | |||
| /** Load the given number of MPU regions from a table. | |||
| * \param table Pointer to the MPU configuration table. | |||
| * \param cnt Amount of regions to be configured. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt) | |||
| { | |||
| const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; | |||
| while (cnt > MPU_TYPE_RALIASES) { | |||
| ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize); | |||
| table += MPU_TYPE_RALIASES; | |||
| cnt -= MPU_TYPE_RALIASES; | |||
| } | |||
| ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize); | |||
| } | |||
| #endif | |||
| @@ -0,0 +1,352 @@ | |||
| /****************************************************************************** | |||
| * @file mpu_armv8.h | |||
| * @brief CMSIS MPU API for Armv8-M and Armv8.1-M MPU | |||
| * @version V5.1.3 | |||
| * @date 03. February 2021 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2017-2021 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef ARM_MPU_ARMV8_H | |||
| #define ARM_MPU_ARMV8_H | |||
| /** \brief Attribute for device memory (outer only) */ | |||
| #define ARM_MPU_ATTR_DEVICE ( 0U ) | |||
| /** \brief Attribute for non-cacheable, normal memory */ | |||
| #define ARM_MPU_ATTR_NON_CACHEABLE ( 4U ) | |||
| /** \brief Attribute for normal memory (outer and inner) | |||
| * \param NT Non-Transient: Set to 1 for non-transient data. | |||
| * \param WB Write-Back: Set to 1 to use write-back update policy. | |||
| * \param RA Read Allocation: Set to 1 to use cache allocation on read miss. | |||
| * \param WA Write Allocation: Set to 1 to use cache allocation on write miss. | |||
| */ | |||
| #define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \ | |||
| ((((NT) & 1U) << 3U) | (((WB) & 1U) << 2U) | (((RA) & 1U) << 1U) | ((WA) & 1U)) | |||
| /** \brief Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement */ | |||
| #define ARM_MPU_ATTR_DEVICE_nGnRnE (0U) | |||
| /** \brief Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement */ | |||
| #define ARM_MPU_ATTR_DEVICE_nGnRE (1U) | |||
| /** \brief Device memory type non Gathering, Re-ordering, Early Write Acknowledgement */ | |||
| #define ARM_MPU_ATTR_DEVICE_nGRE (2U) | |||
| /** \brief Device memory type Gathering, Re-ordering, Early Write Acknowledgement */ | |||
| #define ARM_MPU_ATTR_DEVICE_GRE (3U) | |||
| /** \brief Memory Attribute | |||
| * \param O Outer memory attributes | |||
| * \param I O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes | |||
| */ | |||
| #define ARM_MPU_ATTR(O, I) ((((O) & 0xFU) << 4U) | ((((O) & 0xFU) != 0U) ? ((I) & 0xFU) : (((I) & 0x3U) << 2U))) | |||
| /** \brief Normal memory non-shareable */ | |||
| #define ARM_MPU_SH_NON (0U) | |||
| /** \brief Normal memory outer shareable */ | |||
| #define ARM_MPU_SH_OUTER (2U) | |||
| /** \brief Normal memory inner shareable */ | |||
| #define ARM_MPU_SH_INNER (3U) | |||
| /** \brief Memory access permissions | |||
| * \param RO Read-Only: Set to 1 for read-only memory. | |||
| * \param NP Non-Privileged: Set to 1 for non-privileged memory. | |||
| */ | |||
| #define ARM_MPU_AP_(RO, NP) ((((RO) & 1U) << 1U) | ((NP) & 1U)) | |||
| /** \brief Region Base Address Register value | |||
| * \param BASE The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned. | |||
| * \param SH Defines the Shareability domain for this memory region. | |||
| * \param RO Read-Only: Set to 1 for a read-only memory region. | |||
| * \param NP Non-Privileged: Set to 1 for a non-privileged memory region. | |||
| * \oaram XN eXecute Never: Set to 1 for a non-executable memory region. | |||
| */ | |||
| #define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \ | |||
| (((BASE) & MPU_RBAR_BASE_Msk) | \ | |||
| (((SH) << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \ | |||
| ((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \ | |||
| (((XN) << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk)) | |||
| /** \brief Region Limit Address Register value | |||
| * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended. | |||
| * \param IDX The attribute index to be associated with this memory region. | |||
| */ | |||
| #define ARM_MPU_RLAR(LIMIT, IDX) \ | |||
| (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \ | |||
| (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ | |||
| (MPU_RLAR_EN_Msk)) | |||
| #if defined(MPU_RLAR_PXN_Pos) | |||
| /** \brief Region Limit Address Register with PXN value | |||
| * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended. | |||
| * \param PXN Privileged execute never. Defines whether code can be executed from this privileged region. | |||
| * \param IDX The attribute index to be associated with this memory region. | |||
| */ | |||
| #define ARM_MPU_RLAR_PXN(LIMIT, PXN, IDX) \ | |||
| (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \ | |||
| (((PXN) << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \ | |||
| (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ | |||
| (MPU_RLAR_EN_Msk)) | |||
| #endif | |||
| /** | |||
| * Struct for a single MPU Region | |||
| */ | |||
| typedef struct { | |||
| uint32_t RBAR; /*!< Region Base Address Register value */ | |||
| uint32_t RLAR; /*!< Region Limit Address Register value */ | |||
| } ARM_MPU_Region_t; | |||
| /** Enable the MPU. | |||
| * \param MPU_Control Default access permissions for unconfigured regions. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) | |||
| { | |||
| __DMB(); | |||
| MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| /** Disable the MPU. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Disable(void) | |||
| { | |||
| __DMB(); | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Enable the Non-secure MPU. | |||
| * \param MPU_Control Default access permissions for unconfigured regions. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control) | |||
| { | |||
| __DMB(); | |||
| MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| /** Disable the Non-secure MPU. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Disable_NS(void) | |||
| { | |||
| __DMB(); | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk; | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| /** Set the memory attribute encoding to the given MPU. | |||
| * \param mpu Pointer to the MPU to be configured. | |||
| * \param idx The attribute index to be set [0-7] | |||
| * \param attr The attribute value to be set. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr) | |||
| { | |||
| const uint8_t reg = idx / 4U; | |||
| const uint32_t pos = ((idx % 4U) * 8U); | |||
| const uint32_t mask = 0xFFU << pos; | |||
| if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) { | |||
| return; // invalid index | |||
| } | |||
| mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask)); | |||
| } | |||
| /** Set the memory attribute encoding. | |||
| * \param idx The attribute index to be set [0-7] | |||
| * \param attr The attribute value to be set. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr) | |||
| { | |||
| ARM_MPU_SetMemAttrEx(MPU, idx, attr); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Set the memory attribute encoding to the Non-secure MPU. | |||
| * \param idx The attribute index to be set [0-7] | |||
| * \param attr The attribute value to be set. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr) | |||
| { | |||
| ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr); | |||
| } | |||
| #endif | |||
| /** Clear and disable the given MPU region of the given MPU. | |||
| * \param mpu Pointer to MPU to be used. | |||
| * \param rnr Region number to be cleared. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr) | |||
| { | |||
| mpu->RNR = rnr; | |||
| mpu->RLAR = 0U; | |||
| } | |||
| /** Clear and disable the given MPU region. | |||
| * \param rnr Region number to be cleared. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) | |||
| { | |||
| ARM_MPU_ClrRegionEx(MPU, rnr); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Clear and disable the given Non-secure MPU region. | |||
| * \param rnr Region number to be cleared. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr) | |||
| { | |||
| ARM_MPU_ClrRegionEx(MPU_NS, rnr); | |||
| } | |||
| #endif | |||
| /** Configure the given MPU region of the given MPU. | |||
| * \param mpu Pointer to MPU to be used. | |||
| * \param rnr Region number to be configured. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rlar Value for RLAR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar) | |||
| { | |||
| mpu->RNR = rnr; | |||
| mpu->RBAR = rbar; | |||
| mpu->RLAR = rlar; | |||
| } | |||
| /** Configure the given MPU region. | |||
| * \param rnr Region number to be configured. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rlar Value for RLAR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar) | |||
| { | |||
| ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Configure the given Non-secure MPU region. | |||
| * \param rnr Region number to be configured. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rlar Value for RLAR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar) | |||
| { | |||
| ARM_MPU_SetRegionEx(MPU_NS, rnr, rbar, rlar); | |||
| } | |||
| #endif | |||
| /** Memcpy with strictly ordered memory access, e.g. used by code in ARM_MPU_LoadEx() | |||
| * \param dst Destination data is copied to. | |||
| * \param src Source data is copied from. | |||
| * \param len Amount of data words to be copied. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) | |||
| { | |||
| uint32_t i; | |||
| for (i = 0U; i < len; ++i) | |||
| { | |||
| dst[i] = src[i]; | |||
| } | |||
| } | |||
| /** Load the given number of MPU regions from a table to the given MPU. | |||
| * \param mpu Pointer to the MPU registers to be used. | |||
| * \param rnr First region number to be configured. | |||
| * \param table Pointer to the MPU configuration table. | |||
| * \param cnt Amount of regions to be configured. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) | |||
| { | |||
| const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; | |||
| if (cnt == 1U) { | |||
| mpu->RNR = rnr; | |||
| ARM_MPU_OrderedMemcpy(&(mpu->RBAR), &(table->RBAR), rowWordSize); | |||
| } else { | |||
| uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U); | |||
| uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES; | |||
| mpu->RNR = rnrBase; | |||
| while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) { | |||
| uint32_t c = MPU_TYPE_RALIASES - rnrOffset; | |||
| ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), c*rowWordSize); | |||
| table += c; | |||
| cnt -= c; | |||
| rnrOffset = 0U; | |||
| rnrBase += MPU_TYPE_RALIASES; | |||
| mpu->RNR = rnrBase; | |||
| } | |||
| ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), cnt*rowWordSize); | |||
| } | |||
| } | |||
| /** Load the given number of MPU regions from a table. | |||
| * \param rnr First region number to be configured. | |||
| * \param table Pointer to the MPU configuration table. | |||
| * \param cnt Amount of regions to be configured. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) | |||
| { | |||
| ARM_MPU_LoadEx(MPU, rnr, table, cnt); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Load the given number of MPU regions from a table to the Non-secure MPU. | |||
| * \param rnr First region number to be configured. | |||
| * \param table Pointer to the MPU configuration table. | |||
| * \param cnt Amount of regions to be configured. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) | |||
| { | |||
| ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt); | |||
| } | |||
| #endif | |||
| #endif | |||
| @@ -0,0 +1,206 @@ | |||
| /****************************************************************************** | |||
| * @file pac_armv81.h | |||
| * @brief CMSIS PAC key functions for Armv8.1-M PAC extension | |||
| * @version V1.0.0 | |||
| * @date 23. March 2022 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2022 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef PAC_ARMV81_H | |||
| #define PAC_ARMV81_H | |||
| /* ################### PAC Key functions ########################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_PacKeyFunctions PAC Key functions | |||
| \brief Functions that access the PAC keys. | |||
| @{ | |||
| */ | |||
| #if (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1)) | |||
| /** | |||
| \brief read the PAC key used for privileged mode | |||
| \details Reads the PAC key stored in the PAC_KEY_P registers. | |||
| \param [out] pPacKey 128bit PAC key | |||
| */ | |||
| __STATIC_FORCEINLINE void __get_PAC_KEY_P (uint32_t* pPacKey) { | |||
| __ASM volatile ( | |||
| "mrs r1, pac_key_p_0\n" | |||
| "str r1,[%0,#0]\n" | |||
| "mrs r1, pac_key_p_1\n" | |||
| "str r1,[%0,#4]\n" | |||
| "mrs r1, pac_key_p_2\n" | |||
| "str r1,[%0,#8]\n" | |||
| "mrs r1, pac_key_p_3\n" | |||
| "str r1,[%0,#12]\n" | |||
| : : "r" (pPacKey) : "memory", "r1" | |||
| ); | |||
| } | |||
| /** | |||
| \brief write the PAC key used for privileged mode | |||
| \details writes the given PAC key to the PAC_KEY_P registers. | |||
| \param [in] pPacKey 128bit PAC key | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_PAC_KEY_P (uint32_t* pPacKey) { | |||
| __ASM volatile ( | |||
| "ldr r1,[%0,#0]\n" | |||
| "msr pac_key_p_0, r1\n" | |||
| "ldr r1,[%0,#4]\n" | |||
| "msr pac_key_p_1, r1\n" | |||
| "ldr r1,[%0,#8]\n" | |||
| "msr pac_key_p_2, r1\n" | |||
| "ldr r1,[%0,#12]\n" | |||
| "msr pac_key_p_3, r1\n" | |||
| : : "r" (pPacKey) : "memory", "r1" | |||
| ); | |||
| } | |||
| /** | |||
| \brief read the PAC key used for unprivileged mode | |||
| \details Reads the PAC key stored in the PAC_KEY_U registers. | |||
| \param [out] pPacKey 128bit PAC key | |||
| */ | |||
| __STATIC_FORCEINLINE void __get_PAC_KEY_U (uint32_t* pPacKey) { | |||
| __ASM volatile ( | |||
| "mrs r1, pac_key_u_0\n" | |||
| "str r1,[%0,#0]\n" | |||
| "mrs r1, pac_key_u_1\n" | |||
| "str r1,[%0,#4]\n" | |||
| "mrs r1, pac_key_u_2\n" | |||
| "str r1,[%0,#8]\n" | |||
| "mrs r1, pac_key_u_3\n" | |||
| "str r1,[%0,#12]\n" | |||
| : : "r" (pPacKey) : "memory", "r1" | |||
| ); | |||
| } | |||
| /** | |||
| \brief write the PAC key used for unprivileged mode | |||
| \details writes the given PAC key to the PAC_KEY_U registers. | |||
| \param [in] pPacKey 128bit PAC key | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_PAC_KEY_U (uint32_t* pPacKey) { | |||
| __ASM volatile ( | |||
| "ldr r1,[%0,#0]\n" | |||
| "msr pac_key_u_0, r1\n" | |||
| "ldr r1,[%0,#4]\n" | |||
| "msr pac_key_u_1, r1\n" | |||
| "ldr r1,[%0,#8]\n" | |||
| "msr pac_key_u_2, r1\n" | |||
| "ldr r1,[%0,#12]\n" | |||
| "msr pac_key_u_3, r1\n" | |||
| : : "r" (pPacKey) : "memory", "r1" | |||
| ); | |||
| } | |||
| #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) | |||
| /** | |||
| \brief read the PAC key used for privileged mode (non-secure) | |||
| \details Reads the PAC key stored in the non-secure PAC_KEY_P registers when in secure mode. | |||
| \param [out] pPacKey 128bit PAC key | |||
| */ | |||
| __STATIC_FORCEINLINE void __TZ_get_PAC_KEY_P_NS (uint32_t* pPacKey) { | |||
| __ASM volatile ( | |||
| "mrs r1, pac_key_p_0_ns\n" | |||
| "str r1,[%0,#0]\n" | |||
| "mrs r1, pac_key_p_1_ns\n" | |||
| "str r1,[%0,#4]\n" | |||
| "mrs r1, pac_key_p_2_ns\n" | |||
| "str r1,[%0,#8]\n" | |||
| "mrs r1, pac_key_p_3_ns\n" | |||
| "str r1,[%0,#12]\n" | |||
| : : "r" (pPacKey) : "memory", "r1" | |||
| ); | |||
| } | |||
| /** | |||
| \brief write the PAC key used for privileged mode (non-secure) | |||
| \details writes the given PAC key to the non-secure PAC_KEY_P registers when in secure mode. | |||
| \param [in] pPacKey 128bit PAC key | |||
| */ | |||
| __STATIC_FORCEINLINE void __TZ_set_PAC_KEY_P_NS (uint32_t* pPacKey) { | |||
| __ASM volatile ( | |||
| "ldr r1,[%0,#0]\n" | |||
| "msr pac_key_p_0_ns, r1\n" | |||
| "ldr r1,[%0,#4]\n" | |||
| "msr pac_key_p_1_ns, r1\n" | |||
| "ldr r1,[%0,#8]\n" | |||
| "msr pac_key_p_2_ns, r1\n" | |||
| "ldr r1,[%0,#12]\n" | |||
| "msr pac_key_p_3_ns, r1\n" | |||
| : : "r" (pPacKey) : "memory", "r1" | |||
| ); | |||
| } | |||
| /** | |||
| \brief read the PAC key used for unprivileged mode (non-secure) | |||
| \details Reads the PAC key stored in the non-secure PAC_KEY_U registers when in secure mode. | |||
| \param [out] pPacKey 128bit PAC key | |||
| */ | |||
| __STATIC_FORCEINLINE void __TZ_get_PAC_KEY_U_NS (uint32_t* pPacKey) { | |||
| __ASM volatile ( | |||
| "mrs r1, pac_key_u_0_ns\n" | |||
| "str r1,[%0,#0]\n" | |||
| "mrs r1, pac_key_u_1_ns\n" | |||
| "str r1,[%0,#4]\n" | |||
| "mrs r1, pac_key_u_2_ns\n" | |||
| "str r1,[%0,#8]\n" | |||
| "mrs r1, pac_key_u_3_ns\n" | |||
| "str r1,[%0,#12]\n" | |||
| : : "r" (pPacKey) : "memory", "r1" | |||
| ); | |||
| } | |||
| /** | |||
| \brief write the PAC key used for unprivileged mode (non-secure) | |||
| \details writes the given PAC key to the non-secure PAC_KEY_U registers when in secure mode. | |||
| \param [in] pPacKey 128bit PAC key | |||
| */ | |||
| __STATIC_FORCEINLINE void __TZ_set_PAC_KEY_U_NS (uint32_t* pPacKey) { | |||
| __ASM volatile ( | |||
| "ldr r1,[%0,#0]\n" | |||
| "msr pac_key_u_0_ns, r1\n" | |||
| "ldr r1,[%0,#4]\n" | |||
| "msr pac_key_u_1_ns, r1\n" | |||
| "ldr r1,[%0,#8]\n" | |||
| "msr pac_key_u_2_ns, r1\n" | |||
| "ldr r1,[%0,#12]\n" | |||
| "msr pac_key_u_3_ns, r1\n" | |||
| : : "r" (pPacKey) : "memory", "r1" | |||
| ); | |||
| } | |||
| #endif /* (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) */ | |||
| #endif /* (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1)) */ | |||
| /*@} end of CMSIS_Core_PacKeyFunctions */ | |||
| #endif /* PAC_ARMV81_H */ | |||
| @@ -0,0 +1,337 @@ | |||
| /****************************************************************************** | |||
| * @file pmu_armv8.h | |||
| * @brief CMSIS PMU API for Armv8.1-M PMU | |||
| * @version V1.0.1 | |||
| * @date 15. April 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef ARM_PMU_ARMV8_H | |||
| #define ARM_PMU_ARMV8_H | |||
| /** | |||
| * \brief PMU Events | |||
| * \note See the Armv8.1-M Architecture Reference Manual for full details on these PMU events. | |||
| * */ | |||
| #define ARM_PMU_SW_INCR 0x0000 /*!< Software update to the PMU_SWINC register, architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_L1I_CACHE_REFILL 0x0001 /*!< L1 I-Cache refill */ | |||
| #define ARM_PMU_L1D_CACHE_REFILL 0x0003 /*!< L1 D-Cache refill */ | |||
| #define ARM_PMU_L1D_CACHE 0x0004 /*!< L1 D-Cache access */ | |||
| #define ARM_PMU_LD_RETIRED 0x0006 /*!< Memory-reading instruction architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_ST_RETIRED 0x0007 /*!< Memory-writing instruction architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_INST_RETIRED 0x0008 /*!< Instruction architecturally executed */ | |||
| #define ARM_PMU_EXC_TAKEN 0x0009 /*!< Exception entry */ | |||
| #define ARM_PMU_EXC_RETURN 0x000A /*!< Exception return instruction architecturally executed and the condition code check pass */ | |||
| #define ARM_PMU_PC_WRITE_RETIRED 0x000C /*!< Software change to the Program Counter (PC). Instruction is architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_BR_IMMED_RETIRED 0x000D /*!< Immediate branch architecturally executed */ | |||
| #define ARM_PMU_BR_RETURN_RETIRED 0x000E /*!< Function return instruction architecturally executed and the condition code check pass */ | |||
| #define ARM_PMU_UNALIGNED_LDST_RETIRED 0x000F /*!< Unaligned memory memory-reading or memory-writing instruction architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_BR_MIS_PRED 0x0010 /*!< Mispredicted or not predicted branch speculatively executed */ | |||
| #define ARM_PMU_CPU_CYCLES 0x0011 /*!< Cycle */ | |||
| #define ARM_PMU_BR_PRED 0x0012 /*!< Predictable branch speculatively executed */ | |||
| #define ARM_PMU_MEM_ACCESS 0x0013 /*!< Data memory access */ | |||
| #define ARM_PMU_L1I_CACHE 0x0014 /*!< Level 1 instruction cache access */ | |||
| #define ARM_PMU_L1D_CACHE_WB 0x0015 /*!< Level 1 data cache write-back */ | |||
| #define ARM_PMU_L2D_CACHE 0x0016 /*!< Level 2 data cache access */ | |||
| #define ARM_PMU_L2D_CACHE_REFILL 0x0017 /*!< Level 2 data cache refill */ | |||
| #define ARM_PMU_L2D_CACHE_WB 0x0018 /*!< Level 2 data cache write-back */ | |||
| #define ARM_PMU_BUS_ACCESS 0x0019 /*!< Bus access */ | |||
| #define ARM_PMU_MEMORY_ERROR 0x001A /*!< Local memory error */ | |||
| #define ARM_PMU_INST_SPEC 0x001B /*!< Instruction speculatively executed */ | |||
| #define ARM_PMU_BUS_CYCLES 0x001D /*!< Bus cycles */ | |||
| #define ARM_PMU_CHAIN 0x001E /*!< For an odd numbered counter, increment when an overflow occurs on the preceding even-numbered counter on the same PE */ | |||
| #define ARM_PMU_L1D_CACHE_ALLOCATE 0x001F /*!< Level 1 data cache allocation without refill */ | |||
| #define ARM_PMU_L2D_CACHE_ALLOCATE 0x0020 /*!< Level 2 data cache allocation without refill */ | |||
| #define ARM_PMU_BR_RETIRED 0x0021 /*!< Branch instruction architecturally executed */ | |||
| #define ARM_PMU_BR_MIS_PRED_RETIRED 0x0022 /*!< Mispredicted branch instruction architecturally executed */ | |||
| #define ARM_PMU_STALL_FRONTEND 0x0023 /*!< No operation issued because of the frontend */ | |||
| #define ARM_PMU_STALL_BACKEND 0x0024 /*!< No operation issued because of the backend */ | |||
| #define ARM_PMU_L2I_CACHE 0x0027 /*!< Level 2 instruction cache access */ | |||
| #define ARM_PMU_L2I_CACHE_REFILL 0x0028 /*!< Level 2 instruction cache refill */ | |||
| #define ARM_PMU_L3D_CACHE_ALLOCATE 0x0029 /*!< Level 3 data cache allocation without refill */ | |||
| #define ARM_PMU_L3D_CACHE_REFILL 0x002A /*!< Level 3 data cache refill */ | |||
| #define ARM_PMU_L3D_CACHE 0x002B /*!< Level 3 data cache access */ | |||
| #define ARM_PMU_L3D_CACHE_WB 0x002C /*!< Level 3 data cache write-back */ | |||
| #define ARM_PMU_LL_CACHE_RD 0x0036 /*!< Last level data cache read */ | |||
| #define ARM_PMU_LL_CACHE_MISS_RD 0x0037 /*!< Last level data cache read miss */ | |||
| #define ARM_PMU_L1D_CACHE_MISS_RD 0x0039 /*!< Level 1 data cache read miss */ | |||
| #define ARM_PMU_OP_COMPLETE 0x003A /*!< Operation retired */ | |||
| #define ARM_PMU_OP_SPEC 0x003B /*!< Operation speculatively executed */ | |||
| #define ARM_PMU_STALL 0x003C /*!< Stall cycle for instruction or operation not sent for execution */ | |||
| #define ARM_PMU_STALL_OP_BACKEND 0x003D /*!< Stall cycle for instruction or operation not sent for execution due to pipeline backend */ | |||
| #define ARM_PMU_STALL_OP_FRONTEND 0x003E /*!< Stall cycle for instruction or operation not sent for execution due to pipeline frontend */ | |||
| #define ARM_PMU_STALL_OP 0x003F /*!< Instruction or operation slots not occupied each cycle */ | |||
| #define ARM_PMU_L1D_CACHE_RD 0x0040 /*!< Level 1 data cache read */ | |||
| #define ARM_PMU_LE_RETIRED 0x0100 /*!< Loop end instruction executed */ | |||
| #define ARM_PMU_LE_SPEC 0x0101 /*!< Loop end instruction speculatively executed */ | |||
| #define ARM_PMU_BF_RETIRED 0x0104 /*!< Branch future instruction architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_BF_SPEC 0x0105 /*!< Branch future instruction speculatively executed and condition code check pass */ | |||
| #define ARM_PMU_LE_CANCEL 0x0108 /*!< Loop end instruction not taken */ | |||
| #define ARM_PMU_BF_CANCEL 0x0109 /*!< Branch future instruction not taken */ | |||
| #define ARM_PMU_SE_CALL_S 0x0114 /*!< Call to secure function, resulting in Security state change */ | |||
| #define ARM_PMU_SE_CALL_NS 0x0115 /*!< Call to non-secure function, resulting in Security state change */ | |||
| #define ARM_PMU_DWT_CMPMATCH0 0x0118 /*!< DWT comparator 0 match */ | |||
| #define ARM_PMU_DWT_CMPMATCH1 0x0119 /*!< DWT comparator 1 match */ | |||
| #define ARM_PMU_DWT_CMPMATCH2 0x011A /*!< DWT comparator 2 match */ | |||
| #define ARM_PMU_DWT_CMPMATCH3 0x011B /*!< DWT comparator 3 match */ | |||
| #define ARM_PMU_MVE_INST_RETIRED 0x0200 /*!< MVE instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_INST_SPEC 0x0201 /*!< MVE instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_FP_RETIRED 0x0204 /*!< MVE floating-point instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_FP_SPEC 0x0205 /*!< MVE floating-point instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_FP_HP_RETIRED 0x0208 /*!< MVE half-precision floating-point instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_FP_HP_SPEC 0x0209 /*!< MVE half-precision floating-point instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_FP_SP_RETIRED 0x020C /*!< MVE single-precision floating-point instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_FP_SP_SPEC 0x020D /*!< MVE single-precision floating-point instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_FP_MAC_RETIRED 0x0214 /*!< MVE floating-point multiply or multiply-accumulate instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_FP_MAC_SPEC 0x0215 /*!< MVE floating-point multiply or multiply-accumulate instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_INT_RETIRED 0x0224 /*!< MVE integer instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_INT_SPEC 0x0225 /*!< MVE integer instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_INT_MAC_RETIRED 0x0228 /*!< MVE multiply or multiply-accumulate instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_INT_MAC_SPEC 0x0229 /*!< MVE multiply or multiply-accumulate instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_RETIRED 0x0238 /*!< MVE load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_SPEC 0x0239 /*!< MVE load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_RETIRED 0x023C /*!< MVE load instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_SPEC 0x023D /*!< MVE load instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_RETIRED 0x0240 /*!< MVE store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_SPEC 0x0241 /*!< MVE store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_CONTIG_RETIRED 0x0244 /*!< MVE contiguous load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_CONTIG_SPEC 0x0245 /*!< MVE contiguous load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_CONTIG_RETIRED 0x0248 /*!< MVE contiguous load instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_CONTIG_SPEC 0x0249 /*!< MVE contiguous load instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_CONTIG_RETIRED 0x024C /*!< MVE contiguous store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_CONTIG_SPEC 0x024D /*!< MVE contiguous store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_NONCONTIG_RETIRED 0x0250 /*!< MVE non-contiguous load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_NONCONTIG_SPEC 0x0251 /*!< MVE non-contiguous load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_NONCONTIG_RETIRED 0x0254 /*!< MVE non-contiguous load instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_NONCONTIG_SPEC 0x0255 /*!< MVE non-contiguous load instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_NONCONTIG_RETIRED 0x0258 /*!< MVE non-contiguous store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_NONCONTIG_SPEC 0x0259 /*!< MVE non-contiguous store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_MULTI_RETIRED 0x025C /*!< MVE memory instruction targeting multiple registers architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_MULTI_SPEC 0x025D /*!< MVE memory instruction targeting multiple registers speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_MULTI_RETIRED 0x0260 /*!< MVE memory load instruction targeting multiple registers architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_MULTI_SPEC 0x0261 /*!< MVE memory load instruction targeting multiple registers speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_MULTI_RETIRED 0x0261 /*!< MVE memory store instruction targeting multiple registers architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_MULTI_SPEC 0x0265 /*!< MVE memory store instruction targeting multiple registers speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_UNALIGNED_RETIRED 0x028C /*!< MVE unaligned memory load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_UNALIGNED_SPEC 0x028D /*!< MVE unaligned memory load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_UNALIGNED_RETIRED 0x0290 /*!< MVE unaligned load instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_UNALIGNED_SPEC 0x0291 /*!< MVE unaligned load instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_UNALIGNED_RETIRED 0x0294 /*!< MVE unaligned store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_UNALIGNED_SPEC 0x0295 /*!< MVE unaligned store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_UNALIGNED_NONCONTIG_RETIRED 0x0298 /*!< MVE unaligned noncontiguous load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_UNALIGNED_NONCONTIG_SPEC 0x0299 /*!< MVE unaligned noncontiguous load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_RETIRED 0x02A0 /*!< MVE vector reduction instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_SPEC 0x02A1 /*!< MVE vector reduction instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_FP_RETIRED 0x02A4 /*!< MVE floating-point vector reduction instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_FP_SPEC 0x02A5 /*!< MVE floating-point vector reduction instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_INT_RETIRED 0x02A8 /*!< MVE integer vector reduction instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_INT_SPEC 0x02A9 /*!< MVE integer vector reduction instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_PRED 0x02B8 /*!< Cycles where one or more predicated beats architecturally executed */ | |||
| #define ARM_PMU_MVE_STALL 0x02CC /*!< Stall cycles caused by an MVE instruction */ | |||
| #define ARM_PMU_MVE_STALL_RESOURCE 0x02CD /*!< Stall cycles caused by an MVE instruction because of resource conflicts */ | |||
| #define ARM_PMU_MVE_STALL_RESOURCE_MEM 0x02CE /*!< Stall cycles caused by an MVE instruction because of memory resource conflicts */ | |||
| #define ARM_PMU_MVE_STALL_RESOURCE_FP 0x02CF /*!< Stall cycles caused by an MVE instruction because of floating-point resource conflicts */ | |||
| #define ARM_PMU_MVE_STALL_RESOURCE_INT 0x02D0 /*!< Stall cycles caused by an MVE instruction because of integer resource conflicts */ | |||
| #define ARM_PMU_MVE_STALL_BREAK 0x02D3 /*!< Stall cycles caused by an MVE chain break */ | |||
| #define ARM_PMU_MVE_STALL_DEPENDENCY 0x02D4 /*!< Stall cycles caused by MVE register dependency */ | |||
| #define ARM_PMU_ITCM_ACCESS 0x4007 /*!< Instruction TCM access */ | |||
| #define ARM_PMU_DTCM_ACCESS 0x4008 /*!< Data TCM access */ | |||
| #define ARM_PMU_TRCEXTOUT0 0x4010 /*!< ETM external output 0 */ | |||
| #define ARM_PMU_TRCEXTOUT1 0x4011 /*!< ETM external output 1 */ | |||
| #define ARM_PMU_TRCEXTOUT2 0x4012 /*!< ETM external output 2 */ | |||
| #define ARM_PMU_TRCEXTOUT3 0x4013 /*!< ETM external output 3 */ | |||
| #define ARM_PMU_CTI_TRIGOUT4 0x4018 /*!< Cross-trigger Interface output trigger 4 */ | |||
| #define ARM_PMU_CTI_TRIGOUT5 0x4019 /*!< Cross-trigger Interface output trigger 5 */ | |||
| #define ARM_PMU_CTI_TRIGOUT6 0x401A /*!< Cross-trigger Interface output trigger 6 */ | |||
| #define ARM_PMU_CTI_TRIGOUT7 0x401B /*!< Cross-trigger Interface output trigger 7 */ | |||
| /** \brief PMU Functions */ | |||
| __STATIC_INLINE void ARM_PMU_Enable(void); | |||
| __STATIC_INLINE void ARM_PMU_Disable(void); | |||
| __STATIC_INLINE void ARM_PMU_Set_EVTYPER(uint32_t num, uint32_t type); | |||
| __STATIC_INLINE void ARM_PMU_CYCCNT_Reset(void); | |||
| __STATIC_INLINE void ARM_PMU_EVCNTR_ALL_Reset(void); | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Enable(uint32_t mask); | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Disable(uint32_t mask); | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_CCNTR(void); | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_EVCNTR(uint32_t num); | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_CNTR_OVS(void); | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_OVS(uint32_t mask); | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Enable(uint32_t mask); | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask); | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask); | |||
| /** | |||
| \brief Enable the PMU | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Enable(void) | |||
| { | |||
| PMU->CTRL |= PMU_CTRL_ENABLE_Msk; | |||
| } | |||
| /** | |||
| \brief Disable the PMU | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Disable(void) | |||
| { | |||
| PMU->CTRL &= ~PMU_CTRL_ENABLE_Msk; | |||
| } | |||
| /** | |||
| \brief Set event to count for PMU eventer counter | |||
| \param [in] num Event counter (0-30) to configure | |||
| \param [in] type Event to count | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Set_EVTYPER(uint32_t num, uint32_t type) | |||
| { | |||
| PMU->EVTYPER[num] = type; | |||
| } | |||
| /** | |||
| \brief Reset cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_CYCCNT_Reset(void) | |||
| { | |||
| PMU->CTRL |= PMU_CTRL_CYCCNT_RESET_Msk; | |||
| } | |||
| /** | |||
| \brief Reset all event counters | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_EVCNTR_ALL_Reset(void) | |||
| { | |||
| PMU->CTRL |= PMU_CTRL_EVENTCNT_RESET_Msk; | |||
| } | |||
| /** | |||
| \brief Enable counters | |||
| \param [in] mask Counters to enable | |||
| \note Enables one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Enable(uint32_t mask) | |||
| { | |||
| PMU->CNTENSET = mask; | |||
| } | |||
| /** | |||
| \brief Disable counters | |||
| \param [in] mask Counters to enable | |||
| \note Disables one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Disable(uint32_t mask) | |||
| { | |||
| PMU->CNTENCLR = mask; | |||
| } | |||
| /** | |||
| \brief Read cycle counter | |||
| \return Cycle count | |||
| */ | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_CCNTR(void) | |||
| { | |||
| return PMU->CCNTR; | |||
| } | |||
| /** | |||
| \brief Read event counter | |||
| \param [in] num Event counter (0-30) to read | |||
| \return Event count | |||
| */ | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_EVCNTR(uint32_t num) | |||
| { | |||
| return PMU_EVCNTR_CNT_Msk & PMU->EVCNTR[num]; | |||
| } | |||
| /** | |||
| \brief Read counter overflow status | |||
| \return Counter overflow status bits for the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_CNTR_OVS(void) | |||
| { | |||
| return PMU->OVSSET; | |||
| } | |||
| /** | |||
| \brief Clear counter overflow status | |||
| \param [in] mask Counter overflow status bits to clear | |||
| \note Clears overflow status bits for one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_OVS(uint32_t mask) | |||
| { | |||
| PMU->OVSCLR = mask; | |||
| } | |||
| /** | |||
| \brief Enable counter overflow interrupt request | |||
| \param [in] mask Counter overflow interrupt request bits to set | |||
| \note Sets overflow interrupt request bits for one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Enable(uint32_t mask) | |||
| { | |||
| PMU->INTENSET = mask; | |||
| } | |||
| /** | |||
| \brief Disable counter overflow interrupt request | |||
| \param [in] mask Counter overflow interrupt request bits to clear | |||
| \note Clears overflow interrupt request bits for one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask) | |||
| { | |||
| PMU->INTENCLR = mask; | |||
| } | |||
| /** | |||
| \brief Software increment event counter | |||
| \param [in] mask Counters to increment | |||
| \note Software increment bits for one or more event counters (0-30) | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask) | |||
| { | |||
| PMU->SWINC = mask; | |||
| } | |||
| #endif | |||
| @@ -0,0 +1,70 @@ | |||
| /****************************************************************************** | |||
| * @file tz_context.h | |||
| * @brief Context Management for Armv8-M TrustZone | |||
| * @version V1.0.1 | |||
| * @date 10. January 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2017-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef TZ_CONTEXT_H | |||
| #define TZ_CONTEXT_H | |||
| #include <stdint.h> | |||
| #ifndef TZ_MODULEID_T | |||
| #define TZ_MODULEID_T | |||
| /// \details Data type that identifies secure software modules called by a process. | |||
| typedef uint32_t TZ_ModuleId_t; | |||
| #endif | |||
| /// \details TZ Memory ID identifies an allocated memory slot. | |||
| typedef uint32_t TZ_MemoryId_t; | |||
| /// Initialize secure context memory system | |||
| /// \return execution status (1: success, 0: error) | |||
| uint32_t TZ_InitContextSystem_S (void); | |||
| /// Allocate context memory for calling secure software modules in TrustZone | |||
| /// \param[in] module identifies software modules called from non-secure mode | |||
| /// \return value != 0 id TrustZone memory slot identifier | |||
| /// \return value 0 no memory available or internal error | |||
| TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); | |||
| /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); | |||
| /// Load secure context (called on RTOS thread context switch) | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); | |||
| /// Store secure context (called on RTOS thread context switch) | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); | |||
| #endif // TZ_CONTEXT_H | |||
| @@ -0,0 +1,58 @@ | |||
| /****************************************************************************** | |||
| * @file main_s.c | |||
| * @brief Code template for secure main function | |||
| * @version V1.1.1 | |||
| * @date 10. January 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2013-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| /* Use CMSE intrinsics */ | |||
| #include <arm_cmse.h> | |||
| #include "RTE_Components.h" | |||
| #include CMSIS_device_header | |||
| /* TZ_START_NS: Start address of non-secure application */ | |||
| #ifndef TZ_START_NS | |||
| #define TZ_START_NS (0x200000U) | |||
| #endif | |||
| /* typedef for non-secure callback functions */ | |||
| typedef void (*funcptr_void) (void) __attribute__((cmse_nonsecure_call)); | |||
| /* Secure main() */ | |||
| int main(void) { | |||
| funcptr_void NonSecure_ResetHandler; | |||
| /* Add user setup code for secure part here*/ | |||
| /* Set non-secure main stack (MSP_NS) */ | |||
| __TZ_set_MSP_NS(*((uint32_t *)(TZ_START_NS))); | |||
| /* Get non-secure reset handler */ | |||
| NonSecure_ResetHandler = (funcptr_void)(*((uint32_t *)((TZ_START_NS) + 4U))); | |||
| /* Start non-secure state software application */ | |||
| NonSecure_ResetHandler(); | |||
| /* Non-secure software does not return, this code is not executed */ | |||
| while (1) { | |||
| __NOP(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,200 @@ | |||
| /****************************************************************************** | |||
| * @file tz_context.c | |||
| * @brief Context Management for Armv8-M TrustZone - Sample implementation | |||
| * @version V1.1.1 | |||
| * @date 10. January 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2016-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "RTE_Components.h" | |||
| #include CMSIS_device_header | |||
| #include "tz_context.h" | |||
| /// Number of process slots (threads may call secure library code) | |||
| #ifndef TZ_PROCESS_STACK_SLOTS | |||
| #define TZ_PROCESS_STACK_SLOTS 8U | |||
| #endif | |||
| /// Stack size of the secure library code | |||
| #ifndef TZ_PROCESS_STACK_SIZE | |||
| #define TZ_PROCESS_STACK_SIZE 256U | |||
| #endif | |||
| typedef struct { | |||
| uint32_t sp_top; // stack space top | |||
| uint32_t sp_limit; // stack space limit | |||
| uint32_t sp; // current stack pointer | |||
| } stack_info_t; | |||
| static stack_info_t ProcessStackInfo [TZ_PROCESS_STACK_SLOTS]; | |||
| static uint64_t ProcessStackMemory[TZ_PROCESS_STACK_SLOTS][TZ_PROCESS_STACK_SIZE/8U]; | |||
| static uint32_t ProcessStackFreeSlot = 0xFFFFFFFFU; | |||
| /// Initialize secure context memory system | |||
| /// \return execution status (1: success, 0: error) | |||
| __attribute__((cmse_nonsecure_entry)) | |||
| uint32_t TZ_InitContextSystem_S (void) { | |||
| uint32_t n; | |||
| if (__get_IPSR() == 0U) { | |||
| return 0U; // Thread Mode | |||
| } | |||
| for (n = 0U; n < TZ_PROCESS_STACK_SLOTS; n++) { | |||
| ProcessStackInfo[n].sp = 0U; | |||
| ProcessStackInfo[n].sp_limit = (uint32_t)&ProcessStackMemory[n]; | |||
| ProcessStackInfo[n].sp_top = (uint32_t)&ProcessStackMemory[n] + TZ_PROCESS_STACK_SIZE; | |||
| *((uint32_t *)ProcessStackMemory[n]) = n + 1U; | |||
| } | |||
| *((uint32_t *)ProcessStackMemory[--n]) = 0xFFFFFFFFU; | |||
| ProcessStackFreeSlot = 0U; | |||
| // Default process stack pointer and stack limit | |||
| __set_PSPLIM((uint32_t)ProcessStackMemory); | |||
| __set_PSP ((uint32_t)ProcessStackMemory); | |||
| // Privileged Thread Mode using PSP | |||
| __set_CONTROL(0x02U); | |||
| return 1U; // Success | |||
| } | |||
| /// Allocate context memory for calling secure software modules in TrustZone | |||
| /// \param[in] module identifies software modules called from non-secure mode | |||
| /// \return value != 0 id TrustZone memory slot identifier | |||
| /// \return value 0 no memory available or internal error | |||
| __attribute__((cmse_nonsecure_entry)) | |||
| TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module) { | |||
| uint32_t slot; | |||
| (void)module; // Ignore (fixed Stack size) | |||
| if (__get_IPSR() == 0U) { | |||
| return 0U; // Thread Mode | |||
| } | |||
| if (ProcessStackFreeSlot == 0xFFFFFFFFU) { | |||
| return 0U; // No slot available | |||
| } | |||
| slot = ProcessStackFreeSlot; | |||
| ProcessStackFreeSlot = *((uint32_t *)ProcessStackMemory[slot]); | |||
| ProcessStackInfo[slot].sp = ProcessStackInfo[slot].sp_top; | |||
| return (slot + 1U); | |||
| } | |||
| /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| __attribute__((cmse_nonsecure_entry)) | |||
| uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id) { | |||
| uint32_t slot; | |||
| if (__get_IPSR() == 0U) { | |||
| return 0U; // Thread Mode | |||
| } | |||
| if ((id == 0U) || (id > TZ_PROCESS_STACK_SLOTS)) { | |||
| return 0U; // Invalid ID | |||
| } | |||
| slot = id - 1U; | |||
| if (ProcessStackInfo[slot].sp == 0U) { | |||
| return 0U; // Inactive slot | |||
| } | |||
| ProcessStackInfo[slot].sp = 0U; | |||
| *((uint32_t *)ProcessStackMemory[slot]) = ProcessStackFreeSlot; | |||
| ProcessStackFreeSlot = slot; | |||
| return 1U; // Success | |||
| } | |||
| /// Load secure context (called on RTOS thread context switch) | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| __attribute__((cmse_nonsecure_entry)) | |||
| uint32_t TZ_LoadContext_S (TZ_MemoryId_t id) { | |||
| uint32_t slot; | |||
| if ((__get_IPSR() == 0U) || ((__get_CONTROL() & 2U) == 0U)) { | |||
| return 0U; // Thread Mode or using Main Stack for threads | |||
| } | |||
| if ((id == 0U) || (id > TZ_PROCESS_STACK_SLOTS)) { | |||
| return 0U; // Invalid ID | |||
| } | |||
| slot = id - 1U; | |||
| if (ProcessStackInfo[slot].sp == 0U) { | |||
| return 0U; // Inactive slot | |||
| } | |||
| // Setup process stack pointer and stack limit | |||
| __set_PSPLIM(ProcessStackInfo[slot].sp_limit); | |||
| __set_PSP (ProcessStackInfo[slot].sp); | |||
| return 1U; // Success | |||
| } | |||
| /// Store secure context (called on RTOS thread context switch) | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| __attribute__((cmse_nonsecure_entry)) | |||
| uint32_t TZ_StoreContext_S (TZ_MemoryId_t id) { | |||
| uint32_t slot; | |||
| uint32_t sp; | |||
| if ((__get_IPSR() == 0U) || ((__get_CONTROL() & 2U) == 0U)) { | |||
| return 0U; // Thread Mode or using Main Stack for threads | |||
| } | |||
| if ((id == 0U) || (id > TZ_PROCESS_STACK_SLOTS)) { | |||
| return 0U; // Invalid ID | |||
| } | |||
| slot = id - 1U; | |||
| if (ProcessStackInfo[slot].sp == 0U) { | |||
| return 0U; // Inactive slot | |||
| } | |||
| sp = __get_PSP(); | |||
| if ((sp < ProcessStackInfo[slot].sp_limit) || | |||
| (sp > ProcessStackInfo[slot].sp_top)) { | |||
| return 0U; // SP out of range | |||
| } | |||
| ProcessStackInfo[slot].sp = sp; | |||
| // Default process stack pointer and stack limit | |||
| __set_PSPLIM((uint32_t)ProcessStackMemory); | |||
| __set_PSP ((uint32_t)ProcessStackMemory); | |||
| return 1U; // Success | |||
| } | |||
| @@ -0,0 +1,563 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_armcc.h | |||
| * @brief CMSIS compiler specific macros, functions, instructions | |||
| * @version V1.0.5 | |||
| * @date 05. May 2021 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2021 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef __CMSIS_ARMCC_H | |||
| #define __CMSIS_ARMCC_H | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677) | |||
| #error "Please use Arm Compiler Toolchain V4.0.677 or later!" | |||
| #endif | |||
| /* CMSIS compiler control architecture macros */ | |||
| #if (defined (__TARGET_ARCH_7_A ) && (__TARGET_ARCH_7_A == 1)) | |||
| #define __ARM_ARCH_7A__ 1 | |||
| #endif | |||
| /* CMSIS compiler specific defines */ | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE __inline | |||
| #endif | |||
| #ifndef __FORCEINLINE | |||
| #define __FORCEINLINE __forceinline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static __inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE static __forceinline | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __declspec(noreturn) | |||
| #endif | |||
| #ifndef CMSIS_DEPRECATED | |||
| #define CMSIS_DEPRECATED __attribute__((deprecated)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed)) | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT __packed struct | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| #define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr))) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| #define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr))) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed)) | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #define __COMPILER_BARRIER() __memory_changed() | |||
| #endif | |||
| /* ########################## Core Instruction Access ######################### */ | |||
| /** | |||
| \brief No Operation | |||
| */ | |||
| #define __NOP __nop | |||
| /** | |||
| \brief Wait For Interrupt | |||
| */ | |||
| #define __WFI __wfi | |||
| /** | |||
| \brief Wait For Event | |||
| */ | |||
| #define __WFE __wfe | |||
| /** | |||
| \brief Send Event | |||
| */ | |||
| #define __SEV __sev | |||
| /** | |||
| \brief Instruction Synchronization Barrier | |||
| */ | |||
| #define __ISB() __isb(0xF) | |||
| /** | |||
| \brief Data Synchronization Barrier | |||
| */ | |||
| #define __DSB() __dsb(0xF) | |||
| /** | |||
| \brief Data Memory Barrier | |||
| */ | |||
| #define __DMB() __dmb(0xF) | |||
| /** | |||
| \brief Reverse byte order (32 bit) | |||
| \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #define __REV __rev | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #ifndef __NO_EMBEDDED_ASM | |||
| __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) | |||
| { | |||
| rev16 r0, r0 | |||
| bx lr | |||
| } | |||
| #endif | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #ifndef __NO_EMBEDDED_ASM | |||
| __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value) | |||
| { | |||
| revsh r0, r0 | |||
| bx lr | |||
| } | |||
| #endif | |||
| /** | |||
| \brief Rotate Right in unsigned value (32 bit) | |||
| \param [in] op1 Value to rotate | |||
| \param [in] op2 Number of Bits to rotate | |||
| \return Rotated value | |||
| */ | |||
| #define __ROR __ror | |||
| /** | |||
| \brief Breakpoint | |||
| \param [in] value is ignored by the processor. | |||
| If required, a debugger can use it to store additional information about the breakpoint. | |||
| */ | |||
| #define __BKPT(value) __breakpoint(value) | |||
| /** | |||
| \brief Reverse bit order of value | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #define __RBIT __rbit | |||
| /** | |||
| \brief Count leading zeros | |||
| \param [in] value Value to count the leading zeros | |||
| \return number of leading zeros in value | |||
| */ | |||
| #define __CLZ __clz | |||
| /** | |||
| \brief LDR Exclusive (8 bit) | |||
| \details Executes a exclusive LDR instruction for 8 bit value. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint8_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief LDR Exclusive (16 bit) | |||
| \details Executes a exclusive LDR instruction for 16 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint16_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief LDR Exclusive (32 bit) | |||
| \details Executes a exclusive LDR instruction for 32 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint32_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (8 bit) | |||
| \details Executes a exclusive STR instruction for 8 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXB(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (16 bit) | |||
| \details Executes a exclusive STR instruction for 16 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXH(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (32 bit) | |||
| \details Executes a exclusive STR instruction for 32 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXW(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief Remove the exclusive lock | |||
| \details Removes the exclusive lock which is created by LDREX. | |||
| */ | |||
| #define __CLREX __clrex | |||
| /** | |||
| \brief Signed Saturate | |||
| \details Saturates a signed value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (1..32) | |||
| \return Saturated value | |||
| */ | |||
| #define __SSAT __ssat | |||
| /** | |||
| \brief Unsigned Saturate | |||
| \details Saturates an unsigned value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (0..31) | |||
| \return Saturated value | |||
| */ | |||
| #define __USAT __usat | |||
| /* ########################### Core Function Access ########################### */ | |||
| /** | |||
| \brief Enable IRQ Interrupts | |||
| \details Enables IRQ interrupts by clearing the I-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| /* intrinsic void __enable_irq(); */ | |||
| /** | |||
| \brief Disable IRQ Interrupts | |||
| \details Disables IRQ interrupts by setting the I-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| /* intrinsic void __disable_irq(void); */ | |||
| /** | |||
| \brief Enable FIQ | |||
| \details Enables FIQ interrupts by clearing the F-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| #define __enable_fault_irq __enable_fiq | |||
| /** | |||
| \brief Disable FIQ | |||
| \details Disables FIQ interrupts by setting the F-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| #define __disable_fault_irq __disable_fiq | |||
| /** | |||
| \brief Get FPSCR (Floating Point Status/Control) | |||
| \return Floating Point Status/Control register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_FPSCR(void) | |||
| { | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| register uint32_t __regfpscr __ASM("fpscr"); | |||
| return(__regfpscr); | |||
| #else | |||
| return(0U); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Set FPSCR (Floating Point Status/Control) | |||
| \param [in] fpscr Floating Point Status/Control value to set | |||
| */ | |||
| __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) | |||
| { | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| register uint32_t __regfpscr __ASM("fpscr"); | |||
| __regfpscr = (fpscr); | |||
| #else | |||
| (void)fpscr; | |||
| #endif | |||
| } | |||
| /** \brief Get CPSR (Current Program Status Register) | |||
| \return CPSR Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_CPSR(void) | |||
| { | |||
| register uint32_t __regCPSR __ASM("cpsr"); | |||
| return(__regCPSR); | |||
| } | |||
| /** \brief Set CPSR (Current Program Status Register) | |||
| \param [in] cpsr CPSR value to set | |||
| */ | |||
| __STATIC_INLINE void __set_CPSR(uint32_t cpsr) | |||
| { | |||
| register uint32_t __regCPSR __ASM("cpsr"); | |||
| __regCPSR = cpsr; | |||
| } | |||
| /** \brief Get Mode | |||
| \return Processor Mode | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_mode(void) | |||
| { | |||
| return (__get_CPSR() & 0x1FU); | |||
| } | |||
| /** \brief Set Mode | |||
| \param [in] mode Mode value to set | |||
| */ | |||
| __STATIC_INLINE __ASM void __set_mode(uint32_t mode) | |||
| { | |||
| MOV r1, lr | |||
| MSR CPSR_C, r0 | |||
| BX r1 | |||
| } | |||
| /** \brief Get Stack Pointer | |||
| \return Stack Pointer | |||
| */ | |||
| __STATIC_INLINE __ASM uint32_t __get_SP(void) | |||
| { | |||
| MOV r0, sp | |||
| BX lr | |||
| } | |||
| /** \brief Set Stack Pointer | |||
| \param [in] stack Stack Pointer value to set | |||
| */ | |||
| __STATIC_INLINE __ASM void __set_SP(uint32_t stack) | |||
| { | |||
| MOV sp, r0 | |||
| BX lr | |||
| } | |||
| /** \brief Get USR/SYS Stack Pointer | |||
| \return USR/SYSStack Pointer | |||
| */ | |||
| __STATIC_INLINE __ASM uint32_t __get_SP_usr(void) | |||
| { | |||
| ARM | |||
| PRESERVE8 | |||
| MRS R1, CPSR | |||
| CPS #0x1F ;no effect in USR mode | |||
| MOV R0, SP | |||
| MSR CPSR_c, R1 ;no effect in USR mode | |||
| ISB | |||
| BX LR | |||
| } | |||
| /** \brief Set USR/SYS Stack Pointer | |||
| \param [in] topOfProcStack USR/SYS Stack Pointer value to set | |||
| */ | |||
| __STATIC_INLINE __ASM void __set_SP_usr(uint32_t topOfProcStack) | |||
| { | |||
| ARM | |||
| PRESERVE8 | |||
| MRS R1, CPSR | |||
| CPS #0x1F ;no effect in USR mode | |||
| MOV SP, R0 | |||
| MSR CPSR_c, R1 ;no effect in USR mode | |||
| ISB | |||
| BX LR | |||
| } | |||
| /** \brief Get FPEXC (Floating Point Exception Control Register) | |||
| \return Floating Point Exception Control Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_FPEXC(void) | |||
| { | |||
| #if (__FPU_PRESENT == 1) | |||
| register uint32_t __regfpexc __ASM("fpexc"); | |||
| return(__regfpexc); | |||
| #else | |||
| return(0); | |||
| #endif | |||
| } | |||
| /** \brief Set FPEXC (Floating Point Exception Control Register) | |||
| \param [in] fpexc Floating Point Exception Control value to set | |||
| */ | |||
| __STATIC_INLINE void __set_FPEXC(uint32_t fpexc) | |||
| { | |||
| #if (__FPU_PRESENT == 1) | |||
| register uint32_t __regfpexc __ASM("fpexc"); | |||
| __regfpexc = (fpexc); | |||
| #endif | |||
| } | |||
| /* | |||
| * Include common core functions to access Coprocessor 15 registers | |||
| */ | |||
| #define __get_CP(cp, op1, Rt, CRn, CRm, op2) do { register volatile uint32_t tmp __ASM("cp" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2); (Rt) = tmp; } while(0) | |||
| #define __set_CP(cp, op1, Rt, CRn, CRm, op2) do { register volatile uint32_t tmp __ASM("cp" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2); tmp = (Rt); } while(0) | |||
| #define __get_CP64(cp, op1, Rt, CRm) \ | |||
| do { \ | |||
| uint32_t ltmp, htmp; \ | |||
| __ASM volatile("MRRC p" # cp ", " # op1 ", ltmp, htmp, c" # CRm); \ | |||
| (Rt) = ((((uint64_t)htmp) << 32U) | ((uint64_t)ltmp)); \ | |||
| } while(0) | |||
| #define __set_CP64(cp, op1, Rt, CRm) \ | |||
| do { \ | |||
| const uint64_t tmp = (Rt); \ | |||
| const uint32_t ltmp = (uint32_t)(tmp); \ | |||
| const uint32_t htmp = (uint32_t)(tmp >> 32U); \ | |||
| __ASM volatile("MCRR p" # cp ", " # op1 ", ltmp, htmp, c" # CRm); \ | |||
| } while(0) | |||
| #include "cmsis_cp15.h" | |||
| /** \brief Enable Floating Point Unit | |||
| Critical section, called from undef handler, so systick is disabled | |||
| */ | |||
| __STATIC_INLINE __ASM void __FPU_Enable(void) | |||
| { | |||
| ARM | |||
| //Permit access to VFP/NEON, registers by modifying CPACR | |||
| MRC p15,0,R1,c1,c0,2 | |||
| ORR R1,R1,#0x00F00000 | |||
| MCR p15,0,R1,c1,c0,2 | |||
| //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted | |||
| ISB | |||
| //Enable VFP/NEON | |||
| VMRS R1,FPEXC | |||
| ORR R1,R1,#0x40000000 | |||
| VMSR FPEXC,R1 | |||
| //Initialise VFP/NEON registers to 0 | |||
| MOV R2,#0 | |||
| //Initialise D16 registers to 0 | |||
| VMOV D0, R2,R2 | |||
| VMOV D1, R2,R2 | |||
| VMOV D2, R2,R2 | |||
| VMOV D3, R2,R2 | |||
| VMOV D4, R2,R2 | |||
| VMOV D5, R2,R2 | |||
| VMOV D6, R2,R2 | |||
| VMOV D7, R2,R2 | |||
| VMOV D8, R2,R2 | |||
| VMOV D9, R2,R2 | |||
| VMOV D10,R2,R2 | |||
| VMOV D11,R2,R2 | |||
| VMOV D12,R2,R2 | |||
| VMOV D13,R2,R2 | |||
| VMOV D14,R2,R2 | |||
| VMOV D15,R2,R2 | |||
| IF {TARGET_FEATURE_EXTENSION_REGISTER_COUNT} == 32 | |||
| //Initialise D32 registers to 0 | |||
| VMOV D16,R2,R2 | |||
| VMOV D17,R2,R2 | |||
| VMOV D18,R2,R2 | |||
| VMOV D19,R2,R2 | |||
| VMOV D20,R2,R2 | |||
| VMOV D21,R2,R2 | |||
| VMOV D22,R2,R2 | |||
| VMOV D23,R2,R2 | |||
| VMOV D24,R2,R2 | |||
| VMOV D25,R2,R2 | |||
| VMOV D26,R2,R2 | |||
| VMOV D27,R2,R2 | |||
| VMOV D28,R2,R2 | |||
| VMOV D29,R2,R2 | |||
| VMOV D30,R2,R2 | |||
| VMOV D31,R2,R2 | |||
| ENDIF | |||
| //Initialise FPSCR to a known state | |||
| VMRS R1,FPSCR | |||
| LDR R2,=0x00086060 //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero. | |||
| AND R1,R1,R2 | |||
| VMSR FPSCR,R1 | |||
| BX LR | |||
| } | |||
| #endif /* __CMSIS_ARMCC_H */ | |||
| @@ -0,0 +1,614 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_armclang.h | |||
| * @brief CMSIS compiler specific macros, functions, instructions | |||
| * @version V1.2.1 | |||
| * @date 05. May 2021 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2021 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef __CMSIS_ARMCLANG_H | |||
| #define __CMSIS_ARMCLANG_H | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| /* CMSIS compiler specific defines */ | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE __inline | |||
| #endif | |||
| #ifndef __FORCEINLINE | |||
| #define __FORCEINLINE __attribute__((always_inline)) | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static __inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __attribute__((__noreturn__)) | |||
| #endif | |||
| #ifndef CMSIS_DEPRECATED | |||
| #define CMSIS_DEPRECATED __attribute__((deprecated)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed, aligned(1))) | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| #pragma clang diagnostic push | |||
| #pragma clang diagnostic ignored "-Wpacked" | |||
| /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */ | |||
| __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; | |||
| #pragma clang diagnostic pop | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| #pragma clang diagnostic push | |||
| #pragma clang diagnostic ignored "-Wpacked" | |||
| /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */ | |||
| __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; | |||
| #pragma clang diagnostic pop | |||
| #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| #pragma clang diagnostic push | |||
| #pragma clang diagnostic ignored "-Wpacked" | |||
| /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */ | |||
| __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; | |||
| #pragma clang diagnostic pop | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| #pragma clang diagnostic push | |||
| #pragma clang diagnostic ignored "-Wpacked" | |||
| __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; | |||
| #pragma clang diagnostic pop | |||
| #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed)) | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #define __COMPILER_BARRIER() __ASM volatile("":::"memory") | |||
| #endif | |||
| /* ########################## Core Instruction Access ######################### */ | |||
| /** | |||
| \brief No Operation | |||
| */ | |||
| #define __NOP __builtin_arm_nop | |||
| /** | |||
| \brief Wait For Interrupt | |||
| */ | |||
| #define __WFI __builtin_arm_wfi | |||
| /** | |||
| \brief Wait For Event | |||
| */ | |||
| #define __WFE __builtin_arm_wfe | |||
| /** | |||
| \brief Send Event | |||
| */ | |||
| #define __SEV __builtin_arm_sev | |||
| /** | |||
| \brief Instruction Synchronization Barrier | |||
| */ | |||
| #define __ISB() __builtin_arm_isb(0xF) | |||
| /** | |||
| \brief Data Synchronization Barrier | |||
| */ | |||
| #define __DSB() __builtin_arm_dsb(0xF) | |||
| /** | |||
| \brief Data Memory Barrier | |||
| */ | |||
| #define __DMB() __builtin_arm_dmb(0xF) | |||
| /** | |||
| \brief Reverse byte order (32 bit) | |||
| \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #define __REV(value) __builtin_bswap32(value) | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #define __REV16(value) __ROR(__REV(value), 16) | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #define __REVSH(value) (int16_t)__builtin_bswap16(value) | |||
| /** | |||
| \brief Rotate Right in unsigned value (32 bit) | |||
| \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. | |||
| \param [in] op1 Value to rotate | |||
| \param [in] op2 Number of Bits to rotate | |||
| \return Rotated value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) | |||
| { | |||
| op2 %= 32U; | |||
| if (op2 == 0U) | |||
| { | |||
| return op1; | |||
| } | |||
| return (op1 >> op2) | (op1 << (32U - op2)); | |||
| } | |||
| /** | |||
| \brief Breakpoint | |||
| \param [in] value is ignored by the processor. | |||
| If required, a debugger can use it to store additional information about the breakpoint. | |||
| */ | |||
| #define __BKPT(value) __ASM volatile ("bkpt "#value) | |||
| /** | |||
| \brief Reverse bit order of value | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #define __RBIT __builtin_arm_rbit | |||
| /** | |||
| \brief Count leading zeros | |||
| \param [in] value Value to count the leading zeros | |||
| \return number of leading zeros in value | |||
| */ | |||
| __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) | |||
| { | |||
| /* Even though __builtin_clz produces a CLZ instruction on ARM, formally | |||
| __builtin_clz(0) is undefined behaviour, so handle this case specially. | |||
| This guarantees ARM-compatible results if happening to compile on a non-ARM | |||
| target, and ensures the compiler doesn't decide to activate any | |||
| optimisations using the logic "value was passed to __builtin_clz, so it | |||
| is non-zero". | |||
| ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a | |||
| single CLZ instruction. | |||
| */ | |||
| if (value == 0U) | |||
| { | |||
| return 32U; | |||
| } | |||
| return __builtin_clz(value); | |||
| } | |||
| /** | |||
| \brief LDR Exclusive (8 bit) | |||
| \details Executes a exclusive LDR instruction for 8 bit value. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint8_t at (*ptr) | |||
| */ | |||
| #define __LDREXB (uint8_t)__builtin_arm_ldrex | |||
| /** | |||
| \brief LDR Exclusive (16 bit) | |||
| \details Executes a exclusive LDR instruction for 16 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint16_t at (*ptr) | |||
| */ | |||
| #define __LDREXH (uint16_t)__builtin_arm_ldrex | |||
| /** | |||
| \brief LDR Exclusive (32 bit) | |||
| \details Executes a exclusive LDR instruction for 32 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint32_t at (*ptr) | |||
| */ | |||
| #define __LDREXW (uint32_t)__builtin_arm_ldrex | |||
| /** | |||
| \brief STR Exclusive (8 bit) | |||
| \details Executes a exclusive STR instruction for 8 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #define __STREXB (uint32_t)__builtin_arm_strex | |||
| /** | |||
| \brief STR Exclusive (16 bit) | |||
| \details Executes a exclusive STR instruction for 16 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #define __STREXH (uint32_t)__builtin_arm_strex | |||
| /** | |||
| \brief STR Exclusive (32 bit) | |||
| \details Executes a exclusive STR instruction for 32 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #define __STREXW (uint32_t)__builtin_arm_strex | |||
| /** | |||
| \brief Remove the exclusive lock | |||
| \details Removes the exclusive lock which is created by LDREX. | |||
| */ | |||
| #define __CLREX __builtin_arm_clrex | |||
| /** | |||
| \brief Signed Saturate | |||
| \details Saturates a signed value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (1..32) | |||
| \return Saturated value | |||
| */ | |||
| #define __SSAT __builtin_arm_ssat | |||
| /** | |||
| \brief Unsigned Saturate | |||
| \details Saturates an unsigned value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (0..31) | |||
| \return Saturated value | |||
| */ | |||
| #define __USAT __builtin_arm_usat | |||
| /* ################### Compiler specific Intrinsics ########################### */ | |||
| /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics | |||
| Access to dedicated SIMD instructions | |||
| @{ | |||
| */ | |||
| #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) | |||
| #define __SADD8 __builtin_arm_sadd8 | |||
| #define __SADD16 __builtin_arm_sadd16 | |||
| #define __QADD8 __builtin_arm_qadd8 | |||
| #define __QSUB8 __builtin_arm_qsub8 | |||
| #define __QADD16 __builtin_arm_qadd16 | |||
| #define __SHADD16 __builtin_arm_shadd16 | |||
| #define __QSUB16 __builtin_arm_qsub16 | |||
| #define __SHSUB16 __builtin_arm_shsub16 | |||
| #define __QASX __builtin_arm_qasx | |||
| #define __SHASX __builtin_arm_shasx | |||
| #define __QSAX __builtin_arm_qsax | |||
| #define __SHSAX __builtin_arm_shsax | |||
| #define __SXTB16 __builtin_arm_sxtb16 | |||
| #define __SMUAD __builtin_arm_smuad | |||
| #define __SMUADX __builtin_arm_smuadx | |||
| #define __SMLAD __builtin_arm_smlad | |||
| #define __SMLADX __builtin_arm_smladx | |||
| #define __SMLALD __builtin_arm_smlald | |||
| #define __SMLALDX __builtin_arm_smlaldx | |||
| #define __SMUSD __builtin_arm_smusd | |||
| #define __SMUSDX __builtin_arm_smusdx | |||
| #define __SMLSDX __builtin_arm_smlsdx | |||
| #define __USAT16 __builtin_arm_usat16 | |||
| #define __SSUB8 __builtin_arm_ssub8 | |||
| #define __SXTB16 __builtin_arm_sxtb16 | |||
| #define __SXTAB16 __builtin_arm_sxtab16 | |||
| __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2) | |||
| { | |||
| int32_t result; | |||
| __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) | |||
| { | |||
| int32_t result; | |||
| __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ | |||
| ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) | |||
| #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ | |||
| ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) | |||
| __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) | |||
| { | |||
| int32_t result; | |||
| __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); | |||
| return(result); | |||
| } | |||
| #endif /* (__ARM_FEATURE_DSP == 1) */ | |||
| /* ########################### Core Function Access ########################### */ | |||
| /** | |||
| \brief Enable IRQ Interrupts | |||
| \details Enables IRQ interrupts by clearing the I-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| __STATIC_FORCEINLINE void __enable_irq(void) | |||
| { | |||
| __ASM volatile ("cpsie i" : : : "memory"); | |||
| } | |||
| /** | |||
| \brief Disable IRQ Interrupts | |||
| \details Disables IRQ interrupts by setting the I-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| __STATIC_FORCEINLINE void __disable_irq(void) | |||
| { | |||
| __ASM volatile ("cpsid i" : : : "memory"); | |||
| } | |||
| /** | |||
| \brief Enable FIQ | |||
| \details Enables FIQ interrupts by clearing the F-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| __STATIC_FORCEINLINE void __enable_fault_irq(void) | |||
| { | |||
| __ASM volatile ("cpsie f" : : : "memory"); | |||
| } | |||
| /** | |||
| \brief Disable FIQ | |||
| \details Disables FIQ interrupts by setting the F-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| __STATIC_FORCEINLINE void __disable_fault_irq(void) | |||
| { | |||
| __ASM volatile ("cpsid f" : : : "memory"); | |||
| } | |||
| /** | |||
| \brief Get FPSCR | |||
| \details Returns the current value of the Floating Point Status/Control register. | |||
| \return Floating Point Status/Control register value | |||
| */ | |||
| #define __get_FPSCR __builtin_arm_get_fpscr | |||
| /** | |||
| \brief Set FPSCR | |||
| \details Assigns the given value to the Floating Point Status/Control register. | |||
| \param [in] fpscr Floating Point Status/Control value to set | |||
| */ | |||
| #define __set_FPSCR __builtin_arm_set_fpscr | |||
| /** \brief Get CPSR Register | |||
| \return CPSR Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CPSR(void) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile("MRS %0, cpsr" : "=r" (result) ); | |||
| return(result); | |||
| } | |||
| /** \brief Set CPSR Register | |||
| \param [in] cpsr CPSR value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_CPSR(uint32_t cpsr) | |||
| { | |||
| __ASM volatile ("MSR cpsr, %0" : : "r" (cpsr) : "cc", "memory"); | |||
| } | |||
| /** \brief Get Mode | |||
| \return Processor Mode | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_mode(void) | |||
| { | |||
| return (__get_CPSR() & 0x1FU); | |||
| } | |||
| /** \brief Set Mode | |||
| \param [in] mode Mode value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_mode(uint32_t mode) | |||
| { | |||
| __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory"); | |||
| } | |||
| /** \brief Get Stack Pointer | |||
| \return Stack Pointer value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_SP(void) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile("MOV %0, sp" : "=r" (result) : : "memory"); | |||
| return result; | |||
| } | |||
| /** \brief Set Stack Pointer | |||
| \param [in] stack Stack Pointer value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_SP(uint32_t stack) | |||
| { | |||
| __ASM volatile("MOV sp, %0" : : "r" (stack) : "memory"); | |||
| } | |||
| /** \brief Get USR/SYS Stack Pointer | |||
| \return USR/SYS Stack Pointer value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_SP_usr(void) | |||
| { | |||
| uint32_t cpsr; | |||
| uint32_t result; | |||
| __ASM volatile( | |||
| "MRS %0, cpsr \n" | |||
| "CPS #0x1F \n" // no effect in USR mode | |||
| "MOV %1, sp \n" | |||
| "MSR cpsr_c, %0 \n" // no effect in USR mode | |||
| "ISB" : "=r"(cpsr), "=r"(result) : : "memory" | |||
| ); | |||
| return result; | |||
| } | |||
| /** \brief Set USR/SYS Stack Pointer | |||
| \param [in] topOfProcStack USR/SYS Stack Pointer value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_SP_usr(uint32_t topOfProcStack) | |||
| { | |||
| uint32_t cpsr; | |||
| __ASM volatile( | |||
| "MRS %0, cpsr \n" | |||
| "CPS #0x1F \n" // no effect in USR mode | |||
| "MOV sp, %1 \n" | |||
| "MSR cpsr_c, %0 \n" // no effect in USR mode | |||
| "ISB" : "=r"(cpsr) : "r" (topOfProcStack) : "memory" | |||
| ); | |||
| } | |||
| /** \brief Get FPEXC | |||
| \return Floating Point Exception Control register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_FPEXC(void) | |||
| { | |||
| #if (__FPU_PRESENT == 1) | |||
| uint32_t result; | |||
| __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory"); | |||
| return(result); | |||
| #else | |||
| return(0); | |||
| #endif | |||
| } | |||
| /** \brief Set FPEXC | |||
| \param [in] fpexc Floating Point Exception Control value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_FPEXC(uint32_t fpexc) | |||
| { | |||
| #if (__FPU_PRESENT == 1) | |||
| __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory"); | |||
| #endif | |||
| } | |||
| /* | |||
| * Include common core functions to access Coprocessor 15 registers | |||
| */ | |||
| #define __get_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" ) | |||
| #define __set_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" ) | |||
| #define __get_CP64(cp, op1, Rt, CRm) __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" ) | |||
| #define __set_CP64(cp, op1, Rt, CRm) __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" ) | |||
| #include "cmsis_cp15.h" | |||
| /** \brief Enable Floating Point Unit | |||
| Critical section, called from undef handler, so systick is disabled | |||
| */ | |||
| __STATIC_INLINE void __FPU_Enable(void) | |||
| { | |||
| __ASM volatile( | |||
| //Permit access to VFP/NEON, registers by modifying CPACR | |||
| " MRC p15,0,R1,c1,c0,2 \n" | |||
| " ORR R1,R1,#0x00F00000 \n" | |||
| " MCR p15,0,R1,c1,c0,2 \n" | |||
| //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted | |||
| " ISB \n" | |||
| //Enable VFP/NEON | |||
| " VMRS R1,FPEXC \n" | |||
| " ORR R1,R1,#0x40000000 \n" | |||
| " VMSR FPEXC,R1 \n" | |||
| //Initialise VFP/NEON registers to 0 | |||
| " MOV R2,#0 \n" | |||
| //Initialise D16 registers to 0 | |||
| " VMOV D0, R2,R2 \n" | |||
| " VMOV D1, R2,R2 \n" | |||
| " VMOV D2, R2,R2 \n" | |||
| " VMOV D3, R2,R2 \n" | |||
| " VMOV D4, R2,R2 \n" | |||
| " VMOV D5, R2,R2 \n" | |||
| " VMOV D6, R2,R2 \n" | |||
| " VMOV D7, R2,R2 \n" | |||
| " VMOV D8, R2,R2 \n" | |||
| " VMOV D9, R2,R2 \n" | |||
| " VMOV D10,R2,R2 \n" | |||
| " VMOV D11,R2,R2 \n" | |||
| " VMOV D12,R2,R2 \n" | |||
| " VMOV D13,R2,R2 \n" | |||
| " VMOV D14,R2,R2 \n" | |||
| " VMOV D15,R2,R2 \n" | |||
| #if (defined(__ARM_NEON) && (__ARM_NEON == 1)) | |||
| //Initialise D32 registers to 0 | |||
| " VMOV D16,R2,R2 \n" | |||
| " VMOV D17,R2,R2 \n" | |||
| " VMOV D18,R2,R2 \n" | |||
| " VMOV D19,R2,R2 \n" | |||
| " VMOV D20,R2,R2 \n" | |||
| " VMOV D21,R2,R2 \n" | |||
| " VMOV D22,R2,R2 \n" | |||
| " VMOV D23,R2,R2 \n" | |||
| " VMOV D24,R2,R2 \n" | |||
| " VMOV D25,R2,R2 \n" | |||
| " VMOV D26,R2,R2 \n" | |||
| " VMOV D27,R2,R2 \n" | |||
| " VMOV D28,R2,R2 \n" | |||
| " VMOV D29,R2,R2 \n" | |||
| " VMOV D30,R2,R2 \n" | |||
| " VMOV D31,R2,R2 \n" | |||
| #endif | |||
| //Initialise FPSCR to a known state | |||
| " VMRS R1,FPSCR \n" | |||
| " LDR R2,=0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero. | |||
| " AND R1,R1,R2 \n" | |||
| " VMSR FPSCR,R1 " | |||
| : : : "cc", "r1", "r2" | |||
| ); | |||
| } | |||
| #endif /* __CMSIS_ARMCLANG_H */ | |||
| @@ -0,0 +1,213 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_compiler.h | |||
| * @brief CMSIS compiler specific macros, functions, instructions | |||
| * @version V1.0.2 | |||
| * @date 10. January 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef __CMSIS_COMPILER_H | |||
| #define __CMSIS_COMPILER_H | |||
| #include <stdint.h> | |||
| /* | |||
| * Arm Compiler 4/5 | |||
| */ | |||
| #if defined ( __CC_ARM ) | |||
| #include "cmsis_armcc.h" | |||
| /* | |||
| * Arm Compiler 6 (armclang) | |||
| */ | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) | |||
| #include "cmsis_armclang.h" | |||
| /* | |||
| * GNU Compiler | |||
| */ | |||
| #elif defined ( __GNUC__ ) | |||
| #include "cmsis_gcc.h" | |||
| /* | |||
| * IAR Compiler | |||
| */ | |||
| #elif defined ( __ICCARM__ ) | |||
| #include "cmsis_iccarm.h" | |||
| /* | |||
| * TI Arm Compiler | |||
| */ | |||
| #elif defined ( __TI_ARM__ ) | |||
| #include <cmsis_ccs.h> | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __attribute__((noreturn)) | |||
| #endif | |||
| #ifndef CMSIS_DEPRECATED | |||
| #define CMSIS_DEPRECATED __attribute__((deprecated)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 | |||
| struct __attribute__((packed)) T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed)) | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| /* | |||
| * TASKING Compiler | |||
| */ | |||
| #elif defined ( __TASKING__ ) | |||
| /* | |||
| * The CMSIS functions have been implemented as intrinsics in the compiler. | |||
| * Please use "carm -?i" to get an up to date list of all intrinsics, | |||
| * Including the CMSIS ones. | |||
| */ | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __attribute__((noreturn)) | |||
| #endif | |||
| #ifndef CMSIS_DEPRECATED | |||
| #define CMSIS_DEPRECATED __attribute__((deprecated)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 | |||
| struct __packed__ T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __align(x) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __packed__ | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| /* | |||
| * COSMIC Compiler | |||
| */ | |||
| #elif defined ( __CSMC__ ) | |||
| #include <cmsis_csm.h> | |||
| #ifndef __ASM | |||
| #define __ASM _asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| // NO RETURN is automatically detected hence no warning here | |||
| #define __NO_RETURN | |||
| #endif | |||
| #ifndef __USED | |||
| #warning No compiler specific solution for __USED. __USED is ignored. | |||
| #define __USED | |||
| #endif | |||
| #ifndef CMSIS_DEPRECATED | |||
| #warning No compiler specific solution for CMSIS_DEPRECATED. CMSIS_DEPRECATED is ignored. | |||
| #define CMSIS_DEPRECATED | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __weak | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 | |||
| @packed struct T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. | |||
| #define __ALIGNED(x) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED @packed | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| #else | |||
| #error Unknown compiler. | |||
| #endif | |||
| #endif /* __CMSIS_COMPILER_H */ | |||
| @@ -0,0 +1,514 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_cp15.h | |||
| * @brief CMSIS compiler specific macros, functions, instructions | |||
| * @version V1.0.1 | |||
| * @date 07. Sep 2017 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2017 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef __CMSIS_CP15_H | |||
| #define __CMSIS_CP15_H | |||
| /** \brief Get ACTLR | |||
| \return Auxiliary Control register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_ACTLR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 1, 0, 1); | |||
| return(result); | |||
| } | |||
| /** \brief Set ACTLR | |||
| \param [in] actlr Auxiliary Control value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_ACTLR(uint32_t actlr) | |||
| { | |||
| __set_CP(15, 0, actlr, 1, 0, 1); | |||
| } | |||
| /** \brief Get CPACR | |||
| \return Coprocessor Access Control register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CPACR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 1, 0, 2); | |||
| return result; | |||
| } | |||
| /** \brief Set CPACR | |||
| \param [in] cpacr Coprocessor Access Control value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_CPACR(uint32_t cpacr) | |||
| { | |||
| __set_CP(15, 0, cpacr, 1, 0, 2); | |||
| } | |||
| /** \brief Get DFSR | |||
| \return Data Fault Status Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_DFSR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 5, 0, 0); | |||
| return result; | |||
| } | |||
| /** \brief Set DFSR | |||
| \param [in] dfsr Data Fault Status value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_DFSR(uint32_t dfsr) | |||
| { | |||
| __set_CP(15, 0, dfsr, 5, 0, 0); | |||
| } | |||
| /** \brief Get IFSR | |||
| \return Instruction Fault Status Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_IFSR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 5, 0, 1); | |||
| return result; | |||
| } | |||
| /** \brief Set IFSR | |||
| \param [in] ifsr Instruction Fault Status value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_IFSR(uint32_t ifsr) | |||
| { | |||
| __set_CP(15, 0, ifsr, 5, 0, 1); | |||
| } | |||
| /** \brief Get ISR | |||
| \return Interrupt Status Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_ISR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 12, 1, 0); | |||
| return result; | |||
| } | |||
| /** \brief Get CBAR | |||
| \return Configuration Base Address register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CBAR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 4, result, 15, 0, 0); | |||
| return result; | |||
| } | |||
| /** \brief Get TTBR0 | |||
| This function returns the value of the Translation Table Base Register 0. | |||
| \return Translation Table Base Register 0 value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_TTBR0(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 2, 0, 0); | |||
| return result; | |||
| } | |||
| /** \brief Set TTBR0 | |||
| This function assigns the given value to the Translation Table Base Register 0. | |||
| \param [in] ttbr0 Translation Table Base Register 0 value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_TTBR0(uint32_t ttbr0) | |||
| { | |||
| __set_CP(15, 0, ttbr0, 2, 0, 0); | |||
| } | |||
| /** \brief Get DACR | |||
| This function returns the value of the Domain Access Control Register. | |||
| \return Domain Access Control Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_DACR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 3, 0, 0); | |||
| return result; | |||
| } | |||
| /** \brief Set DACR | |||
| This function assigns the given value to the Domain Access Control Register. | |||
| \param [in] dacr Domain Access Control Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_DACR(uint32_t dacr) | |||
| { | |||
| __set_CP(15, 0, dacr, 3, 0, 0); | |||
| } | |||
| /** \brief Set SCTLR | |||
| This function assigns the given value to the System Control Register. | |||
| \param [in] sctlr System Control Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_SCTLR(uint32_t sctlr) | |||
| { | |||
| __set_CP(15, 0, sctlr, 1, 0, 0); | |||
| } | |||
| /** \brief Get SCTLR | |||
| \return System Control Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_SCTLR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 1, 0, 0); | |||
| return result; | |||
| } | |||
| /** \brief Set ACTRL | |||
| \param [in] actrl Auxiliary Control Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_ACTRL(uint32_t actrl) | |||
| { | |||
| __set_CP(15, 0, actrl, 1, 0, 1); | |||
| } | |||
| /** \brief Get ACTRL | |||
| \return Auxiliary Control Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_ACTRL(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 1, 0, 1); | |||
| return result; | |||
| } | |||
| /** \brief Get MPIDR | |||
| This function returns the value of the Multiprocessor Affinity Register. | |||
| \return Multiprocessor Affinity Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_MPIDR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 0, 0, 5); | |||
| return result; | |||
| } | |||
| /** \brief Get VBAR | |||
| This function returns the value of the Vector Base Address Register. | |||
| \return Vector Base Address Register | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_VBAR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 12, 0, 0); | |||
| return result; | |||
| } | |||
| /** \brief Set VBAR | |||
| This function assigns the given value to the Vector Base Address Register. | |||
| \param [in] vbar Vector Base Address Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_VBAR(uint32_t vbar) | |||
| { | |||
| __set_CP(15, 0, vbar, 12, 0, 0); | |||
| } | |||
| /** \brief Get MVBAR | |||
| This function returns the value of the Monitor Vector Base Address Register. | |||
| \return Monitor Vector Base Address Register | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_MVBAR(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 12, 0, 1); | |||
| return result; | |||
| } | |||
| /** \brief Set MVBAR | |||
| This function assigns the given value to the Monitor Vector Base Address Register. | |||
| \param [in] mvbar Monitor Vector Base Address Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_MVBAR(uint32_t mvbar) | |||
| { | |||
| __set_CP(15, 0, mvbar, 12, 0, 1); | |||
| } | |||
| #if (defined(__CORTEX_A) && (__CORTEX_A == 7U) && \ | |||
| defined(__TIM_PRESENT) && (__TIM_PRESENT == 1U)) || \ | |||
| defined(DOXYGEN) | |||
| /** \brief Set CNTFRQ | |||
| This function assigns the given value to PL1 Physical Timer Counter Frequency Register (CNTFRQ). | |||
| \param [in] value CNTFRQ Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_CNTFRQ(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 14, 0, 0); | |||
| } | |||
| /** \brief Get CNTFRQ | |||
| This function returns the value of the PL1 Physical Timer Counter Frequency Register (CNTFRQ). | |||
| \return CNTFRQ Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CNTFRQ(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 14, 0 , 0); | |||
| return result; | |||
| } | |||
| /** \brief Set CNTP_TVAL | |||
| This function assigns the given value to PL1 Physical Timer Value Register (CNTP_TVAL). | |||
| \param [in] value CNTP_TVAL Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_CNTP_TVAL(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 14, 2, 0); | |||
| } | |||
| /** \brief Get CNTP_TVAL | |||
| This function returns the value of the PL1 Physical Timer Value Register (CNTP_TVAL). | |||
| \return CNTP_TVAL Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CNTP_TVAL(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 14, 2, 0); | |||
| return result; | |||
| } | |||
| /** \brief Get CNTPCT | |||
| This function returns the value of the 64 bits PL1 Physical Count Register (CNTPCT). | |||
| \return CNTPCT Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint64_t __get_CNTPCT(void) | |||
| { | |||
| uint64_t result; | |||
| __get_CP64(15, 0, result, 14); | |||
| return result; | |||
| } | |||
| /** \brief Set CNTP_CVAL | |||
| This function assigns the given value to 64bits PL1 Physical Timer CompareValue Register (CNTP_CVAL). | |||
| \param [in] value CNTP_CVAL Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_CNTP_CVAL(uint64_t value) | |||
| { | |||
| __set_CP64(15, 2, value, 14); | |||
| } | |||
| /** \brief Get CNTP_CVAL | |||
| This function returns the value of the 64 bits PL1 Physical Timer CompareValue Register (CNTP_CVAL). | |||
| \return CNTP_CVAL Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint64_t __get_CNTP_CVAL(void) | |||
| { | |||
| uint64_t result; | |||
| __get_CP64(15, 2, result, 14); | |||
| return result; | |||
| } | |||
| /** \brief Set CNTP_CTL | |||
| This function assigns the given value to PL1 Physical Timer Control Register (CNTP_CTL). | |||
| \param [in] value CNTP_CTL Register value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_CNTP_CTL(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 14, 2, 1); | |||
| } | |||
| /** \brief Get CNTP_CTL register | |||
| \return CNTP_CTL Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CNTP_CTL(void) | |||
| { | |||
| uint32_t result; | |||
| __get_CP(15, 0, result, 14, 2, 1); | |||
| return result; | |||
| } | |||
| #endif | |||
| /** \brief Set TLBIALL | |||
| TLB Invalidate All | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_TLBIALL(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 8, 7, 0); | |||
| } | |||
| /** \brief Set BPIALL. | |||
| Branch Predictor Invalidate All | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_BPIALL(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 7, 5, 6); | |||
| } | |||
| /** \brief Set ICIALLU | |||
| Instruction Cache Invalidate All | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_ICIALLU(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 7, 5, 0); | |||
| } | |||
| /** \brief Set DCCMVAC | |||
| Data cache clean | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_DCCMVAC(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 7, 10, 1); | |||
| } | |||
| /** \brief Set DCIMVAC | |||
| Data cache invalidate | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_DCIMVAC(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 7, 6, 1); | |||
| } | |||
| /** \brief Set DCCIMVAC | |||
| Data cache clean and invalidate | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_DCCIMVAC(uint32_t value) | |||
| { | |||
| __set_CP(15, 0, value, 7, 14, 1); | |||
| } | |||
| /** \brief Set CSSELR | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_CSSELR(uint32_t value) | |||
| { | |||
| // __ASM volatile("MCR p15, 2, %0, c0, c0, 0" : : "r"(value) : "memory"); | |||
| __set_CP(15, 2, value, 0, 0, 0); | |||
| } | |||
| /** \brief Get CSSELR | |||
| \return CSSELR Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CSSELR(void) | |||
| { | |||
| uint32_t result; | |||
| // __ASM volatile("MRC p15, 2, %0, c0, c0, 0" : "=r"(result) : : "memory"); | |||
| __get_CP(15, 2, result, 0, 0, 0); | |||
| return result; | |||
| } | |||
| /** \brief Set CCSIDR | |||
| \deprecated CCSIDR itself is read-only. Use __set_CSSELR to select cache level instead. | |||
| */ | |||
| CMSIS_DEPRECATED | |||
| __STATIC_FORCEINLINE void __set_CCSIDR(uint32_t value) | |||
| { | |||
| __set_CSSELR(value); | |||
| } | |||
| /** \brief Get CCSIDR | |||
| \return CCSIDR Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CCSIDR(void) | |||
| { | |||
| uint32_t result; | |||
| // __ASM volatile("MRC p15, 1, %0, c0, c0, 0" : "=r"(result) : : "memory"); | |||
| __get_CP(15, 1, result, 0, 0, 0); | |||
| return result; | |||
| } | |||
| /** \brief Get CLIDR | |||
| \return CLIDR Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CLIDR(void) | |||
| { | |||
| uint32_t result; | |||
| // __ASM volatile("MRC p15, 1, %0, c0, c0, 1" : "=r"(result) : : "memory"); | |||
| __get_CP(15, 1, result, 0, 0, 1); | |||
| return result; | |||
| } | |||
| /** \brief Set DCISW | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_DCISW(uint32_t value) | |||
| { | |||
| // __ASM volatile("MCR p15, 0, %0, c7, c6, 2" : : "r"(value) : "memory") | |||
| __set_CP(15, 0, value, 7, 6, 2); | |||
| } | |||
| /** \brief Set DCCSW | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_DCCSW(uint32_t value) | |||
| { | |||
| // __ASM volatile("MCR p15, 0, %0, c7, c10, 2" : : "r"(value) : "memory") | |||
| __set_CP(15, 0, value, 7, 10, 2); | |||
| } | |||
| /** \brief Set DCCISW | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_DCCISW(uint32_t value) | |||
| { | |||
| // __ASM volatile("MCR p15, 0, %0, c7, c14, 2" : : "r"(value) : "memory") | |||
| __set_CP(15, 0, value, 7, 14, 2); | |||
| } | |||
| #endif | |||
| @@ -0,0 +1,917 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_gcc.h | |||
| * @brief CMSIS compiler specific macros, functions, instructions | |||
| * @version V1.3.2 | |||
| * @date 24. March 2022 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2022 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef __CMSIS_GCC_H | |||
| #define __CMSIS_GCC_H | |||
| /* ignore some GCC warnings */ | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wsign-conversion" | |||
| #pragma GCC diagnostic ignored "-Wconversion" | |||
| #pragma GCC diagnostic ignored "-Wunused-parameter" | |||
| /* Fallback for __has_builtin */ | |||
| #ifndef __has_builtin | |||
| #define __has_builtin(x) (0) | |||
| #endif | |||
| /* CMSIS compiler specific defines */ | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __FORCEINLINE | |||
| #define __FORCEINLINE __attribute__((always_inline)) | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __attribute__((__noreturn__)) | |||
| #endif | |||
| #ifndef CMSIS_DEPRECATED | |||
| #define CMSIS_DEPRECATED __attribute__((deprecated)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed, aligned(1))) | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpacked" | |||
| /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */ | |||
| __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; | |||
| #pragma GCC diagnostic pop | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpacked" | |||
| /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */ | |||
| __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; | |||
| #pragma GCC diagnostic pop | |||
| #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpacked" | |||
| /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */ | |||
| __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; | |||
| #pragma GCC diagnostic pop | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpacked" | |||
| __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; | |||
| #pragma GCC diagnostic pop | |||
| #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #define __COMPILER_BARRIER() __ASM volatile("":::"memory") | |||
| #endif | |||
| __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2) | |||
| { | |||
| int32_t result; | |||
| __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) | |||
| { | |||
| union llreg_u{ | |||
| uint32_t w32[2]; | |||
| uint64_t w64; | |||
| } llr; | |||
| llr.w64 = acc; | |||
| #ifndef __ARMEB__ /* Little endian */ | |||
| __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); | |||
| #else /* Big endian */ | |||
| __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); | |||
| #endif | |||
| return(llr.w64); | |||
| } | |||
| __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) | |||
| { | |||
| int32_t result; | |||
| __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ | |||
| ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) | |||
| #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ | |||
| ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) | |||
| __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) | |||
| { | |||
| union llreg_u{ | |||
| uint32_t w32[2]; | |||
| uint64_t w64; | |||
| } llr; | |||
| llr.w64 = acc; | |||
| #ifndef __ARMEB__ /* Little endian */ | |||
| __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); | |||
| #else /* Big endian */ | |||
| __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); | |||
| #endif | |||
| return(llr.w64); | |||
| } | |||
| __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) | |||
| { | |||
| int32_t result; | |||
| __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); | |||
| return(result); | |||
| } | |||
| __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); | |||
| return(result); | |||
| } | |||
| /* ########################## Core Instruction Access ######################### */ | |||
| /** | |||
| \brief No Operation | |||
| */ | |||
| #define __NOP() __ASM volatile ("nop") | |||
| /** | |||
| \brief Wait For Interrupt | |||
| */ | |||
| #define __WFI() __ASM volatile ("wfi":::"memory") | |||
| /** | |||
| \brief Wait For Event | |||
| */ | |||
| #define __WFE() __ASM volatile ("wfe":::"memory") | |||
| /** | |||
| \brief Send Event | |||
| */ | |||
| #define __SEV() __ASM volatile ("sev") | |||
| /** | |||
| \brief Instruction Synchronization Barrier | |||
| \details Instruction Synchronization Barrier flushes the pipeline in the processor, | |||
| so that all instructions following the ISB are fetched from cache or memory, | |||
| after the instruction has been completed. | |||
| */ | |||
| __STATIC_FORCEINLINE void __ISB(void) | |||
| { | |||
| __ASM volatile ("isb 0xF":::"memory"); | |||
| } | |||
| /** | |||
| \brief Data Synchronization Barrier | |||
| \details Acts as a special kind of Data Memory Barrier. | |||
| It completes when all explicit memory accesses before this instruction complete. | |||
| */ | |||
| __STATIC_FORCEINLINE void __DSB(void) | |||
| { | |||
| __ASM volatile ("dsb 0xF":::"memory"); | |||
| } | |||
| /** | |||
| \brief Data Memory Barrier | |||
| \details Ensures the apparent order of the explicit memory operations before | |||
| and after the instruction, without ensuring their completion. | |||
| */ | |||
| __STATIC_FORCEINLINE void __DMB(void) | |||
| { | |||
| __ASM volatile ("dmb 0xF":::"memory"); | |||
| } | |||
| /** | |||
| \brief Reverse byte order (32 bit) | |||
| \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __REV(uint32_t value) | |||
| { | |||
| #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) | |||
| return __builtin_bswap32(value); | |||
| #else | |||
| uint32_t result; | |||
| __ASM ("rev %0, %1" : "=r" (result) : "r" (value) ); | |||
| return result; | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("rev16 %0, %1" : "=r" (result) : "r" (value)); | |||
| return result; | |||
| } | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| __STATIC_FORCEINLINE int16_t __REVSH(int16_t value) | |||
| { | |||
| #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) | |||
| return (int16_t)__builtin_bswap16(value); | |||
| #else | |||
| int16_t result; | |||
| __ASM ("revsh %0, %1" : "=r" (result) : "r" (value) ); | |||
| return result; | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Rotate Right in unsigned value (32 bit) | |||
| \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. | |||
| \param [in] op1 Value to rotate | |||
| \param [in] op2 Number of Bits to rotate | |||
| \return Rotated value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) | |||
| { | |||
| op2 %= 32U; | |||
| if (op2 == 0U) | |||
| { | |||
| return op1; | |||
| } | |||
| return (op1 >> op2) | (op1 << (32U - op2)); | |||
| } | |||
| /** | |||
| \brief Breakpoint | |||
| \param [in] value is ignored by the processor. | |||
| If required, a debugger can use it to store additional information about the breakpoint. | |||
| */ | |||
| #define __BKPT(value) __ASM volatile ("bkpt "#value) | |||
| /** | |||
| \brief Reverse bit order of value | |||
| \details Reverses the bit order of the given value. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value) | |||
| { | |||
| uint32_t result; | |||
| __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) ); | |||
| return result; | |||
| } | |||
| /** | |||
| \brief Count leading zeros | |||
| \param [in] value Value to count the leading zeros | |||
| \return number of leading zeros in value | |||
| */ | |||
| __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) | |||
| { | |||
| /* Even though __builtin_clz produces a CLZ instruction on ARM, formally | |||
| __builtin_clz(0) is undefined behaviour, so handle this case specially. | |||
| This guarantees ARM-compatible results if happening to compile on a non-ARM | |||
| target, and ensures the compiler doesn't decide to activate any | |||
| optimisations using the logic "value was passed to __builtin_clz, so it | |||
| is non-zero". | |||
| ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a | |||
| single CLZ instruction. | |||
| */ | |||
| if (value == 0U) | |||
| { | |||
| return 32U; | |||
| } | |||
| return __builtin_clz(value); | |||
| } | |||
| /** | |||
| \brief LDR Exclusive (8 bit) | |||
| \details Executes a exclusive LDR instruction for 8 bit value. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint8_t at (*ptr) | |||
| */ | |||
| __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr) | |||
| { | |||
| uint32_t result; | |||
| #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) | |||
| __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) ); | |||
| #else | |||
| /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not | |||
| accepted by assembler. So has to use following less efficient pattern. | |||
| */ | |||
| __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); | |||
| #endif | |||
| return ((uint8_t) result); /* Add explicit type cast here */ | |||
| } | |||
| /** | |||
| \brief LDR Exclusive (16 bit) | |||
| \details Executes a exclusive LDR instruction for 16 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint16_t at (*ptr) | |||
| */ | |||
| __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr) | |||
| { | |||
| uint32_t result; | |||
| #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) | |||
| __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) ); | |||
| #else | |||
| /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not | |||
| accepted by assembler. So has to use following less efficient pattern. | |||
| */ | |||
| __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); | |||
| #endif | |||
| return ((uint16_t) result); /* Add explicit type cast here */ | |||
| } | |||
| /** | |||
| \brief LDR Exclusive (32 bit) | |||
| \details Executes a exclusive LDR instruction for 32 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint32_t at (*ptr) | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) ); | |||
| return(result); | |||
| } | |||
| /** | |||
| \brief STR Exclusive (8 bit) | |||
| \details Executes a exclusive STR instruction for 8 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); | |||
| return(result); | |||
| } | |||
| /** | |||
| \brief STR Exclusive (16 bit) | |||
| \details Executes a exclusive STR instruction for 16 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); | |||
| return(result); | |||
| } | |||
| /** | |||
| \brief STR Exclusive (32 bit) | |||
| \details Executes a exclusive STR instruction for 32 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); | |||
| return(result); | |||
| } | |||
| /** | |||
| \brief Remove the exclusive lock | |||
| \details Removes the exclusive lock which is created by LDREX. | |||
| */ | |||
| __STATIC_FORCEINLINE void __CLREX(void) | |||
| { | |||
| __ASM volatile ("clrex" ::: "memory"); | |||
| } | |||
| /** | |||
| \brief Signed Saturate | |||
| \details Saturates a signed value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (1..32) | |||
| \return Saturated value | |||
| */ | |||
| #define __SSAT(ARG1, ARG2) \ | |||
| __extension__ \ | |||
| ({ \ | |||
| int32_t __RES, __ARG1 = (ARG1); \ | |||
| __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \ | |||
| __RES; \ | |||
| }) | |||
| /** | |||
| \brief Unsigned Saturate | |||
| \details Saturates an unsigned value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (0..31) | |||
| \return Saturated value | |||
| */ | |||
| #define __USAT(ARG1, ARG2) \ | |||
| __extension__ \ | |||
| ({ \ | |||
| uint32_t __RES, __ARG1 = (ARG1); \ | |||
| __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \ | |||
| __RES; \ | |||
| }) | |||
| /* ########################### Core Function Access ########################### */ | |||
| /** | |||
| \brief Enable IRQ Interrupts | |||
| \details Enables IRQ interrupts by clearing the I-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| __STATIC_FORCEINLINE void __enable_irq(void) | |||
| { | |||
| __ASM volatile ("cpsie i" : : : "memory"); | |||
| } | |||
| /** | |||
| \brief Disable IRQ Interrupts | |||
| \details Disables IRQ interrupts by setting the I-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| __STATIC_FORCEINLINE void __disable_irq(void) | |||
| { | |||
| __ASM volatile ("cpsid i" : : : "memory"); | |||
| } | |||
| /** | |||
| \brief Enable FIQ | |||
| \details Enables FIQ interrupts by clearing the F-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| __STATIC_FORCEINLINE void __enable_fault_irq(void) | |||
| { | |||
| __ASM volatile ("cpsie f" : : : "memory"); | |||
| } | |||
| /** | |||
| \brief Disable FIQ | |||
| \details Disables FIQ interrupts by setting the F-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| __STATIC_FORCEINLINE void __disable_fault_irq(void) | |||
| { | |||
| __ASM volatile ("cpsid f" : : : "memory"); | |||
| } | |||
| /** | |||
| \brief Get FPSCR | |||
| \details Returns the current value of the Floating Point Status/Control register. | |||
| \return Floating Point Status/Control register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_FPSCR(void) | |||
| { | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| #if __has_builtin(__builtin_arm_get_fpscr) | |||
| // Re-enable using built-in when GCC has been fixed | |||
| // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) | |||
| /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ | |||
| return __builtin_arm_get_fpscr(); | |||
| #else | |||
| uint32_t result; | |||
| __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); | |||
| return(result); | |||
| #endif | |||
| #else | |||
| return(0U); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Set FPSCR | |||
| \details Assigns the given value to the Floating Point Status/Control register. | |||
| \param [in] fpscr Floating Point Status/Control value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr) | |||
| { | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| #if __has_builtin(__builtin_arm_set_fpscr) | |||
| // Re-enable using built-in when GCC has been fixed | |||
| // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) | |||
| /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ | |||
| __builtin_arm_set_fpscr(fpscr); | |||
| #else | |||
| __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory"); | |||
| #endif | |||
| #else | |||
| (void)fpscr; | |||
| #endif | |||
| } | |||
| /** \brief Get CPSR Register | |||
| \return CPSR Register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_CPSR(void) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile("MRS %0, cpsr" : "=r" (result) ); | |||
| return(result); | |||
| } | |||
| /** \brief Set CPSR Register | |||
| \param [in] cpsr CPSR value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_CPSR(uint32_t cpsr) | |||
| { | |||
| __ASM volatile ("MSR cpsr, %0" : : "r" (cpsr) : "cc", "memory"); | |||
| } | |||
| /** \brief Get Mode | |||
| \return Processor Mode | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_mode(void) | |||
| { | |||
| return (__get_CPSR() & 0x1FU); | |||
| } | |||
| /** \brief Set Mode | |||
| \param [in] mode Mode value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_mode(uint32_t mode) | |||
| { | |||
| __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory"); | |||
| } | |||
| /** \brief Get Stack Pointer | |||
| \return Stack Pointer value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_SP(void) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile("MOV %0, sp" : "=r" (result) : : "memory"); | |||
| return result; | |||
| } | |||
| /** \brief Set Stack Pointer | |||
| \param [in] stack Stack Pointer value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_SP(uint32_t stack) | |||
| { | |||
| __ASM volatile("MOV sp, %0" : : "r" (stack) : "memory"); | |||
| } | |||
| /** \brief Get USR/SYS Stack Pointer | |||
| \return USR/SYS Stack Pointer value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_SP_usr(void) | |||
| { | |||
| uint32_t cpsr = __get_CPSR(); | |||
| uint32_t result; | |||
| __ASM volatile( | |||
| "CPS #0x1F \n" | |||
| "MOV %0, sp " : "=r"(result) : : "memory" | |||
| ); | |||
| __set_CPSR(cpsr); | |||
| __ISB(); | |||
| return result; | |||
| } | |||
| /** \brief Set USR/SYS Stack Pointer | |||
| \param [in] topOfProcStack USR/SYS Stack Pointer value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_SP_usr(uint32_t topOfProcStack) | |||
| { | |||
| uint32_t cpsr = __get_CPSR(); | |||
| __ASM volatile( | |||
| "CPS #0x1F \n" | |||
| "MOV sp, %0 " : : "r" (topOfProcStack) : "memory" | |||
| ); | |||
| __set_CPSR(cpsr); | |||
| __ISB(); | |||
| } | |||
| /** \brief Get FPEXC | |||
| \return Floating Point Exception Control register value | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t __get_FPEXC(void) | |||
| { | |||
| #if (__FPU_PRESENT == 1) | |||
| uint32_t result; | |||
| __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory"); | |||
| return(result); | |||
| #else | |||
| return(0); | |||
| #endif | |||
| } | |||
| /** \brief Set FPEXC | |||
| \param [in] fpexc Floating Point Exception Control value to set | |||
| */ | |||
| __STATIC_FORCEINLINE void __set_FPEXC(uint32_t fpexc) | |||
| { | |||
| #if (__FPU_PRESENT == 1) | |||
| __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory"); | |||
| #endif | |||
| } | |||
| /* | |||
| * Include common core functions to access Coprocessor 15 registers | |||
| */ | |||
| #define __get_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" ) | |||
| #define __set_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" ) | |||
| #define __get_CP64(cp, op1, Rt, CRm) __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" ) | |||
| #define __set_CP64(cp, op1, Rt, CRm) __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" ) | |||
| #include "cmsis_cp15.h" | |||
| /** \brief Enable Floating Point Unit | |||
| Critical section, called from undef handler, so systick is disabled | |||
| */ | |||
| __STATIC_INLINE void __FPU_Enable(void) | |||
| { | |||
| __ASM volatile( | |||
| //Permit access to VFP/NEON, registers by modifying CPACR | |||
| " MRC p15,0,R1,c1,c0,2 \n" | |||
| " ORR R1,R1,#0x00F00000 \n" | |||
| " MCR p15,0,R1,c1,c0,2 \n" | |||
| //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted | |||
| " ISB \n" | |||
| //Enable VFP/NEON | |||
| " VMRS R1,FPEXC \n" | |||
| " ORR R1,R1,#0x40000000 \n" | |||
| " VMSR FPEXC,R1 \n" | |||
| //Initialise VFP/NEON registers to 0 | |||
| " MOV R2,#0 \n" | |||
| //Initialise D16 registers to 0 | |||
| " VMOV D0, R2,R2 \n" | |||
| " VMOV D1, R2,R2 \n" | |||
| " VMOV D2, R2,R2 \n" | |||
| " VMOV D3, R2,R2 \n" | |||
| " VMOV D4, R2,R2 \n" | |||
| " VMOV D5, R2,R2 \n" | |||
| " VMOV D6, R2,R2 \n" | |||
| " VMOV D7, R2,R2 \n" | |||
| " VMOV D8, R2,R2 \n" | |||
| " VMOV D9, R2,R2 \n" | |||
| " VMOV D10,R2,R2 \n" | |||
| " VMOV D11,R2,R2 \n" | |||
| " VMOV D12,R2,R2 \n" | |||
| " VMOV D13,R2,R2 \n" | |||
| " VMOV D14,R2,R2 \n" | |||
| " VMOV D15,R2,R2 \n" | |||
| #if (defined(__ARM_NEON) && (__ARM_NEON == 1)) | |||
| //Initialise D32 registers to 0 | |||
| " VMOV D16,R2,R2 \n" | |||
| " VMOV D17,R2,R2 \n" | |||
| " VMOV D18,R2,R2 \n" | |||
| " VMOV D19,R2,R2 \n" | |||
| " VMOV D20,R2,R2 \n" | |||
| " VMOV D21,R2,R2 \n" | |||
| " VMOV D22,R2,R2 \n" | |||
| " VMOV D23,R2,R2 \n" | |||
| " VMOV D24,R2,R2 \n" | |||
| " VMOV D25,R2,R2 \n" | |||
| " VMOV D26,R2,R2 \n" | |||
| " VMOV D27,R2,R2 \n" | |||
| " VMOV D28,R2,R2 \n" | |||
| " VMOV D29,R2,R2 \n" | |||
| " VMOV D30,R2,R2 \n" | |||
| " VMOV D31,R2,R2 \n" | |||
| #endif | |||
| //Initialise FPSCR to a known state | |||
| " VMRS R1,FPSCR \n" | |||
| " LDR R2,=0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero. | |||
| " AND R1,R1,R2 \n" | |||
| " VMSR FPSCR,R1 " | |||
| : : : "cc", "r1", "r2" | |||
| ); | |||
| } | |||
| #pragma GCC diagnostic pop | |||
| #endif /* __CMSIS_GCC_H */ | |||
| @@ -0,0 +1,573 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_iccarm.h | |||
| * @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file | |||
| * @version V5.0.7 | |||
| * @date 15. May 2019 | |||
| ******************************************************************************/ | |||
| //------------------------------------------------------------------------------ | |||
| // | |||
| // Copyright (c) 2017-2018 IAR Systems | |||
| // Copyright (c) 2018-2019 Arm Limited | |||
| // | |||
| // SPDX-License-Identifier: Apache-2.0 | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License") | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| // | |||
| //------------------------------------------------------------------------------ | |||
| #ifndef __CMSIS_ICCARM_H__ | |||
| #define __CMSIS_ICCARM_H__ | |||
| #ifndef __ICCARM__ | |||
| #error This file should only be compiled by ICCARM | |||
| #endif | |||
| #pragma system_include | |||
| #define __IAR_FT _Pragma("inline=forced") __intrinsic | |||
| #if (__VER__ >= 8000000) | |||
| #define __ICCARM_V8 1 | |||
| #else | |||
| #define __ICCARM_V8 0 | |||
| #endif | |||
| #pragma language=extended | |||
| #ifndef __ALIGNED | |||
| #if __ICCARM_V8 | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #elif (__VER__ >= 7080000) | |||
| /* Needs IAR language extensions */ | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #else | |||
| #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored. | |||
| #define __ALIGNED(x) | |||
| #endif | |||
| #endif | |||
| /* Define compiler macros for CPU architecture, used in CMSIS 5. | |||
| */ | |||
| #if __ARM_ARCH_7A__ | |||
| /* Macro already defined */ | |||
| #else | |||
| #if defined(__ARM7A__) | |||
| #define __ARM_ARCH_7A__ 1 | |||
| #endif | |||
| #endif | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #define __COMPILER_BARRIER() __ASM volatile("":::"memory") | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #if __ICCARM_V8 | |||
| #define __NO_RETURN __attribute__((__noreturn__)) | |||
| #else | |||
| #define __NO_RETURN _Pragma("object_attribute=__noreturn") | |||
| #endif | |||
| #endif | |||
| #ifndef __PACKED | |||
| /* Needs IAR language extensions */ | |||
| #if __ICCARM_V8 | |||
| #define __PACKED __attribute__((packed, aligned(1))) | |||
| #else | |||
| #define __PACKED __packed | |||
| #endif | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| /* Needs IAR language extensions */ | |||
| #if __ICCARM_V8 | |||
| #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) | |||
| #else | |||
| #define __PACKED_STRUCT __packed struct | |||
| #endif | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| /* Needs IAR language extensions */ | |||
| #if __ICCARM_V8 | |||
| #define __PACKED_UNION union __attribute__((packed, aligned(1))) | |||
| #else | |||
| #define __PACKED_UNION __packed union | |||
| #endif | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #if __ICCARM_V8 | |||
| #define __RESTRICT __restrict | |||
| #else | |||
| /* Needs IAR language extensions */ | |||
| #define __RESTRICT restrict | |||
| #endif | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __FORCEINLINE | |||
| #define __FORCEINLINE _Pragma("inline=forced") | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef CMSIS_DEPRECATED | |||
| #define CMSIS_DEPRECATED __attribute__((deprecated)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __IAR_FT uint16_t __iar_uint16_read(void const *ptr) | |||
| { | |||
| return *(__packed uint16_t*)(ptr); | |||
| } | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val) | |||
| { | |||
| *(__packed uint16_t*)(ptr) = val;; | |||
| } | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __IAR_FT uint32_t __iar_uint32_read(void const *ptr) | |||
| { | |||
| return *(__packed uint32_t*)(ptr); | |||
| } | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val) | |||
| { | |||
| *(__packed uint32_t*)(ptr) = val;; | |||
| } | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL) | |||
| #endif | |||
| #if 0 | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __packed struct __iar_u32 { uint32_t v; }; | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v) | |||
| #endif | |||
| #endif | |||
| #ifndef __USED | |||
| #if __ICCARM_V8 | |||
| #define __USED __attribute__((used)) | |||
| #else | |||
| #define __USED _Pragma("__root") | |||
| #endif | |||
| #endif | |||
| #ifndef __WEAK | |||
| #if __ICCARM_V8 | |||
| #define __WEAK __attribute__((weak)) | |||
| #else | |||
| #define __WEAK _Pragma("__weak") | |||
| #endif | |||
| #endif | |||
| #ifndef __ICCARM_INTRINSICS_VERSION__ | |||
| #define __ICCARM_INTRINSICS_VERSION__ 0 | |||
| #endif | |||
| #if __ICCARM_INTRINSICS_VERSION__ == 2 | |||
| #if defined(__CLZ) | |||
| #undef __CLZ | |||
| #endif | |||
| #if defined(__REVSH) | |||
| #undef __REVSH | |||
| #endif | |||
| #if defined(__RBIT) | |||
| #undef __RBIT | |||
| #endif | |||
| #if defined(__SSAT) | |||
| #undef __SSAT | |||
| #endif | |||
| #if defined(__USAT) | |||
| #undef __USAT | |||
| #endif | |||
| #include "iccarm_builtin.h" | |||
| #define __enable_irq __iar_builtin_enable_interrupt | |||
| #define __disable_irq __iar_builtin_disable_interrupt | |||
| #define __enable_fault_irq __iar_builtin_enable_fiq | |||
| #define __disable_fault_irq __iar_builtin_disable_fiq | |||
| #define __arm_rsr __iar_builtin_rsr | |||
| #define __arm_wsr __iar_builtin_wsr | |||
| #if __FPU_PRESENT | |||
| #define __get_FPSCR() (__arm_rsr("FPSCR")) | |||
| #else | |||
| #define __get_FPSCR() ( 0 ) | |||
| #endif | |||
| #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", VALUE)) | |||
| #define __get_CPSR() (__arm_rsr("CPSR")) | |||
| #define __get_mode() (__get_CPSR() & 0x1FU) | |||
| #define __set_CPSR(VALUE) (__arm_wsr("CPSR", (VALUE))) | |||
| #define __set_mode(VALUE) (__arm_wsr("CPSR_c", (VALUE))) | |||
| #define __get_FPEXC() (__arm_rsr("FPEXC")) | |||
| #define __set_FPEXC(VALUE) (__arm_wsr("FPEXC", VALUE)) | |||
| #define __get_CP(cp, op1, RT, CRn, CRm, op2) \ | |||
| ((RT) = __arm_rsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2)) | |||
| #define __set_CP(cp, op1, RT, CRn, CRm, op2) \ | |||
| (__arm_wsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2, (RT))) | |||
| #define __get_CP64(cp, op1, Rt, CRm) \ | |||
| __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" ) | |||
| #define __set_CP64(cp, op1, Rt, CRm) \ | |||
| __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" ) | |||
| #include "cmsis_cp15.h" | |||
| #define __NOP __iar_builtin_no_operation | |||
| #define __CLZ __iar_builtin_CLZ | |||
| #define __CLREX __iar_builtin_CLREX | |||
| #define __DMB __iar_builtin_DMB | |||
| #define __DSB __iar_builtin_DSB | |||
| #define __ISB __iar_builtin_ISB | |||
| #define __LDREXB __iar_builtin_LDREXB | |||
| #define __LDREXH __iar_builtin_LDREXH | |||
| #define __LDREXW __iar_builtin_LDREX | |||
| #define __RBIT __iar_builtin_RBIT | |||
| #define __REV __iar_builtin_REV | |||
| #define __REV16 __iar_builtin_REV16 | |||
| __IAR_FT int16_t __REVSH(int16_t val) | |||
| { | |||
| return (int16_t) __iar_builtin_REVSH(val); | |||
| } | |||
| #define __ROR __iar_builtin_ROR | |||
| #define __RRX __iar_builtin_RRX | |||
| #define __SEV __iar_builtin_SEV | |||
| #define __SSAT __iar_builtin_SSAT | |||
| #define __STREXB __iar_builtin_STREXB | |||
| #define __STREXH __iar_builtin_STREXH | |||
| #define __STREXW __iar_builtin_STREX | |||
| #define __USAT __iar_builtin_USAT | |||
| #define __WFE __iar_builtin_WFE | |||
| #define __WFI __iar_builtin_WFI | |||
| #define __SADD8 __iar_builtin_SADD8 | |||
| #define __QADD8 __iar_builtin_QADD8 | |||
| #define __SHADD8 __iar_builtin_SHADD8 | |||
| #define __UADD8 __iar_builtin_UADD8 | |||
| #define __UQADD8 __iar_builtin_UQADD8 | |||
| #define __UHADD8 __iar_builtin_UHADD8 | |||
| #define __SSUB8 __iar_builtin_SSUB8 | |||
| #define __QSUB8 __iar_builtin_QSUB8 | |||
| #define __SHSUB8 __iar_builtin_SHSUB8 | |||
| #define __USUB8 __iar_builtin_USUB8 | |||
| #define __UQSUB8 __iar_builtin_UQSUB8 | |||
| #define __UHSUB8 __iar_builtin_UHSUB8 | |||
| #define __SADD16 __iar_builtin_SADD16 | |||
| #define __QADD16 __iar_builtin_QADD16 | |||
| #define __SHADD16 __iar_builtin_SHADD16 | |||
| #define __UADD16 __iar_builtin_UADD16 | |||
| #define __UQADD16 __iar_builtin_UQADD16 | |||
| #define __UHADD16 __iar_builtin_UHADD16 | |||
| #define __SSUB16 __iar_builtin_SSUB16 | |||
| #define __QSUB16 __iar_builtin_QSUB16 | |||
| #define __SHSUB16 __iar_builtin_SHSUB16 | |||
| #define __USUB16 __iar_builtin_USUB16 | |||
| #define __UQSUB16 __iar_builtin_UQSUB16 | |||
| #define __UHSUB16 __iar_builtin_UHSUB16 | |||
| #define __SASX __iar_builtin_SASX | |||
| #define __QASX __iar_builtin_QASX | |||
| #define __SHASX __iar_builtin_SHASX | |||
| #define __UASX __iar_builtin_UASX | |||
| #define __UQASX __iar_builtin_UQASX | |||
| #define __UHASX __iar_builtin_UHASX | |||
| #define __SSAX __iar_builtin_SSAX | |||
| #define __QSAX __iar_builtin_QSAX | |||
| #define __SHSAX __iar_builtin_SHSAX | |||
| #define __USAX __iar_builtin_USAX | |||
| #define __UQSAX __iar_builtin_UQSAX | |||
| #define __UHSAX __iar_builtin_UHSAX | |||
| #define __USAD8 __iar_builtin_USAD8 | |||
| #define __USADA8 __iar_builtin_USADA8 | |||
| #define __SSAT16 __iar_builtin_SSAT16 | |||
| #define __USAT16 __iar_builtin_USAT16 | |||
| #define __UXTB16 __iar_builtin_UXTB16 | |||
| #define __UXTAB16 __iar_builtin_UXTAB16 | |||
| #define __SXTB16 __iar_builtin_SXTB16 | |||
| #define __SXTAB16 __iar_builtin_SXTAB16 | |||
| #define __SMUAD __iar_builtin_SMUAD | |||
| #define __SMUADX __iar_builtin_SMUADX | |||
| #define __SMMLA __iar_builtin_SMMLA | |||
| #define __SMLAD __iar_builtin_SMLAD | |||
| #define __SMLADX __iar_builtin_SMLADX | |||
| #define __SMLALD __iar_builtin_SMLALD | |||
| #define __SMLALDX __iar_builtin_SMLALDX | |||
| #define __SMUSD __iar_builtin_SMUSD | |||
| #define __SMUSDX __iar_builtin_SMUSDX | |||
| #define __SMLSD __iar_builtin_SMLSD | |||
| #define __SMLSDX __iar_builtin_SMLSDX | |||
| #define __SMLSLD __iar_builtin_SMLSLD | |||
| #define __SMLSLDX __iar_builtin_SMLSLDX | |||
| #define __SEL __iar_builtin_SEL | |||
| #define __QADD __iar_builtin_QADD | |||
| #define __QSUB __iar_builtin_QSUB | |||
| #define __PKHBT __iar_builtin_PKHBT | |||
| #define __PKHTB __iar_builtin_PKHTB | |||
| #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */ | |||
| #if !__FPU_PRESENT | |||
| #define __get_FPSCR __cmsis_iar_get_FPSR_not_active | |||
| #endif | |||
| #ifdef __INTRINSICS_INCLUDED | |||
| #error intrinsics.h is already included previously! | |||
| #endif | |||
| #include <intrinsics.h> | |||
| #if !__FPU_PRESENT | |||
| #define __get_FPSCR() (0) | |||
| #endif | |||
| #pragma diag_suppress=Pe940 | |||
| #pragma diag_suppress=Pe177 | |||
| #define __enable_irq __enable_interrupt | |||
| #define __disable_irq __disable_interrupt | |||
| #define __enable_fault_irq __enable_fiq | |||
| #define __disable_fault_irq __disable_fiq | |||
| #define __NOP __no_operation | |||
| #define __get_xPSR __get_PSR | |||
| __IAR_FT void __set_mode(uint32_t mode) | |||
| { | |||
| __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory"); | |||
| } | |||
| __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr) | |||
| { | |||
| return __LDREX((unsigned long *)ptr); | |||
| } | |||
| __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr) | |||
| { | |||
| return __STREX(value, (unsigned long *)ptr); | |||
| } | |||
| __IAR_FT uint32_t __RRX(uint32_t value) | |||
| { | |||
| uint32_t result; | |||
| __ASM("RRX %0, %1" : "=r"(result) : "r" (value) : "cc"); | |||
| return(result); | |||
| } | |||
| __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2) | |||
| { | |||
| return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2)); | |||
| } | |||
| __IAR_FT uint32_t __get_FPEXC(void) | |||
| { | |||
| #if (__FPU_PRESENT == 1) | |||
| uint32_t result; | |||
| __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory"); | |||
| return(result); | |||
| #else | |||
| return(0); | |||
| #endif | |||
| } | |||
| __IAR_FT void __set_FPEXC(uint32_t fpexc) | |||
| { | |||
| #if (__FPU_PRESENT == 1) | |||
| __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory"); | |||
| #endif | |||
| } | |||
| #define __get_CP(cp, op1, Rt, CRn, CRm, op2) \ | |||
| __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" ) | |||
| #define __set_CP(cp, op1, Rt, CRn, CRm, op2) \ | |||
| __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" ) | |||
| #define __get_CP64(cp, op1, Rt, CRm) \ | |||
| __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" ) | |||
| #define __set_CP64(cp, op1, Rt, CRm) \ | |||
| __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" ) | |||
| #include "cmsis_cp15.h" | |||
| #endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */ | |||
| #define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value)) | |||
| __IAR_FT uint32_t __get_SP_usr(void) | |||
| { | |||
| uint32_t cpsr; | |||
| uint32_t result; | |||
| __ASM volatile( | |||
| "MRS %0, cpsr \n" | |||
| "CPS #0x1F \n" // no effect in USR mode | |||
| "MOV %1, sp \n" | |||
| "MSR cpsr_c, %2 \n" // no effect in USR mode | |||
| "ISB" : "=r"(cpsr), "=r"(result) : "r"(cpsr) : "memory" | |||
| ); | |||
| return result; | |||
| } | |||
| __IAR_FT void __set_SP_usr(uint32_t topOfProcStack) | |||
| { | |||
| uint32_t cpsr; | |||
| __ASM volatile( | |||
| "MRS %0, cpsr \n" | |||
| "CPS #0x1F \n" // no effect in USR mode | |||
| "MOV sp, %1 \n" | |||
| "MSR cpsr_c, %2 \n" // no effect in USR mode | |||
| "ISB" : "=r"(cpsr) : "r" (topOfProcStack), "r"(cpsr) : "memory" | |||
| ); | |||
| } | |||
| #define __get_mode() (__get_CPSR() & 0x1FU) | |||
| __STATIC_INLINE | |||
| void __FPU_Enable(void) | |||
| { | |||
| __ASM volatile( | |||
| //Permit access to VFP/NEON, registers by modifying CPACR | |||
| " MRC p15,0,R1,c1,c0,2 \n" | |||
| " ORR R1,R1,#0x00F00000 \n" | |||
| " MCR p15,0,R1,c1,c0,2 \n" | |||
| //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted | |||
| " ISB \n" | |||
| //Enable VFP/NEON | |||
| " VMRS R1,FPEXC \n" | |||
| " ORR R1,R1,#0x40000000 \n" | |||
| " VMSR FPEXC,R1 \n" | |||
| //Initialise VFP/NEON registers to 0 | |||
| " MOV R2,#0 \n" | |||
| //Initialise D16 registers to 0 | |||
| " VMOV D0, R2,R2 \n" | |||
| " VMOV D1, R2,R2 \n" | |||
| " VMOV D2, R2,R2 \n" | |||
| " VMOV D3, R2,R2 \n" | |||
| " VMOV D4, R2,R2 \n" | |||
| " VMOV D5, R2,R2 \n" | |||
| " VMOV D6, R2,R2 \n" | |||
| " VMOV D7, R2,R2 \n" | |||
| " VMOV D8, R2,R2 \n" | |||
| " VMOV D9, R2,R2 \n" | |||
| " VMOV D10,R2,R2 \n" | |||
| " VMOV D11,R2,R2 \n" | |||
| " VMOV D12,R2,R2 \n" | |||
| " VMOV D13,R2,R2 \n" | |||
| " VMOV D14,R2,R2 \n" | |||
| " VMOV D15,R2,R2 \n" | |||
| #ifdef __ARM_ADVANCED_SIMD__ | |||
| //Initialise D32 registers to 0 | |||
| " VMOV D16,R2,R2 \n" | |||
| " VMOV D17,R2,R2 \n" | |||
| " VMOV D18,R2,R2 \n" | |||
| " VMOV D19,R2,R2 \n" | |||
| " VMOV D20,R2,R2 \n" | |||
| " VMOV D21,R2,R2 \n" | |||
| " VMOV D22,R2,R2 \n" | |||
| " VMOV D23,R2,R2 \n" | |||
| " VMOV D24,R2,R2 \n" | |||
| " VMOV D25,R2,R2 \n" | |||
| " VMOV D26,R2,R2 \n" | |||
| " VMOV D27,R2,R2 \n" | |||
| " VMOV D28,R2,R2 \n" | |||
| " VMOV D29,R2,R2 \n" | |||
| " VMOV D30,R2,R2 \n" | |||
| " VMOV D31,R2,R2 \n" | |||
| #endif | |||
| //Initialise FPSCR to a known state | |||
| " VMRS R1,FPSCR \n" | |||
| " MOV32 R2,#0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero. | |||
| " AND R1,R1,R2 \n" | |||
| " VMSR FPSCR,R1 \n" | |||
| : : : "cc", "r1", "r2" | |||
| ); | |||
| } | |||
| #undef __IAR_FT | |||
| #undef __ICCARM_V8 | |||
| #pragma diag_default=Pe940 | |||
| #pragma diag_default=Pe177 | |||
| #endif /* __CMSIS_ICCARM_H__ */ | |||
| @@ -0,0 +1,192 @@ | |||
| /**************************************************************************//** | |||
| * @file irq_ctrl.h | |||
| * @brief Interrupt Controller API header file | |||
| * @version V1.1.0 | |||
| * @date 03. March 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2017-2020 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef IRQ_CTRL_H_ | |||
| #define IRQ_CTRL_H_ | |||
| #include <stdint.h> | |||
| #ifndef IRQHANDLER_T | |||
| #define IRQHANDLER_T | |||
| /// Interrupt handler data type | |||
| typedef void (*IRQHandler_t) (void); | |||
| #endif | |||
| #ifndef IRQN_ID_T | |||
| #define IRQN_ID_T | |||
| /// Interrupt ID number data type | |||
| typedef int32_t IRQn_ID_t; | |||
| #endif | |||
| /* Interrupt mode bit-masks */ | |||
| #define IRQ_MODE_TRIG_Pos (0U) | |||
| #define IRQ_MODE_TRIG_Msk (0x07UL /*<< IRQ_MODE_TRIG_Pos*/) | |||
| #define IRQ_MODE_TRIG_LEVEL (0x00UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: level triggered interrupt | |||
| #define IRQ_MODE_TRIG_LEVEL_LOW (0x01UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: low level triggered interrupt | |||
| #define IRQ_MODE_TRIG_LEVEL_HIGH (0x02UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: high level triggered interrupt | |||
| #define IRQ_MODE_TRIG_EDGE (0x04UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: edge triggered interrupt | |||
| #define IRQ_MODE_TRIG_EDGE_RISING (0x05UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: rising edge triggered interrupt | |||
| #define IRQ_MODE_TRIG_EDGE_FALLING (0x06UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: falling edge triggered interrupt | |||
| #define IRQ_MODE_TRIG_EDGE_BOTH (0x07UL /*<< IRQ_MODE_TRIG_Pos*/) ///< Trigger: rising and falling edge triggered interrupt | |||
| #define IRQ_MODE_TYPE_Pos (3U) | |||
| #define IRQ_MODE_TYPE_Msk (0x01UL << IRQ_MODE_TYPE_Pos) | |||
| #define IRQ_MODE_TYPE_IRQ (0x00UL << IRQ_MODE_TYPE_Pos) ///< Type: interrupt source triggers CPU IRQ line | |||
| #define IRQ_MODE_TYPE_FIQ (0x01UL << IRQ_MODE_TYPE_Pos) ///< Type: interrupt source triggers CPU FIQ line | |||
| #define IRQ_MODE_DOMAIN_Pos (4U) | |||
| #define IRQ_MODE_DOMAIN_Msk (0x01UL << IRQ_MODE_DOMAIN_Pos) | |||
| #define IRQ_MODE_DOMAIN_NONSECURE (0x00UL << IRQ_MODE_DOMAIN_Pos) ///< Domain: interrupt is targeting non-secure domain | |||
| #define IRQ_MODE_DOMAIN_SECURE (0x01UL << IRQ_MODE_DOMAIN_Pos) ///< Domain: interrupt is targeting secure domain | |||
| #define IRQ_MODE_CPU_Pos (5U) | |||
| #define IRQ_MODE_CPU_Msk (0xFFUL << IRQ_MODE_CPU_Pos) | |||
| #define IRQ_MODE_CPU_ALL (0x00UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets all CPUs | |||
| #define IRQ_MODE_CPU_0 (0x01UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 0 | |||
| #define IRQ_MODE_CPU_1 (0x02UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 1 | |||
| #define IRQ_MODE_CPU_2 (0x04UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 2 | |||
| #define IRQ_MODE_CPU_3 (0x08UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 3 | |||
| #define IRQ_MODE_CPU_4 (0x10UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 4 | |||
| #define IRQ_MODE_CPU_5 (0x20UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 5 | |||
| #define IRQ_MODE_CPU_6 (0x40UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 6 | |||
| #define IRQ_MODE_CPU_7 (0x80UL << IRQ_MODE_CPU_Pos) ///< CPU: interrupt targets CPU 7 | |||
| // Encoding in some early GIC implementations | |||
| #define IRQ_MODE_MODEL_Pos (13U) | |||
| #define IRQ_MODE_MODEL_Msk (0x1UL << IRQ_MODE_MODEL_Pos) | |||
| #define IRQ_MODE_MODEL_NN (0x0UL << IRQ_MODE_MODEL_Pos) ///< Corresponding interrupt is handled using the N-N model | |||
| #define IRQ_MODE_MODEL_1N (0x1UL << IRQ_MODE_MODEL_Pos) ///< Corresponding interrupt is handled using the 1-N model | |||
| #define IRQ_MODE_ERROR (0x80000000UL) ///< Bit indicating mode value error | |||
| /* Interrupt priority bit-masks */ | |||
| #define IRQ_PRIORITY_Msk (0x0000FFFFUL) ///< Interrupt priority value bit-mask | |||
| #define IRQ_PRIORITY_ERROR (0x80000000UL) ///< Bit indicating priority value error | |||
| /// Initialize interrupt controller. | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_Initialize (void); | |||
| /// Register interrupt handler. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \param[in] handler interrupt handler function address | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_SetHandler (IRQn_ID_t irqn, IRQHandler_t handler); | |||
| /// Get the registered interrupt handler. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return registered interrupt handler function address. | |||
| IRQHandler_t IRQ_GetHandler (IRQn_ID_t irqn); | |||
| /// Enable interrupt. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_Enable (IRQn_ID_t irqn); | |||
| /// Disable interrupt. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_Disable (IRQn_ID_t irqn); | |||
| /// Get interrupt enable state. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return 0 - interrupt is disabled, 1 - interrupt is enabled. | |||
| uint32_t IRQ_GetEnableState (IRQn_ID_t irqn); | |||
| /// Configure interrupt request mode. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \param[in] mode mode configuration | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_SetMode (IRQn_ID_t irqn, uint32_t mode); | |||
| /// Get interrupt mode configuration. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return current interrupt mode configuration with optional IRQ_MODE_ERROR bit set. | |||
| uint32_t IRQ_GetMode (IRQn_ID_t irqn); | |||
| /// Get ID number of current interrupt request (IRQ). | |||
| /// \return interrupt ID number. | |||
| IRQn_ID_t IRQ_GetActiveIRQ (void); | |||
| /// Get ID number of current fast interrupt request (FIQ). | |||
| /// \return interrupt ID number. | |||
| IRQn_ID_t IRQ_GetActiveFIQ (void); | |||
| /// Signal end of interrupt processing. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_EndOfInterrupt (IRQn_ID_t irqn); | |||
| /// Set interrupt pending flag. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_SetPending (IRQn_ID_t irqn); | |||
| /// Get interrupt pending flag. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return 0 - interrupt is not pending, 1 - interrupt is pending. | |||
| uint32_t IRQ_GetPending (IRQn_ID_t irqn); | |||
| /// Clear interrupt pending flag. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_ClearPending (IRQn_ID_t irqn); | |||
| /// Set interrupt priority value. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \param[in] priority interrupt priority value | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_SetPriority (IRQn_ID_t irqn, uint32_t priority); | |||
| /// Get interrupt priority. | |||
| /// \param[in] irqn interrupt ID number | |||
| /// \return current interrupt priority value with optional IRQ_PRIORITY_ERROR bit set. | |||
| uint32_t IRQ_GetPriority (IRQn_ID_t irqn); | |||
| /// Set priority masking threshold. | |||
| /// \param[in] priority priority masking threshold value | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_SetPriorityMask (uint32_t priority); | |||
| /// Get priority masking threshold | |||
| /// \return current priority masking threshold value with optional IRQ_PRIORITY_ERROR bit set. | |||
| uint32_t IRQ_GetPriorityMask (void); | |||
| /// Set priority grouping field split point | |||
| /// \param[in] bits number of MSB bits included in the group priority field comparison | |||
| /// \return 0 on success, -1 on error. | |||
| int32_t IRQ_SetPriorityGroupBits (uint32_t bits); | |||
| /// Get priority grouping field split point | |||
| /// \return current number of MSB bits included in the group priority field comparison with | |||
| /// optional IRQ_PRIORITY_ERROR bit set. | |||
| uint32_t IRQ_GetPriorityGroupBits (void); | |||
| #endif // IRQ_CTRL_H_ | |||
| @@ -0,0 +1,418 @@ | |||
| /**************************************************************************//** | |||
| * @file irq_ctrl_gic.c | |||
| * @brief Interrupt controller handling implementation for GIC | |||
| * @version V1.1.1 | |||
| * @date 29. March 2021 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2017-2021 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include <stddef.h> | |||
| #include "RTE_Components.h" | |||
| #include CMSIS_device_header | |||
| #include "irq_ctrl.h" | |||
| #if defined(__GIC_PRESENT) && (__GIC_PRESENT == 1U) | |||
| /// Number of implemented interrupt lines | |||
| #ifndef IRQ_GIC_LINE_COUNT | |||
| #define IRQ_GIC_LINE_COUNT (1020U) | |||
| #endif | |||
| static IRQHandler_t IRQTable[IRQ_GIC_LINE_COUNT] = { 0U }; | |||
| static uint32_t IRQ_ID0; | |||
| /// Initialize interrupt controller. | |||
| __WEAK int32_t IRQ_Initialize (void) { | |||
| uint32_t i; | |||
| for (i = 0U; i < IRQ_GIC_LINE_COUNT; i++) { | |||
| IRQTable[i] = (IRQHandler_t)NULL; | |||
| } | |||
| GIC_Enable(); | |||
| return (0); | |||
| } | |||
| /// Register interrupt handler. | |||
| __WEAK int32_t IRQ_SetHandler (IRQn_ID_t irqn, IRQHandler_t handler) { | |||
| int32_t status; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| IRQTable[irqn] = handler; | |||
| status = 0; | |||
| } else { | |||
| status = -1; | |||
| } | |||
| return (status); | |||
| } | |||
| /// Get the registered interrupt handler. | |||
| __WEAK IRQHandler_t IRQ_GetHandler (IRQn_ID_t irqn) { | |||
| IRQHandler_t h; | |||
| // Ignore CPUID field (software generated interrupts) | |||
| irqn &= 0x3FFU; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| h = IRQTable[irqn]; | |||
| } else { | |||
| h = (IRQHandler_t)0; | |||
| } | |||
| return (h); | |||
| } | |||
| /// Enable interrupt. | |||
| __WEAK int32_t IRQ_Enable (IRQn_ID_t irqn) { | |||
| int32_t status; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| GIC_EnableIRQ ((IRQn_Type)irqn); | |||
| status = 0; | |||
| } else { | |||
| status = -1; | |||
| } | |||
| return (status); | |||
| } | |||
| /// Disable interrupt. | |||
| __WEAK int32_t IRQ_Disable (IRQn_ID_t irqn) { | |||
| int32_t status; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| GIC_DisableIRQ ((IRQn_Type)irqn); | |||
| status = 0; | |||
| } else { | |||
| status = -1; | |||
| } | |||
| return (status); | |||
| } | |||
| /// Get interrupt enable state. | |||
| __WEAK uint32_t IRQ_GetEnableState (IRQn_ID_t irqn) { | |||
| uint32_t enable; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| enable = GIC_GetEnableIRQ((IRQn_Type)irqn); | |||
| } else { | |||
| enable = 0U; | |||
| } | |||
| return (enable); | |||
| } | |||
| /// Configure interrupt request mode. | |||
| __WEAK int32_t IRQ_SetMode (IRQn_ID_t irqn, uint32_t mode) { | |||
| uint32_t val; | |||
| uint8_t cfg; | |||
| uint8_t secure; | |||
| uint8_t cpu; | |||
| int32_t status = 0; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| // Check triggering mode | |||
| val = (mode & IRQ_MODE_TRIG_Msk); | |||
| if (val == IRQ_MODE_TRIG_LEVEL) { | |||
| cfg = 0x00U; | |||
| } else if (val == IRQ_MODE_TRIG_EDGE) { | |||
| cfg = 0x02U; | |||
| } else { | |||
| cfg = 0x00U; | |||
| status = -1; | |||
| } | |||
| val = (mode & IRQ_MODE_MODEL_Msk); | |||
| if (val == IRQ_MODE_MODEL_1N) { | |||
| cfg |= 1; // 1-N model | |||
| } | |||
| // Check interrupt type | |||
| val = mode & IRQ_MODE_TYPE_Msk; | |||
| if (val != IRQ_MODE_TYPE_IRQ) { | |||
| status = -1; | |||
| } | |||
| // Check interrupt domain | |||
| val = mode & IRQ_MODE_DOMAIN_Msk; | |||
| if (val == IRQ_MODE_DOMAIN_NONSECURE) { | |||
| secure = 0U; | |||
| } else { | |||
| // Check security extensions support | |||
| val = GIC_DistributorInfo() & (1UL << 10U); | |||
| if (val != 0U) { | |||
| // Security extensions are supported | |||
| secure = 1U; | |||
| } else { | |||
| secure = 0U; | |||
| status = -1; | |||
| } | |||
| } | |||
| // Check interrupt CPU targets | |||
| val = mode & IRQ_MODE_CPU_Msk; | |||
| if (val == IRQ_MODE_CPU_ALL) { | |||
| cpu = 0xFFU; | |||
| } else { | |||
| cpu = (uint8_t)(val >> IRQ_MODE_CPU_Pos); | |||
| } | |||
| // Apply configuration if no mode error | |||
| if (status == 0) { | |||
| GIC_SetConfiguration((IRQn_Type)irqn, cfg); | |||
| GIC_SetTarget ((IRQn_Type)irqn, cpu); | |||
| if (secure != 0U) { | |||
| GIC_SetGroup ((IRQn_Type)irqn, secure); | |||
| } | |||
| } | |||
| } | |||
| return (status); | |||
| } | |||
| /// Get interrupt mode configuration. | |||
| __WEAK uint32_t IRQ_GetMode (IRQn_ID_t irqn) { | |||
| uint32_t mode; | |||
| uint32_t val; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| mode = IRQ_MODE_TYPE_IRQ; | |||
| // Get trigger mode | |||
| val = GIC_GetConfiguration((IRQn_Type)irqn); | |||
| if ((val & 2U) != 0U) { | |||
| // Corresponding interrupt is edge triggered | |||
| mode |= IRQ_MODE_TRIG_EDGE; | |||
| } else { | |||
| // Corresponding interrupt is level triggered | |||
| mode |= IRQ_MODE_TRIG_LEVEL; | |||
| } | |||
| if (val & 1U) { | |||
| mode |= IRQ_MODE_MODEL_1N; | |||
| } | |||
| // Get interrupt CPU targets | |||
| mode |= GIC_GetTarget ((IRQn_Type)irqn) << IRQ_MODE_CPU_Pos; | |||
| } else { | |||
| mode = IRQ_MODE_ERROR; | |||
| } | |||
| return (mode); | |||
| } | |||
| /// Get ID number of current interrupt request (IRQ). | |||
| __WEAK IRQn_ID_t IRQ_GetActiveIRQ (void) { | |||
| IRQn_ID_t irqn; | |||
| uint32_t prio; | |||
| /* Dummy read to avoid GIC 390 errata 801120 */ | |||
| GIC_GetHighPendingIRQ(); | |||
| irqn = GIC_AcknowledgePending(); | |||
| __DSB(); | |||
| /* Workaround GIC 390 errata 733075 (GIC-390_Errata_Notice_v6.pdf, 09-Jul-2014) */ | |||
| /* The following workaround code is for a single-core system. It would be */ | |||
| /* different in a multi-core system. */ | |||
| /* If the ID is 0 or 0x3FE or 0x3FF, then the GIC CPU interface may be locked-up */ | |||
| /* so unlock it, otherwise service the interrupt as normal. */ | |||
| /* Special IDs 1020=0x3FC and 1021=0x3FD are reserved values in GICv1 and GICv2 */ | |||
| /* so will not occur here. */ | |||
| if ((irqn == 0) || (irqn >= 0x3FE)) { | |||
| /* Unlock the CPU interface with a dummy write to Interrupt Priority Register */ | |||
| prio = GIC_GetPriority((IRQn_Type)0); | |||
| GIC_SetPriority ((IRQn_Type)0, prio); | |||
| __DSB(); | |||
| if ((irqn == 0U) && ((GIC_GetIRQStatus ((IRQn_Type)irqn) & 1U) != 0U) && (IRQ_ID0 == 0U)) { | |||
| /* If the ID is 0, is active and has not been seen before */ | |||
| IRQ_ID0 = 1U; | |||
| } | |||
| /* End of Workaround GIC 390 errata 733075 */ | |||
| } | |||
| return (irqn); | |||
| } | |||
| /// Get ID number of current fast interrupt request (FIQ). | |||
| __WEAK IRQn_ID_t IRQ_GetActiveFIQ (void) { | |||
| return ((IRQn_ID_t)-1); | |||
| } | |||
| /// Signal end of interrupt processing. | |||
| __WEAK int32_t IRQ_EndOfInterrupt (IRQn_ID_t irqn) { | |||
| int32_t status; | |||
| IRQn_Type irq = (IRQn_Type)irqn; | |||
| irqn &= 0x3FFU; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| GIC_EndInterrupt (irq); | |||
| if (irqn == 0) { | |||
| IRQ_ID0 = 0U; | |||
| } | |||
| status = 0; | |||
| } else { | |||
| status = -1; | |||
| } | |||
| return (status); | |||
| } | |||
| /// Set interrupt pending flag. | |||
| __WEAK int32_t IRQ_SetPending (IRQn_ID_t irqn) { | |||
| int32_t status; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| GIC_SetPendingIRQ ((IRQn_Type)irqn); | |||
| status = 0; | |||
| } else { | |||
| status = -1; | |||
| } | |||
| return (status); | |||
| } | |||
| /// Get interrupt pending flag. | |||
| __WEAK uint32_t IRQ_GetPending (IRQn_ID_t irqn) { | |||
| uint32_t pending; | |||
| if ((irqn >= 16) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| pending = GIC_GetPendingIRQ ((IRQn_Type)irqn); | |||
| } else { | |||
| pending = 0U; | |||
| } | |||
| return (pending & 1U); | |||
| } | |||
| /// Clear interrupt pending flag. | |||
| __WEAK int32_t IRQ_ClearPending (IRQn_ID_t irqn) { | |||
| int32_t status; | |||
| if ((irqn >= 16) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| GIC_ClearPendingIRQ ((IRQn_Type)irqn); | |||
| status = 0; | |||
| } else { | |||
| status = -1; | |||
| } | |||
| return (status); | |||
| } | |||
| /// Set interrupt priority value. | |||
| __WEAK int32_t IRQ_SetPriority (IRQn_ID_t irqn, uint32_t priority) { | |||
| int32_t status; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| GIC_SetPriority ((IRQn_Type)irqn, priority); | |||
| status = 0; | |||
| } else { | |||
| status = -1; | |||
| } | |||
| return (status); | |||
| } | |||
| /// Get interrupt priority. | |||
| __WEAK uint32_t IRQ_GetPriority (IRQn_ID_t irqn) { | |||
| uint32_t priority; | |||
| if ((irqn >= 0) && (irqn < (IRQn_ID_t)IRQ_GIC_LINE_COUNT)) { | |||
| priority = GIC_GetPriority ((IRQn_Type)irqn); | |||
| } else { | |||
| priority = IRQ_PRIORITY_ERROR; | |||
| } | |||
| return (priority); | |||
| } | |||
| /// Set priority masking threshold. | |||
| __WEAK int32_t IRQ_SetPriorityMask (uint32_t priority) { | |||
| GIC_SetInterfacePriorityMask (priority); | |||
| return (0); | |||
| } | |||
| /// Get priority masking threshold | |||
| __WEAK uint32_t IRQ_GetPriorityMask (void) { | |||
| return GIC_GetInterfacePriorityMask(); | |||
| } | |||
| /// Set priority grouping field split point | |||
| __WEAK int32_t IRQ_SetPriorityGroupBits (uint32_t bits) { | |||
| int32_t status; | |||
| if (bits == IRQ_PRIORITY_Msk) { | |||
| bits = 7U; | |||
| } | |||
| if (bits < 8U) { | |||
| GIC_SetBinaryPoint (7U - bits); | |||
| status = 0; | |||
| } else { | |||
| status = -1; | |||
| } | |||
| return (status); | |||
| } | |||
| /// Get priority grouping field split point | |||
| __WEAK uint32_t IRQ_GetPriorityGroupBits (void) { | |||
| uint32_t bp; | |||
| bp = GIC_GetBinaryPoint() & 0x07U; | |||
| return (7U - bp); | |||
| } | |||
| #endif | |||
| @@ -0,0 +1,561 @@ | |||
| /* | |||
| * Copyright (c) 2013-2021 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| * ---------------------------------------------------------------------- | |||
| * | |||
| * $Date: 16. June 2021 | |||
| * $Revision: V2.1.0 | |||
| * | |||
| * Project: CMSIS-DAP Configuration | |||
| * Title: DAP_config.h CMSIS-DAP Configuration File (Template) | |||
| * | |||
| *---------------------------------------------------------------------------*/ | |||
| #ifndef __DAP_CONFIG_H__ | |||
| #define __DAP_CONFIG_H__ | |||
| //************************************************************************************************** | |||
| /** | |||
| \defgroup DAP_Config_Debug_gr CMSIS-DAP Debug Unit Information | |||
| \ingroup DAP_ConfigIO_gr | |||
| @{ | |||
| Provides definitions about the hardware and configuration of the Debug Unit. | |||
| This information includes: | |||
| - Definition of Cortex-M processor parameters used in CMSIS-DAP Debug Unit. | |||
| - Debug Unit Identification strings (Vendor, Product, Serial Number). | |||
| - Debug Unit communication packet size. | |||
| - Debug Access Port supported modes and settings (JTAG/SWD and SWO). | |||
| - Optional information about a connected Target Device (for Evaluation Boards). | |||
| */ | |||
| #ifdef _RTE_ | |||
| #include "RTE_Components.h" | |||
| #include CMSIS_device_header | |||
| #else | |||
| #include "device.h" // Debug Unit Cortex-M Processor Header File | |||
| #endif | |||
| /// Processor Clock of the Cortex-M MCU used in the Debug Unit. | |||
| /// This value is used to calculate the SWD/JTAG clock speed. | |||
| #define CPU_CLOCK 100000000U ///< Specifies the CPU Clock in Hz. | |||
| /// Number of processor cycles for I/O Port write operations. | |||
| /// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O | |||
| /// Port write operations in the Debug Unit by a Cortex-M MCU. Most Cortex-M processors | |||
| /// require 2 processor cycles for a I/O Port Write operation. If the Debug Unit uses | |||
| /// a Cortex-M0+ processor with high-speed peripheral I/O only 1 processor cycle might be | |||
| /// required. | |||
| #define IO_PORT_WRITE_CYCLES 2U ///< I/O Cycles: 2=default, 1=Cortex-M0+ fast I/0. | |||
| /// Indicate that Serial Wire Debug (SWD) communication mode is available at the Debug Access Port. | |||
| /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>. | |||
| #define DAP_SWD 1 ///< SWD Mode: 1 = available, 0 = not available. | |||
| /// Indicate that JTAG communication mode is available at the Debug Port. | |||
| /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>. | |||
| #define DAP_JTAG 1 ///< JTAG Mode: 1 = available, 0 = not available. | |||
| /// Configure maximum number of JTAG devices on the scan chain connected to the Debug Access Port. | |||
| /// This setting impacts the RAM requirements of the Debug Unit. Valid range is 1 .. 255. | |||
| #define DAP_JTAG_DEV_CNT 8U ///< Maximum number of JTAG devices on scan chain. | |||
| /// Default communication mode on the Debug Access Port. | |||
| /// Used for the command \ref DAP_Connect when Port Default mode is selected. | |||
| #define DAP_DEFAULT_PORT 1U ///< Default JTAG/SWJ Port Mode: 1 = SWD, 2 = JTAG. | |||
| /// Default communication speed on the Debug Access Port for SWD and JTAG mode. | |||
| /// Used to initialize the default SWD/JTAG clock frequency. | |||
| /// The command \ref DAP_SWJ_Clock can be used to overwrite this default setting. | |||
| #define DAP_DEFAULT_SWJ_CLOCK 1000000U ///< Default SWD/JTAG clock frequency in Hz. | |||
| /// Maximum Package Size for Command and Response data. | |||
| /// This configuration settings is used to optimize the communication performance with the | |||
| /// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB, | |||
| /// 1024 for High-speed USB HID and 512 for High-speed USB WinUSB. | |||
| #define DAP_PACKET_SIZE 512U ///< Specifies Packet Size in bytes. | |||
| /// Maximum Package Buffers for Command and Response data. | |||
| /// This configuration settings is used to optimize the communication performance with the | |||
| /// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the | |||
| /// setting can be reduced (valid range is 1 .. 255). | |||
| #define DAP_PACKET_COUNT 8U ///< Specifies number of packets buffered. | |||
| /// Indicate that UART Serial Wire Output (SWO) trace is available. | |||
| /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>. | |||
| #define SWO_UART 1 ///< SWO UART: 1 = available, 0 = not available. | |||
| /// USART Driver instance number for the UART SWO. | |||
| #define SWO_UART_DRIVER 0 ///< USART Driver instance number (Driver_USART#). | |||
| /// Maximum SWO UART Baudrate. | |||
| #define SWO_UART_MAX_BAUDRATE 10000000U ///< SWO UART Maximum Baudrate in Hz. | |||
| /// Indicate that Manchester Serial Wire Output (SWO) trace is available. | |||
| /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>. | |||
| #define SWO_MANCHESTER 0 ///< SWO Manchester: 1 = available, 0 = not available. | |||
| /// SWO Trace Buffer Size. | |||
| #define SWO_BUFFER_SIZE 4096U ///< SWO Trace Buffer Size in bytes (must be 2^n). | |||
| /// SWO Streaming Trace. | |||
| #define SWO_STREAM 0 ///< SWO Streaming Trace: 1 = available, 0 = not available. | |||
| /// Clock frequency of the Test Domain Timer. Timer value is returned with \ref TIMESTAMP_GET. | |||
| #define TIMESTAMP_CLOCK 100000000U ///< Timestamp clock in Hz (0 = timestamps not supported). | |||
| /// Indicate that UART Communication Port is available. | |||
| /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>. | |||
| #define DAP_UART 1 ///< DAP UART: 1 = available, 0 = not available. | |||
| /// USART Driver instance number for the UART Communication Port. | |||
| #define DAP_UART_DRIVER 1 ///< USART Driver instance number (Driver_USART#). | |||
| /// UART Receive Buffer Size. | |||
| #define DAP_UART_RX_BUFFER_SIZE 1024U ///< Uart Receive Buffer Size in bytes (must be 2^n). | |||
| /// UART Transmit Buffer Size. | |||
| #define DAP_UART_TX_BUFFER_SIZE 1024U ///< Uart Transmit Buffer Size in bytes (must be 2^n). | |||
| /// Indicate that UART Communication via USB COM Port is available. | |||
| /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>. | |||
| #define DAP_UART_USB_COM_PORT 1 ///< USB COM Port: 1 = available, 0 = not available. | |||
| /// Debug Unit is connected to fixed Target Device. | |||
| /// The Debug Unit may be part of an evaluation board and always connected to a fixed | |||
| /// known device. In this case a Device Vendor, Device Name, Board Vendor and Board Name strings | |||
| /// are stored and may be used by the debugger or IDE to configure device parameters. | |||
| #define TARGET_FIXED 0 ///< Target: 1 = known, 0 = unknown; | |||
| #define TARGET_DEVICE_VENDOR "Arm" ///< String indicating the Silicon Vendor | |||
| #define TARGET_DEVICE_NAME "Cortex-M" ///< String indicating the Target Device | |||
| #define TARGET_BOARD_VENDOR "Arm" ///< String indicating the Board Vendor | |||
| #define TARGET_BOARD_NAME "Arm board" ///< String indicating the Board Name | |||
| #if TARGET_FIXED != 0 | |||
| #include <string.h> | |||
| static const char TargetDeviceVendor [] = TARGET_DEVICE_VENDOR; | |||
| static const char TargetDeviceName [] = TARGET_DEVICE_NAME; | |||
| static const char TargetBoardVendor [] = TARGET_BOARD_VENDOR; | |||
| static const char TargetBoardName [] = TARGET_BOARD_NAME; | |||
| #endif | |||
| /** Get Vendor Name string. | |||
| \param str Pointer to buffer to store the string (max 60 characters). | |||
| \return String length (including terminating NULL character) or 0 (no string). | |||
| */ | |||
| __STATIC_INLINE uint8_t DAP_GetVendorString (char *str) { | |||
| (void)str; | |||
| return (0U); | |||
| } | |||
| /** Get Product Name string. | |||
| \param str Pointer to buffer to store the string (max 60 characters). | |||
| \return String length (including terminating NULL character) or 0 (no string). | |||
| */ | |||
| __STATIC_INLINE uint8_t DAP_GetProductString (char *str) { | |||
| (void)str; | |||
| return (0U); | |||
| } | |||
| /** Get Serial Number string. | |||
| \param str Pointer to buffer to store the string (max 60 characters). | |||
| \return String length (including terminating NULL character) or 0 (no string). | |||
| */ | |||
| __STATIC_INLINE uint8_t DAP_GetSerNumString (char *str) { | |||
| (void)str; | |||
| return (0U); | |||
| } | |||
| /** Get Target Device Vendor string. | |||
| \param str Pointer to buffer to store the string (max 60 characters). | |||
| \return String length (including terminating NULL character) or 0 (no string). | |||
| */ | |||
| __STATIC_INLINE uint8_t DAP_GetTargetDeviceVendorString (char *str) { | |||
| #if TARGET_FIXED != 0 | |||
| uint8_t len; | |||
| strcpy(str, TargetDeviceVendor); | |||
| len = (uint8_t)(strlen(TargetDeviceVendor) + 1U); | |||
| return (len); | |||
| #else | |||
| (void)str; | |||
| return (0U); | |||
| #endif | |||
| } | |||
| /** Get Target Device Name string. | |||
| \param str Pointer to buffer to store the string (max 60 characters). | |||
| \return String length (including terminating NULL character) or 0 (no string). | |||
| */ | |||
| __STATIC_INLINE uint8_t DAP_GetTargetDeviceNameString (char *str) { | |||
| #if TARGET_FIXED != 0 | |||
| uint8_t len; | |||
| strcpy(str, TargetDeviceName); | |||
| len = (uint8_t)(strlen(TargetDeviceName) + 1U); | |||
| return (len); | |||
| #else | |||
| (void)str; | |||
| return (0U); | |||
| #endif | |||
| } | |||
| /** Get Target Board Vendor string. | |||
| \param str Pointer to buffer to store the string (max 60 characters). | |||
| \return String length (including terminating NULL character) or 0 (no string). | |||
| */ | |||
| __STATIC_INLINE uint8_t DAP_GetTargetBoardVendorString (char *str) { | |||
| #if TARGET_FIXED != 0 | |||
| uint8_t len; | |||
| strcpy(str, TargetBoardVendor); | |||
| len = (uint8_t)(strlen(TargetBoardVendor) + 1U); | |||
| return (len); | |||
| #else | |||
| (void)str; | |||
| return (0U); | |||
| #endif | |||
| } | |||
| /** Get Target Board Name string. | |||
| \param str Pointer to buffer to store the string (max 60 characters). | |||
| \return String length (including terminating NULL character) or 0 (no string). | |||
| */ | |||
| __STATIC_INLINE uint8_t DAP_GetTargetBoardNameString (char *str) { | |||
| #if TARGET_FIXED != 0 | |||
| uint8_t len; | |||
| strcpy(str, TargetBoardName); | |||
| len = (uint8_t)(strlen(TargetBoardName) + 1U); | |||
| return (len); | |||
| #else | |||
| (void)str; | |||
| return (0U); | |||
| #endif | |||
| } | |||
| /** Get Product Firmware Version string. | |||
| \param str Pointer to buffer to store the string (max 60 characters). | |||
| \return String length (including terminating NULL character) or 0 (no string). | |||
| */ | |||
| __STATIC_INLINE uint8_t DAP_GetProductFirmwareVersionString (char *str) { | |||
| (void)str; | |||
| return (0U); | |||
| } | |||
| ///@} | |||
| //************************************************************************************************** | |||
| /** | |||
| \defgroup DAP_Config_PortIO_gr CMSIS-DAP Hardware I/O Pin Access | |||
| \ingroup DAP_ConfigIO_gr | |||
| @{ | |||
| Standard I/O Pins of the CMSIS-DAP Hardware Debug Port support standard JTAG mode | |||
| and Serial Wire Debug (SWD) mode. In SWD mode only 2 pins are required to implement the debug | |||
| interface of a device. The following I/O Pins are provided: | |||
| JTAG I/O Pin | SWD I/O Pin | CMSIS-DAP Hardware pin mode | |||
| ---------------------------- | -------------------- | --------------------------------------------- | |||
| TCK: Test Clock | SWCLK: Clock | Output Push/Pull | |||
| TMS: Test Mode Select | SWDIO: Data I/O | Output Push/Pull; Input (for receiving data) | |||
| TDI: Test Data Input | | Output Push/Pull | |||
| TDO: Test Data Output | | Input | |||
| nTRST: Test Reset (optional) | | Output Open Drain with pull-up resistor | |||
| nRESET: Device Reset | nRESET: Device Reset | Output Open Drain with pull-up resistor | |||
| DAP Hardware I/O Pin Access Functions | |||
| ------------------------------------- | |||
| The various I/O Pins are accessed by functions that implement the Read, Write, Set, or Clear to | |||
| these I/O Pins. | |||
| For the SWDIO I/O Pin there are additional functions that are called in SWD I/O mode only. | |||
| This functions are provided to achieve faster I/O that is possible with some advanced GPIO | |||
| peripherals that can independently write/read a single I/O pin without affecting any other pins | |||
| of the same I/O port. The following SWDIO I/O Pin functions are provided: | |||
| - \ref PIN_SWDIO_OUT_ENABLE to enable the output mode from the DAP hardware. | |||
| - \ref PIN_SWDIO_OUT_DISABLE to enable the input mode to the DAP hardware. | |||
| - \ref PIN_SWDIO_IN to read from the SWDIO I/O pin with utmost possible speed. | |||
| - \ref PIN_SWDIO_OUT to write to the SWDIO I/O pin with utmost possible speed. | |||
| */ | |||
| // Configure DAP I/O pins ------------------------------ | |||
| /** Setup JTAG I/O pins: TCK, TMS, TDI, TDO, nTRST, and nRESET. | |||
| Configures the DAP Hardware I/O pins for JTAG mode: | |||
| - TCK, TMS, TDI, nTRST, nRESET to output mode and set to high level. | |||
| - TDO to input mode. | |||
| */ | |||
| __STATIC_INLINE void PORT_JTAG_SETUP (void) { | |||
| ; | |||
| } | |||
| /** Setup SWD I/O pins: SWCLK, SWDIO, and nRESET. | |||
| Configures the DAP Hardware I/O pins for Serial Wire Debug (SWD) mode: | |||
| - SWCLK, SWDIO, nRESET to output mode and set to default high level. | |||
| - TDI, nTRST to HighZ mode (pins are unused in SWD mode). | |||
| */ | |||
| __STATIC_INLINE void PORT_SWD_SETUP (void) { | |||
| ; | |||
| } | |||
| /** Disable JTAG/SWD I/O Pins. | |||
| Disables the DAP Hardware I/O pins which configures: | |||
| - TCK/SWCLK, TMS/SWDIO, TDI, TDO, nTRST, nRESET to High-Z mode. | |||
| */ | |||
| __STATIC_INLINE void PORT_OFF (void) { | |||
| ; | |||
| } | |||
| // SWCLK/TCK I/O pin ------------------------------------- | |||
| /** SWCLK/TCK I/O pin: Get Input. | |||
| \return Current status of the SWCLK/TCK DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t PIN_SWCLK_TCK_IN (void) { | |||
| return (0U); | |||
| } | |||
| /** SWCLK/TCK I/O pin: Set Output to High. | |||
| Set the SWCLK/TCK DAP hardware I/O pin to high level. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_SWCLK_TCK_SET (void) { | |||
| ; | |||
| } | |||
| /** SWCLK/TCK I/O pin: Set Output to Low. | |||
| Set the SWCLK/TCK DAP hardware I/O pin to low level. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_SWCLK_TCK_CLR (void) { | |||
| ; | |||
| } | |||
| // SWDIO/TMS Pin I/O -------------------------------------- | |||
| /** SWDIO/TMS I/O pin: Get Input. | |||
| \return Current status of the SWDIO/TMS DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t PIN_SWDIO_TMS_IN (void) { | |||
| return (0U); | |||
| } | |||
| /** SWDIO/TMS I/O pin: Set Output to High. | |||
| Set the SWDIO/TMS DAP hardware I/O pin to high level. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_SWDIO_TMS_SET (void) { | |||
| ; | |||
| } | |||
| /** SWDIO/TMS I/O pin: Set Output to Low. | |||
| Set the SWDIO/TMS DAP hardware I/O pin to low level. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_SWDIO_TMS_CLR (void) { | |||
| ; | |||
| } | |||
| /** SWDIO I/O pin: Get Input (used in SWD mode only). | |||
| \return Current status of the SWDIO DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t PIN_SWDIO_IN (void) { | |||
| return (0U); | |||
| } | |||
| /** SWDIO I/O pin: Set Output (used in SWD mode only). | |||
| \param bit Output value for the SWDIO DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_SWDIO_OUT (uint32_t bit) { | |||
| ; | |||
| } | |||
| /** SWDIO I/O pin: Switch to Output mode (used in SWD mode only). | |||
| Configure the SWDIO DAP hardware I/O pin to output mode. This function is | |||
| called prior \ref PIN_SWDIO_OUT function calls. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_SWDIO_OUT_ENABLE (void) { | |||
| ; | |||
| } | |||
| /** SWDIO I/O pin: Switch to Input mode (used in SWD mode only). | |||
| Configure the SWDIO DAP hardware I/O pin to input mode. This function is | |||
| called prior \ref PIN_SWDIO_IN function calls. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_SWDIO_OUT_DISABLE (void) { | |||
| ; | |||
| } | |||
| // TDI Pin I/O --------------------------------------------- | |||
| /** TDI I/O pin: Get Input. | |||
| \return Current status of the TDI DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t PIN_TDI_IN (void) { | |||
| return (0U); | |||
| } | |||
| /** TDI I/O pin: Set Output. | |||
| \param bit Output value for the TDI DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_TDI_OUT (uint32_t bit) { | |||
| ; | |||
| } | |||
| // TDO Pin I/O --------------------------------------------- | |||
| /** TDO I/O pin: Get Input. | |||
| \return Current status of the TDO DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t PIN_TDO_IN (void) { | |||
| return (0U); | |||
| } | |||
| // nTRST Pin I/O ------------------------------------------- | |||
| /** nTRST I/O pin: Get Input. | |||
| \return Current status of the nTRST DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t PIN_nTRST_IN (void) { | |||
| return (0U); | |||
| } | |||
| /** nTRST I/O pin: Set Output. | |||
| \param bit JTAG TRST Test Reset pin status: | |||
| - 0: issue a JTAG TRST Test Reset. | |||
| - 1: release JTAG TRST Test Reset. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_nTRST_OUT (uint32_t bit) { | |||
| ; | |||
| } | |||
| // nRESET Pin I/O------------------------------------------ | |||
| /** nRESET I/O pin: Get Input. | |||
| \return Current status of the nRESET DAP hardware I/O pin. | |||
| */ | |||
| __STATIC_FORCEINLINE uint32_t PIN_nRESET_IN (void) { | |||
| return (0U); | |||
| } | |||
| /** nRESET I/O pin: Set Output. | |||
| \param bit target device hardware reset pin status: | |||
| - 0: issue a device hardware reset. | |||
| - 1: release device hardware reset. | |||
| */ | |||
| __STATIC_FORCEINLINE void PIN_nRESET_OUT (uint32_t bit) { | |||
| ; | |||
| } | |||
| ///@} | |||
| //************************************************************************************************** | |||
| /** | |||
| \defgroup DAP_Config_LEDs_gr CMSIS-DAP Hardware Status LEDs | |||
| \ingroup DAP_ConfigIO_gr | |||
| @{ | |||
| CMSIS-DAP Hardware may provide LEDs that indicate the status of the CMSIS-DAP Debug Unit. | |||
| It is recommended to provide the following LEDs for status indication: | |||
| - Connect LED: is active when the DAP hardware is connected to a debugger. | |||
| - Running LED: is active when the debugger has put the target device into running state. | |||
| */ | |||
| /** Debug Unit: Set status of Connected LED. | |||
| \param bit status of the Connect LED. | |||
| - 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit. | |||
| - 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit. | |||
| */ | |||
| __STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {} | |||
| /** Debug Unit: Set status Target Running LED. | |||
| \param bit status of the Target Running LED. | |||
| - 1: Target Running LED ON: program execution in target started. | |||
| - 0: Target Running LED OFF: program execution in target stopped. | |||
| */ | |||
| __STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {} | |||
| ///@} | |||
| //************************************************************************************************** | |||
| /** | |||
| \defgroup DAP_Config_Timestamp_gr CMSIS-DAP Timestamp | |||
| \ingroup DAP_ConfigIO_gr | |||
| @{ | |||
| Access function for Test Domain Timer. | |||
| The value of the Test Domain Timer in the Debug Unit is returned by the function \ref TIMESTAMP_GET. By | |||
| default, the DWT timer is used. The frequency of this timer is configured with \ref TIMESTAMP_CLOCK. | |||
| */ | |||
| /** Get timestamp of Test Domain Timer. | |||
| \return Current timestamp value. | |||
| */ | |||
| __STATIC_INLINE uint32_t TIMESTAMP_GET (void) { | |||
| return (DWT->CYCCNT); | |||
| } | |||
| ///@} | |||
| //************************************************************************************************** | |||
| /** | |||
| \defgroup DAP_Config_Initialization_gr CMSIS-DAP Initialization | |||
| \ingroup DAP_ConfigIO_gr | |||
| @{ | |||
| CMSIS-DAP Hardware I/O and LED Pins are initialized with the function \ref DAP_SETUP. | |||
| */ | |||
| /** Setup of the Debug Unit I/O pins and LEDs (called when Debug Unit is initialized). | |||
| This function performs the initialization of the CMSIS-DAP Hardware I/O Pins and the | |||
| Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled and set: | |||
| - I/O clock system enabled. | |||
| - all I/O pins: input buffer enabled, output pins are set to HighZ mode. | |||
| - for nTRST, nRESET a weak pull-up (if available) is enabled. | |||
| - LED output pins are enabled and LEDs are turned off. | |||
| */ | |||
| __STATIC_INLINE void DAP_SETUP (void) { | |||
| ; | |||
| } | |||
| /** Reset Target Device with custom specific I/O pin or command sequence. | |||
| This function allows the optional implementation of a device specific reset sequence. | |||
| It is called when the command \ref DAP_ResetTarget and is for example required | |||
| when a device needs a time-critical unlock sequence that enables the debug port. | |||
| \return 0 = no device specific reset sequence is implemented.\n | |||
| 1 = a device specific reset sequence is implemented. | |||
| */ | |||
| __STATIC_INLINE uint8_t RESET_TARGET (void) { | |||
| return (0U); // change to '1' when a device reset sequence is implemented | |||
| } | |||
| ///@} | |||
| #endif /* __DAP_CONFIG_H__ */ | |||
| @@ -0,0 +1,367 @@ | |||
| /* | |||
| * Copyright (c) 2013-2022 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| * ---------------------------------------------------------------------- | |||
| * | |||
| * $Date: 26. April 2022 | |||
| * $Revision: V2.1.1 | |||
| * | |||
| * Project: CMSIS-DAP Include | |||
| * Title: DAP.h Definitions | |||
| * | |||
| *---------------------------------------------------------------------------*/ | |||
| #ifndef __DAP_H__ | |||
| #define __DAP_H__ | |||
| // DAP Firmware Version | |||
| #ifdef DAP_FW_V1 | |||
| #define DAP_FW_VER "1.3.0" | |||
| #else | |||
| #define DAP_FW_VER "2.1.1" | |||
| #endif | |||
| // DAP Command IDs | |||
| #define ID_DAP_Info 0x00U | |||
| #define ID_DAP_HostStatus 0x01U | |||
| #define ID_DAP_Connect 0x02U | |||
| #define ID_DAP_Disconnect 0x03U | |||
| #define ID_DAP_TransferConfigure 0x04U | |||
| #define ID_DAP_Transfer 0x05U | |||
| #define ID_DAP_TransferBlock 0x06U | |||
| #define ID_DAP_TransferAbort 0x07U | |||
| #define ID_DAP_WriteABORT 0x08U | |||
| #define ID_DAP_Delay 0x09U | |||
| #define ID_DAP_ResetTarget 0x0AU | |||
| #define ID_DAP_SWJ_Pins 0x10U | |||
| #define ID_DAP_SWJ_Clock 0x11U | |||
| #define ID_DAP_SWJ_Sequence 0x12U | |||
| #define ID_DAP_SWD_Configure 0x13U | |||
| #define ID_DAP_SWD_Sequence 0x1DU | |||
| #define ID_DAP_JTAG_Sequence 0x14U | |||
| #define ID_DAP_JTAG_Configure 0x15U | |||
| #define ID_DAP_JTAG_IDCODE 0x16U | |||
| #define ID_DAP_SWO_Transport 0x17U | |||
| #define ID_DAP_SWO_Mode 0x18U | |||
| #define ID_DAP_SWO_Baudrate 0x19U | |||
| #define ID_DAP_SWO_Control 0x1AU | |||
| #define ID_DAP_SWO_Status 0x1BU | |||
| #define ID_DAP_SWO_ExtendedStatus 0x1EU | |||
| #define ID_DAP_SWO_Data 0x1CU | |||
| #define ID_DAP_UART_Transport 0x1FU | |||
| #define ID_DAP_UART_Configure 0x20U | |||
| #define ID_DAP_UART_Control 0x22U | |||
| #define ID_DAP_UART_Status 0x23U | |||
| #define ID_DAP_UART_Transfer 0x21U | |||
| #define ID_DAP_QueueCommands 0x7EU | |||
| #define ID_DAP_ExecuteCommands 0x7FU | |||
| // DAP Vendor Command IDs | |||
| #define ID_DAP_Vendor0 0x80U | |||
| #define ID_DAP_Vendor1 0x81U | |||
| #define ID_DAP_Vendor2 0x82U | |||
| #define ID_DAP_Vendor3 0x83U | |||
| #define ID_DAP_Vendor4 0x84U | |||
| #define ID_DAP_Vendor5 0x85U | |||
| #define ID_DAP_Vendor6 0x86U | |||
| #define ID_DAP_Vendor7 0x87U | |||
| #define ID_DAP_Vendor8 0x88U | |||
| #define ID_DAP_Vendor9 0x89U | |||
| #define ID_DAP_Vendor10 0x8AU | |||
| #define ID_DAP_Vendor11 0x8BU | |||
| #define ID_DAP_Vendor12 0x8CU | |||
| #define ID_DAP_Vendor13 0x8DU | |||
| #define ID_DAP_Vendor14 0x8EU | |||
| #define ID_DAP_Vendor15 0x8FU | |||
| #define ID_DAP_Vendor16 0x90U | |||
| #define ID_DAP_Vendor17 0x91U | |||
| #define ID_DAP_Vendor18 0x92U | |||
| #define ID_DAP_Vendor19 0x93U | |||
| #define ID_DAP_Vendor20 0x94U | |||
| #define ID_DAP_Vendor21 0x95U | |||
| #define ID_DAP_Vendor22 0x96U | |||
| #define ID_DAP_Vendor23 0x97U | |||
| #define ID_DAP_Vendor24 0x98U | |||
| #define ID_DAP_Vendor25 0x99U | |||
| #define ID_DAP_Vendor26 0x9AU | |||
| #define ID_DAP_Vendor27 0x9BU | |||
| #define ID_DAP_Vendor28 0x9CU | |||
| #define ID_DAP_Vendor29 0x9DU | |||
| #define ID_DAP_Vendor30 0x9EU | |||
| #define ID_DAP_Vendor31 0x9FU | |||
| #define ID_DAP_Invalid 0xFFU | |||
| // DAP Status Code | |||
| #define DAP_OK 0U | |||
| #define DAP_ERROR 0xFFU | |||
| // DAP ID | |||
| #define DAP_ID_VENDOR 1U | |||
| #define DAP_ID_PRODUCT 2U | |||
| #define DAP_ID_SER_NUM 3U | |||
| #define DAP_ID_DAP_FW_VER 4U | |||
| #define DAP_ID_DEVICE_VENDOR 5U | |||
| #define DAP_ID_DEVICE_NAME 6U | |||
| #define DAP_ID_BOARD_VENDOR 7U | |||
| #define DAP_ID_BOARD_NAME 8U | |||
| #define DAP_ID_PRODUCT_FW_VER 9U | |||
| #define DAP_ID_CAPABILITIES 0xF0U | |||
| #define DAP_ID_TIMESTAMP_CLOCK 0xF1U | |||
| #define DAP_ID_UART_RX_BUFFER_SIZE 0xFBU | |||
| #define DAP_ID_UART_TX_BUFFER_SIZE 0xFCU | |||
| #define DAP_ID_SWO_BUFFER_SIZE 0xFDU | |||
| #define DAP_ID_PACKET_COUNT 0xFEU | |||
| #define DAP_ID_PACKET_SIZE 0xFFU | |||
| // DAP Host Status | |||
| #define DAP_DEBUGGER_CONNECTED 0U | |||
| #define DAP_TARGET_RUNNING 1U | |||
| // DAP Port | |||
| #define DAP_PORT_AUTODETECT 0U // Autodetect Port | |||
| #define DAP_PORT_DISABLED 0U // Port Disabled (I/O pins in High-Z) | |||
| #define DAP_PORT_SWD 1U // SWD Port (SWCLK, SWDIO) + nRESET | |||
| #define DAP_PORT_JTAG 2U // JTAG Port (TCK, TMS, TDI, TDO, nTRST) + nRESET | |||
| // DAP SWJ Pins | |||
| #define DAP_SWJ_SWCLK_TCK 0 // SWCLK/TCK | |||
| #define DAP_SWJ_SWDIO_TMS 1 // SWDIO/TMS | |||
| #define DAP_SWJ_TDI 2 // TDI | |||
| #define DAP_SWJ_TDO 3 // TDO | |||
| #define DAP_SWJ_nTRST 5 // nTRST | |||
| #define DAP_SWJ_nRESET 7 // nRESET | |||
| // DAP Transfer Request | |||
| #define DAP_TRANSFER_APnDP (1U<<0) | |||
| #define DAP_TRANSFER_RnW (1U<<1) | |||
| #define DAP_TRANSFER_A2 (1U<<2) | |||
| #define DAP_TRANSFER_A3 (1U<<3) | |||
| #define DAP_TRANSFER_MATCH_VALUE (1U<<4) | |||
| #define DAP_TRANSFER_MATCH_MASK (1U<<5) | |||
| #define DAP_TRANSFER_TIMESTAMP (1U<<7) | |||
| // DAP Transfer Response | |||
| #define DAP_TRANSFER_OK (1U<<0) | |||
| #define DAP_TRANSFER_WAIT (1U<<1) | |||
| #define DAP_TRANSFER_FAULT (1U<<2) | |||
| #define DAP_TRANSFER_ERROR (1U<<3) | |||
| #define DAP_TRANSFER_MISMATCH (1U<<4) | |||
| // DAP SWO Trace Mode | |||
| #define DAP_SWO_OFF 0U | |||
| #define DAP_SWO_UART 1U | |||
| #define DAP_SWO_MANCHESTER 2U | |||
| // DAP SWO Trace Status | |||
| #define DAP_SWO_CAPTURE_ACTIVE (1U<<0) | |||
| #define DAP_SWO_CAPTURE_PAUSED (1U<<1) | |||
| #define DAP_SWO_STREAM_ERROR (1U<<6) | |||
| #define DAP_SWO_BUFFER_OVERRUN (1U<<7) | |||
| // DAP UART Transport | |||
| #define DAP_UART_TRANSPORT_NONE 0U | |||
| #define DAP_UART_TRANSPORT_USB_COM_PORT 1U | |||
| #define DAP_UART_TRANSPORT_DAP_COMMAND 2U | |||
| // DAP UART Control | |||
| #define DAP_UART_CONTROL_RX_ENABLE (1U<<0) | |||
| #define DAP_UART_CONTROL_RX_DISABLE (1U<<1) | |||
| #define DAP_UART_CONTROL_RX_BUF_FLUSH (1U<<2) | |||
| #define DAP_UART_CONTROL_TX_ENABLE (1U<<4) | |||
| #define DAP_UART_CONTROL_TX_DISABLE (1U<<5) | |||
| #define DAP_UART_CONTROL_TX_BUF_FLUSH (1U<<6) | |||
| // DAP UART Status | |||
| #define DAP_UART_STATUS_RX_ENABLED (1U<<0) | |||
| #define DAP_UART_STATUS_RX_DATA_LOST (1U<<1) | |||
| #define DAP_UART_STATUS_FRAMING_ERROR (1U<<2) | |||
| #define DAP_UART_STATUS_PARITY_ERROR (1U<<3) | |||
| #define DAP_UART_STATUS_TX_ENABLED (1U<<4) | |||
| // DAP UART Configure Error | |||
| #define DAP_UART_CFG_ERROR_DATA_BITS (1U<<0) | |||
| #define DAP_UART_CFG_ERROR_PARITY (1U<<1) | |||
| #define DAP_UART_CFG_ERROR_STOP_BITS (1U<<2) | |||
| // Debug Port Register Addresses | |||
| #define DP_IDCODE 0x00U // IDCODE Register (SW Read only) | |||
| #define DP_ABORT 0x00U // Abort Register (SW Write only) | |||
| #define DP_CTRL_STAT 0x04U // Control & Status | |||
| #define DP_WCR 0x04U // Wire Control Register (SW Only) | |||
| #define DP_SELECT 0x08U // Select Register (JTAG R/W & SW W) | |||
| #define DP_RESEND 0x08U // Resend (SW Read Only) | |||
| #define DP_RDBUFF 0x0CU // Read Buffer (Read Only) | |||
| // JTAG IR Codes | |||
| #define JTAG_ABORT 0x08U | |||
| #define JTAG_DPACC 0x0AU | |||
| #define JTAG_APACC 0x0BU | |||
| #define JTAG_IDCODE 0x0EU | |||
| #define JTAG_BYPASS 0x0FU | |||
| // JTAG Sequence Info | |||
| #define JTAG_SEQUENCE_TCK 0x3FU // TCK count | |||
| #define JTAG_SEQUENCE_TMS 0x40U // TMS value | |||
| #define JTAG_SEQUENCE_TDO 0x80U // TDO capture | |||
| // SWD Sequence Info | |||
| #define SWD_SEQUENCE_CLK 0x3FU // SWCLK count | |||
| #define SWD_SEQUENCE_DIN 0x80U // SWDIO capture | |||
| #include <stddef.h> | |||
| #include <stdint.h> | |||
| #include "cmsis_compiler.h" | |||
| // DAP Data structure | |||
| typedef struct { | |||
| uint8_t debug_port; // Debug Port | |||
| uint8_t fast_clock; // Fast Clock Flag | |||
| uint8_t padding[2]; | |||
| uint32_t clock_delay; // Clock Delay | |||
| uint32_t timestamp; // Last captured Timestamp | |||
| struct { // Transfer Configuration | |||
| uint8_t idle_cycles; // Idle cycles after transfer | |||
| uint8_t padding[3]; | |||
| uint16_t retry_count; // Number of retries after WAIT response | |||
| uint16_t match_retry; // Number of retries if read value does not match | |||
| uint32_t match_mask; // Match Mask | |||
| } transfer; | |||
| #if (DAP_SWD != 0) | |||
| struct { // SWD Configuration | |||
| uint8_t turnaround; // Turnaround period | |||
| uint8_t data_phase; // Always generate Data Phase | |||
| } swd_conf; | |||
| #endif | |||
| #if (DAP_JTAG != 0) | |||
| struct { // JTAG Device Chain | |||
| uint8_t count; // Number of devices | |||
| uint8_t index; // Device index (device at TDO has index 0) | |||
| #if (DAP_JTAG_DEV_CNT != 0) | |||
| uint8_t ir_length[DAP_JTAG_DEV_CNT]; // IR Length in bits | |||
| uint16_t ir_before[DAP_JTAG_DEV_CNT]; // Bits before IR | |||
| uint16_t ir_after [DAP_JTAG_DEV_CNT]; // Bits after IR | |||
| #endif | |||
| } jtag_dev; | |||
| #endif | |||
| } DAP_Data_t; | |||
| extern DAP_Data_t DAP_Data; // DAP Data | |||
| extern volatile uint8_t DAP_TransferAbort; // Transfer Abort Flag | |||
| #ifdef __cplusplus | |||
| extern "C" | |||
| { | |||
| #endif | |||
| // Functions | |||
| extern void SWJ_Sequence (uint32_t count, const uint8_t *data); | |||
| extern void SWD_Sequence (uint32_t info, const uint8_t *swdo, uint8_t *swdi); | |||
| extern void JTAG_Sequence (uint32_t info, const uint8_t *tdi, uint8_t *tdo); | |||
| extern void JTAG_IR (uint32_t ir); | |||
| extern uint32_t JTAG_ReadIDCode (void); | |||
| extern void JTAG_WriteAbort (uint32_t data); | |||
| extern uint8_t JTAG_Transfer (uint32_t request, uint32_t *data); | |||
| extern uint8_t SWD_Transfer (uint32_t request, uint32_t *data); | |||
| extern void Delayms (uint32_t delay); | |||
| extern uint32_t SWO_Transport (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t SWO_Mode (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t SWO_Baudrate (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t SWO_Control (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t SWO_Status (uint8_t *response); | |||
| extern uint32_t SWO_ExtendedStatus (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t SWO_Data (const uint8_t *request, uint8_t *response); | |||
| extern void SWO_QueueTransfer (uint8_t *buf, uint32_t num); | |||
| extern void SWO_AbortTransfer (void); | |||
| extern void SWO_TransferComplete (void); | |||
| extern uint32_t SWO_Mode_UART (uint32_t enable); | |||
| extern uint32_t SWO_Baudrate_UART (uint32_t baudrate); | |||
| extern uint32_t SWO_Control_UART (uint32_t active); | |||
| extern void SWO_Capture_UART (uint8_t *buf, uint32_t num); | |||
| extern uint32_t SWO_GetCount_UART (void); | |||
| extern uint32_t SWO_Mode_Manchester (uint32_t enable); | |||
| extern uint32_t SWO_Baudrate_Manchester (uint32_t baudrate); | |||
| extern uint32_t SWO_Control_Manchester (uint32_t active); | |||
| extern void SWO_Capture_Manchester (uint8_t *buf, uint32_t num); | |||
| extern uint32_t SWO_GetCount_Manchester (void); | |||
| extern uint32_t UART_Transport (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t UART_Configure (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t UART_Control (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t UART_Status (uint8_t *response); | |||
| extern uint32_t UART_Transfer (const uint8_t *request, uint8_t *response); | |||
| extern uint8_t USB_COM_PORT_Activate (uint32_t cmd); | |||
| extern uint32_t DAP_ProcessVendorCommand (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t DAP_ProcessCommand (const uint8_t *request, uint8_t *response); | |||
| extern uint32_t DAP_ExecuteCommand (const uint8_t *request, uint8_t *response); | |||
| extern void DAP_Setup (void); | |||
| // Configurable delay for clock generation | |||
| #ifndef DELAY_SLOW_CYCLES | |||
| #define DELAY_SLOW_CYCLES 3U // Number of cycles for one iteration | |||
| #endif | |||
| #if defined(__CC_ARM) | |||
| __STATIC_FORCEINLINE void PIN_DELAY_SLOW (uint32_t delay) { | |||
| uint32_t count = delay; | |||
| while (--count); | |||
| } | |||
| #else | |||
| __STATIC_FORCEINLINE void PIN_DELAY_SLOW (uint32_t delay) { | |||
| __ASM volatile ( | |||
| ".syntax unified\n" | |||
| "0:\n\t" | |||
| "subs %0,%0,#1\n\t" | |||
| "bne 0b\n" | |||
| : "+l" (delay) : : "cc" | |||
| ); | |||
| } | |||
| #endif | |||
| // Fixed delay for fast clock generation | |||
| #ifndef DELAY_FAST_CYCLES | |||
| #define DELAY_FAST_CYCLES 0U // Number of cycles: 0..3 | |||
| #endif | |||
| __STATIC_FORCEINLINE void PIN_DELAY_FAST (void) { | |||
| #if (DELAY_FAST_CYCLES >= 1U) | |||
| __NOP(); | |||
| #endif | |||
| #if (DELAY_FAST_CYCLES >= 2U) | |||
| __NOP(); | |||
| #endif | |||
| #if (DELAY_FAST_CYCLES >= 3U) | |||
| __NOP(); | |||
| #endif | |||
| } | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __DAP_H__ */ | |||
| @@ -0,0 +1,100 @@ | |||
| /* | |||
| * Copyright (c) 2013-2017 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| * ---------------------------------------------------------------------- | |||
| * | |||
| * $Date: 1. December 2017 | |||
| * $Revision: V2.0.0 | |||
| * | |||
| * Project: CMSIS-DAP Source | |||
| * Title: DAP_vendor.c CMSIS-DAP Vendor Commands | |||
| * | |||
| *---------------------------------------------------------------------------*/ | |||
| #include "DAP_config.h" | |||
| #include "DAP.h" | |||
| //************************************************************************************************** | |||
| /** | |||
| \defgroup DAP_Vendor_Adapt_gr Adapt Vendor Commands | |||
| \ingroup DAP_Vendor_gr | |||
| @{ | |||
| The file DAP_vendor.c provides template source code for extension of a Debug Unit with | |||
| Vendor Commands. Copy this file to the project folder of the Debug Unit and add the | |||
| file to the MDK-ARM project under the file group Configuration. | |||
| */ | |||
| /** Process DAP Vendor Command and prepare Response Data | |||
| \param request pointer to request data | |||
| \param response pointer to response data | |||
| \return number of bytes in response (lower 16 bits) | |||
| number of bytes in request (upper 16 bits) | |||
| */ | |||
| uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { | |||
| uint32_t num = (1U << 16) | 1U; | |||
| *response++ = *request; // copy Command ID | |||
| switch (*request++) { // first byte in request is Command ID | |||
| case ID_DAP_Vendor0: | |||
| #if 0 // example user command | |||
| num += 1U << 16; // increment request count | |||
| if (*request == 1U) { // when first command data byte is 1 | |||
| *response++ = 'X'; // send 'X' as response | |||
| num++; // increment response count | |||
| } | |||
| #endif | |||
| break; | |||
| case ID_DAP_Vendor1: break; | |||
| case ID_DAP_Vendor2: break; | |||
| case ID_DAP_Vendor3: break; | |||
| case ID_DAP_Vendor4: break; | |||
| case ID_DAP_Vendor5: break; | |||
| case ID_DAP_Vendor6: break; | |||
| case ID_DAP_Vendor7: break; | |||
| case ID_DAP_Vendor8: break; | |||
| case ID_DAP_Vendor9: break; | |||
| case ID_DAP_Vendor10: break; | |||
| case ID_DAP_Vendor11: break; | |||
| case ID_DAP_Vendor12: break; | |||
| case ID_DAP_Vendor13: break; | |||
| case ID_DAP_Vendor14: break; | |||
| case ID_DAP_Vendor15: break; | |||
| case ID_DAP_Vendor16: break; | |||
| case ID_DAP_Vendor17: break; | |||
| case ID_DAP_Vendor18: break; | |||
| case ID_DAP_Vendor19: break; | |||
| case ID_DAP_Vendor20: break; | |||
| case ID_DAP_Vendor21: break; | |||
| case ID_DAP_Vendor22: break; | |||
| case ID_DAP_Vendor23: break; | |||
| case ID_DAP_Vendor24: break; | |||
| case ID_DAP_Vendor25: break; | |||
| case ID_DAP_Vendor26: break; | |||
| case ID_DAP_Vendor27: break; | |||
| case ID_DAP_Vendor28: break; | |||
| case ID_DAP_Vendor29: break; | |||
| case ID_DAP_Vendor30: break; | |||
| case ID_DAP_Vendor31: break; | |||
| } | |||
| return (num); | |||
| } | |||
| ///@} | |||
| @@ -0,0 +1,370 @@ | |||
| /* | |||
| * Copyright (c) 2013-2017 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| * ---------------------------------------------------------------------- | |||
| * | |||
| * $Date: 1. December 2017 | |||
| * $Revision: V2.0.0 | |||
| * | |||
| * Project: CMSIS-DAP Source | |||
| * Title: JTAG_DP.c CMSIS-DAP JTAG DP I/O | |||
| * | |||
| *---------------------------------------------------------------------------*/ | |||
| #include "DAP_config.h" | |||
| #include "DAP.h" | |||
| // JTAG Macros | |||
| #define PIN_TCK_SET PIN_SWCLK_TCK_SET | |||
| #define PIN_TCK_CLR PIN_SWCLK_TCK_CLR | |||
| #define PIN_TMS_SET PIN_SWDIO_TMS_SET | |||
| #define PIN_TMS_CLR PIN_SWDIO_TMS_CLR | |||
| #define JTAG_CYCLE_TCK() \ | |||
| PIN_TCK_CLR(); \ | |||
| PIN_DELAY(); \ | |||
| PIN_TCK_SET(); \ | |||
| PIN_DELAY() | |||
| #define JTAG_CYCLE_TDI(tdi) \ | |||
| PIN_TDI_OUT(tdi); \ | |||
| PIN_TCK_CLR(); \ | |||
| PIN_DELAY(); \ | |||
| PIN_TCK_SET(); \ | |||
| PIN_DELAY() | |||
| #define JTAG_CYCLE_TDO(tdo) \ | |||
| PIN_TCK_CLR(); \ | |||
| PIN_DELAY(); \ | |||
| tdo = PIN_TDO_IN(); \ | |||
| PIN_TCK_SET(); \ | |||
| PIN_DELAY() | |||
| #define JTAG_CYCLE_TDIO(tdi,tdo) \ | |||
| PIN_TDI_OUT(tdi); \ | |||
| PIN_TCK_CLR(); \ | |||
| PIN_DELAY(); \ | |||
| tdo = PIN_TDO_IN(); \ | |||
| PIN_TCK_SET(); \ | |||
| PIN_DELAY() | |||
| #define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) | |||
| #if (DAP_JTAG != 0) | |||
| // Generate JTAG Sequence | |||
| // info: sequence information | |||
| // tdi: pointer to TDI generated data | |||
| // tdo: pointer to TDO captured data | |||
| // return: none | |||
| void JTAG_Sequence (uint32_t info, const uint8_t *tdi, uint8_t *tdo) { | |||
| uint32_t i_val; | |||
| uint32_t o_val; | |||
| uint32_t bit; | |||
| uint32_t n, k; | |||
| n = info & JTAG_SEQUENCE_TCK; | |||
| if (n == 0U) { | |||
| n = 64U; | |||
| } | |||
| if (info & JTAG_SEQUENCE_TMS) { | |||
| PIN_TMS_SET(); | |||
| } else { | |||
| PIN_TMS_CLR(); | |||
| } | |||
| while (n) { | |||
| i_val = *tdi++; | |||
| o_val = 0U; | |||
| for (k = 8U; k && n; k--, n--) { | |||
| JTAG_CYCLE_TDIO(i_val, bit); | |||
| i_val >>= 1; | |||
| o_val >>= 1; | |||
| o_val |= bit << 7; | |||
| } | |||
| o_val >>= k; | |||
| if (info & JTAG_SEQUENCE_TDO) { | |||
| *tdo++ = (uint8_t)o_val; | |||
| } | |||
| } | |||
| } | |||
| // JTAG Set IR | |||
| // ir: IR value | |||
| // return: none | |||
| #define JTAG_IR_Function(speed) /**/ \ | |||
| static void JTAG_IR_##speed (uint32_t ir) { \ | |||
| uint32_t n; \ | |||
| \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TCK(); /* Select-DR-Scan */ \ | |||
| JTAG_CYCLE_TCK(); /* Select-IR-Scan */ \ | |||
| PIN_TMS_CLR(); \ | |||
| JTAG_CYCLE_TCK(); /* Capture-IR */ \ | |||
| JTAG_CYCLE_TCK(); /* Shift-IR */ \ | |||
| \ | |||
| PIN_TDI_OUT(1U); \ | |||
| for (n = DAP_Data.jtag_dev.ir_before[DAP_Data.jtag_dev.index]; n; n--) { \ | |||
| JTAG_CYCLE_TCK(); /* Bypass before data */ \ | |||
| } \ | |||
| for (n = DAP_Data.jtag_dev.ir_length[DAP_Data.jtag_dev.index] - 1U; n; n--) { \ | |||
| JTAG_CYCLE_TDI(ir); /* Set IR bits (except last) */ \ | |||
| ir >>= 1; \ | |||
| } \ | |||
| n = DAP_Data.jtag_dev.ir_after[DAP_Data.jtag_dev.index]; \ | |||
| if (n) { \ | |||
| JTAG_CYCLE_TDI(ir); /* Set last IR bit */ \ | |||
| PIN_TDI_OUT(1U); \ | |||
| for (--n; n; n--) { \ | |||
| JTAG_CYCLE_TCK(); /* Bypass after data */ \ | |||
| } \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TCK(); /* Bypass & Exit1-IR */ \ | |||
| } else { \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TDI(ir); /* Set last IR bit & Exit1-IR */ \ | |||
| } \ | |||
| \ | |||
| JTAG_CYCLE_TCK(); /* Update-IR */ \ | |||
| PIN_TMS_CLR(); \ | |||
| JTAG_CYCLE_TCK(); /* Idle */ \ | |||
| PIN_TDI_OUT(1U); \ | |||
| } | |||
| // JTAG Transfer I/O | |||
| // request: A[3:2] RnW APnDP | |||
| // data: DATA[31:0] | |||
| // return: ACK[2:0] | |||
| #define JTAG_TransferFunction(speed) /**/ \ | |||
| static uint8_t JTAG_Transfer##speed (uint32_t request, uint32_t *data) { \ | |||
| uint32_t ack; \ | |||
| uint32_t bit; \ | |||
| uint32_t val; \ | |||
| uint32_t n; \ | |||
| \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TCK(); /* Select-DR-Scan */ \ | |||
| PIN_TMS_CLR(); \ | |||
| JTAG_CYCLE_TCK(); /* Capture-DR */ \ | |||
| JTAG_CYCLE_TCK(); /* Shift-DR */ \ | |||
| \ | |||
| for (n = DAP_Data.jtag_dev.index; n; n--) { \ | |||
| JTAG_CYCLE_TCK(); /* Bypass before data */ \ | |||
| } \ | |||
| \ | |||
| JTAG_CYCLE_TDIO(request >> 1, bit); /* Set RnW, Get ACK.0 */ \ | |||
| ack = bit << 1; \ | |||
| JTAG_CYCLE_TDIO(request >> 2, bit); /* Set A2, Get ACK.1 */ \ | |||
| ack |= bit << 0; \ | |||
| JTAG_CYCLE_TDIO(request >> 3, bit); /* Set A3, Get ACK.2 */ \ | |||
| ack |= bit << 2; \ | |||
| \ | |||
| if (ack != DAP_TRANSFER_OK) { \ | |||
| /* Exit on error */ \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TCK(); /* Exit1-DR */ \ | |||
| goto exit; \ | |||
| } \ | |||
| \ | |||
| if (request & DAP_TRANSFER_RnW) { \ | |||
| /* Read Transfer */ \ | |||
| val = 0U; \ | |||
| for (n = 31U; n; n--) { \ | |||
| JTAG_CYCLE_TDO(bit); /* Get D0..D30 */ \ | |||
| val |= bit << 31; \ | |||
| val >>= 1; \ | |||
| } \ | |||
| n = DAP_Data.jtag_dev.count - DAP_Data.jtag_dev.index - 1U; \ | |||
| if (n) { \ | |||
| JTAG_CYCLE_TDO(bit); /* Get D31 */ \ | |||
| for (--n; n; n--) { \ | |||
| JTAG_CYCLE_TCK(); /* Bypass after data */ \ | |||
| } \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TCK(); /* Bypass & Exit1-DR */ \ | |||
| } else { \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TDO(bit); /* Get D31 & Exit1-DR */ \ | |||
| } \ | |||
| val |= bit << 31; \ | |||
| if (data) { *data = val; } \ | |||
| } else { \ | |||
| /* Write Transfer */ \ | |||
| val = *data; \ | |||
| for (n = 31U; n; n--) { \ | |||
| JTAG_CYCLE_TDI(val); /* Set D0..D30 */ \ | |||
| val >>= 1; \ | |||
| } \ | |||
| n = DAP_Data.jtag_dev.count - DAP_Data.jtag_dev.index - 1U; \ | |||
| if (n) { \ | |||
| JTAG_CYCLE_TDI(val); /* Set D31 */ \ | |||
| for (--n; n; n--) { \ | |||
| JTAG_CYCLE_TCK(); /* Bypass after data */ \ | |||
| } \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TCK(); /* Bypass & Exit1-DR */ \ | |||
| } else { \ | |||
| PIN_TMS_SET(); \ | |||
| JTAG_CYCLE_TDI(val); /* Set D31 & Exit1-DR */ \ | |||
| } \ | |||
| } \ | |||
| \ | |||
| exit: \ | |||
| JTAG_CYCLE_TCK(); /* Update-DR */ \ | |||
| PIN_TMS_CLR(); \ | |||
| JTAG_CYCLE_TCK(); /* Idle */ \ | |||
| PIN_TDI_OUT(1U); \ | |||
| \ | |||
| /* Capture Timestamp */ \ | |||
| if (request & DAP_TRANSFER_TIMESTAMP) { \ | |||
| DAP_Data.timestamp = TIMESTAMP_GET(); \ | |||
| } \ | |||
| \ | |||
| /* Idle cycles */ \ | |||
| n = DAP_Data.transfer.idle_cycles; \ | |||
| while (n--) { \ | |||
| JTAG_CYCLE_TCK(); /* Idle */ \ | |||
| } \ | |||
| \ | |||
| return ((uint8_t)ack); \ | |||
| } | |||
| #undef PIN_DELAY | |||
| #define PIN_DELAY() PIN_DELAY_FAST() | |||
| JTAG_IR_Function(Fast) | |||
| JTAG_TransferFunction(Fast) | |||
| #undef PIN_DELAY | |||
| #define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) | |||
| JTAG_IR_Function(Slow) | |||
| JTAG_TransferFunction(Slow) | |||
| // JTAG Read IDCODE register | |||
| // return: value read | |||
| uint32_t JTAG_ReadIDCode (void) { | |||
| uint32_t bit; | |||
| uint32_t val; | |||
| uint32_t n; | |||
| PIN_TMS_SET(); | |||
| JTAG_CYCLE_TCK(); /* Select-DR-Scan */ | |||
| PIN_TMS_CLR(); | |||
| JTAG_CYCLE_TCK(); /* Capture-DR */ | |||
| JTAG_CYCLE_TCK(); /* Shift-DR */ | |||
| for (n = DAP_Data.jtag_dev.index; n; n--) { | |||
| JTAG_CYCLE_TCK(); /* Bypass before data */ | |||
| } | |||
| val = 0U; | |||
| for (n = 31U; n; n--) { | |||
| JTAG_CYCLE_TDO(bit); /* Get D0..D30 */ | |||
| val |= bit << 31; | |||
| val >>= 1; | |||
| } | |||
| PIN_TMS_SET(); | |||
| JTAG_CYCLE_TDO(bit); /* Get D31 & Exit1-DR */ | |||
| val |= bit << 31; | |||
| JTAG_CYCLE_TCK(); /* Update-DR */ | |||
| PIN_TMS_CLR(); | |||
| JTAG_CYCLE_TCK(); /* Idle */ | |||
| return (val); | |||
| } | |||
| // JTAG Write ABORT register | |||
| // data: value to write | |||
| // return: none | |||
| void JTAG_WriteAbort (uint32_t data) { | |||
| uint32_t n; | |||
| PIN_TMS_SET(); | |||
| JTAG_CYCLE_TCK(); /* Select-DR-Scan */ | |||
| PIN_TMS_CLR(); | |||
| JTAG_CYCLE_TCK(); /* Capture-DR */ | |||
| JTAG_CYCLE_TCK(); /* Shift-DR */ | |||
| for (n = DAP_Data.jtag_dev.index; n; n--) { | |||
| JTAG_CYCLE_TCK(); /* Bypass before data */ | |||
| } | |||
| PIN_TDI_OUT(0U); | |||
| JTAG_CYCLE_TCK(); /* Set RnW=0 (Write) */ | |||
| JTAG_CYCLE_TCK(); /* Set A2=0 */ | |||
| JTAG_CYCLE_TCK(); /* Set A3=0 */ | |||
| for (n = 31U; n; n--) { | |||
| JTAG_CYCLE_TDI(data); /* Set D0..D30 */ | |||
| data >>= 1; | |||
| } | |||
| n = DAP_Data.jtag_dev.count - DAP_Data.jtag_dev.index - 1U; | |||
| if (n) { | |||
| JTAG_CYCLE_TDI(data); /* Set D31 */ | |||
| for (--n; n; n--) { | |||
| JTAG_CYCLE_TCK(); /* Bypass after data */ | |||
| } | |||
| PIN_TMS_SET(); | |||
| JTAG_CYCLE_TCK(); /* Bypass & Exit1-DR */ | |||
| } else { | |||
| PIN_TMS_SET(); | |||
| JTAG_CYCLE_TDI(data); /* Set D31 & Exit1-DR */ | |||
| } | |||
| JTAG_CYCLE_TCK(); /* Update-DR */ | |||
| PIN_TMS_CLR(); | |||
| JTAG_CYCLE_TCK(); /* Idle */ | |||
| PIN_TDI_OUT(1U); | |||
| } | |||
| // JTAG Set IR | |||
| // ir: IR value | |||
| // return: none | |||
| void JTAG_IR (uint32_t ir) { | |||
| if (DAP_Data.fast_clock) { | |||
| JTAG_IR_Fast(ir); | |||
| } else { | |||
| JTAG_IR_Slow(ir); | |||
| } | |||
| } | |||
| // JTAG Transfer I/O | |||
| // request: A[3:2] RnW APnDP | |||
| // data: DATA[31:0] | |||
| // return: ACK[2:0] | |||
| uint8_t JTAG_Transfer(uint32_t request, uint32_t *data) { | |||
| if (DAP_Data.fast_clock) { | |||
| return JTAG_TransferFast(request, data); | |||
| } else { | |||
| return JTAG_TransferSlow(request, data); | |||
| } | |||
| } | |||
| #endif /* (DAP_JTAG != 0) */ | |||
| @@ -0,0 +1,798 @@ | |||
| /* | |||
| * Copyright (c) 2013-2021 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| * ---------------------------------------------------------------------- | |||
| * | |||
| * $Date: 29. March 2021 | |||
| * $Revision: V2.0.1 | |||
| * | |||
| * Project: CMSIS-DAP Source | |||
| * Title: SWO.c CMSIS-DAP SWO I/O | |||
| * | |||
| *---------------------------------------------------------------------------*/ | |||
| #include "DAP_config.h" | |||
| #include "DAP.h" | |||
| #if (SWO_UART != 0) | |||
| #include "Driver_USART.h" | |||
| #endif | |||
| #if (SWO_STREAM != 0) | |||
| #include "cmsis_os2.h" | |||
| #define osObjectsExternal | |||
| #include "osObjects.h" | |||
| #endif | |||
| #if (SWO_STREAM != 0) | |||
| #ifdef DAP_FW_V1 | |||
| #error "SWO Streaming Trace not supported in DAP V1!" | |||
| #endif | |||
| #endif | |||
| #if (SWO_UART != 0) | |||
| // USART Driver | |||
| #define _USART_Driver_(n) Driver_USART##n | |||
| #define USART_Driver_(n) _USART_Driver_(n) | |||
| extern ARM_DRIVER_USART USART_Driver_(SWO_UART_DRIVER); | |||
| #define pUSART (&USART_Driver_(SWO_UART_DRIVER)) | |||
| static uint8_t USART_Ready = 0U; | |||
| #endif /* (SWO_UART != 0) */ | |||
| #if ((SWO_UART != 0) || (SWO_MANCHESTER != 0)) | |||
| #define SWO_STREAM_TIMEOUT 50U /* Stream timeout in ms */ | |||
| #define USB_BLOCK_SIZE 512U /* USB Block Size */ | |||
| #define TRACE_BLOCK_SIZE 64U /* Trace Block Size (2^n: 32...512) */ | |||
| // Trace State | |||
| static uint8_t TraceTransport = 0U; /* Trace Transport */ | |||
| static uint8_t TraceMode = 0U; /* Trace Mode */ | |||
| static uint8_t TraceStatus = 0U; /* Trace Status without Errors */ | |||
| static uint8_t TraceError[2] = {0U, 0U}; /* Trace Error flags (banked) */ | |||
| static uint8_t TraceError_n = 0U; /* Active Trace Error bank */ | |||
| // Trace Buffer | |||
| static uint8_t TraceBuf[SWO_BUFFER_SIZE]; /* Trace Buffer (must be 2^n) */ | |||
| static volatile uint32_t TraceIndexI = 0U; /* Incoming Trace Index */ | |||
| static volatile uint32_t TraceIndexO = 0U; /* Outgoing Trace Index */ | |||
| static volatile uint8_t TraceUpdate; /* Trace Update Flag */ | |||
| static uint32_t TraceBlockSize; /* Current Trace Block Size */ | |||
| #if (TIMESTAMP_CLOCK != 0U) | |||
| // Trace Timestamp | |||
| static volatile struct { | |||
| uint32_t index; | |||
| uint32_t tick; | |||
| } TraceTimestamp; | |||
| #endif | |||
| // Trace Helper functions | |||
| static void ClearTrace (void); | |||
| static void ResumeTrace (void); | |||
| static uint32_t GetTraceCount (void); | |||
| static uint8_t GetTraceStatus (void); | |||
| static void SetTraceError (uint8_t flag); | |||
| #if (SWO_STREAM != 0) | |||
| extern osThreadId_t SWO_ThreadId; | |||
| static volatile uint8_t TransferBusy = 0U; /* Transfer Busy Flag */ | |||
| static uint32_t TransferSize; /* Current Transfer Size */ | |||
| #endif | |||
| #if (SWO_UART != 0) | |||
| // USART Driver Callback function | |||
| // event: event mask | |||
| static void USART_Callback (uint32_t event) { | |||
| uint32_t index_i; | |||
| uint32_t index_o; | |||
| uint32_t count; | |||
| uint32_t num; | |||
| if (event & ARM_USART_EVENT_RECEIVE_COMPLETE) { | |||
| #if (TIMESTAMP_CLOCK != 0U) | |||
| TraceTimestamp.tick = TIMESTAMP_GET(); | |||
| #endif | |||
| index_o = TraceIndexO; | |||
| index_i = TraceIndexI; | |||
| index_i += TraceBlockSize; | |||
| TraceIndexI = index_i; | |||
| #if (TIMESTAMP_CLOCK != 0U) | |||
| TraceTimestamp.index = index_i; | |||
| #endif | |||
| num = TRACE_BLOCK_SIZE - (index_i & (TRACE_BLOCK_SIZE - 1U)); | |||
| count = index_i - index_o; | |||
| if (count <= (SWO_BUFFER_SIZE - num)) { | |||
| index_i &= SWO_BUFFER_SIZE - 1U; | |||
| TraceBlockSize = num; | |||
| pUSART->Receive(&TraceBuf[index_i], num); | |||
| } else { | |||
| TraceStatus = DAP_SWO_CAPTURE_ACTIVE | DAP_SWO_CAPTURE_PAUSED; | |||
| } | |||
| TraceUpdate = 1U; | |||
| #if (SWO_STREAM != 0) | |||
| if (TraceTransport == 2U) { | |||
| if (count >= (USB_BLOCK_SIZE - (index_o & (USB_BLOCK_SIZE - 1U)))) { | |||
| osThreadFlagsSet(SWO_ThreadId, 1U); | |||
| } | |||
| } | |||
| #endif | |||
| } | |||
| if (event & ARM_USART_EVENT_RX_OVERFLOW) { | |||
| SetTraceError(DAP_SWO_BUFFER_OVERRUN); | |||
| } | |||
| if (event & (ARM_USART_EVENT_RX_BREAK | | |||
| ARM_USART_EVENT_RX_FRAMING_ERROR | | |||
| ARM_USART_EVENT_RX_PARITY_ERROR)) { | |||
| SetTraceError(DAP_SWO_STREAM_ERROR); | |||
| } | |||
| } | |||
| // Enable or disable SWO Mode (UART) | |||
| // enable: enable flag | |||
| // return: 1 - Success, 0 - Error | |||
| __WEAK uint32_t SWO_Mode_UART (uint32_t enable) { | |||
| int32_t status; | |||
| USART_Ready = 0U; | |||
| if (enable != 0U) { | |||
| status = pUSART->Initialize(USART_Callback); | |||
| if (status != ARM_DRIVER_OK) { | |||
| return (0U); | |||
| } | |||
| status = pUSART->PowerControl(ARM_POWER_FULL); | |||
| if (status != ARM_DRIVER_OK) { | |||
| pUSART->Uninitialize(); | |||
| return (0U); | |||
| } | |||
| } else { | |||
| pUSART->Control(ARM_USART_CONTROL_RX, 0U); | |||
| pUSART->Control(ARM_USART_ABORT_RECEIVE, 0U); | |||
| pUSART->PowerControl(ARM_POWER_OFF); | |||
| pUSART->Uninitialize(); | |||
| } | |||
| return (1U); | |||
| } | |||
| // Configure SWO Baudrate (UART) | |||
| // baudrate: requested baudrate | |||
| // return: actual baudrate or 0 when not configured | |||
| __WEAK uint32_t SWO_Baudrate_UART (uint32_t baudrate) { | |||
| int32_t status; | |||
| uint32_t index; | |||
| uint32_t num; | |||
| if (baudrate > SWO_UART_MAX_BAUDRATE) { | |||
| baudrate = SWO_UART_MAX_BAUDRATE; | |||
| } | |||
| if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE) { | |||
| pUSART->Control(ARM_USART_CONTROL_RX, 0U); | |||
| if (pUSART->GetStatus().rx_busy) { | |||
| TraceIndexI += pUSART->GetRxCount(); | |||
| pUSART->Control(ARM_USART_ABORT_RECEIVE, 0U); | |||
| } | |||
| } | |||
| status = pUSART->Control(ARM_USART_MODE_ASYNCHRONOUS | | |||
| ARM_USART_DATA_BITS_8 | | |||
| ARM_USART_PARITY_NONE | | |||
| ARM_USART_STOP_BITS_1, | |||
| baudrate); | |||
| if (status == ARM_DRIVER_OK) { | |||
| USART_Ready = 1U; | |||
| } else { | |||
| USART_Ready = 0U; | |||
| return (0U); | |||
| } | |||
| if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE) { | |||
| if ((TraceStatus & DAP_SWO_CAPTURE_PAUSED) == 0U) { | |||
| index = TraceIndexI & (SWO_BUFFER_SIZE - 1U); | |||
| num = TRACE_BLOCK_SIZE - (index & (TRACE_BLOCK_SIZE - 1U)); | |||
| TraceBlockSize = num; | |||
| pUSART->Receive(&TraceBuf[index], num); | |||
| } | |||
| pUSART->Control(ARM_USART_CONTROL_RX, 1U); | |||
| } | |||
| return (baudrate); | |||
| } | |||
| // Control SWO Capture (UART) | |||
| // active: active flag | |||
| // return: 1 - Success, 0 - Error | |||
| __WEAK uint32_t SWO_Control_UART (uint32_t active) { | |||
| int32_t status; | |||
| if (active) { | |||
| if (!USART_Ready) { | |||
| return (0U); | |||
| } | |||
| TraceBlockSize = 1U; | |||
| status = pUSART->Receive(&TraceBuf[0], 1U); | |||
| if (status != ARM_DRIVER_OK) { | |||
| return (0U); | |||
| } | |||
| status = pUSART->Control(ARM_USART_CONTROL_RX, 1U); | |||
| if (status != ARM_DRIVER_OK) { | |||
| return (0U); | |||
| } | |||
| } else { | |||
| pUSART->Control(ARM_USART_CONTROL_RX, 0U); | |||
| if (pUSART->GetStatus().rx_busy) { | |||
| TraceIndexI += pUSART->GetRxCount(); | |||
| pUSART->Control(ARM_USART_ABORT_RECEIVE, 0U); | |||
| } | |||
| } | |||
| return (1U); | |||
| } | |||
| // Start SWO Capture (UART) | |||
| // buf: pointer to buffer for capturing | |||
| // num: number of bytes to capture | |||
| __WEAK void SWO_Capture_UART (uint8_t *buf, uint32_t num) { | |||
| TraceBlockSize = num; | |||
| pUSART->Receive(buf, num); | |||
| } | |||
| // Get SWO Pending Trace Count (UART) | |||
| // return: number of pending trace data bytes | |||
| __WEAK uint32_t SWO_GetCount_UART (void) { | |||
| uint32_t count; | |||
| if (pUSART->GetStatus().rx_busy) { | |||
| count = pUSART->GetRxCount(); | |||
| } else { | |||
| count = 0U; | |||
| } | |||
| return (count); | |||
| } | |||
| #endif /* (SWO_UART != 0) */ | |||
| #if (SWO_MANCHESTER != 0) | |||
| // Enable or disable SWO Mode (Manchester) | |||
| // enable: enable flag | |||
| // return: 1 - Success, 0 - Error | |||
| __WEAK uint32_t SWO_Mode_Manchester (uint32_t enable) { | |||
| return (0U); | |||
| } | |||
| // Configure SWO Baudrate (Manchester) | |||
| // baudrate: requested baudrate | |||
| // return: actual baudrate or 0 when not configured | |||
| __WEAK uint32_t SWO_Baudrate_Manchester (uint32_t baudrate) { | |||
| return (0U); | |||
| } | |||
| // Control SWO Capture (Manchester) | |||
| // active: active flag | |||
| // return: 1 - Success, 0 - Error | |||
| __WEAK uint32_t SWO_Control_Manchester (uint32_t active) { | |||
| return (0U); | |||
| } | |||
| // Start SWO Capture (Manchester) | |||
| // buf: pointer to buffer for capturing | |||
| // num: number of bytes to capture | |||
| __WEAK void SWO_Capture_Manchester (uint8_t *buf, uint32_t num) { | |||
| } | |||
| // Get SWO Pending Trace Count (Manchester) | |||
| // return: number of pending trace data bytes | |||
| __WEAK uint32_t SWO_GetCount_Manchester (void) { | |||
| } | |||
| #endif /* (SWO_MANCHESTER != 0) */ | |||
| // Clear Trace Errors and Data | |||
| static void ClearTrace (void) { | |||
| #if (SWO_STREAM != 0) | |||
| if (TraceTransport == 2U) { | |||
| if (TransferBusy != 0U) { | |||
| SWO_AbortTransfer(); | |||
| TransferBusy = 0U; | |||
| } | |||
| } | |||
| #endif | |||
| TraceError[0] = 0U; | |||
| TraceError[1] = 0U; | |||
| TraceError_n = 0U; | |||
| TraceIndexI = 0U; | |||
| TraceIndexO = 0U; | |||
| #if (TIMESTAMP_CLOCK != 0U) | |||
| TraceTimestamp.index = 0U; | |||
| TraceTimestamp.tick = 0U; | |||
| #endif | |||
| } | |||
| // Resume Trace Capture | |||
| static void ResumeTrace (void) { | |||
| uint32_t index_i; | |||
| uint32_t index_o; | |||
| if (TraceStatus == (DAP_SWO_CAPTURE_ACTIVE | DAP_SWO_CAPTURE_PAUSED)) { | |||
| index_i = TraceIndexI; | |||
| index_o = TraceIndexO; | |||
| if ((index_i - index_o) < SWO_BUFFER_SIZE) { | |||
| index_i &= SWO_BUFFER_SIZE - 1U; | |||
| switch (TraceMode) { | |||
| #if (SWO_UART != 0) | |||
| case DAP_SWO_UART: | |||
| TraceStatus = DAP_SWO_CAPTURE_ACTIVE; | |||
| SWO_Capture_UART(&TraceBuf[index_i], 1U); | |||
| break; | |||
| #endif | |||
| #if (SWO_MANCHESTER != 0) | |||
| case DAP_SWO_MANCHESTER: | |||
| TraceStatus = DAP_SWO_CAPTURE_ACTIVE; | |||
| SWO_Capture_Manchester(&TraceBuf[index_i], 1U); | |||
| break; | |||
| #endif | |||
| default: | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| // Get Trace Count | |||
| // return: number of available data bytes in trace buffer | |||
| static uint32_t GetTraceCount (void) { | |||
| uint32_t count; | |||
| if (TraceStatus == DAP_SWO_CAPTURE_ACTIVE) { | |||
| do { | |||
| TraceUpdate = 0U; | |||
| count = TraceIndexI - TraceIndexO; | |||
| switch (TraceMode) { | |||
| #if (SWO_UART != 0) | |||
| case DAP_SWO_UART: | |||
| count += SWO_GetCount_UART(); | |||
| break; | |||
| #endif | |||
| #if (SWO_MANCHESTER != 0) | |||
| case DAP_SWO_MANCHESTER: | |||
| count += SWO_GetCount_Manchester(); | |||
| break; | |||
| #endif | |||
| default: | |||
| break; | |||
| } | |||
| } while (TraceUpdate != 0U); | |||
| } else { | |||
| count = TraceIndexI - TraceIndexO; | |||
| } | |||
| return (count); | |||
| } | |||
| // Get Trace Status (clear Error flags) | |||
| // return: Trace Status (Active flag and Error flags) | |||
| static uint8_t GetTraceStatus (void) { | |||
| uint8_t status; | |||
| uint32_t n; | |||
| n = TraceError_n; | |||
| TraceError_n ^= 1U; | |||
| status = TraceStatus | TraceError[n]; | |||
| TraceError[n] = 0U; | |||
| return (status); | |||
| } | |||
| // Set Trace Error flag(s) | |||
| // flag: error flag(s) to set | |||
| static void SetTraceError (uint8_t flag) { | |||
| TraceError[TraceError_n] |= flag; | |||
| } | |||
| // Process SWO Transport command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t SWO_Transport (const uint8_t *request, uint8_t *response) { | |||
| uint8_t transport; | |||
| uint32_t result; | |||
| if ((TraceStatus & DAP_SWO_CAPTURE_ACTIVE) == 0U) { | |||
| transport = *request; | |||
| switch (transport) { | |||
| case 0U: | |||
| case 1U: | |||
| #if (SWO_STREAM != 0) | |||
| case 2U: | |||
| #endif | |||
| TraceTransport = transport; | |||
| result = 1U; | |||
| break; | |||
| default: | |||
| result = 0U; | |||
| break; | |||
| } | |||
| } else { | |||
| result = 0U; | |||
| } | |||
| if (result != 0U) { | |||
| *response = DAP_OK; | |||
| } else { | |||
| *response = DAP_ERROR; | |||
| } | |||
| return ((1U << 16) | 1U); | |||
| } | |||
| // Process SWO Mode command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t SWO_Mode (const uint8_t *request, uint8_t *response) { | |||
| uint8_t mode; | |||
| uint32_t result; | |||
| mode = *request; | |||
| switch (TraceMode) { | |||
| #if (SWO_UART != 0) | |||
| case DAP_SWO_UART: | |||
| SWO_Mode_UART(0U); | |||
| break; | |||
| #endif | |||
| #if (SWO_MANCHESTER != 0) | |||
| case DAP_SWO_MANCHESTER: | |||
| SWO_Mode_Manchester(0U); | |||
| break; | |||
| #endif | |||
| default: | |||
| break; | |||
| } | |||
| switch (mode) { | |||
| case DAP_SWO_OFF: | |||
| result = 1U; | |||
| break; | |||
| #if (SWO_UART != 0) | |||
| case DAP_SWO_UART: | |||
| result = SWO_Mode_UART(1U); | |||
| break; | |||
| #endif | |||
| #if (SWO_MANCHESTER != 0) | |||
| case DAP_SWO_MANCHESTER: | |||
| result = SWO_Mode_Manchester(1U); | |||
| break; | |||
| #endif | |||
| default: | |||
| result = 0U; | |||
| break; | |||
| } | |||
| if (result != 0U) { | |||
| TraceMode = mode; | |||
| } else { | |||
| TraceMode = DAP_SWO_OFF; | |||
| } | |||
| TraceStatus = 0U; | |||
| if (result != 0U) { | |||
| *response = DAP_OK; | |||
| } else { | |||
| *response = DAP_ERROR; | |||
| } | |||
| return ((1U << 16) | 1U); | |||
| } | |||
| // Process SWO Baudrate command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t SWO_Baudrate (const uint8_t *request, uint8_t *response) { | |||
| uint32_t baudrate; | |||
| baudrate = (uint32_t)(*(request+0) << 0) | | |||
| (uint32_t)(*(request+1) << 8) | | |||
| (uint32_t)(*(request+2) << 16) | | |||
| (uint32_t)(*(request+3) << 24); | |||
| switch (TraceMode) { | |||
| #if (SWO_UART != 0) | |||
| case DAP_SWO_UART: | |||
| baudrate = SWO_Baudrate_UART(baudrate); | |||
| break; | |||
| #endif | |||
| #if (SWO_MANCHESTER != 0) | |||
| case DAP_SWO_MANCHESTER: | |||
| baudrate = SWO_Baudrate_Manchester(baudrate); | |||
| break; | |||
| #endif | |||
| default: | |||
| baudrate = 0U; | |||
| break; | |||
| } | |||
| if (baudrate == 0U) { | |||
| TraceStatus = 0U; | |||
| } | |||
| *response++ = (uint8_t)(baudrate >> 0); | |||
| *response++ = (uint8_t)(baudrate >> 8); | |||
| *response++ = (uint8_t)(baudrate >> 16); | |||
| *response = (uint8_t)(baudrate >> 24); | |||
| return ((4U << 16) | 4U); | |||
| } | |||
| // Process SWO Control command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t SWO_Control (const uint8_t *request, uint8_t *response) { | |||
| uint8_t active; | |||
| uint32_t result; | |||
| active = *request & DAP_SWO_CAPTURE_ACTIVE; | |||
| if (active != (TraceStatus & DAP_SWO_CAPTURE_ACTIVE)) { | |||
| if (active) { | |||
| ClearTrace(); | |||
| } | |||
| switch (TraceMode) { | |||
| #if (SWO_UART != 0) | |||
| case DAP_SWO_UART: | |||
| result = SWO_Control_UART(active); | |||
| break; | |||
| #endif | |||
| #if (SWO_MANCHESTER != 0) | |||
| case DAP_SWO_MANCHESTER: | |||
| result = SWO_Control_Manchester(active); | |||
| break; | |||
| #endif | |||
| default: | |||
| result = 0U; | |||
| break; | |||
| } | |||
| if (result != 0U) { | |||
| TraceStatus = active; | |||
| #if (SWO_STREAM != 0) | |||
| if (TraceTransport == 2U) { | |||
| osThreadFlagsSet(SWO_ThreadId, 1U); | |||
| } | |||
| #endif | |||
| } | |||
| } else { | |||
| result = 1U; | |||
| } | |||
| if (result != 0U) { | |||
| *response = DAP_OK; | |||
| } else { | |||
| *response = DAP_ERROR; | |||
| } | |||
| return ((1U << 16) | 1U); | |||
| } | |||
| // Process SWO Status command and prepare response | |||
| // response: pointer to response data | |||
| // return: number of bytes in response | |||
| uint32_t SWO_Status (uint8_t *response) { | |||
| uint8_t status; | |||
| uint32_t count; | |||
| status = GetTraceStatus(); | |||
| count = GetTraceCount(); | |||
| *response++ = status; | |||
| *response++ = (uint8_t)(count >> 0); | |||
| *response++ = (uint8_t)(count >> 8); | |||
| *response++ = (uint8_t)(count >> 16); | |||
| *response = (uint8_t)(count >> 24); | |||
| return (5U); | |||
| } | |||
| // Process SWO Extended Status command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t SWO_ExtendedStatus (const uint8_t *request, uint8_t *response) { | |||
| uint8_t cmd; | |||
| uint8_t status; | |||
| uint32_t count; | |||
| #if (TIMESTAMP_CLOCK != 0U) | |||
| uint32_t index; | |||
| uint32_t tick; | |||
| #endif | |||
| uint32_t num; | |||
| num = 0U; | |||
| cmd = *request; | |||
| if (cmd & 0x01U) { | |||
| status = GetTraceStatus(); | |||
| *response++ = status; | |||
| num += 1U; | |||
| } | |||
| if (cmd & 0x02U) { | |||
| count = GetTraceCount(); | |||
| *response++ = (uint8_t)(count >> 0); | |||
| *response++ = (uint8_t)(count >> 8); | |||
| *response++ = (uint8_t)(count >> 16); | |||
| *response++ = (uint8_t)(count >> 24); | |||
| num += 4U; | |||
| } | |||
| #if (TIMESTAMP_CLOCK != 0U) | |||
| if (cmd & 0x04U) { | |||
| do { | |||
| TraceUpdate = 0U; | |||
| index = TraceTimestamp.index; | |||
| tick = TraceTimestamp.tick; | |||
| } while (TraceUpdate != 0U); | |||
| *response++ = (uint8_t)(index >> 0); | |||
| *response++ = (uint8_t)(index >> 8); | |||
| *response++ = (uint8_t)(index >> 16); | |||
| *response++ = (uint8_t)(index >> 24); | |||
| *response++ = (uint8_t)(tick >> 0); | |||
| *response++ = (uint8_t)(tick >> 8); | |||
| *response++ = (uint8_t)(tick >> 16); | |||
| *response++ = (uint8_t)(tick >> 24); | |||
| num += 4U; | |||
| } | |||
| #endif | |||
| return ((1U << 16) | num); | |||
| } | |||
| // Process SWO Data command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t SWO_Data (const uint8_t *request, uint8_t *response) { | |||
| uint8_t status; | |||
| uint32_t count; | |||
| uint32_t index; | |||
| uint32_t n, i; | |||
| status = GetTraceStatus(); | |||
| count = GetTraceCount(); | |||
| if (TraceTransport == 1U) { | |||
| n = (uint32_t)(*(request+0) << 0) | | |||
| (uint32_t)(*(request+1) << 8); | |||
| if (n > (DAP_PACKET_SIZE - 4U)) { | |||
| n = DAP_PACKET_SIZE - 4U; | |||
| } | |||
| if (count > n) { | |||
| count = n; | |||
| } | |||
| } else { | |||
| count = 0U; | |||
| } | |||
| *response++ = status; | |||
| *response++ = (uint8_t)(count >> 0); | |||
| *response++ = (uint8_t)(count >> 8); | |||
| if (TraceTransport == 1U) { | |||
| index = TraceIndexO; | |||
| for (i = index, n = count; n; n--) { | |||
| i &= SWO_BUFFER_SIZE - 1U; | |||
| *response++ = TraceBuf[i++]; | |||
| } | |||
| TraceIndexO = index + count; | |||
| ResumeTrace(); | |||
| } | |||
| return ((2U << 16) | (3U + count)); | |||
| } | |||
| #if (SWO_STREAM != 0) | |||
| // SWO Data Transfer complete callback | |||
| void SWO_TransferComplete (void) { | |||
| TraceIndexO += TransferSize; | |||
| TransferBusy = 0U; | |||
| ResumeTrace(); | |||
| osThreadFlagsSet(SWO_ThreadId, 1U); | |||
| } | |||
| // SWO Thread | |||
| __NO_RETURN void SWO_Thread (void *argument) { | |||
| uint32_t timeout; | |||
| uint32_t flags; | |||
| uint32_t count; | |||
| uint32_t index; | |||
| uint32_t i, n; | |||
| (void) argument; | |||
| timeout = osWaitForever; | |||
| for (;;) { | |||
| flags = osThreadFlagsWait(1U, osFlagsWaitAny, timeout); | |||
| if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE) { | |||
| timeout = SWO_STREAM_TIMEOUT; | |||
| } else { | |||
| timeout = osWaitForever; | |||
| flags = osFlagsErrorTimeout; | |||
| } | |||
| if (TransferBusy == 0U) { | |||
| count = GetTraceCount(); | |||
| if (count != 0U) { | |||
| index = TraceIndexO & (SWO_BUFFER_SIZE - 1U); | |||
| n = SWO_BUFFER_SIZE - index; | |||
| if (count > n) { | |||
| count = n; | |||
| } | |||
| if (flags != osFlagsErrorTimeout) { | |||
| i = index & (USB_BLOCK_SIZE - 1U); | |||
| if (i == 0U) { | |||
| count &= ~(USB_BLOCK_SIZE - 1U); | |||
| } else { | |||
| n = USB_BLOCK_SIZE - i; | |||
| if (count >= n) { | |||
| count = n; | |||
| } else { | |||
| count = 0U; | |||
| } | |||
| } | |||
| } | |||
| if (count != 0U) { | |||
| TransferSize = count; | |||
| TransferBusy = 1U; | |||
| SWO_QueueTransfer(&TraceBuf[index], count); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| #endif /* (SWO_STREAM != 0) */ | |||
| #endif /* ((SWO_UART != 0) || (SWO_MANCHESTER != 0)) */ | |||
| @@ -0,0 +1,286 @@ | |||
| /* | |||
| * Copyright (c) 2013-2017 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| * ---------------------------------------------------------------------- | |||
| * | |||
| * $Date: 1. December 2017 | |||
| * $Revision: V2.0.0 | |||
| * | |||
| * Project: CMSIS-DAP Source | |||
| * Title: SW_DP.c CMSIS-DAP SW DP I/O | |||
| * | |||
| *---------------------------------------------------------------------------*/ | |||
| #include "DAP_config.h" | |||
| #include "DAP.h" | |||
| // SW Macros | |||
| #define PIN_SWCLK_SET PIN_SWCLK_TCK_SET | |||
| #define PIN_SWCLK_CLR PIN_SWCLK_TCK_CLR | |||
| #define SW_CLOCK_CYCLE() \ | |||
| PIN_SWCLK_CLR(); \ | |||
| PIN_DELAY(); \ | |||
| PIN_SWCLK_SET(); \ | |||
| PIN_DELAY() | |||
| #define SW_WRITE_BIT(bit) \ | |||
| PIN_SWDIO_OUT(bit); \ | |||
| PIN_SWCLK_CLR(); \ | |||
| PIN_DELAY(); \ | |||
| PIN_SWCLK_SET(); \ | |||
| PIN_DELAY() | |||
| #define SW_READ_BIT(bit) \ | |||
| PIN_SWCLK_CLR(); \ | |||
| PIN_DELAY(); \ | |||
| bit = PIN_SWDIO_IN(); \ | |||
| PIN_SWCLK_SET(); \ | |||
| PIN_DELAY() | |||
| #define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) | |||
| // Generate SWJ Sequence | |||
| // count: sequence bit count | |||
| // data: pointer to sequence bit data | |||
| // return: none | |||
| #if ((DAP_SWD != 0) || (DAP_JTAG != 0)) | |||
| void SWJ_Sequence (uint32_t count, const uint8_t *data) { | |||
| uint32_t val; | |||
| uint32_t n; | |||
| val = 0U; | |||
| n = 0U; | |||
| while (count--) { | |||
| if (n == 0U) { | |||
| val = *data++; | |||
| n = 8U; | |||
| } | |||
| if (val & 1U) { | |||
| PIN_SWDIO_TMS_SET(); | |||
| } else { | |||
| PIN_SWDIO_TMS_CLR(); | |||
| } | |||
| SW_CLOCK_CYCLE(); | |||
| val >>= 1; | |||
| n--; | |||
| } | |||
| } | |||
| #endif | |||
| // Generate SWD Sequence | |||
| // info: sequence information | |||
| // swdo: pointer to SWDIO generated data | |||
| // swdi: pointer to SWDIO captured data | |||
| // return: none | |||
| #if (DAP_SWD != 0) | |||
| void SWD_Sequence (uint32_t info, const uint8_t *swdo, uint8_t *swdi) { | |||
| uint32_t val; | |||
| uint32_t bit; | |||
| uint32_t n, k; | |||
| n = info & SWD_SEQUENCE_CLK; | |||
| if (n == 0U) { | |||
| n = 64U; | |||
| } | |||
| if (info & SWD_SEQUENCE_DIN) { | |||
| while (n) { | |||
| val = 0U; | |||
| for (k = 8U; k && n; k--, n--) { | |||
| SW_READ_BIT(bit); | |||
| val >>= 1; | |||
| val |= bit << 7; | |||
| } | |||
| val >>= k; | |||
| *swdi++ = (uint8_t)val; | |||
| } | |||
| } else { | |||
| while (n) { | |||
| val = *swdo++; | |||
| for (k = 8U; k && n; k--, n--) { | |||
| SW_WRITE_BIT(val); | |||
| val >>= 1; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| #endif | |||
| #if (DAP_SWD != 0) | |||
| // SWD Transfer I/O | |||
| // request: A[3:2] RnW APnDP | |||
| // data: DATA[31:0] | |||
| // return: ACK[2:0] | |||
| #define SWD_TransferFunction(speed) /**/ \ | |||
| static uint8_t SWD_Transfer##speed (uint32_t request, uint32_t *data) { \ | |||
| uint32_t ack; \ | |||
| uint32_t bit; \ | |||
| uint32_t val; \ | |||
| uint32_t parity; \ | |||
| \ | |||
| uint32_t n; \ | |||
| \ | |||
| /* Packet Request */ \ | |||
| parity = 0U; \ | |||
| SW_WRITE_BIT(1U); /* Start Bit */ \ | |||
| bit = request >> 0; \ | |||
| SW_WRITE_BIT(bit); /* APnDP Bit */ \ | |||
| parity += bit; \ | |||
| bit = request >> 1; \ | |||
| SW_WRITE_BIT(bit); /* RnW Bit */ \ | |||
| parity += bit; \ | |||
| bit = request >> 2; \ | |||
| SW_WRITE_BIT(bit); /* A2 Bit */ \ | |||
| parity += bit; \ | |||
| bit = request >> 3; \ | |||
| SW_WRITE_BIT(bit); /* A3 Bit */ \ | |||
| parity += bit; \ | |||
| SW_WRITE_BIT(parity); /* Parity Bit */ \ | |||
| SW_WRITE_BIT(0U); /* Stop Bit */ \ | |||
| SW_WRITE_BIT(1U); /* Park Bit */ \ | |||
| \ | |||
| /* Turnaround */ \ | |||
| PIN_SWDIO_OUT_DISABLE(); \ | |||
| for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ | |||
| SW_CLOCK_CYCLE(); \ | |||
| } \ | |||
| \ | |||
| /* Acknowledge response */ \ | |||
| SW_READ_BIT(bit); \ | |||
| ack = bit << 0; \ | |||
| SW_READ_BIT(bit); \ | |||
| ack |= bit << 1; \ | |||
| SW_READ_BIT(bit); \ | |||
| ack |= bit << 2; \ | |||
| \ | |||
| if (ack == DAP_TRANSFER_OK) { /* OK response */ \ | |||
| /* Data transfer */ \ | |||
| if (request & DAP_TRANSFER_RnW) { \ | |||
| /* Read data */ \ | |||
| val = 0U; \ | |||
| parity = 0U; \ | |||
| for (n = 32U; n; n--) { \ | |||
| SW_READ_BIT(bit); /* Read RDATA[0:31] */ \ | |||
| parity += bit; \ | |||
| val >>= 1; \ | |||
| val |= bit << 31; \ | |||
| } \ | |||
| SW_READ_BIT(bit); /* Read Parity */ \ | |||
| if ((parity ^ bit) & 1U) { \ | |||
| ack = DAP_TRANSFER_ERROR; \ | |||
| } \ | |||
| if (data) { *data = val; } \ | |||
| /* Turnaround */ \ | |||
| for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ | |||
| SW_CLOCK_CYCLE(); \ | |||
| } \ | |||
| PIN_SWDIO_OUT_ENABLE(); \ | |||
| } else { \ | |||
| /* Turnaround */ \ | |||
| for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ | |||
| SW_CLOCK_CYCLE(); \ | |||
| } \ | |||
| PIN_SWDIO_OUT_ENABLE(); \ | |||
| /* Write data */ \ | |||
| val = *data; \ | |||
| parity = 0U; \ | |||
| for (n = 32U; n; n--) { \ | |||
| SW_WRITE_BIT(val); /* Write WDATA[0:31] */ \ | |||
| parity += val; \ | |||
| val >>= 1; \ | |||
| } \ | |||
| SW_WRITE_BIT(parity); /* Write Parity Bit */ \ | |||
| } \ | |||
| /* Capture Timestamp */ \ | |||
| if (request & DAP_TRANSFER_TIMESTAMP) { \ | |||
| DAP_Data.timestamp = TIMESTAMP_GET(); \ | |||
| } \ | |||
| /* Idle cycles */ \ | |||
| n = DAP_Data.transfer.idle_cycles; \ | |||
| if (n) { \ | |||
| PIN_SWDIO_OUT(0U); \ | |||
| for (; n; n--) { \ | |||
| SW_CLOCK_CYCLE(); \ | |||
| } \ | |||
| } \ | |||
| PIN_SWDIO_OUT(1U); \ | |||
| return ((uint8_t)ack); \ | |||
| } \ | |||
| \ | |||
| if ((ack == DAP_TRANSFER_WAIT) || (ack == DAP_TRANSFER_FAULT)) { \ | |||
| /* WAIT or FAULT response */ \ | |||
| if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) != 0U)) { \ | |||
| for (n = 32U+1U; n; n--) { \ | |||
| SW_CLOCK_CYCLE(); /* Dummy Read RDATA[0:31] + Parity */ \ | |||
| } \ | |||
| } \ | |||
| /* Turnaround */ \ | |||
| for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ | |||
| SW_CLOCK_CYCLE(); \ | |||
| } \ | |||
| PIN_SWDIO_OUT_ENABLE(); \ | |||
| if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) == 0U)) { \ | |||
| PIN_SWDIO_OUT(0U); \ | |||
| for (n = 32U+1U; n; n--) { \ | |||
| SW_CLOCK_CYCLE(); /* Dummy Write WDATA[0:31] + Parity */ \ | |||
| } \ | |||
| } \ | |||
| PIN_SWDIO_OUT(1U); \ | |||
| return ((uint8_t)ack); \ | |||
| } \ | |||
| \ | |||
| /* Protocol error */ \ | |||
| for (n = DAP_Data.swd_conf.turnaround + 32U + 1U; n; n--) { \ | |||
| SW_CLOCK_CYCLE(); /* Back off data phase */ \ | |||
| } \ | |||
| PIN_SWDIO_OUT_ENABLE(); \ | |||
| PIN_SWDIO_OUT(1U); \ | |||
| return ((uint8_t)ack); \ | |||
| } | |||
| #undef PIN_DELAY | |||
| #define PIN_DELAY() PIN_DELAY_FAST() | |||
| SWD_TransferFunction(Fast) | |||
| #undef PIN_DELAY | |||
| #define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) | |||
| SWD_TransferFunction(Slow) | |||
| // SWD Transfer I/O | |||
| // request: A[3:2] RnW APnDP | |||
| // data: DATA[31:0] | |||
| // return: ACK[2:0] | |||
| uint8_t SWD_Transfer(uint32_t request, uint32_t *data) { | |||
| if (DAP_Data.fast_clock) { | |||
| return SWD_TransferFast(request, data); | |||
| } else { | |||
| return SWD_TransferSlow(request, data); | |||
| } | |||
| } | |||
| #endif /* (DAP_SWD != 0) */ | |||
| @@ -0,0 +1,652 @@ | |||
| /* | |||
| * Copyright (c) 2021 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| * | |||
| * ---------------------------------------------------------------------- | |||
| * | |||
| * $Date: 1. March 2021 | |||
| * $Revision: V1.0.0 | |||
| * | |||
| * Project: CMSIS-DAP Source | |||
| * Title: UART.c CMSIS-DAP UART | |||
| * | |||
| *---------------------------------------------------------------------------*/ | |||
| #include "DAP_config.h" | |||
| #include "DAP.h" | |||
| #if (DAP_UART != 0) | |||
| #ifdef DAP_FW_V1 | |||
| #error "UART Communication Port not supported in DAP V1!" | |||
| #endif | |||
| #include "Driver_USART.h" | |||
| #include "cmsis_os2.h" | |||
| #include <string.h> | |||
| #define UART_RX_BLOCK_SIZE 32U /* Uart Rx Block Size (must be 2^n) */ | |||
| // USART Driver | |||
| #define _USART_Driver_(n) Driver_USART##n | |||
| #define USART_Driver_(n) _USART_Driver_(n) | |||
| extern ARM_DRIVER_USART USART_Driver_(DAP_UART_DRIVER); | |||
| #define pUSART (&USART_Driver_(DAP_UART_DRIVER)) | |||
| // UART Configuration | |||
| #if (DAP_UART_USB_COM_PORT != 0) | |||
| static uint8_t UartTransport = DAP_UART_TRANSPORT_USB_COM_PORT; | |||
| #else | |||
| static uint8_t UartTransport = DAP_UART_TRANSPORT_NONE; | |||
| #endif | |||
| // UART Flags | |||
| static uint8_t UartConfigured = 0U; | |||
| static uint8_t UartReceiveEnabled = 0U; | |||
| static uint8_t UartTransmitEnabled = 0U; | |||
| static uint8_t UartTransmitActive = 0U; | |||
| // UART TX Buffer | |||
| static uint8_t UartTxBuf[DAP_UART_TX_BUFFER_SIZE]; | |||
| static volatile uint32_t UartTxIndexI = 0U; | |||
| static volatile uint32_t UartTxIndexO = 0U; | |||
| // UART RX Buffer | |||
| static uint8_t UartRxBuf[DAP_UART_RX_BUFFER_SIZE]; | |||
| static volatile uint32_t UartRxIndexI = 0U; | |||
| static volatile uint32_t UartRxIndexO = 0U; | |||
| // Uart Errors | |||
| static volatile uint8_t UartErrorRxDataLost = 0U; | |||
| static volatile uint8_t UartErrorFraming = 0U; | |||
| static volatile uint8_t UartErrorParity = 0U; | |||
| // UART Transmit | |||
| static uint32_t UartTxNum = 0U; | |||
| // Function prototypes | |||
| static uint8_t UART_Init (void); | |||
| static void UART_Uninit (void); | |||
| static uint8_t UART_Get_Status (void); | |||
| static uint8_t UART_Receive_Enable (void); | |||
| static uint8_t UART_Transmit_Enable (void); | |||
| static void UART_Receive_Disable (void); | |||
| static void UART_Transmit_Disable (void); | |||
| static void UART_Receive_Flush (void); | |||
| static void UART_Transmit_Flush (void); | |||
| static void UART_Receive (void); | |||
| static void UART_Transmit (void); | |||
| // USART Driver Callback function | |||
| // event: event mask | |||
| static void USART_Callback (uint32_t event) { | |||
| if (event & ARM_USART_EVENT_SEND_COMPLETE) { | |||
| UartTxIndexO += UartTxNum; | |||
| UartTransmitActive = 0U; | |||
| UART_Transmit(); | |||
| } | |||
| if (event & ARM_USART_EVENT_RECEIVE_COMPLETE) { | |||
| UartRxIndexI += UART_RX_BLOCK_SIZE; | |||
| UART_Receive(); | |||
| } | |||
| if (event & ARM_USART_EVENT_RX_OVERFLOW) { | |||
| UartErrorRxDataLost = 1U; | |||
| } | |||
| if (event & ARM_USART_EVENT_RX_FRAMING_ERROR) { | |||
| UartErrorFraming = 1U; | |||
| } | |||
| if (event & ARM_USART_EVENT_RX_PARITY_ERROR) { | |||
| UartErrorParity = 1U; | |||
| } | |||
| } | |||
| // Init UART | |||
| // return: DAP_OK or DAP_ERROR | |||
| static uint8_t UART_Init (void) { | |||
| int32_t status; | |||
| uint8_t ret = DAP_ERROR; | |||
| UartConfigured = 0U; | |||
| UartReceiveEnabled = 0U; | |||
| UartTransmitEnabled = 0U; | |||
| UartTransmitActive = 0U; | |||
| UartErrorRxDataLost = 0U; | |||
| UartErrorFraming = 0U; | |||
| UartErrorParity = 0U; | |||
| UartTxIndexI = 0U; | |||
| UartTxIndexO = 0U; | |||
| UartRxIndexI = 0U; | |||
| UartRxIndexO = 0U; | |||
| UartTxNum = 0U; | |||
| status = pUSART->Initialize(USART_Callback); | |||
| if (status == ARM_DRIVER_OK) { | |||
| status = pUSART->PowerControl(ARM_POWER_FULL); | |||
| } | |||
| if (status == ARM_DRIVER_OK) { | |||
| ret = DAP_OK; | |||
| } | |||
| return (ret); | |||
| } | |||
| // Un-Init UART | |||
| static void UART_Uninit (void) { | |||
| UartConfigured = 0U; | |||
| pUSART->PowerControl(ARM_POWER_OFF); | |||
| pUSART->Uninitialize(); | |||
| } | |||
| // Get UART Status | |||
| // return: status | |||
| static uint8_t UART_Get_Status (void) { | |||
| uint8_t status = 0U; | |||
| if (UartReceiveEnabled != 0U) { | |||
| status |= DAP_UART_STATUS_RX_ENABLED; | |||
| } | |||
| if (UartErrorRxDataLost != 0U) { | |||
| UartErrorRxDataLost = 0U; | |||
| status |= DAP_UART_STATUS_RX_DATA_LOST; | |||
| } | |||
| if (UartErrorFraming != 0U) { | |||
| UartErrorFraming = 0U; | |||
| status |= DAP_UART_STATUS_FRAMING_ERROR; | |||
| } | |||
| if (UartErrorParity != 0U) { | |||
| UartErrorParity = 0U; | |||
| status |= DAP_UART_STATUS_PARITY_ERROR; | |||
| } | |||
| if (UartTransmitEnabled != 0U) { | |||
| status |= DAP_UART_STATUS_TX_ENABLED; | |||
| } | |||
| return (status); | |||
| } | |||
| // Enable UART Receive | |||
| // return: DAP_OK or DAP_ERROR | |||
| static uint8_t UART_Receive_Enable (void) { | |||
| int32_t status; | |||
| uint8_t ret = DAP_ERROR; | |||
| if (UartReceiveEnabled == 0U) { | |||
| // Flush Buffers | |||
| UartRxIndexI = 0U; | |||
| UartRxIndexO = 0U; | |||
| UART_Receive(); | |||
| status = pUSART->Control(ARM_USART_CONTROL_RX, 1U); | |||
| if (status == ARM_DRIVER_OK) { | |||
| UartReceiveEnabled = 1U; | |||
| ret = DAP_OK; | |||
| } | |||
| } else { | |||
| ret = DAP_OK; | |||
| } | |||
| return (ret); | |||
| } | |||
| // Enable UART Transmit | |||
| // return: DAP_OK or DAP_ERROR | |||
| static uint8_t UART_Transmit_Enable (void) { | |||
| int32_t status; | |||
| uint8_t ret = DAP_ERROR; | |||
| if (UartTransmitEnabled == 0U) { | |||
| // Flush Buffers | |||
| UartTransmitActive = 0U; | |||
| UartTxIndexI = 0U; | |||
| UartTxIndexO = 0U; | |||
| UartTxNum = 0U; | |||
| status = pUSART->Control(ARM_USART_CONTROL_TX, 1U); | |||
| if (status == ARM_DRIVER_OK) { | |||
| UartTransmitEnabled = 1U; | |||
| ret = DAP_OK; | |||
| } | |||
| } else { | |||
| ret = DAP_OK; | |||
| } | |||
| return (ret); | |||
| } | |||
| // Disable UART Receive | |||
| static void UART_Receive_Disable (void) { | |||
| if (UartReceiveEnabled != 0U) { | |||
| pUSART->Control(ARM_USART_CONTROL_RX, 0U); | |||
| pUSART->Control(ARM_USART_ABORT_RECEIVE, 0U); | |||
| UartReceiveEnabled = 0U; | |||
| } | |||
| } | |||
| // Disable UART Transmit | |||
| static void UART_Transmit_Disable (void) { | |||
| if (UartTransmitEnabled != 0U) { | |||
| pUSART->Control(ARM_USART_ABORT_SEND, 0U); | |||
| pUSART->Control(ARM_USART_CONTROL_TX, 0U); | |||
| UartTransmitActive = 0U; | |||
| UartTransmitEnabled = 0U; | |||
| } | |||
| } | |||
| // Flush UART Receive buffer | |||
| static void UART_Receive_Flush (void) { | |||
| pUSART->Control(ARM_USART_ABORT_RECEIVE, 0U); | |||
| UartRxIndexI = 0U; | |||
| UartRxIndexO = 0U; | |||
| if (UartReceiveEnabled != 0U) { | |||
| UART_Receive(); | |||
| } | |||
| } | |||
| // Flush UART Transmit buffer | |||
| static void UART_Transmit_Flush (void) { | |||
| pUSART->Control(ARM_USART_ABORT_SEND, 0U); | |||
| UartTransmitActive = 0U; | |||
| UartTxIndexI = 0U; | |||
| UartTxIndexO = 0U; | |||
| UartTxNum = 0U; | |||
| } | |||
| // Receive data from target via UART | |||
| static void UART_Receive (void) { | |||
| uint32_t index; | |||
| index = UartRxIndexI & (DAP_UART_RX_BUFFER_SIZE - 1U); | |||
| pUSART->Receive(&UartRxBuf[index], UART_RX_BLOCK_SIZE); | |||
| } | |||
| // Transmit available data to target via UART | |||
| static void UART_Transmit (void) { | |||
| uint32_t count; | |||
| uint32_t index; | |||
| count = UartTxIndexI - UartTxIndexO; | |||
| index = UartTxIndexO & (DAP_UART_TX_BUFFER_SIZE - 1U); | |||
| if (count != 0U) { | |||
| if ((index + count) <= DAP_UART_TX_BUFFER_SIZE) { | |||
| UartTxNum = count; | |||
| } else { | |||
| UartTxNum = DAP_UART_TX_BUFFER_SIZE - index; | |||
| } | |||
| UartTransmitActive = 1U; | |||
| pUSART->Send(&UartTxBuf[index], UartTxNum); | |||
| } | |||
| } | |||
| // Process UART Transport command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t UART_Transport (const uint8_t *request, uint8_t *response) { | |||
| uint8_t transport; | |||
| uint8_t ret = DAP_ERROR; | |||
| transport = *request; | |||
| switch (transport) { | |||
| case DAP_UART_TRANSPORT_NONE: | |||
| switch (UartTransport) { | |||
| case DAP_UART_TRANSPORT_NONE: | |||
| ret = DAP_OK; | |||
| break; | |||
| case DAP_UART_TRANSPORT_USB_COM_PORT: | |||
| #if (DAP_UART_USB_COM_PORT != 0) | |||
| USB_COM_PORT_Activate(0U); | |||
| UartTransport = DAP_UART_TRANSPORT_NONE; | |||
| ret = DAP_OK; | |||
| #endif | |||
| break; | |||
| case DAP_UART_TRANSPORT_DAP_COMMAND: | |||
| UART_Receive_Disable(); | |||
| UART_Transmit_Disable(); | |||
| UART_Uninit(); | |||
| UartTransport = DAP_UART_TRANSPORT_NONE; | |||
| ret= DAP_OK; | |||
| break; | |||
| } | |||
| break; | |||
| case DAP_UART_TRANSPORT_USB_COM_PORT: | |||
| switch (UartTransport) { | |||
| case DAP_UART_TRANSPORT_NONE: | |||
| #if (DAP_UART_USB_COM_PORT != 0) | |||
| if (USB_COM_PORT_Activate(1U) == 0U) { | |||
| UartTransport = DAP_UART_TRANSPORT_USB_COM_PORT; | |||
| ret = DAP_OK; | |||
| } | |||
| #endif | |||
| break; | |||
| case DAP_UART_TRANSPORT_USB_COM_PORT: | |||
| ret = DAP_OK; | |||
| break; | |||
| case DAP_UART_TRANSPORT_DAP_COMMAND: | |||
| UART_Receive_Disable(); | |||
| UART_Transmit_Disable(); | |||
| UART_Uninit(); | |||
| UartTransport = DAP_UART_TRANSPORT_NONE; | |||
| #if (DAP_UART_USB_COM_PORT != 0) | |||
| if (USB_COM_PORT_Activate(1U) == 0U) { | |||
| UartTransport = DAP_UART_TRANSPORT_USB_COM_PORT; | |||
| ret = DAP_OK; | |||
| } | |||
| #endif | |||
| break; | |||
| } | |||
| break; | |||
| case DAP_UART_TRANSPORT_DAP_COMMAND: | |||
| switch (UartTransport) { | |||
| case DAP_UART_TRANSPORT_NONE: | |||
| ret = UART_Init(); | |||
| if (ret == DAP_OK) { | |||
| UartTransport = DAP_UART_TRANSPORT_DAP_COMMAND; | |||
| } | |||
| break; | |||
| case DAP_UART_TRANSPORT_USB_COM_PORT: | |||
| #if (DAP_UART_USB_COM_PORT != 0) | |||
| USB_COM_PORT_Activate(0U); | |||
| UartTransport = DAP_UART_TRANSPORT_NONE; | |||
| #endif | |||
| ret = UART_Init(); | |||
| if (ret == DAP_OK) { | |||
| UartTransport = DAP_UART_TRANSPORT_DAP_COMMAND; | |||
| } | |||
| break; | |||
| case DAP_UART_TRANSPORT_DAP_COMMAND: | |||
| ret = DAP_OK; | |||
| break; | |||
| } | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| *response = ret; | |||
| return ((1U << 16) | 1U); | |||
| } | |||
| // Process UART Configure command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t UART_Configure (const uint8_t *request, uint8_t *response) { | |||
| uint8_t control, status; | |||
| uint32_t baudrate; | |||
| int32_t result; | |||
| if (UartTransport != DAP_UART_TRANSPORT_DAP_COMMAND) { | |||
| status = DAP_UART_CFG_ERROR_DATA_BITS | | |||
| DAP_UART_CFG_ERROR_PARITY | | |||
| DAP_UART_CFG_ERROR_STOP_BITS; | |||
| baudrate = 0U; // baudrate error | |||
| } else { | |||
| status = 0U; | |||
| control = *request; | |||
| baudrate = (uint32_t)(*(request+1) << 0) | | |||
| (uint32_t)(*(request+2) << 8) | | |||
| (uint32_t)(*(request+3) << 16) | | |||
| (uint32_t)(*(request+4) << 24); | |||
| result = pUSART->Control(control | | |||
| ARM_USART_MODE_ASYNCHRONOUS | | |||
| ARM_USART_FLOW_CONTROL_NONE, | |||
| baudrate); | |||
| if (result == ARM_DRIVER_OK) { | |||
| UartConfigured = 1U; | |||
| } else { | |||
| UartConfigured = 0U; | |||
| switch (result) { | |||
| case ARM_USART_ERROR_BAUDRATE: | |||
| status = 0U; | |||
| baudrate = 0U; | |||
| break; | |||
| case ARM_USART_ERROR_DATA_BITS: | |||
| status = DAP_UART_CFG_ERROR_DATA_BITS; | |||
| break; | |||
| case ARM_USART_ERROR_PARITY: | |||
| status = DAP_UART_CFG_ERROR_PARITY; | |||
| break; | |||
| case ARM_USART_ERROR_STOP_BITS: | |||
| status = DAP_UART_CFG_ERROR_STOP_BITS; | |||
| break; | |||
| default: | |||
| status = DAP_UART_CFG_ERROR_DATA_BITS | | |||
| DAP_UART_CFG_ERROR_PARITY | | |||
| DAP_UART_CFG_ERROR_STOP_BITS; | |||
| baudrate = 0U; | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| *response++ = status; | |||
| *response++ = (uint8_t)(baudrate >> 0); | |||
| *response++ = (uint8_t)(baudrate >> 8); | |||
| *response++ = (uint8_t)(baudrate >> 16); | |||
| *response = (uint8_t)(baudrate >> 24); | |||
| return ((5U << 16) | 5U); | |||
| } | |||
| // Process UART Control command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t UART_Control (const uint8_t *request, uint8_t *response) { | |||
| uint8_t control; | |||
| uint8_t result; | |||
| uint8_t ret = DAP_OK; | |||
| if (UartTransport != DAP_UART_TRANSPORT_DAP_COMMAND) { | |||
| ret = DAP_ERROR; | |||
| } else { | |||
| control = *request; | |||
| if ((control & DAP_UART_CONTROL_RX_DISABLE) != 0U) { | |||
| // Receive disable | |||
| UART_Receive_Disable(); | |||
| } else if ((control & DAP_UART_CONTROL_RX_ENABLE) != 0U) { | |||
| // Receive enable | |||
| if (UartConfigured != 0U) { | |||
| result = UART_Receive_Enable(); | |||
| if (result != DAP_OK) { | |||
| ret = DAP_ERROR; | |||
| } | |||
| } else { | |||
| ret = DAP_ERROR; | |||
| } | |||
| } | |||
| if ((control & DAP_UART_CONTROL_RX_BUF_FLUSH) != 0U) { | |||
| UART_Receive_Flush(); | |||
| } | |||
| if ((control & DAP_UART_CONTROL_TX_DISABLE) != 0U) { | |||
| // Transmit disable | |||
| UART_Transmit_Disable(); | |||
| } else if ((control & DAP_UART_CONTROL_TX_ENABLE) != 0U) { | |||
| // Transmit enable | |||
| if (UartConfigured != 0U) { | |||
| result = UART_Transmit_Enable(); | |||
| if (result != DAP_OK) { | |||
| ret = DAP_ERROR; | |||
| } | |||
| } else { | |||
| ret = DAP_ERROR; | |||
| } | |||
| } | |||
| if ((control & DAP_UART_CONTROL_TX_BUF_FLUSH) != 0U) { | |||
| UART_Transmit_Flush(); | |||
| } | |||
| } | |||
| *response = ret; | |||
| return ((1U << 16) | 1U); | |||
| } | |||
| // Process UART Status command and prepare response | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t UART_Status (uint8_t *response) { | |||
| uint32_t rx_cnt, tx_cnt; | |||
| uint32_t cnt; | |||
| uint8_t status; | |||
| if ((UartTransport != DAP_UART_TRANSPORT_DAP_COMMAND) || | |||
| (UartConfigured == 0U)) { | |||
| rx_cnt = 0U; | |||
| tx_cnt = 0U; | |||
| status = 0U; | |||
| } else { | |||
| rx_cnt = UartRxIndexI - UartRxIndexO; | |||
| rx_cnt += pUSART->GetRxCount(); | |||
| if (rx_cnt > (DAP_UART_RX_BUFFER_SIZE - (UART_RX_BLOCK_SIZE*2))) { | |||
| // Overflow | |||
| UartErrorRxDataLost = 1U; | |||
| rx_cnt = (DAP_UART_RX_BUFFER_SIZE - (UART_RX_BLOCK_SIZE*2)); | |||
| UartRxIndexO = UartRxIndexI - rx_cnt; | |||
| } | |||
| tx_cnt = UartTxIndexI - UartTxIndexO; | |||
| cnt = pUSART->GetTxCount(); | |||
| if (UartTransmitActive != 0U) { | |||
| tx_cnt -= cnt; | |||
| } | |||
| status = UART_Get_Status(); | |||
| } | |||
| *response++ = status; | |||
| *response++ = (uint8_t)(rx_cnt >> 0); | |||
| *response++ = (uint8_t)(rx_cnt >> 8); | |||
| *response++ = (uint8_t)(rx_cnt >> 16); | |||
| *response++ = (uint8_t)(rx_cnt >> 24); | |||
| *response++ = (uint8_t)(tx_cnt >> 0); | |||
| *response++ = (uint8_t)(tx_cnt >> 8); | |||
| *response++ = (uint8_t)(tx_cnt >> 16); | |||
| *response = (uint8_t)(tx_cnt >> 24); | |||
| return ((0U << 16) | 9U); | |||
| } | |||
| // Process UART Transfer command and prepare response | |||
| // request: pointer to request data | |||
| // response: pointer to response data | |||
| // return: number of bytes in response (lower 16 bits) | |||
| // number of bytes in request (upper 16 bits) | |||
| uint32_t UART_Transfer (const uint8_t *request, uint8_t *response) { | |||
| uint32_t rx_cnt, tx_cnt; | |||
| uint32_t rx_num, tx_num; | |||
| uint8_t *rx_data; | |||
| const | |||
| uint8_t *tx_data; | |||
| uint32_t num; | |||
| uint32_t index; | |||
| uint8_t status; | |||
| if (UartTransport != DAP_UART_TRANSPORT_DAP_COMMAND) { | |||
| status = 0U; | |||
| rx_cnt = 0U; | |||
| tx_cnt = 0U; | |||
| } else { | |||
| // RX Data | |||
| rx_cnt = ((uint32_t)(*(request+0) << 0) | | |||
| (uint32_t)(*(request+1) << 8)); | |||
| if (rx_cnt > (DAP_PACKET_SIZE - 6U)) { | |||
| rx_cnt = (DAP_PACKET_SIZE - 6U); | |||
| } | |||
| rx_num = UartRxIndexI - UartRxIndexO; | |||
| rx_num += pUSART->GetRxCount(); | |||
| if (rx_num > (DAP_UART_RX_BUFFER_SIZE - (UART_RX_BLOCK_SIZE*2))) { | |||
| // Overflow | |||
| UartErrorRxDataLost = 1U; | |||
| rx_num = (DAP_UART_RX_BUFFER_SIZE - (UART_RX_BLOCK_SIZE*2)); | |||
| UartRxIndexO = UartRxIndexI - rx_num; | |||
| } | |||
| if (rx_cnt > rx_num) { | |||
| rx_cnt = rx_num; | |||
| } | |||
| rx_data = (response+5); | |||
| index = UartRxIndexO & (DAP_UART_RX_BUFFER_SIZE - 1U); | |||
| if ((index + rx_cnt) <= DAP_UART_RX_BUFFER_SIZE) { | |||
| memcpy( rx_data, &UartRxBuf[index], rx_cnt); | |||
| } else { | |||
| num = DAP_UART_RX_BUFFER_SIZE - index; | |||
| memcpy( rx_data, &UartRxBuf[index], num); | |||
| memcpy(&rx_data[num], &UartRxBuf[0], rx_cnt - num); | |||
| } | |||
| UartRxIndexO += rx_cnt; | |||
| // TX Data | |||
| tx_cnt = ((uint32_t)(*(request+2) << 0) | | |||
| (uint32_t)(*(request+3) << 8)); | |||
| tx_data = (request+4); | |||
| if (tx_cnt > (DAP_PACKET_SIZE - 5U)) { | |||
| tx_cnt = (DAP_PACKET_SIZE - 5U); | |||
| } | |||
| tx_num = UartTxIndexI - UartTxIndexO; | |||
| num = pUSART->GetTxCount(); | |||
| if (UartTransmitActive != 0U) { | |||
| tx_num -= num; | |||
| } | |||
| if (tx_cnt > (DAP_UART_TX_BUFFER_SIZE - tx_num)) { | |||
| tx_cnt = (DAP_UART_TX_BUFFER_SIZE - tx_num); | |||
| } | |||
| index = UartTxIndexI & (DAP_UART_TX_BUFFER_SIZE - 1U); | |||
| if ((index + tx_cnt) <= DAP_UART_TX_BUFFER_SIZE) { | |||
| memcpy(&UartTxBuf[index], tx_data, tx_cnt); | |||
| } else { | |||
| num = DAP_UART_TX_BUFFER_SIZE - index; | |||
| memcpy(&UartTxBuf[index], tx_data, num); | |||
| memcpy(&UartTxBuf[0], &tx_data[num], tx_cnt - num); | |||
| } | |||
| UartTxIndexI += tx_cnt; | |||
| if (UartTransmitActive == 0U) { | |||
| UART_Transmit(); | |||
| } | |||
| status = UART_Get_Status(); | |||
| } | |||
| *response++ = status; | |||
| *response++ = (uint8_t)(tx_cnt >> 0); | |||
| *response++ = (uint8_t)(tx_cnt >> 8); | |||
| *response++ = (uint8_t)(rx_cnt >> 0); | |||
| *response = (uint8_t)(rx_cnt >> 8); | |||
| return (((4U + tx_cnt) << 16) | (5U + rx_cnt)); | |||
| } | |||
| #endif /* DAP_UART */ | |||
| @@ -0,0 +1,414 @@ | |||
| /* | |||
| * Copyright (c) 2016, 2019 ARM Limited. | |||
| * | |||
| * SPDX-License-Identifier: MIT | |||
| * | |||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | |||
| * of this software and associated documentation files (the "Software"), to | |||
| * deal in the Software without restriction, including without limitation the | |||
| * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |||
| * sell copies of the Software, and to permit persons to whom the Software is | |||
| * furnished to do so, subject to the following conditions: | |||
| * | |||
| * The above copyright notice and this permission notice shall be included in all | |||
| * copies or substantial portions of the Software. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
| * SOFTWARE. | |||
| */ | |||
| #ifndef __ARM_COMPUTE_NEMATH_H__ | |||
| #define __ARM_COMPUTE_NEMATH_H__ | |||
| #if defined(ARM_MATH_NEON) | |||
| /** Calculate floor of a vector. | |||
| * | |||
| * @param[in] val Input vector value in F32 format. | |||
| * | |||
| * @return The calculated floor vector. | |||
| */ | |||
| static inline float32x4_t vfloorq_f32(float32x4_t val); | |||
| /** Calculate inverse square root. | |||
| * | |||
| * @param[in] x Input value. | |||
| * | |||
| * @return The calculated inverse square root. | |||
| */ | |||
| static inline float32x2_t vinvsqrt_f32(float32x2_t x); | |||
| /** Calculate inverse square root. | |||
| * | |||
| * @param[in] x Input value. | |||
| * | |||
| * @return The calculated inverse square root. | |||
| */ | |||
| static inline float32x4_t vinvsqrtq_f32(float32x4_t x); | |||
| /** Calculate reciprocal. | |||
| * | |||
| * @param[in] x Input value. | |||
| * | |||
| * @return The calculated reciprocal. | |||
| */ | |||
| static inline float32x2_t vinv_f32(float32x2_t x); | |||
| /** Calculate reciprocal. | |||
| * | |||
| * @param[in] x Input value. | |||
| * | |||
| * @return The calculated reciprocal. | |||
| */ | |||
| static inline float32x4_t vinvq_f32(float32x4_t x); | |||
| /** Perform a 7th degree polynomial approximation using Estrin's method. | |||
| * | |||
| * @param[in] x Input vector value in F32 format. | |||
| * @param[in] coeffs Polynomial coefficients table. (array of flattened float32x4_t vectors) | |||
| * | |||
| * @return The calculated approximation. | |||
| */ | |||
| static inline float32x4_t vtaylor_polyq_f32(float32x4_t x, const float32_t *coeffs); | |||
| /** Calculate exponential | |||
| * | |||
| * @param[in] x Input vector value in F32 format. | |||
| * | |||
| * @return The calculated exponent. | |||
| */ | |||
| static inline float32x4_t vexpq_f32(float32x4_t x); | |||
| /** Calculate logarithm | |||
| * | |||
| * @param[in] x Input vector value in F32 format. | |||
| * | |||
| * @return The calculated logarithm. | |||
| */ | |||
| static inline float32x4_t vlogq_f32(float32x4_t x); | |||
| /** Calculate hyperbolic tangent. | |||
| * | |||
| * tanh(x) = (e^2x - 1)/(e^2x + 1) | |||
| * | |||
| * @note We clamp x to [-5,5] to avoid overflowing issues. | |||
| * | |||
| * @param[in] val Input vector value in F32 format. | |||
| * | |||
| * @return The calculated Hyperbolic Tangent. | |||
| */ | |||
| static inline float32x4_t vtanhq_f32(float32x4_t val); | |||
| /** Calculate n power of a number. | |||
| * | |||
| * pow(x,n) = e^(n*log(x)) | |||
| * | |||
| * @param[in] val Input vector value in F32 format. | |||
| * @param[in] n Powers to raise the input to. | |||
| * | |||
| * @return The calculated power. | |||
| */ | |||
| static inline float32x4_t vpowq_f32(float32x4_t val, float32x4_t n); | |||
| #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC | |||
| /** Calculate hyperbolic tangent. | |||
| * | |||
| * tanh(x) = (e^2x - 1)/(e^2x + 1) | |||
| * | |||
| * @note We clamp x to [-5,5] to avoid overflowing issues. | |||
| * | |||
| * @param[in] val Input vector value in F32 format. | |||
| * | |||
| * @return The calculated Hyperbolic Tangent. | |||
| */ | |||
| static inline float16x8_t vtanhq_f16(float16x8_t val); | |||
| /** Calculate reciprocal. | |||
| * | |||
| * @param[in] x Input value. | |||
| * | |||
| * @return The calculated reciprocal. | |||
| */ | |||
| static inline float16x4_t vinv_f16(float16x4_t x); | |||
| /** Calculate reciprocal. | |||
| * | |||
| * @param[in] x Input value. | |||
| * | |||
| * @return The calculated reciprocal. | |||
| */ | |||
| static inline float16x8_t vinvq_f16(float16x8_t x); | |||
| /** Calculate inverse square root. | |||
| * | |||
| * @param[in] x Input value. | |||
| * | |||
| * @return The calculated inverse square root. | |||
| */ | |||
| static inline float16x4_t vinvsqrt_f16(float16x4_t x); | |||
| /** Calculate inverse square root. | |||
| * | |||
| * @param[in] x Input value. | |||
| * | |||
| * @return The calculated inverse square root. | |||
| */ | |||
| static inline float16x8_t vinvsqrtq_f16(float16x8_t x); | |||
| /** Calculate exponential | |||
| * | |||
| * @param[in] x Input vector value in F16 format. | |||
| * | |||
| * @return The calculated exponent. | |||
| */ | |||
| static inline float16x8_t vexpq_f16(float16x8_t x); | |||
| /** Calculate n power of a number. | |||
| * | |||
| * pow(x,n) = e^(n*log(x)) | |||
| * | |||
| * @param[in] val Input vector value in F16 format. | |||
| * @param[in] n Powers to raise the input to. | |||
| * | |||
| * @return The calculated power. | |||
| */ | |||
| static inline float16x8_t vpowq_f16(float16x8_t val, float16x8_t n); | |||
| #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ | |||
| /** Exponent polynomial coefficients */ | |||
| extern const float32_t exp_tab[4*8]; | |||
| /** Logarithm polynomial coefficients */ | |||
| extern const float32_t log_tab[4*8]; | |||
| #ifndef DOXYGEN_SKIP_THIS | |||
| inline float32x4_t vfloorq_f32(float32x4_t val) | |||
| { | |||
| static const float32_t CONST_1[4] = {1.f,1.f,1.f,1.f}; | |||
| const int32x4_t z = vcvtq_s32_f32(val); | |||
| const float32x4_t r = vcvtq_f32_s32(z); | |||
| return vbslq_f32(vcgtq_f32(r, val), vsubq_f32(r, vld1q_f32(CONST_1)), r); | |||
| } | |||
| inline float32x2_t vinvsqrt_f32(float32x2_t x) | |||
| { | |||
| float32x2_t sqrt_reciprocal = vrsqrte_f32(x); | |||
| sqrt_reciprocal = vmul_f32(vrsqrts_f32(vmul_f32(x, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); | |||
| sqrt_reciprocal = vmul_f32(vrsqrts_f32(vmul_f32(x, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); | |||
| return sqrt_reciprocal; | |||
| } | |||
| inline float32x4_t vinvsqrtq_f32(float32x4_t x) | |||
| { | |||
| float32x4_t sqrt_reciprocal = vrsqrteq_f32(x); | |||
| sqrt_reciprocal = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); | |||
| sqrt_reciprocal = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); | |||
| return sqrt_reciprocal; | |||
| } | |||
| inline float32x2_t vinv_f32(float32x2_t x) | |||
| { | |||
| float32x2_t recip = vrecpe_f32(x); | |||
| recip = vmul_f32(vrecps_f32(x, recip), recip); | |||
| recip = vmul_f32(vrecps_f32(x, recip), recip); | |||
| return recip; | |||
| } | |||
| inline float32x4_t vinvq_f32(float32x4_t x) | |||
| { | |||
| float32x4_t recip = vrecpeq_f32(x); | |||
| recip = vmulq_f32(vrecpsq_f32(x, recip), recip); | |||
| recip = vmulq_f32(vrecpsq_f32(x, recip), recip); | |||
| return recip; | |||
| } | |||
| inline float32x4_t vtaylor_polyq_f32(float32x4_t x, const float32_t *coeffs) | |||
| { | |||
| float32x4_t A = vmlaq_f32(vld1q_f32(&coeffs[4*0]), vld1q_f32(&coeffs[4*4]), x); | |||
| float32x4_t B = vmlaq_f32(vld1q_f32(&coeffs[4*2]), vld1q_f32(&coeffs[4*6]), x); | |||
| float32x4_t C = vmlaq_f32(vld1q_f32(&coeffs[4*1]), vld1q_f32(&coeffs[4*5]), x); | |||
| float32x4_t D = vmlaq_f32(vld1q_f32(&coeffs[4*3]), vld1q_f32(&coeffs[4*7]), x); | |||
| float32x4_t x2 = vmulq_f32(x, x); | |||
| float32x4_t x4 = vmulq_f32(x2, x2); | |||
| float32x4_t res = vmlaq_f32(vmlaq_f32(A, B, x2), vmlaq_f32(C, D, x2), x4); | |||
| return res; | |||
| } | |||
| inline float32x4_t vexpq_f32(float32x4_t x) | |||
| { | |||
| static const float32_t CONST_LN2[4] = {0.6931471805f,0.6931471805f,0.6931471805f,0.6931471805f}; // ln(2) | |||
| static const float32_t CONST_INV_LN2[4] = {1.4426950408f,1.4426950408f,1.4426950408f,1.4426950408f}; // 1/ln(2) | |||
| static const float32_t CONST_0[4] = {0.f,0.f,0.f,0.f}; | |||
| static const int32_t CONST_NEGATIVE_126[4] = {-126,-126,-126,-126}; | |||
| // Perform range reduction [-log(2),log(2)] | |||
| int32x4_t m = vcvtq_s32_f32(vmulq_f32(x, vld1q_f32(CONST_INV_LN2))); | |||
| float32x4_t val = vmlsq_f32(x, vcvtq_f32_s32(m), vld1q_f32(CONST_LN2)); | |||
| // Polynomial Approximation | |||
| float32x4_t poly = vtaylor_polyq_f32(val, exp_tab); | |||
| // Reconstruct | |||
| poly = vreinterpretq_f32_s32(vqaddq_s32(vreinterpretq_s32_f32(poly), vqshlq_n_s32(m, 23))); | |||
| poly = vbslq_f32(vcltq_s32(m, vld1q_s32(CONST_NEGATIVE_126)), vld1q_f32(CONST_0), poly); | |||
| return poly; | |||
| } | |||
| inline float32x4_t vlogq_f32(float32x4_t x) | |||
| { | |||
| static const int32_t CONST_127[4] = {127,127,127,127}; // 127 | |||
| static const float32_t CONST_LN2[4] = {0.6931471805f,0.6931471805f,0.6931471805f,0.6931471805f}; // ln(2) | |||
| // Extract exponent | |||
| int32x4_t m = vsubq_s32(vreinterpretq_s32_u32(vshrq_n_u32(vreinterpretq_u32_f32(x), 23)), vld1q_s32(CONST_127)); | |||
| float32x4_t val = vreinterpretq_f32_s32(vsubq_s32(vreinterpretq_s32_f32(x), vshlq_n_s32(m, 23))); | |||
| // Polynomial Approximation | |||
| float32x4_t poly = vtaylor_polyq_f32(val, log_tab); | |||
| // Reconstruct | |||
| poly = vmlaq_f32(poly, vcvtq_f32_s32(m), vld1q_f32(CONST_LN2)); | |||
| return poly; | |||
| } | |||
| inline float32x4_t vtanhq_f32(float32x4_t val) | |||
| { | |||
| static const float32_t CONST_1[4] = {1.f,1.f,1.f,1.f}; | |||
| static const float32_t CONST_2[4] = {2.f,2.f,2.f,2.f}; | |||
| static const float32_t CONST_MIN_TANH[4] = {-10.f,-10.f,-10.f,-10.f}; | |||
| static const float32_t CONST_MAX_TANH[4] = {10.f,10.f,10.f,10.f}; | |||
| float32x4_t x = vminq_f32(vmaxq_f32(val, vld1q_f32(CONST_MIN_TANH)), vld1q_f32(CONST_MAX_TANH)); | |||
| float32x4_t exp2x = vexpq_f32(vmulq_f32(vld1q_f32(CONST_2), x)); | |||
| float32x4_t num = vsubq_f32(exp2x, vld1q_f32(CONST_1)); | |||
| float32x4_t den = vaddq_f32(exp2x, vld1q_f32(CONST_1)); | |||
| float32x4_t tanh = vmulq_f32(num, vinvq_f32(den)); | |||
| return tanh; | |||
| } | |||
| inline float32x4_t vpowq_f32(float32x4_t val, float32x4_t n) | |||
| { | |||
| return vexpq_f32(vmulq_f32(n, vlogq_f32(val))); | |||
| } | |||
| #endif /* DOXYGEN_SKIP_THIS */ | |||
| #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC | |||
| /** Exponent polynomial coefficients */ | |||
| /** Logarithm polynomial coefficients */ | |||
| #ifndef DOXYGEN_SKIP_THIS | |||
| inline float16x8_t vfloorq_f16(float16x8_t val) | |||
| { | |||
| static const float16_t CONST_1[8] = {1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f}; | |||
| const int16x8_t z = vcvtq_s16_f16(val); | |||
| const float16x8_t r = vcvtq_f16_s16(z); | |||
| return vbslq_f16(vcgtq_f16(r, val), vsubq_f16(r, vld1q_f16(CONST_1)), r); | |||
| } | |||
| inline float16x4_t vinvsqrt_f16(float16x4_t x) | |||
| { | |||
| float16x4_t sqrt_reciprocal = vrsqrte_f16(x); | |||
| sqrt_reciprocal = vmul_f16(vrsqrts_f16(vmul_f16(x, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); | |||
| sqrt_reciprocal = vmul_f16(vrsqrts_f16(vmul_f16(x, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); | |||
| return sqrt_reciprocal; | |||
| } | |||
| inline float16x8_t vinvsqrtq_f16(float16x8_t x) | |||
| { | |||
| float16x8_t sqrt_reciprocal = vrsqrteq_f16(x); | |||
| sqrt_reciprocal = vmulq_f16(vrsqrtsq_f16(vmulq_f16(x, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); | |||
| sqrt_reciprocal = vmulq_f16(vrsqrtsq_f16(vmulq_f16(x, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); | |||
| return sqrt_reciprocal; | |||
| } | |||
| inline float16x4_t vinv_f16(float16x4_t x) | |||
| { | |||
| float16x4_t recip = vrecpe_f16(x); | |||
| recip = vmul_f16(vrecps_f16(x, recip), recip); | |||
| recip = vmul_f16(vrecps_f16(x, recip), recip); | |||
| return recip; | |||
| } | |||
| inline float16x8_t vinvq_f16(float16x8_t x) | |||
| { | |||
| float16x8_t recip = vrecpeq_f16(x); | |||
| recip = vmulq_f16(vrecpsq_f16(x, recip), recip); | |||
| recip = vmulq_f16(vrecpsq_f16(x, recip), recip); | |||
| return recip; | |||
| } | |||
| inline float16x8_t vtanhq_f16(float16x8_t val) | |||
| { | |||
| const float16_t CONST_1[8] = {1.f,1.f,1.f,1.f,1.f,1.f,1.f,1.f}; | |||
| const float16_t CONST_2[8] = {2.f,2.f,2.f,2.f,2.f,2.f,2.f,2.f}; | |||
| const float16_t CONST_MIN_TANH[8] = {-10.f,-10.f,-10.f,-10.f,-10.f,-10.f,-10.f,-10.f}; | |||
| const float16_t CONST_MAX_TANH[8] = {10.f,10.f,10.f,10.f,10.f,10.f,10.f,10.f}; | |||
| const float16x8_t x = vminq_f16(vmaxq_f16(val, vld1q_f16(CONST_MIN_TANH)), vld1q_f16(CONST_MAX_TANH)); | |||
| const float16x8_t exp2x = vexpq_f16(vmulq_f16(vld1q_f16(CONST_2), x)); | |||
| const float16x8_t num = vsubq_f16(exp2x, vld1q_f16(CONST_1)); | |||
| const float16x8_t den = vaddq_f16(exp2x, vld1q_f16(CONST_1)); | |||
| const float16x8_t tanh = vmulq_f16(num, vinvq_f16(den)); | |||
| return tanh; | |||
| } | |||
| inline float16x8_t vtaylor_polyq_f16(float16x8_t x, const float16_t *coeffs) | |||
| { | |||
| const float16x8_t A = vaddq_f16(vld1q_f16(&coeffs[8*0]), vmulq_f16(vld1q_f16(&coeffs[8*4]), x)); | |||
| const float16x8_t B = vaddq_f16(vld1q_f16(&coeffs[8*2]), vmulq_f16(vld1q_f16(&coeffs[8*6]), x)); | |||
| const float16x8_t C = vaddq_f16(vld1q_f16(&coeffs[8*1]), vmulq_f16(vld1q_f16(&coeffs[8*5]), x)); | |||
| const float16x8_t D = vaddq_f16(vld1q_f16(&coeffs[8*3]), vmulq_f16(vld1q_f16(&coeffs[8*7]), x)); | |||
| const float16x8_t x2 = vmulq_f16(x, x); | |||
| const float16x8_t x4 = vmulq_f16(x2, x2); | |||
| const float16x8_t res = vaddq_f16(vaddq_f16(A, vmulq_f16(B, x2)), vmulq_f16(vaddq_f16(C, vmulq_f16(D, x2)), x4)); | |||
| return res; | |||
| } | |||
| inline float16x8_t vexpq_f16(float16x8_t x) | |||
| { | |||
| // TODO (COMPMID-1535) : Revisit FP16 approximations | |||
| const float32x4_t x_high = vcvt_f32_f16(vget_high_f16(x)); | |||
| const float32x4_t x_low = vcvt_f32_f16(vget_low_f16(x)); | |||
| const float16x8_t res = vcvt_high_f16_f32(vcvt_f16_f32(vexpq_f32(x_low)), vexpq_f32(x_high)); | |||
| return res; | |||
| } | |||
| inline float16x8_t vlogq_f16(float16x8_t x) | |||
| { | |||
| // TODO (COMPMID-1535) : Revisit FP16 approximations | |||
| const float32x4_t x_high = vcvt_f32_f16(vget_high_f16(x)); | |||
| const float32x4_t x_low = vcvt_f32_f16(vget_low_f16(x)); | |||
| const float16x8_t res = vcvt_high_f16_f32(vcvt_f16_f32(vlogq_f32(x_low)), vlogq_f32(x_high)); | |||
| return res; | |||
| } | |||
| inline float16x8_t vpowq_f16(float16x8_t val, float16x8_t n) | |||
| { | |||
| // TODO (giaiod01) - COMPMID-1535 | |||
| float32x4_t n0_f32 = vcvt_f32_f16(vget_low_f16(n)); | |||
| float32x4_t n1_f32 = vcvt_f32_f16(vget_high_f16(n)); | |||
| float32x4_t val0_f32 = vcvt_f32_f16(vget_low_f16(val)); | |||
| float32x4_t val1_f32 = vcvt_f32_f16(vget_high_f16(val)); | |||
| float32x4_t res0_f32 = vexpq_f32(vmulq_f32(n0_f32, vlogq_f32(val0_f32))); | |||
| float32x4_t res1_f32 = vexpq_f32(vmulq_f32(n1_f32, vlogq_f32(val1_f32))); | |||
| return vcombine_f16(vcvt_f16_f32(res0_f32), vcvt_f16_f32(res1_f32)); | |||
| } | |||
| #endif /* DOXYGEN_SKIP_THIS */ | |||
| #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ | |||
| #endif | |||
| #endif /* __ARM_COMPUTE_NEMATH_H__ */ | |||
| @@ -0,0 +1,21 @@ | |||
| MIT License | |||
| Copyright (c) 2017-2019 ARM Software | |||
| Permission is hereby granted, free of charge, to any person obtaining a copy | |||
| of this software and associated documentation files (the "Software"), to deal | |||
| in the Software without restriction, including without limitation the rights | |||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
| copies of the Software, and to permit persons to whom the Software is | |||
| furnished to do so, subject to the following conditions: | |||
| The above copyright notice and this permission notice shall be included in all | |||
| copies or substantial portions of the Software. | |||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
| SOFTWARE. | |||
| @@ -0,0 +1,55 @@ | |||
| /* | |||
| * Copyright (c) 2016, 2019 ARM Limited. | |||
| * | |||
| * SPDX-License-Identifier: MIT | |||
| * | |||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | |||
| * of this software and associated documentation files (the "Software"), to | |||
| * deal in the Software without restriction, including without limitation the | |||
| * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |||
| * sell copies of the Software, and to permit persons to whom the Software is | |||
| * furnished to do so, subject to the following conditions: | |||
| * | |||
| * The above copyright notice and this permission notice shall be included in all | |||
| * copies or substantial portions of the Software. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
| * SOFTWARE. | |||
| */ | |||
| #include "arm_math.h" | |||
| #include "NEMath.h" | |||
| #if defined(ARM_MATH_NEON) | |||
| /** Exponent polynomial coefficients */ | |||
| const float32_t exp_tab[4*8] = | |||
| { | |||
| 1.f,1.f,1.f,1.f, | |||
| 0.0416598916054f,0.0416598916054f,0.0416598916054f,0.0416598916054f, | |||
| 0.500000596046f,0.500000596046f,0.500000596046f,0.500000596046f, | |||
| 0.0014122662833f,0.0014122662833f,0.0014122662833f,0.0014122662833f, | |||
| 1.00000011921f,1.00000011921f,1.00000011921f,1.00000011921f, | |||
| 0.00833693705499f,0.00833693705499f,0.00833693705499f,0.00833693705499f, | |||
| 0.166665703058f,0.166665703058f,0.166665703058f,0.166665703058f, | |||
| 0.000195780929062f,0.000195780929062f,0.000195780929062f,0.000195780929062f | |||
| }; | |||
| /** Logarithm polynomial coefficients */ | |||
| const float32_t log_tab[4*8] = | |||
| { | |||
| -2.29561495781f,-2.29561495781f,-2.29561495781f,-2.29561495781f, | |||
| -2.47071170807f,-2.47071170807f,-2.47071170807f,-2.47071170807f, | |||
| -5.68692588806f,-5.68692588806f,-5.68692588806f,-5.68692588806f, | |||
| -0.165253549814f,-0.165253549814f,-0.165253549814f,-0.165253549814f, | |||
| 5.17591238022f,5.17591238022f,5.17591238022f,5.17591238022f, | |||
| 0.844007015228f,0.844007015228f,0.844007015228f,0.844007015228f, | |||
| 4.58445882797f,4.58445882797f,4.58445882797f,4.58445882797f, | |||
| 0.0141278216615f,0.0141278216615f,0.0141278216615f,0.0141278216615f | |||
| }; | |||
| #endif | |||
| @@ -0,0 +1,8 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| armcortexm0ct.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| armcortexm0ct.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| armcortexm0ct.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| armcortexm0ct.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,8 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| armcortexm3ct.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| armcortexm3ct.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| armcortexm3ct.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| armcortexm3ct.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,9 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| armcortexm4ct.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| armcortexm4ct.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| armcortexm4ct.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| armcortexm4ct.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| armcortexm4ct.vfp-present=1 # (bool , init-time) default = '1' : Set whether the model has VFP support | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,25 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| cpu0.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| cpu0.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| cpu0.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| cpu0.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| cpu0.FPU=1 # (bool , init-time) default = '1' : Set whether the model has VFP support | |||
| cpu0.MVE=2 # (int , init-time) default = '0x1' : Set whether the model has MVE support. If FPU = 0: 0=MVE not included, 1=Integer subset of MVE included. If FPU = 1: 0=MVE not included, 1=Integer subset of MVE included, 2=Integer and half and single precision floating point MVE included | |||
| cpu0.SAU=0 # (int , init-time) default = '0x8' : Number of SAU regions (0 => no SAU) | |||
| cpu0.SECEXT=0 # (bool , init-time) default = '1' : Whether the ARMv8-M Security Extensions are included | |||
| cpu0.INITSVTOR=0 # (int , init-time) default = '0x10000000' : Secure vector-table offset at reset | |||
| cpu0.INITNSVTOR=0 # (int , init-time) default = '0x0' : Non-Secure vector-table offset at reset | |||
| # | |||
| cpu1.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| cpu1.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| cpu1.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| cpu1.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| cpu1.FPU=1 # (bool , init-time) default = '1' : Set whether the model has VFP support | |||
| cpu1.MVE=2 # (int , init-time) default = '0x1' : Set whether the model has MVE support. If FPU = 0: 0=MVE not included, 1=Integer subset of MVE included. If FPU = 1: 0=MVE not included, 1=Integer subset of MVE included, 2=Integer and half and single precision floating point MVE included | |||
| cpu1.SAU=0 # (int , init-time) default = '0x8' : Number of SAU regions (0 => no SAU) | |||
| cpu1.SECEXT=0 # (bool , init-time) default = '1' : Whether the ARMv8-M Security Extensions are included | |||
| cpu1.INITSVTOR=0 # (int , init-time) default = '0x10000000' : Secure vector-table offset at reset | |||
| cpu1.INITNSVTOR=0 # (int , init-time) default = '0x0' : Non-Secure vector-table offset at reset | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,9 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| armcortexm7ct.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| armcortexm7ct.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| armcortexm7ct.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| armcortexm7ct.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| armcortexm7ct.vfp-present=1 # (bool , init-time) default = '1' : Set whether the model has VFP support | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,10 @@ | |||
| CMSIS DSP_Lib example arm_class_marks_example | |||
| The example is available for different targets: | |||
| Cortex-M0 | |||
| Cortex-M3 | |||
| Cortex-M4 with FPU | |||
| Cortex-M7 with single precision FPU | |||
| Cortex-M55 with double precision FPU, Integer + Floating Point MVE | |||
| The example is configured for Models Debugger | |||
| @@ -0,0 +1,45 @@ | |||
| cmake_minimum_required (VERSION 3.14) | |||
| project (arm_bayes_example VERSION 0.1) | |||
| # Needed to include the configBoot module | |||
| # Define the path to CMSIS-DSP (ROOT is defined on command line when using cmake) | |||
| set(ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) | |||
| set(DSP ${ROOT}/CMSIS/DSP) | |||
| # Add DSP folder to module path | |||
| list(APPEND CMAKE_MODULE_PATH ${DSP}) | |||
| ################################### | |||
| # | |||
| # LIBRARIES | |||
| # | |||
| ################################### | |||
| ########### | |||
| # | |||
| # CMSIS DSP | |||
| # | |||
| add_subdirectory(../../../Source bin_dsp) | |||
| ################################### | |||
| # | |||
| # TEST APPLICATION | |||
| # | |||
| ################################### | |||
| add_executable(arm_bayes_example) | |||
| include(config) | |||
| configApp(arm_bayes_example ${ROOT}) | |||
| target_sources(arm_bayes_example PRIVATE arm_bayes_example_f32.c) | |||
| ### Sources and libs | |||
| target_link_libraries(arm_bayes_example PRIVATE CMSISDSP) | |||
| @@ -0,0 +1,131 @@ | |||
| /****************************************************************************** | |||
| * @file startup_ARMCM0.c | |||
| * @brief CMSIS-Core(M) Device Startup File for a Cortex-M0 Device | |||
| * @version V2.0.2 | |||
| * @date 15. November 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "ARMCM0.h" | |||
| /*---------------------------------------------------------------------------- | |||
| External References | |||
| *----------------------------------------------------------------------------*/ | |||
| extern uint32_t __INITIAL_SP; | |||
| extern __NO_RETURN void __PROGRAM_START(void); | |||
| /*---------------------------------------------------------------------------- | |||
| Internal References | |||
| *----------------------------------------------------------------------------*/ | |||
| void __NO_RETURN Default_Handler(void); | |||
| void __NO_RETURN Reset_Handler (void); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| /* Exceptions */ | |||
| void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void HardFault_Handler (void) __attribute__ ((weak)); | |||
| void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt0_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt1_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt2_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt3_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt4_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt5_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt6_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt7_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt8_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt9_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpedantic" | |||
| #endif | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[48]; | |||
| const VECTOR_TABLE_Type __VECTOR_TABLE[48] __VECTOR_TABLE_ATTRIBUTE = { | |||
| (VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */ | |||
| Reset_Handler, /* Reset Handler */ | |||
| NMI_Handler, /* -14 NMI Handler */ | |||
| HardFault_Handler, /* -13 Hard Fault Handler */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| SVC_Handler, /* -5 SVCall Handler */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| PendSV_Handler, /* -2 PendSV Handler */ | |||
| SysTick_Handler, /* -1 SysTick Handler */ | |||
| /* Interrupts */ | |||
| Interrupt0_Handler, /* 0 Interrupt 0 */ | |||
| Interrupt1_Handler, /* 1 Interrupt 1 */ | |||
| Interrupt2_Handler, /* 2 Interrupt 2 */ | |||
| Interrupt3_Handler, /* 3 Interrupt 3 */ | |||
| Interrupt4_Handler, /* 4 Interrupt 4 */ | |||
| Interrupt5_Handler, /* 5 Interrupt 5 */ | |||
| Interrupt6_Handler, /* 6 Interrupt 6 */ | |||
| Interrupt7_Handler, /* 7 Interrupt 7 */ | |||
| Interrupt8_Handler, /* 8 Interrupt 8 */ | |||
| Interrupt9_Handler /* 9 Interrupt 9 */ | |||
| /* Interrupts 10..31 are left out */ | |||
| }; | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic pop | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Reset Handler called on controller reset | |||
| *----------------------------------------------------------------------------*/ | |||
| __NO_RETURN void Reset_Handler(void) | |||
| { | |||
| SystemInit(); /* CMSIS System Initialization */ | |||
| __PROGRAM_START(); /* Enter PreMain (C library entry point) */ | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Hard Fault Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| void HardFault_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Default Handler for Exceptions / Interrupts | |||
| *----------------------------------------------------------------------------*/ | |||
| void Default_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| @@ -0,0 +1,56 @@ | |||
| /**************************************************************************//** | |||
| * @file system_ARMCM0.c | |||
| * @brief CMSIS Device System Source File for | |||
| * ARMCM0 Device | |||
| * @version V5.3.1 | |||
| * @date 09. July 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "ARMCM0.h" | |||
| /*---------------------------------------------------------------------------- | |||
| Define clocks | |||
| *----------------------------------------------------------------------------*/ | |||
| #define XTAL (50000000UL) /* Oscillator frequency */ | |||
| #define SYSTEM_CLOCK (XTAL / 2U) | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock Variable | |||
| *----------------------------------------------------------------------------*/ | |||
| uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock update function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemCoreClockUpdate (void) | |||
| { | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| System initialization function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemInit (void) | |||
| { | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| @@ -0,0 +1,135 @@ | |||
| /****************************************************************************** | |||
| * @file startup_ARMCM3.c | |||
| * @brief CMSIS-Core(M) Device Startup File for a Cortex-M3 Device | |||
| * @version V2.0.2 | |||
| * @date 15. November 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "ARMCM3.h" | |||
| /*---------------------------------------------------------------------------- | |||
| External References | |||
| *----------------------------------------------------------------------------*/ | |||
| extern uint32_t __INITIAL_SP; | |||
| extern __NO_RETURN void __PROGRAM_START(void) ; | |||
| /*---------------------------------------------------------------------------- | |||
| Internal References | |||
| *----------------------------------------------------------------------------*/ | |||
| __NO_RETURN void Default_Handler(void); | |||
| __NO_RETURN void Reset_Handler (void); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| /* Exceptions */ | |||
| void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void HardFault_Handler (void) __attribute__ ((weak)); | |||
| void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt0_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt1_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt2_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt3_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt4_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt5_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt6_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt7_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt8_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt9_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpedantic" | |||
| #endif | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[240]; | |||
| const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = { | |||
| (VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */ | |||
| Reset_Handler, /* Reset Handler */ | |||
| NMI_Handler, /* -14 NMI Handler */ | |||
| HardFault_Handler, /* -13 Hard Fault Handler */ | |||
| MemManage_Handler, /* -12 MPU Fault Handler */ | |||
| BusFault_Handler, /* -11 Bus Fault Handler */ | |||
| UsageFault_Handler, /* -10 Usage Fault Handler */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| SVC_Handler, /* -5 SVCall Handler */ | |||
| DebugMon_Handler, /* -4 Debug Monitor Handler */ | |||
| 0, /* Reserved */ | |||
| PendSV_Handler, /* -2 PendSV Handler */ | |||
| SysTick_Handler, /* -1 SysTick Handler */ | |||
| /* Interrupts */ | |||
| Interrupt0_Handler, /* 0 Interrupt 0 */ | |||
| Interrupt1_Handler, /* 1 Interrupt 1 */ | |||
| Interrupt2_Handler, /* 2 Interrupt 2 */ | |||
| Interrupt3_Handler, /* 3 Interrupt 3 */ | |||
| Interrupt4_Handler, /* 4 Interrupt 4 */ | |||
| Interrupt5_Handler, /* 5 Interrupt 5 */ | |||
| Interrupt6_Handler, /* 6 Interrupt 6 */ | |||
| Interrupt7_Handler, /* 7 Interrupt 7 */ | |||
| Interrupt8_Handler, /* 8 Interrupt 8 */ | |||
| Interrupt9_Handler /* 9 Interrupt 9 */ | |||
| /* Interrupts 10 .. 223 are left out */ | |||
| }; | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic pop | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Reset Handler called on controller reset | |||
| *----------------------------------------------------------------------------*/ | |||
| void Reset_Handler(void) | |||
| { | |||
| SystemInit(); /* CMSIS System Initialization */ | |||
| __PROGRAM_START(); /* Enter PreMain (C library entry point) */ | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Hard Fault Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| __NO_RETURN void HardFault_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Default Handler for Exceptions / Interrupts | |||
| *----------------------------------------------------------------------------*/ | |||
| void Default_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| @@ -0,0 +1,65 @@ | |||
| /**************************************************************************//** | |||
| * @file system_ARMCM3.c | |||
| * @brief CMSIS Device System Source File for | |||
| * ARMCM3 Device | |||
| * @version V1.0.1 | |||
| * @date 15. November 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "ARMCM3.h" | |||
| /*---------------------------------------------------------------------------- | |||
| Define clocks | |||
| *----------------------------------------------------------------------------*/ | |||
| #define XTAL (50000000UL) /* Oscillator frequency */ | |||
| #define SYSTEM_CLOCK (XTAL / 2U) | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[240]; | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock Variable | |||
| *----------------------------------------------------------------------------*/ | |||
| uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock update function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemCoreClockUpdate (void) | |||
| { | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| System initialization function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemInit (void) | |||
| { | |||
| #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) | |||
| SCB->VTOR = (uint32_t) &(__VECTOR_TABLE[0]); | |||
| #endif | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| @@ -0,0 +1,141 @@ | |||
| /****************************************************************************** | |||
| * @file startup_ARMCM4.c | |||
| * @brief CMSIS-Core(M) Device Startup File for a Cortex-M4 Device | |||
| * @version V2.0.2 | |||
| * @date 15. November 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined (ARMCM4) | |||
| #include "ARMCM4.h" | |||
| #elif defined (ARMCM4_FP) | |||
| #include "ARMCM4_FP.h" | |||
| #else | |||
| #error device not specified! | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| External References | |||
| *----------------------------------------------------------------------------*/ | |||
| extern uint32_t __INITIAL_SP; | |||
| extern __NO_RETURN void __PROGRAM_START(void); | |||
| /*---------------------------------------------------------------------------- | |||
| Internal References | |||
| *----------------------------------------------------------------------------*/ | |||
| void __NO_RETURN Default_Handler(void); | |||
| void __NO_RETURN Reset_Handler (void); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| /* Exceptions */ | |||
| void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void HardFault_Handler (void) __attribute__ ((weak)); | |||
| void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt0_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt1_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt2_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt3_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt4_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt5_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt6_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt7_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt8_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt9_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpedantic" | |||
| #endif | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[240]; | |||
| const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = { | |||
| (VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */ | |||
| Reset_Handler, /* Reset Handler */ | |||
| NMI_Handler, /* -14 NMI Handler */ | |||
| HardFault_Handler, /* -13 Hard Fault Handler */ | |||
| MemManage_Handler, /* -12 MPU Fault Handler */ | |||
| BusFault_Handler, /* -11 Bus Fault Handler */ | |||
| UsageFault_Handler, /* -10 Usage Fault Handler */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| SVC_Handler, /* -5 SVCall Handler */ | |||
| DebugMon_Handler, /* -4 Debug Monitor Handler */ | |||
| 0, /* Reserved */ | |||
| PendSV_Handler, /* -2 PendSV Handler */ | |||
| SysTick_Handler, /* -1 SysTick Handler */ | |||
| /* Interrupts */ | |||
| Interrupt0_Handler, /* 0 Interrupt 0 */ | |||
| Interrupt1_Handler, /* 1 Interrupt 1 */ | |||
| Interrupt2_Handler, /* 2 Interrupt 2 */ | |||
| Interrupt3_Handler, /* 3 Interrupt 3 */ | |||
| Interrupt4_Handler, /* 4 Interrupt 4 */ | |||
| Interrupt5_Handler, /* 5 Interrupt 5 */ | |||
| Interrupt6_Handler, /* 6 Interrupt 6 */ | |||
| Interrupt7_Handler, /* 7 Interrupt 7 */ | |||
| Interrupt8_Handler, /* 8 Interrupt 8 */ | |||
| Interrupt9_Handler /* 9 Interrupt 9 */ | |||
| /* Interrupts 10 .. 223 are left out */ | |||
| }; | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic pop | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Reset Handler called on controller reset | |||
| *----------------------------------------------------------------------------*/ | |||
| void Reset_Handler(void) | |||
| { | |||
| SystemInit(); /* CMSIS System Initialization */ | |||
| __PROGRAM_START(); /* Enter PreMain (C library entry point) */ | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Hard Fault Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| __NO_RETURN void HardFault_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Default Handler for Exceptions / Interrupts | |||
| *----------------------------------------------------------------------------*/ | |||
| void Default_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| @@ -0,0 +1,81 @@ | |||
| /**************************************************************************//** | |||
| * @file system_ARMCM4.c | |||
| * @brief CMSIS Device System Source File for | |||
| * ARMCM4 Device | |||
| * @version V1.0.1 | |||
| * @date 15. November 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined (ARMCM4) | |||
| #include "ARMCM4.h" | |||
| #elif defined (ARMCM4_FP) | |||
| #include "ARMCM4_FP.h" | |||
| #else | |||
| #error device not specified! | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Define clocks | |||
| *----------------------------------------------------------------------------*/ | |||
| #define XTAL (50000000UL) /* Oscillator frequency */ | |||
| #define SYSTEM_CLOCK (XTAL / 2U) | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[240]; | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock Variable | |||
| *----------------------------------------------------------------------------*/ | |||
| uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock update function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemCoreClockUpdate (void) | |||
| { | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| System initialization function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemInit (void) | |||
| { | |||
| #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) | |||
| SCB->VTOR = (uint32_t) &(__VECTOR_TABLE[0]); | |||
| #endif | |||
| #if defined (__FPU_USED) && (__FPU_USED == 1U) | |||
| SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ | |||
| (3U << 11U*2U) ); /* enable CP11 Full Access */ | |||
| #endif | |||
| #ifdef UNALIGNED_SUPPORT_DISABLE | |||
| SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; | |||
| #endif | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| @@ -0,0 +1,154 @@ | |||
| /****************************************************************************** | |||
| * @file startup_ARMCM55.c | |||
| * @brief CMSIS Core Device Startup File for ARMCM55 Device | |||
| * @version V1.0.0 | |||
| * @date 31. March 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined (ARMCM55) | |||
| #include "ARMCM55.h" | |||
| #else | |||
| #error device not specified! | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| External References | |||
| *----------------------------------------------------------------------------*/ | |||
| extern uint32_t __INITIAL_SP; | |||
| extern uint32_t __STACK_LIMIT; | |||
| extern __NO_RETURN void __PROGRAM_START(void); | |||
| /*---------------------------------------------------------------------------- | |||
| Internal References | |||
| *----------------------------------------------------------------------------*/ | |||
| __NO_RETURN void Reset_Handler (void); | |||
| void Default_Handler(void); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| /* Exceptions */ | |||
| void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void HardFault_Handler (void) __attribute__ ((weak)); | |||
| void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SecureFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt0_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt1_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt2_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt3_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt4_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt5_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt6_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt7_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt8_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt9_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpedantic" | |||
| #endif | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[496]; | |||
| const VECTOR_TABLE_Type __VECTOR_TABLE[496] __VECTOR_TABLE_ATTRIBUTE = { | |||
| (VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */ | |||
| Reset_Handler, /* Reset Handler */ | |||
| NMI_Handler, /* -14 NMI Handler */ | |||
| HardFault_Handler, /* -13 Hard Fault Handler */ | |||
| MemManage_Handler, /* -12 MPU Fault Handler */ | |||
| BusFault_Handler, /* -11 Bus Fault Handler */ | |||
| UsageFault_Handler, /* -10 Usage Fault Handler */ | |||
| SecureFault_Handler, /* -9 Secure Fault Handler */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| SVC_Handler, /* -5 SVCall Handler */ | |||
| DebugMon_Handler, /* -4 Debug Monitor Handler */ | |||
| 0, /* Reserved */ | |||
| PendSV_Handler, /* -2 PendSV Handler */ | |||
| SysTick_Handler, /* -1 SysTick Handler */ | |||
| /* Interrupts */ | |||
| Interrupt0_Handler, /* 0 Interrupt 0 */ | |||
| Interrupt1_Handler, /* 1 Interrupt 1 */ | |||
| Interrupt2_Handler, /* 2 Interrupt 2 */ | |||
| Interrupt3_Handler, /* 3 Interrupt 3 */ | |||
| Interrupt4_Handler, /* 4 Interrupt 4 */ | |||
| Interrupt5_Handler, /* 5 Interrupt 5 */ | |||
| Interrupt6_Handler, /* 6 Interrupt 6 */ | |||
| Interrupt7_Handler, /* 7 Interrupt 7 */ | |||
| Interrupt8_Handler, /* 8 Interrupt 8 */ | |||
| Interrupt9_Handler /* 9 Interrupt 9 */ | |||
| /* Interrupts 10 .. 480 are left out */ | |||
| }; | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic pop | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Reset Handler called on controller reset | |||
| *----------------------------------------------------------------------------*/ | |||
| __NO_RETURN void Reset_Handler(void) | |||
| { | |||
| __set_MSPLIM((uint32_t)(&__STACK_LIMIT)); | |||
| SystemInit(); /* CMSIS System Initialization */ | |||
| __PROGRAM_START(); /* Enter PreMain (C library entry point) */ | |||
| } | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) | |||
| #pragma clang diagnostic push | |||
| #pragma clang diagnostic ignored "-Wmissing-noreturn" | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Hard Fault Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| void HardFault_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Default Handler for Exceptions / Interrupts | |||
| *----------------------------------------------------------------------------*/ | |||
| void Default_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) | |||
| #pragma clang diagnostic pop | |||
| #endif | |||
| @@ -0,0 +1,90 @@ | |||
| /**************************************************************************//** | |||
| * @file system_ARMCM55.c | |||
| * @brief CMSIS Device System Source File for | |||
| * ARMCM55 Device | |||
| * @version V1.0.0 | |||
| * @date 23. March 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined (ARMCM55) | |||
| #include "ARMCM55.h" | |||
| #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) | |||
| #include "partition_ARMCM55.h" | |||
| #endif | |||
| #else | |||
| #error device not specified! | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Define clocks | |||
| *----------------------------------------------------------------------------*/ | |||
| #define XTAL ( 5000000UL) /* Oscillator frequency */ | |||
| #define SYSTEM_CLOCK (5U * XTAL) | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[496]; | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock Variable | |||
| *----------------------------------------------------------------------------*/ | |||
| uint32_t SystemCoreClock = SYSTEM_CLOCK; | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock update function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemCoreClockUpdate (void) | |||
| { | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| System initialization function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemInit (void) | |||
| { | |||
| #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) | |||
| SCB->VTOR = (uint32_t)(&__VECTOR_TABLE[0]); | |||
| #endif | |||
| #if (defined (__FPU_USED) && (__FPU_USED == 1U)) || \ | |||
| (defined (__ARM_FEATURE_MVE) && (__ARM_FEATURE_MVE > 0U)) | |||
| SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ | |||
| (3U << 11U*2U) ); /* enable CP11 Full Access */ | |||
| #endif | |||
| #ifdef UNALIGNED_SUPPORT_DISABLE | |||
| SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; | |||
| #endif | |||
| #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) | |||
| TZ_SAU_Setup(); | |||
| #endif | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| @@ -0,0 +1,143 @@ | |||
| /****************************************************************************** | |||
| * @file startup_ARMCM7.c | |||
| * @brief CMSIS-Core(M) Device Startup File for a Cortex-M7 Device | |||
| * @version V2.0.2 | |||
| * @date 15. November 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined (ARMCM7) | |||
| #include "ARMCM7.h" | |||
| #elif defined (ARMCM7_SP) | |||
| #include "ARMCM7_SP.h" | |||
| #elif defined (ARMCM7_DP) | |||
| #include "ARMCM7_DP.h" | |||
| #else | |||
| #error device not specified! | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| External References | |||
| *----------------------------------------------------------------------------*/ | |||
| extern uint32_t __INITIAL_SP; | |||
| extern __NO_RETURN void __PROGRAM_START(void); | |||
| /*---------------------------------------------------------------------------- | |||
| Internal References | |||
| *----------------------------------------------------------------------------*/ | |||
| void __NO_RETURN Default_Handler(void); | |||
| void __NO_RETURN Reset_Handler (void); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| /* Exceptions */ | |||
| void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void HardFault_Handler (void) __attribute__ ((weak)); | |||
| void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt0_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt1_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt2_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt3_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt4_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt5_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt6_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt7_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt8_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| void Interrupt9_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic push | |||
| #pragma GCC diagnostic ignored "-Wpedantic" | |||
| #endif | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[240]; | |||
| const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = { | |||
| (VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */ | |||
| Reset_Handler, /* Reset Handler */ | |||
| NMI_Handler, /* -14 NMI Handler */ | |||
| HardFault_Handler, /* -13 Hard Fault Handler */ | |||
| MemManage_Handler, /* -12 MPU Fault Handler */ | |||
| BusFault_Handler, /* -11 Bus Fault Handler */ | |||
| UsageFault_Handler, /* -10 Usage Fault Handler */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| 0, /* Reserved */ | |||
| SVC_Handler, /* -5 SVCall Handler */ | |||
| DebugMon_Handler, /* -4 Debug Monitor Handler */ | |||
| 0, /* Reserved */ | |||
| PendSV_Handler, /* -2 PendSV Handler */ | |||
| SysTick_Handler, /* -1 SysTick Handler */ | |||
| /* Interrupts */ | |||
| Interrupt0_Handler, /* 0 Interrupt 0 */ | |||
| Interrupt1_Handler, /* 1 Interrupt 1 */ | |||
| Interrupt2_Handler, /* 2 Interrupt 2 */ | |||
| Interrupt3_Handler, /* 3 Interrupt 3 */ | |||
| Interrupt4_Handler, /* 4 Interrupt 4 */ | |||
| Interrupt5_Handler, /* 5 Interrupt 5 */ | |||
| Interrupt6_Handler, /* 6 Interrupt 6 */ | |||
| Interrupt7_Handler, /* 7 Interrupt 7 */ | |||
| Interrupt8_Handler, /* 8 Interrupt 8 */ | |||
| Interrupt9_Handler /* 9 Interrupt 9 */ | |||
| /* Interrupts 10 .. 223 are left out */ | |||
| }; | |||
| #if defined ( __GNUC__ ) | |||
| #pragma GCC diagnostic pop | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Reset Handler called on controller reset | |||
| *----------------------------------------------------------------------------*/ | |||
| void Reset_Handler(void) | |||
| { | |||
| SystemInit(); /* CMSIS System Initialization */ | |||
| __PROGRAM_START(); /* Enter PreMain (C library entry point) */ | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Hard Fault Handler | |||
| *----------------------------------------------------------------------------*/ | |||
| __NO_RETURN void HardFault_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| Default Handler for Exceptions / Interrupts | |||
| *----------------------------------------------------------------------------*/ | |||
| void Default_Handler(void) | |||
| { | |||
| while(1); | |||
| } | |||
| @@ -0,0 +1,83 @@ | |||
| /**************************************************************************//** | |||
| * @file system_ARMCM7.c | |||
| * @brief CMSIS Device System Source File for | |||
| * ARMCM7 Device | |||
| * @version V1.0.1 | |||
| * @date 15. November 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined (ARMCM7) | |||
| #include "ARMCM7.h" | |||
| #elif defined (ARMCM7_SP) | |||
| #include "ARMCM7_SP.h" | |||
| #elif defined (ARMCM7_DP) | |||
| #include "ARMCM7_DP.h" | |||
| #else | |||
| #error device not specified! | |||
| #endif | |||
| /*---------------------------------------------------------------------------- | |||
| Define clocks | |||
| *----------------------------------------------------------------------------*/ | |||
| #define XTAL (50000000UL) /* Oscillator frequency */ | |||
| #define SYSTEM_CLOCK (XTAL / 2U) | |||
| /*---------------------------------------------------------------------------- | |||
| Exception / Interrupt Vector table | |||
| *----------------------------------------------------------------------------*/ | |||
| extern const VECTOR_TABLE_Type __VECTOR_TABLE[240]; | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock Variable | |||
| *----------------------------------------------------------------------------*/ | |||
| uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ | |||
| /*---------------------------------------------------------------------------- | |||
| System Core Clock update function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemCoreClockUpdate (void) | |||
| { | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| /*---------------------------------------------------------------------------- | |||
| System initialization function | |||
| *----------------------------------------------------------------------------*/ | |||
| void SystemInit (void) | |||
| { | |||
| #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) | |||
| SCB->VTOR = (uint32_t) &(__VECTOR_TABLE[0]); | |||
| #endif | |||
| #if defined (__FPU_USED) && (__FPU_USED == 1U) | |||
| SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ | |||
| (3U << 11U*2U) ); /* enable CP11 Full Access */ | |||
| #endif | |||
| #ifdef UNALIGNED_SUPPORT_DISABLE | |||
| SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; | |||
| #endif | |||
| SystemCoreClock = SYSTEM_CLOCK; | |||
| } | |||
| @@ -0,0 +1,145 @@ | |||
| /* ---------------------------------------------------------------------- | |||
| * Copyright (C) 2019-2020 ARM Limited. All rights reserved. | |||
| * | |||
| * $Date: 09. December 2019 | |||
| * $Revision: V1.0.0 | |||
| * | |||
| * Project: CMSIS DSP Library | |||
| * Title: arm_bayes_example_f32.c | |||
| * | |||
| * Description: Example code demonstrating how to use Bayes functions. | |||
| * | |||
| * Target Processor: Cortex-M/Cortex-A | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * - Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * - 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. | |||
| * - Neither the name of ARM LIMITED 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 OWNER 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. | |||
| * -------------------------------------------------------------------- */ | |||
| /** | |||
| * @ingroup groupExamples | |||
| */ | |||
| /** | |||
| * @defgroup BayesExample Bayes Example | |||
| * | |||
| * \par Description: | |||
| * \par | |||
| * Demonstrates the use of Bayesian classifier functions. It is complementing the tutorial | |||
| * about classical ML with CMSIS-DSP and python scikit-learn: | |||
| * https://developer.arm.com/solutions/machine-learning-on-arm/developer-material/how-to-guides/implement-classical-ml-with-arm-cmsis-dsp-libraries | |||
| * | |||
| */ | |||
| /** \example arm_bayes_example_f32.c | |||
| */ | |||
| #include <math.h> | |||
| #include <stdio.h> | |||
| #include "arm_math.h" | |||
| /* | |||
| Those parameters can be generated with the python library scikit-learn. | |||
| */ | |||
| arm_gaussian_naive_bayes_instance_f32 S; | |||
| #define NB_OF_CLASSES 3 | |||
| #define VECTOR_DIMENSION 2 | |||
| const float32_t theta[NB_OF_CLASSES*VECTOR_DIMENSION] = { | |||
| 1.4539529436590528f, 0.8722776016801852f, | |||
| -1.5267934452462473f, 0.903204577814203f, | |||
| -0.15338006360932258f, -2.9997913665803964f | |||
| }; /**< Mean values for the Gaussians */ | |||
| const float32_t sigma[NB_OF_CLASSES*VECTOR_DIMENSION] = { | |||
| 1.0063470889514925f, 0.9038018246524426f, | |||
| 1.0224479953244736f, 0.7768764290432544f, | |||
| 1.1217662403241206f, 1.2303890106020325f | |||
| }; /**< Variances for the Gaussians */ | |||
| const float32_t classPriors[NB_OF_CLASSES] = { | |||
| 0.3333333333333333f, 0.3333333333333333f, 0.3333333333333333f | |||
| }; /**< Class prior probabilities */ | |||
| int32_t main(void) | |||
| { | |||
| /* Array of input data */ | |||
| float32_t in[2]; | |||
| /* Result of the classifier */ | |||
| float32_t result[NB_OF_CLASSES]; | |||
| float32_t temp[NB_OF_CLASSES]; | |||
| float32_t maxProba; | |||
| uint32_t index; | |||
| S.vectorDimension = VECTOR_DIMENSION; | |||
| S.numberOfClasses = NB_OF_CLASSES; | |||
| S.theta = theta; | |||
| S.sigma = sigma; | |||
| S.classPriors = classPriors; | |||
| S.epsilon=4.328939296523643e-09f; | |||
| in[0] = 1.5f; | |||
| in[1] = 1.0f; | |||
| index = arm_gaussian_naive_bayes_predict_f32(&S, in, result,temp); | |||
| maxProba = result[index]; | |||
| #if defined(SEMIHOSTING) | |||
| printf("Class = %d\n", index); | |||
| #endif | |||
| in[0] = -1.5f; | |||
| in[1] = 1.0f; | |||
| index = arm_gaussian_naive_bayes_predict_f32(&S, in, result,temp); | |||
| maxProba = result[index]; | |||
| #if defined(SEMIHOSTING) | |||
| printf("Class = %d\n", index); | |||
| #endif | |||
| in[0] = 0.0f; | |||
| in[1] = -3.0f; | |||
| index = arm_gaussian_naive_bayes_predict_f32(&S, in, result,temp); | |||
| maxProba = result[index]; | |||
| #if defined(SEMIHOSTING) | |||
| printf("Class = %d\n", index); | |||
| #endif | |||
| #if !defined(SEMIHOSTING) | |||
| while (1); /* main function does not return */ | |||
| #endif | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| armcortexm0ct.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| armcortexm0ct.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| armcortexm0ct.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| armcortexm0ct.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,8 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| armcortexm3ct.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| armcortexm3ct.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| armcortexm3ct.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| armcortexm3ct.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,9 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| armcortexm4ct.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| armcortexm4ct.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| armcortexm4ct.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| armcortexm4ct.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| armcortexm4ct.vfp-present=1 # (bool , init-time) default = '1' : Set whether the model has VFP support | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,25 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| cpu0.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| cpu0.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| cpu0.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| cpu0.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| cpu0.FPU=1 # (bool , init-time) default = '1' : Set whether the model has VFP support | |||
| cpu0.MVE=2 # (int , init-time) default = '0x1' : Set whether the model has MVE support. If FPU = 0: 0=MVE not included, 1=Integer subset of MVE included. If FPU = 1: 0=MVE not included, 1=Integer subset of MVE included, 2=Integer and half and single precision floating point MVE included | |||
| cpu0.SAU=0 # (int , init-time) default = '0x8' : Number of SAU regions (0 => no SAU) | |||
| cpu0.SECEXT=0 # (bool , init-time) default = '1' : Whether the ARMv8-M Security Extensions are included | |||
| cpu0.INITSVTOR=0 # (int , init-time) default = '0x10000000' : Secure vector-table offset at reset | |||
| cpu0.INITNSVTOR=0 # (int , init-time) default = '0x0' : Non-Secure vector-table offset at reset | |||
| # | |||
| cpu1.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| cpu1.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| cpu1.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| cpu1.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| cpu1.FPU=1 # (bool , init-time) default = '1' : Set whether the model has VFP support | |||
| cpu1.MVE=2 # (int , init-time) default = '0x1' : Set whether the model has MVE support. If FPU = 0: 0=MVE not included, 1=Integer subset of MVE included. If FPU = 1: 0=MVE not included, 1=Integer subset of MVE included, 2=Integer and half and single precision floating point MVE included | |||
| cpu1.SAU=0 # (int , init-time) default = '0x8' : Number of SAU regions (0 => no SAU) | |||
| cpu1.SECEXT=0 # (bool , init-time) default = '1' : Whether the ARMv8-M Security Extensions are included | |||
| cpu1.INITSVTOR=0 # (int , init-time) default = '0x10000000' : Secure vector-table offset at reset | |||
| cpu1.INITNSVTOR=0 # (int , init-time) default = '0x0' : Non-Secure vector-table offset at reset | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,9 @@ | |||
| # Parameters: | |||
| # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max] | |||
| #------------------------------------------------------------------------------ | |||
| armcortexm7ct.semihosting-enable=0 # (bool , init-time) default = '1' : Enable semihosting SVC traps. Applications that do not use semihosting must set this parameter to false. | |||
| armcortexm7ct.cpi_div=1 # (int , run-time ) default = '0x1' : divider for calculating CPI (Cycles Per Instruction) | |||
| armcortexm7ct.cpi_mul=1 # (int , run-time ) default = '0x1' : multiplier for calculating CPI (Cycles Per Instruction) | |||
| armcortexm7ct.min_sync_level=3 # (int , run-time ) default = '0x0' : force minimum syncLevel (0=off=default,1=syncState,2=postInsnIO,3=postInsnAll) | |||
| armcortexm7ct.vfp-present=1 # (bool , init-time) default = '1' : Set whether the model has VFP support | |||
| #------------------------------------------------------------------------------ | |||
| @@ -0,0 +1,10 @@ | |||
| CMSIS DSP_Lib example arm_class_marks_example | |||
| The example is available for different targets: | |||
| Cortex-M0 | |||
| Cortex-M3 | |||
| Cortex-M4 with FPU | |||
| Cortex-M7 with single precision FPU | |||
| Cortex-M55 with double precision FPU, Integer + Floating Point MVE | |||
| The example is configured for Models Debugger | |||