Atmel Software Framework

avr32/components/memory/sd_mmc/sd_mmc_spi/sd_mmc_spi.c File Reference
#include "conf_access.h"
#include "compiler.h"
#include "board.h"
#include "gpio.h"
#include "spi.h"
#include "conf_sd_mmc_spi.h"
#include "sd_mmc_spi.h"
#include <string.h>

Macros

#define NO_SUPPORT_USB_PING_PONG
 

Functions

bool is_sd_mmc_spi_write_pwd_locked (void)
 This function checks if the card is password-locked Old versions of MMC card don't support this feature ! For a MMC, "lock protection" is featured from v2.1 release ! => see CSD[0]<5:2> bits to know the version : 0x0=1.x, 0x1=1.4, 0x2=2.x, 0x3=3.x, 0x4=4.0. More...
 
int sd_mmc_spi_check_hc (void)
 This function checks whether detected card is High Capacity SD card. More...
 
bool sd_mmc_spi_check_presence (void)
 This function check the presence of a memory card. More...
 
uint8_t sd_mmc_spi_command (uint8_t command, uint32_t arg)
 This function sends a command WITH DATA STATE to the SD/MMC and waits for R1 response The memory /CS signal is not affected so this function can be used to send a command during a large transmission. More...
 
bool sd_mmc_spi_erase_sector_group (uint32_t adr_start, uint32_t adr_end)
 This function erase a group of sectors NOTE : Erasing operation concerns only groups of sectors and not one sector only The global variable "erase_group_size" (extracted from CSD) contains the sector group size boundary User specifies the addresses of the first group and the last group to erase (several contiguous groups can be selected for erase) An misaligned address will not generate an error since the memory card ignore the LSbs of the address Some examples (with "erase_group_size" = 0x20 = group boundary) : More...
 
void sd_mmc_spi_get_capacity (void)
 This function extracts structure information from CSD array and compute the number of blocks of the memory card (stored in global uint32_t sd_mmc_spi_last_block_address), its capacity in bytes (stored in global uint32_t capacity) and the block group size for an erase operation Here is defined the position of required fields in CSD array : READ_BL_LEN : [83:80] == data[5] && 0x0f C_SIZE : [73:72] == data[6] && 0x03 [71:64] == data[7] [63:62] == data[8] && 0xc0 C_SIZE_MULT : [49:48] == data[9] && 0x03 [47] == data[10] && 0x80 ERASE_GRP_SIZE (MMC card only) : [46:42] == data[10] && 0x7c ERASE_GRP_MULT (MMC card only) : [41:40] == data[10] && 0x03 [39:37] == data[11] && 0xe0 SECTOR_SIZE (SD card only) : [45:40] == data[10] && 0x3F [39] == data[11] && 0x80. More...
 
bool sd_mmc_spi_get_cid (uint8_t *buffer)
 This function reads the CID (Card Identification Data) of the memory card. More...
 
bool sd_mmc_spi_get_csd (uint8_t *buffer)
 This function reads the CSD (Card Specific Data) of the memory card. More...
 
int sd_mmc_spi_get_if (void)
 This function detects the card interface. More...
 
bool sd_mmc_spi_get_status (void)
 This function reads the STATUS register of the memory card After a read the error flags are automatically cleared. More...
 
bool sd_mmc_spi_init (spi_options_t spiOptions, unsigned int pba_hz)
 This function initializes the SD/MMC controller & the SPI bus(over which the SD_MMC is controlled). More...
 
bool sd_mmc_spi_internal_init (void)
 This function initializes the SD/MMC controller. More...
 
bool sd_mmc_spi_lock_operation (uint8_t operation, uint8_t pwd_lg, uint8_t *pwd)
 This function manages locking operations for the SD/MMC card (password protection) More...
 
bool sd_mmc_spi_mem_check (void)
 This function performs a memory check on the SD_MMC. More...
 
bool sd_mmc_spi_read_close (void)
 This function unselects the current SD_MMC memory. More...
 
void sd_mmc_spi_read_close_PDCA (void)
 Stop PDCA transfer. More...
 
bool sd_mmc_spi_read_multiple_sector (uint16_t nb_sector)
 This function allow to read multiple sectors. More...
 
bool sd_mmc_spi_read_open (uint32_t pos)
 This function opens a SD_MMC memory in read mode at a given sector address (not byte address) More...
 
bool sd_mmc_spi_read_open_PDCA (uint32_t pos)
 Reading using PDCA. More...
 
bool sd_mmc_spi_read_sector_to_ram (void *ram)
 This function read one MMC sector and load it into a ram buffer. More...
 
uint8_t sd_mmc_spi_send_and_read (uint8_t data_to_send)
 This function sends a byte over SPI and returns the byte read from the slave. More...
 
uint8_t sd_mmc_spi_send_command (uint8_t command, uint32_t arg)
 This function sends a command WITH NO DATA STATE to the SD/MMC and waits for R1 response This function also selects and unselects the memory => should be used only for single command transmission. More...
 
bool sd_mmc_spi_wait_not_busy (void)
 This function waits until the SD/MMC is not busy. More...
 
void sd_mmc_spi_write_close (void)
 This function fills the end of the logical sector (512B) and launch page programming. More...
 
bool sd_mmc_spi_write_multiple_sector (uint16_t nb_sector)
 This function allow to write multiple sectors. More...
 
bool sd_mmc_spi_write_open (uint32_t pos)
 This function opens a SD_MMC memory in write mode at a given sector address. More...
 
bool sd_mmc_spi_write_sector_from_ram (const void *ram)
 This function writes one MMC sector from a ram buffer. More...
 

Variables

volatile uint64_t capacity
 
volatile uint16_t capacity_mult
 
uint8_t card_type
 
uint8_t csd [16]
 
uint8_t data_mem [513]
 
uint16_t erase_group_size
 
static uint32_t gl_ptr_mem
 
uint8_t r1
 
uint16_t r2
 
static spi_options_t sd_mmc_opt
 
static unsigned int sd_mmc_pba_hz
 
bool sd_mmc_spi_init_done = false
 
volatile uint32_t sd_mmc_spi_last_block_address
 
static uint8_t sector_buf [MMC_SECTOR_SIZE]
 

#define NO_SUPPORT_USB_PING_PONG

uint8_t data_mem[513]
spi_options_t sd_mmc_opt
static
unsigned int sd_mmc_pba_hz
static