softspi driver and its app test

This commit is contained in:
wuzheng 2022-11-09 19:23:12 +08:00
parent 094986ac76
commit d3836f1a6f
20 changed files with 590 additions and 26 deletions

View File

@ -26,6 +26,17 @@ menu "test app"
endif
endif
menuconfig USER_TEST_SD
bool "Config test sd"
default n
if USER_TEST_SD
if ADD_XIZI_FETURES
config SD_FPATH
string "Set sd file path"
default "/sdcard_testfile"
endif
endif
config USER_TEST_SEMC
bool "Config test semc sdram"
default n
@ -33,5 +44,7 @@ menu "test app"
config USER_TEST_LCD
bool "Config test lcd device"
default n
endif
endmenu

View File

@ -25,6 +25,10 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
SRC_FILES += test_dac.c
endif
ifeq ($(CONFIG_USER_TEST_SD),y)
SRC_FILES += test_softspi_sd.c
endif
ifeq ($(CONFIG_USER_TEST_SEMC),y)
SRC_FILES += test_extsram.c
endif

View File

@ -56,4 +56,4 @@ void TestAdc(void)
return;
}
PRIV_SHELL_CMD_FUNCTION(TestAdc, a adc test sample, PRIV_SHELL_CMD_MAIN_ATTR);
PRIV_SHELL_CMD_FUNCTION(TestAdc, a adc test sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>
#include <transform.h>
#define MAX_READ_LENGTH 1000
// sd card here is loaded as "/"
void TestSD(void)
{
//open the file in sdcard
int fd = open(SD_FPATH,O_RDWR|O_CREAT);
char filewords[MAX_READ_LENGTH];
memset(filewords,0,MAX_READ_LENGTH);
//read and write then close file
read(fd,filewords,MAX_READ_LENGTH);
printf("read data is \n%s\n",filewords);
const char *input_words = "these words are going to write in sdcard\n";
write(fd,input_words,strlen(input_words));
close(fd);
//re-open the file and re-read the file
fd = open(SD_FPATH,O_RDWR);
read(fd,filewords,MAX_READ_LENGTH);
printf("read data is \n%s\n",filewords);
close(fd);
return;
}
PRIV_SHELL_CMD_FUNCTION(TestSD, a sdcard test sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -44,10 +44,11 @@ Modification:
#include "fpioa.h"
#include "dmac.h"
#include "connect_gpio.h"
#include "connect_soft_spi.h"
#if defined(FS_VFS)
#include <iot-vfs.h>
#endif
// #if defined(FS_VFS)
// #include <iot-vfs.h>
// #endif
#define CPU0 (0)
#define CPU1 (1)
@ -60,8 +61,8 @@ extern int HwTouchInit(void);
extern int HwCh376Init(void);
extern int HwLcdInit(void);
extern int HwSpiInit(void);
extern int HwSoftSPIInit(void);
#ifdef FS_CH376
#include <iot-vfs.h>
#ifdef MOUNT_USB
/**
@ -78,23 +79,34 @@ int MountUSB(void)
return 0;
}
#endif
#ifdef MOUNT_SDCARD
#if defined(FS_VFS) && defined (MOUNT_SDCARD)
#include <iot-vfs.h>
#include <sd_spi.h>
extern SpiSdDeviceType SpiSdInit(struct Bus *bus, const char *dev_name, const char *drv_name, const char *sd_name);
/**
* @description: Mount SD card
* @return 0
*/
int MountSDCard(void)
int MountSDCard(void)
{
if (MountFilesystem(SDIO_BUS_NAME,SDIO_DEVICE_NAME ,SDIO_DRIVER_NAME , FSTYPE_CH376, "/") == 0)
KPrintf("sd card mount to '/'\n");
else
KPrintf("sd card mount to '/' failed!\n");
return 0;
struct Bus *spi_bus;
spi_bus = BusFind(SOFT_SPI_BUS_NAME);
if (NONE == SpiSdInit(spi_bus, SOFT_SPI_DEVICE_NAME, SOFT_SPI_DRV_NAME, SPI_SD_NAME)) {
KPrintf("MountSDCard SpiSdInit error!\n");
return -1;
}
if (EOK != MountFilesystem(SOFT_SPI_BUS_NAME, SPI_SD_NAME, SOFT_SPI_DRV_NAME, FSTYPE_FATFS, "/")) {
return -1;
}
KPrintf("SPI SD card fatfs mounted\n");
return 0;
}
#endif
#endif
void InitBss(void)
{
@ -183,10 +195,14 @@ struct InitSequenceDesc _board_init[] =
#endif
#ifdef BSP_USING_TOUCH
{"touch", HwTouchInit },
#endif
#ifdef BSP_USING_SOFT_SPI
{"soft_spi", HwSoftSPIInit },
#endif
{ " NONE ",NONE },
};
void InitBoardHardware(void)
{
int i = 0;

View File

@ -16,6 +16,16 @@ menuconfig BSP_USING_SPI
source "$BSP_DIR/third_party_driver/spi/Kconfig"
endif
menuconfig BSP_USING_SOFT_SPI
bool "Using SOFT_SPI device"
default n
select BSP_USING_SPI
select MOUNT_SDCARD
select FS_VFS
if BSP_USING_SOFT_SPI
source "$BSP_DIR/third_party_driver/soft_spi/Kconfig"
endif
menuconfig BSP_USING_LCD
bool "Using LCD device"
default n

View File

@ -40,4 +40,8 @@ ifeq ($(CONFIG_BSP_USING_LCD),y)
SRC_DIR += lcd
endif
ifeq ($(CONFIG_BSP_USING_SOFT_SPI),y)
SRC_DIR += soft_spi
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -95,7 +95,13 @@ static struct io_config
IOCONFIG(BSP_CH438_D4_PIN, HS_GPIO(FPIOA_CH438_D4)),
IOCONFIG(BSP_CH438_D5_PIN, HS_GPIO(FPIOA_CH438_D5)),
IOCONFIG(BSP_CH438_D6_PIN, HS_GPIO(FPIOA_CH438_D6)),
IOCONFIG(BSP_CH438_D7_PIN, HS_GPIO(FPIOA_CH438_D7))
IOCONFIG(BSP_CH438_D7_PIN, HS_GPIO(FPIOA_CH438_D7)),
#endif
#ifdef BSP_USING_SOFT_SPI
IOCONFIG(BSP_SOFT_SPI_SCK_PIN, HS_GPIO(FPIOA_SOFT_SPI_SCK)),
IOCONFIG(BSP_SOFT_SPI_MIOS_PIN, HS_GPIO(FPIOA_SOFT_SPI_MIOS)),
IOCONFIG(BSP_SOFT_SPI_MSOI_PIN, HS_GPIO(FPIOA_SOFT_SPI_MSOI)),
IOCONFIG(BSP_SOFT_SPI_NCS_PIN, HS_GPIO(FPIOA_SOFT_SPI_NCS)),
#endif
};

View File

@ -0,0 +1,14 @@
#ifndef CONNECT_TF_H
#define CONNECT_TF_H
#ifdef __cplusplus
extern "C" {
#endif
int HwSoftSPIInit(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -78,6 +78,19 @@ enum HS_GPIO_CONFIG
#define BSP_CH438_INT_PIN 35
#endif
#define BSP_USING_SOFT_SPI
#ifdef BSP_USING_SOFT_SPI
#define FPIOA_SOFT_SPI_SCK 26
#define FPIOA_SOFT_SPI_MIOS 25
#define FPIOA_SOFT_SPI_MSOI 27
#define FPIOA_SOFT_SPI_NCS 28
#define BSP_SOFT_SPI_SCK_PIN 26
#define BSP_SOFT_SPI_MIOS_PIN 25
#define BSP_SOFT_SPI_MSOI_PIN 27
#define BSP_SOFT_SPI_NCS_PIN 28
#endif
extern int IoConfigInit(void);
#endif

View File

@ -0,0 +1,47 @@
if BSP_USING_SOFT_SPI
config SOFT_SPI_BUS_NAME
string "soft spi bus 1 name"
default "soft_spi1_bus1"
config SOFT_SPI_DEVICE_NAME
string "soft spi dev 1 name"
default "soft_spi1_dev1"
config SOFT_SPI_DRV_NAME
string "soft spi drv 1 name"
default "soft_spi1_drv1"
config SOFT_SPI_SCK
int "soft spi sck pin"
default 26
config SOFT_SPI_MOSI
int "soft spi mosi pin"
default 27
config SOFT_SPI_MISO
int "soft spi miso pin"
default 25
config SOFT_SPI_CS0_PIN
int "soft spi cs pin"
default 28
config SOFT_SPI_DEVICE_SLAVE_ID
int "soft spi slave id"
default 0
config SOFT_SPI_CHIP_SELECT
int "soft spi chip selected"
default 0
config SOFT_SPI_CLK_DELAY
int "clk in microsecond"
default 0
config SOFT_SPI_READ_DELAY
int "read after millisecond"
default 1
endif

View File

@ -0,0 +1,3 @@
SRC_FILES := connect_soft_spi.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,292 @@
#include <xizi.h>
#include <device.h>
#include <fpioa.h>
#include <gpiohs.h>
#include "drv_io_config.h"
#include <plic.h>
#include <utils.h>
#include <connect_soft_spi.h>
#include <sleep.h>
#include <sd_spi.h>
#include <dev_spi.h>
#include <bus_spi.h>
static x_err_t softSPIinit(struct SpiDriver *spi_drv, struct BusConfigureInfo *cfg)
{
NULL_PARAM_CHECK(spi_drv );
NULL_PARAM_CHECK(cfg );
//mode CPOL = 0 CPHA = 0
gpiohs_set_drive_mode(SOFT_SPI_CS0_PIN,GPIO_DM_OUTPUT);
gpiohs_set_pin(SOFT_SPI_CS0_PIN, GPIO_PV_HIGH);//set the cs gpio high
gpiohs_set_drive_mode(SOFT_SPI_SCK, GPIO_DM_OUTPUT);
gpiohs_set_drive_mode(SOFT_SPI_MOSI, GPIO_DM_OUTPUT);
gpiohs_set_drive_mode(SOFT_SPI_MISO, GPIO_DM_INPUT);
gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_LOW);
KPrintf("%s init done\n",SOFT_SPI_BUS_NAME);
return EOK;
}
static uint32 softSpiDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
NULL_PARAM_CHECK(configure_info);
x_err_t ret = EOK;
struct SpiDriver *spi_drv = (struct SpiDriver *)drv;
struct SpiMasterParam *spi_param;
switch (configure_info->configure_cmd)
{
case OPE_INT:
softSPIinit(spi_drv,configure_info);
break;
case OPE_CFG:
break;
default:
break;
}
return ret;
}
static void soft_spi_writebyte(struct SpiHardwareDevice *spi_dev, uint8_t data)
{
int8_t i = 0;
uint8_t temp = 0;
for(i=0; i<8; i++)
{
temp = ((data&0x80)==0x80)? 1:0;
data = data<<1;
gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_LOW);
usleep(SOFT_SPI_CLK_DELAY);
if(0 == temp )
{
gpiohs_set_pin(SOFT_SPI_MOSI,GPIO_PV_LOW);
}
else
{
gpiohs_set_pin(SOFT_SPI_MOSI,GPIO_PV_HIGH);
}
gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_HIGH);
usleep(SOFT_SPI_CLK_DELAY);
}
gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_LOW);
}
/* 读一个字节 */
static uint8_t soft_spi_readbyte(struct SpiHardwareDevice *spi_dev)
{
uint8_t i = 0;
uint8_t read_data = 0xFF;
for(i=0; i<8; i++)
{
read_data = read_data << 1;
gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_LOW);
usleep(SOFT_SPI_CLK_DELAY);
gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_HIGH);
usleep(SOFT_SPI_CLK_DELAY);
if(1==gpiohs_get_pin(SOFT_SPI_MISO))
{
read_data = read_data | 0x01;
}
}
return read_data;
}
/* 读写一个字节 */
//this funcition is unverify until now!
static uint8_t soft_spi_readwritebyte(struct SpiHardwareDevice *spi_dev, uint8_t data)
{
uint8_t i = 0;
uint8_t temp = 0;
uint8_t read_data = 0xFF;
for(i=0;i<8;i++)
{
temp = ((data&0x80)==0x80)? 1:0;
data = data<<1;
read_data = read_data<<1;
if(temp == 0)
{
gpiohs_set_pin(SOFT_SPI_MOSI,GPIO_PV_LOW);
}
else
{
gpiohs_set_pin(SOFT_SPI_MOSI,GPIO_PV_HIGH);
}
usleep(SOFT_SPI_CLK_DELAY);
gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_HIGH);
usleep(SOFT_SPI_CLK_DELAY);
if(gpiohs_get_pin(SOFT_SPI_MISO)==1)
{
read_data = read_data + 1;
}
}
return read_data;
}
static uint32 softSpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
{
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data);
uint8 cs_gpio_pin = dev_param->spi_slave_param->spi_cs_gpio_pin;
const uint8_t *data_buff = spi_datacfg->tx_buff;
int data_length = spi_datacfg->length;
if(NONE == spi_datacfg->tx_buff){
data_length = 0;
}
if (spi_datacfg->spi_chip_select) {
gpiohs_set_pin(cs_gpio_pin, GPIO_PV_LOW);
}
for(size_t i=0;i<data_length;i++){
soft_spi_writebyte(spi_dev,data_buff[i] );
}
if (spi_datacfg->spi_cs_release) {
gpiohs_set_pin(cs_gpio_pin, GPIO_PV_HIGH);
}
spi_datacfg = spi_datacfg->next;
return EOK;
}
static uint32 softSpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
{
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data);
uint8 cs_gpio_pin = dev_param->spi_slave_param->spi_cs_gpio_pin;
uint8_t *recv_buff = spi_datacfg->rx_buff;
int recv_length = spi_datacfg->length;
if(NONE == spi_datacfg->rx_buff){
recv_length = 0;
}
if (spi_datacfg->spi_chip_select) {
gpiohs_set_pin(cs_gpio_pin, GPIO_PV_LOW);
}
for(size_t i=0;i<recv_length;i++){
recv_buff[i] = soft_spi_readbyte(spi_dev);
}
if (spi_datacfg->spi_cs_release) {
gpiohs_set_pin(cs_gpio_pin, GPIO_PV_HIGH);
}
spi_datacfg = spi_datacfg->next;
return spi_datacfg->length;
}
const struct SpiDevDone soft_spi_dev_done={
.dev_close = NONE,
.dev_open = NONE,
.dev_read = softSpiReadData,
.dev_write = softSpiWriteData
};
static int BoardSoftSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver)
{
x_err_t ret = EOK;
/*Init the spi bus */
ret = SpiBusInit(spi_bus, SOFT_SPI_BUS_NAME);
if (EOK != ret) {
KPrintf("Board_Spi_init SpiBusInit error %d\n", ret);
return ERROR;
}
/*Init the spi driver*/
ret = SpiDriverInit(spi_driver, SOFT_SPI_DRV_NAME);
if (EOK != ret) {
KPrintf("Board_Spi_init SpiDriverInit error %d\n", ret);
return ERROR;
}
/*Attach the spi driver to the spi bus*/
ret = SpiDriverAttachToBus(SOFT_SPI_DRV_NAME, SOFT_SPI_BUS_NAME);
if (EOK != ret) {
KPrintf("Board_Spi_init SpiDriverAttachToBus error %d\n", ret);
return ERROR;
}
return ret;
}
static int BoardSoftSpiDevBend(void)
{
x_err_t ret = EOK;
static struct SpiHardwareDevice spi_device0;
memset(&spi_device0, 0, sizeof(struct SpiHardwareDevice));
static struct SpiSlaveParam spi_slaveparam0;
memset(&spi_slaveparam0, 0, sizeof(struct SpiSlaveParam));
spi_slaveparam0.spi_slave_id = SOFT_SPI_DEVICE_SLAVE_ID;
spi_slaveparam0.spi_cs_gpio_pin = SOFT_SPI_CS0_PIN;
spi_slaveparam0.spi_cs_select_id = SOFT_SPI_CHIP_SELECT;
spi_device0.spi_param.spi_dma_param = NONE;
spi_device0.spi_param.spi_slave_param = &spi_slaveparam0;
spi_device0.spi_dev_done = &(soft_spi_dev_done);
ret = SpiDeviceRegister(&spi_device0, (void *)(&spi_device0.spi_param), SOFT_SPI_DEVICE_NAME);
if (EOK != ret) {
KPrintf("Board_Spi_init SpiDeviceInit device %s error %d\n", SOFT_SPI_DEVICE_NAME, ret);
return ERROR;
}
ret = SpiDeviceAttachToBus(SOFT_SPI_DEVICE_NAME, SOFT_SPI_BUS_NAME);
if (EOK != ret) {
KPrintf("Board_Spi_init SpiDeviceAttachToBus device %s error %d\n", SOFT_SPI_DEVICE_NAME, ret);
return ERROR;
}
return ret;
}
int HwSoftSPIInit(void){
x_err_t ret = EOK;
static struct SpiBus spi_bus;
memset(&spi_bus, 0, sizeof(struct SpiBus));
static struct SpiDriver spi_driver;
memset(&spi_driver, 0, sizeof(struct SpiDriver));
spi_driver.configure = &(softSpiDrvConfigure);
ret = BoardSoftSpiBusInit(&spi_bus, &spi_driver);
if (EOK != ret) {
KPrintf("Board_Spi_Init error ret %u\n", ret);
return ERROR;
}
ret = BoardSoftSpiDevBend();
if (EOK != ret) {
KPrintf("Board_Spi_Init error ret %u\n", ret);
return ERROR;
}
return ret;
}

View File

@ -62,4 +62,7 @@ menuconfig KERNEL_TEST
config KERNEL_TEST_SPI_FLASH
bool "Config test spi flash"
default n
config KERNEL_TEST_SOFT_SPI_SD
bool "Config test soft spi sd"
default n
endif

View File

@ -92,4 +92,8 @@ ifeq ($(CONFIG_KERNEL_TEST_SPI_FLASH),y)
SRC_FILES += test_spi_flash.c
endif
ifeq ($(KERNEL_TEST_SOFT_SPI_SD),y)
SRC_FILES += test_softspi_sd.c
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -118,6 +118,8 @@ int TestMain(int argc, char*argv[])
#ifdef KERNEL_TEST_REALTIME
if (argc > 2)
TestRealtime(argc-2, &argv[2]);
#endif
#ifdef KERNEL_TEST_SOFT_SPI_SD
#endif
default:
break;

View File

@ -0,0 +1,105 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2016-09-28 armink first version.
*/
/**
* @file test_spi_flash.c
* @brief support to test spi flash function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-17
*/
/*************************************************
File name: test_spi_flash.c
Description: support spi flash function test
Others: add spi flash test cmd from SFUD/blob/master/demo/stm32f2xx_rtt/RT-Thread-2.1.0/components/drivers/spi/spi_flash_sfud.c
https://github.com/armink/SFUD/
History:
1. Date: 2021-05-17
Author: AIIT XUOS Lab
Modification:
1. support spi flash open, read and write function
*************************************************/
#include <xizi.h>
#include <device.h>
#include <bus.h>
// void SDpen(void)
// {
// x_err_t ret = EOK;
// ret=HwTFInit();
// if (ret < 0) {
// KPrintf("open spi flash fd error %d\n", ret);
// }
// KPrintf("Spi Flash init succeed\n");
// return;
// }
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
// SDpen, SDpen, open spi flash device);
// void SDRead(int argc, char *argv[])
// {
// x_err_t ret = EOK;
// }
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
// SDRead, SDRead, read data from spi flash device);
// void SDWrite(int argc, char *argv[])
// {
// x_err_t ret = EOK;
// x_size_t i, j = 0;
// uint32 addr;
// uint32 size;
// uint8 data[16];
// struct BusBlockWriteParam write_param;
// memset(&write_param, 0, sizeof(struct BusBlockWriteParam));
// memset(data, 0, 16);
// if (argc < 3) {
// KPrintf("FlashWrite cmd format: FlashWrite addr data.\n");
// return;
// } else {
// addr = strtol(argv[1], NULL, 0);
// size = argc - 2;
// write_param.buffer = data;
// write_param.pos = addr;
// write_param.size = size;
// if (data) {
// for (i = 0; i < size; i++) {
// data[i] = strtol(argv[2 + i], NULL, 0);
// }
// ret = write(spi_flash_fd, &write_param, size);
// if (EOK == ret) {
// KPrintf("Write the %s flash data success. Start from 0x%08X, size is %ld.\n",
// SPI_FLASH_PATH, addr, size);
// KPrintf("Write data: ");
// for (i = 0; i < size; i++) {
// KPrintf("%d ", data[i]);
// }
// KPrintf(".\n");
// }
// } else {
// KPrintf("SpiFlashWrite alloc write buffer failed!\n");
// }
// }
// }
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
// SDWrite, SDWrite, write data to spi flash device);

View File

@ -164,7 +164,6 @@ void EnvInitKTask(void *parameter)
_InitSubCmpts(components_init);
_InitSubCmpts(env_init);
ENABLE_INTERRUPT(lock);
_InitSubCmpts(communication_init);
#ifdef ARCH_SMP

View File

@ -28,11 +28,11 @@
extern "C" {
#endif
#define SPI_SD_FREQUENCY 400000
#define SPI_SD_FREQUENCY 400000
#define SPI_SD_TIMEOUT_NUM 100
#define SD_CMD_RESPONE_LENGTH 5
#define SD_CMD_CSD_LENGTH 16
#define SD_BLOCK_LENGTH 512
#define SD_BLOCK_LENGTH 512
#define SD_TIMEOUT(cnt, time) \
do \

View File

@ -96,9 +96,8 @@ static uint32 SdSendCmdByte(SpiSdDeviceType spi_sd_dev, struct SdCmdParam *sd_cm
if ((SD_CMD_17 == sd_cmd_param->sd_cmd_type) || (SD_CMD_18 == sd_cmd_param->sd_cmd_type)) {
MdelayKTask(100);
}
SD_TIMEOUT(start_time, 2 * SPI_SD_TIMEOUT_NUM);
}while((0 != (read[0] & 0x80)));
}while(0 != (read[0] & 0x80));
switch (sd_cmd_param->sd_respone_type)
{
@ -672,7 +671,7 @@ static uint32 SdHwReadCSD(SpiSdDeviceType spi_sd_dev)
g_sd_cmd_param.sd_cmd_type = SD_CMD_9;
g_sd_cmd_param.sd_cmd_args = 0x00;
g_sd_cmd_param.sd_cmd_crc = 0x00;
g_sd_cmd_param.sd_respone_type = SD_RESPONE_2;
g_sd_cmd_param.sd_respone_type = SD_RESPONE_1;
/*pull down the cs pin*/
SpiDevConfigureCs(&spi_sd_dev->spi_dev->haldev, 1, 0);
@ -691,7 +690,7 @@ static uint32 SdHwReadCSD(SpiSdDeviceType spi_sd_dev)
if (0xFE != g_sd_cmd_param.sd_respone_data[1]) {
/*Step2 : SPI write data 0xFF until read 0xFE*/
uint8 data = 0xFF;
uint8 read_spi;
uint8 read_spi=0x00;
uint32 start_time;
write_param.buffer = (void *)&data;
@ -705,7 +704,6 @@ static uint32 SdHwReadCSD(SpiSdDeviceType spi_sd_dev)
{
BusDevWriteData(&spi_sd_dev->spi_dev->haldev, &write_param);
BusDevReadData(&spi_sd_dev->spi_dev->haldev, &read_param);
SD_TIMEOUT(start_time, 10 * SPI_SD_TIMEOUT_NUM);
}while(0xFE != read_spi);
}
@ -768,7 +766,7 @@ static uint32 SdReadSingleBlock(SpiSdDeviceType spi_sd_dev, uint32 id, uint8 *re
return ERROR;
}
/*Step2 : SPI write data 0xFF until read 0xFE*/
/*Step2 : SPI read until 0xFE*/
uint8 data = 0xFF;
uint8 read[2];
uint32 start_time;
@ -782,7 +780,6 @@ static uint32 SdReadSingleBlock(SpiSdDeviceType spi_sd_dev, uint32 id, uint8 *re
do
{
BusDevWriteData(&spi_sd_dev->spi_dev->haldev, &write_param);
BusDevReadData(&spi_sd_dev->spi_dev->haldev, &read_param);
SD_TIMEOUT(start_time, 100 * SPI_SD_TIMEOUT_NUM);
@ -1077,6 +1074,7 @@ static uint32 SdWriteMultiBlock(SpiSdDeviceType spi_sd_dev, uint32 id, const voi
}
/*Step8 : SPI write 0xFD, multi block write data done*/
data = 0xFD;
write_param.buffer = (void *)&data;
write_param.size = 1;
BusDevWriteData(&spi_sd_dev->spi_dev->haldev, &write_param);