63
63
#define LINK_MTU 1024
64
64
#define MAX (a ,b ) (a>b)?a:b
65
65
66
+ /* D-cache maintenance for DMA buffers */
67
+ #if defined (__DCACHE_PRESENT ) && (__DCACHE_PRESENT == 1U )
68
+ #define _CYHAL_DCACHE_MAINTENANCE
69
+ #define _CYHAL_DMA_BUFFER_ALIGN_BYTES (32u)
70
+ #else
71
+ #define _CYHAL_DMA_BUFFER_ALIGN_BYTES (4u)
72
+ #endif /* defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) */
73
+
74
+ /* Macro to ALIGN */
75
+ #if defined (__ARMCC_VERSION ) /* ARM Compiler */
76
+ #define ALIGN_HAL_COMMON (buf , x ) __align(x) buf
77
+ #elif defined (__GNUC__ ) /* GNU Compiler */
78
+ #define ALIGN_HAL_COMMON (buf , x ) buf __attribute__ ((aligned (x)))
79
+ #elif defined (__ICCARM__ ) /* IAR Compiler */
80
+ #define ALIGN_HAL_COMMON (buf , x ) __ALIGNED(x) buf
81
+ #endif
82
+
83
+ /* Macro to get variable aligned for cache maintenance purpose */
84
+ #define CYHAL_ALIGN_DMA_BUFFER (arg ) ALIGN_HAL_COMMON(arg, _CYHAL_DMA_BUFFER_ALIGN_BYTES)
85
+
86
+
66
87
extern pinconfig_t PinConfig [];
67
88
extern SD_HandleTypeDef hsd ;
68
89
@@ -74,7 +95,7 @@ static uint32_t dctrl;
74
95
static whd_driver_t whd_handler ;
75
96
static cyhal_sdio_irq_handler_t sdio_irq_handler ;
76
97
77
- static uint8_t temp_dma_buffer [2048 ] __attribute__(( aligned ( 8 )) );
98
+ CYHAL_ALIGN_DMA_BUFFER ( static uint8_t temp_dma_buffer [2048 ]);
78
99
static uint8_t * user_data ;
79
100
static uint32_t user_data_size ;
80
101
static uint8_t * dma_data_source ;
@@ -150,22 +171,24 @@ static void sdio_prepare_data_transfer(cyhal_transfer_t direction, uint32_t bloc
150
171
dma_transfer_size = (uint32_t )(((data_size + (uint16_t ) block_size - 1 ) / (uint16_t ) block_size ) * (uint16_t ) block_size );
151
172
152
173
if (direction == CYHAL_WRITE ) {
153
-
154
- #if !(defined(DUAL_CORE ) && defined(CORE_CM4 ))
155
- SCB_CleanDCache_by_Addr ((uint32_t * )dma_data_source , data_size + 32 );
156
- #endif
157
174
memcpy (temp_dma_buffer , data , data_size );
158
175
dma_data_source = temp_dma_buffer ;
159
176
} else {
160
177
dma_data_source = (uint8_t * )temp_dma_buffer ;
161
- //VIKR
162
- //memset(dma_data_source,0x12,data_size);
178
+ }
163
179
164
- #if !(defined(DUAL_CORE ) && defined(CORE_CM4 ))
180
+ #ifdef _CYHAL_DCACHE_MAINTENANCE
181
+ if (direction == CYHAL_WRITE )
182
+ {
183
+ SCB_CleanDCache_by_Addr ((uint32_t * )dma_data_source , block_size * dma_transfer_size );
184
+ }
185
+ else
186
+ {
165
187
/* Cache-Invalidate the output from DMA */
166
- SCB_CleanDCache_by_Addr ((uint32_t * )dma_data_source , data_size + 32 );
167
- #endif
188
+ SCB_InvalidateDCache_by_Addr ((uint32_t * )dma_data_source ,
189
+ data_size + __SCB_DCACHE_LINE_SIZE );
168
190
}
191
+ #endif
169
192
170
193
SDIO -> DTIMER = (uint32_t ) 0xFFFFFFFF ;
171
194
SDIO -> DLEN = dma_transfer_size ;
@@ -252,12 +275,6 @@ cy_rslt_t cyhal_sdio_init(cyhal_sdio_t *obj, cyhal_gpio_t cmd, cyhal_gpio_t clk,
252
275
/* Enable the SDIO Clock */
253
276
__HAL_RCC_SDMMC1_CLK_ENABLE ();
254
277
255
- #if !(defined(DUAL_CORE ) && defined(CORE_CM4 ))
256
- /* Disable DCache for STM32H7 family */
257
- SCB_CleanDCache ();
258
- SCB_DisableDCache ();
259
- #endif
260
-
261
278
WPRINT_WHD_DEBUG (("in init: %p\n" , sdio_transfer_finished_semaphore ));
262
279
263
280
// Lower speed configuration
@@ -437,6 +454,12 @@ cy_rslt_t cyhal_sdio_bulk_transfer(cyhal_sdio_t *obj, cyhal_transfer_t direction
437
454
}
438
455
439
456
if (direction == CYHAL_READ ) {
457
+ #ifdef _CYHAL_DCACHE_MAINTENANCE
458
+ SCB_CleanInvalidateDCache_by_Addr (
459
+ (uint32_t * )((uint32_t )dma_data_source & ~(__SCB_DCACHE_LINE_SIZE - 1U )),
460
+ user_data_size + __SCB_DCACHE_LINE_SIZE );
461
+ #endif /* if defined(_CYHAL_DCACHE_MAINTENANCE) */
462
+
440
463
memcpy (user_data , dma_data_source , (size_t ) user_data_size );
441
464
}
442
465
0 commit comments