Skip to content

Commit 445c893

Browse files
FRASTMcarlescufi
authored andcommitted
tests: drivers: dma adapt the dma tests applications for stm32 devices
It adds flexibility to test different dma channels The chan_blen_transfer is modified like the loop_transfer application to support stm32xx devices with dma and/or dmamux. On the stm32 devices, the first dma channel is 1. Signed-off-by: Francois Ramu <[email protected]>
1 parent a188560 commit 445c893

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2020 STMicroelectronics
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "DMA Loop Transfer Test"
5+
6+
source "Kconfig.zephyr"
7+
8+
config DMA_TRANSFER_DRV_NAME
9+
string "DMA device name to use for test"
10+
default "DMA_0"
11+
12+
config DMA_TRANSFER_CHANNEL_NR_0
13+
int "first DMA channel to use"
14+
default 0
15+
16+
config DMA_TRANSFER_CHANNEL_NR_1
17+
int "second DMA channel to use"
18+
default 1

tests/drivers/dma/chan_blen_transfer/src/test_dma.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#include <drivers/dma.h>
2121
#include <ztest.h>
2222

23-
#define DMA_DEVICE_NAME CONFIG_DMA_0_NAME
23+
#define DMA_DEVICE_NAME CONFIG_DMA_TRANSFER_DRV_NAME
24+
2425
#define RX_BUFF_SIZE (48)
2526

2627
#ifdef CONFIG_NOCACHE_MEMORY
@@ -49,7 +50,6 @@ static int test_task(uint32_t chan_id, uint32_t blen)
4950
struct dma_config dma_cfg = { 0 };
5051
struct dma_block_config dma_block_cfg = { 0 };
5152
const struct device *dma = device_get_binding(DMA_DEVICE_NAME);
52-
5353
if (!dma) {
5454
TC_PRINT("Cannot get dma controller\n");
5555
return TC_FAIL;
@@ -101,20 +101,20 @@ static int test_task(uint32_t chan_id, uint32_t blen)
101101
/* export test cases */
102102
void test_dma_m2m_chan0_burst8(void)
103103
{
104-
zassert_true((test_task(0, 8) == TC_PASS), NULL);
104+
zassert_true((test_task(CONFIG_DMA_TRANSFER_CHANNEL_NR_0, 8) == TC_PASS), NULL);
105105
}
106106

107107
void test_dma_m2m_chan1_burst8(void)
108108
{
109-
zassert_true((test_task(1, 8) == TC_PASS), NULL);
109+
zassert_true((test_task(CONFIG_DMA_TRANSFER_CHANNEL_NR_1, 8) == TC_PASS), NULL);
110110
}
111111

112112
void test_dma_m2m_chan0_burst16(void)
113113
{
114-
zassert_true((test_task(0, 16) == TC_PASS), NULL);
114+
zassert_true((test_task(CONFIG_DMA_TRANSFER_CHANNEL_NR_0, 16) == TC_PASS), NULL);
115115
}
116116

117117
void test_dma_m2m_chan1_burst16(void)
118118
{
119-
zassert_true((test_task(1, 16) == TC_PASS), NULL);
119+
zassert_true((test_task(CONFIG_DMA_TRANSFER_CHANNEL_NR_1, 16) == TC_PASS), NULL);
120120
}

tests/drivers/dma/loop_transfer/src/dma.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ static void test_transfer(const struct device *dev, uint32_t id)
4646
dma_block_cfg.block_size = strlen(tx_data);
4747
dma_block_cfg.source_address = (uint32_t)tx_data;
4848
dma_block_cfg.dest_address = (uint32_t)rx_data[transfer_count];
49-
5049
ret = dma_config(dev, id, &dma_cfg);
5150
if (ret == 0) {
5251
dma_start(dev, id);
@@ -63,7 +62,14 @@ static void dma_user_callback(const struct device *dma_dev, void *arg,
6362
uint32_t id, int error_code)
6463
{
6564
if (error_code == 0) {
65+
#ifdef CONFIG_DMAMUX_STM32
66+
/* the channel is the DMAMUX's one
67+
* the device is the DMAMUX, given through
68+
* the stream->user_data by the dma_stm32_irq_handler */
69+
test_transfer((struct device *)arg, id);
70+
#else
6671
test_transfer(dma_dev, id);
72+
#endif /* CONFIG_DMAMUX_STM32 */
6773
} else {
6874
test_error();
6975
}
@@ -96,30 +102,34 @@ void main(void)
96102
dma_cfg.dest_data_size = 1U;
97103
dma_cfg.source_burst_length = 1U;
98104
dma_cfg.dest_burst_length = 1U;
105+
#ifdef CONFIG_DMAMUX_STM32
106+
dma_cfg.user_data = (struct device *)dma;
107+
#else
99108
dma_cfg.user_data = NULL;
109+
#endif /* CONFIG_DMAMUX_STM32 */
100110
dma_cfg.dma_callback = dma_user_callback;
101111
dma_cfg.block_count = 1U;
102112
dma_cfg.head_block = &dma_block_cfg;
113+
103114
#ifdef CONFIG_DMA_MCUX_TEST_SLOT_START
104115
dma_cfg.dma_slot = CONFIG_DMA_MCUX_TEST_SLOT_START;
105116
#endif
106-
107117
chan_id = CONFIG_DMA_LOOP_TRANSFER_CHANNEL_NR;
108118
transfer_count = 0;
109-
printk("Starting the transfer and waiting for 1 second\n");
119+
printk("Starting the transfer on channel %d and waiting for 1 second\n", chan_id);
110120
printk("TX data: %s\n", tx_data);
111121
printk("block_size %d\n", strlen(tx_data));
112122
dma_block_cfg.block_size = strlen(tx_data);
113123
dma_block_cfg.source_address = (uint32_t)tx_data;
114124
dma_block_cfg.dest_address = (uint32_t)rx_data[transfer_count];
115125

116126
if (dma_config(dma, chan_id, &dma_cfg)) {
117-
printk("ERROR: transfer config\n");
127+
printk("ERROR: transfer config (%d)\n", chan_id);
118128
return;
119129
}
120130

121131
if (dma_start(dma, chan_id)) {
122-
printk("ERROR: transfer start\n");
132+
printk("ERROR: transfer start (%d)\n", chan_id);
123133
return;
124134
}
125135

0 commit comments

Comments
 (0)