SD card example code for Seeed Wio 3G
Fork of Wio_3G-example-sd-driver by
README.md@1:080085a0a3ec, 2018-12-03 (annotated)
- Committer:
- ytsuboi
- Date:
- Mon Dec 03 08:27:31 2018 +0000
- Revision:
- 1:080085a0a3ec
- Parent:
- 0:8eedb2495d52
Added format demo for Handson.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:8eedb2495d52 | 1 | # Getting Started With The sd-driver |
MACRUM | 0:8eedb2495d52 | 2 | |
MACRUM | 0:8eedb2495d52 | 3 | This is the mbed-os example for the SDBlockDevice (SDCard) block device driver. |
MACRUM | 0:8eedb2495d52 | 4 | See the [sd-driver](https://github.com/armmbed/sd-driver) repository for more information. |
MACRUM | 0:8eedb2495d52 | 5 | |
MACRUM | 0:8eedb2495d52 | 6 | This guide reviews the steps to get the SDCard with FAT filesystem working on an mbed OS platform. |
MACRUM | 0:8eedb2495d52 | 7 | |
MACRUM | 0:8eedb2495d52 | 8 | Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). |
MACRUM | 0:8eedb2495d52 | 9 | |
MACRUM | 0:8eedb2495d52 | 10 | ## Hardware Requirements |
MACRUM | 0:8eedb2495d52 | 11 | |
MACRUM | 0:8eedb2495d52 | 12 | This example can be used on an mbedos platform that: |
MACRUM | 0:8eedb2495d52 | 13 | |
MACRUM | 0:8eedb2495d52 | 14 | - Has an on-board SDCard slot or, |
MACRUM | 0:8eedb2495d52 | 15 | - Is fitted with a [CI Test Shield](https://github.com/ARMmbed/ci-test-shield). |
MACRUM | 0:8eedb2495d52 | 16 | |
MACRUM | 0:8eedb2495d52 | 17 | This document uses the K64F as an example. Simply change the relevant options (e.g. -m K64F) to be appropriate for your target. |
MACRUM | 0:8eedb2495d52 | 18 | |
MACRUM | 0:8eedb2495d52 | 19 | ## Create the Example Application |
MACRUM | 0:8eedb2495d52 | 20 | |
MACRUM | 0:8eedb2495d52 | 21 | From the command-line, import the example: |
MACRUM | 0:8eedb2495d52 | 22 | |
MACRUM | 0:8eedb2495d52 | 23 | ``` |
MACRUM | 0:8eedb2495d52 | 24 | mbed import mbed-os-example-sd-driver |
MACRUM | 0:8eedb2495d52 | 25 | ``` |
MACRUM | 0:8eedb2495d52 | 26 | |
MACRUM | 0:8eedb2495d52 | 27 | You should see: |
MACRUM | 0:8eedb2495d52 | 28 | |
MACRUM | 0:8eedb2495d52 | 29 | [mbed] Importing program "mbed-os-example-sd-driver" from "https://github.com/ARMmbed/mbed-os-example-sd-driver" at latest revision in the current branch |
MACRUM | 0:8eedb2495d52 | 30 | [mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at rev #f4864dc6429e |
MACRUM | 0:8eedb2495d52 | 31 | |
MACRUM | 0:8eedb2495d52 | 32 | Move into the newly created directory: |
MACRUM | 0:8eedb2495d52 | 33 | |
MACRUM | 0:8eedb2495d52 | 34 | ``` |
MACRUM | 0:8eedb2495d52 | 35 | cd mbed-os-example-sd-driver |
MACRUM | 0:8eedb2495d52 | 36 | ``` |
MACRUM | 0:8eedb2495d52 | 37 | |
MACRUM | 0:8eedb2495d52 | 38 | If the mbed-os library was not automatically added (see trace above), do the following to import mbed-os: |
MACRUM | 0:8eedb2495d52 | 39 | |
MACRUM | 0:8eedb2495d52 | 40 | ``` |
MACRUM | 0:8eedb2495d52 | 41 | mbed new . |
MACRUM | 0:8eedb2495d52 | 42 | ``` |
MACRUM | 0:8eedb2495d52 | 43 | |
MACRUM | 0:8eedb2495d52 | 44 | Add the sd-driver repository: |
MACRUM | 0:8eedb2495d52 | 45 | |
MACRUM | 0:8eedb2495d52 | 46 | ``` |
MACRUM | 0:8eedb2495d52 | 47 | mbed add sd-driver |
MACRUM | 0:8eedb2495d52 | 48 | ``` |
MACRUM | 0:8eedb2495d52 | 49 | |
MACRUM | 0:8eedb2495d52 | 50 | ## Build the Example |
MACRUM | 0:8eedb2495d52 | 51 | |
MACRUM | 0:8eedb2495d52 | 52 | Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the GCC_ARM toolchain: |
MACRUM | 0:8eedb2495d52 | 53 | |
MACRUM | 0:8eedb2495d52 | 54 | ``` |
MACRUM | 0:8eedb2495d52 | 55 | mbed compile -m K64F -t GCC_ARM |
MACRUM | 0:8eedb2495d52 | 56 | ``` |
MACRUM | 0:8eedb2495d52 | 57 | |
MACRUM | 0:8eedb2495d52 | 58 | Your PC may take a few minutes to compile your code. At the end, you see the following result: |
MACRUM | 0:8eedb2495d52 | 59 | |
MACRUM | 0:8eedb2495d52 | 60 | [snip] |
MACRUM | 0:8eedb2495d52 | 61 | Compile [ 99.7%]: SDBlockDevice.cpp |
MACRUM | 0:8eedb2495d52 | 62 | Compile [100.0%]: SPIFBlockDevice.cpp |
MACRUM | 0:8eedb2495d52 | 63 | Link: mbed-os-example-sd-driver |
MACRUM | 0:8eedb2495d52 | 64 | Elf2Bin: mbed-os-example-sd-driver |
MACRUM | 0:8eedb2495d52 | 65 | +--------------------------+-------+-------+-------+ |
MACRUM | 0:8eedb2495d52 | 66 | | Module | .text | .data | .bss | |
MACRUM | 0:8eedb2495d52 | 67 | +--------------------------+-------+-------+-------+ |
MACRUM | 0:8eedb2495d52 | 68 | | Fill | 162 | 0 | 2514 | |
MACRUM | 0:8eedb2495d52 | 69 | | Misc | 53840 | 2284 | 1112 | |
MACRUM | 0:8eedb2495d52 | 70 | | drivers | 1130 | 0 | 64 | |
MACRUM | 0:8eedb2495d52 | 71 | | features/filesystem | 13379 | 0 | 550 | |
MACRUM | 0:8eedb2495d52 | 72 | | features/storage | 42 | 0 | 184 | |
MACRUM | 0:8eedb2495d52 | 73 | | hal | 450 | 0 | 8 | |
MACRUM | 0:8eedb2495d52 | 74 | | platform | 2497 | 20 | 582 | |
MACRUM | 0:8eedb2495d52 | 75 | | rtos | 149 | 4 | 4 | |
MACRUM | 0:8eedb2495d52 | 76 | | rtos/rtx | 6143 | 20 | 6870 | |
MACRUM | 0:8eedb2495d52 | 77 | | targets/TARGET_Freescale | 12888 | 12 | 384 | |
MACRUM | 0:8eedb2495d52 | 78 | | Subtotals | 90680 | 2340 | 12272 | |
MACRUM | 0:8eedb2495d52 | 79 | +--------------------------+-------+-------+-------+ |
MACRUM | 0:8eedb2495d52 | 80 | Allocated Heap: 24576 bytes |
MACRUM | 0:8eedb2495d52 | 81 | Allocated Stack: unknown |
MACRUM | 0:8eedb2495d52 | 82 | Total Static RAM memory (data + bss): 14612 bytes |
MACRUM | 0:8eedb2495d52 | 83 | Total RAM memory (data + bss + heap + stack): 39188 bytes |
MACRUM | 0:8eedb2495d52 | 84 | Total Flash memory (text + data + misc): 94060 bytes |
MACRUM | 0:8eedb2495d52 | 85 | |
MACRUM | 0:8eedb2495d52 | 86 | Image: .\BUILD\K64F\GCC_ARM\mbed-os-example-sd-driver.bin |
MACRUM | 0:8eedb2495d52 | 87 | |
MACRUM | 0:8eedb2495d52 | 88 | ## <a name="insert-sdcard-into-k64f"></a> Insert SDCard into K64F |
MACRUM | 0:8eedb2495d52 | 89 | |
MACRUM | 0:8eedb2495d52 | 90 | This example has been run on a K64F with the following pre-formatted microSDHC cards: |
MACRUM | 0:8eedb2495d52 | 91 | |
MACRUM | 0:8eedb2495d52 | 92 | - Kingston 2GB mircoSDHC card. |
MACRUM | 0:8eedb2495d52 | 93 | - Kingston 8GB mircoSDHC card. |
MACRUM | 0:8eedb2495d52 | 94 | - SanDisk 16GB mircoSDHC ultra card. |
MACRUM | 0:8eedb2495d52 | 95 | |
MACRUM | 0:8eedb2495d52 | 96 | If the card requires formatting then the following procedure is known to work: |
MACRUM | 0:8eedb2495d52 | 97 | |
MACRUM | 0:8eedb2495d52 | 98 | - Insert microSD card into SD adapter in USB stick (or similar) so the microSD card can be insert into windows PC. |
MACRUM | 0:8eedb2495d52 | 99 | - Within file explorer, right click/Format on the USB drive. |
MACRUM | 0:8eedb2495d52 | 100 | - Select FAT32, 4096 cluster size, Quick Format. |
MACRUM | 0:8eedb2495d52 | 101 | - Format the drive. |
MACRUM | 0:8eedb2495d52 | 102 | |
MACRUM | 0:8eedb2495d52 | 103 | The microSD card should then be ready for use in the K64F. Insert the formatted card |
MACRUM | 0:8eedb2495d52 | 104 | into the SDCard slot on the K64F PCB. |
MACRUM | 0:8eedb2495d52 | 105 | |
MACRUM | 0:8eedb2495d52 | 106 | ## <a name="run-the-example-binary-on-the-k64f"></a> Run the Example Binary on the K64F |
MACRUM | 0:8eedb2495d52 | 107 | |
MACRUM | 0:8eedb2495d52 | 108 | Copy the binary from `<root_dir>/mbed-os-example-sd-driver/BUILD/K64F/GCC_ARM/main.bin` to the K64F: |
MACRUM | 0:8eedb2495d52 | 109 | |
MACRUM | 0:8eedb2495d52 | 110 | 1. Connect your mbed device to the computer over USB. |
MACRUM | 0:8eedb2495d52 | 111 | 1. Copy the binary file to the mbed device. |
MACRUM | 0:8eedb2495d52 | 112 | 1. Press the reset button to start the program. |
MACRUM | 0:8eedb2495d52 | 113 | 1. Open the UART of the board in your favorite UART viewing program. For example, `screen /dev/ttyACM0`. |
MACRUM | 0:8eedb2495d52 | 114 | |
MACRUM | 0:8eedb2495d52 | 115 | You see the following output: |
MACRUM | 0:8eedb2495d52 | 116 | |
MACRUM | 0:8eedb2495d52 | 117 | After connecting a serial console and resetting the target, the following trace should be seen: |
MACRUM | 0:8eedb2495d52 | 118 | |
MACRUM | 0:8eedb2495d52 | 119 | Welcome to the filesystem example. |
MACRUM | 0:8eedb2495d52 | 120 | Opening a new file, numbers.txt. done. |
MACRUM | 0:8eedb2495d52 | 121 | Writing decimal numbers to a file (20/20) done. |
MACRUM | 0:8eedb2495d52 | 122 | Closing file. done. |
MACRUM | 0:8eedb2495d52 | 123 | Re-opening file read-only. done. |
MACRUM | 0:8eedb2495d52 | 124 | Dumping file to screen. |
MACRUM | 0:8eedb2495d52 | 125 | 0 |
MACRUM | 0:8eedb2495d52 | 126 | 1 |
MACRUM | 0:8eedb2495d52 | 127 | 2 |
MACRUM | 0:8eedb2495d52 | 128 | 3 |
MACRUM | 0:8eedb2495d52 | 129 | 4 |
MACRUM | 0:8eedb2495d52 | 130 | 5 |
MACRUM | 0:8eedb2495d52 | 131 | 6 |
MACRUM | 0:8eedb2495d52 | 132 | 7 |
MACRUM | 0:8eedb2495d52 | 133 | 8 |
MACRUM | 0:8eedb2495d52 | 134 | 9 |
MACRUM | 0:8eedb2495d52 | 135 | 10 |
MACRUM | 0:8eedb2495d52 | 136 | 11 |
MACRUM | 0:8eedb2495d52 | 137 | 12 |
MACRUM | 0:8eedb2495d52 | 138 | 13 |
MACRUM | 0:8eedb2495d52 | 139 | 14 |
MACRUM | 0:8eedb2495d52 | 140 | 15 |
MACRUM | 0:8eedb2495d52 | 141 | 16 |
MACRUM | 0:8eedb2495d52 | 142 | 17 |
MACRUM | 0:8eedb2495d52 | 143 | 18 |
MACRUM | 0:8eedb2495d52 | 144 | 19 |
MACRUM | 0:8eedb2495d52 | 145 | EOF. |
MACRUM | 0:8eedb2495d52 | 146 | Closing file. done. |
MACRUM | 0:8eedb2495d52 | 147 | Opening root directory. done. |
MACRUM | 0:8eedb2495d52 | 148 | Printing all filenames: |
MACRUM | 0:8eedb2495d52 | 149 | numbers.txt |
MACRUM | 0:8eedb2495d52 | 150 | Closeing root directory. done. |
MACRUM | 0:8eedb2495d52 | 151 | Filesystem Demo complete. |
MACRUM | 0:8eedb2495d52 | 152 | |
MACRUM | 0:8eedb2495d52 | 153 | |
MACRUM | 0:8eedb2495d52 | 154 | ## <a name="testing-with-an-sdcard-on-target-xyx"></a> Testing with an SDCard on Target XYZ |
MACRUM | 0:8eedb2495d52 | 155 | |
MACRUM | 0:8eedb2495d52 | 156 | The standard way to test is with the mbed CI Test Shield plugged into the |
MACRUM | 0:8eedb2495d52 | 157 | target board. This pin mapping for this configuration is parameterised in |
MACRUM | 0:8eedb2495d52 | 158 | the `mbed_app.json` file. |
MACRUM | 0:8eedb2495d52 | 159 | |
MACRUM | 0:8eedb2495d52 | 160 | The following is an example of the `mbed_app.json` file available in the repository: |
MACRUM | 0:8eedb2495d52 | 161 | |
MACRUM | 0:8eedb2495d52 | 162 | { |
MACRUM | 0:8eedb2495d52 | 163 | "config": { |
MACRUM | 0:8eedb2495d52 | 164 | "UART_RX": "D0", |
MACRUM | 0:8eedb2495d52 | 165 | "UART_TX": "D1", |
MACRUM | 0:8eedb2495d52 | 166 | "DIO_0": "D0", |
MACRUM | 0:8eedb2495d52 | 167 | "DIO_1": "D1", |
MACRUM | 0:8eedb2495d52 | 168 | "DIO_2": "D2", |
MACRUM | 0:8eedb2495d52 | 169 | "DIO_3": "D3", |
MACRUM | 0:8eedb2495d52 | 170 | "DIO_4": "D4", |
MACRUM | 0:8eedb2495d52 | 171 | "DIO_5": "D5", |
MACRUM | 0:8eedb2495d52 | 172 | "DIO_6": "D6", |
MACRUM | 0:8eedb2495d52 | 173 | "DIO_7": "D7", |
MACRUM | 0:8eedb2495d52 | 174 | "DIO_8": "D8", |
MACRUM | 0:8eedb2495d52 | 175 | "DIO_9": "D9", |
MACRUM | 0:8eedb2495d52 | 176 | "SPI_CS": "D10", |
MACRUM | 0:8eedb2495d52 | 177 | "SPI_MOSI": "D11", |
MACRUM | 0:8eedb2495d52 | 178 | "SPI_MISO": "D12", |
MACRUM | 0:8eedb2495d52 | 179 | "SPI_CLK": "D13", |
MACRUM | 0:8eedb2495d52 | 180 | "I2C_SDA": "D14", |
MACRUM | 0:8eedb2495d52 | 181 | "I2C_SCL": "D15", |
MACRUM | 0:8eedb2495d52 | 182 | "I2C_TEMP_ADDR":"0x90", |
MACRUM | 0:8eedb2495d52 | 183 | "I2C_EEPROM_ADDR":"0xA0", |
MACRUM | 0:8eedb2495d52 | 184 | "AIN_0": "A0", |
MACRUM | 0:8eedb2495d52 | 185 | "AIN_1": "A1", |
MACRUM | 0:8eedb2495d52 | 186 | "AIN_2": "A2", |
MACRUM | 0:8eedb2495d52 | 187 | "AIN_3": "A3", |
MACRUM | 0:8eedb2495d52 | 188 | "AIN_4": "A4", |
MACRUM | 0:8eedb2495d52 | 189 | "AIN_5": "A5", |
MACRUM | 0:8eedb2495d52 | 190 | "AOUT" : "A5", |
MACRUM | 0:8eedb2495d52 | 191 | "PWM_0": "D3", |
MACRUM | 0:8eedb2495d52 | 192 | "PWM_1": "D5", |
MACRUM | 0:8eedb2495d52 | 193 | "PWM_2": "D6", |
MACRUM | 0:8eedb2495d52 | 194 | "PWM_3": "D9", |
MACRUM | 0:8eedb2495d52 | 195 | "DEBUG_MSG": 0, |
MACRUM | 0:8eedb2495d52 | 196 | "DEVICE_SPI": 1, |
MACRUM | 0:8eedb2495d52 | 197 | "FSFAT_SDCARD_INSTALLED": 1 |
MACRUM | 0:8eedb2495d52 | 198 | }, |
MACRUM | 0:8eedb2495d52 | 199 | "target_overrides": { |
MACRUM | 0:8eedb2495d52 | 200 | "DISCO_F051R8": { |
MACRUM | 0:8eedb2495d52 | 201 | "SPI_MOSI": "SPI_MOSI", |
MACRUM | 0:8eedb2495d52 | 202 | "SPI_MISO": "SPI_MISO", |
MACRUM | 0:8eedb2495d52 | 203 | "SPI_CLK": "SPI_SCK", |
MACRUM | 0:8eedb2495d52 | 204 | "SPI_CS": "SPI_CS" |
MACRUM | 0:8eedb2495d52 | 205 | }, |
MACRUM | 0:8eedb2495d52 | 206 | "K20D50M": { |
MACRUM | 0:8eedb2495d52 | 207 | "SPI_MOSI": "PTD2", |
MACRUM | 0:8eedb2495d52 | 208 | "SPI_MISO": "PTD3", |
MACRUM | 0:8eedb2495d52 | 209 | "SPI_CLK": "PTD1", |
MACRUM | 0:8eedb2495d52 | 210 | "SPI_CS": "PTC2" |
MACRUM | 0:8eedb2495d52 | 211 | }, |
MACRUM | 0:8eedb2495d52 | 212 | "KL22F": { |
MACRUM | 0:8eedb2495d52 | 213 | "SPI_MOSI": "PTD6", |
MACRUM | 0:8eedb2495d52 | 214 | "SPI_MISO": "PTD7", |
MACRUM | 0:8eedb2495d52 | 215 | "SPI_CLK": "PTD5", |
MACRUM | 0:8eedb2495d52 | 216 | "SPI_CS": "PTD4" |
MACRUM | 0:8eedb2495d52 | 217 | }, |
MACRUM | 0:8eedb2495d52 | 218 | "KL25Z": { |
MACRUM | 0:8eedb2495d52 | 219 | "SPI_MOSI": "PTD2", |
MACRUM | 0:8eedb2495d52 | 220 | "SPI_MISO": "PTD3", |
MACRUM | 0:8eedb2495d52 | 221 | "SPI_CLK": "PTD1", |
MACRUM | 0:8eedb2495d52 | 222 | "SPI_CS": "PTD0" |
MACRUM | 0:8eedb2495d52 | 223 | }, |
MACRUM | 0:8eedb2495d52 | 224 | "KL43Z": { |
MACRUM | 0:8eedb2495d52 | 225 | "SPI_MOSI": "PTD6", |
MACRUM | 0:8eedb2495d52 | 226 | "SPI_MISO": "PTD7", |
MACRUM | 0:8eedb2495d52 | 227 | "SPI_CLK": "PTD5", |
MACRUM | 0:8eedb2495d52 | 228 | "SPI_CS": "PTD4" |
MACRUM | 0:8eedb2495d52 | 229 | }, |
MACRUM | 0:8eedb2495d52 | 230 | "KL46Z": { |
MACRUM | 0:8eedb2495d52 | 231 | "SPI_MOSI": "PTD6", |
MACRUM | 0:8eedb2495d52 | 232 | "SPI_MISO": "PTD7", |
MACRUM | 0:8eedb2495d52 | 233 | "SPI_CLK": "PTD5", |
MACRUM | 0:8eedb2495d52 | 234 | "SPI_CS": "PTD4" |
MACRUM | 0:8eedb2495d52 | 235 | }, |
MACRUM | 0:8eedb2495d52 | 236 | "K64F": { |
MACRUM | 0:8eedb2495d52 | 237 | "SPI_MOSI": "PTE3", |
MACRUM | 0:8eedb2495d52 | 238 | "SPI_MISO": "PTE1", |
MACRUM | 0:8eedb2495d52 | 239 | "SPI_CLK": "PTE2", |
MACRUM | 0:8eedb2495d52 | 240 | "SPI_CS": "PTE4" |
MACRUM | 0:8eedb2495d52 | 241 | }, |
MACRUM | 0:8eedb2495d52 | 242 | "K66F": { |
MACRUM | 0:8eedb2495d52 | 243 | "SPI_MOSI": "PTE3", |
MACRUM | 0:8eedb2495d52 | 244 | "SPI_MISO": "PTE1", |
MACRUM | 0:8eedb2495d52 | 245 | "SPI_CLK": "PTE2", |
MACRUM | 0:8eedb2495d52 | 246 | "SPI_CS": "PTE4" |
MACRUM | 0:8eedb2495d52 | 247 | }, |
MACRUM | 0:8eedb2495d52 | 248 | "LPC11U37H_401": { |
MACRUM | 0:8eedb2495d52 | 249 | "SPI_MOSI": "SDMOSI", |
MACRUM | 0:8eedb2495d52 | 250 | "SPI_MISO": "SDMISO", |
MACRUM | 0:8eedb2495d52 | 251 | "SPI_CLK": "SDSCLK", |
MACRUM | 0:8eedb2495d52 | 252 | "SPI_CS": "SDSSEL" |
MACRUM | 0:8eedb2495d52 | 253 | }, |
MACRUM | 0:8eedb2495d52 | 254 | "LPC2368": { |
MACRUM | 0:8eedb2495d52 | 255 | "SPI_MOSI": "p11", |
MACRUM | 0:8eedb2495d52 | 256 | "SPI_MISO": "p12", |
MACRUM | 0:8eedb2495d52 | 257 | "SPI_CLK": "p13", |
MACRUM | 0:8eedb2495d52 | 258 | "SPI_CS": "p14" |
MACRUM | 0:8eedb2495d52 | 259 | }, |
MACRUM | 0:8eedb2495d52 | 260 | "NUCLEO_L031K6": { |
MACRUM | 0:8eedb2495d52 | 261 | "SPI_MOSI": "SPI_MOSI", |
MACRUM | 0:8eedb2495d52 | 262 | "SPI_MISO": "SPI_MISO", |
MACRUM | 0:8eedb2495d52 | 263 | "SPI_CLK": "SPI_SCK", |
MACRUM | 0:8eedb2495d52 | 264 | "SPI_CS": "SPI_CS" |
MACRUM | 0:8eedb2495d52 | 265 | }, |
MACRUM | 0:8eedb2495d52 | 266 | "nRF51822": { |
MACRUM | 0:8eedb2495d52 | 267 | "SPI_MOSI": "p12", |
MACRUM | 0:8eedb2495d52 | 268 | "SPI_MISO": "p13", |
MACRUM | 0:8eedb2495d52 | 269 | "SPI_CLK": "p15", |
MACRUM | 0:8eedb2495d52 | 270 | "SPI_CS": "p14" |
MACRUM | 0:8eedb2495d52 | 271 | }, |
MACRUM | 0:8eedb2495d52 | 272 | "RZ_A1H": { |
MACRUM | 0:8eedb2495d52 | 273 | "SPI_MOSI": "P8_5", |
MACRUM | 0:8eedb2495d52 | 274 | "SPI_MISO": "P8_6", |
MACRUM | 0:8eedb2495d52 | 275 | "SPI_CLK": "P8_3", |
MACRUM | 0:8eedb2495d52 | 276 | "SPI_CS": "P8_4" |
MACRUM | 0:8eedb2495d52 | 277 | } |
MACRUM | 0:8eedb2495d52 | 278 | } |
MACRUM | 0:8eedb2495d52 | 279 | } |
MACRUM | 0:8eedb2495d52 | 280 | |
MACRUM | 0:8eedb2495d52 | 281 | Note the following things about the `mbed_app.json` file: |
MACRUM | 0:8eedb2495d52 | 282 | |
MACRUM | 0:8eedb2495d52 | 283 | - The `mbed_app.json` file is used to define target specific symbols for the SPI pins connecting the SDCard slot to the target MCU: |
MACRUM | 0:8eedb2495d52 | 284 | - "SPI\_CS". This is the Chip Select line. |
MACRUM | 0:8eedb2495d52 | 285 | - "SPI\_MOSI". This is the Master Out Slave In data line. |
MACRUM | 0:8eedb2495d52 | 286 | - "SPI\_MISO". This is the Master In Slave Out data line. |
MACRUM | 0:8eedb2495d52 | 287 | - "SPI\_CLK". This is the serial Clock line. |
MACRUM | 0:8eedb2495d52 | 288 | - The default configuration defined in the "config" section is for the standard Arduino header pin mappings for the SPI bus. |
MACRUM | 0:8eedb2495d52 | 289 | The "config" section defines a dictionary mapping functional names to target board Arduino header pins: |
MACRUM | 0:8eedb2495d52 | 290 | - "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. |
MACRUM | 0:8eedb2495d52 | 291 | D10 is defined in the target specific PinNames.h file. |
MACRUM | 0:8eedb2495d52 | 292 | - "SPI\_MOSI": "D11". This causes the MBED\_CONF\_APP\_SPI\_MOSI symbol to be defined in mbed\_config.h. |
MACRUM | 0:8eedb2495d52 | 293 | - "SPI\_MISO": "D12". This causes the MBED\_CONF\_APP\_SPI\_MISO symbol to be defined in mbed\_config.h. |
MACRUM | 0:8eedb2495d52 | 294 | - "SPI\_CLK": "D13". This causes the MBED\_CONF\_APP\_SPI\_CLK symbol to be defined in mbed\_config.h. |
MACRUM | 0:8eedb2495d52 | 295 | - The `"target_overrides"` section is used to override the "SPI\_xxx" symbols for specific target boards, which may have an SDCard slot, for example. |
MACRUM | 0:8eedb2495d52 | 296 | This is the case for the K64F, where the "SPI\_xxx" are mapped to the pin names for the on-board SDCard. |
MACRUM | 0:8eedb2495d52 | 297 | |
MACRUM | 0:8eedb2495d52 | 298 | ``` |
MACRUM | 0:8eedb2495d52 | 299 | "K64F": { |
MACRUM | 0:8eedb2495d52 | 300 | "SPI_MOSI": "PTE3", |
MACRUM | 0:8eedb2495d52 | 301 | "SPI_MISO": "PTE1", |
MACRUM | 0:8eedb2495d52 | 302 | "SPI_CLK": "PTE2", |
MACRUM | 0:8eedb2495d52 | 303 | "SPI_CS": "PTE4" |
MACRUM | 0:8eedb2495d52 | 304 | } |
MACRUM | 0:8eedb2495d52 | 305 | ``` |
MACRUM | 0:8eedb2495d52 | 306 | - Thus, in the absence of any target specific definitions in the `"target_overrides"` section, all boards will default to |
MACRUM | 0:8eedb2495d52 | 307 | using the Arduino header configuration. For those platforms with a `"target_overrides"` section then this configuration |
MACRUM | 0:8eedb2495d52 | 308 | will be used in preference. |
MACRUM | 0:8eedb2495d52 | 309 | - Hence in the case that you want to test a platform with an SDCard inserted into a |
MACRUM | 0:8eedb2495d52 | 310 | fitted CI test shield (rather than the on-board SDCard slot) |
MACRUM | 0:8eedb2495d52 | 311 | and there is a `"target_overrides"` section present in the `mbed_app.json` file, you must then delete the `"target_overrides"` |
MACRUM | 0:8eedb2495d52 | 312 | section before building. This will result in the default configuration being used (suitable for the CI |
MACRUM | 0:8eedb2495d52 | 313 | Test Shield). |
MACRUM | 0:8eedb2495d52 | 314 | - Note when inserting the v1.0.0 CI Test Shield into the Arduino header of the target platform, the shield pins D0 and |
MACRUM | 0:8eedb2495d52 | 315 | D1 should be bent to be parallel to the shield PCB so they are not inserted into the Arduino header. This is because |
MACRUM | 0:8eedb2495d52 | 316 | some boards use the same UART on DAPLINK and D0/D1, which means the serial debug channel breaks and hence the mbed greentea |
MACRUM | 0:8eedb2495d52 | 317 | test suite will not work correctly. This is mainly on older ST boards and should not be a problem on |
MACRUM | 0:8eedb2495d52 | 318 | `K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2`. Note also that the v2.0.0 CI Test Shield doesn't suffer from this |
MACRUM | 0:8eedb2495d52 | 319 | problem and the pins don't need to be bent. |
MACRUM | 0:8eedb2495d52 | 320 | - When inserting the SDCard into the card slot on the CI test shield, make sure the card is fully inserted. |
MACRUM | 0:8eedb2495d52 | 321 | On insertion, there should be a small clicking sound when the card registers, and the back edge of the card |
MACRUM | 0:8eedb2495d52 | 322 | should protrude no more than ~1mm over the edge of the CI test shield PCB. If the SDCard fails to register, |
MACRUM | 0:8eedb2495d52 | 323 | try gently pushing the metal flexible strip in the shape of a spade at the top edge of the SDCard metal slot |
MACRUM | 0:8eedb2495d52 | 324 | casing with a pair of tweezers, bending it a little to lower it into the slot casing. This helps with the |
MACRUM | 0:8eedb2495d52 | 325 | insertion mechanism. |
MACRUM | 0:8eedb2495d52 | 326 | |
MACRUM | 0:8eedb2495d52 | 327 | |
MACRUM | 0:8eedb2495d52 | 328 | ## Target K64F with CI Test Shield fitted |
MACRUM | 0:8eedb2495d52 | 329 | |
MACRUM | 0:8eedb2495d52 | 330 | ![alt text](pics/sd_driver_k64_with_ci_test_shield.jpg "unseen title text") |
MACRUM | 0:8eedb2495d52 | 331 | |
MACRUM | 0:8eedb2495d52 | 332 | **Figure 1. The figure shows the K64F platform with the CI shield fitted.** |
MACRUM | 0:8eedb2495d52 | 333 | |
MACRUM | 0:8eedb2495d52 | 334 | The above figure shows the K64F with the v1.0.0 CI test shield fitted. Note: |
MACRUM | 0:8eedb2495d52 | 335 | |
MACRUM | 0:8eedb2495d52 | 336 | - The pins D0/D1 (top right of CI test shield) are bent sideways so as not to insert into the header. |
MACRUM | 0:8eedb2495d52 | 337 | - The SDCard is fully inserted into the slot and overhangs the PCB by ~1mm. |
MACRUM | 0:8eedb2495d52 | 338 | |
MACRUM | 0:8eedb2495d52 | 339 | |
MACRUM | 0:8eedb2495d52 | 340 | # Troubleshooting |
MACRUM | 0:8eedb2495d52 | 341 | |
MACRUM | 0:8eedb2495d52 | 342 | 1. Make sure `mbed-cli` is working correctly and its version is newer than `1.0.0`. |
MACRUM | 0:8eedb2495d52 | 343 | |
MACRUM | 0:8eedb2495d52 | 344 | ``` |
MACRUM | 0:8eedb2495d52 | 345 | mbed --version |
MACRUM | 0:8eedb2495d52 | 346 | ``` |
MACRUM | 0:8eedb2495d52 | 347 | |
MACRUM | 0:8eedb2495d52 | 348 | If not, update it: |
MACRUM | 0:8eedb2495d52 | 349 | |
MACRUM | 0:8eedb2495d52 | 350 | ``` |
MACRUM | 0:8eedb2495d52 | 351 | pip install mbed-cli --upgrade |
MACRUM | 0:8eedb2495d52 | 352 | ``` |
MACRUM | 0:8eedb2495d52 | 353 |