Skip to content

Commit 3ec9c19

Browse files
authored
Merge pull request #10314 from kjbracey-arm/rt1050_dcache
i.MX RT1050: Reactivate data cache
2 parents 69b9f3f + 6fe5076 commit 3ec9c19

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

features/netsocket/emac-drivers/TARGET_NXP_EMAC/TARGET_IMX/imx_emac.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ static void update_read_buffer(uint8_t *buf)
9999
g_handle.rxBdCurrent[0]->buffer = buf;
100100
}
101101

102+
/* Ensures buffer pointer is written before control. */
103+
__DMB();
104+
102105
/* Clears status. */
103106
g_handle.rxBdCurrent[0]->control &= ENET_BUFFDESCRIPTOR_RX_WRAP_MASK;
104107

@@ -112,6 +115,9 @@ static void update_read_buffer(uint8_t *buf)
112115
g_handle.rxBdCurrent[0]++;
113116
}
114117

118+
/* Ensures descriptor is written before kicking hardware. */
119+
__DSB();
120+
115121
/* Actives the receive buffer descriptor. */
116122
ENET->RDAR = ENET_RDAR_RDAR_MASK;
117123
}
@@ -195,6 +201,7 @@ bool Kinetis_EMAC::low_level_init_successful()
195201
return false;
196202

197203
rx_ptr[i] = (uint32_t*)memory_manager->get_ptr(rx_buff[i]);
204+
SCB_InvalidateDCache_by_Addr(rx_ptr[i], ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT));
198205
}
199206

200207
tx_consume_index = tx_produce_index = 0;
@@ -277,6 +284,7 @@ emac_mem_buf_t *Kinetis_EMAC::low_level_input(int idx)
277284

278285
/* Zero-copy */
279286
p = rx_buff[idx];
287+
SCB_InvalidateDCache_by_Addr(rx_ptr[idx], length);
280288
memory_manager->set_len(p, length);
281289

282290
/* Attempt to queue new buffer */
@@ -295,6 +303,7 @@ emac_mem_buf_t *Kinetis_EMAC::low_level_input(int idx)
295303

296304
rx_buff[idx] = temp_rxbuf;
297305
rx_ptr[idx] = (uint32_t*)memory_manager->get_ptr(rx_buff[idx]);
306+
SCB_InvalidateDCache_by_Addr(rx_ptr[idx], ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT));
298307

299308
update_read_buffer((uint8_t*)rx_ptr[idx]);
300309
}
@@ -399,6 +408,8 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
399408
buf = copy_buf;
400409
}
401410

411+
SCB_CleanDCache_by_Addr(static_cast<uint32_t *>(memory_manager->get_ptr(buf)), memory_manager->get_len(buf));
412+
402413
/* Check if a descriptor is available for the transfer (wait 10ms before dropping the buffer) */
403414
if (xTXDCountSem.wait(10) == 0) {
404415
memory_manager->free(buf);
@@ -415,6 +426,8 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
415426
/* Setup transfers */
416427
g_handle.txBdCurrent[0]->buffer = static_cast<uint8_t *>(memory_manager->get_ptr(buf));
417428
g_handle.txBdCurrent[0]->length = memory_manager->get_len(buf);
429+
/* Ensures buffer and length is written before control. */
430+
__DMB();
418431
g_handle.txBdCurrent[0]->control |= (ENET_BUFFDESCRIPTOR_TX_READY_MASK | ENET_BUFFDESCRIPTOR_TX_LAST_MASK);
419432

420433
/* Increase the buffer descriptor address. */
@@ -424,6 +437,9 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
424437
g_handle.txBdCurrent[0]++;
425438
}
426439

440+
/* Ensures descriptor is written before kicking hardware. */
441+
__DSB();
442+
427443
/* Active the transmit buffer descriptor. */
428444
ENET->TDAR = ENET_TDAR_TDAR_MASK;
429445

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/TARGET_EVK/mbed_overrides.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ void BOARD_ConfigMPU(void)
102102
* this suggestion is referred from chapter 2.2.1 Memory regions,
103103
* types and attributes in Cortex-M7 Devices, Generic User Guide */
104104
#if defined(SDRAM_IS_SHAREABLE)
105-
/* Region 7 setting: Memory with Normal type, not shareable, outer/inner write back */
105+
/* Region 7 setting: Memory with Normal type, shareable, outer/inner write back, write/read allocate */
106106
MPU->RBAR = ARM_MPU_RBAR(7, 0x80000000U);
107-
MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 1, 1, 1, 0, ARM_MPU_REGION_SIZE_32MB);
107+
MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 1, 1, 1, 0, ARM_MPU_REGION_SIZE_32MB);
108108
#else
109-
/* Region 7 setting: Memory with Normal type, not shareable, outer/inner write back */
109+
/* Region 7 setting: Memory with Normal type, not shareable, outer/inner write back, write/read allocate */
110110
MPU->RBAR = ARM_MPU_RBAR(7, 0x80000000U);
111-
MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_32MB);
111+
MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_32MB);
112112
#endif
113113

114114
/* Region 8 setting, set last 2MB of SDRAM can't be accessed by cache, glocal variables which are not expected to be

targets/targets.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,6 @@
19201920
"XIP_BOOT_HEADER_DCD_ENABLE=1",
19211921
"SKIP_SYSCLK_INIT",
19221922
"FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE",
1923-
"SDRAM_IS_SHAREABLE",
19241923
"MBED_MPU_CUSTOM"
19251924
],
19261925
"inherits": ["Target"],

0 commit comments

Comments
 (0)