├── Core
├── Inc
│ ├── Scales.h
│ ├── gpio.h
│ ├── usart.h
│ ├── tim.h
│ ├── ModbusConfig.h
│ ├── stm32f4xx_it.h
│ ├── main.h
│ ├── Ramps.h
│ ├── FreeRTOSConfig.h
│ └── Modbus.h
└── Src
│ ├── Scales.c
│ ├── gpio.c
│ ├── stm32f4xx_hal_msp.c
│ ├── sysmem.c
│ ├── syscalls.c
│ ├── usart.c
│ ├── freertos.c
│ ├── UARTCallback.c
│ ├── stm32f4xx_hal_timebase_tim.c
│ ├── stm32f4xx_it.c
│ └── main.c
├── raspberry.cfg
├── Drivers
├── CMSIS
│ ├── Device
│ │ └── ST
│ │ │ └── STM32F4xx
│ │ │ ├── LICENSE.txt
│ │ │ └── Include
│ │ │ └── system_stm32f4xx.h
│ └── Include
│ │ ├── cmsis_version.h
│ │ ├── tz_context.h
│ │ └── cmsis_compiler.h
└── STM32F4xx_HAL_Driver
│ ├── LICENSE.txt
│ ├── Inc
│ ├── stm32f4xx_hal_flash_ramfunc.h
│ ├── stm32f4xx_hal_dma_ex.h
│ └── stm32f4xx_hal_def.h
│ └── Src
│ └── stm32f4xx_hal_flash_ramfunc.c
├── st_nucleo_f4.cfg
├── Middlewares
└── Third_Party
│ └── FreeRTOS
│ └── Source
│ ├── LICENSE
│ ├── CMSIS_RTOS_V2
│ └── freertos_mpool.h
│ ├── include
│ ├── projdefs.h
│ ├── stack_macros.h
│ ├── StackMacros.h
│ ├── deprecated_definitions.h
│ ├── portable.h
│ └── mpu_wrappers.h
│ ├── list.c
│ └── portable
│ └── GCC
│ └── ARM_CM4F
│ └── portmacro.h
├── .project
├── .github
└── workflows
│ └── release.yaml
├── CMakeLists_template.txt
├── CMakeLists.txt
├── README.md
├── .gitignore
├── STM32F411CEUX_RAM.ld
├── STM32F411CEUX_FLASH.ld
└── rotary-controller-f4.ioc
/Core/Inc/Scales.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by stefano on 12/30/22.
3 | //
4 |
5 | #ifndef ROTARY_CONTROLLER_F4_SCALES_H
6 | #define ROTARY_CONTROLLER_F4_SCALES_H
7 | #include "stm32f4xx_hal.h"
8 |
9 | #define SCALES_COUNT 4
10 |
11 | HAL_StatusTypeDef initScaleTimer(TIM_HandleTypeDef * timHandle);
12 | #endif //ROTARY_CONTROLLER_F4_SCALES_H
13 |
--------------------------------------------------------------------------------
/raspberry.cfg:
--------------------------------------------------------------------------------
1 | source [find interface/raspberrypi2-native.cfg]
2 |
3 | adapter gpio swclk -chip 0 25
4 | adapter gpio swdio -chip 0 24
5 |
6 | transport select swd
7 |
8 | source [find target/stm32f4x.cfg]
9 |
10 | program ./rotary-controller-f4.elf verify reset
11 |
12 | sleep 1000
13 | reset run
14 | sleep 1000
15 | reset run
16 | sleep 1000
17 | shutdown
18 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Device/ST/STM32F4xx/LICENSE.txt:
--------------------------------------------------------------------------------
1 | This software component is provided to you as part of a software package and
2 | applicable license terms are in the Package_license file. If you received this
3 | software component outside of a package or without applicable license terms,
4 | the terms of the Apache-2.0 license shall apply.
5 | You may obtain a copy of the Apache-2.0 at:
6 | https://opensource.org/licenses/Apache-2.0
7 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/LICENSE.txt:
--------------------------------------------------------------------------------
1 | This software component is provided to you as part of a software package and
2 | applicable license terms are in the Package_license file. If you received this
3 | software component outside of a package or without applicable license terms,
4 | the terms of the BSD-3-Clause license shall apply.
5 | You may obtain a copy of the BSD-3-Clause at:
6 | https://opensource.org/licenses/BSD-3-Clause
7 |
--------------------------------------------------------------------------------
/st_nucleo_f4.cfg:
--------------------------------------------------------------------------------
1 | # This is for all ST NUCLEO with any STM32F4. Known boards at the moment:
2 | # STM32F401RET6
3 | # http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260000
4 | # STM32F411RET6
5 | # http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260320
6 |
7 | source [find interface/stlink.cfg]
8 |
9 | transport select hla_swd
10 |
11 | source [find target/stm32f4x.cfg]
12 |
13 | #reset_config srst_only
14 |
15 | reset_config none separate
16 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 | Permission is hereby granted, free of charge, to any person obtaining a copy of
3 | this software and associated documentation files (the "Software"), to deal in
4 | the Software without restriction, including without limitation the rights to
5 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
6 | the Software, and to permit persons to whom the Software is furnished to do so,
7 | subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all
10 | copies or substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
14 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 |
19 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | rotary-controller-f4
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | com.st.stm32cube.ide.mcu.MCUProjectNature
23 | org.eclipse.cdt.core.cnature
24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature
25 | com.st.stm32cube.ide.mcu.MCUCubeProjectNature
26 | com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature
27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature
28 | com.st.stm32cube.ide.mcu.MCURootProjectNature
29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Core/Src/Scales.c:
--------------------------------------------------------------------------------
1 | //
2 | // Created by stefano on 12/30/22.
3 | //
4 | #include "Scales.h"
5 |
6 | HAL_StatusTypeDef initScaleTimer(TIM_HandleTypeDef * timHandle)
7 | {
8 | TIM_Encoder_InitTypeDef sConfig = {0};
9 | TIM_MasterConfigTypeDef sMasterConfig = {0};
10 |
11 | timHandle->Init.Prescaler = 0;
12 | timHandle->Init.CounterMode = TIM_COUNTERMODE_UP;
13 | timHandle->Init.Period = 65535;
14 | timHandle->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
15 | timHandle->Init.RepetitionCounter = 0;
16 | timHandle->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
17 | sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
18 | sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
19 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
20 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
21 | sConfig.IC1Filter = 0;
22 | sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
23 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
24 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
25 | sConfig.IC2Filter = 0;
26 |
27 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_ENABLE;
28 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
29 |
30 | HAL_StatusTypeDef result = HAL_TIM_Encoder_Init(timHandle, &sConfig);
31 | if (result != HAL_OK) {
32 | return result;
33 | }
34 |
35 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
36 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
37 |
38 | result = HAL_TIMEx_MasterConfigSynchronization(timHandle, &sMasterConfig);
39 | return result;
40 | }
41 |
--------------------------------------------------------------------------------
/Core/Inc/gpio.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file gpio.h
5 | * @brief This file contains all the function prototypes for
6 | * the gpio.c file
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * Copyright (c) 2022 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software is licensed under terms that can be found in the LICENSE file
14 | * in the root directory of this software component.
15 | * If no LICENSE file comes with this software, it is provided AS-IS.
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __GPIO_H__
22 | #define __GPIO_H__
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "main.h"
30 |
31 | /* USER CODE BEGIN Includes */
32 |
33 | /* USER CODE END Includes */
34 |
35 | /* USER CODE BEGIN Private defines */
36 |
37 | /* USER CODE END Private defines */
38 |
39 | void MX_GPIO_Init(void);
40 |
41 | /* USER CODE BEGIN Prototypes */
42 |
43 | /* USER CODE END Prototypes */
44 |
45 | #ifdef __cplusplus
46 | }
47 | #endif
48 | #endif /*__ GPIO_H__ */
49 |
50 |
--------------------------------------------------------------------------------
/Core/Inc/usart.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file usart.h
5 | * @brief This file contains all the function prototypes for
6 | * the usart.c file
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * Copyright (c) 2022 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software is licensed under terms that can be found in the LICENSE file
14 | * in the root directory of this software component.
15 | * If no LICENSE file comes with this software, it is provided AS-IS.
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __USART_H__
22 | #define __USART_H__
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "main.h"
30 |
31 | /* USER CODE BEGIN Includes */
32 |
33 | /* USER CODE END Includes */
34 |
35 | extern UART_HandleTypeDef huart1;
36 |
37 | /* USER CODE BEGIN Private defines */
38 |
39 | /* USER CODE END Private defines */
40 |
41 | void MX_USART1_UART_Init(void);
42 |
43 | /* USER CODE BEGIN Prototypes */
44 |
45 | /* USER CODE END Prototypes */
46 |
47 | #ifdef __cplusplus
48 | }
49 | #endif
50 |
51 | #endif /* __USART_H__ */
52 |
53 |
--------------------------------------------------------------------------------
/Core/Inc/tim.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file tim.h
5 | * @brief This file contains all the function prototypes for
6 | * the tim.c file
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * Copyright (c) 2022 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software is licensed under terms that can be found in the LICENSE file
14 | * in the root directory of this software component.
15 | * If no LICENSE file comes with this software, it is provided AS-IS.
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __TIM_H__
22 | #define __TIM_H__
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "main.h"
30 |
31 | /* USER CODE BEGIN Includes */
32 |
33 | /* USER CODE END Includes */
34 |
35 | extern TIM_HandleTypeDef htim1;
36 |
37 | extern TIM_HandleTypeDef htim2;
38 |
39 | extern TIM_HandleTypeDef htim3;
40 |
41 | extern TIM_HandleTypeDef htim4;
42 |
43 | extern TIM_HandleTypeDef htim9;
44 |
45 | /* USER CODE BEGIN Private defines */
46 |
47 | /* USER CODE END Private defines */
48 |
49 | void MX_TIM1_Init(void);
50 | void MX_TIM2_Init(void);
51 | void MX_TIM3_Init(void);
52 | void MX_TIM4_Init(void);
53 | void MX_TIM9_Init(void);
54 |
55 | /* USER CODE BEGIN Prototypes */
56 |
57 | /* USER CODE END Prototypes */
58 |
59 | #ifdef __cplusplus
60 | }
61 | #endif
62 |
63 | #endif /* __TIM_H__ */
64 |
65 |
--------------------------------------------------------------------------------
/Core/Inc/ModbusConfig.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ModbusConfig.h
3 | *
4 | * Created on: Apr 28, 2021
5 | * Author: Alejandro Mera
6 | *
7 | * This is a template for the Modbus library configuration.
8 | * Every project needs a tailored copy of this file renamed to ModbusConfig.h, and added to the include path.
9 | */
10 |
11 | #ifndef THIRD_PARTY_MODBUS_LIB_CONFIG_MODBUSCONFIG_H_
12 | #define THIRD_PARTY_MODBUS_LIB_CONFIG_MODBUSCONFIG_H_
13 |
14 |
15 |
16 | /* Uncomment the following line to enable support for Modbus RTU over USB CDC profile. Only tested for BluePill f103 board. */
17 | //#define ENABLE_USB_CDC 1
18 |
19 | /* Uncomment the following line to enable support for Modbus TCP. Only tested for Nucleo144-F429ZI. */
20 | //#define ENABLE_TCP 1
21 |
22 | /* Uncomment the following line to enable support for Modbus RTU USART DMA mode. Only tested for Nucleo144-F429ZI. */
23 | #define ENABLE_USART_DMA 1
24 |
25 |
26 | #define T35 5 // Timer T35 period (in ticks) for end frame detection.
27 | #define MAX_BUFFER 256 // Maximum size for the communication buffer in bytes.
28 | #define TIMEOUT_MODBUS 1000 // Timeout for master query (in ticks)
29 | #define MAX_M_HANDLERS 2 //Maximum number of modbus handlers that can work concurrently
30 | #define MAX_TELEGRAMS 2 //Max number of Telegrams in master queue
31 |
32 | #if ENABLE_TCP == 1
33 | #define NUMBERTCPCONN 4 // Maximum number of simultaneous client connections, it should be equal or less than LWIP configuration
34 | #define TCPAGINGCYCLES 1000 // Number of times the server will check for a incoming request before closing the connection for inactivity
35 | /* Note: the total aging time for a connection is approximately NUMBERTCPCONN*TCPAGINGCYCLES*u16timeOut ticks
36 | */
37 | #endif
38 |
39 |
40 |
41 |
42 | #endif /* THIRD_PARTY_MODBUS_LIB_CONFIG_MODBUSCONFIG_H_ */
43 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/cmsis_version.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file cmsis_version.h
3 | * @brief CMSIS Core(M) Version definitions
4 | * @version V5.0.2
5 | * @date 19. April 2017
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved.
9 | *
10 | * SPDX-License-Identifier: Apache-2.0
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the License); you may
13 | * not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | #if defined ( __ICCARM__ )
26 | #pragma system_include /* treat file as system include file for MISRA check */
27 | #elif defined (__clang__)
28 | #pragma clang system_header /* treat file as system include file */
29 | #endif
30 |
31 | #ifndef __CMSIS_VERSION_H
32 | #define __CMSIS_VERSION_H
33 |
34 | /* CMSIS Version definitions */
35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */
37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
39 | #endif
40 |
--------------------------------------------------------------------------------
/Core/Inc/stm32f4xx_it.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file stm32f4xx_it.h
5 | * @brief This file contains the headers of the interrupt handlers.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2022 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file
13 | * in the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | *
16 | ******************************************************************************
17 | */
18 | /* USER CODE END Header */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __STM32F4xx_IT_H
22 | #define __STM32F4xx_IT_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Private includes ----------------------------------------------------------*/
29 | /* USER CODE BEGIN Includes */
30 |
31 | /* USER CODE END Includes */
32 |
33 | /* Exported types ------------------------------------------------------------*/
34 | /* USER CODE BEGIN ET */
35 |
36 | /* USER CODE END ET */
37 |
38 | /* Exported constants --------------------------------------------------------*/
39 | /* USER CODE BEGIN EC */
40 |
41 | /* USER CODE END EC */
42 |
43 | /* Exported macro ------------------------------------------------------------*/
44 | /* USER CODE BEGIN EM */
45 |
46 | /* USER CODE END EM */
47 |
48 | /* Exported functions prototypes ---------------------------------------------*/
49 | void NMI_Handler(void);
50 | void HardFault_Handler(void);
51 | void MemManage_Handler(void);
52 | void BusFault_Handler(void);
53 | void UsageFault_Handler(void);
54 | void DebugMon_Handler(void);
55 | void TIM1_BRK_TIM9_IRQHandler(void);
56 | void TIM1_UP_TIM10_IRQHandler(void);
57 | void TIM1_TRG_COM_TIM11_IRQHandler(void);
58 | void USART1_IRQHandler(void);
59 | /* USER CODE BEGIN EFP */
60 |
61 | /* USER CODE END EFP */
62 |
63 | #ifdef __cplusplus
64 | }
65 | #endif
66 |
67 | #endif /* __STM32F4xx_IT_H */
68 |
--------------------------------------------------------------------------------
/Core/Inc/main.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file : main.h
5 | * @brief : Header for main.c file.
6 | * This file contains the common defines of the application.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * Copyright (c) 2022 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software is licensed under terms that can be found in the LICENSE file
14 | * in the root directory of this software component.
15 | * If no LICENSE file comes with this software, it is provided AS-IS.
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 |
21 | /* Define to prevent recursive inclusion -------------------------------------*/
22 | #ifndef __MAIN_H
23 | #define __MAIN_H
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | /* Includes ------------------------------------------------------------------*/
30 | #include "stm32f4xx_hal.h"
31 |
32 | /* Private includes ----------------------------------------------------------*/
33 | /* USER CODE BEGIN Includes */
34 | #include "Ramps.h"
35 | /* USER CODE END Includes */
36 |
37 | /* Exported types ------------------------------------------------------------*/
38 | /* USER CODE BEGIN ET */
39 |
40 | /* USER CODE END ET */
41 |
42 | /* Exported constants --------------------------------------------------------*/
43 | /* USER CODE BEGIN EC */
44 |
45 | /* USER CODE END EC */
46 |
47 | /* Exported macro ------------------------------------------------------------*/
48 | /* USER CODE BEGIN EM */
49 |
50 | /* USER CODE END EM */
51 |
52 | /* Exported functions prototypes ---------------------------------------------*/
53 | void Error_Handler(void);
54 |
55 | /* USER CODE BEGIN EFP */
56 |
57 | /* USER CODE END EFP */
58 |
59 | /* Private defines -----------------------------------------------------------*/
60 | #define SPARE_1_Pin GPIO_PIN_1
61 | #define SPARE_1_GPIO_Port GPIOA
62 | #define USR_LED_Pin GPIO_PIN_12
63 | #define USR_LED_GPIO_Port GPIOB
64 |
65 | /* USER CODE BEGIN Private defines */
66 |
67 | /* USER CODE END Private defines */
68 |
69 | #ifdef __cplusplus
70 | }
71 | #endif
72 |
73 | #endif /* __MAIN_H */
74 |
--------------------------------------------------------------------------------
/Core/Src/gpio.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file gpio.c
5 | * @brief This file provides code for the configuration
6 | * of all used GPIO pins.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * Copyright (c) 2022 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software is licensed under terms that can be found in the LICENSE file
14 | * in the root directory of this software component.
15 | * If no LICENSE file comes with this software, it is provided AS-IS.
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 |
21 | /* Includes ------------------------------------------------------------------*/
22 | #include "gpio.h"
23 |
24 | /* USER CODE BEGIN 0 */
25 |
26 | /* USER CODE END 0 */
27 |
28 | /*----------------------------------------------------------------------------*/
29 | /* Configure GPIO */
30 | /*----------------------------------------------------------------------------*/
31 | /* USER CODE BEGIN 1 */
32 |
33 | /* USER CODE END 1 */
34 |
35 | /** Configure pins as
36 | * Analog
37 | * Input
38 | * Output
39 | * EVENT_OUT
40 | * EXTI
41 | */
42 | void MX_GPIO_Init(void)
43 | {
44 |
45 | GPIO_InitTypeDef GPIO_InitStruct = {0};
46 |
47 | /* GPIO Ports Clock Enable */
48 | __HAL_RCC_GPIOH_CLK_ENABLE();
49 | __HAL_RCC_GPIOA_CLK_ENABLE();
50 | __HAL_RCC_GPIOB_CLK_ENABLE();
51 |
52 | /*Configure GPIO pin Output Level */
53 | HAL_GPIO_WritePin(SPARE_1_GPIO_PORT, SPARE_1_PIN, GPIO_PIN_RESET);
54 |
55 | /*Configure GPIO pin Output Level */
56 | HAL_GPIO_WritePin(USR_LED_GPIO_Port, USR_LED_Pin, GPIO_PIN_SET);
57 |
58 | /*Configure GPIO pin : PtPin */
59 | GPIO_InitStruct.Pin = SPARE_1_PIN;
60 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
61 | GPIO_InitStruct.Pull = GPIO_NOPULL;
62 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
63 | HAL_GPIO_Init(SPARE_1_GPIO_PORT, &GPIO_InitStruct);
64 |
65 | /*Configure GPIO pin : PtPin */
66 | GPIO_InitStruct.Pin = USR_LED_Pin;
67 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
68 | GPIO_InitStruct.Pull = GPIO_NOPULL;
69 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
70 | HAL_GPIO_Init(USR_LED_GPIO_Port, &GPIO_InitStruct);
71 |
72 | }
73 |
74 | /* USER CODE BEGIN 2 */
75 |
76 | /* USER CODE END 2 */
77 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_flash_ramfunc.h
4 | * @author MCD Application Team
5 | * @brief Header file of FLASH RAMFUNC driver.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2017 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file in
13 | * the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | ******************************************************************************
16 | */
17 |
18 | /* Define to prevent recursive inclusion -------------------------------------*/
19 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H
20 | #define __STM32F4xx_FLASH_RAMFUNC_H
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\
26 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx)
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "stm32f4xx_hal_def.h"
30 |
31 | /** @addtogroup STM32F4xx_HAL_Driver
32 | * @{
33 | */
34 |
35 | /** @addtogroup FLASH_RAMFUNC
36 | * @{
37 | */
38 |
39 | /* Exported types ------------------------------------------------------------*/
40 | /* Exported macro ------------------------------------------------------------*/
41 | /* Exported functions --------------------------------------------------------*/
42 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions
43 | * @{
44 | */
45 |
46 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1
47 | * @{
48 | */
49 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void);
50 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void);
51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void);
52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void);
53 | /**
54 | * @}
55 | */
56 |
57 | /**
58 | * @}
59 | */
60 |
61 | /**
62 | * @}
63 | */
64 |
65 | /**
66 | * @}
67 | */
68 |
69 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
70 | #ifdef __cplusplus
71 | }
72 | #endif
73 |
74 |
75 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */
76 |
77 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/freertos_mpool.h:
--------------------------------------------------------------------------------
1 | /* --------------------------------------------------------------------------
2 | * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the License); you may
7 | * not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | *
18 | * Name: freertos_mpool.h
19 | * Purpose: CMSIS RTOS2 wrapper for FreeRTOS
20 | *
21 | *---------------------------------------------------------------------------*/
22 |
23 | #ifndef FREERTOS_MPOOL_H_
24 | #define FREERTOS_MPOOL_H_
25 |
26 | #include
27 | #include "FreeRTOS.h"
28 | #include "semphr.h"
29 |
30 | /* Memory Pool implementation definitions */
31 | #define MPOOL_STATUS 0x5EED0000U
32 |
33 | /* Memory Block header */
34 | typedef struct {
35 | void *next; /* Pointer to next block */
36 | } MemPoolBlock_t;
37 |
38 | /* Memory Pool control block */
39 | typedef struct MemPoolDef_t {
40 | MemPoolBlock_t *head; /* Pointer to head block */
41 | SemaphoreHandle_t sem; /* Pool semaphore handle */
42 | uint8_t *mem_arr; /* Pool memory array */
43 | uint32_t mem_sz; /* Pool memory array size */
44 | const char *name; /* Pointer to name string */
45 | uint32_t bl_sz; /* Size of a single block */
46 | uint32_t bl_cnt; /* Number of blocks */
47 | uint32_t n; /* Block allocation index */
48 | volatile uint32_t status; /* Object status flags */
49 | #if (configSUPPORT_STATIC_ALLOCATION == 1)
50 | StaticSemaphore_t mem_sem; /* Semaphore object memory */
51 | #endif
52 | } MemPool_t;
53 |
54 | /* No need to hide static object type, just align to coding style */
55 | #define StaticMemPool_t MemPool_t
56 |
57 | /* Define memory pool control block size */
58 | #define MEMPOOL_CB_SIZE (sizeof(StaticMemPool_t))
59 |
60 | /* Define size of the byte array required to create count of blocks of given size */
61 | #define MEMPOOL_ARR_SIZE(bl_count, bl_size) (((((bl_size) + (4 - 1)) / 4) * 4)*(bl_count))
62 |
63 | #endif /* FREERTOS_MPOOL_H_ */
64 |
--------------------------------------------------------------------------------
/Core/Src/stm32f4xx_hal_msp.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file stm32f4xx_hal_msp.c
5 | * @brief This file provides code for the MSP Initialization
6 | * and de-Initialization codes.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * Copyright (c) 2022 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software is licensed under terms that can be found in the LICENSE file
14 | * in the root directory of this software component.
15 | * If no LICENSE file comes with this software, it is provided AS-IS.
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 |
21 | /* Includes ------------------------------------------------------------------*/
22 | #include "main.h"
23 |
24 | /* USER CODE BEGIN Includes */
25 |
26 | /* USER CODE END Includes */
27 |
28 | /* Private typedef -----------------------------------------------------------*/
29 | /* USER CODE BEGIN TD */
30 |
31 | /* USER CODE END TD */
32 |
33 | /* Private define ------------------------------------------------------------*/
34 | /* USER CODE BEGIN Define */
35 |
36 | /* USER CODE END Define */
37 |
38 | /* Private macro -------------------------------------------------------------*/
39 | /* USER CODE BEGIN Macro */
40 |
41 | /* USER CODE END Macro */
42 |
43 | /* Private variables ---------------------------------------------------------*/
44 | /* USER CODE BEGIN PV */
45 |
46 | /* USER CODE END PV */
47 |
48 | /* Private function prototypes -----------------------------------------------*/
49 | /* USER CODE BEGIN PFP */
50 |
51 | /* USER CODE END PFP */
52 |
53 | /* External functions --------------------------------------------------------*/
54 | /* USER CODE BEGIN ExternalFunctions */
55 |
56 | /* USER CODE END ExternalFunctions */
57 |
58 | /* USER CODE BEGIN 0 */
59 |
60 | /* USER CODE END 0 */
61 | /**
62 | * Initializes the Global MSP.
63 | */
64 | void HAL_MspInit(void)
65 | {
66 | /* USER CODE BEGIN MspInit 0 */
67 |
68 | /* USER CODE END MspInit 0 */
69 |
70 | __HAL_RCC_SYSCFG_CLK_ENABLE();
71 | __HAL_RCC_PWR_CLK_ENABLE();
72 |
73 | /* System interrupt init*/
74 | /* DebugMonitor_IRQn interrupt configuration */
75 | HAL_NVIC_SetPriority(DebugMonitor_IRQn, 5, 0);
76 | /* PendSV_IRQn interrupt configuration */
77 | HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
78 |
79 | /* USER CODE BEGIN MspInit 1 */
80 |
81 | /* USER CODE END MspInit 1 */
82 | }
83 |
84 | /* USER CODE BEGIN 1 */
85 |
86 | /* USER CODE END 1 */
87 |
--------------------------------------------------------------------------------
/.github/workflows/release.yaml:
--------------------------------------------------------------------------------
1 | name: Release
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | - dev
8 | - slow
9 |
10 | permissions: write-all
11 |
12 | jobs:
13 | release:
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - name: Checkout Code
18 | uses: actions/checkout@v4
19 | with:
20 | persist-credentials: false
21 | fetch-depth: 0
22 |
23 | - name: Determine Branch
24 | run: echo "BRANCH=${{ github.ref }}" >> $GITHUB_ENV
25 |
26 | - name: Git Semantic Version
27 | uses: PaulHatch/semantic-version@v5.0.3
28 | with:
29 | major_pattern: "major:"
30 | minor_pattern: "feat:"
31 | id: version
32 |
33 | - name: Create New Format Version
34 | env:
35 | PROD_VERSION: "${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.${{ steps.version.outputs.patch}}"
36 | DEV_VERSION: "${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.${{ steps.version.outputs.patch }}-${{github.ref_name}}.${{ steps.version.outputs.increment }}"
37 | run: |
38 | echo "${{steps.version.outputs.version}}"
39 | if [[ "${{ env.BRANCH }}" == "refs/heads/main" ]]; then
40 | echo "NEW_VERSION=${{ env.PROD_VERSION }}" >> $GITHUB_ENV
41 | else
42 | echo "NEW_VERSION=${{ env.DEV_VERSION }}" >> $GITHUB_ENV
43 | fi
44 |
45 | - name: Install packages
46 | run: |
47 | sudo apt-get update && \
48 | sudo apt-get install -yy \
49 | coreutils procps make cmake \
50 | build-essential gcc-arm-none-eabi \
51 | libstdc++-arm-none-eabi-dev libstdc++-arm-none-eabi-newlib \
52 | libnewlib-arm-none-eabi
53 |
54 | - name: Build binaries
55 | run: |
56 | cmake -DCMAKE_BUILD_TYPE:string=Release . && \
57 | make clean && make
58 |
59 | - name: Create Git Tag
60 | env:
61 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62 | run: |
63 | git config --local user.name "Github Action"
64 | git config --local user.email "bartei81@gmail.com"
65 | git tag -a v${{ env.NEW_VERSION }} -m "Version v${{ env.NEW_VERSION }}"
66 |
67 | - name: Push changes
68 | uses: ad-m/github-push-action@master
69 | with:
70 | github_token: ${{ secrets.GITHUB_TOKEN }}
71 | force: true
72 | tags: true
73 |
74 | - name: Release
75 | uses: softprops/action-gh-release@v1
76 | with:
77 | token: ${{ secrets.GITHUB_TOKEN }}
78 | tag_name: "v${{ env.NEW_VERSION }}"
79 | generate_release_notes: false
80 | files: |
81 | rotary-controller-f4.bin
82 | rotary-controller-f4.elf
83 | rotary-controller-f4.hex
84 |
--------------------------------------------------------------------------------
/CMakeLists_template.txt:
--------------------------------------------------------------------------------
1 | #${templateWarning}
2 | set(CMAKE_SYSTEM_NAME Generic)
3 | set(CMAKE_SYSTEM_VERSION 1)
4 | ${cmakeRequiredVersion}
5 | # specify cross-compilers and tools
6 | set(CMAKE_C_COMPILER arm-none-eabi-gcc)
7 | set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
8 | set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
9 | set(CMAKE_AR arm-none-eabi-ar)
10 | set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
11 | set(CMAKE_OBJDUMP arm-none-eabi-objdump)
12 | set(SIZE arm-none-eabi-size)
13 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
14 |
15 | # project settings
16 | project(${projectName} C CXX ASM)
17 | set(CMAKE_CXX_STANDARD 17)
18 | set(CMAKE_C_STANDARD 11)
19 |
20 | #Uncomment for hardware floating point
21 | add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
22 | add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
23 | add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
24 |
25 | #Uncomment for software floating point
26 | #add_compile_options(-mfloat-abi=soft)
27 |
28 | add_compile_options(-mcpu=${mcpu} -mthumb -mthumb-interwork)
29 | add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)
30 |
31 | # uncomment to mitigate c++17 absolute addresses warnings
32 | #set(CMAKE_CXX_FLAGS "$${CMAKE_CXX_FLAGS} -Wno-register")
33 |
34 | # Enable assembler files preprocessing
35 | add_compile_options($<$:-x$assembler-with-cpp>)
36 |
37 | if ("$${CMAKE_BUILD_TYPE}" STREQUAL "Release")
38 | message(STATUS "Maximum optimization for speed")
39 | add_compile_options(-Ofast)
40 | elseif ("$${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
41 | message(STATUS "Maximum optimization for speed, debug info included")
42 | add_compile_options(-Ofast -g)
43 | elseif ("$${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
44 | message(STATUS "Maximum optimization for size")
45 | add_compile_options(-Os)
46 | else ()
47 | message(STATUS "Minimal optimization, debug info included")
48 | add_compile_options(-Og -g)
49 | endif ()
50 |
51 | include_directories(${includes})
52 |
53 | add_definitions(${defines})
54 |
55 | file(GLOB_RECURSE SOURCES ${sources})
56 |
57 | set(LINKER_SCRIPT $${CMAKE_SOURCE_DIR}/${linkerScript})
58 |
59 | add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=$${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.map)
60 | add_link_options(-mcpu=${mcpu} -mthumb -mthumb-interwork)
61 | add_link_options(-T $${LINKER_SCRIPT})
62 |
63 | add_executable($${PROJECT_NAME}.elf $${SOURCES} $${LINKER_SCRIPT})
64 |
65 | set(HEX_FILE $${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.hex)
66 | set(BIN_FILE $${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.bin)
67 |
68 | add_custom_command(TARGET $${PROJECT_NAME}.elf POST_BUILD
69 | COMMAND $${CMAKE_OBJCOPY} -Oihex $ $${HEX_FILE}
70 | COMMAND $${CMAKE_OBJCOPY} -Obinary $ $${BIN_FILE}
71 | COMMENT "Building $${HEX_FILE}
72 | Building $${BIN_FILE}")
73 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file system_stm32f4xx.h
4 | * @author MCD Application Team
5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2017 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file
13 | * in the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | *
16 | ******************************************************************************
17 | */
18 |
19 | /** @addtogroup CMSIS
20 | * @{
21 | */
22 |
23 | /** @addtogroup stm32f4xx_system
24 | * @{
25 | */
26 |
27 | /**
28 | * @brief Define to prevent recursive inclusion
29 | */
30 | #ifndef __SYSTEM_STM32F4XX_H
31 | #define __SYSTEM_STM32F4XX_H
32 |
33 | #ifdef __cplusplus
34 | extern "C" {
35 | #endif
36 |
37 | /** @addtogroup STM32F4xx_System_Includes
38 | * @{
39 | */
40 |
41 | /**
42 | * @}
43 | */
44 |
45 |
46 | /** @addtogroup STM32F4xx_System_Exported_types
47 | * @{
48 | */
49 | /* This variable is updated in three ways:
50 | 1) by calling CMSIS function SystemCoreClockUpdate()
51 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq()
52 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
53 | Note: If you use this function to configure the system clock; then there
54 | is no need to call the 2 first functions listed above, since SystemCoreClock
55 | variable is updated automatically.
56 | */
57 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
58 |
59 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */
60 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | /** @addtogroup STM32F4xx_System_Exported_Constants
67 | * @{
68 | */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /** @addtogroup STM32F4xx_System_Exported_Macros
75 | * @{
76 | */
77 |
78 | /**
79 | * @}
80 | */
81 |
82 | /** @addtogroup STM32F4xx_System_Exported_Functions
83 | * @{
84 | */
85 |
86 | extern void SystemInit(void);
87 | extern void SystemCoreClockUpdate(void);
88 | /**
89 | * @}
90 | */
91 |
92 | #ifdef __cplusplus
93 | }
94 | #endif
95 |
96 | #endif /*__SYSTEM_STM32F4XX_H */
97 |
98 | /**
99 | * @}
100 | */
101 |
102 | /**
103 | * @}
104 | */
105 |
--------------------------------------------------------------------------------
/Core/Src/sysmem.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file sysmem.c
4 | * @author Generated by STM32CubeIDE
5 | * @brief STM32CubeIDE System Memory calls file
6 | *
7 | * For more information about which C functions
8 | * need which of these lowlevel functions
9 | * please consult the newlib libc manual
10 | ******************************************************************************
11 | * @attention
12 | *
13 | * Copyright (c) 2022 STMicroelectronics.
14 | * All rights reserved.
15 | *
16 | * This software is licensed under terms that can be found in the LICENSE file
17 | * in the root directory of this software component.
18 | * If no LICENSE file comes with this software, it is provided AS-IS.
19 | *
20 | ******************************************************************************
21 | */
22 |
23 | /* Includes */
24 | #include
25 | #include
26 |
27 | /**
28 | * Pointer to the current high watermark of the heap usage
29 | */
30 | static uint8_t *__sbrk_heap_end = NULL;
31 |
32 | /**
33 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc
34 | * and others from the C library
35 | *
36 | * @verbatim
37 | * ############################################################################
38 | * # .data # .bss # newlib heap # MSP stack #
39 | * # # # # Reserved by _Min_Stack_Size #
40 | * ############################################################################
41 | * ^-- RAM start ^-- _end _estack, RAM end --^
42 | * @endverbatim
43 | *
44 | * This implementation starts allocating at the '_end' linker symbol
45 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
46 | * The implementation considers '_estack' linker symbol to be RAM end
47 | * NOTE: If the MSP stack, at any point during execution, grows larger than the
48 | * reserved size, please increase the '_Min_Stack_Size'.
49 | *
50 | * @param incr Memory size
51 | * @return Pointer to allocated memory
52 | */
53 | void *_sbrk(ptrdiff_t incr)
54 | {
55 | extern uint8_t _end; /* Symbol defined in the linker script */
56 | extern uint8_t _estack; /* Symbol defined in the linker script */
57 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
58 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
59 | const uint8_t *max_heap = (uint8_t *)stack_limit;
60 | uint8_t *prev_heap_end;
61 |
62 | /* Initialize heap end at first call */
63 | if (NULL == __sbrk_heap_end)
64 | {
65 | __sbrk_heap_end = &_end;
66 | }
67 |
68 | /* Protect heap from growing into the reserved MSP stack */
69 | if (__sbrk_heap_end + incr > max_heap)
70 | {
71 | errno = ENOMEM;
72 | return (void *)-1;
73 | }
74 |
75 | prev_heap_end = __sbrk_heap_end;
76 | __sbrk_heap_end += incr;
77 |
78 | return (void *)prev_heap_end;
79 | }
80 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/tz_context.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file tz_context.h
3 | * @brief Context Management for Armv8-M TrustZone
4 | * @version V1.0.1
5 | * @date 10. January 2018
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved.
9 | *
10 | * SPDX-License-Identifier: Apache-2.0
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the License); you may
13 | * not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | #if defined ( __ICCARM__ )
26 | #pragma system_include /* treat file as system include file for MISRA check */
27 | #elif defined (__clang__)
28 | #pragma clang system_header /* treat file as system include file */
29 | #endif
30 |
31 | #ifndef TZ_CONTEXT_H
32 | #define TZ_CONTEXT_H
33 |
34 | #include
35 |
36 | #ifndef TZ_MODULEID_T
37 | #define TZ_MODULEID_T
38 | /// \details Data type that identifies secure software modules called by a process.
39 | typedef uint32_t TZ_ModuleId_t;
40 | #endif
41 |
42 | /// \details TZ Memory ID identifies an allocated memory slot.
43 | typedef uint32_t TZ_MemoryId_t;
44 |
45 | /// Initialize secure context memory system
46 | /// \return execution status (1: success, 0: error)
47 | uint32_t TZ_InitContextSystem_S (void);
48 |
49 | /// Allocate context memory for calling secure software modules in TrustZone
50 | /// \param[in] module identifies software modules called from non-secure mode
51 | /// \return value != 0 id TrustZone memory slot identifier
52 | /// \return value 0 no memory available or internal error
53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module);
54 |
55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S
56 | /// \param[in] id TrustZone memory slot identifier
57 | /// \return execution status (1: success, 0: error)
58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id);
59 |
60 | /// Load secure context (called on RTOS thread context switch)
61 | /// \param[in] id TrustZone memory slot identifier
62 | /// \return execution status (1: success, 0: error)
63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id);
64 |
65 | /// Store secure context (called on RTOS thread context switch)
66 | /// \param[in] id TrustZone memory slot identifier
67 | /// \return execution status (1: success, 0: error)
68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id);
69 |
70 | #endif // TZ_CONTEXT_H
71 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_dma_ex.h
4 | * @author MCD Application Team
5 | * @brief Header file of DMA HAL extension module.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2017 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file in
13 | * the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | *
16 | ******************************************************************************
17 | */
18 |
19 | /* Define to prevent recursive inclusion -------------------------------------*/
20 | #ifndef __STM32F4xx_HAL_DMA_EX_H
21 | #define __STM32F4xx_HAL_DMA_EX_H
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | /* Includes ------------------------------------------------------------------*/
28 | #include "stm32f4xx_hal_def.h"
29 |
30 | /** @addtogroup STM32F4xx_HAL_Driver
31 | * @{
32 | */
33 |
34 | /** @addtogroup DMAEx
35 | * @{
36 | */
37 |
38 | /* Exported types ------------------------------------------------------------*/
39 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types
40 | * @brief DMAEx Exported types
41 | * @{
42 | */
43 |
44 | /**
45 | * @brief HAL DMA Memory definition
46 | */
47 | typedef enum
48 | {
49 | MEMORY0 = 0x00U, /*!< Memory 0 */
50 | MEMORY1 = 0x01U /*!< Memory 1 */
51 | }HAL_DMA_MemoryTypeDef;
52 |
53 | /**
54 | * @}
55 | */
56 |
57 | /* Exported functions --------------------------------------------------------*/
58 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions
59 | * @brief DMAEx Exported functions
60 | * @{
61 | */
62 |
63 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions
64 | * @brief Extended features functions
65 | * @{
66 | */
67 |
68 | /* IO operation functions *******************************************************/
69 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength);
70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength);
71 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory);
72 |
73 | /**
74 | * @}
75 | */
76 | /**
77 | * @}
78 | */
79 |
80 | /* Private functions ---------------------------------------------------------*/
81 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions
82 | * @brief DMAEx Private functions
83 | * @{
84 | */
85 | /**
86 | * @}
87 | */
88 |
89 | /**
90 | * @}
91 | */
92 |
93 | /**
94 | * @}
95 | */
96 |
97 | #ifdef __cplusplus
98 | }
99 | #endif
100 |
101 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/
102 |
103 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
2 | set(CMAKE_SYSTEM_NAME Generic)
3 | set(CMAKE_SYSTEM_VERSION 1)
4 | cmake_minimum_required(VERSION 3.30)
5 |
6 | # specify cross-compilers and tools
7 | set(CMAKE_C_COMPILER arm-none-eabi-gcc)
8 | set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
9 | set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
10 | set(CMAKE_AR arm-none-eabi-ar)
11 | set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
12 | set(CMAKE_OBJDUMP arm-none-eabi-objdump)
13 | set(SIZE arm-none-eabi-size)
14 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
15 |
16 | # project settings
17 | project(rotary-controller-f4 C CXX ASM)
18 | set(CMAKE_CXX_STANDARD 17)
19 | set(CMAKE_C_STANDARD 11)
20 |
21 | #Uncomment for hardware floating point
22 | add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
23 | add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
24 | add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
25 |
26 | #Uncomment for software floating point
27 | #add_compile_options(-mfloat-abi=soft)
28 |
29 | add_compile_options(-mcpu=cortex-m4 -mthumb -mthumb-interwork)
30 | add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)
31 |
32 | # uncomment to mitigate c++17 absolute addresses warnings
33 | #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")
34 |
35 | # Enable assembler files preprocessing
36 | add_compile_options($<$:-x$assembler-with-cpp>)
37 |
38 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
39 | message(STATUS "Maximum optimization for speed")
40 | add_compile_options(-Ofast)
41 | elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
42 | message(STATUS "Maximum optimization for speed, debug info included")
43 | add_compile_options(-Ofast -g)
44 | elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
45 | message(STATUS "Maximum optimization for size")
46 | add_compile_options(-Os)
47 | else ()
48 | message(STATUS "Minimal optimization, debug info included")
49 | add_compile_options(-Og -g)
50 | endif ()
51 |
52 | include_directories(Core/Inc Drivers/STM32F4xx_HAL_Driver/Inc Drivers/STM32F4xx_HAL_Driver/Inc/Legacy Middlewares/Third_Party/FreeRTOS/Source/include Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F Drivers/CMSIS/Device/ST/STM32F4xx/Include Drivers/CMSIS/Include)
53 |
54 | add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32F411xE)
55 |
56 | file(GLOB_RECURSE SOURCES "Core/*.*" "Middlewares/*.*" "Drivers/*.*")
57 |
58 | set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F411CEUX_FLASH.ld)
59 |
60 | add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
61 | add_link_options(-mcpu=cortex-m4 -mthumb -mthumb-interwork)
62 | add_link_options(-T ${LINKER_SCRIPT})
63 |
64 | add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
65 |
66 | set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
67 | set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
68 |
69 | add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
70 | COMMAND ${CMAKE_OBJCOPY} -Oihex $ ${HEX_FILE}
71 | COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${BIN_FILE}
72 | COMMENT "Building ${HEX_FILE}
73 | Building ${BIN_FILE}")
74 |
--------------------------------------------------------------------------------
/Core/Src/syscalls.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file syscalls.c
4 | * @author Auto-generated by STM32CubeIDE
5 | * @brief STM32CubeIDE Minimal System calls file
6 | *
7 | * For more information about which c-functions
8 | * need which of these lowlevel functions
9 | * please consult the Newlib libc-manual
10 | ******************************************************************************
11 | * @attention
12 | *
13 | * Copyright (c) 2022 STMicroelectronics.
14 | * All rights reserved.
15 | *
16 | * This software is licensed under terms that can be found in the LICENSE file
17 | * in the root directory of this software component.
18 | * If no LICENSE file comes with this software, it is provided AS-IS.
19 | *
20 | ******************************************************************************
21 | */
22 |
23 | /* Includes */
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 |
34 | /* Variables */
35 | extern int __io_putchar(int ch) __attribute__((weak));
36 | extern int __io_getchar(void) __attribute__((weak));
37 |
38 |
39 | char *__env[1] = { 0 };
40 | char **environ = __env;
41 |
42 |
43 | /* Functions */
44 | void initialise_monitor_handles()
45 | {
46 | }
47 |
48 | int _getpid(void)
49 | {
50 | return 1;
51 | }
52 |
53 | int _kill(int pid, int sig)
54 | {
55 | errno = EINVAL;
56 | return -1;
57 | }
58 |
59 | void _exit (int status)
60 | {
61 | _kill(status, -1);
62 | while (1) {} /* Make sure we hang here */
63 | }
64 |
65 | __attribute__((weak)) int _read(int file, char *ptr, int len)
66 | {
67 | int DataIdx;
68 |
69 | for (DataIdx = 0; DataIdx < len; DataIdx++)
70 | {
71 | *ptr++ = __io_getchar();
72 | }
73 |
74 | return len;
75 | }
76 |
77 | __attribute__((weak)) int _write(int file, char *ptr, int len)
78 | {
79 | int DataIdx;
80 |
81 | for (DataIdx = 0; DataIdx < len; DataIdx++)
82 | {
83 | __io_putchar(*ptr++);
84 | }
85 | return len;
86 | }
87 |
88 | int _close(int file)
89 | {
90 | return -1;
91 | }
92 |
93 |
94 | int _fstat(int file, struct stat *st)
95 | {
96 | st->st_mode = S_IFCHR;
97 | return 0;
98 | }
99 |
100 | int _isatty(int file)
101 | {
102 | return 1;
103 | }
104 |
105 | int _lseek(int file, int ptr, int dir)
106 | {
107 | return 0;
108 | }
109 |
110 | int _open(char *path, int flags, ...)
111 | {
112 | /* Pretend like we always fail */
113 | return -1;
114 | }
115 |
116 | int _wait(int *status)
117 | {
118 | errno = ECHILD;
119 | return -1;
120 | }
121 |
122 | int _unlink(char *name)
123 | {
124 | errno = ENOENT;
125 | return -1;
126 | }
127 |
128 | int _times(struct tms *buf)
129 | {
130 | return -1;
131 | }
132 |
133 | int _stat(char *file, struct stat *st)
134 | {
135 | st->st_mode = S_IFCHR;
136 | return 0;
137 | }
138 |
139 | int _link(char *old, char *new)
140 | {
141 | errno = EMLINK;
142 | return -1;
143 | }
144 |
145 | int _fork(void)
146 | {
147 | errno = EAGAIN;
148 | return -1;
149 | }
150 |
151 | int _execve(char *name, char **argv, char **env)
152 | {
153 | errno = ENOMEM;
154 | return -1;
155 | }
156 |
--------------------------------------------------------------------------------
/Core/Src/usart.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file usart.c
5 | * @brief This file provides code for the configuration
6 | * of the USART instances.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * Copyright (c) 2022 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software is licensed under terms that can be found in the LICENSE file
14 | * in the root directory of this software component.
15 | * If no LICENSE file comes with this software, it is provided AS-IS.
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 | /* Includes ------------------------------------------------------------------*/
21 | #include "usart.h"
22 |
23 | /* USER CODE BEGIN 0 */
24 |
25 | /* USER CODE END 0 */
26 |
27 | UART_HandleTypeDef huart1;
28 |
29 | /* USART1 init function */
30 |
31 | void MX_USART1_UART_Init(void)
32 | {
33 |
34 | /* USER CODE BEGIN USART1_Init 0 */
35 |
36 | /* USER CODE END USART1_Init 0 */
37 |
38 | /* USER CODE BEGIN USART1_Init 1 */
39 |
40 | /* USER CODE END USART1_Init 1 */
41 | huart1.Instance = USART1;
42 | huart1.Init.BaudRate = 115200;
43 | huart1.Init.WordLength = UART_WORDLENGTH_8B;
44 | huart1.Init.StopBits = UART_STOPBITS_1;
45 | huart1.Init.Parity = UART_PARITY_NONE;
46 | huart1.Init.Mode = UART_MODE_TX_RX;
47 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
48 | huart1.Init.OverSampling = UART_OVERSAMPLING_16;
49 | if (HAL_UART_Init(&huart1) != HAL_OK)
50 | {
51 | Error_Handler();
52 | }
53 | /* USER CODE BEGIN USART1_Init 2 */
54 |
55 | /* USER CODE END USART1_Init 2 */
56 |
57 | }
58 |
59 | void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
60 | {
61 |
62 | GPIO_InitTypeDef GPIO_InitStruct = {0};
63 | if(uartHandle->Instance==USART1)
64 | {
65 | /* USER CODE BEGIN USART1_MspInit 0 */
66 |
67 | /* USER CODE END USART1_MspInit 0 */
68 | /* USART1 clock enable */
69 | __HAL_RCC_USART1_CLK_ENABLE();
70 |
71 | __HAL_RCC_GPIOA_CLK_ENABLE();
72 | /**USART1 GPIO Configuration
73 | PA10 ------> USART1_RX
74 | PA15 ------> USART1_TX
75 | */
76 | GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_15;
77 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
78 | GPIO_InitStruct.Pull = GPIO_NOPULL;
79 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
80 | GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
81 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
82 |
83 | /* USART1 interrupt Init */
84 | HAL_NVIC_SetPriority(USART1_IRQn, 15, 0);
85 | HAL_NVIC_EnableIRQ(USART1_IRQn);
86 | /* USER CODE BEGIN USART1_MspInit 1 */
87 |
88 | /* USER CODE END USART1_MspInit 1 */
89 | }
90 | }
91 |
92 | void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
93 | {
94 |
95 | if(uartHandle->Instance==USART1)
96 | {
97 | /* USER CODE BEGIN USART1_MspDeInit 0 */
98 |
99 | /* USER CODE END USART1_MspDeInit 0 */
100 | /* Peripheral clock disable */
101 | __HAL_RCC_USART1_CLK_DISABLE();
102 |
103 | /**USART1 GPIO Configuration
104 | PA10 ------> USART1_RX
105 | PA15 ------> USART1_TX
106 | */
107 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_10|GPIO_PIN_15);
108 |
109 | /* USART1 interrupt Deinit */
110 | HAL_NVIC_DisableIRQ(USART1_IRQn);
111 | /* USER CODE BEGIN USART1_MspDeInit 1 */
112 |
113 | /* USER CODE END USART1_MspDeInit 1 */
114 | }
115 | }
116 |
117 | /* USER CODE BEGIN 1 */
118 |
119 | /* USER CODE END 1 */
120 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Rotary Controller (F4)
2 |
3 | [](https://discord.gg/EDtgj7Yayr) [](https://www.provvedo.com/shop)
4 |
5 |
6 | This repository contains the **firmware** for a rotary controller board based on the **STM32F411** microcontroller ([github.com][1]). It provides Digital Read Out (DRO) and single-axis control for CNC-style rotary tables.
7 |
8 | 🛒 **Purchase all boards from our shop:** [Provvedo Shop](https://www.provvedo.com/shop)
9 |
10 | ---
11 |
12 | ## ⚙️ Features
13 |
14 | * Utilizes **STM32CubeMX** for hardware configuration (.ioc file included)
15 | * Modular firmware structure with FreeRTOS support
16 | * Supports ST‑Link V2 and Raspberry Pi + OpenOCD programming
17 | * Optimized for high-speed encoder + stepper motor control
18 |
19 | ---
20 |
21 | ## 🛠️ Build & Flash
22 |
23 | ### Requirements
24 |
25 | * CMake & C/C++ toolchain (e.g. `arm-none-eabi-gcc`, `make`)
26 | * ST-Link v2 or Raspberry Pi with OpenOCD
27 |
28 | ### Build
29 |
30 | ```bash
31 | git clone https://github.com/bartei/rotary-controller-f4.git
32 | cd rotary-controller-f4
33 | cmake -DCMAKE_BUILD_TYPE=Release .
34 | make -j$(nproc)
35 | ```
36 |
37 | ### Clean
38 |
39 | ```bash
40 | make clean
41 | ```
42 |
43 | ### Flash
44 |
45 | * **ST‑Link V2**:
46 |
47 | ```bash
48 | st-flash --format ihex write rotary-controller-f4.hex
49 | ```
50 |
51 | * **Raspberry Pi + OpenOCD**:
52 |
53 | ```bash
54 | openocd -f ./raspberry.cfg
55 | ```
56 |
57 | The default `raspberry.cfg` configures SWD over GPIO pins 24/25 + GND. Ensure GND wiring is the **same length** as SWCLK/SWDIO for reliability. Modify the GPIO pins in `raspberry.cfg` if needed.
58 |
59 | ---
60 |
61 | ## 🔧 Hardware Configuration
62 |
63 | * `.ioc` file for use with STM32CubeMX included
64 | * Pin assignments for encoder, buttons, LEDs, SWD, etc. reviewed and tested
65 | * Memory layout defined by `STM32F411CEUX_FLASH.ld` and `STM32F411CEUX_RAM.ld`
66 |
67 | ---
68 |
69 | ## 🧩 PCB & Schematic
70 |
71 | Firmware integrates with hardware design available at:
72 |
73 | * **PCB repo**: bartei/rotary-controller-pcb — includes Proteus schematic, BOM (with pricing), and fab files; KiCad version in progress ([github.com][2], [github.com][3], [github.com][1])
74 |
75 | Together, they form a complete controller + UI system when paired with:
76 |
77 | * `rotary-controller-python` — a Raspberry Pi Kivy-based DRO + control UI
78 |
79 | ---
80 |
81 | ## 🛎️ Usage Notes
82 |
83 | * Works as a **single-axis rotary DRO**
84 | * FreeRTOS scheduler handles encoder sampling loop
85 | * GPIO/button routines support nudge and rotary button functions
86 | * SWD pins must be appropriately wired and matched in length
87 |
88 | ---
89 |
90 | ## 📘 Resources & Links
91 |
92 | * [Firmware repo](https://github.com/bartei/rotary-controller-f4)
93 | * [PCB repo (Proteus/KiCad)](https://github.com/bartei/rotary-controller-pcb)
94 | * [Raspberry Pi UI with Kivy](https://github.com/bartei/rotary-controller-python)
95 | * Join the community on **Discord**
96 |
97 | ---
98 |
99 | ## ✅ Next Steps
100 |
101 | 1. Test hardware interface in CubeMX; verify pin assignments
102 | 2. Build and flash firmware, connect to DRO UI app
103 | 3. Utilize FreeRTOS for real-time sampling and control
104 | 4. Contribute improvements — e.g. KiCad support, UI features, multi-axis
105 |
106 | ---
107 |
108 | ## 📝 Contact & Support
109 |
110 | Need help? Join our **Discord** community for support, discussions, and updates.
111 |
112 |
113 | ---
114 |
115 | Let me know if you'd like additions like block diagrams, pinout tables, or usage screenshots!
116 |
117 | [1]: https://github.com/bartei/rotary-controller-f4"
118 | [2]: https://github.com/bartei/rotary-controller-pcb"
119 | [3]: https://github.com/bartei/rotary-controller-python"
120 |
--------------------------------------------------------------------------------
/Core/Src/freertos.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * File Name : freertos.c
5 | * Description : Code for freertos applications
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2022 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file
13 | * in the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | *
16 | ******************************************************************************
17 | */
18 | /* USER CODE END Header */
19 |
20 | /* Includes ------------------------------------------------------------------*/
21 | #include "FreeRTOS.h"
22 | #include "task.h"
23 | #include "main.h"
24 | #include "cmsis_os.h"
25 |
26 | /* Private includes ----------------------------------------------------------*/
27 | /* USER CODE BEGIN Includes */
28 |
29 | /* USER CODE END Includes */
30 |
31 | /* Private typedef -----------------------------------------------------------*/
32 | /* USER CODE BEGIN PTD */
33 |
34 | /* USER CODE END PTD */
35 |
36 | /* Private define ------------------------------------------------------------*/
37 | /* USER CODE BEGIN PD */
38 |
39 | /* USER CODE END PD */
40 |
41 | /* Private macro -------------------------------------------------------------*/
42 | /* USER CODE BEGIN PM */
43 |
44 | /* USER CODE END PM */
45 |
46 | /* Private variables ---------------------------------------------------------*/
47 | /* USER CODE BEGIN Variables */
48 |
49 | /* USER CODE END Variables */
50 | /* Definitions for defaultTask */
51 | osThreadId_t defaultTaskHandle;
52 | const osThreadAttr_t defaultTask_attributes = {
53 | .name = "defaultTask",
54 | .stack_size = 128 * 4,
55 | .priority = (osPriority_t) osPriorityNormal,
56 | };
57 |
58 | /* Private function prototypes -----------------------------------------------*/
59 | /* USER CODE BEGIN FunctionPrototypes */
60 |
61 | /* USER CODE END FunctionPrototypes */
62 |
63 | void StartDefaultTask(void *argument);
64 |
65 | void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
66 |
67 | /**
68 | * @brief FreeRTOS initialization
69 | * @param None
70 | * @retval None
71 | */
72 | void MX_FREERTOS_Init(void) {
73 | /* USER CODE BEGIN Init */
74 | /* USER CODE END Init */
75 |
76 | /* USER CODE BEGIN RTOS_MUTEX */
77 | /* add mutexes, ... */
78 | /* USER CODE END RTOS_MUTEX */
79 |
80 | /* USER CODE BEGIN RTOS_SEMAPHORES */
81 | /* add semaphores, ... */
82 | /* USER CODE END RTOS_SEMAPHORES */
83 |
84 | /* USER CODE BEGIN RTOS_TIMERS */
85 | /* start timers, add new ones, ... */
86 | /* USER CODE END RTOS_TIMERS */
87 |
88 | /* USER CODE BEGIN RTOS_QUEUES */
89 | /* add queues, ... */
90 | /* USER CODE END RTOS_QUEUES */
91 |
92 | /* Create the thread(s) */
93 | /* creation of defaultTask */
94 | defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
95 |
96 | /* USER CODE BEGIN RTOS_THREADS */
97 | /* add threads, ... */
98 | /* USER CODE END RTOS_THREADS */
99 |
100 | /* USER CODE BEGIN RTOS_EVENTS */
101 | /* add events, ... */
102 | /* USER CODE END RTOS_EVENTS */
103 |
104 | }
105 |
106 | /* USER CODE BEGIN Header_StartDefaultTask */
107 | /**
108 | * @brief Function implementing the defaultTask thread.
109 | * @param argument: Not used
110 | * @retval None
111 | */
112 | /* USER CODE END Header_StartDefaultTask */
113 | void StartDefaultTask(void *argument)
114 | {
115 | /* USER CODE BEGIN StartDefaultTask */
116 | /* Infinite loop */
117 | for(;;)
118 | {
119 | osDelay(1000);
120 | HAL_GPIO_TogglePin(USR_LED_GPIO_Port, USR_LED_Pin);
121 |
122 | }
123 | /* USER CODE END StartDefaultTask */
124 | }
125 |
126 | /* Private application code --------------------------------------------------*/
127 | /* USER CODE BEGIN Application */
128 |
129 | /* USER CODE END Application */
130 |
131 |
--------------------------------------------------------------------------------
/Core/Inc/Ramps.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright © 2022
3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 | * and associated documentation files (the “Software”), to deal in the Software without restriction,
5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7 | * furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
13 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 | #ifndef THIRD_PARTY_RAMPS_H_
19 | #define THIRD_PARTY_RAMPS_H_
20 |
21 | #include
22 | #include "stm32f4xx_hal.h"
23 | #include "cmsis_os2.h"
24 | #include "Modbus.h"
25 | #include "Scales.h"
26 |
27 | #define MODBUS_ADDRESS 17
28 |
29 | #define STEP_PIN GPIO_PIN_0
30 | #define STEP_GPIO_PORT GPIOA
31 |
32 | #define DIR_PIN GPIO_PIN_14
33 | #define DIR_GPIO_PORT GPIOB
34 |
35 | #define ENA_PIN GPIO_PIN_15
36 | #define ENA_GPIO_PORT GPIOB
37 | #define ENA_DELAY_MS 500
38 |
39 | #define USR_LED_Pin GPIO_PIN_12
40 | #define USR_LED_GPIO_Port GPIOB
41 |
42 | #define SPARE_1_PIN GPIO_PIN_1
43 | #define SPARE_1_GPIO_PORT GPIOA
44 |
45 | #define SPARE_2_PIN GPIO_PIN_3
46 | #define SPARE_2_GPIO_PORT GPIOA
47 |
48 | #define SPARE_3_PIN GPIO_PIN_4
49 | #define SPARE_3_GPIO_PORT GPIOA
50 |
51 |
52 | typedef struct {
53 | int32_t delta;
54 | uint32_t oldPosition;
55 | uint32_t position;
56 | int32_t scaledDelta;
57 | int32_t error;
58 | } deltaPosError_t;
59 |
60 | typedef struct {
61 | TIM_HandleTypeDef *timerHandle;
62 | int32_t position;
63 | int32_t speed;
64 | int32_t syncRatioNum, syncRatioDen;
65 | uint16_t syncEnable;
66 | } input_t;
67 |
68 | typedef struct {
69 | float maxSpeed;
70 | float currentSpeed;
71 | float jogSpeed;
72 | float acceleration;
73 | int32_t stepsToGo;
74 | uint32_t destinationSteps;
75 | uint32_t currentSteps;
76 | uint32_t desiredSteps;
77 | } servo_t;
78 |
79 | typedef struct {
80 | uint32_t servoCurrent;
81 | uint32_t servoDesired;
82 | uint32_t stepsToGo;
83 | float servoSpeed;
84 | int32_t scaleCurrent[SCALES_COUNT];
85 | int32_t scaleSpeed[SCALES_COUNT];
86 | uint32_t cycles;
87 | uint32_t executionInterval;
88 | uint16_t servoMode; // Servo modes: 0=disabled, 1=sync/index, 2=jog
89 | } fastData_t;
90 |
91 | typedef struct {
92 | uint32_t executionInterval;
93 | uint32_t executionIntervalPrevious;
94 | uint32_t executionIntervalCurrent;
95 | uint32_t executionCycles;
96 | servo_t servo;
97 | input_t scales[SCALES_COUNT];
98 | fastData_t fastData;
99 | } rampsSharedData_t;
100 |
101 |
102 | typedef struct {
103 | // Modbus shared data
104 | rampsSharedData_t shared;
105 |
106 | // STM32 Related
107 | TIM_HandleTypeDef *synchroRefreshTimer;
108 | UART_HandleTypeDef *modbusUart;
109 |
110 | deltaPosError_t scalesDeltaPos[SCALES_COUNT];
111 | deltaPosError_t scalesSyncDeltaPos[SCALES_COUNT];
112 | deltaPosError_t scalesSpeed[SCALES_COUNT];
113 | deltaPosError_t rampsDeltaPos;
114 | uint32_t servoPreviousDirection;
115 | } rampsHandler_t;
116 |
117 | extern modbusHandler_t RampsModbusData;
118 |
119 | void RampsStart(rampsHandler_t *rampsData);
120 |
121 | void SynchroRefreshTimerIsr(rampsHandler_t *data);
122 |
123 | _Noreturn void updateSpeedTask(void *argument);
124 |
125 | _Noreturn void userLedTask(__attribute__((unused)) void *argument);
126 |
127 | _Noreturn void servoEnableTask(void *argument);
128 |
129 | //static void timServoEnableOnCallback(xTimerHandle pxTimer);
130 | //static void timServoEnableOffCallback(xTimerHandle pxTimer);
131 |
132 | #endif
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### C++ template
2 | # Prerequisites
3 | *.d
4 |
5 | # Compiled Object files
6 | *.slo
7 | *.lo
8 | *.o
9 | *.obj
10 |
11 | # Precompiled Headers
12 | *.gch
13 | *.pch
14 |
15 | # Compiled Dynamic libraries
16 | *.so
17 | *.dylib
18 | *.dll
19 |
20 | # Fortran module files
21 | *.mod
22 | *.smod
23 |
24 | # Compiled Static libraries
25 | *.lai
26 | *.la
27 | *.a
28 | *.lib
29 |
30 | # Executables
31 | *.exe
32 | *.out
33 | *.app
34 |
35 | ### C template
36 | # Prerequisites
37 | *.d
38 |
39 | # Object files
40 | *.o
41 | *.ko
42 | *.obj
43 | *.elf
44 |
45 | # Linker output
46 | *.ilk
47 | *.map
48 | *.exp
49 |
50 | # Precompiled Headers
51 | *.gch
52 | *.pch
53 |
54 | # Libraries
55 | *.lib
56 | *.a
57 | *.la
58 | *.lo
59 |
60 | # Shared objects (inc. Windows DLLs)
61 | *.dll
62 | *.so
63 | *.so.*
64 | *.dylib
65 |
66 | # Executables
67 | *.exe
68 | *.out
69 | *.app
70 | *.i*86
71 | *.x86_64
72 | *.hex
73 |
74 | # Debug files
75 | *.dSYM/
76 | *.su
77 | *.idb
78 | *.pdb
79 |
80 | # Kernel Module Compile Results
81 | *.mod*
82 | *.cmd
83 | .tmp_versions/
84 | modules.order
85 | Module.symvers
86 | Mkfile.old
87 | dkms.conf
88 |
89 | .idea
90 | /cmake-build-debug/
91 | /.settings/
92 | /Debug/
93 | /rotary-controller-f4.launch
94 | /Release/Core/Src/freertos.cyclo
95 | /Release/Core/Src/gpio.cyclo
96 | /Release/Core/Src/main.cyclo
97 | /Release/Core/Src/Modbus.cyclo
98 | /Release/Core/Src/Ramps.cyclo
99 | /Release/Core/Src/Scales.cyclo
100 | /Release/Core/Src/stm32f4xx_hal_msp.cyclo
101 | /Release/Core/Src/stm32f4xx_hal_timebase_tim.cyclo
102 | /Release/Core/Src/stm32f4xx_it.cyclo
103 | /Release/Core/Src/subdir.mk
104 | /Release/Core/Src/syscalls.cyclo
105 | /Release/Core/Src/sysmem.cyclo
106 | /Release/Core/Src/system_stm32f4xx.cyclo
107 | /Release/Core/Src/tim.cyclo
108 | /Release/Core/Src/UARTCallback.cyclo
109 | /Release/Core/Src/usart.cyclo
110 | /Release/Core/Startup/subdir.mk
111 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.cyclo
112 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.cyclo
113 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.cyclo
114 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.cyclo
115 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.cyclo
116 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.cyclo
117 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.cyclo
118 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.cyclo
119 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.cyclo
120 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.cyclo
121 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.cyclo
122 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.cyclo
123 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.cyclo
124 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.cyclo
125 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.cyclo
126 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.cyclo
127 | /Release/Drivers/STM32F4xx_HAL_Driver/Src/subdir.mk
128 | /Release/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.cyclo
129 | /Release/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/subdir.mk
130 | /Release/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.cyclo
131 | /Release/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/subdir.mk
132 | /Release/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.cyclo
133 | /Release/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/subdir.mk
134 | /Release/Middlewares/Third_Party/FreeRTOS/Source/croutine.cyclo
135 | /Release/Middlewares/Third_Party/FreeRTOS/Source/event_groups.cyclo
136 | /Release/Middlewares/Third_Party/FreeRTOS/Source/list.cyclo
137 | /Release/Middlewares/Third_Party/FreeRTOS/Source/queue.cyclo
138 | /Release/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.cyclo
139 | /Release/Middlewares/Third_Party/FreeRTOS/Source/subdir.mk
140 | /Release/Middlewares/Third_Party/FreeRTOS/Source/tasks.cyclo
141 | /Release/Middlewares/Third_Party/FreeRTOS/Source/timers.cyclo
142 | /Release/makefile
143 | /Release/objects.list
144 | /Release/objects.mk
145 | /Release/rotary-controller-f4.list
146 | /Release/sources.mk
147 |
--------------------------------------------------------------------------------
/Core/Src/UARTCallback.c:
--------------------------------------------------------------------------------
1 | /*
2 | * UARTCallback.c
3 | *
4 | * Created on: May 27, 2020
5 | * Author: Alejandro Mera
6 | */
7 |
8 | #include "FreeRTOS.h"
9 | #include "cmsis_os.h"
10 | #include "task.h"
11 | #include "main.h"
12 | #include "Modbus.h"
13 |
14 |
15 | /**
16 | * @brief
17 | * This is the callback for HAL interrupts of UART TX used by Modbus library.
18 | * This callback is shared among all UARTS, if more interrupts are used
19 | * user should implement the correct control flow and verification to maintain
20 | * Modbus functionality.
21 | * @ingroup UartHandle UART HAL handler
22 | */
23 |
24 | void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
25 | {
26 | /* Modbus RTU TX callback BEGIN */
27 | BaseType_t xHigherPriorityTaskWoken = pdFALSE;
28 | int i;
29 | for (i = 0; i < numberHandlers; i++ )
30 | {
31 | if (mHandlers[i]->port == huart )
32 | {
33 | // notify the end of TX
34 | xTaskNotifyFromISR(mHandlers[i]->myTaskModbusAHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
35 | break;
36 | }
37 |
38 | }
39 | portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
40 |
41 | /* Modbus RTU TX callback END */
42 |
43 | /*
44 | * Here you should implement the callback code for other UARTs not used by Modbus
45 | *
46 | * */
47 |
48 | }
49 |
50 |
51 |
52 | /**
53 | * @brief
54 | * This is the callback for HAL interrupt of UART RX
55 | * This callback is shared among all UARTS, if more interrupts are used
56 | * user should implement the correct control flow and verification to maintain
57 | * Modbus functionality.
58 | * @ingroup UartHandle UART HAL handler
59 | */
60 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
61 | {
62 | BaseType_t xHigherPriorityTaskWoken = pdFALSE;
63 |
64 | /* Modbus RTU RX callback BEGIN */
65 | int i;
66 | for (i = 0; i < numberHandlers; i++ )
67 | {
68 | if (mHandlers[i]->port == UartHandle )
69 | {
70 |
71 | if(mHandlers[i]->xTypeHW == USART_HW)
72 | {
73 | RingAdd(&mHandlers[i]->xBufferRX, mHandlers[i]->dataRX);
74 | HAL_UART_Receive_IT(mHandlers[i]->port, &mHandlers[i]->dataRX, 1);
75 | xTimerResetFromISR(mHandlers[i]->xTimerT35, &xHigherPriorityTaskWoken);
76 | }
77 | break;
78 | }
79 | }
80 | portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
81 |
82 | /* Modbus RTU RX callback END */
83 |
84 | /*
85 | * Here you should implement the callback code for other UARTs not used by Modbus
86 | *
87 | *
88 | * */
89 |
90 | }
91 |
92 |
93 | #if ENABLE_USART_DMA == 1
94 | /*
95 | * DMA requires to handle callbacks for special communication modes of the HAL
96 | * It also has to handle eventual errors including extra steps that are not automatically
97 | * handled by the HAL
98 | * */
99 |
100 |
101 | void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
102 | {
103 |
104 | int i;
105 |
106 | for (i = 0; i < numberHandlers; i++ )
107 | {
108 | if (mHandlers[i]->port == huart )
109 | {
110 |
111 | if(mHandlers[i]->xTypeHW == USART_HW_DMA)
112 | {
113 | while(HAL_UARTEx_ReceiveToIdle_DMA(mHandlers[i]->port, mHandlers[i]->xBufferRX.uxBuffer, MAX_BUFFER) != HAL_OK)
114 | {
115 | HAL_UART_DMAStop(mHandlers[i]->port);
116 | }
117 | __HAL_DMA_DISABLE_IT(mHandlers[i]->port->hdmarx, DMA_IT_HT); // we don't need half-transfer interrupt
118 |
119 | }
120 |
121 | break;
122 | }
123 | }
124 | }
125 |
126 |
127 | void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
128 | {
129 | BaseType_t xHigherPriorityTaskWoken = pdFALSE;
130 | /* Modbus RTU RX callback BEGIN */
131 | int i;
132 | for (i = 0; i < numberHandlers; i++ )
133 | {
134 | if (mHandlers[i]->port == huart )
135 | {
136 |
137 |
138 | if(mHandlers[i]->xTypeHW == USART_HW_DMA)
139 | {
140 | if(Size) //check if we have received any byte
141 | {
142 | mHandlers[i]->xBufferRX.u8available = Size;
143 | mHandlers[i]->xBufferRX.overflow = false;
144 |
145 | while(HAL_UARTEx_ReceiveToIdle_DMA(mHandlers[i]->port, mHandlers[i]->xBufferRX.uxBuffer, MAX_BUFFER) != HAL_OK)
146 | {
147 | HAL_UART_DMAStop(mHandlers[i]->port);
148 |
149 | }
150 | __HAL_DMA_DISABLE_IT(mHandlers[i]->port->hdmarx, DMA_IT_HT); // we don't need half-transfer interrupt
151 |
152 | xTaskNotifyFromISR(mHandlers[i]->myTaskModbusAHandle, 0 , eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
153 | }
154 | }
155 |
156 | break;
157 | }
158 | }
159 | portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
160 | }
161 |
162 | #endif
--------------------------------------------------------------------------------
/Core/Src/stm32f4xx_hal_timebase_tim.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file stm32f4xx_hal_timebase_TIM.c
5 | * @brief HAL time base based on the hardware TIM.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2022 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file
13 | * in the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | *
16 | ******************************************************************************
17 | */
18 | /* USER CODE END Header */
19 |
20 | /* Includes ------------------------------------------------------------------*/
21 | #include "stm32f4xx_hal.h"
22 | #include "stm32f4xx_hal_tim.h"
23 |
24 | /* Private typedef -----------------------------------------------------------*/
25 | /* Private define ------------------------------------------------------------*/
26 | /* Private macro -------------------------------------------------------------*/
27 | /* Private variables ---------------------------------------------------------*/
28 | TIM_HandleTypeDef htim11;
29 | /* Private function prototypes -----------------------------------------------*/
30 | /* Private functions ---------------------------------------------------------*/
31 |
32 | /**
33 | * @brief This function configures the TIM11 as a time base source.
34 | * The time source is configured to have 1ms time base with a dedicated
35 | * Tick interrupt priority.
36 | * @note This function is called automatically at the beginning of program after
37 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
38 | * @param TickPriority: Tick interrupt priority.
39 | * @retval HAL status
40 | */
41 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
42 | {
43 | RCC_ClkInitTypeDef clkconfig;
44 | uint32_t uwTimclock = 0U;
45 |
46 | uint32_t uwPrescalerValue = 0U;
47 | uint32_t pFLatency;
48 | HAL_StatusTypeDef status;
49 |
50 | /* Enable TIM11 clock */
51 | __HAL_RCC_TIM11_CLK_ENABLE();
52 |
53 | /* Get clock configuration */
54 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
55 |
56 | /* Compute TIM11 clock */
57 | uwTimclock = HAL_RCC_GetPCLK2Freq();
58 |
59 | /* Compute the prescaler value to have TIM11 counter clock equal to 1MHz */
60 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
61 |
62 | /* Initialize TIM11 */
63 | htim11.Instance = TIM11;
64 |
65 | /* Initialize TIMx peripheral as follow:
66 |
67 | + Period = [(TIM11CLK/1000) - 1]. to have a (1/1000) s time base.
68 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
69 | + ClockDivision = 0
70 | + Counter direction = Up
71 | */
72 | htim11.Init.Period = (1000000U / 1000U) - 1U;
73 | htim11.Init.Prescaler = uwPrescalerValue;
74 | htim11.Init.ClockDivision = 0;
75 | htim11.Init.CounterMode = TIM_COUNTERMODE_UP;
76 | htim11.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
77 |
78 | status = HAL_TIM_Base_Init(&htim11);
79 | if (status == HAL_OK)
80 | {
81 | /* Start the TIM time Base generation in interrupt mode */
82 | status = HAL_TIM_Base_Start_IT(&htim11);
83 | if (status == HAL_OK)
84 | {
85 | /* Enable the TIM11 global Interrupt */
86 | HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);
87 | /* Configure the SysTick IRQ priority */
88 | if (TickPriority < (1UL << __NVIC_PRIO_BITS))
89 | {
90 | /* Configure the TIM IRQ priority */
91 | HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn, TickPriority, 0U);
92 | uwTickPrio = TickPriority;
93 | }
94 | else
95 | {
96 | status = HAL_ERROR;
97 | }
98 | }
99 | }
100 |
101 | /* Return function status */
102 | return status;
103 | }
104 |
105 | /**
106 | * @brief Suspend Tick increment.
107 | * @note Disable the tick increment by disabling TIM11 update interrupt.
108 | * @param None
109 | * @retval None
110 | */
111 | void HAL_SuspendTick(void)
112 | {
113 | /* Disable TIM11 update Interrupt */
114 | __HAL_TIM_DISABLE_IT(&htim11, TIM_IT_UPDATE);
115 | }
116 |
117 | /**
118 | * @brief Resume Tick increment.
119 | * @note Enable the tick increment by Enabling TIM11 update interrupt.
120 | * @param None
121 | * @retval None
122 | */
123 | void HAL_ResumeTick(void)
124 | {
125 | /* Enable TIM11 Update interrupt */
126 | __HAL_TIM_ENABLE_IT(&htim11, TIM_IT_UPDATE);
127 | }
128 |
129 |
--------------------------------------------------------------------------------
/STM32F411CEUX_RAM.ld:
--------------------------------------------------------------------------------
1 | /*
2 | ******************************************************************************
3 | **
4 | ** @file : LinkerScript.ld (debug in RAM dedicated)
5 | **
6 | ** @author : Auto-generated by STM32CubeIDE
7 | **
8 | ** @brief : Linker script for STM32F411CEUx Device from STM32F4 series
9 | ** 512Kbytes FLASH
10 | ** 128Kbytes RAM
11 | **
12 | ** Set heap size, stack size and stack location according
13 | ** to application requirements.
14 | **
15 | ** Set memory bank area and size if external memory is used
16 | **
17 | ** Target : STMicroelectronics STM32
18 | **
19 | ** Distribution: The file is distributed as is, without any warranty
20 | ** of any kind.
21 | **
22 | ******************************************************************************
23 | ** @attention
24 | **
25 | ** Copyright (c) 2022 STMicroelectronics.
26 | ** All rights reserved.
27 | **
28 | ** This software is licensed under terms that can be found in the LICENSE file
29 | ** in the root directory of this software component.
30 | ** If no LICENSE file comes with this software, it is provided AS-IS.
31 | **
32 | ******************************************************************************
33 | */
34 |
35 | /* Entry Point */
36 | ENTRY(Reset_Handler)
37 |
38 | /* Highest address of the user mode stack */
39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
40 |
41 | _Min_Heap_Size = 0x200; /* required amount of heap */
42 | _Min_Stack_Size = 0x400; /* required amount of stack */
43 |
44 | /* Memories definition */
45 | MEMORY
46 | {
47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
48 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
49 | }
50 |
51 | /* Sections */
52 | SECTIONS
53 | {
54 | /* The startup code into "RAM" Ram type memory */
55 | .isr_vector :
56 | {
57 | . = ALIGN(4);
58 | KEEP(*(.isr_vector)) /* Startup code */
59 | . = ALIGN(4);
60 | } >RAM
61 |
62 | /* The program code and other data into "RAM" Ram type memory */
63 | .text :
64 | {
65 | . = ALIGN(4);
66 | *(.text) /* .text sections (code) */
67 | *(.text*) /* .text* sections (code) */
68 | *(.glue_7) /* glue arm to thumb code */
69 | *(.glue_7t) /* glue thumb to arm code */
70 | *(.eh_frame)
71 | *(.RamFunc) /* .RamFunc sections */
72 | *(.RamFunc*) /* .RamFunc* sections */
73 |
74 | KEEP (*(.init))
75 | KEEP (*(.fini))
76 |
77 | . = ALIGN(4);
78 | _etext = .; /* define a global symbols at end of code */
79 | } >RAM
80 |
81 | /* Constant data into "RAM" Ram type memory */
82 | .rodata :
83 | {
84 | . = ALIGN(4);
85 | *(.rodata) /* .rodata sections (constants, strings, etc.) */
86 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
87 | . = ALIGN(4);
88 | } >RAM
89 |
90 | .ARM.extab : {
91 | . = ALIGN(4);
92 | *(.ARM.extab* .gnu.linkonce.armextab.*)
93 | . = ALIGN(4);
94 | } >RAM
95 |
96 | .ARM : {
97 | . = ALIGN(4);
98 | __exidx_start = .;
99 | *(.ARM.exidx*)
100 | __exidx_end = .;
101 | . = ALIGN(4);
102 | } >RAM
103 |
104 | .preinit_array :
105 | {
106 | . = ALIGN(4);
107 | PROVIDE_HIDDEN (__preinit_array_start = .);
108 | KEEP (*(.preinit_array*))
109 | PROVIDE_HIDDEN (__preinit_array_end = .);
110 | . = ALIGN(4);
111 | } >RAM
112 |
113 | .init_array :
114 | {
115 | . = ALIGN(4);
116 | PROVIDE_HIDDEN (__init_array_start = .);
117 | KEEP (*(SORT(.init_array.*)))
118 | KEEP (*(.init_array*))
119 | PROVIDE_HIDDEN (__init_array_end = .);
120 | . = ALIGN(4);
121 | } >RAM
122 |
123 | .fini_array :
124 | {
125 | . = ALIGN(4);
126 | PROVIDE_HIDDEN (__fini_array_start = .);
127 | KEEP (*(SORT(.fini_array.*)))
128 | KEEP (*(.fini_array*))
129 | PROVIDE_HIDDEN (__fini_array_end = .);
130 | . = ALIGN(4);
131 | } >RAM
132 |
133 | /* Used by the startup to initialize data */
134 | _sidata = LOADADDR(.data);
135 |
136 | /* Initialized data sections into "RAM" Ram type memory */
137 | .data :
138 | {
139 | . = ALIGN(4);
140 | _sdata = .; /* create a global symbol at data start */
141 | *(.data) /* .data sections */
142 | *(.data*) /* .data* sections */
143 |
144 | . = ALIGN(4);
145 | _edata = .; /* define a global symbol at data end */
146 |
147 | } >RAM
148 |
149 | /* Uninitialized data section into "RAM" Ram type memory */
150 | . = ALIGN(4);
151 | .bss :
152 | {
153 | /* This is used by the startup in order to initialize the .bss section */
154 | _sbss = .; /* define a global symbol at bss start */
155 | __bss_start__ = _sbss;
156 | *(.bss)
157 | *(.bss*)
158 | *(COMMON)
159 |
160 | . = ALIGN(4);
161 | _ebss = .; /* define a global symbol at bss end */
162 | __bss_end__ = _ebss;
163 | } >RAM
164 |
165 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
166 | ._user_heap_stack :
167 | {
168 | . = ALIGN(8);
169 | PROVIDE ( end = . );
170 | PROVIDE ( _end = . );
171 | . = . + _Min_Heap_Size;
172 | . = . + _Min_Stack_Size;
173 | . = ALIGN(8);
174 | } >RAM
175 |
176 | /* Remove information from the compiler libraries */
177 | /DISCARD/ :
178 | {
179 | libc.a ( * )
180 | libm.a ( * )
181 | libgcc.a ( * )
182 | }
183 |
184 | .ARM.attributes 0 : { *(.ARM.attributes) }
185 | }
186 |
--------------------------------------------------------------------------------
/STM32F411CEUX_FLASH.ld:
--------------------------------------------------------------------------------
1 | /*
2 | ******************************************************************************
3 | **
4 | ** @file : LinkerScript.ld
5 | **
6 | ** @author : Auto-generated by STM32CubeIDE
7 | **
8 | ** @brief : Linker script for STM32F411CEUx Device from STM32F4 series
9 | ** 512Kbytes FLASH
10 | ** 128Kbytes RAM
11 | **
12 | ** Set heap size, stack size and stack location according
13 | ** to application requirements.
14 | **
15 | ** Set memory bank area and size if external memory is used
16 | **
17 | ** Target : STMicroelectronics STM32
18 | **
19 | ** Distribution: The file is distributed as is, without any warranty
20 | ** of any kind.
21 | **
22 | ******************************************************************************
23 | ** @attention
24 | **
25 | ** Copyright (c) 2022 STMicroelectronics.
26 | ** All rights reserved.
27 | **
28 | ** This software is licensed under terms that can be found in the LICENSE file
29 | ** in the root directory of this software component.
30 | ** If no LICENSE file comes with this software, it is provided AS-IS.
31 | **
32 | ******************************************************************************
33 | */
34 |
35 | /* Entry Point */
36 | ENTRY(Reset_Handler)
37 |
38 | /* Highest address of the user mode stack */
39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
40 |
41 | _Min_Heap_Size = 0x200; /* required amount of heap */
42 | _Min_Stack_Size = 0x400; /* required amount of stack */
43 |
44 | /* Memories definition */
45 | MEMORY
46 | {
47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
48 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
49 | }
50 |
51 | /* Sections */
52 | SECTIONS
53 | {
54 | /* The startup code into "FLASH" Rom type memory */
55 | .isr_vector :
56 | {
57 | . = ALIGN(4);
58 | KEEP(*(.isr_vector)) /* Startup code */
59 | . = ALIGN(4);
60 | } >FLASH
61 |
62 | /* The program code and other data into "FLASH" Rom type memory */
63 | .text :
64 | {
65 | . = ALIGN(4);
66 | *(.text) /* .text sections (code) */
67 | *(.text*) /* .text* sections (code) */
68 | *(.glue_7) /* glue arm to thumb code */
69 | *(.glue_7t) /* glue thumb to arm code */
70 | *(.eh_frame)
71 |
72 | KEEP (*(.init))
73 | KEEP (*(.fini))
74 |
75 | . = ALIGN(4);
76 | _etext = .; /* define a global symbols at end of code */
77 | } >FLASH
78 |
79 | /* Constant data into "FLASH" Rom type memory */
80 | .rodata :
81 | {
82 | . = ALIGN(4);
83 | *(.rodata) /* .rodata sections (constants, strings, etc.) */
84 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
85 | . = ALIGN(4);
86 | } >FLASH
87 |
88 | .ARM.extab : {
89 | . = ALIGN(4);
90 | *(.ARM.extab* .gnu.linkonce.armextab.*)
91 | . = ALIGN(4);
92 | } >FLASH
93 |
94 | .ARM : {
95 | . = ALIGN(4);
96 | __exidx_start = .;
97 | *(.ARM.exidx*)
98 | __exidx_end = .;
99 | . = ALIGN(4);
100 | } >FLASH
101 |
102 | .preinit_array :
103 | {
104 | . = ALIGN(4);
105 | PROVIDE_HIDDEN (__preinit_array_start = .);
106 | KEEP (*(.preinit_array*))
107 | PROVIDE_HIDDEN (__preinit_array_end = .);
108 | . = ALIGN(4);
109 | } >FLASH
110 |
111 | .init_array :
112 | {
113 | . = ALIGN(4);
114 | PROVIDE_HIDDEN (__init_array_start = .);
115 | KEEP (*(SORT(.init_array.*)))
116 | KEEP (*(.init_array*))
117 | PROVIDE_HIDDEN (__init_array_end = .);
118 | . = ALIGN(4);
119 | } >FLASH
120 |
121 | .fini_array :
122 | {
123 | . = ALIGN(4);
124 | PROVIDE_HIDDEN (__fini_array_start = .);
125 | KEEP (*(SORT(.fini_array.*)))
126 | KEEP (*(.fini_array*))
127 | PROVIDE_HIDDEN (__fini_array_end = .);
128 | . = ALIGN(4);
129 | } >FLASH
130 |
131 | /* Used by the startup to initialize data */
132 | _sidata = LOADADDR(.data);
133 |
134 | /* Initialized data sections into "RAM" Ram type memory */
135 | .data :
136 | {
137 | . = ALIGN(4);
138 | _sdata = .; /* create a global symbol at data start */
139 | *(.data) /* .data sections */
140 | *(.data*) /* .data* sections */
141 | *(.RamFunc) /* .RamFunc sections */
142 | *(.RamFunc*) /* .RamFunc* sections */
143 |
144 | . = ALIGN(4);
145 | _edata = .; /* define a global symbol at data end */
146 |
147 | } >RAM AT> FLASH
148 |
149 | /* Uninitialized data section into "RAM" Ram type memory */
150 | . = ALIGN(4);
151 | .bss :
152 | {
153 | /* This is used by the startup in order to initialize the .bss section */
154 | _sbss = .; /* define a global symbol at bss start */
155 | __bss_start__ = _sbss;
156 | *(.bss)
157 | *(.bss*)
158 | *(COMMON)
159 |
160 | . = ALIGN(4);
161 | _ebss = .; /* define a global symbol at bss end */
162 | __bss_end__ = _ebss;
163 | } >RAM
164 |
165 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
166 | ._user_heap_stack :
167 | {
168 | . = ALIGN(8);
169 | PROVIDE ( end = . );
170 | PROVIDE ( _end = . );
171 | . = . + _Min_Heap_Size;
172 | . = . + _Min_Stack_Size;
173 | . = ALIGN(8);
174 | } >RAM
175 |
176 | /* Remove information from the compiler libraries */
177 | /DISCARD/ :
178 | {
179 | libc.a ( * )
180 | libm.a ( * )
181 | libgcc.a ( * )
182 | }
183 |
184 | .ARM.attributes 0 : { *(.ARM.attributes) }
185 | }
186 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/include/projdefs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeRTOS Kernel V10.3.1
3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to
8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | * the Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | *
22 | * http://www.FreeRTOS.org
23 | * http://aws.amazon.com/freertos
24 | *
25 | * 1 tab == 4 spaces!
26 | */
27 |
28 | #ifndef PROJDEFS_H
29 | #define PROJDEFS_H
30 |
31 | /*
32 | * Defines the prototype to which task functions must conform. Defined in this
33 | * file to ensure the type is known before portable.h is included.
34 | */
35 | typedef void (*TaskFunction_t)( void * );
36 |
37 | /* Converts a time in milliseconds to a time in ticks. This macro can be
38 | overridden by a macro of the same name defined in FreeRTOSConfig.h in case the
39 | definition here is not suitable for your application. */
40 | #ifndef pdMS_TO_TICKS
41 | #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) )
42 | #endif
43 |
44 | #define pdFALSE ( ( BaseType_t ) 0 )
45 | #define pdTRUE ( ( BaseType_t ) 1 )
46 |
47 | #define pdPASS ( pdTRUE )
48 | #define pdFAIL ( pdFALSE )
49 | #define errQUEUE_EMPTY ( ( BaseType_t ) 0 )
50 | #define errQUEUE_FULL ( ( BaseType_t ) 0 )
51 |
52 | /* FreeRTOS error definitions. */
53 | #define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 )
54 | #define errQUEUE_BLOCKED ( -4 )
55 | #define errQUEUE_YIELD ( -5 )
56 |
57 | /* Macros used for basic data corruption checks. */
58 | #ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES
59 | #define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0
60 | #endif
61 |
62 | #if( configUSE_16_BIT_TICKS == 1 )
63 | #define pdINTEGRITY_CHECK_VALUE 0x5a5a
64 | #else
65 | #define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL
66 | #endif
67 |
68 | /* The following errno values are used by FreeRTOS+ components, not FreeRTOS
69 | itself. */
70 | #define pdFREERTOS_ERRNO_NONE 0 /* No errors */
71 | #define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */
72 | #define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */
73 | #define pdFREERTOS_ERRNO_EIO 5 /* I/O error */
74 | #define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */
75 | #define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */
76 | #define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */
77 | #define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */
78 | #define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */
79 | #define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */
80 | #define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */
81 | #define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */
82 | #define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */
83 | #define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */
84 | #define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */
85 | #define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */
86 | #define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */
87 | #define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */
88 | #define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */
89 | #define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */
90 | #define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */
91 | #define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */
92 | #define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */
93 | #define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */
94 | #define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */
95 | #define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */
96 | #define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */
97 | #define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
98 | #define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */
99 | #define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */
100 | #define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */
101 | #define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */
102 | #define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */
103 | #define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */
104 | #define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */
105 | #define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */
106 | #define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */
107 | #define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */
108 | #define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */
109 | #define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */
110 |
111 | /* The following endian values are used by FreeRTOS+ components, not FreeRTOS
112 | itself. */
113 | #define pdFREERTOS_LITTLE_ENDIAN 0
114 | #define pdFREERTOS_BIG_ENDIAN 1
115 |
116 | /* Re-defining endian values for generic naming. */
117 | #define pdLITTLE_ENDIAN pdFREERTOS_LITTLE_ENDIAN
118 | #define pdBIG_ENDIAN pdFREERTOS_BIG_ENDIAN
119 |
120 |
121 | #endif /* PROJDEFS_H */
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/include/stack_macros.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeRTOS Kernel V10.3.1
3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to
8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | * the Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | *
22 | * http://www.FreeRTOS.org
23 | * http://aws.amazon.com/freertos
24 | *
25 | * 1 tab == 4 spaces!
26 | */
27 |
28 | #ifndef STACK_MACROS_H
29 | #define STACK_MACROS_H
30 |
31 | /*
32 | * Call the stack overflow hook function if the stack of the task being swapped
33 | * out is currently overflowed, or looks like it might have overflowed in the
34 | * past.
35 | *
36 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
37 | * the current stack state only - comparing the current top of stack value to
38 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
39 | * will also cause the last few stack bytes to be checked to ensure the value
40 | * to which the bytes were set when the task was created have not been
41 | * overwritten. Note this second test does not guarantee that an overflowed
42 | * stack will always be recognised.
43 | */
44 |
45 | /*-----------------------------------------------------------*/
46 |
47 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )
48 |
49 | /* Only the current stack state is to be checked. */
50 | #define taskCHECK_FOR_STACK_OVERFLOW() \
51 | { \
52 | /* Is the currently saved stack pointer within the stack limit? */ \
53 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
54 | { \
55 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
56 | } \
57 | }
58 |
59 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
60 | /*-----------------------------------------------------------*/
61 |
62 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )
63 |
64 | /* Only the current stack state is to be checked. */
65 | #define taskCHECK_FOR_STACK_OVERFLOW() \
66 | { \
67 | \
68 | /* Is the currently saved stack pointer within the stack limit? */ \
69 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
70 | { \
71 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
72 | } \
73 | }
74 |
75 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
76 | /*-----------------------------------------------------------*/
77 |
78 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
79 |
80 | #define taskCHECK_FOR_STACK_OVERFLOW() \
81 | { \
82 | const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
83 | const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \
84 | \
85 | if( ( pulStack[ 0 ] != ulCheckValue ) || \
86 | ( pulStack[ 1 ] != ulCheckValue ) || \
87 | ( pulStack[ 2 ] != ulCheckValue ) || \
88 | ( pulStack[ 3 ] != ulCheckValue ) ) \
89 | { \
90 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
91 | } \
92 | }
93 |
94 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
95 | /*-----------------------------------------------------------*/
96 |
97 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
98 |
99 | #define taskCHECK_FOR_STACK_OVERFLOW() \
100 | { \
101 | int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
102 | static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
103 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
104 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
105 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
106 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
107 | \
108 | \
109 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
110 | \
111 | /* Has the extremity of the task stack ever been written over? */ \
112 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
113 | { \
114 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
115 | } \
116 | }
117 |
118 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
119 | /*-----------------------------------------------------------*/
120 |
121 | /* Remove stack overflow macro if not being used. */
122 | #ifndef taskCHECK_FOR_STACK_OVERFLOW
123 | #define taskCHECK_FOR_STACK_OVERFLOW()
124 | #endif
125 |
126 |
127 |
128 | #endif /* STACK_MACROS_H */
129 |
130 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/include/StackMacros.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeRTOS Kernel V10.3.1
3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to
8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | * the Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | *
22 | * http://www.FreeRTOS.org
23 | * http://aws.amazon.com/freertos
24 | *
25 | * 1 tab == 4 spaces!
26 | */
27 |
28 | #ifndef STACK_MACROS_H
29 | #define STACK_MACROS_H
30 |
31 | #ifndef _MSC_VER /* Visual Studio doesn't support #warning. */
32 | #warning The name of this file has changed to stack_macros.h. Please update your code accordingly. This source file (which has the original name) will be removed in future released.
33 | #endif
34 |
35 | /*
36 | * Call the stack overflow hook function if the stack of the task being swapped
37 | * out is currently overflowed, or looks like it might have overflowed in the
38 | * past.
39 | *
40 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
41 | * the current stack state only - comparing the current top of stack value to
42 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
43 | * will also cause the last few stack bytes to be checked to ensure the value
44 | * to which the bytes were set when the task was created have not been
45 | * overwritten. Note this second test does not guarantee that an overflowed
46 | * stack will always be recognised.
47 | */
48 |
49 | /*-----------------------------------------------------------*/
50 |
51 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )
52 |
53 | /* Only the current stack state is to be checked. */
54 | #define taskCHECK_FOR_STACK_OVERFLOW() \
55 | { \
56 | /* Is the currently saved stack pointer within the stack limit? */ \
57 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
58 | { \
59 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
60 | } \
61 | }
62 |
63 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
64 | /*-----------------------------------------------------------*/
65 |
66 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )
67 |
68 | /* Only the current stack state is to be checked. */
69 | #define taskCHECK_FOR_STACK_OVERFLOW() \
70 | { \
71 | \
72 | /* Is the currently saved stack pointer within the stack limit? */ \
73 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
74 | { \
75 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
76 | } \
77 | }
78 |
79 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
80 | /*-----------------------------------------------------------*/
81 |
82 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
83 |
84 | #define taskCHECK_FOR_STACK_OVERFLOW() \
85 | { \
86 | const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
87 | const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \
88 | \
89 | if( ( pulStack[ 0 ] != ulCheckValue ) || \
90 | ( pulStack[ 1 ] != ulCheckValue ) || \
91 | ( pulStack[ 2 ] != ulCheckValue ) || \
92 | ( pulStack[ 3 ] != ulCheckValue ) ) \
93 | { \
94 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
95 | } \
96 | }
97 |
98 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
99 | /*-----------------------------------------------------------*/
100 |
101 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
102 |
103 | #define taskCHECK_FOR_STACK_OVERFLOW() \
104 | { \
105 | int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
106 | static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
107 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
108 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
109 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
110 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
111 | \
112 | \
113 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
114 | \
115 | /* Has the extremity of the task stack ever been written over? */ \
116 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
117 | { \
118 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
119 | } \
120 | }
121 |
122 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
123 | /*-----------------------------------------------------------*/
124 |
125 | /* Remove stack overflow macro if not being used. */
126 | #ifndef taskCHECK_FOR_STACK_OVERFLOW
127 | #define taskCHECK_FOR_STACK_OVERFLOW()
128 | #endif
129 |
130 |
131 |
132 | #endif /* STACK_MACROS_H */
133 |
134 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_flash_ramfunc.c
4 | * @author MCD Application Team
5 | * @brief FLASH RAMFUNC module driver.
6 | * This file provides a FLASH firmware functions which should be
7 | * executed from internal SRAM
8 | * + Stop/Start the flash interface while System Run
9 | * + Enable/Disable the flash sleep while System Run
10 | @verbatim
11 | ==============================================================================
12 | ##### APIs executed from Internal RAM #####
13 | ==============================================================================
14 | [..]
15 | *** ARM Compiler ***
16 | --------------------
17 | [..] RAM functions are defined using the toolchain options.
18 | Functions that are be executed in RAM should reside in a separate
19 | source module. Using the 'Options for File' dialog you can simply change
20 | the 'Code / Const' area of a module to a memory space in physical RAM.
21 | Available memory areas are declared in the 'Target' tab of the
22 | Options for Target' dialog.
23 |
24 | *** ICCARM Compiler ***
25 | -----------------------
26 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".
27 |
28 | *** GNU Compiler ***
29 | --------------------
30 | [..] RAM functions are defined using a specific toolchain attribute
31 | "__attribute__((section(".RamFunc")))".
32 |
33 | @endverbatim
34 | ******************************************************************************
35 | * @attention
36 | *
37 | * Copyright (c) 2017 STMicroelectronics.
38 | * All rights reserved.
39 | *
40 | * This software is licensed under terms that can be found in the LICENSE file in
41 | * the root directory of this software component.
42 | * If no LICENSE file comes with this software, it is provided AS-IS.
43 | ******************************************************************************
44 | */
45 |
46 | /* Includes ------------------------------------------------------------------*/
47 | #include "stm32f4xx_hal.h"
48 |
49 | /** @addtogroup STM32F4xx_HAL_Driver
50 | * @{
51 | */
52 |
53 | /** @defgroup FLASH_RAMFUNC FLASH RAMFUNC
54 | * @brief FLASH functions executed from RAM
55 | * @{
56 | */
57 | #ifdef HAL_FLASH_MODULE_ENABLED
58 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
59 | defined(STM32F412Rx) || defined(STM32F412Cx)
60 |
61 | /* Private typedef -----------------------------------------------------------*/
62 | /* Private define ------------------------------------------------------------*/
63 | /* Private macro -------------------------------------------------------------*/
64 | /* Private variables ---------------------------------------------------------*/
65 | /* Private function prototypes -----------------------------------------------*/
66 | /* Exported functions --------------------------------------------------------*/
67 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions
68 | * @{
69 | */
70 |
71 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM
72 | * @brief Peripheral Extended features functions
73 | *
74 | @verbatim
75 |
76 | ===============================================================================
77 | ##### ramfunc functions #####
78 | ===============================================================================
79 | [..]
80 | This subsection provides a set of functions that should be executed from RAM
81 | transfers.
82 |
83 | @endverbatim
84 | * @{
85 | */
86 |
87 | /**
88 | * @brief Stop the flash interface while System Run
89 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
90 | * @note This mode couldn't be set while executing with the flash itself.
91 | * It should be done with specific routine executed from RAM.
92 | * @retval HAL status
93 | */
94 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void)
95 | {
96 | /* Enable Power ctrl clock */
97 | __HAL_RCC_PWR_CLK_ENABLE();
98 | /* Stop the flash interface while System Run */
99 | SET_BIT(PWR->CR, PWR_CR_FISSR);
100 |
101 | return HAL_OK;
102 | }
103 |
104 | /**
105 | * @brief Start the flash interface while System Run
106 | * @note This mode is only available for STM32F411xx/STM32F446xx devices.
107 | * @note This mode couldn't be set while executing with the flash itself.
108 | * It should be done with specific routine executed from RAM.
109 | * @retval HAL status
110 | */
111 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void)
112 | {
113 | /* Enable Power ctrl clock */
114 | __HAL_RCC_PWR_CLK_ENABLE();
115 | /* Start the flash interface while System Run */
116 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR);
117 |
118 | return HAL_OK;
119 | }
120 |
121 | /**
122 | * @brief Enable the flash sleep while System Run
123 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
124 | * @note This mode could n't be set while executing with the flash itself.
125 | * It should be done with specific routine executed from RAM.
126 | * @retval HAL status
127 | */
128 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void)
129 | {
130 | /* Enable Power ctrl clock */
131 | __HAL_RCC_PWR_CLK_ENABLE();
132 | /* Enable the flash sleep while System Run */
133 | SET_BIT(PWR->CR, PWR_CR_FMSSR);
134 |
135 | return HAL_OK;
136 | }
137 |
138 | /**
139 | * @brief Disable the flash sleep while System Run
140 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices.
141 | * @note This mode couldn't be set while executing with the flash itself.
142 | * It should be done with specific routine executed from RAM.
143 | * @retval HAL status
144 | */
145 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void)
146 | {
147 | /* Enable Power ctrl clock */
148 | __HAL_RCC_PWR_CLK_ENABLE();
149 | /* Disable the flash sleep while System Run */
150 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR);
151 |
152 | return HAL_OK;
153 | }
154 |
155 | /**
156 | * @}
157 | */
158 |
159 | /**
160 | * @}
161 | */
162 |
163 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
164 | #endif /* HAL_FLASH_MODULE_ENABLED */
165 | /**
166 | * @}
167 | */
168 |
169 | /**
170 | * @}
171 | */
172 |
173 |
--------------------------------------------------------------------------------
/Core/Src/stm32f4xx_it.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file stm32f4xx_it.c
5 | * @brief Interrupt Service Routines.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2022 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file
13 | * in the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | *
16 | ******************************************************************************
17 | */
18 | /* USER CODE END Header */
19 |
20 | /* Includes ------------------------------------------------------------------*/
21 | #include "main.h"
22 | #include "stm32f4xx_it.h"
23 | /* Private includes ----------------------------------------------------------*/
24 | /* USER CODE BEGIN Includes */
25 | /* USER CODE END Includes */
26 |
27 | /* Private typedef -----------------------------------------------------------*/
28 | /* USER CODE BEGIN TD */
29 |
30 | /* USER CODE END TD */
31 |
32 | /* Private define ------------------------------------------------------------*/
33 | /* USER CODE BEGIN PD */
34 |
35 | /* USER CODE END PD */
36 |
37 | /* Private macro -------------------------------------------------------------*/
38 | /* USER CODE BEGIN PM */
39 |
40 | /* USER CODE END PM */
41 |
42 | /* Private variables ---------------------------------------------------------*/
43 | /* USER CODE BEGIN PV */
44 | extern rampsHandler_t RampsData;
45 | /* USER CODE END PV */
46 |
47 | /* Private function prototypes -----------------------------------------------*/
48 | /* USER CODE BEGIN PFP */
49 |
50 | /* USER CODE END PFP */
51 |
52 | /* Private user code ---------------------------------------------------------*/
53 | /* USER CODE BEGIN 0 */
54 |
55 | /* USER CODE END 0 */
56 |
57 | /* External variables --------------------------------------------------------*/
58 | extern TIM_HandleTypeDef htim1;
59 | extern TIM_HandleTypeDef htim9;
60 | extern UART_HandleTypeDef huart1;
61 | extern TIM_HandleTypeDef htim11;
62 |
63 | /* USER CODE BEGIN EV */
64 |
65 | /* USER CODE END EV */
66 |
67 | /******************************************************************************/
68 | /* Cortex-M4 Processor Interruption and Exception Handlers */
69 | /******************************************************************************/
70 | /**
71 | * @brief This function handles Non maskable interrupt.
72 | */
73 | void NMI_Handler(void)
74 | {
75 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
76 |
77 | /* USER CODE END NonMaskableInt_IRQn 0 */
78 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
79 | while (1)
80 | {
81 | }
82 | /* USER CODE END NonMaskableInt_IRQn 1 */
83 | }
84 |
85 | /**
86 | * @brief This function handles Hard fault interrupt.
87 | */
88 | void HardFault_Handler(void)
89 | {
90 | /* USER CODE BEGIN HardFault_IRQn 0 */
91 |
92 | /* USER CODE END HardFault_IRQn 0 */
93 | while (1)
94 | {
95 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */
96 | /* USER CODE END W1_HardFault_IRQn 0 */
97 | }
98 | }
99 |
100 | /**
101 | * @brief This function handles Memory management fault.
102 | */
103 | void MemManage_Handler(void)
104 | {
105 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */
106 |
107 | /* USER CODE END MemoryManagement_IRQn 0 */
108 | while (1)
109 | {
110 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
111 | /* USER CODE END W1_MemoryManagement_IRQn 0 */
112 | }
113 | }
114 |
115 | /**
116 | * @brief This function handles Pre-fetch fault, memory access fault.
117 | */
118 | void BusFault_Handler(void)
119 | {
120 | /* USER CODE BEGIN BusFault_IRQn 0 */
121 |
122 | /* USER CODE END BusFault_IRQn 0 */
123 | while (1)
124 | {
125 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */
126 | /* USER CODE END W1_BusFault_IRQn 0 */
127 | }
128 | }
129 |
130 | /**
131 | * @brief This function handles Undefined instruction or illegal state.
132 | */
133 | void UsageFault_Handler(void)
134 | {
135 | /* USER CODE BEGIN UsageFault_IRQn 0 */
136 |
137 | /* USER CODE END UsageFault_IRQn 0 */
138 | while (1)
139 | {
140 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
141 | /* USER CODE END W1_UsageFault_IRQn 0 */
142 | }
143 | }
144 |
145 | /**
146 | * @brief This function handles Debug monitor.
147 | */
148 | void DebugMon_Handler(void)
149 | {
150 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */
151 |
152 | /* USER CODE END DebugMonitor_IRQn 0 */
153 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */
154 |
155 | /* USER CODE END DebugMonitor_IRQn 1 */
156 | }
157 |
158 | /******************************************************************************/
159 | /* STM32F4xx Peripheral Interrupt Handlers */
160 | /* Add here the Interrupt Handlers for the used peripherals. */
161 | /* For the available peripheral interrupt handler names, */
162 | /* please refer to the startup file (startup_stm32f4xx.s). */
163 | /******************************************************************************/
164 |
165 | /**
166 | * @brief This function handles TIM1 break interrupt and TIM9 global interrupt.
167 | */
168 | void TIM1_BRK_TIM9_IRQHandler(void)
169 | {
170 | /* USER CODE BEGIN TIM1_BRK_TIM9_IRQn 0 */
171 |
172 | /* USER CODE END TIM1_BRK_TIM9_IRQn 0 */
173 | HAL_TIM_IRQHandler(&htim1);
174 | HAL_TIM_IRQHandler(&htim9);
175 | /* USER CODE BEGIN TIM1_BRK_TIM9_IRQn 1 */
176 | SynchroRefreshTimerIsr(&RampsData);
177 | /* USER CODE END TIM1_BRK_TIM9_IRQn 1 */
178 | }
179 |
180 | /**
181 | * @brief This function handles TIM1 update interrupt and TIM10 global interrupt.
182 | */
183 | void TIM1_UP_TIM10_IRQHandler(void)
184 | {
185 | /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
186 |
187 | /* USER CODE END TIM1_UP_TIM10_IRQn 0 */
188 | HAL_TIM_IRQHandler(&htim1);
189 | /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
190 | /* USER CODE END TIM1_UP_TIM10_IRQn 1 */
191 | }
192 |
193 | /**
194 | * @brief This function handles TIM1 trigger and commutation interrupts and TIM11 global interrupt.
195 | */
196 | void TIM1_TRG_COM_TIM11_IRQHandler(void)
197 | {
198 | /* USER CODE BEGIN TIM1_TRG_COM_TIM11_IRQn 0 */
199 |
200 | /* USER CODE END TIM1_TRG_COM_TIM11_IRQn 0 */
201 | HAL_TIM_IRQHandler(&htim1);
202 | HAL_TIM_IRQHandler(&htim11);
203 | /* USER CODE BEGIN TIM1_TRG_COM_TIM11_IRQn 1 */
204 |
205 | /* USER CODE END TIM1_TRG_COM_TIM11_IRQn 1 */
206 | }
207 |
208 | /**
209 | * @brief This function handles USART1 global interrupt.
210 | */
211 | void USART1_IRQHandler(void)
212 | {
213 | /* USER CODE BEGIN USART1_IRQn 0 */
214 |
215 | /* USER CODE END USART1_IRQn 0 */
216 | HAL_UART_IRQHandler(&huart1);
217 | /* USER CODE BEGIN USART1_IRQn 1 */
218 |
219 | /* USER CODE END USART1_IRQn 1 */
220 | }
221 |
222 | /* USER CODE BEGIN 1 */
223 |
224 | /* USER CODE END 1 */
225 |
--------------------------------------------------------------------------------
/Core/Src/main.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file : main.c
5 | * @brief : Main program body
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2022 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file
13 | * in the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | *
16 | ******************************************************************************
17 | */
18 | /* USER CODE END Header */
19 | /* Includes ------------------------------------------------------------------*/
20 | #include "main.h"
21 | #include "cmsis_os.h"
22 | #include "tim.h"
23 | #include "usart.h"
24 | #include "gpio.h"
25 |
26 | /* Private includes ----------------------------------------------------------*/
27 | /* USER CODE BEGIN Includes */
28 |
29 | /* USER CODE END Includes */
30 |
31 | /* Private typedef -----------------------------------------------------------*/
32 | /* USER CODE BEGIN PTD */
33 |
34 | /* USER CODE END PTD */
35 |
36 | /* Private define ------------------------------------------------------------*/
37 | /* USER CODE BEGIN PD */
38 | /* USER CODE END PD */
39 |
40 | /* Private macro -------------------------------------------------------------*/
41 | /* USER CODE BEGIN PM */
42 |
43 | /* USER CODE END PM */
44 |
45 | /* Private variables ---------------------------------------------------------*/
46 |
47 | /* USER CODE BEGIN PV */
48 | rampsHandler_t RampsData;
49 | /* USER CODE END PV */
50 |
51 | /* Private function prototypes -----------------------------------------------*/
52 | void SystemClock_Config(void);
53 | void MX_FREERTOS_Init(void);
54 | /* USER CODE BEGIN PFP */
55 |
56 | /* USER CODE END PFP */
57 |
58 | /* Private user code ---------------------------------------------------------*/
59 | /* USER CODE BEGIN 0 */
60 |
61 | /* USER CODE END 0 */
62 |
63 | /**
64 | * @brief The application entry point.
65 | * @retval int
66 | */
67 | int main(void)
68 | {
69 | /* USER CODE BEGIN 1 */
70 |
71 | /* USER CODE END 1 */
72 |
73 | /* MCU Configuration--------------------------------------------------------*/
74 |
75 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
76 | HAL_Init();
77 |
78 | /* USER CODE BEGIN Init */
79 |
80 | /* USER CODE END Init */
81 |
82 | /* Configure the system clock */
83 | SystemClock_Config();
84 |
85 | /* USER CODE BEGIN SysInit */
86 |
87 | /* USER CODE END SysInit */
88 |
89 | /* Initialize all configured peripherals */
90 | MX_GPIO_Init();
91 | MX_TIM1_Init();
92 | MX_TIM2_Init();
93 | MX_TIM3_Init();
94 | MX_TIM4_Init();
95 | MX_USART1_UART_Init();
96 | MX_TIM9_Init();
97 | /* USER CODE BEGIN 2 */
98 | // htim1 is used in encoder mode
99 | // htim2 is used in encoder mode
100 | // htim3 is used in encoder mode
101 | // htim4 is used in encoder mode
102 | // htim9 is used to generate the synchro motion
103 |
104 | RampsData.shared.scales[0].timerHandle = &htim1;
105 | RampsData.shared.scales[1].timerHandle = &htim2;
106 | RampsData.shared.scales[2].timerHandle = &htim3;
107 | RampsData.shared.scales[3].timerHandle = &htim4;
108 | RampsData.synchroRefreshTimer = &htim9;
109 | RampsData.modbusUart = &huart1;
110 | RampsStart(&RampsData);
111 |
112 | /* USER CODE END 2 */
113 |
114 | /* Init scheduler */
115 | osKernelInitialize();
116 |
117 | /* Call init function for freertos objects (in freertos.c) */
118 | MX_FREERTOS_Init();
119 |
120 | /* Start scheduler */
121 | osKernelStart();
122 |
123 | /* We should never get here as control is now taken by the scheduler */
124 | /* Infinite loop */
125 | /* USER CODE BEGIN WHILE */
126 | while (1)
127 | {
128 | /* USER CODE END WHILE */
129 |
130 | /* USER CODE BEGIN 3 */
131 | }
132 | /* USER CODE END 3 */
133 | }
134 |
135 | /**
136 | * @brief System Clock Configuration
137 | * @retval None
138 | */
139 | void SystemClock_Config(void)
140 | {
141 | RCC_OscInitTypeDef RCC_OscInitStruct = {0};
142 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
143 |
144 | /** Configure the main internal regulator output voltage
145 | */
146 | __HAL_RCC_PWR_CLK_ENABLE();
147 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
148 |
149 | /** Initializes the RCC Oscillators according to the specified parameters
150 | * in the RCC_OscInitTypeDef structure.
151 | */
152 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
153 | RCC_OscInitStruct.HSEState = RCC_HSE_ON;
154 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
155 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
156 | RCC_OscInitStruct.PLL.PLLM = 4;
157 | RCC_OscInitStruct.PLL.PLLN = 100;
158 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
159 | RCC_OscInitStruct.PLL.PLLQ = 4;
160 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
161 | {
162 | Error_Handler();
163 | }
164 |
165 | /** Initializes the CPU, AHB and APB buses clocks
166 | */
167 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
168 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
169 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
170 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
171 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
172 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
173 |
174 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
175 | {
176 | Error_Handler();
177 | }
178 | }
179 |
180 | /* USER CODE BEGIN 4 */
181 |
182 | /* USER CODE END 4 */
183 |
184 | /**
185 | * @brief Period elapsed callback in non blocking mode
186 | * @note This function is called when TIM11 interrupt took place, inside
187 | * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
188 | * a global variable "uwTick" used as application time base.
189 | * @param htim : TIM handle
190 | * @retval None
191 | */
192 | void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
193 | {
194 | /* USER CODE BEGIN Callback 0 */
195 |
196 | /* USER CODE END Callback 0 */
197 | if (htim->Instance == TIM11) {
198 | HAL_IncTick();
199 | }
200 | /* USER CODE BEGIN Callback 1 */
201 |
202 | /* USER CODE END Callback 1 */
203 | }
204 |
205 | /**
206 | * @brief This function is executed in case of error occurrence.
207 | * @retval None
208 | */
209 | void Error_Handler(void)
210 | {
211 | /* USER CODE BEGIN Error_Handler_Debug */
212 | /* User can add his own implementation to report the HAL error return state */
213 | __disable_irq();
214 | while (1)
215 | {
216 | }
217 | /* USER CODE END Error_Handler_Debug */
218 | }
219 |
220 | #ifdef USE_FULL_ASSERT
221 | /**
222 | * @brief Reports the name of the source file and the source line number
223 | * where the assert_param error has occurred.
224 | * @param file: pointer to the source file name
225 | * @param line: assert_param error line source number
226 | * @retval None
227 | */
228 | void assert_failed(uint8_t *file, uint32_t line)
229 | {
230 | /* USER CODE BEGIN 6 */
231 | /* User can add his own implementation to report the file name and line number,
232 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
233 | /* USER CODE END 6 */
234 | }
235 | #endif /* USE_FULL_ASSERT */
236 |
--------------------------------------------------------------------------------
/Core/Inc/FreeRTOSConfig.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /*
3 | * FreeRTOS Kernel V10.3.1
4 | * Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 | * Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved.
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | *
24 | * http://www.FreeRTOS.org
25 | * http://aws.amazon.com/freertos
26 | *
27 | * 1 tab == 4 spaces!
28 | */
29 | /* USER CODE END Header */
30 |
31 | #ifndef FREERTOS_CONFIG_H
32 | #define FREERTOS_CONFIG_H
33 |
34 | /*-----------------------------------------------------------
35 | * Application specific definitions.
36 | *
37 | * These definitions should be adjusted for your particular hardware and
38 | * application requirements.
39 | *
40 | * These parameters and more are described within the 'configuration' section of the
41 | * FreeRTOS API documentation available on the FreeRTOS.org web site.
42 | *
43 | * See http://www.freertos.org/a00110.html
44 | *----------------------------------------------------------*/
45 |
46 | /* USER CODE BEGIN Includes */
47 | /* Section where include file can be added */
48 | /* USER CODE END Includes */
49 |
50 | /* Ensure definitions are only used by the compiler, and not by the assembler. */
51 | #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
52 | #include
53 | extern uint32_t SystemCoreClock;
54 | #endif
55 | #ifndef CMSIS_device_header
56 | #define CMSIS_device_header "stm32f4xx.h"
57 | #endif /* CMSIS_device_header */
58 |
59 | #define configENABLE_FPU 1
60 | #define configENABLE_MPU 0
61 |
62 | #define configUSE_PREEMPTION 1
63 | #define configSUPPORT_STATIC_ALLOCATION 1
64 | #define configSUPPORT_DYNAMIC_ALLOCATION 1
65 | #define configUSE_IDLE_HOOK 0
66 | #define configUSE_TICK_HOOK 0
67 | #define configCPU_CLOCK_HZ ( SystemCoreClock )
68 | #define configTICK_RATE_HZ ((TickType_t)1000)
69 | #define configMAX_PRIORITIES ( 56 )
70 | #define configMINIMAL_STACK_SIZE ((uint16_t)128)
71 | #define configTOTAL_HEAP_SIZE ((size_t)15360)
72 | #define configMAX_TASK_NAME_LEN ( 16 )
73 | #define configUSE_TRACE_FACILITY 1
74 | #define configUSE_16_BIT_TICKS 0
75 | #define configUSE_MUTEXES 1
76 | #define configQUEUE_REGISTRY_SIZE 8
77 | #define configUSE_RECURSIVE_MUTEXES 1
78 | #define configUSE_COUNTING_SEMAPHORES 1
79 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
80 | /* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */
81 | /* Defaults to size_t for backward compatibility, but can be changed
82 | if lengths will always be less than the number of bytes in a size_t. */
83 | #define configMESSAGE_BUFFER_LENGTH_TYPE size_t
84 | /* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */
85 |
86 | /* Co-routine definitions. */
87 | #define configUSE_CO_ROUTINES 0
88 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
89 |
90 | /* Software timer definitions. */
91 | #define configUSE_TIMERS 1
92 | #define configTIMER_TASK_PRIORITY ( 2 )
93 | #define configTIMER_QUEUE_LENGTH 10
94 | #define configTIMER_TASK_STACK_DEPTH 256
95 |
96 | /* The following flag must be enabled only when using newlib */
97 | #define configUSE_NEWLIB_REENTRANT 1
98 |
99 | /* CMSIS-RTOS V2 flags */
100 | #define configUSE_OS2_THREAD_SUSPEND_RESUME 1
101 | #define configUSE_OS2_THREAD_ENUMERATE 1
102 | #define configUSE_OS2_EVENTFLAGS_FROM_ISR 1
103 | #define configUSE_OS2_THREAD_FLAGS 1
104 | #define configUSE_OS2_TIMER 1
105 | #define configUSE_OS2_MUTEX 1
106 |
107 | /* Set the following definitions to 1 to include the API function, or zero
108 | to exclude the API function. */
109 | #define INCLUDE_vTaskPrioritySet 1
110 | #define INCLUDE_uxTaskPriorityGet 1
111 | #define INCLUDE_vTaskDelete 1
112 | #define INCLUDE_vTaskCleanUpResources 0
113 | #define INCLUDE_vTaskSuspend 1
114 | #define INCLUDE_vTaskDelayUntil 1
115 | #define INCLUDE_vTaskDelay 1
116 | #define INCLUDE_xTaskGetSchedulerState 1
117 | #define INCLUDE_xTimerPendFunctionCall 1
118 | #define INCLUDE_xQueueGetMutexHolder 1
119 | #define INCLUDE_uxTaskGetStackHighWaterMark 1
120 | #define INCLUDE_xTaskGetCurrentTaskHandle 1
121 | #define INCLUDE_eTaskGetState 1
122 |
123 | /*
124 | * The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used
125 | * by the application thus the correct define need to be enabled below
126 | */
127 | #define USE_FreeRTOS_HEAP_4
128 |
129 | /* Cortex-M specific definitions. */
130 | #ifdef __NVIC_PRIO_BITS
131 | /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
132 | #define configPRIO_BITS __NVIC_PRIO_BITS
133 | #else
134 | #define configPRIO_BITS 4
135 | #endif
136 |
137 | /* The lowest interrupt priority that can be used in a call to a "set priority"
138 | function. */
139 | #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
140 |
141 | /* The highest interrupt priority that can be used by any interrupt service
142 | routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
143 | INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
144 | PRIORITY THAN THIS! (higher priorities are lower numeric values. */
145 | #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
146 |
147 | /* Interrupt priorities used by the kernel port layer itself. These are generic
148 | to all Cortex-M ports, and do not rely on any particular library functions. */
149 | #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
150 | /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
151 | See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
152 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
153 |
154 | /* Normal assert() semantics without relying on the provision of an assert.h
155 | header file. */
156 | /* USER CODE BEGIN 1 */
157 | #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
158 | /* USER CODE END 1 */
159 |
160 | /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
161 | standard names. */
162 | #define vPortSVCHandler SVC_Handler
163 | #define xPortPendSVHandler PendSV_Handler
164 |
165 | /* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */
166 |
167 | #define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0
168 |
169 | /* USER CODE BEGIN Defines */
170 | /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
171 | /* USER CODE END Defines */
172 |
173 | #endif /* FREERTOS_CONFIG_H */
174 |
--------------------------------------------------------------------------------
/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_def.h
4 | * @author MCD Application Team
5 | * @brief This file contains HAL common defines, enumeration, macros and
6 | * structures definitions.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * Copyright (c) 2017 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software is licensed under terms that can be found in the LICENSE file
14 | * in the root directory of this software component.
15 | * If no LICENSE file comes with this software, it is provided AS-IS.
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __STM32F4xx_HAL_DEF
22 | #define __STM32F4xx_HAL_DEF
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "stm32f4xx.h"
30 | #include "Legacy/stm32_hal_legacy.h"
31 | #include
32 |
33 | /* Exported types ------------------------------------------------------------*/
34 |
35 | /**
36 | * @brief HAL Status structures definition
37 | */
38 | typedef enum
39 | {
40 | HAL_OK = 0x00U,
41 | HAL_ERROR = 0x01U,
42 | HAL_BUSY = 0x02U,
43 | HAL_TIMEOUT = 0x03U
44 | } HAL_StatusTypeDef;
45 |
46 | /**
47 | * @brief HAL Lock structures definition
48 | */
49 | typedef enum
50 | {
51 | HAL_UNLOCKED = 0x00U,
52 | HAL_LOCKED = 0x01U
53 | } HAL_LockTypeDef;
54 |
55 | /* Exported macro ------------------------------------------------------------*/
56 |
57 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */
58 |
59 | #define HAL_MAX_DELAY 0xFFFFFFFFU
60 |
61 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT))
62 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U)
63 |
64 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \
65 | do{ \
66 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
67 | (__DMA_HANDLE__).Parent = (__HANDLE__); \
68 | } while(0U)
69 |
70 | /** @brief Reset the Handle's State field.
71 | * @param __HANDLE__ specifies the Peripheral Handle.
72 | * @note This macro can be used for the following purpose:
73 | * - When the Handle is declared as local variable; before passing it as parameter
74 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
75 | * to set to 0 the Handle's "State" field.
76 | * Otherwise, "State" field may have any random value and the first time the function
77 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed
78 | * (i.e. HAL_PPP_MspInit() will not be executed).
79 | * - When there is a need to reconfigure the low level hardware: instead of calling
80 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
81 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function
82 | * HAL_PPP_MspInit() which will reconfigure the low level hardware.
83 | * @retval None
84 | */
85 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U)
86 |
87 | #if (USE_RTOS == 1U)
88 | /* Reserved for future use */
89 | #error "USE_RTOS should be 0 in the current HAL release"
90 | #else
91 | #define __HAL_LOCK(__HANDLE__) \
92 | do{ \
93 | if((__HANDLE__)->Lock == HAL_LOCKED) \
94 | { \
95 | return HAL_BUSY; \
96 | } \
97 | else \
98 | { \
99 | (__HANDLE__)->Lock = HAL_LOCKED; \
100 | } \
101 | }while (0U)
102 |
103 | #define __HAL_UNLOCK(__HANDLE__) \
104 | do{ \
105 | (__HANDLE__)->Lock = HAL_UNLOCKED; \
106 | }while (0U)
107 | #endif /* USE_RTOS */
108 |
109 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
110 | #ifndef __weak
111 | #define __weak __attribute__((weak))
112 | #endif
113 | #ifndef __packed
114 | #define __packed __attribute__((packed))
115 | #endif
116 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
117 | #ifndef __weak
118 | #define __weak __attribute__((weak))
119 | #endif /* __weak */
120 | #ifndef __packed
121 | #define __packed __attribute__((__packed__))
122 | #endif /* __packed */
123 | #endif /* __GNUC__ */
124 |
125 |
126 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
127 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
128 | #ifndef __ALIGN_BEGIN
129 | #define __ALIGN_BEGIN
130 | #endif
131 | #ifndef __ALIGN_END
132 | #define __ALIGN_END __attribute__ ((aligned (4)))
133 | #endif
134 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
135 | #ifndef __ALIGN_END
136 | #define __ALIGN_END __attribute__ ((aligned (4)))
137 | #endif /* __ALIGN_END */
138 | #ifndef __ALIGN_BEGIN
139 | #define __ALIGN_BEGIN
140 | #endif /* __ALIGN_BEGIN */
141 | #else
142 | #ifndef __ALIGN_END
143 | #define __ALIGN_END
144 | #endif /* __ALIGN_END */
145 | #ifndef __ALIGN_BEGIN
146 | #if defined (__CC_ARM) /* ARM Compiler V5*/
147 | #define __ALIGN_BEGIN __align(4)
148 | #elif defined (__ICCARM__) /* IAR Compiler */
149 | #define __ALIGN_BEGIN
150 | #endif /* __CC_ARM */
151 | #endif /* __ALIGN_BEGIN */
152 | #endif /* __GNUC__ */
153 |
154 |
155 | /**
156 | * @brief __RAM_FUNC definition
157 | */
158 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
159 | /* ARM Compiler V4/V5 and V6
160 | --------------------------
161 | RAM functions are defined using the toolchain options.
162 | Functions that are executed in RAM should reside in a separate source module.
163 | Using the 'Options for File' dialog you can simply change the 'Code / Const'
164 | area of a module to a memory space in physical RAM.
165 | Available memory areas are declared in the 'Target' tab of the 'Options for Target'
166 | dialog.
167 | */
168 | #define __RAM_FUNC
169 |
170 | #elif defined ( __ICCARM__ )
171 | /* ICCARM Compiler
172 | ---------------
173 | RAM functions are defined using a specific toolchain keyword "__ramfunc".
174 | */
175 | #define __RAM_FUNC __ramfunc
176 |
177 | #elif defined ( __GNUC__ )
178 | /* GNU Compiler
179 | ------------
180 | RAM functions are defined using a specific toolchain attribute
181 | "__attribute__((section(".RamFunc")))".
182 | */
183 | #define __RAM_FUNC __attribute__((section(".RamFunc")))
184 |
185 | #endif
186 |
187 | /**
188 | * @brief __NOINLINE definition
189 | */
190 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ )
191 | /* ARM V4/V5 and V6 & GNU Compiler
192 | -------------------------------
193 | */
194 | #define __NOINLINE __attribute__ ( (noinline) )
195 |
196 | #elif defined ( __ICCARM__ )
197 | /* ICCARM Compiler
198 | ---------------
199 | */
200 | #define __NOINLINE _Pragma("optimize = no_inline")
201 |
202 | #endif
203 |
204 | #ifdef __cplusplus
205 | }
206 | #endif
207 |
208 | #endif /* ___STM32F4xx_HAL_DEF */
209 |
210 |
211 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeRTOS Kernel V10.3.1
3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to
8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | * the Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | *
22 | * http://www.FreeRTOS.org
23 | * http://aws.amazon.com/freertos
24 | *
25 | * 1 tab == 4 spaces!
26 | */
27 |
28 | #ifndef DEPRECATED_DEFINITIONS_H
29 | #define DEPRECATED_DEFINITIONS_H
30 |
31 |
32 | /* Each FreeRTOS port has a unique portmacro.h header file. Originally a
33 | pre-processor definition was used to ensure the pre-processor found the correct
34 | portmacro.h file for the port being used. That scheme was deprecated in favour
35 | of setting the compiler's include path such that it found the correct
36 | portmacro.h file - removing the need for the constant and allowing the
37 | portmacro.h file to be located anywhere in relation to the port being used. The
38 | definitions below remain in the code for backward compatibility only. New
39 | projects should not use them. */
40 |
41 | #ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT
42 | #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h"
43 | typedef void ( __interrupt __far *pxISR )();
44 | #endif
45 |
46 | #ifdef OPEN_WATCOM_FLASH_LITE_186_PORT
47 | #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h"
48 | typedef void ( __interrupt __far *pxISR )();
49 | #endif
50 |
51 | #ifdef GCC_MEGA_AVR
52 | #include "../portable/GCC/ATMega323/portmacro.h"
53 | #endif
54 |
55 | #ifdef IAR_MEGA_AVR
56 | #include "../portable/IAR/ATMega323/portmacro.h"
57 | #endif
58 |
59 | #ifdef MPLAB_PIC24_PORT
60 | #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h"
61 | #endif
62 |
63 | #ifdef MPLAB_DSPIC_PORT
64 | #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h"
65 | #endif
66 |
67 | #ifdef MPLAB_PIC18F_PORT
68 | #include "../../Source/portable/MPLAB/PIC18F/portmacro.h"
69 | #endif
70 |
71 | #ifdef MPLAB_PIC32MX_PORT
72 | #include "../../Source/portable/MPLAB/PIC32MX/portmacro.h"
73 | #endif
74 |
75 | #ifdef _FEDPICC
76 | #include "libFreeRTOS/Include/portmacro.h"
77 | #endif
78 |
79 | #ifdef SDCC_CYGNAL
80 | #include "../../Source/portable/SDCC/Cygnal/portmacro.h"
81 | #endif
82 |
83 | #ifdef GCC_ARM7
84 | #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h"
85 | #endif
86 |
87 | #ifdef GCC_ARM7_ECLIPSE
88 | #include "portmacro.h"
89 | #endif
90 |
91 | #ifdef ROWLEY_LPC23xx
92 | #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h"
93 | #endif
94 |
95 | #ifdef IAR_MSP430
96 | #include "..\..\Source\portable\IAR\MSP430\portmacro.h"
97 | #endif
98 |
99 | #ifdef GCC_MSP430
100 | #include "../../Source/portable/GCC/MSP430F449/portmacro.h"
101 | #endif
102 |
103 | #ifdef ROWLEY_MSP430
104 | #include "../../Source/portable/Rowley/MSP430F449/portmacro.h"
105 | #endif
106 |
107 | #ifdef ARM7_LPC21xx_KEIL_RVDS
108 | #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h"
109 | #endif
110 |
111 | #ifdef SAM7_GCC
112 | #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h"
113 | #endif
114 |
115 | #ifdef SAM7_IAR
116 | #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h"
117 | #endif
118 |
119 | #ifdef SAM9XE_IAR
120 | #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h"
121 | #endif
122 |
123 | #ifdef LPC2000_IAR
124 | #include "..\..\Source\portable\IAR\LPC2000\portmacro.h"
125 | #endif
126 |
127 | #ifdef STR71X_IAR
128 | #include "..\..\Source\portable\IAR\STR71x\portmacro.h"
129 | #endif
130 |
131 | #ifdef STR75X_IAR
132 | #include "..\..\Source\portable\IAR\STR75x\portmacro.h"
133 | #endif
134 |
135 | #ifdef STR75X_GCC
136 | #include "..\..\Source\portable\GCC\STR75x\portmacro.h"
137 | #endif
138 |
139 | #ifdef STR91X_IAR
140 | #include "..\..\Source\portable\IAR\STR91x\portmacro.h"
141 | #endif
142 |
143 | #ifdef GCC_H8S
144 | #include "../../Source/portable/GCC/H8S2329/portmacro.h"
145 | #endif
146 |
147 | #ifdef GCC_AT91FR40008
148 | #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h"
149 | #endif
150 |
151 | #ifdef RVDS_ARMCM3_LM3S102
152 | #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h"
153 | #endif
154 |
155 | #ifdef GCC_ARMCM3_LM3S102
156 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h"
157 | #endif
158 |
159 | #ifdef GCC_ARMCM3
160 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h"
161 | #endif
162 |
163 | #ifdef IAR_ARM_CM3
164 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h"
165 | #endif
166 |
167 | #ifdef IAR_ARMCM3_LM
168 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h"
169 | #endif
170 |
171 | #ifdef HCS12_CODE_WARRIOR
172 | #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h"
173 | #endif
174 |
175 | #ifdef MICROBLAZE_GCC
176 | #include "../../Source/portable/GCC/MicroBlaze/portmacro.h"
177 | #endif
178 |
179 | #ifdef TERN_EE
180 | #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h"
181 | #endif
182 |
183 | #ifdef GCC_HCS12
184 | #include "../../Source/portable/GCC/HCS12/portmacro.h"
185 | #endif
186 |
187 | #ifdef GCC_MCF5235
188 | #include "../../Source/portable/GCC/MCF5235/portmacro.h"
189 | #endif
190 |
191 | #ifdef COLDFIRE_V2_GCC
192 | #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h"
193 | #endif
194 |
195 | #ifdef COLDFIRE_V2_CODEWARRIOR
196 | #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h"
197 | #endif
198 |
199 | #ifdef GCC_PPC405
200 | #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h"
201 | #endif
202 |
203 | #ifdef GCC_PPC440
204 | #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h"
205 | #endif
206 |
207 | #ifdef _16FX_SOFTUNE
208 | #include "..\..\Source\portable\Softune\MB96340\portmacro.h"
209 | #endif
210 |
211 | #ifdef BCC_INDUSTRIAL_PC_PORT
212 | /* A short file name has to be used in place of the normal
213 | FreeRTOSConfig.h when using the Borland compiler. */
214 | #include "frconfig.h"
215 | #include "..\portable\BCC\16BitDOS\PC\prtmacro.h"
216 | typedef void ( __interrupt __far *pxISR )();
217 | #endif
218 |
219 | #ifdef BCC_FLASH_LITE_186_PORT
220 | /* A short file name has to be used in place of the normal
221 | FreeRTOSConfig.h when using the Borland compiler. */
222 | #include "frconfig.h"
223 | #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h"
224 | typedef void ( __interrupt __far *pxISR )();
225 | #endif
226 |
227 | #ifdef __GNUC__
228 | #ifdef __AVR32_AVR32A__
229 | #include "portmacro.h"
230 | #endif
231 | #endif
232 |
233 | #ifdef __ICCAVR32__
234 | #ifdef __CORE__
235 | #if __CORE__ == __AVR32A__
236 | #include "portmacro.h"
237 | #endif
238 | #endif
239 | #endif
240 |
241 | #ifdef __91467D
242 | #include "portmacro.h"
243 | #endif
244 |
245 | #ifdef __96340
246 | #include "portmacro.h"
247 | #endif
248 |
249 |
250 | #ifdef __IAR_V850ES_Fx3__
251 | #include "../../Source/portable/IAR/V850ES/portmacro.h"
252 | #endif
253 |
254 | #ifdef __IAR_V850ES_Jx3__
255 | #include "../../Source/portable/IAR/V850ES/portmacro.h"
256 | #endif
257 |
258 | #ifdef __IAR_V850ES_Jx3_L__
259 | #include "../../Source/portable/IAR/V850ES/portmacro.h"
260 | #endif
261 |
262 | #ifdef __IAR_V850ES_Jx2__
263 | #include "../../Source/portable/IAR/V850ES/portmacro.h"
264 | #endif
265 |
266 | #ifdef __IAR_V850ES_Hx2__
267 | #include "../../Source/portable/IAR/V850ES/portmacro.h"
268 | #endif
269 |
270 | #ifdef __IAR_78K0R_Kx3__
271 | #include "../../Source/portable/IAR/78K0R/portmacro.h"
272 | #endif
273 |
274 | #ifdef __IAR_78K0R_Kx3L__
275 | #include "../../Source/portable/IAR/78K0R/portmacro.h"
276 | #endif
277 |
278 | #endif /* DEPRECATED_DEFINITIONS_H */
279 |
280 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/include/portable.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeRTOS Kernel V10.3.1
3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to
8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | * the Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | *
22 | * http://www.FreeRTOS.org
23 | * http://aws.amazon.com/freertos
24 | *
25 | * 1 tab == 4 spaces!
26 | */
27 |
28 | /*-----------------------------------------------------------
29 | * Portable layer API. Each function must be defined for each port.
30 | *----------------------------------------------------------*/
31 |
32 | #ifndef PORTABLE_H
33 | #define PORTABLE_H
34 |
35 | /* Each FreeRTOS port has a unique portmacro.h header file. Originally a
36 | pre-processor definition was used to ensure the pre-processor found the correct
37 | portmacro.h file for the port being used. That scheme was deprecated in favour
38 | of setting the compiler's include path such that it found the correct
39 | portmacro.h file - removing the need for the constant and allowing the
40 | portmacro.h file to be located anywhere in relation to the port being used.
41 | Purely for reasons of backward compatibility the old method is still valid, but
42 | to make it clear that new projects should not use it, support for the port
43 | specific constants has been moved into the deprecated_definitions.h header
44 | file. */
45 | #include "deprecated_definitions.h"
46 |
47 | /* If portENTER_CRITICAL is not defined then including deprecated_definitions.h
48 | did not result in a portmacro.h header file being included - and it should be
49 | included here. In this case the path to the correct portmacro.h header file
50 | must be set in the compiler's include path. */
51 | #ifndef portENTER_CRITICAL
52 | #include "portmacro.h"
53 | #endif
54 |
55 | #if portBYTE_ALIGNMENT == 32
56 | #define portBYTE_ALIGNMENT_MASK ( 0x001f )
57 | #endif
58 |
59 | #if portBYTE_ALIGNMENT == 16
60 | #define portBYTE_ALIGNMENT_MASK ( 0x000f )
61 | #endif
62 |
63 | #if portBYTE_ALIGNMENT == 8
64 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 )
65 | #endif
66 |
67 | #if portBYTE_ALIGNMENT == 4
68 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 )
69 | #endif
70 |
71 | #if portBYTE_ALIGNMENT == 2
72 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 )
73 | #endif
74 |
75 | #if portBYTE_ALIGNMENT == 1
76 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 )
77 | #endif
78 |
79 | #ifndef portBYTE_ALIGNMENT_MASK
80 | #error "Invalid portBYTE_ALIGNMENT definition"
81 | #endif
82 |
83 | #ifndef portNUM_CONFIGURABLE_REGIONS
84 | #define portNUM_CONFIGURABLE_REGIONS 1
85 | #endif
86 |
87 | #ifndef portHAS_STACK_OVERFLOW_CHECKING
88 | #define portHAS_STACK_OVERFLOW_CHECKING 0
89 | #endif
90 |
91 | #ifndef portARCH_NAME
92 | #define portARCH_NAME NULL
93 | #endif
94 |
95 | #ifdef __cplusplus
96 | extern "C" {
97 | #endif
98 |
99 | #include "mpu_wrappers.h"
100 |
101 | /*
102 | * Setup the stack of a new task so it is ready to be placed under the
103 | * scheduler control. The registers have to be placed on the stack in
104 | * the order that the port expects to find them.
105 | *
106 | */
107 | #if( portUSING_MPU_WRAPPERS == 1 )
108 | #if( portHAS_STACK_OVERFLOW_CHECKING == 1 )
109 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION;
110 | #else
111 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION;
112 | #endif
113 | #else
114 | #if( portHAS_STACK_OVERFLOW_CHECKING == 1 )
115 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION;
116 | #else
117 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION;
118 | #endif
119 | #endif
120 |
121 | /* Used by heap_5.c to define the start address and size of each memory region
122 | that together comprise the total FreeRTOS heap space. */
123 | typedef struct HeapRegion
124 | {
125 | uint8_t *pucStartAddress;
126 | size_t xSizeInBytes;
127 | } HeapRegion_t;
128 |
129 | /* Used to pass information about the heap out of vPortGetHeapStats(). */
130 | typedef struct xHeapStats
131 | {
132 | size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */
133 | size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
134 | size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
135 | size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */
136 | size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */
137 | size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */
138 | size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */
139 | } HeapStats_t;
140 |
141 | /*
142 | * Used to define multiple heap regions for use by heap_5.c. This function
143 | * must be called before any calls to pvPortMalloc() - not creating a task,
144 | * queue, semaphore, mutex, software timer, event group, etc. will result in
145 | * pvPortMalloc being called.
146 | *
147 | * pxHeapRegions passes in an array of HeapRegion_t structures - each of which
148 | * defines a region of memory that can be used as the heap. The array is
149 | * terminated by a HeapRegions_t structure that has a size of 0. The region
150 | * with the lowest start address must appear first in the array.
151 | */
152 | void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION;
153 |
154 | /*
155 | * Returns a HeapStats_t structure filled with information about the current
156 | * heap state.
157 | */
158 | void vPortGetHeapStats( HeapStats_t *pxHeapStats );
159 |
160 | /*
161 | * Map to the memory management routines required for the port.
162 | */
163 | void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
164 | void vPortFree( void *pv ) PRIVILEGED_FUNCTION;
165 | void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
166 | size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;
167 | size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;
168 |
169 | /*
170 | * Setup the hardware ready for the scheduler to take control. This generally
171 | * sets up a tick interrupt and sets timers for the correct tick frequency.
172 | */
173 | BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION;
174 |
175 | /*
176 | * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so
177 | * the hardware is left in its original condition after the scheduler stops
178 | * executing.
179 | */
180 | void vPortEndScheduler( void ) PRIVILEGED_FUNCTION;
181 |
182 | /*
183 | * The structures and methods of manipulating the MPU are contained within the
184 | * port layer.
185 | *
186 | * Fills the xMPUSettings structure with the memory region information
187 | * contained in xRegions.
188 | */
189 | #if( portUSING_MPU_WRAPPERS == 1 )
190 | struct xMEMORY_REGION;
191 | void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t ulStackDepth ) PRIVILEGED_FUNCTION;
192 | #endif
193 |
194 | #ifdef __cplusplus
195 | }
196 | #endif
197 |
198 | #endif /* PORTABLE_H */
199 |
200 |
--------------------------------------------------------------------------------
/Core/Inc/Modbus.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Modbus.h
3 | *
4 | * Created on: May 5, 2020
5 | * Author: Alejandro Mera
6 | */
7 |
8 | #ifndef THIRD_PARTY_MODBUS_INC_MODBUS_H_
9 | #define THIRD_PARTY_MODBUS_INC_MODBUS_H_
10 |
11 |
12 | #include "ModbusConfig.h"
13 | #include
14 | #include
15 | #include "FreeRTOS.h"
16 | #include "cmsis_os.h"
17 | #include "task.h"
18 | #include "queue.h"
19 | #include "timers.h"
20 |
21 |
22 | typedef enum
23 | {
24 | USART_HW = 1,
25 | USB_CDC_HW = 2,
26 | TCP_HW = 3,
27 | USART_HW_DMA = 4,
28 | }mb_hardware_t ;
29 |
30 |
31 | typedef enum
32 | {
33 | MB_SLAVE = 3,
34 | MB_MASTER = 4
35 | }mb_masterslave_t ;
36 |
37 |
38 |
39 | /**
40 | * @enum MB_FC
41 | * @brief
42 | * Modbus function codes summary.
43 | * These are the implement function codes either for Master or for Slave.
44 | *
45 | * @see also fctsupported
46 | * @see also modbus_t
47 | */
48 | typedef enum MB_FC
49 | {
50 | MB_FC_READ_COILS = 1, /*!< FCT=1 -> read coils or digital outputs */
51 | MB_FC_READ_DISCRETE_INPUT = 2, /*!< FCT=2 -> read digital inputs */
52 | MB_FC_READ_REGISTERS = 3, /*!< FCT=3 -> read registers or analog outputs */
53 | MB_FC_READ_INPUT_REGISTER = 4, /*!< FCT=4 -> read analog inputs */
54 | MB_FC_WRITE_COIL = 5, /*!< FCT=5 -> write single coil or output */
55 | MB_FC_WRITE_REGISTER = 6, /*!< FCT=6 -> write single register */
56 | MB_FC_WRITE_MULTIPLE_COILS = 15, /*!< FCT=15 -> write multiple coils or outputs */
57 | MB_FC_WRITE_MULTIPLE_REGISTERS = 16 /*!< FCT=16 -> write multiple registers */
58 | }mb_functioncode_t;
59 |
60 |
61 | typedef struct
62 | {
63 | uint8_t uxBuffer[MAX_BUFFER];
64 | uint8_t u8start;
65 | uint8_t u8end;
66 | uint8_t u8available;
67 | bool overflow;
68 | }modbusRingBuffer_t;
69 |
70 |
71 |
72 |
73 | /**
74 | * @enum MESSAGE
75 | * @brief
76 | * Indexes to telegram frame positions
77 | */
78 | typedef enum MESSAGE
79 | {
80 | ID = 0, //!< ID field
81 | FUNC, //!< Function code position
82 | ADD_HI, //!< Address high byte
83 | ADD_LO, //!< Address low byte
84 | NB_HI, //!< Number of coils or registers high byte
85 | NB_LO, //!< Number of coils or registers low byte
86 | BYTE_CNT //!< byte counter
87 | }mb_message_t;
88 |
89 | typedef enum COM_STATES
90 | {
91 | COM_IDLE = 0,
92 | COM_WAITING = 1,
93 |
94 | }mb_com_state_t;
95 |
96 | typedef enum ERR_LIST
97 | {
98 | ERR_NOT_MASTER = -1,
99 | ERR_POLLING = -2,
100 | ERR_BUFF_OVERFLOW = -3,
101 | ERR_BAD_CRC = -4,
102 | ERR_EXCEPTION = -5,
103 | ERR_BAD_SIZE = -6,
104 | ERR_BAD_ADDRESS = -7,
105 | ERR_TIME_OUT = -8,
106 | ERR_BAD_SLAVE_ID = -9,
107 | ERR_BAD_TCP_ID = -10,
108 | ERR_OK_QUERY = -11
109 |
110 | }mb_errot_t;
111 |
112 | enum
113 | {
114 | EXC_FUNC_CODE = 1,
115 | EXC_ADDR_RANGE = 2,
116 | EXC_REGS_QUANT = 3,
117 | EXC_EXECUTE = 4
118 | };
119 |
120 | typedef union {
121 | uint8_t u8[4];
122 | uint16_t u16[2];
123 | uint32_t u32;
124 |
125 | } bytesFields ;
126 |
127 |
128 |
129 |
130 |
131 | /**
132 | * @struct modbus_t
133 | * @brief
134 | * Master query structure:
135 | * This structure contains all the necessary fields to make the Master generate a Modbus query.
136 | * A Master may keep several of these structures and send them cyclically or
137 | * use them according to program needs.
138 | */
139 | typedef struct
140 | {
141 | uint8_t u8id; /*!< Slave address between 1 and 247. 0 means broadcast */
142 | mb_functioncode_t u8fct; /*!< Function code: 1, 2, 3, 4, 5, 6, 15 or 16 */
143 | uint16_t u16RegAdd; /*!< Address of the first register to access at slave/s */
144 | uint16_t u16CoilsNo; /*!< Number of coils or registers to access */
145 | uint16_t *u16reg; /*!< Pointer to memory image in master */
146 | uint32_t *u32CurrentTask; /*!< Pointer to the task that will receive notifications from Modbus */
147 | #if ENABLE_TCP ==1
148 | uint32_t xIpAddress;
149 | uint16_t u16Port;
150 | uint8_t u8clientID;
151 | #endif
152 | }
153 | modbus_t;
154 |
155 |
156 | #if ENABLE_TCP == 1
157 | typedef struct
158 | {
159 | struct netconn *conn;
160 | uint32_t aging;
161 | }
162 | tcpclients_t;
163 |
164 | #endif
165 |
166 |
167 | /**
168 | * @struct modbusHandler_t
169 | * @brief
170 | * Modbus handler structure
171 | * Contains all the variables required for Modbus daemon operation
172 | */
173 | typedef struct
174 | {
175 |
176 | mb_masterslave_t uModbusType;
177 | UART_HandleTypeDef *port; //HAL Serial Port handler
178 | uint8_t u8id; //!< 0=master, 1..247=slave number
179 | GPIO_TypeDef* EN_Port; //!< flow control pin: 0=USB or RS-232 mode, >1=RS-485 mode
180 | uint16_t EN_Pin; //!< flow control pin: 0=USB or RS-232 mode, >1=RS-485 mode
181 | mb_errot_t i8lastError;
182 | uint8_t u8Buffer[MAX_BUFFER]; //Modbus buffer for communication
183 | uint8_t u8BufferSize;
184 | uint8_t u8lastRec;
185 | uint16_t *u16regs;
186 | uint16_t u16InCnt, u16OutCnt, u16errCnt; //keep statistics of Modbus traffic
187 | uint16_t u16timeOut;
188 | uint16_t u16regsize;
189 | uint8_t dataRX;
190 | int8_t i8state;
191 |
192 | //FreeRTOS components
193 |
194 | //Queue Modbus Telegram
195 | osMessageQueueId_t QueueTelegramHandle;
196 |
197 | //Task Modbus slave
198 | osThreadId_t myTaskModbusAHandle;
199 | //Timer RX Modbus
200 | xTimerHandle xTimerT35;
201 | //Timer MasterTimeout
202 | xTimerHandle xTimerTimeout;
203 | //Semaphore for Modbus data
204 | osSemaphoreId_t ModBusSphrHandle;
205 | // RX ring buffer for USART
206 | modbusRingBuffer_t xBufferRX;
207 | // type of hardware TCP, USB CDC, USART
208 | mb_hardware_t xTypeHW;
209 |
210 | #if ENABLE_TCP == 1
211 |
212 | tcpclients_t newconns[NUMBERTCPCONN];
213 | struct netconn *conn;
214 | uint32_t xIpAddress;
215 | uint16_t u16TransactionID;
216 | uint16_t uTcpPort; // this is only used for the slave (i.e., the server)
217 | uint8_t newconnIndex;
218 |
219 | #endif
220 |
221 | }
222 | modbusHandler_t;
223 |
224 |
225 | enum
226 | {
227 | RESPONSE_SIZE = 6,
228 | EXCEPTION_SIZE = 3,
229 | CHECKSUM_SIZE = 2
230 | };
231 |
232 |
233 |
234 | extern modbusHandler_t *mHandlers[MAX_M_HANDLERS];
235 |
236 | // Function prototypes
237 | void ModbusInit(modbusHandler_t * modH);
238 | void ModbusStart(modbusHandler_t * modH);
239 |
240 | #if ENABLE_USB_CDC == 1
241 | void ModbusStartCDC(modbusHandler_t * modH);
242 | #endif
243 |
244 | void setTimeOut( uint16_t u16timeOut); //!
30 | #include "FreeRTOS.h"
31 | #include "list.h"
32 |
33 | /*-----------------------------------------------------------
34 | * PUBLIC LIST API documented in list.h
35 | *----------------------------------------------------------*/
36 |
37 | void vListInitialise( List_t * const pxList )
38 | {
39 | /* The list structure contains a list item which is used to mark the
40 | end of the list. To initialise the list the list end is inserted
41 | as the only list entry. */
42 | pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
43 |
44 | /* The list end value is the highest possible value in the list to
45 | ensure it remains at the end of the list. */
46 | pxList->xListEnd.xItemValue = portMAX_DELAY;
47 |
48 | /* The list end next and previous pointers point to itself so we know
49 | when the list is empty. */
50 | pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
51 | pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
52 |
53 | pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
54 |
55 | /* Write known values into the list if
56 | configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
57 | listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
58 | listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
59 | }
60 | /*-----------------------------------------------------------*/
61 |
62 | void vListInitialiseItem( ListItem_t * const pxItem )
63 | {
64 | /* Make sure the list item is not recorded as being on a list. */
65 | pxItem->pxContainer = NULL;
66 |
67 | /* Write known values into the list item if
68 | configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
69 | listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
70 | listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
71 | }
72 | /*-----------------------------------------------------------*/
73 |
74 | void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
75 | {
76 | ListItem_t * const pxIndex = pxList->pxIndex;
77 |
78 | /* Only effective when configASSERT() is also defined, these tests may catch
79 | the list data structures being overwritten in memory. They will not catch
80 | data errors caused by incorrect configuration or use of FreeRTOS. */
81 | listTEST_LIST_INTEGRITY( pxList );
82 | listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
83 |
84 | /* Insert a new list item into pxList, but rather than sort the list,
85 | makes the new list item the last item to be removed by a call to
86 | listGET_OWNER_OF_NEXT_ENTRY(). */
87 | pxNewListItem->pxNext = pxIndex;
88 | pxNewListItem->pxPrevious = pxIndex->pxPrevious;
89 |
90 | /* Only used during decision coverage testing. */
91 | mtCOVERAGE_TEST_DELAY();
92 |
93 | pxIndex->pxPrevious->pxNext = pxNewListItem;
94 | pxIndex->pxPrevious = pxNewListItem;
95 |
96 | /* Remember which list the item is in. */
97 | pxNewListItem->pxContainer = pxList;
98 |
99 | ( pxList->uxNumberOfItems )++;
100 | }
101 | /*-----------------------------------------------------------*/
102 |
103 | void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
104 | {
105 | ListItem_t *pxIterator;
106 | const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
107 |
108 | /* Only effective when configASSERT() is also defined, these tests may catch
109 | the list data structures being overwritten in memory. They will not catch
110 | data errors caused by incorrect configuration or use of FreeRTOS. */
111 | listTEST_LIST_INTEGRITY( pxList );
112 | listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
113 |
114 | /* Insert the new list item into the list, sorted in xItemValue order.
115 |
116 | If the list already contains a list item with the same item value then the
117 | new list item should be placed after it. This ensures that TCBs which are
118 | stored in ready lists (all of which have the same xItemValue value) get a
119 | share of the CPU. However, if the xItemValue is the same as the back marker
120 | the iteration loop below will not end. Therefore the value is checked
121 | first, and the algorithm slightly modified if necessary. */
122 | if( xValueOfInsertion == portMAX_DELAY )
123 | {
124 | pxIterator = pxList->xListEnd.pxPrevious;
125 | }
126 | else
127 | {
128 | /* *** NOTE ***********************************************************
129 | If you find your application is crashing here then likely causes are
130 | listed below. In addition see https://www.freertos.org/FAQHelp.html for
131 | more tips, and ensure configASSERT() is defined!
132 | https://www.freertos.org/a00110.html#configASSERT
133 |
134 | 1) Stack overflow -
135 | see https://www.freertos.org/Stacks-and-stack-overflow-checking.html
136 | 2) Incorrect interrupt priority assignment, especially on Cortex-M
137 | parts where numerically high priority values denote low actual
138 | interrupt priorities, which can seem counter intuitive. See
139 | https://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition
140 | of configMAX_SYSCALL_INTERRUPT_PRIORITY on
141 | https://www.freertos.org/a00110.html
142 | 3) Calling an API function from within a critical section or when
143 | the scheduler is suspended, or calling an API function that does
144 | not end in "FromISR" from an interrupt.
145 | 4) Using a queue or semaphore before it has been initialised or
146 | before the scheduler has been started (are interrupts firing
147 | before vTaskStartScheduler() has been called?).
148 | **********************************************************************/
149 |
150 | for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
151 | {
152 | /* There is nothing to do here, just iterating to the wanted
153 | insertion position. */
154 | }
155 | }
156 |
157 | pxNewListItem->pxNext = pxIterator->pxNext;
158 | pxNewListItem->pxNext->pxPrevious = pxNewListItem;
159 | pxNewListItem->pxPrevious = pxIterator;
160 | pxIterator->pxNext = pxNewListItem;
161 |
162 | /* Remember which list the item is in. This allows fast removal of the
163 | item later. */
164 | pxNewListItem->pxContainer = pxList;
165 |
166 | ( pxList->uxNumberOfItems )++;
167 | }
168 | /*-----------------------------------------------------------*/
169 |
170 | UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
171 | {
172 | /* The list item knows which list it is in. Obtain the list from the list
173 | item. */
174 | List_t * const pxList = pxItemToRemove->pxContainer;
175 |
176 | pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
177 | pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
178 |
179 | /* Only used during decision coverage testing. */
180 | mtCOVERAGE_TEST_DELAY();
181 |
182 | /* Make sure the index is left pointing to a valid item. */
183 | if( pxList->pxIndex == pxItemToRemove )
184 | {
185 | pxList->pxIndex = pxItemToRemove->pxPrevious;
186 | }
187 | else
188 | {
189 | mtCOVERAGE_TEST_MARKER();
190 | }
191 |
192 | pxItemToRemove->pxContainer = NULL;
193 | ( pxList->uxNumberOfItems )--;
194 |
195 | return pxList->uxNumberOfItems;
196 | }
197 | /*-----------------------------------------------------------*/
198 |
199 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeRTOS Kernel V10.3.1
3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to
8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | * the Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | *
22 | * http://www.FreeRTOS.org
23 | * http://aws.amazon.com/freertos
24 | *
25 | * 1 tab == 4 spaces!
26 | */
27 |
28 |
29 | #ifndef PORTMACRO_H
30 | #define PORTMACRO_H
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | /*-----------------------------------------------------------
37 | * Port specific definitions.
38 | *
39 | * The settings in this file configure FreeRTOS correctly for the
40 | * given hardware and compiler.
41 | *
42 | * These settings should not be altered.
43 | *-----------------------------------------------------------
44 | */
45 |
46 | /* Type definitions. */
47 | #define portCHAR char
48 | #define portFLOAT float
49 | #define portDOUBLE double
50 | #define portLONG long
51 | #define portSHORT short
52 | #define portSTACK_TYPE uint32_t
53 | #define portBASE_TYPE long
54 |
55 | typedef portSTACK_TYPE StackType_t;
56 | typedef long BaseType_t;
57 | typedef unsigned long UBaseType_t;
58 |
59 | #if( configUSE_16_BIT_TICKS == 1 )
60 | typedef uint16_t TickType_t;
61 | #define portMAX_DELAY ( TickType_t ) 0xffff
62 | #else
63 | typedef uint32_t TickType_t;
64 | #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
65 |
66 | /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
67 | not need to be guarded with a critical section. */
68 | #define portTICK_TYPE_IS_ATOMIC 1
69 | #endif
70 | /*-----------------------------------------------------------*/
71 |
72 | /* Architecture specifics. */
73 | #define portSTACK_GROWTH ( -1 )
74 | #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
75 | #define portBYTE_ALIGNMENT 8
76 | /*-----------------------------------------------------------*/
77 |
78 | /* Scheduler utilities. */
79 | #define portYIELD() \
80 | { \
81 | /* Set a PendSV to request a context switch. */ \
82 | portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \
83 | \
84 | /* Barriers are normally not required but do ensure the code is completely \
85 | within the specified behaviour for the architecture. */ \
86 | __asm volatile( "dsb" ::: "memory" ); \
87 | __asm volatile( "isb" ); \
88 | }
89 |
90 | #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) )
91 | #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL )
92 | #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD()
93 | #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
94 | /*-----------------------------------------------------------*/
95 |
96 | /* Critical section management. */
97 | extern void vPortEnterCritical( void );
98 | extern void vPortExitCritical( void );
99 | #define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI()
100 | #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortSetBASEPRI(x)
101 | #define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI()
102 | #define portENABLE_INTERRUPTS() vPortSetBASEPRI(0)
103 | #define portENTER_CRITICAL() vPortEnterCritical()
104 | #define portEXIT_CRITICAL() vPortExitCritical()
105 |
106 | /*-----------------------------------------------------------*/
107 |
108 | /* Task function macros as described on the FreeRTOS.org WEB site. These are
109 | not necessary for to use this port. They are defined so the common demo files
110 | (which build with all the ports) will build. */
111 | #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
112 | #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
113 | /*-----------------------------------------------------------*/
114 |
115 | /* Tickless idle/low power functionality. */
116 | #ifndef portSUPPRESS_TICKS_AND_SLEEP
117 | extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );
118 | #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime )
119 | #endif
120 | /*-----------------------------------------------------------*/
121 |
122 | /* Architecture specific optimisations. */
123 | #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
124 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
125 | #endif
126 |
127 | #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
128 |
129 | /* Generic helper function. */
130 | __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
131 | {
132 | uint8_t ucReturn;
133 |
134 | __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );
135 | return ucReturn;
136 | }
137 |
138 | /* Check the configuration. */
139 | #if( configMAX_PRIORITIES > 32 )
140 | #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.
141 | #endif
142 |
143 | /* Store/clear the ready priorities in a bit map. */
144 | #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
145 | #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
146 |
147 | /*-----------------------------------------------------------*/
148 |
149 | #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )
150 |
151 | #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
152 |
153 | /*-----------------------------------------------------------*/
154 |
155 | #ifdef configASSERT
156 | void vPortValidateInterruptPriority( void );
157 | #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
158 | #endif
159 |
160 | /* portNOP() is not required by this port. */
161 | #define portNOP()
162 |
163 | #define portINLINE __inline
164 |
165 | #ifndef portFORCE_INLINE
166 | #define portFORCE_INLINE inline __attribute__(( always_inline))
167 | #endif
168 |
169 | portFORCE_INLINE static BaseType_t xPortIsInsideInterrupt( void )
170 | {
171 | uint32_t ulCurrentInterrupt;
172 | BaseType_t xReturn;
173 |
174 | /* Obtain the number of the currently executing interrupt. */
175 | __asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) :: "memory" );
176 |
177 | if( ulCurrentInterrupt == 0 )
178 | {
179 | xReturn = pdFALSE;
180 | }
181 | else
182 | {
183 | xReturn = pdTRUE;
184 | }
185 |
186 | return xReturn;
187 | }
188 |
189 | /*-----------------------------------------------------------*/
190 |
191 | portFORCE_INLINE static void vPortRaiseBASEPRI( void )
192 | {
193 | uint32_t ulNewBASEPRI;
194 |
195 | __asm volatile
196 | (
197 | " mov %0, %1 \n" \
198 | " msr basepri, %0 \n" \
199 | " isb \n" \
200 | " dsb \n" \
201 | :"=r" (ulNewBASEPRI) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"
202 | );
203 | }
204 |
205 | /*-----------------------------------------------------------*/
206 |
207 | portFORCE_INLINE static uint32_t ulPortRaiseBASEPRI( void )
208 | {
209 | uint32_t ulOriginalBASEPRI, ulNewBASEPRI;
210 |
211 | __asm volatile
212 | (
213 | " mrs %0, basepri \n" \
214 | " mov %1, %2 \n" \
215 | " msr basepri, %1 \n" \
216 | " isb \n" \
217 | " dsb \n" \
218 | :"=r" (ulOriginalBASEPRI), "=r" (ulNewBASEPRI) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"
219 | );
220 |
221 | /* This return will not be reached but is necessary to prevent compiler
222 | warnings. */
223 | return ulOriginalBASEPRI;
224 | }
225 | /*-----------------------------------------------------------*/
226 |
227 | portFORCE_INLINE static void vPortSetBASEPRI( uint32_t ulNewMaskValue )
228 | {
229 | __asm volatile
230 | (
231 | " msr basepri, %0 " :: "r" ( ulNewMaskValue ) : "memory"
232 | );
233 | }
234 | /*-----------------------------------------------------------*/
235 |
236 | #define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" )
237 |
238 | #ifdef __cplusplus
239 | }
240 | #endif
241 |
242 | #endif /* PORTMACRO_H */
243 |
244 |
--------------------------------------------------------------------------------
/Middlewares/Third_Party/FreeRTOS/Source/include/mpu_wrappers.h:
--------------------------------------------------------------------------------
1 | /*
2 | * FreeRTOS Kernel V10.3.1
3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to
8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | * the Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | *
22 | * http://www.FreeRTOS.org
23 | * http://aws.amazon.com/freertos
24 | *
25 | * 1 tab == 4 spaces!
26 | */
27 |
28 | #ifndef MPU_WRAPPERS_H
29 | #define MPU_WRAPPERS_H
30 |
31 | /* This file redefines API functions to be called through a wrapper macro, but
32 | only for ports that are using the MPU. */
33 | #ifdef portUSING_MPU_WRAPPERS
34 |
35 | /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is
36 | included from queue.c or task.c to prevent it from having an effect within
37 | those files. */
38 | #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
39 |
40 | /*
41 | * Map standard (non MPU) API functions to equivalents that start
42 | * "MPU_". This will cause the application code to call the MPU_
43 | * version, which wraps the non-MPU version with privilege promoting
44 | * then demoting code, so the kernel code always runs will full
45 | * privileges.
46 | */
47 |
48 | /* Map standard tasks.h API functions to the MPU equivalents. */
49 | #define xTaskCreate MPU_xTaskCreate
50 | #define xTaskCreateStatic MPU_xTaskCreateStatic
51 | #define xTaskCreateRestricted MPU_xTaskCreateRestricted
52 | #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
53 | #define vTaskDelete MPU_vTaskDelete
54 | #define vTaskDelay MPU_vTaskDelay
55 | #define vTaskDelayUntil MPU_vTaskDelayUntil
56 | #define xTaskAbortDelay MPU_xTaskAbortDelay
57 | #define uxTaskPriorityGet MPU_uxTaskPriorityGet
58 | #define eTaskGetState MPU_eTaskGetState
59 | #define vTaskGetInfo MPU_vTaskGetInfo
60 | #define vTaskPrioritySet MPU_vTaskPrioritySet
61 | #define vTaskSuspend MPU_vTaskSuspend
62 | #define vTaskResume MPU_vTaskResume
63 | #define vTaskSuspendAll MPU_vTaskSuspendAll
64 | #define xTaskResumeAll MPU_xTaskResumeAll
65 | #define xTaskGetTickCount MPU_xTaskGetTickCount
66 | #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks
67 | #define pcTaskGetName MPU_pcTaskGetName
68 | #define xTaskGetHandle MPU_xTaskGetHandle
69 | #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark
70 | #define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2
71 | #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag
72 | #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag
73 | #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer
74 | #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer
75 | #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook
76 | #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle
77 | #define uxTaskGetSystemState MPU_uxTaskGetSystemState
78 | #define vTaskList MPU_vTaskList
79 | #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats
80 | #define ulTaskGetIdleRunTimeCounter MPU_ulTaskGetIdleRunTimeCounter
81 | #define xTaskGenericNotify MPU_xTaskGenericNotify
82 | #define xTaskNotifyWait MPU_xTaskNotifyWait
83 | #define ulTaskNotifyTake MPU_ulTaskNotifyTake
84 | #define xTaskNotifyStateClear MPU_xTaskNotifyStateClear
85 | #define ulTaskNotifyValueClear MPU_ulTaskNotifyValueClear
86 | #define xTaskCatchUpTicks MPU_xTaskCatchUpTicks
87 |
88 | #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle
89 | #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState
90 | #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut
91 | #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState
92 |
93 | /* Map standard queue.h API functions to the MPU equivalents. */
94 | #define xQueueGenericSend MPU_xQueueGenericSend
95 | #define xQueueReceive MPU_xQueueReceive
96 | #define xQueuePeek MPU_xQueuePeek
97 | #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake
98 | #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting
99 | #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable
100 | #define vQueueDelete MPU_vQueueDelete
101 | #define xQueueCreateMutex MPU_xQueueCreateMutex
102 | #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic
103 | #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore
104 | #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic
105 | #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder
106 | #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive
107 | #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive
108 | #define xQueueGenericCreate MPU_xQueueGenericCreate
109 | #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic
110 | #define xQueueCreateSet MPU_xQueueCreateSet
111 | #define xQueueAddToSet MPU_xQueueAddToSet
112 | #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet
113 | #define xQueueSelectFromSet MPU_xQueueSelectFromSet
114 | #define xQueueGenericReset MPU_xQueueGenericReset
115 |
116 | #if( configQUEUE_REGISTRY_SIZE > 0 )
117 | #define vQueueAddToRegistry MPU_vQueueAddToRegistry
118 | #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue
119 | #define pcQueueGetName MPU_pcQueueGetName
120 | #endif
121 |
122 | /* Map standard timer.h API functions to the MPU equivalents. */
123 | #define xTimerCreate MPU_xTimerCreate
124 | #define xTimerCreateStatic MPU_xTimerCreateStatic
125 | #define pvTimerGetTimerID MPU_pvTimerGetTimerID
126 | #define vTimerSetTimerID MPU_vTimerSetTimerID
127 | #define xTimerIsTimerActive MPU_xTimerIsTimerActive
128 | #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle
129 | #define xTimerPendFunctionCall MPU_xTimerPendFunctionCall
130 | #define pcTimerGetName MPU_pcTimerGetName
131 | #define vTimerSetReloadMode MPU_vTimerSetReloadMode
132 | #define uxTimerGetReloadMode MPU_uxTimerGetReloadMode
133 | #define xTimerGetPeriod MPU_xTimerGetPeriod
134 | #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime
135 | #define xTimerGenericCommand MPU_xTimerGenericCommand
136 |
137 | /* Map standard event_group.h API functions to the MPU equivalents. */
138 | #define xEventGroupCreate MPU_xEventGroupCreate
139 | #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic
140 | #define xEventGroupWaitBits MPU_xEventGroupWaitBits
141 | #define xEventGroupClearBits MPU_xEventGroupClearBits
142 | #define xEventGroupSetBits MPU_xEventGroupSetBits
143 | #define xEventGroupSync MPU_xEventGroupSync
144 | #define vEventGroupDelete MPU_vEventGroupDelete
145 |
146 | /* Map standard message/stream_buffer.h API functions to the MPU
147 | equivalents. */
148 | #define xStreamBufferSend MPU_xStreamBufferSend
149 | #define xStreamBufferReceive MPU_xStreamBufferReceive
150 | #define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes
151 | #define vStreamBufferDelete MPU_vStreamBufferDelete
152 | #define xStreamBufferIsFull MPU_xStreamBufferIsFull
153 | #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty
154 | #define xStreamBufferReset MPU_xStreamBufferReset
155 | #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable
156 | #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable
157 | #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel
158 | #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate
159 | #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic
160 |
161 |
162 | /* Remove the privileged function macro, but keep the PRIVILEGED_DATA
163 | macro so applications can place data in privileged access sections
164 | (useful when using statically allocated objects). */
165 | #define PRIVILEGED_FUNCTION
166 | #define PRIVILEGED_DATA __attribute__((section("privileged_data")))
167 | #define FREERTOS_SYSTEM_CALL
168 |
169 | #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
170 |
171 | /* Ensure API functions go in the privileged execution section. */
172 | #define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions")))
173 | #define PRIVILEGED_DATA __attribute__((section("privileged_data")))
174 | #define FREERTOS_SYSTEM_CALL __attribute__((section( "freertos_system_calls")))
175 |
176 | #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
177 |
178 | #else /* portUSING_MPU_WRAPPERS */
179 |
180 | #define PRIVILEGED_FUNCTION
181 | #define PRIVILEGED_DATA
182 | #define FREERTOS_SYSTEM_CALL
183 | #define portUSING_MPU_WRAPPERS 0
184 |
185 | #endif /* portUSING_MPU_WRAPPERS */
186 |
187 |
188 | #endif /* MPU_WRAPPERS_H */
189 |
190 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/cmsis_compiler.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file cmsis_compiler.h
3 | * @brief CMSIS compiler generic header file
4 | * @version V5.0.4
5 | * @date 10. January 2018
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
9 | *
10 | * SPDX-License-Identifier: Apache-2.0
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the License); you may
13 | * not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | #ifndef __CMSIS_COMPILER_H
26 | #define __CMSIS_COMPILER_H
27 |
28 | #include
29 |
30 | /*
31 | * Arm Compiler 4/5
32 | */
33 | #if defined ( __CC_ARM )
34 | #include "cmsis_armcc.h"
35 |
36 |
37 | /*
38 | * Arm Compiler 6 (armclang)
39 | */
40 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
41 | #include "cmsis_armclang.h"
42 |
43 |
44 | /*
45 | * GNU Compiler
46 | */
47 | #elif defined ( __GNUC__ )
48 | #include "cmsis_gcc.h"
49 |
50 |
51 | /*
52 | * IAR Compiler
53 | */
54 | #elif defined ( __ICCARM__ )
55 | #include
56 |
57 |
58 | /*
59 | * TI Arm Compiler
60 | */
61 | #elif defined ( __TI_ARM__ )
62 | #include
63 |
64 | #ifndef __ASM
65 | #define __ASM __asm
66 | #endif
67 | #ifndef __INLINE
68 | #define __INLINE inline
69 | #endif
70 | #ifndef __STATIC_INLINE
71 | #define __STATIC_INLINE static inline
72 | #endif
73 | #ifndef __STATIC_FORCEINLINE
74 | #define __STATIC_FORCEINLINE __STATIC_INLINE
75 | #endif
76 | #ifndef __NO_RETURN
77 | #define __NO_RETURN __attribute__((noreturn))
78 | #endif
79 | #ifndef __USED
80 | #define __USED __attribute__((used))
81 | #endif
82 | #ifndef __WEAK
83 | #define __WEAK __attribute__((weak))
84 | #endif
85 | #ifndef __PACKED
86 | #define __PACKED __attribute__((packed))
87 | #endif
88 | #ifndef __PACKED_STRUCT
89 | #define __PACKED_STRUCT struct __attribute__((packed))
90 | #endif
91 | #ifndef __PACKED_UNION
92 | #define __PACKED_UNION union __attribute__((packed))
93 | #endif
94 | #ifndef __UNALIGNED_UINT32 /* deprecated */
95 | struct __attribute__((packed)) T_UINT32 { uint32_t v; };
96 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
97 | #endif
98 | #ifndef __UNALIGNED_UINT16_WRITE
99 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
100 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
101 | #endif
102 | #ifndef __UNALIGNED_UINT16_READ
103 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
104 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
105 | #endif
106 | #ifndef __UNALIGNED_UINT32_WRITE
107 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
108 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
109 | #endif
110 | #ifndef __UNALIGNED_UINT32_READ
111 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
112 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
113 | #endif
114 | #ifndef __ALIGNED
115 | #define __ALIGNED(x) __attribute__((aligned(x)))
116 | #endif
117 | #ifndef __RESTRICT
118 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
119 | #define __RESTRICT
120 | #endif
121 |
122 |
123 | /*
124 | * TASKING Compiler
125 | */
126 | #elif defined ( __TASKING__ )
127 | /*
128 | * The CMSIS functions have been implemented as intrinsics in the compiler.
129 | * Please use "carm -?i" to get an up to date list of all intrinsics,
130 | * Including the CMSIS ones.
131 | */
132 |
133 | #ifndef __ASM
134 | #define __ASM __asm
135 | #endif
136 | #ifndef __INLINE
137 | #define __INLINE inline
138 | #endif
139 | #ifndef __STATIC_INLINE
140 | #define __STATIC_INLINE static inline
141 | #endif
142 | #ifndef __STATIC_FORCEINLINE
143 | #define __STATIC_FORCEINLINE __STATIC_INLINE
144 | #endif
145 | #ifndef __NO_RETURN
146 | #define __NO_RETURN __attribute__((noreturn))
147 | #endif
148 | #ifndef __USED
149 | #define __USED __attribute__((used))
150 | #endif
151 | #ifndef __WEAK
152 | #define __WEAK __attribute__((weak))
153 | #endif
154 | #ifndef __PACKED
155 | #define __PACKED __packed__
156 | #endif
157 | #ifndef __PACKED_STRUCT
158 | #define __PACKED_STRUCT struct __packed__
159 | #endif
160 | #ifndef __PACKED_UNION
161 | #define __PACKED_UNION union __packed__
162 | #endif
163 | #ifndef __UNALIGNED_UINT32 /* deprecated */
164 | struct __packed__ T_UINT32 { uint32_t v; };
165 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
166 | #endif
167 | #ifndef __UNALIGNED_UINT16_WRITE
168 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
169 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
170 | #endif
171 | #ifndef __UNALIGNED_UINT16_READ
172 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
173 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
174 | #endif
175 | #ifndef __UNALIGNED_UINT32_WRITE
176 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
177 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
178 | #endif
179 | #ifndef __UNALIGNED_UINT32_READ
180 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
181 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
182 | #endif
183 | #ifndef __ALIGNED
184 | #define __ALIGNED(x) __align(x)
185 | #endif
186 | #ifndef __RESTRICT
187 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
188 | #define __RESTRICT
189 | #endif
190 |
191 |
192 | /*
193 | * COSMIC Compiler
194 | */
195 | #elif defined ( __CSMC__ )
196 | #include
197 |
198 | #ifndef __ASM
199 | #define __ASM _asm
200 | #endif
201 | #ifndef __INLINE
202 | #define __INLINE inline
203 | #endif
204 | #ifndef __STATIC_INLINE
205 | #define __STATIC_INLINE static inline
206 | #endif
207 | #ifndef __STATIC_FORCEINLINE
208 | #define __STATIC_FORCEINLINE __STATIC_INLINE
209 | #endif
210 | #ifndef __NO_RETURN
211 | // NO RETURN is automatically detected hence no warning here
212 | #define __NO_RETURN
213 | #endif
214 | #ifndef __USED
215 | #warning No compiler specific solution for __USED. __USED is ignored.
216 | #define __USED
217 | #endif
218 | #ifndef __WEAK
219 | #define __WEAK __weak
220 | #endif
221 | #ifndef __PACKED
222 | #define __PACKED @packed
223 | #endif
224 | #ifndef __PACKED_STRUCT
225 | #define __PACKED_STRUCT @packed struct
226 | #endif
227 | #ifndef __PACKED_UNION
228 | #define __PACKED_UNION @packed union
229 | #endif
230 | #ifndef __UNALIGNED_UINT32 /* deprecated */
231 | @packed struct T_UINT32 { uint32_t v; };
232 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
233 | #endif
234 | #ifndef __UNALIGNED_UINT16_WRITE
235 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
236 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
237 | #endif
238 | #ifndef __UNALIGNED_UINT16_READ
239 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
240 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
241 | #endif
242 | #ifndef __UNALIGNED_UINT32_WRITE
243 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
244 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
245 | #endif
246 | #ifndef __UNALIGNED_UINT32_READ
247 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
248 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
249 | #endif
250 | #ifndef __ALIGNED
251 | #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
252 | #define __ALIGNED(x)
253 | #endif
254 | #ifndef __RESTRICT
255 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
256 | #define __RESTRICT
257 | #endif
258 |
259 |
260 | #else
261 | #error Unknown compiler.
262 | #endif
263 |
264 |
265 | #endif /* __CMSIS_COMPILER_H */
266 |
267 |
--------------------------------------------------------------------------------