1 | /* USER CODE BEGIN Header */ |
---|
2 | /** |
---|
3 | ****************************************************************************** |
---|
4 | * @file app_azure_rtos.c |
---|
5 | * @author MCD Application Team |
---|
6 | * @brief app_azure_rtos application implementation file |
---|
7 | ****************************************************************************** |
---|
8 | * @attention |
---|
9 | * |
---|
10 | * Copyright (c) 2020-2021 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 | |
---|
23 | #include "app_azure_rtos.h" |
---|
24 | #include "stm32h7xx.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 | #if (USE_STATIC_ALLOCATION == 1) |
---|
48 | /* USER CODE BEGIN TX_Pool_Buffer */ |
---|
49 | /* USER CODE END TX_Pool_Buffer */ |
---|
50 | #if defined ( __ICCARM__ ) |
---|
51 | #pragma data_alignment=4 |
---|
52 | #endif |
---|
53 | __ALIGN_BEGIN static UCHAR tx_byte_pool_buffer[TX_APP_MEM_POOL_SIZE] __ALIGN_END; |
---|
54 | static TX_BYTE_POOL tx_app_byte_pool; |
---|
55 | |
---|
56 | /* USER CODE BEGIN FX_Pool_Buffer */ |
---|
57 | /* USER CODE END FX_Pool_Buffer */ |
---|
58 | #if defined ( __ICCARM__ ) |
---|
59 | #pragma data_alignment=4 |
---|
60 | #endif |
---|
61 | __ALIGN_BEGIN static UCHAR fx_byte_pool_buffer[FX_APP_MEM_POOL_SIZE] __ALIGN_END; |
---|
62 | static TX_BYTE_POOL fx_app_byte_pool; |
---|
63 | |
---|
64 | #endif |
---|
65 | |
---|
66 | /* USER CODE BEGIN PV */ |
---|
67 | |
---|
68 | /* USER CODE END PV */ |
---|
69 | |
---|
70 | /* Private function prototypes -----------------------------------------------*/ |
---|
71 | /* USER CODE BEGIN PFP */ |
---|
72 | |
---|
73 | /* USER CODE END PFP */ |
---|
74 | |
---|
75 | /** |
---|
76 | * @brief Define the initial system. |
---|
77 | * @param first_unused_memory : Pointer to the first unused memory |
---|
78 | * @retval None |
---|
79 | */ |
---|
80 | VOID tx_application_define(VOID *first_unused_memory) |
---|
81 | { |
---|
82 | /* USER CODE BEGIN tx_application_define_1*/ |
---|
83 | |
---|
84 | /* USER CODE END tx_application_define_1 */ |
---|
85 | #if (USE_STATIC_ALLOCATION == 1) |
---|
86 | UINT status = TX_SUCCESS; |
---|
87 | VOID *memory_ptr; |
---|
88 | |
---|
89 | if (tx_byte_pool_create(&tx_app_byte_pool, "Tx App memory pool", tx_byte_pool_buffer, TX_APP_MEM_POOL_SIZE) != TX_SUCCESS) |
---|
90 | { |
---|
91 | /* USER CODE BEGIN TX_Byte_Pool_Error */ |
---|
92 | |
---|
93 | /* USER CODE END TX_Byte_Pool_Error */ |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | /* USER CODE BEGIN TX_Byte_Pool_Success */ |
---|
98 | |
---|
99 | /* USER CODE END TX_Byte_Pool_Success */ |
---|
100 | |
---|
101 | memory_ptr = (VOID *)&tx_app_byte_pool; |
---|
102 | status = App_ThreadX_Init(memory_ptr); |
---|
103 | if (status != TX_SUCCESS) |
---|
104 | { |
---|
105 | /* USER CODE BEGIN App_ThreadX_Init_Error */ |
---|
106 | while(1) |
---|
107 | { |
---|
108 | } |
---|
109 | /* USER CODE END App_ThreadX_Init_Error */ |
---|
110 | } |
---|
111 | |
---|
112 | /* USER CODE BEGIN App_ThreadX_Init_Success */ |
---|
113 | |
---|
114 | /* USER CODE END App_ThreadX_Init_Success */ |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | if (tx_byte_pool_create(&fx_app_byte_pool, "Fx App memory pool", fx_byte_pool_buffer, FX_APP_MEM_POOL_SIZE) != TX_SUCCESS) |
---|
119 | { |
---|
120 | /* USER CODE BEGIN FX_Byte_Pool_Error */ |
---|
121 | |
---|
122 | /* USER CODE END FX_Byte_Pool_Error */ |
---|
123 | } |
---|
124 | else |
---|
125 | { |
---|
126 | /* USER CODE BEGIN FX_Byte_Pool_Success */ |
---|
127 | |
---|
128 | /* USER CODE END FX_Byte_Pool_Success */ |
---|
129 | |
---|
130 | memory_ptr = (VOID *)&fx_app_byte_pool; |
---|
131 | status = MX_FileX_Init(memory_ptr); |
---|
132 | if (status != FX_SUCCESS) |
---|
133 | { |
---|
134 | /* USER CODE BEGIN MX_FileX_Init_Error */ |
---|
135 | while(1) |
---|
136 | { |
---|
137 | } |
---|
138 | /* USER CODE END MX_FileX_Init_Error */ |
---|
139 | } |
---|
140 | |
---|
141 | /* USER CODE BEGIN MX_FileX_Init_Success */ |
---|
142 | |
---|
143 | /* USER CODE END MX_FileX_Init_Success */ |
---|
144 | } |
---|
145 | |
---|
146 | #else |
---|
147 | /* |
---|
148 | * Using dynamic memory allocation requires to apply some changes to the linker file. |
---|
149 | * ThreadX needs to pass a pointer to the first free memory location in RAM to the tx_application_define() function, |
---|
150 | * using the "first_unused_memory" argument. |
---|
151 | * This require changes in the linker files to expose this memory location. |
---|
152 | * For EWARM add the following section into the .icf file: |
---|
153 | place in RAM_region { last section FREE_MEM }; |
---|
154 | * For MDK-ARM |
---|
155 | - either define the RW_IRAM1 region in the ".sct" file |
---|
156 | - or modify the line below in "tx_initialize_low_level.S to match the memory region being used |
---|
157 | LDR r1, =|Image$$RW_IRAM1$$ZI$$Limit| |
---|
158 | |
---|
159 | * For STM32CubeIDE add the following section into the .ld file: |
---|
160 | ._threadx_heap : |
---|
161 | { |
---|
162 | . = ALIGN(8); |
---|
163 | __RAM_segment_used_end__ = .; |
---|
164 | . = . + 64K; |
---|
165 | . = ALIGN(8); |
---|
166 | } >RAM_D1 AT> RAM_D1 |
---|
167 | * The simplest way to provide memory for ThreadX is to define a new section, see ._threadx_heap above. |
---|
168 | * In the example above the ThreadX heap size is set to 64KBytes. |
---|
169 | * The ._threadx_heap must be located between the .bss and the ._user_heap_stack sections in the linker script. |
---|
170 | * Caution: Make sure that ThreadX does not need more than the provided heap memory (64KBytes in this example). |
---|
171 | * Read more in STM32CubeIDE User Guide, chapter: "Linker script". |
---|
172 | |
---|
173 | * The "tx_initialize_low_level.S" should be also modified to enable the "USE_DYNAMIC_MEMORY_ALLOCATION" flag. |
---|
174 | */ |
---|
175 | |
---|
176 | /* USER CODE BEGIN DYNAMIC_MEM_ALLOC */ |
---|
177 | (void)first_unused_memory; |
---|
178 | /* USER CODE END DYNAMIC_MEM_ALLOC */ |
---|
179 | #endif |
---|
180 | |
---|
181 | } |
---|