Added mbed_app.json support for definitions of SPI pin names for SDCard support, the default configuration being for the CI test shield plugged into the Arduino header.

pull/7774/head
Simon Hughes 2017-02-17 17:53:12 +00:00
parent 9e5cca3be0
commit b939ebca60
4 changed files with 315 additions and 163 deletions

118
config/mbed_app.json Normal file
View File

@ -0,0 +1,118 @@
{
"config": {
"UART_RX": "D0",
"UART_TX": "D1",
"DIO_0": "D0",
"DIO_1": "D1",
"DIO_2": "D2",
"DIO_3": "D3",
"DIO_4": "D4",
"DIO_5": "D5",
"DIO_6": "D6",
"DIO_7": "D7",
"DIO_8": "D8",
"DIO_9": "D9",
"SPI_CS": "D10",
"SPI_MOSI": "D11",
"SPI_MISO": "D12",
"SPI_CLK": "D13",
"I2C_SDA": "D14",
"I2C_SCL": "D15",
"I2C_TEMP_ADDR":"0x90",
"I2C_EEPROM_ADDR":"0xA0",
"AIN_0": "A0",
"AIN_1": "A1",
"AIN_2": "A2",
"AIN_3": "A3",
"AIN_4": "A4",
"AIN_5": "A5",
"AOUT" : "A5",
"PWM_0": "D3",
"PWM_1": "D5",
"PWM_2": "D6",
"PWM_3": "D9",
"DEBUG_MSG": 0,
"DEVICE_SPI": 1,
"FSFAT_SDCARD_INSTALLED": 1
},
"target_overrides": {
"DISCO_F051R8": {
"SPI_MOSI": "SPI_MOSI",
"SPI_MISO": "SPI_MISO",
"SPI_CLK": "SPI_SCK",
"SPI_CS": "SPI_CS"
},
"K20D50M": {
"SPI_MOSI": "PTD2",
"SPI_MISO": "PTD3",
"SPI_CLK": "PTD1",
"SPI_CS": "PTC2"
},
"KL22F": {
"SPI_MOSI": "PTD6",
"SPI_MISO": "PTD7",
"SPI_CLK": "PTD5",
"SPI_CS": "PTD4"
},
"KL25Z": {
"SPI_MOSI": "PTD2",
"SPI_MISO": "PTD3",
"SPI_CLK": "PTD1",
"SPI_CS": "PTD0"
},
"KL43Z": {
"SPI_MOSI": "PTD6",
"SPI_MISO": "PTD7",
"SPI_CLK": "PTD5",
"SPI_CS": "PTD4"
},
"KL46Z": {
"SPI_MOSI": "PTD6",
"SPI_MISO": "PTD7",
"SPI_CLK": "PTD5",
"SPI_CS": "PTD4"
},
"K64F": {
"SPI_MOSI": "PTE3",
"SPI_MISO": "PTE1",
"SPI_CLK": "PTE2",
"SPI_CS": "PTE4"
},
"K66F": {
"SPI_MOSI": "PTE3",
"SPI_MISO": "PTE1",
"SPI_CLK": "PTE2",
"SPI_CS": "PTE4"
},
"LPC11U37H_401": {
"SPI_MOSI": "SDMOSI",
"SPI_MISO": "SDMISO",
"SPI_CLK": "SDSCLK",
"SPI_CS": "SDSSEL"
},
"LPC2368": {
"SPI_MOSI": "p11",
"SPI_MISO": "p12",
"SPI_CLK": "p13",
"SPI_CS": "p14"
},
"NUCLEO_L031K6": {
"SPI_MOSI": "SPI_MOSI",
"SPI_MISO": "SPI_MISO",
"SPI_CLK": "SPI_SCK",
"SPI_CS": "SPI_CS"
},
"nRF51822": {
"SPI_MOSI": "p12",
"SPI_MISO": "p13",
"SPI_CLK": "p15",
"SPI_CS": "p14"
},
"RZ_A1H": {
"SPI_MOSI": "P8_5",
"SPI_MISO": "P8_6",
"SPI_CLK": "P8_3",
"SPI_CS": "P8_4"
}
}
}

View File

@ -46,6 +46,7 @@
*/
#include "mbed.h"
#include "mbed_config.h"
#include "FATFileSystem.h"
#include "SDBlockDevice.h"
#include "test_env.h"
@ -67,18 +68,21 @@ using namespace utest::v1;
/* DEVICE_SPI
* This symbol is defined in targets.json if the target has a SPI interface, which is required for SDCard support.
* FSFAT_SDCARD_INSTALLTED
* For testing purposes, an SDCard must be installed on the target for the test cases in this file to succeed.
* If the target has an SD card installed then uncomment the #define FSFAT_SDCARD_INSTALLED directive for the target.
*
* Notes
* The following 2 lines should be instated to perform the tests in this file:
* #define FSFAT_SDCARD_INSTALLED
* #define DEVICE_SPI
* MBED_CONF_APP_FSFAT_SDCARD_INSTALLED
* For testing purposes, an SDCard must be installed on the target for the test cases in this file to succeed.
* If the target has an SD card installed then the MBED_CONF_APP_FSFAT_SDCARD_INSTALLED will be generated
* from the mbed_app.json, which includes the line
* {
* "config": {
* "UART_RX": "D0",
* <<< lines removed >>>
* "DEVICE_SPI": 1,
* "MBED_CONF_APP_FSFAT_SDCARD_INSTALLED": 1
* },
* <<< lines removed >>>
*/
#define FSFAT_SDCARD_INSTALLED
#define DEVICE_SPI
#if defined(DEVICE_SPI) && defined(FSFAT_SDCARD_INSTALLED)
#if defined(DEVICE_SPI) && defined(MBED_CONF_APP_FSFAT_SDCARD_INSTALLED)
#define FSFAT_BASIC_TEST_00 fsfat_basic_test_00
#define FSFAT_BASIC_TEST_01 fsfat_basic_test_01
@ -94,77 +98,9 @@ const int FSFAT_BASIC_DATA_SIZE = 256;
static char fsfat_basic_msg_g[FSFAT_BASIC_MSG_BUF_SIZE];
#if defined(TARGET_KL25Z)
SDBlockDevice sd(PTD2, PTD3, PTD1, PTD0);
SDBlockDevice sd(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_CS);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
SDBlockDevice sd(PTD6, PTD7, PTD5, PTD4);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
SDBlockDevice sd(PTE3, PTE1, PTE2, PTE4);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_K22F)
SDBlockDevice sd(PTD6, PTD7, PTD5, PTD4);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_K20D50M)
SDBlockDevice sd(PTD2, PTD3, PTD1, PTC2);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_nRF51822)
SDBlockDevice sd(p12, p13, p15, p14);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_NUCLEO_F030R8) || \
defined(TARGET_NUCLEO_F070RB) || \
defined(TARGET_NUCLEO_F072RB) || \
defined(TARGET_NUCLEO_F091RC) || \
defined(TARGET_NUCLEO_F103RB) || \
defined(TARGET_NUCLEO_F302R8) || \
defined(TARGET_NUCLEO_F303RE) || \
defined(TARGET_NUCLEO_F334R8) || \
defined(TARGET_NUCLEO_F401RE) || \
defined(TARGET_NUCLEO_F410RB) || \
defined(TARGET_NUCLEO_F411RE) || \
defined(TARGET_NUCLEO_L053R8) || \
defined(TARGET_NUCLEO_L073RZ) || \
defined(TARGET_NUCLEO_L152RE)
SDBlockDevice sd(D11, D12, D13, D10);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_DISCO_F051R8) || \
defined(TARGET_NUCLEO_L031K6)
SDBlockDevice sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_LPC2368)
SDBlockDevice sd(p11, p12, p13, p14);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_LPC11U68)
SDBlockDevice sd(D11, D12, D13, D10);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_LPC1549)
SDBlockDevice sd(D11, D12, D13, D10);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_RZ_A1H)
SDBlockDevice sd(P8_5, P8_6, P8_3, P8_4);
FATFileSystem fs(sd_mount_pt, &sd);
#elif defined(TARGET_LPC11U37H_401)
SDBlockDevice sd(SDMOSI, SDMISO, SDSCLK, SDSSEL);
FATFileSystem fs(sd_mount_pt, &sd);
#else
#error "[NOT SUPPORTED] Instantiate SDBlockDevice sd(p11, p12, p13, p14) with the correct pin specification for target"
#endif
#define FSFAT_BASIC_MSG(_buf, _max_len, _fmt, ...) \
do \
{ \
@ -507,7 +443,7 @@ static control_t fsfat_basic_test_dummy()
return CaseNext;
}
#endif /* defined(DEVICE_SPI) && defined(FSFAT_SDCARD_INSTALLED) */
#endif /* defined(DEVICE_SPI) && defined(MBED_CONF_APP_FSFAT_SDCARD_INSTALLED) */
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{

View File

@ -22,6 +22,7 @@
*/
#include "mbed.h"
#include "mbed_config.h"
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
#include "fsfat_debug.h"
@ -44,6 +45,7 @@
#include <sys/stat.h>
#endif
using namespace utest::v1;
//using namespace mbed;
/// @cond FSFAT_DOXYGEN_DISABLE
#ifdef FSFAT_DEBUG
@ -56,18 +58,21 @@ using namespace utest::v1;
/* DEVICE_SPI
* This symbol is defined in targets.json if the target has a SPI interface, which is required for SDCard support.
* FSFAT_SDCARD_INSTALLTED
* For testing purposes, an SDCard must be installed on the target for the test cases in this file to succeed.
* If the target has an SD card installed then uncomment the #define FSFAT_SDCARD_INSTALLED directive for the target.
*
* Notes
* The following 2 lines should be instated to perform the tests in this file:
* #define FSFAT_SDCARD_INSTALLED
* #define DEVICE_SPI
* MBED_CONF_APP_FSFAT_SDCARD_INSTALLED
* For testing purposes, an SDCard must be installed on the target for the test cases in this file to succeed.
* If the target has an SD card installed then the MBED_CONF_APP_FSFAT_SDCARD_INSTALLED will be generated
* from the mbed_app.json, which includes the line
* {
* "config": {
* "UART_RX": "D0",
* <<< lines removed >>>
* "DEVICE_SPI": 1,
* "FSFAT_SDCARD_INSTALLED": 1
* },
* <<< lines removed >>>
*/
#define FSFAT_SDCARD_INSTALLED
#define DEVICE_SPI
#if defined(DEVICE_SPI) && defined(FSFAT_SDCARD_INSTALLED)
#if defined(DEVICE_SPI) && defined(MBED_CONF_APP_FSFAT_SDCARD_INSTALLED)
static char fsfat_fopen_utest_msg_g[FSFAT_UTEST_MSG_BUF_SIZE];
#define FSFAT_FOPEN_TEST_MOUNT_PT_NAME "sd"
@ -77,78 +82,9 @@ static char fsfat_fopen_utest_msg_g[FSFAT_UTEST_MSG_BUF_SIZE];
static const char *sd_badfile_path = "/sd/badfile.txt";
static const char *sd_testfile_path = "/sd/test.txt";
#if defined(TARGET_KL25Z)
SDBlockDevice sd(PTD2, PTD3, PTD1, PTD0);
SDBlockDevice sd(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_CS);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
SDBlockDevice sd(PTD6, PTD7, PTD5, PTD4);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
SDBlockDevice sd(PTE3, PTE1, PTE2, PTE4);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_K22F)
SDBlockDevice sd(PTD6, PTD7, PTD5, PTD4);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_K20D50M)
SDBlockDevice sd(PTD2, PTD3, PTD1, PTC2);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_nRF51822)
SDBlockDevice sd(p12, p13, p15, p14);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_NUCLEO_F030R8) || \
defined(TARGET_NUCLEO_F070RB) || \
defined(TARGET_NUCLEO_F072RB) || \
defined(TARGET_NUCLEO_F091RC) || \
defined(TARGET_NUCLEO_F103RB) || \
defined(TARGET_NUCLEO_F302R8) || \
defined(TARGET_NUCLEO_F303RE) || \
defined(TARGET_NUCLEO_F334R8) || \
defined(TARGET_NUCLEO_F401RE) || \
defined(TARGET_NUCLEO_F410RB) || \
defined(TARGET_NUCLEO_F411RE) || \
defined(TARGET_NUCLEO_L053R8) || \
defined(TARGET_NUCLEO_L073RZ) || \
defined(TARGET_NUCLEO_L152RE)
SDBlockDevice sd(D11, D12, D13, D10);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_DISCO_F051R8) || \
defined(TARGET_NUCLEO_L031K6)
SDBlockDevice sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_LPC2368)
SDBlockDevice sd(p11, p12, p13, p14);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_LPC11U68)
SDBlockDevice sd(D11, D12, D13, D10);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_LPC1549)
SDBlockDevice sd(D11, D12, D13, D10);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_RZ_A1H)
SDBlockDevice sd(P8_5, P8_6, P8_3, P8_4);
FATFileSystem fs("sd", &sd);
#elif defined(TARGET_LPC11U37H_401)
SDBlockDevice sd(SDMOSI, SDMISO, SDSCLK, SDSSEL);
FATFileSystem fs("sd", &sd);
#else
#error "[NOT SUPPORTED] Instantiate SDBlockDevice sd(p11, p12, p13, p14) with the correct pin specification for target"
#endif
#define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_01
#define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_02
#define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_03
@ -1548,7 +1484,7 @@ static control_t fsfat_fopen_test_dummy()
return CaseNext;
}
#endif /* defined(DEVICE_SPI) && defined(FSFAT_SDCARD_INSTALLED) */
#endif /* defined(DEVICE_SPI) && defined(MBED_CONF_APP_FSFAT_SDCARD_INSTALLED) */
/// @cond FSFAT_DOXYGEN_DISABLE

View File

@ -92,16 +92,178 @@ Switch to the `feature-storage` branch using the following commands:
<other branches deleted>
simhug01@E107851:/d/demo_area/ex_app1$
When the feature-storage branch has been merged to master, then the following the sd-driver repository should also be cloned:
simhug01@E107851:/d/demo_area/ex_app1$ mbed import https://github.com/ARMmbed/sd-driver
Copy the mbed_app.json file to the top level of the project:
simhug01@E107851:/d/demo_area/ex_app1$ cp sd-driver/config/mbed_app.json .
Build the test cases for the K64F target using the following commands:
simhug01@E107851:/d/demo_area/ex_app1$ mbed -v test --compile -t GCC_ARM -m K64F -DFSFAT_SDCARD_INSTALLED 2>&1 | tee build_tests_gcc_20161219_1007.txt
simhug01@E107851:/d/demo_area/ex_app1$ mbed -v test --compile -t GCC_ARM -m K64F --app-config mbed_app.json 2>&1 | tee build_tests_gcc_20161219_1007.txt
<trace removed>
simhug01@E107851:/d/demo_area/ex_app1$
The complete [build log][BUILD-TESTS-GCC-20161219-1007] is available for reference.
### <a name="insert-sdcard-into-k64f"></a> Insert SDCard into K64F
### <a name="insert-sdcard-into-k64f"></a> Testing with an SDCard on Target XYZ
The standard way to test is with the mbed CI Test Shield plugged into the target board. This pin mapping for this configuration is parameeterised in the mbed_app.json file.
The following is an example of the mbed_app.json file that was defined in the project at the time of writing:
{
"config": {
"UART_RX": "D0",
"UART_TX": "D1",
"DIO_0": "D0",
"DIO_1": "D1",
"DIO_2": "D2",
"DIO_3": "D3",
"DIO_4": "D4",
"DIO_5": "D5",
"DIO_6": "D6",
"DIO_7": "D7",
"DIO_8": "D8",
"DIO_9": "D9",
"SPI_CS": "D10",
"SPI_MOSI": "D11",
"SPI_MISO": "D12",
"SPI_CLK": "D13",
"I2C_SDA": "D14",
"I2C_SCL": "D15",
"I2C_TEMP_ADDR":"0x90",
"I2C_EEPROM_ADDR":"0xA0",
"AIN_0": "A0",
"AIN_1": "A1",
"AIN_2": "A2",
"AIN_3": "A3",
"AIN_4": "A4",
"AIN_5": "A5",
"AOUT" : "A5",
"PWM_0": "D3",
"PWM_1": "D5",
"PWM_2": "D6",
"PWM_3": "D9",
"DEBUG_MSG": 0,
"DEVICE_SPI": 1,
"FSFAT_SDCARD_INSTALLED": 1
},
"target_overrides": {
"DISCO_F051R8": {
"SPI_MOSI": "SPI_MOSI",
"SPI_MISO": "SPI_MISO",
"SPI_CLK": "SPI_SCK",
"SPI_CS": "SPI_CS"
},
"K20D50M": {
"SPI_MOSI": "PTD2",
"SPI_MISO": "PTD3",
"SPI_CLK": "PTD1",
"SPI_CS": "PTC2"
},
"KL22F": {
"SPI_MOSI": "PTD6",
"SPI_MISO": "PTD7",
"SPI_CLK": "PTD5",
"SPI_CS": "PTD4"
},
"KL25Z": {
"SPI_MOSI": "PTD2",
"SPI_MISO": "PTD3",
"SPI_CLK": "PTD1",
"SPI_CS": "PTD0"
},
"KL43Z": {
"SPI_MOSI": "PTD6",
"SPI_MISO": "PTD7",
"SPI_CLK": "PTD5",
"SPI_CS": "PTD4"
},
"KL46Z": {
"SPI_MOSI": "PTD6",
"SPI_MISO": "PTD7",
"SPI_CLK": "PTD5",
"SPI_CS": "PTD4"
},
"K64F": {
"SPI_MOSI": "PTE3",
"SPI_MISO": "PTE1",
"SPI_CLK": "PTE2",
"SPI_CS": "PTE4"
},
"K66F": {
"SPI_MOSI": "PTE3",
"SPI_MISO": "PTE1",
"SPI_CLK": "PTE2",
"SPI_CS": "PTE4"
},
"LPC11U37H_401": {
"SPI_MOSI": "SDMOSI",
"SPI_MISO": "SDMISO",
"SPI_CLK": "SDSCLK",
"SPI_CS": "SDSSEL"
},
"LPC2368": {
"SPI_MOSI": "p11",
"SPI_MISO": "p12",
"SPI_CLK": "p13",
"SPI_CS": "p14"
},
"NUCLEO_L031K6": {
"SPI_MOSI": "SPI_MOSI",
"SPI_MISO": "SPI_MISO",
"SPI_CLK": "SPI_SCK",
"SPI_CS": "SPI_CS"
},
"nRF51822": {
"SPI_MOSI": "p12",
"SPI_MISO": "p13",
"SPI_CLK": "p15",
"SPI_CS": "p14"
},
"RZ_A1H": {
"SPI_MOSI": "P8_5",
"SPI_MISO": "P8_6",
"SPI_CLK": "P8_3",
"SPI_CS": "P8_4"
}
}
}
Note the following things about the mbed_app.json file:
- The mbed_app.json is used to define target specific symbols for the SPI pins used to connect the SDCard slot to the target MCU:
- "SPI\_CS".
- "SPI\_MOSI".
- "SPI\_MISO".
- "SPI\_CLK".
- The default configuration is defined in the "config" section for mappings to the standard Arduino header pins for the SPI bus.
The "config" section defines a dictionary which maps functional names to target board Arduino header pins:
- "SPI\_CS": "D10". This causes the MBED\_CONF\_APP\_SPI\_CS symbol to be defined in mbed\_config.h as D10, which is used in the filesystem test implementation.
D10 is defined in the target specific PinNames.h file.
- "SPI\_MOSI": "D11". This causes the MBED\_CONF\_APP\_SPI\_MOSI symbol to be defined in mbed\_config.h.
- "SPI\_MISO": "D12". This causes the MBED\_CONF\_APP\_SPI\_MISO symbol to be defined in mbed\_config.h.
- "SPI\_CLK": "D13". This causes the MBED\_CONF\_APP\_SPI\_CLK symbol to be defined in mbed\_config.h.
- The ""target_overrides" is used to override the "SPI\_xxx" symbols for specific target boards, which may have an SDCard slot, for example.
This is the case for the K64F, where the "SPI\_xxx" are mapped to the pin names for the on-board SDCard
```
"K64F": {
"SPI_MOSI": "PTE3",
"SPI_MISO": "PTE1",
"SPI_CLK": "PTE2",
"SPI_CS": "PTE4"
}
```
- Thus, in the absence of any target specific definitions in the "target_overrides" section, all boards will default to
use the Arduino header configuration.
#### <a name="insert-sdcard-into-k64f"></a> Insert SDCard into K64F
The test cases have been run on a K64F with the following microSDHC cards: