Skip to content

Conversation

@mathieuchopstm
Copy link
Contributor

This PR places the chan_blen_transfer DMA test's TX and RX buffers in a separate file that gets entirely relocated. This ensures that the buffers reside in the correct memory, without breaking other things due to relocation of test data/code.

Fixes #75676 (tested on Nucleo-H743ZI) without introducing regression of #75125 (tested on Nucleo-WB09KE).

@zephyrbot zephyrbot added the area: DMA Direct Memory Access label Jul 15, 2024
@mathieuchopstm mathieuchopstm added the priority: low Low impact/importance bug label Jul 15, 2024
@zephyrbot zephyrbot requested a review from teburd July 15, 2024 14:46
@mathieuchopstm mathieuchopstm added this to the v4.0.0 milestone Jul 15, 2024
This commit places the chan_blen_transfer DMA test's TX and RX buffers
in a separate file that gets entirely relocated. This ensures that the
buffers reside in the correct memory, without breaking other things
due to relocation of test data/code.

Fixes zephyrproject-rtos#75676.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
@mathieuchopstm mathieuchopstm force-pushed the dma_chan_blen_transfer_fix_v2 branch from 3cb13d7 to 6a9a715 Compare July 15, 2024 14:50
@mathieuchopstm
Copy link
Contributor Author

Testing on NXP boards - which are the only other users of code relocation for this sample, and should have probably been broken by #75125 too - would be appreciated.

@erwango
Copy link
Member

erwango commented Jul 31, 2024

Testing on NXP boards - which are the only other users of code relocation for this sample, and should have probably been broken by #75125 too - would be appreciated.

@hakehuang Would you be able to have a look ?

@erwango erwango added the backport v3.7-branch Request backport to the v3.7-branch label Jul 31, 2024
erwango
erwango previously approved these changes Jul 31, 2024
teburd
teburd previously approved these changes Jul 31, 2024
@hakehuang
Copy link
Contributor

hakehuang commented Aug 1, 2024

@hakehuang Would you be able to have a look ?

@erwango let me run some regression test on this, the code seems good to me, will feedback soon.

I meet a problem in mimxrt1024_evk/mimxrt1050_evk/mimxrt1060_evk

*** Booting Zephyr OS build v3.7.0-rc3-1-g6a9a715ee3f4 ***
Running TESTSUITE dma_m2m
===================================================================
START - test_tst_dma0_m2m_chan0_burst16
Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=0, BURST_LEN=2
Starting the transfer
ASSERTION FAIL [0] @ WEST_TOPDIR/zephyr/lib/libc/picolibc/libc-hooks.c:224
E: r0/a1:  0x00000004  r1/a2:  0x000000e0  r2/a3:  0x40184000
E: r3/a4:  0x00000004 r12/ip:  0x00000000 r14/lr:  0x60003839
E:  xpsr:  0x21000000
E: Faulting instruction address (r15/pc): 0x60007508
E: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
E: Current thread: 0x80000838 (test_tst_dma0_m2m_chan0_burst16)
E: Halting system

the mainline code is ok

2024-07-22 01:09:41,299 - twister - DEBUG - DEVICE: *** Booting Zephyr OS build v3.7.0-rc3-91-gf9e3b65d3a97 ***
2024-07-22 01:09:41,301 - twister - DEBUG - DEVICE: Running TESTSUITE dma_m2m
2024-07-22 01:09:41,307 - twister - DEBUG - DEVICE: ===================================================================
2024-07-22 01:09:41,311 - twister - DEBUG - DEVICE: START - test_tst_dma0_m2m_chan0_burst16
2024-07-22 01:09:41,311 - twister - DEBUG - Could not find a matching testcase for 
2024-07-22 01:09:43,326 - twister - DEBUG - DEVICE: It is harder to be kind than to be wise........
2024-07-22 01:09:43,331 - twister - DEBUG - DEVICE: PASS - test_tst_dma0_m2m_chan0_burst16 in 2.015 seconds
2024-07-22 01:09:43,337 - twister - DEBUG - DEVICE: ===================================================================
2024-07-22 01:09:43,340 - twister - DEBUG - DEVICE: START - test_tst_dma0_m2m_chan0_burst8
2024-07-22 01:09:43,341 - twister - DEBUG - Could not find a matching testcase for drivers.dma.chan_blen_transfer.tst_dma0_m2m_chan0_burst8
2024-07-22 01:09:43,347 - twister - DEBUG - DEVICE: Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=0, BURST_LEN=1
2024-07-22 01:09:43,349 - twister - DEBUG - DEVICE: Starting the transfer
2024-07-22 01:09:43,351 - twister - DEBUG - DEVICE: DMA transfer done
2024-07-22 01:09:45,353 - twister - DEBUG - DEVICE: It is harder to be kind than to be wise........
2024-07-22 01:09:45,358 - twister - DEBUG - DEVICE: PASS - test_tst_dma0_m2m_chan0_burst8 in 2.014 seconds
2024-07-22 01:09:45,364 - twister - DEBUG - DEVICE: ===================================================================
2024-07-22 01:09:45,367 - twister - DEBUG - DEVICE: START - test_tst_dma0_m2m_chan1_burst16
2024-07-22 01:09:45,367 - twister - DEBUG - Could not find a matching testcase for drivers.dma.chan_blen_transfer.tst_dma0_m2m_chan1_burst16
2024-07-22 01:09:45,374 - twister - DEBUG - DEVICE: Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=1, BURST_LEN=2
2024-07-22 01:09:45,376 - twister - DEBUG - DEVICE: Starting the transfer
2024-07-22 01:09:45,378 - twister - DEBUG - DEVICE: DMA transfer done
2024-07-22 01:09:47,381 - twister - DEBUG - DEVICE: It is harder to be kind than to be wise........
2024-07-22 01:09:47,386 - twister - DEBUG - DEVICE: PASS - test_tst_dma0_m2m_chan1_burst16 in 2.014 seconds
2024-07-22 01:09:47,392 - twister - DEBUG - DEVICE: ===================================================================
2024-07-22 01:09:47,396 - twister - DEBUG - DEVICE: START - test_tst_dma0_m2m_chan1_burst8
2024-07-22 01:09:47,396 - twister - DEBUG - Could not find a matching testcase for drivers.dma.chan_blen_transfer.tst_dma0_m2m_chan1_burst8
2024-07-22 01:09:47,403 - twister - DEBUG - DEVICE: Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=1, BURST_LEN=1
2024-07-22 01:09:47,405 - twister - DEBUG - DEVICE: Starting the transfer
2024-07-22 01:09:47,406 - twister - DEBUG - DEVICE: DMA transfer done
2024-07-22 01:09:49,409 - twister - DEBUG - DEVICE: It is harder to be kind than to be wise........
2024-07-22 01:09:49,414 - twister - DEBUG - DEVICE: PASS - test_tst_dma0_m2m_chan1_burst8 in 2.014 seconds
2024-07-22 01:09:49,420 - twister - DEBUG - DEVICE: ===================================================================
2024-07-22 01:09:49,422 - twister - DEBUG - DEVICE: TESTSUITE dma_m2m succeeded
2024-07-22 01:09:49,423 - twister - DEBUG - DEVICE: 
2024-07-22 01:09:49,426 - twister - DEBUG - DEVICE: ------ TESTSUITE SUMMARY START ------
2024-07-22 01:09:49,426 - twister - DEBUG - DEVICE: 
2024-07-22 01:09:49,434 - twister - DEBUG - DEVICE: SUITE PASS - 100.00% [dma_m2m]: pass = 4, fail = 0, skip = 0, total = 4 duration = 8.057 seconds
2024-07-22 01:09:49,441 - twister - DEBUG - DEVICE: - PASS - [dma_m2m.test_tst_dma0_m2m_chan0_burst16] duration = 2.015 seconds
2024-07-22 01:09:49,448 - twister - DEBUG - DEVICE: - PASS - [dma_m2m.test_tst_dma0_m2m_chan0_burst8] duration = 2.014 seconds
2024-07-22 01:09:49,455 - twister - DEBUG - DEVICE: - PASS - [dma_m2m.test_tst_dma0_m2m_chan1_burst16] duration = 2.014 seconds
2024-07-22 01:09:49,461 - twister - DEBUG - DEVICE: - PASS - [dma_m2m.test_tst_dma0_m2m_chan1_burst8] duration = 2.014 seconds
2024-07-22 01:09:49,462 - twister - DEBUG - DEVICE: 
2024-07-22 01:09:49,465 - twister - DEBUG - DEVICE: ------ TESTSUITE SUMMARY END ------
2024-07-22 01:09:49,465 - twister - DEBUG - DEVICE: 
2024-07-22 01:09:49,471 - twister - DEBUG - DEVICE: ===================================================================
2024-07-22 01:09:49,475 - twister - DEBUG - DEVICE: RunID: c2d0fed492969696f6bbc125ddecdd14
2024-07-22 01:09:49,477 - twister - DEBUG - DEVICE: PROJECT EXECUTION SUCCESSFUL

@mathieuchopstm
Copy link
Contributor Author

@hakehuang

*** Booting Zephyr OS build v3.7.0-rc3-1-g6a9a715ee3f4 ***
Running TESTSUITE dma_m2m
===================================================================
START - test_tst_dma0_m2m_chan0_burst16
Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=0, BURST_LEN=2
Starting the transfer
ASSERTION FAIL [0] @ WEST_TOPDIR/zephyr/lib/libc/picolibc/libc-hooks.c:224
E: r0/a1:  0x00000004  r1/a2:  0x000000e0  r2/a3:  0x40184000
E: r3/a4:  0x00000004 r12/ip:  0x00000000 r14/lr:  0x60003839
E:  xpsr:  0x21000000
E: Faulting instruction address (r15/pc): 0x60007508
E: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
E: Current thread: 0x80000838 (test_tst_dma0_m2m_chan0_burst16)
E: Halting system

Trace isn't very informative since assertion was raised by libc-hooks.c:224:

FUNC_NORETURN void __assert_no_args(void)
{
__ASSERT_NO_MSG(0);
CODE_UNREACHABLE;
}

This is invoked by picolibc assert if _ASSERT_VERBOSE is not set:
https://github.com/zephyrproject-rtos/picolibc/blob/764ef4e401a8f4c6a86ab723533841f072885a5b/newlib/libc/include/assert.h#L46-L54
I assume the kernel panic comes from CODE_UNREACHABLE generating an undefined instruction.

However, I do not see any use of C assert in the dma_mcux_edma.c driver.
The test uses z_assert_true which, after expansion, is a call to z_zassert_:

static inline bool z_zassert_(bool cond, const char *file, int line)
{
if (cond == false) {
PRINT("\n Assertion failed at %s:%d\n", ztest_relative_filename(file), line);
ztest_test_fail();
return false;
}
return true;
}

Thus I am quite puzzled as to where this assertion failure comes from 🤔.

Could you run the tests with _ASSERT_VERBOSE enabled, which could shed some light as to what the problem is?

the mainline code is ok

Interesting.

Could you run the tests again with the following patch applied (i.e., with code relocation disabled)?

Maybe it was only needed because the i.MX DMA has a limitation similar to STM32WB0's that was worked around...? 🤷‍♂️

CONFIG_CODE_DATA_RELOCATION=y
CONFIG_MEM_ATTR_HEAP=y
CONFIG_DMA_LOOP_TRANSFER_RELOCATE_SECTION="ITCM"

- CONFIG_CODE_DATA_RELOCATION=y 
 CONFIG_MEM_ATTR_HEAP=y 
- CONFIG_DMA_LOOP_TRANSFER_RELOCATE_SECTION="ITCM" 

Marking as DNM until this is worked out.

@mathieuchopstm mathieuchopstm added the DNM This PR should not be merged (Do Not Merge) label Aug 1, 2024
@hakehuang
Copy link
Contributor

hakehuang commented Aug 2, 2024

Could you run the tests again with the following patch applied (i.e., with code relocation disabled)?

will try it and feedback once done.

@mathieuchopstm I find it is the ITCM which can not be accessed by DMA, so if I change below, then it works

--- a/tests/drivers/dma/chan_blen_transfer/boards/mimxrt1050_evk.conf
+++ b/tests/drivers/dma/chan_blen_transfer/boards/mimxrt1050_evk.conf
@@ -1,3 +1,3 @@
 CONFIG_CODE_DATA_RELOCATION=y
 CONFIG_MEM_ATTR_HEAP=y
-CONFIG_DMA_LOOP_TRANSFER_RELOCATE_SECTION="ITCM"
+CONFIG_DMA_LOOP_TRANSFER_RELOCATE_SECTION="DTCM"
diff --git a/tests/drivers/dma/chan_blen_transfer/boards/mimxrt1050_evk.overlay b/tests/drivers/dma/chan_blen_transfer/boards/mimxrt1050_evk.overlay
index 43b7fc37826..82f0bbe94e8 100644
--- a/tests/drivers/dma/chan_blen_transfer/boards/mimxrt1050_evk.overlay
+++ b/tests/drivers/dma/chan_blen_transfer/boards/mimxrt1050_evk.overlay
@@ -7,7 +7,7 @@

 #include <zephyr/dt-bindings/memory-attr/memory-attr-arm.h>

-&itcm {
+&dtcm {
        zephyr,memory-attr = <( DT_MEM_ARM(ATTR_MPU_RAM_NOCACHE) )>;
 };

the impacted platforms are:

boards/mimxrt1050_evk.conf:3:CONFIG_DMA_LOOP_TRANSFER_RELOCATE_SECTION="ITCM"
boards/mimxrt1024_evk.conf:3:CONFIG_DMA_LOOP_TRANSFER_RELOCATE_SECTION="ITCM"
boards/mimxrt1064_evk.conf:3:CONFIG_DMA_LOOP_TRANSFER_RELOCATE_SECTION="ITCM"
boards/mimxrt1060_evkb.conf:3:CONFIG_DMA_LOOP_TRANSFER_RELOCATE_SECTION="ITCM"

can you help to update those platform as what I changed for mimxrt1050_evk in your PR?

below is the test log

*** Booting Zephyr OS build v3.7.0-rc3-1-g6a9a715ee3f4 ***
Running TESTSUITE dma_m2m
===================================================================
START - test_tst_dma0_m2m_chan0_burst16
Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=0, BURST_LEN=2
Starting the transfer
DMA transfer done
It is harder to be kind than to be wise........
 PASS - test_tst_dma0_m2m_chan0_burst16 in 2.015 seconds
===================================================================
START - test_tst_dma0_m2m_chan0_burst8
Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=0, BURST_LEN=1
Starting the transfer
DMA transfer done
It is harder to be kind than to be wise........
 PASS - test_tst_dma0_m2m_chan0_burst8 in 2.014 seconds
===================================================================
START - test_tst_dma0_m2m_chan1_burst16
Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=1, BURST_LEN=2
Starting the transfer
DMA transfer done
It is harder to be kind than to be wise........
 PASS - test_tst_dma0_m2m_chan1_burst16 in 2.014 seconds
===================================================================
START - test_tst_dma0_m2m_chan1_burst8
Preparing DMA Controller: Name=dma-controller@400e8000, Chan_ID=1, BURST_LEN=1
Starting the transfer
DMA transfer done
It is harder to be kind than to be wise........
 PASS - test_tst_dma0_m2m_chan1_burst8 in 2.014 seconds
===================================================================
TESTSUITE dma_m2m succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [dma_m2m]: pass = 4, fail = 0, skip = 0, total = 4 duration = 8.057 seconds
 - PASS - [dma_m2m.test_tst_dma0_m2m_chan0_burst16] duration = 2.015 seconds
 - PASS - [dma_m2m.test_tst_dma0_m2m_chan0_burst8] duration = 2.014 seconds
 - PASS - [dma_m2m.test_tst_dma0_m2m_chan1_burst16] duration = 2.014 seconds
 - PASS - [dma_m2m.test_tst_dma0_m2m_chan1_burst8] duration = 2.014 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL


This commit moves the test buffer from ITCM (not accessible by DMA) to DTCM
on several NXP boards, to make the test successful.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
@mathieuchopstm mathieuchopstm dismissed stale reviews from teburd and erwango via a7ab4a4 August 21, 2024 12:09
@mathieuchopstm
Copy link
Contributor Author

Hi @hakehuang,
sorry for the late reply and thanks for the investigation.

I have added a commit that updates all affected boards and should fix the issue. Could you run a test again with updated PR contents to confirm everything is good?
Will remove DNM once I receive your ACK.

Copy link
Contributor

@hakehuang hakehuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mathieuchopstm mathieuchopstm removed the DNM This PR should not be merged (Do Not Merge) label Aug 22, 2024
@erwango erwango self-requested a review August 22, 2024 14:53
@nashif nashif merged commit eaa799a into zephyrproject-rtos:main Aug 22, 2024
@mathieuchopstm mathieuchopstm deleted the dma_chan_blen_transfer_fix_v2 branch October 15, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: DMA Direct Memory Access backport v3.7-branch Request backport to the v3.7-branch priority: low Low impact/importance bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: dma: chan_blen_transfer: test breakage on Nucleo-H743ZI

6 participants