source: trunk/firmware/App/SES/FileX/Target/fx_stm32_sd_driver.h

Last change on this file was 32, checked in by Zed, 3 weeks ago

Manually added FileX support.

File size: 7.6 KB
Line 
1/***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 * Copyright (c) 2025 STMicroelectronics
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the MIT License which is available at
7 * https://opensource.org/licenses/MIT.
8 *
9 * SPDX-License-Identifier: MIT
10 **************************************************************************/
11
12/* Define to prevent recursive inclusion -------------------------------------*/
13#ifndef FX_STM32_SD_DRIVER_H
14#define FX_STM32_SD_DRIVER_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/* Includes ------------------------------------------------------------------*/
21#include "fx_api.h"
22#include "stm32n6xx_hal.h"
23
24/* USER CODE BEGIN Includes */
25
26/* USER CODE END Includes */
27
28/* Exported types ------------------------------------------------------------*/
29/* USER CODE BEGIN ET */
30
31/* USER CODE END ET */
32
33extern SemaphoreHandle_t sd_tx_semaphore;
34extern SemaphoreHandle_t sd_rx_semaphore;
35
36/* Exported constants --------------------------------------------------------*/
37/* USER CODE BEGIN EC */
38
39/* USER CODE END EC */
40/* Default timeout used to wait for fx operations */
41#define FX_STM32_SD_DEFAULT_TIMEOUT (10 * configTICK_RATE_HZ)
42
43/* Let the filex low-level driver initialize the SD driver */
44#define FX_STM32_SD_INIT 1
45
46/* Enable the cache mainatenance, required when using the SD DMA */
47#define FX_STM32_SD_CACHE_MAINTENANCE 1
48
49/* Use the SD DMA API */
50#define FX_STM32_SD_DMA_API 1
51
52/* SDIO instance to be used by FileX */
53#define FX_STM32_SD_INSTANCE 0
54
55/* Default sector size, used by the driver */
56#define FX_STM32_SD_DEFAULT_SECTOR_SIZE 512
57
58/* Exported macro ------------------------------------------------------------*/
59/* USER CODE BEGIN EM */
60
61/* USER CODE END EM */
62/* Define the CPU Cache maintenance macros */
63#if (FX_STM32_SD_CACHE_MAINTENANCE == 1)
64#define invalidate_cache_by_addr(__ptr__, __size__) SCB_InvalidateDCache_by_Addr((void *)__ptr__, (int32_t)__size__)
65#define clean_cache_by_addr(__ptr__, __size__) SCB_CleanDCache_by_Addr((uint32_t *)__ptr__, (int32_t)__size__)
66#endif
67/* Define the macro to get the current time in ticks */
68/* USER CODE BEGIN FX_STM32_SD_CURRENT_TIME_TX */
69
70#define FX_STM32_SD_CURRENT_TIME() xTaskGetTickCount()
71
72/* USER CODE END FX_STM32_SD_CURRENT_TIME_TX */
73
74/* Macro called before initializing the SD driver
75 * e.g. create a semaphore used for transfer notification */
76/* USER CODE BEGIN FX_STM32_SD_PRE_INIT */
77
78#define FX_STM32_SD_PRE_INIT(_media_ptr) do { \
79 sd_rx_semaphore = xSemaphoreCreateBinary(); \
80 sd_tx_semaphore = xSemaphoreCreateBinary(); \
81 if ((sd_rx_semaphore == NULL) || \
82 (sd_tx_semaphore == NULL)) \
83 { \
84 _media_ptr->fx_media_driver_status = FX_IO_ERROR; \
85 } \
86 } while(0)
87
88/* USER CODE END FX_STM32_SD_PRE_INIT */
89
90/* Macro called after initializing the SD driver */
91/* USER CODE BEGIN FX_STM32_SD_POST_INIT */
92
93#define FX_STM32_SD_POST_INIT(_media_ptr)
94
95/* USER CODE END FX_STM32_SD_POST_INIT */
96
97/* Macro called after the SD deinit */
98/* USER CODE BEGIN FX_STM32_SD_POST_DEINIT */
99
100#define FX_STM32_SD_POST_DEINIT(_media_ptr) do { \
101 vSemaphoreDelete(sd_rx_semaphore); \
102 vSemaphoreDelete(sd_tx_semaphore); \
103 } while(0)
104
105/* USER CODE END FX_STM32_SD_POST_DEINIT */
106
107/* Macro called after the abort request */
108/* USER CODE BEGIN FX_STM32_SD_POST_ABORT */
109
110#define FX_STM32_SD_POST_ABORT(_media_ptr)
111
112/* USER CODE END FX_STM32_SD_POST_ABORT */
113
114/* Macro called before performing read operation */
115/* USER CODE BEGIN FX_STM32_SD_PRE_READ_TRANSFER */
116
117#define FX_STM32_SD_PRE_READ_TRANSFER(_media_ptr)
118
119/* USER CODE END FX_STM32_SD_PRE_READ_TRANSFER */
120
121/* Macro called after performing read operation */
122/* USER CODE BEGIN FX_STM32_SD_POST_READ_TRANSFER */
123
124#define FX_STM32_SD_POST_READ_TRANSFER(_media_ptr)
125
126/* USER CODE END FX_STM32_SD_POST_READ_TRANSFER */
127
128/* Macro for read error handling */
129/* USER CODE BEGIN FX_STM32_SD_READ_TRANSFER_ERROR */
130
131#define FX_STM32_SD_READ_TRANSFER_ERROR(_status_)
132
133/* USER CODE END FX_STM32_SD_READ_TRANSFER_ERROR */
134
135/* Define how to notify about Read completion operation */
136
137/* USER CODE BEGIN FX_STM32_SD_READ_CPLT_NOTIFY */
138
139#define FX_STM32_SD_READ_CPLT_NOTIFY() do { \
140 if(xSemaphoreTake(sd_rx_semaphore, FX_STM32_SD_DEFAULT_TIMEOUT) != pdTRUE) \
141 { \
142 return FX_IO_ERROR; \
143 } \
144 } while(0)
145
146/* USER CODE END FX_STM32_SD_READ_CPLT_NOTIFY */
147
148/* Define how to notify about write completion operation */
149/* USER CODE BEGIN FX_STM32_SD_WRITE_CPLT_NOTIFY */
150
151#define FX_STM32_SD_WRITE_CPLT_NOTIFY() do { \
152 if(xSemaphoreTake(sd_tx_semaphore, FX_STM32_SD_DEFAULT_TIMEOUT) != pdTRUE) \
153 { \
154 return FX_IO_ERROR; \
155 } \
156 } while(0)
157
158/* USER CODE END FX_STM32_SD_WRITE_CPLT_NOTIFY */
159
160/* Macro called before performing write operation */
161/* USER CODE BEGIN FX_STM32_SD_PRE_WRITE_TRANSFER */
162
163#define FX_STM32_SD_PRE_WRITE_TRANSFER(_media_ptr)
164
165/* USER CODE END FX_STM32_SD_PRE_WRITE_TRANSFER */
166
167/* Macro called after performing write operation */
168/* USER CODE BEGIN FX_STM32_SD_POST_WRITE_TRANSFER */
169
170#define FX_STM32_SD_POST_WRITE_TRANSFER(_media_ptr)
171
172/* USER CODE END FX_STM32_SD_POST_WRITE_TRANSFER */
173
174/* Macro for write error handling */
175/* USER CODE BEGIN FX_STM32_SD_WRITE_TRANSFER_ERROR */
176
177#define FX_STM32_SD_WRITE_TRANSFER_ERROR(_status_)
178
179/* USER CODE END FX_STM32_SD_WRITE_TRANSFER_ERROR */
180
181/* Exported functions prototypes ---------------------------------------------*/
182
183INT fx_stm32_sd_init(UINT instance);
184INT fx_stm32_sd_deinit(UINT instance);
185
186INT fx_stm32_sd_get_status(UINT instance);
187
188INT fx_stm32_sd_read_blocks(UINT instance, UINT *buffer, UINT start_block, UINT total_blocks);
189INT fx_stm32_sd_write_blocks(UINT instance, UINT *buffer, UINT start_block, UINT total_blocks);
190
191VOID fx_stm32_sd_driver(FX_MEDIA *media_ptr);
192
193/* USER CODE BEGIN EFP */
194
195/* USER CODE END EFP */
196
197/* Private defines -----------------------------------------------------------*/
198/* USER CODE BEGIN PD */
199
200/* USER CODE END PD */
201
202/* USER CODE BEGIN 1 */
203
204/* USER CODE END 1 */
205
206#ifdef __cplusplus
207}
208#endif
209
210#endif /* FX_STM32_SD_DRIVER_H */
Note: See TracBrowser for help on using the repository browser.