Skip to content

Commit e2f52a3

Browse files
committed
[components][spi] add utest cases
1 parent d875db8 commit e2f52a3

6 files changed

Lines changed: 954 additions & 0 deletions

File tree

components/drivers/spi/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from building import *
22
from gcc import *
3+
import os
34
import rtconfig
45

56
cwd = GetCurrentDir()
@@ -46,4 +47,9 @@ src += src_device
4647

4748
group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_SPI'], CPPPATH = CPPPATH, LOCAL_CFLAGS = LOCAL_CFLAGS)
4849

50+
list = os.listdir(cwd)
51+
for item in list:
52+
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
53+
group = group + SConscript(os.path.join(item, 'SConscript'))
54+
4955
Return('group')
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
menu "SPI Test"
2+
3+
config RT_UTEST_SPI_LOOPBACK
4+
bool "SPI MOSI/MISO Loopback Test"
5+
select RT_USING_SPI
6+
default n
7+
help
8+
This test validates full-duplex loopback data with sendrecv8,
9+
transfer and transfer_message over length and clock matrices.
10+
The hardware transfer mode, such as polling, interrupt or DMA, is
11+
selected by the BSP SPI driver configuration.
12+
13+
if RT_UTEST_SPI_LOOPBACK
14+
15+
config RT_UTEST_SPI_LOOPBACK_BUS_NAME
16+
string "SPI bus name for loopback test"
17+
default "spi2"
18+
19+
config RT_UTEST_SPI_LOOPBACK_DEV_NAME
20+
string "Temporary SPI device name for loopback test"
21+
default "spi_loop"
22+
23+
config RT_UTEST_SPI_LOOPBACK_DATA_SIZE
24+
int "SPI loopback maximum test data size"
25+
range 1 65535
26+
default 512
27+
28+
config RT_UTEST_SPI_LOOPBACK_MAX_HZ
29+
int "SPI loopback maximum clock frequency (Hz)"
30+
range 1 100000000
31+
default 10000000
32+
help
33+
The test automatically builds the clock matrix from standard SPI
34+
frequencies up to this value, and always includes this maximum value.
35+
36+
config RT_UTEST_SPI_LOOPBACK_API_SMOKE
37+
bool "Enable SPI TX-only/RX-only API smoke test"
38+
default n
39+
help
40+
Enable this to smoke-test TX-only and RX-only transfer APIs by return
41+
length. These transfers do not validate MOSI/MISO loopback data and
42+
may be unsupported or unstable on some BSP SPI controllers.
43+
44+
config RT_UTEST_SPI_LOOPBACK_TIMEOUT
45+
int "SPI loopback test timeout (s)"
46+
range 1 3600
47+
default 60
48+
49+
endif
50+
51+
config RT_UTEST_SPI_FLASH
52+
bool "SPI Flash SFUD Read/Write Test"
53+
select RT_USING_SPI
54+
select RT_USING_SFUD
55+
select RT_SFUD_USING_SFDP
56+
select RT_SFUD_USING_FLASH_INFO_TABLE
57+
select RT_USING_HEAP
58+
default n
59+
60+
if RT_UTEST_SPI_FLASH
61+
62+
config RT_UTEST_SPI_FLASH_SPI_DEV_NAME
63+
string "SPI device name for SFUD flash"
64+
default "spi20"
65+
help
66+
The SPI device that connects to the flash, such as spi20. If it does
67+
not exist yet, the test attaches it to the configured SPI bus and CS pin.
68+
69+
config RT_UTEST_SPI_FLASH_BUS_NAME
70+
string "SPI bus name for flash device attach"
71+
default "spi2"
72+
help
73+
The SPI bus used when the test needs to attach the SPI flash device.
74+
75+
config RT_UTEST_SPI_FLASH_CS_PIN
76+
int "SPI flash CS pin index"
77+
range -1 32767
78+
default -1
79+
help
80+
Use the RT-Thread pin index used by the BSP, such as a GET_PIN() value
81+
on STM32. -1 means PIN_NONE.
82+
83+
config RT_UTEST_SPI_FLASH_DEV_NAME
84+
string "SFUD flash model/device name"
85+
default "W25Q64"
86+
help
87+
This is the SFUD flash device name used to find or register the flash,
88+
and is usually set to the board flash model name, such as W25Q64 or
89+
W25Q128. SFUD still verifies the actual chip by JEDEC ID and SFDP or
90+
its flash information table when probing.
91+
92+
config RT_UTEST_SPI_FLASH_TEST_OFFSET
93+
hex "SPI flash test offset"
94+
default 0x0
95+
96+
config RT_UTEST_SPI_FLASH_TEST_SIZE
97+
int "SPI flash test data size"
98+
range 1 4096
99+
default 256
100+
101+
endif
102+
103+
endmenu
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Import('rtconfig')
2+
from building import *
3+
4+
cwd = GetCurrentDir()
5+
src = []
6+
CPPPATH = [cwd, cwd + '/..', cwd + '/../sfud/inc']
7+
8+
if GetDepend(['RT_UTEST_SPI_LOOPBACK']):
9+
src += ['spi_loopback_tc.c']
10+
11+
if GetDepend(['RT_UTEST_SPI_FLASH']):
12+
src += ['spi_flash_tc.c']
13+
14+
group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES', 'RT_USING_SPI'], CPPPATH = CPPPATH)
15+
16+
Return('group')

0 commit comments

Comments
 (0)