Kendryte K210 在freertos上的SD卡的使用

首先修改project_cfg.h文件,将硬件定义好的i2c引脚定义好,如下:

const fpioa_cfg_t g_fpioa_cfg =
{
    .version = PIN_CFG_VERSION,
    .functions_count = 4,
    .functions =
    {
        {32, FUNC_GPIOHS0 + TF_CS_GPIONUM},
        {29, FUNC_SPI0_SCLK},
        {30, FUNC_SPI0_D0},
        {31, FUNC_SPI0_D1},
    }
};

然后在主函数里的如下:

handle_t install_sdcard()
{
    handle_t spi, gpio;
    configASSERT(spi = io_open("/dev/spi0"));
    configASSERT(gpio = io_open("/dev/gpio0"));
    handle_t sd0 = spi_sdcard_driver_install(spi, gpio, 7);
    io_close(spi);
    io_close(gpio);
    return sd0;
}
    printf("Hello sd\n");
    char msg[]="k233333333333333333";
    char buffer[32];
    handle_t sd0 = install_sdcard();
    configASSERT(sd0);
    configASSERT(filesystem_mount("/fs/0/", sd0) == 0);
    io_close(sd0);
/************************* test find file************************************/
    find_find_data_t find_data;
    handle_t find = filesystem_find_first("/fs/0/", "*", &find_data);
    configASSERT(find);
    do
    {
        printf("%s\n", find_data.filename);
    } while (filesystem_find_next(find, &find_data));
    filesystem_file_close(find);
    printf("Done\n");
/************************* test syscalls ************************************/
    FILE *stream;
    if((stream=fopen("/fs/0/test_syscalls.txt","w+"))==NULL)
    {
        fprintf(stderr,"Can not open file.\n");
        exit(-1);
    }
    fwrite(msg, 1, strlen(msg)+1, stream);
    fseek(stream,0,SEEK_SET);
    fread(buffer, 1, strlen(msg)+1, stream);
    printf("test syscalls buffer : %s\n", buffer);
    fclose(stream);
    while (1)
        ;

 

你可能感兴趣的:(Kendryte,K210)