Skip to content

Commit 9030e5c

Browse files
mprse0xc0170
authored andcommitted
Add Ice Tea SPI communication test.
1 parent c81f1e5 commit 9030e5c

File tree

11 files changed

+1960
-0
lines changed

11 files changed

+1960
-0
lines changed

TEST_APPS/device/spi_com/main.cpp

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* Copyright (c) 2018 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include <stdio.h>
17+
#include <stdarg.h>
18+
#include "mbed.h"
19+
#include "mbed-client-cli/ns_cmdline.h"
20+
#include "mbed_config.h"
21+
#include "spi_test_common.h"
22+
#include "spi_master.h"
23+
#include "spi_slave.h"
24+
/**
25+
* Macros for setting console flow control.
26+
*/
27+
#define CONSOLE_FLOWCONTROL_RTS 1
28+
#define CONSOLE_FLOWCONTROL_CTS 2
29+
#define CONSOLE_FLOWCONTROL_RTSCTS 3
30+
#define mbed_console_concat_(x) CONSOLE_FLOWCONTROL_##x
31+
#define mbed_console_concat(x) mbed_console_concat_(x)
32+
#define CONSOLE_FLOWCONTROL mbed_console_concat(MBED_CONF_TARGET_CONSOLE_UART_FLOW_CONTROL)
33+
34+
#define SERIAL_CONSOLE_BAUD_RATE 115200
35+
36+
static config_test_case_t tc_config;
37+
static spi_t spi_master = { 0 };
38+
static spi_t spi_slave = { 0 };
39+
static DigitalOut *ss = NULL;
40+
static target_t spi_target;
41+
42+
void cmd_ready_cb(int retcode)
43+
{
44+
cmd_next(retcode);
45+
}
46+
47+
void wrap_printf(const char *f, va_list a)
48+
{
49+
vprintf(f, a);
50+
}
51+
52+
int validate_config_callback(int argc, char *argv[])
53+
{
54+
int32_t duplex_buf;
55+
int32_t mode_buf;
56+
int32_t sync;
57+
int32_t buffers;
58+
int32_t target;
59+
int result;
60+
61+
sym_count = DEFAULT_TEST_SYM_CNT;
62+
63+
cmd_parameter_int(argc, argv, "target", &target);
64+
cmd_parameter_int(argc, argv, "symbol_size", (int32_t *) &tc_config.symbol_size);
65+
cmd_parameter_int(argc, argv, "mode", &mode_buf);
66+
cmd_parameter_int(argc, argv, "bit_ordering", (int32_t *) &tc_config.bit_ordering);
67+
cmd_parameter_int(argc, argv, "freq_hz", (int32_t *) &tc_config.freq_hz);
68+
cmd_parameter_int(argc, argv, "buffers", &buffers);
69+
cmd_parameter_bool(argc, argv, "master_tx_defined", &tc_config.master_tx_defined);
70+
cmd_parameter_bool(argc, argv, "master_rx_defined", &tc_config.master_rx_defined);
71+
cmd_parameter_bool(argc, argv, "slave_tx_defined", &tc_config.slave_tx_defined);
72+
cmd_parameter_bool(argc, argv, "slave_rx_defined", &tc_config.slave_rx_defined);
73+
cmd_parameter_bool(argc, argv, "auto_ss", &tc_config.auto_ss);
74+
cmd_parameter_int(argc, argv, "duplex", &duplex_buf);
75+
cmd_parameter_int(argc, argv, "sync", &sync);
76+
tc_config.duplex = (duplex_t) duplex_buf;
77+
tc_config.mode = (_spi_mode_t) mode_buf;
78+
tc_config.master_sync = (bool)(sync & MASTER_SYNC_BIT_MASK);
79+
tc_config.slave_sync = (bool)(sync & SLAVE_SYNC_BIT_MASK);
80+
tc_config.master_tx_cnt = (buffers == SPI_BUFFERS_MASTER_TX_LT_RX ? SHORTER_TEST_SYM_CNT : DEFAULT_TEST_SYM_CNT);
81+
tc_config.master_rx_cnt = (buffers == SPI_BUFFERS_MASTER_TX_GT_RX ? SHORTER_TEST_SYM_CNT : DEFAULT_TEST_SYM_CNT);
82+
tc_config.slave_tx_cnt = (buffers == SPI_BUFFERS_SLAVE_TX_LT_RX ? SHORTER_TEST_SYM_CNT : DEFAULT_TEST_SYM_CNT);
83+
tc_config.slave_rx_cnt = (buffers == SPI_BUFFERS_SLAVE_TX_GT_RX ? SHORTER_TEST_SYM_CNT : DEFAULT_TEST_SYM_CNT);
84+
85+
spi_target = (target_t)target;
86+
87+
if (buffers == SPI_BUFFERS_SHORTEST) {
88+
sym_count = SHORTEST_TEST_SYM_CNT;
89+
tc_config.master_tx_cnt = SHORTEST_TEST_SYM_CNT;
90+
tc_config.master_rx_cnt = SHORTEST_TEST_SYM_CNT;
91+
tc_config.slave_tx_cnt = SHORTEST_TEST_SYM_CNT;
92+
tc_config.slave_rx_cnt = SHORTEST_TEST_SYM_CNT;
93+
}
94+
95+
if (buffers == SPI_BUFFERS_LONG) {
96+
sym_count = LONG_TEST_SYM_CNT;
97+
tc_config.master_tx_cnt = LONG_TEST_SYM_CNT;
98+
tc_config.master_rx_cnt = LONG_TEST_SYM_CNT;
99+
tc_config.slave_tx_cnt = LONG_TEST_SYM_CNT;
100+
tc_config.slave_rx_cnt = LONG_TEST_SYM_CNT;
101+
}
102+
103+
if (spi_target == MASTER) {
104+
result = check_capabilities(tc_config.symbol_size, false, tc_config.duplex, tc_config.master_sync);
105+
} else {
106+
result = check_capabilities(tc_config.symbol_size, true, tc_config.duplex, tc_config.slave_sync);
107+
}
108+
109+
return result;
110+
}
111+
112+
int init_test_callback(int argc, char *argv[])
113+
{
114+
int result;
115+
116+
if (spi_target == MASTER) {
117+
result = test_init_master(&spi_master, &tc_config, &ss);
118+
} else {
119+
result = test_init_slave(&spi_slave, &tc_config);
120+
}
121+
122+
return result;
123+
}
124+
125+
int exec_test_callback(int argc, char *argv[])
126+
{
127+
int result;
128+
129+
if (spi_target == MASTER) {
130+
result = test_transfer_master(&spi_master, &tc_config, ss);
131+
} else {
132+
result = test_transfer_slave(&spi_slave, &tc_config);
133+
}
134+
135+
return result;
136+
}
137+
138+
int finish_test_callback(int argc, char *argv[])
139+
{
140+
int result;
141+
142+
if (spi_target == MASTER) {
143+
result = test_finish_master(&spi_master, &tc_config);
144+
} else {
145+
result = test_finish_slave(&spi_slave, &tc_config);
146+
}
147+
148+
return result;
149+
}
150+
151+
int main()
152+
{
153+
cmd_init(&wrap_printf);
154+
cmd_add("validate_config", validate_config_callback, "Validate if given SPI configuration can be handled by this device.", 0);
155+
cmd_add("init_test", init_test_callback, "Initialise the SPI interface.", 0);
156+
cmd_add("exec_test", exec_test_callback, "Execute SPI communication test.", 0);
157+
cmd_add("finish_test", finish_test_callback, "Deinitialise the SPI interface.", 0);
158+
159+
int c;
160+
while ((c = getchar()) != EOF) {
161+
cmd_char_input(c);
162+
}
163+
return 0;
164+
}
165+
166+
FileHandle *mbed::mbed_override_console(int)
167+
{
168+
static UARTSerial console(STDIO_UART_TX, STDIO_UART_RX, SERIAL_CONSOLE_BAUD_RATE);
169+
#if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS
170+
console.set_flow_control(SerialBase::RTS, STDIO_UART_RTS, NC);
171+
#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS
172+
console.set_flow_control(SerialBase::CTS, NC, STDIO_UART_CTS);
173+
#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS
174+
console.set_flow_control(SerialBase::RTSCTS, STDIO_UART_RTS, STDIO_UART_CTS);
175+
#endif
176+
return &console;
177+
}
178+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"config": {
3+
"SPI_MASTER_SS": "D10",
4+
"SPI_MASTER_MOSI": "D11",
5+
"SPI_MASTER_MISO": "D12",
6+
"SPI_MASTER_CLK": "D13",
7+
"SPI_MASTER_HALF_DUPLEX_DATA": "D11",
8+
"SPI_MASTER_SS_ACTIVE_HIGH": "true",
9+
"SPI_MASTER_DELAY": "1000",
10+
"SPI_SLAVE_SS": "D10",
11+
"SPI_SLAVE_MOSI": "D11",
12+
"SPI_SLAVE_MISO": "D12",
13+
"SPI_SLAVE_CLK": "D13",
14+
"SPI_SLAVE_HALF_DUPLEX_DATA": "D11",
15+
"SPI_SLAVE_DELAY": "100",
16+
"SPI_DEBUG": "0"
17+
},
18+
"target_overrides": {
19+
"K66F": {
20+
"SPI_MASTER_SS": "PTD0",
21+
"SPI_MASTER_MOSI": "PTD2",
22+
"SPI_MASTER_MISO": "PTD3",
23+
"SPI_MASTER_CLK": "PTD1",
24+
"SPI_MASTER_HALF_DUPLEX_DATA": "D11",
25+
"SPI_MASTER_SS_ACTIVE_HIGH": "false",
26+
"SPI_MASTER_DELAY": "100",
27+
"SPI_SLAVE_SS": "PTD0",
28+
"SPI_SLAVE_MOSI": "PTD3",
29+
"SPI_SLAVE_MISO": "PTD2",
30+
"SPI_SLAVE_CLK": "PTD1",
31+
"SPI_SLAVE_HALF_DUPLEX_DATA": "D11",
32+
"SPI_SLAVE_DELAY": "1"
33+
},
34+
"NUCLEO_F429ZI": {
35+
"SPI_MASTER_SS": "PA_4",
36+
"SPI_MASTER_MOSI": "PB_5",
37+
"SPI_MASTER_MISO": "PB_4",
38+
"SPI_MASTER_CLK": "PB_3",
39+
"SPI_MASTER_HALF_DUPLEX_DATA": "PB_5",
40+
"SPI_MASTER_SS_ACTIVE_HIGH": "false",
41+
"SPI_MASTER_DELAY": "10",
42+
"SPI_SLAVE_SS": "PA_4",
43+
"SPI_SLAVE_MOSI": "PB_5",
44+
"SPI_SLAVE_MISO": "PB_4",
45+
"SPI_SLAVE_CLK": "PB_3",
46+
"SPI_SLAVE_HALF_DUPLEX_DATA": "PB_4",
47+
"SPI_SLAVE_DELAY": "1",
48+
"SPI_DEBUG": "0"
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)