Overview
The SPI SdCard Example application demonstrates the use of SD card driver with SPI. Provide an example with different modes: (Temporary, this example just don't support SD card memory more than 2 GB)
- Detect card inserted
- Check card status: lock or unlock (detect by hardware pin)
- Read and write single block and multi-blocks to SdCard
- Erase blocks in SdCard
Supported Platforms
These Freescale Freedom development platforms and Tower System modules are supported by the SPI SdCard example.
- TWR-K22F120M
- TWR-K24F120M
- TWR-KV31F120M
System Requirement
Hardware requirements
- J-Link ARM
- P&E Micro Multi-link universal
- Mini/micro USB cable
- USB A to micro AB cable
- Hardware (tower/base board, TWR-MEM board...) for specific device
- Personal Computer
Toolchain requirements
- IAR embedded Workbench version 7.30.4
- ARM GCC 4.8.3 2014q3
- Keil MDK 5.13
- Kinetis Design Studio IDE v.2.5.0
- Atollic TrueSTUDIO for ARM win32 v5.2.1
Software requirements
- The project files are in: <SDK_Install>/examples/<board>/driver_examples/spi_sdcard/<toolchain>.
- Library dependencies: ksdk_platform_lib
Getting Started
Hardware settings
The SPI SdCard Example project does not call for any special hardware configurations. Although not required, the recommendation is to leave the development board's jumper settings and configurations in default state when running this example. If there is not any built-in SD-Card slot on the board, TWR-MEM board is required to run this example.
Prepare the example
- Connect a USB cable between the PC host and the OpenSDA USB port on the board.
- Open a serial terminal with these settings:
- 115200 baud rate
- 8 data bits
- No parity
- One stop bit
- No flow control
- Download the program to the target board.
- Either press the reset button on your board or launch the debugger in your IDE to begin running the example.
Run the example
Ensure that the card doesn't contain any important content because the demo will erase and overwrite some sectors.
These instructions are displayed/shown on the terminal window:
SPI SD Card Demo Start!
BaudRate set to 375000Hz
BaudRate set to 20000000Hz
------- Card Information -------
Card Type: SDSC
Card Capacity: 1.97 GB
-------- Card CID --------
Manufacturer ID: 0x2
OEM ID: 0x544D
Product name: SA02G
Product revision: 0.5
Product serial number: 0x2080728A
Manufacturing data: Aug 2010
-------- Card CSD --------
CSD Structure: 0x0
taac: 2000.00 us
nsac: 0 clks
tran speed: 25000000.00 kbps
ccc: class 0 2 4 5 7 8 10
max read block length: 1024 Bytes
max write block length: 1024 Bytes
Support partial read
Support crossing physical block boundaries reading is allowed
VDD_R_CURR_MIN: 0x7
VDD_R_CURR_MAX: 0x1
VDD_W_CURR_MIN: 0x7
VDD_W_CURR_MAX: 0x3F
c_size_mult: 7
c_size: 3763
Erase unit size is one or multiple units of 512 bytes
The size of write protected group is 2 blocks
R2W_Factor: 2
Hard disk-like file system with partition table
Start read/write example...
Single block read/write example passed!
Writing 4096 bytes for 100 times in 2502 ms, at 163 kB/s
Reading 4096 bytes for 100 times in 2164 ms, at 189 kB/s
Multi-block read/write example passed!
SPI SD Card Demo End!