Skip to content

Commit 5e27b23

Browse files
Try to fix bank test
1 parent 42eb490 commit 5e27b23

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

connectivity/drivers/emac/TARGET_STM/STM32EthMACv1.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ bool STM32EthMACv1::TxDMA::descOwnedByDMA(size_t descIdx) {
6262

6363
bool STM32EthMACv1::TxDMA::isDMAReadableBuffer(uint8_t const *start, size_t size) const {
6464
#ifdef TARGET_STM32F7
65-
if(reinterpret_cast<ptrdiff_t>(start) < 1024*16) {
65+
if(bufferTouchesMemoryBank(start, size, 0, 1024*16)) {
6666
// In ITCM memory, not accessible by DMA. Note that ITCM is not included in the CMSIS memory map (yet).
6767
return false;
6868
}
6969
#endif
7070

7171
#if TARGET_STM32F2 || TARGET_STM32F4
7272
// On STM32F2 and F2, ethernet DMA cannot access the flash memory.
73-
if(reinterpret_cast<ptrdiff_t>(start) >= MBED_ROM_START ||
74-
reinterpret_cast<ptrdiff_t>(start + size) <= MBED_ROM_START + MBED_ROM_SIZE)
75-
{
73+
if(bufferTouchesMemoryBank(start, size, MBED_ROM_START, MBED_ROM_SIZE)) {
7674
return false;
7775
}
7876
#endif

connectivity/drivers/emac/TARGET_STM/STM32EthMACv2.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,14 @@ namespace mbed {
6666
// On STM32H7, the Ethernet DMA cannot access data in DTCM. So, if someone sends
6767
// a packet with a data pointer in DTCM (e.g. a stack allocated payload), everything
6868
// will break if we don't copy it first.
69-
if(reinterpret_cast<ptrdiff_t>(start) >= MBED_RAM_BANK_SRAM_DTC_START ||
70-
reinterpret_cast<ptrdiff_t>(start + size) <= MBED_RAM_BANK_SRAM_DTC_START + MBED_RAM_BANK_SRAM_DTC_SIZE)
71-
{
69+
if(bufferTouchesMemoryBank(start, size, MBED_RAM_BANK_SRAM_DTC_START, MBED_RAM_BANK_SRAM_DTC_SIZE)) {
7270
return false;
7371
}
7472
#endif
7573

7674
#ifdef TARGET_STM32H5
77-
// On STM32H7, the Ethernet DMA cannot access data in backup SRAM.
78-
if(reinterpret_cast<ptrdiff_t>(start) >= MBED_RAM_BANK_SRAM_BKUP_START ||
79-
reinterpret_cast<ptrdiff_t>(start + size) <= MBED_RAM_BANK_SRAM_BKUP_START + MBED_RAM_BANK_SRAM_BKUP_SIZE)
80-
{
75+
// On STM32H5, the Ethernet DMA cannot access data in backup SRAM.
76+
if(bufferTouchesMemoryBank(start, size, MBED_RAM_BANK_SRAM_BKUP_START, MBED_RAM_BANK_SRAM_BKUP_SIZE)) {
8177
return false;
8278
}
8379
#endif

connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,3 @@ elseif("NUCLEO_F756ZG" IN_LIST MBED_TARGET_LABELS)
1212
elseif("NUCLEO_F767ZI" IN_LIST MBED_TARGET_LABELS)
1313
add_subdirectory(TARGET_NUCLEO_F767ZI)
1414
endif()
15-
16-
target_include_directories(mbed-emac
17-
PUBLIC
18-
.
19-
)
20-
21-
target_sources(mbed-emac
22-
PRIVATE
23-
stm32f7_eth_conf.c
24-
)

connectivity/drivers/emac/include/GenericEthDMA.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ namespace mbed {
8383
/// to tell it to start running again.
8484
virtual void giveToDMA(size_t descIdx, uint8_t const * buffer, size_t len, bool firstDesc, bool lastDesc) = 0;
8585

86+
// Utility function for implementing isDMAReadableBuffer().
87+
// 1D intersection test between a buffer and a memory bank.
88+
static bool bufferTouchesMemoryBank(uint8_t const * start, size_t size, uint32_t bankStartAddr, uint32_t bankSize) {
89+
const auto startAddrInt = reinterpret_cast<ptrdiff_t>(start);
90+
91+
if(startAddrInt < bankStartAddr) {
92+
// Case 1: buffer begins before bank
93+
return (startAddrInt + size) > bankStartAddr;
94+
}
95+
else if(startAddrInt >= bankStartAddr && startAddrInt < (bankStartAddr + bankSize)) {
96+
// Case 2: buffer begins inside bank
97+
return true;
98+
}
99+
else {
100+
// Case 3: buffer begins after bank
101+
return false;
102+
}
103+
}
104+
86105
public:
87106
CompositeEMAC::ErrCode init() override {
88107
// At the start, we own all the descriptors

0 commit comments

Comments
 (0)