Skip to content

Add SPI basic test and test header file. #7976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
561 changes: 561 additions & 0 deletions TESTS/mbed_hal/spi/main.cpp

Large diffs are not rendered by default.

145 changes: 145 additions & 0 deletions TESTS/mbed_hal/spi/spi_api_tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** \addtogroup hal_spi_tests */
/** @{*/

#ifndef MBED_SPI_API_TESTS_H
#define MBED_SPI_API_TESTS_H

#include "device.h"

#if DEVICE_SPI

#ifdef __cplusplus
extern "C" {
#endif

/** Test that spi_get_module() returns the SPIName - unique identifier to the peripheral associated
* to this SPI channel.
*
* Given is platform with SPI support.
* When spi_get_module() is called with valid SPI pins.
* Then function returns the SPIName - unique identifier to the peripheral associated
* to this SPI channel.
*
* @note `mosi` or `miso` pin can be undefined (but not both). `mclk` must be defined.
*/
void test_get_module();

/** Test that spi_get_capabilities() fills the given spi_capabilities_t instance with capabilities
* of the specified SPI peripheral.
*
* Given is platform with SPI support.
* When spi_get_capabilities() is called with the valid SPI name (and SS pin).
* Then function fills the given spi_capabilities_t instance with capabilities
* of the specified SPI peripheral.
*
* @note spi_get_capabilities() considers the `ssel` pin when evaluation the
* support_slave_mode capability.
*
*/
void test_get_capabilities();

/** Test that spi_init() successfully initializes the pins and spi_free() can successfully
* reset the pins to their default state.
*
* Given is platform with SPI support.
* When spi_init() is called with the valid pins configuration and then spi_free() is called on
* the created SPI object.
* Then both operations are successfully performed.
*
*/
void test_init_free();

/** Test that spi_format() sets/updates the transmission format of the SPI peripheral.
*
* Given is platform with SPI support.
* When spi_format() is called and valid format is specified.
* Then function is executed successfully.
*
*/
void test_set_format();

/** Test that test_set_frequency() sets the frequency used during the SPI transfer.
*
* Given is platform with SPI support.
* When test_set_frequency() is called and valid frequency is specified.
* Then function is executed successfully and actual frequency which will be used during the transfer is returned.
*
* @note Frequency can be only set by SPI peripheral operating in master mode.
* @note Frequency must be in range specified by the capabilities of the SPI peripheral.
*
*/
void test_set_frequency();

/** Test that spi_transfer() can successfully perform transfer in master mode
* (TX/RX buffers are defined and have the same sizes) and returns the number of
* symbols clocked on the bus during this transfer.
*
* Given is platform with SPI support.
* When spi_transfer() is called for SPI peripheral operating in master mode and
* both TX/RX buffers are specified and have equal sizes.
* Then function is executed successfully and returns number of symbols clocked on the bus during this transfer.
*
*/
void test_transfer_master();

/** Test that spi_transfer() can successfully perform transfer in master mode
* (TX/RX buffers are undefined or have different sizes) and returns the number of
* symbols clocked on the bus during this transfer.
*
* Given is platform with SPI support.
* When spi_transfer() is called for SPI peripheral operating in master mode and
* TX/RX buffers are undefined or have different sizes.
* Then function is executed successfully and returns number of symbols clocked on the bus during this transfer.
*
*/
void test_transfer_master_fill_sym();

/** Test that spi_transfer_async() can successfully perform asynchronous transfer
* in master mode.
*
* Given is platform with SPI support.
* When spi_transfer_async() is called for SPI peripheral operating in master mode.
* Then function returns true on success, performs transfer and invokes specified callback
* when the transfer completes (passing the operation status).
*
*/
void test_transfer_master_async();

/** Test that spi_transfer_async_abort() can successfully abort an on-going async transfer.
*
* Given is platform with SPI support.
* When spi_transfer_async() is called for SPI peripheral operating in master mode and
* operation is aborted immediately by means of spi_transfer_async_abort().
* Then operation is successfully performed and specified callback is invoked with
* the status which indicates that the transfer has been aborted.
*
*/
void test_transfer_master_async_abort();

/**@}*/

#ifdef __cplusplus
}
#endif

#endif

#endif

/**@}*/
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,19 @@ typedef enum {
DAC_0 = 0
} DACName;


#define SPI_COUNT 3
typedef enum {
SPI_0 = 0,
SPI_1 = 1,
SPI_2 = 2,
} SPIName;

/* Specify master/slave interfaces for testing purposes. */
#define SPI_TEST_MASTER SPI_2
#define SPI_TEST_SLAVE SPI_0
#define SPI_TEST_MASTER_PIN(SPI_PIN) SPI_2##_##SPI_PIN
#define SPI_TEST_SLAVE_PIN(SPI_PIN) SPI_0##_##SPI_PIN
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see the reason you want to adding these macros. I am OK with this.
Russ is working on Pinmaps, @c1728p9 do you have better suggestions?


#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,26 @@ typedef enum {

I2C_SCL = D15,
I2C_SDA = D14,

/* Note:
This board does not provide SPI MOSI/MISO pins, instead we have SIN/SOUT pins which can be used
as SPI MOSI/MISO lines depending on SPI operation mode(master or slave):
master: SIN ---> MISO
SOUT ---> MOSI
slave: SIN ---> MOSI
SOUT ---> MISO

SPI_0 interface represents SPI pins configuration for slave and SPI_2 respresents spi configuration
for master.
*/
SPI_0_MOSI = PTD3,
SPI_0_MISO = PTD2,
SPI_0_SCK = PTD1,
SPI_0_CS = PTD0,
SPI_2_MOSI = PTD13,
SPI_2_MISO = PTB23,
SPI_2_SCK = PTD12,
SPI_2_CS = PTB20,

A0 = PTB7,
A1 = PTB6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ typedef enum {
SPI_5 = (int)SPI5_BASE,
SPI_6 = (int)SPI6_BASE
} SPIName;
/* Specify master/slave SPI interfaces for testing purposes. */
#define SPI_TEST_MASTER SPI_1
#define SPI_TEST_SLAVE SPI_4
#define SPI_TEST_MASTER_PIN(SPI_PIN) SPI_1##_##SPI_PIN
#define SPI_TEST_SLAVE_PIN(SPI_PIN) SPI_4##_##SPI_PIN

typedef enum {
I2C_1 = (int)I2C1_BASE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,17 @@ typedef enum {
USBRX = STDIO_UART_RX, // Virtual Com Port
I2C_SCL = D15,
I2C_SDA = D14,
SPI_MOSI = D11,
SPI_MISO = D12,
SPI_SCK = D13,
SPI_CS = D10,
PWM_OUT = D9,

SPI_1_MOSI = PB_5,
SPI_1_MISO = PA_6,
SPI_1_SCK = PA_5,
SPI_1_CS = PA_4,
SPI_4_MOSI = PE_6,
SPI_4_MISO = PE_5,
SPI_4_SCK = PE_2,
SPI_4_CS = PE_4,

/**** USB pins ****/
USB_OTG_FS_DM = PA_11,
USB_OTG_FS_DP = PA_12,
Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_STM/stm_spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ uint32_t spi_transfer(spi_t *obj, const void *tx_buffer, uint32_t tx_length,
out = *(uint8_t *)write_fill;
}
in = spi_write(obj, out);
if (i < rx_length) {
if (rx_buffer && i < rx_length) {
((uint8_t*)rx_buffer)[i] = (uint8_t)in;
}
break;
Expand All @@ -536,7 +536,7 @@ uint32_t spi_transfer(spi_t *obj, const void *tx_buffer, uint32_t tx_length,
out = *(uint16_t *)write_fill;
}
in = spi_write(obj, out);
if (i < rx_length) {
if (rx_buffer && i < rx_length) {
((uint16_t*)rx_buffer)[i] = (uint16_t)in;
}
break;
Expand Down
3 changes: 3 additions & 0 deletions targets/TARGET_TT/TARGET_TT_M3HQ/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#if DEVICE_SPI

#include "spi_api.h"
#include "mbed_error.h"
#include "pinmap.h"
Expand Down Expand Up @@ -274,3 +276,4 @@ uint8_t spi_get_module(spi_t *obj)
{
return (uint8_t)(obj->module);
}
#endif
9 changes: 0 additions & 9 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1299,8 +1299,6 @@
"PWMOUT",
"SERIAL",
"SLEEP",
"SPI",
"SPISLAVE",
"TRNG",
"STDIO_MESSAGES",
"FLASH",
Expand Down Expand Up @@ -7738,8 +7736,6 @@
"CAN",
"I2CSLAVE",
"ANALOGOUT",
"SPI",
"SPISLAVE",
"SERIAL_ASYNCH",
"SERIAL_FC",
"EMAC",
Expand Down Expand Up @@ -7772,7 +7768,6 @@
"PWMOUT",
"SERIAL",
"SLEEP",
"SPI",
"I2C",
"I2CSLAVE",
"STDIO_MESSAGES",
Expand All @@ -7793,8 +7788,6 @@
"CAN",
"I2CSLAVE",
"ANALOGOUT",
"SPI",
"SPISLAVE",
"SERIAL_ASYNCH",
"SERIAL_FC",
"EMAC",
Expand Down Expand Up @@ -7822,8 +7815,6 @@
"CAN",
"I2CSLAVE",
"ANALOGOUT",
"SPI",
"SPISLAVE",
"SERIAL_ASYNCH",
"SERIAL_FC",
"FLASH",
Expand Down
28 changes: 0 additions & 28 deletions tools/test/examples/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,6 @@
"export": true,
"auto-update" : true
},
{
"name": "mbed-os-example-bootloader",
"github":"https://github.com/ARMmbed/mbed-os-example-bootloader",
"mbed": [
"https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-bootloader"
],
"test-repo-source": "github",
"features" : [],
"targets" : ["NUCLEO_F429ZI"],
"toolchains" : [],
"exporters": [],
"compile" : true,
"export": true,
"auto-update" : true
},
{
"name": "mbed-os-example-mbed-crypto",
"github":"https://github.com/ARMmbed/mbed-os-example-mbed-crypto",
Expand Down Expand Up @@ -352,19 +337,6 @@
"compile" : true,
"export": true,
"auto-update" : true
},
{
"name": "mbed-os-example-sd-driver",
"github":"https://github.com/ARMmbed/mbed-os-example-sd-driver",
"mbed": [],
"test-repo-source": "github",
"features" : [],
"targets" : ["K64F"],
"toolchains" : [],
"exporters": [],
"compile" : true,
"export": true,
"auto-update" : true
}
]
}