去年搞了一年的算法,今年终于得空继续学学PYNQ,参考了网上的例子,发现发现SD卡读写是如此简单。

第一步:在zynq中接口设置中选中SD卡,在pynq的默认配置中已经选中SD卡,所以这里不需要任何操作。

第二步:在SDK中添加xilffs库

第三步:添加函数文件sd.c

/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************//** helloworld.c: simple test application** This application configures UART 16550 to baud rate 9600.* PS7 UART (Zynq) is not initialized by this application, since* bootrom/bsp configures it to baud rate 115200** ------------------------------------------------* | UART TYPE   BAUD RATE                        |* ------------------------------------------------*   uartns550   9600*   uartlite    Configurable only in HW design*   ps7_uart    115200 (configured by bootrom/bsp)*/#include "sd.h"int SD_Init()
{FRESULT rc;rc = f_mount(&fatfs,"",0);if(rc){xil_printf("ERROR: f_mount returned %d\r\n",rc);return XST_FAILURE;}return XST_SUCCESS;
}int SD_Transfer_read(char *FileName,u32 DestinationAddress,u32 ByteLength)
{FIL fil;FRESULT rc;UINT br;rc=f_open(&fil,FileName,FA_READ);if(rc){xil_printf("ERROR:f_open returned %d\r\n",rc);return XST_FAILURE;}rc = f_lseek(&fil,0);if(rc){xil_printf("ERROR:f_open returned %d\r\n",rc);return XST_FAILURE;}rc = f_read(&fil,(void*)DestinationAddress,ByteLength,&br);if(rc){xil_printf("ERROR:f_open returned %d\r\n",rc);return XST_FAILURE;}rc = f_close(&fil);if(rc){xil_printf("ERROR:f_open returned %d\r\n",rc);return XST_FAILURE;}return XST_SUCCESS;
}int SD_Transfer_write(char *FileName,u32 SourceAddress,u32 ByteLength)
{FIL fil;FRESULT rc;UINT bw;rc = f_open(&fil,FileName,FA_CREATE_ALWAYS | FA_WRITE);if(rc){xil_printf("ERROR : f_open returned %d\r\n",rc);return XST_FAILURE;}rc = f_lseek(&fil, 0);if(rc){xil_printf("ERROR : f_lseek returned %d\r\n",rc);return XST_FAILURE;}rc = f_write(&fil,(void*) SourceAddress,ByteLength,&bw);if(rc){xil_printf("ERROR : f_write returned %d\r\n", rc);return XST_FAILURE;}rc = f_close(&fil);if(rc){xil_printf("ERROR : f_close returned %d\r\n",rc);return XST_FAILURE;}return XST_SUCCESS;
}

头文件:

/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************//** helloworld.c: simple test application** This application configures UART 16550 to baud rate 9600.* PS7 UART (Zynq) is not initialized by this application, since* bootrom/bsp configures it to baud rate 115200** ------------------------------------------------* | UART TYPE   BAUD RATE                        |* ------------------------------------------------*   uartns550   9600*   uartlite    Configurable only in HW design*   ps7_uart    115200 (configured by bootrom/bsp)*/#include "platform.h"
#include "xparameters.h"
#include "xil_printf.h"
#include "ff.h"
#include "xdevcfg.h"
static FATFS fatfs;int SD_Init();int SD_Transfer_read(char *FileName,u32 DestinationAddress,u32 ByteLength);int SD_Transfer_write(char *FileName,u32 SourceAddress,u32 ByteLength);

第四步:调用测试

main函数如下所示:

#define FILE "test.txt"int main()
{init_platform();int rc;const char src_str[] = "hsp test sd card write and read!";u32 len = strlen(src_str);rc = SD_Init();if(XST_SUCCESS != rc){xil_printf("fail to open SD Card~\n\r");}else{xil_printf("success to open SD Card~\n\r");}rc = SD_Transfer_write(FILE,(u32)src_str,(len/256+1)*256);xil_printf("%d",(len/256+1)*256);if(XST_SUCCESS != rc){xil_printf("fail to write SD Card~\n\r");}else{xil_printf("success to write SD Card~\n\r");}char dest_str[33];rc = SD_Transfer_read(FILE,(u32)dest_str,(len+1));if(XST_SUCCESS != rc){xil_printf("fail to read SD Card~\n\r");}else{xil_printf("success to read SD Card~\n\r");}xil_printf("%s\r\n",dest_str);printf("SD Card Write and Read Success~");cleanup_platform();return 0;}

调用注意事项为:有时候重新编译报错,需要重新添加xilffs库。

PYNQ裸跑之读写SD卡相关推荐

  1. 单片机读tf卡c语言程序,单片机读写SD卡,MMC卡,MiniSD,TF卡,MicroSD卡

    图一 一:系统构成: 1:89C51单片机(ISP 单片机,可不用编程器) 2:128x64LCD 3: 带SD ,MiniSD ,MicroSD(TFSD)卡座 送32MByte SD卡 4:支持红 ...

  2. stm32 Fatfs 读写SD卡

    源:stm32 Fatfs 读写SD卡 转载于:https://www.cnblogs.com/LittleTiger/p/4864052.html

  3. STM32开发板入门教程(十三) - SPI模式读写SD卡

    功能介绍 :使用SPI模式 读写SD卡block数据 可通过串口发送到PC机查看 SD卡是Secure Digital Card卡的简称,直译成汉语就是"安全数字卡",是由日本松下 ...

  4. android 数据持久化——读写SD卡中的内容

    在前面讲的那三个方法:openFileOutput .openFileInput 虽然都能通过流对象OutputStream和InputStream可以处理任意文件中的数据,但与SharedPrefe ...

  5. android 清空数组缓存,Android数据持久化之读写SD卡中内容的方法详解

    本文实例讲述了Android数据持久化之读写SD卡中内容的方法.分享给大家供大家参考,具体如下: 前面文章里讲的那三个方法:openFileOutput.openFileInput虽然都能通过流对象O ...

  6. SDIO读写SD卡速度有多快?

    前两天测试了SPI方式读写SD卡的速度<SPI方式读写SD卡速度测试>,今天来测试一下SDIO方式的读写速度. 测试条件: 单片机:STM32F407VET6 编译环境:MDK 5.30+ ...

  7. STM32CubeMX+SPI+FATFS读写SD卡

    一.软件硬件说明 软件:STM32CubeMX V6.6.1 /KEIL5 V5.29 硬件:正点原子mini开发板,SD卡,通过SPI方式驱动SD卡,用的是SPI1接口 以上内容来源于正点原子min ...

  8. STM32利用SPI读写SD卡的程序详解

    STM32利用SPI读写SD卡的一些程序详解 关于SD卡的基础知识这里不做过多陈述,如果有对这方面感兴趣的朋友可以直接百度一下,有很多讲SD卡的文章,这里主要是针对SD卡的读写程序实现做一些详细说明. ...

  9. STM32CUBEMX_SDIO和FATFS_读写SD卡

    STM32CUBEMX_SDIO和FATFS_读写SD卡 简述 FATFS是一个完全免费开源,专为小型嵌入式系统设计的FAT(File Allocation Table)文件系统模块.FATFS的编写 ...

最新文章

  1. linux进程间通信-XSI IPC
  2. 组装计算机的游戏,如何组装一台游戏电脑
  3. 演示:配置日志发送到VTY虚拟终端线路
  4. mysql upgrade help_【MySQL学生手册】MySQL的升级
  5. java窗口how2j_HOW2J java文件的创建及常用方法
  6. tomcat启动停止在 Initializing Spring root WebApplicationContext,就不运行了
  7. Qt文档阅读笔记-C++与QML混合编程(QML画饼状图)【通过信号与槽交互】
  8. Airflow 中文文档:用Dask扩展
  9. dnf搬砖代码Python_DNF:95版本搬砖角色怎么提高移速,不花钱就花时间吧
  10. 电瓶车续航测试软件,【电驹视频】实测13款电动车真实续航,最靠谱的竟然是它……...
  11. Nebula3渲染层: Graphics
  12. 01-简单的基于SVM的SAR海冰分离-Arcgis制作数据集标签
  13. 浪潮 服务器数据安全管理系统,浪潮SSC运维安全管控系统
  14. java 实验室预约系统_基于Java的实验室预约管理系统
  15. android手机截图功能,手机截屏怎么弄?安卓手机怎么截屏?
  16. Pytroch相关操作(1)
  17. python绘制箭头_python如何绘制坐标箭头?
  18. [乐意黎原创]访问Centos下Apache主机页面抛You don't have permission to access / on this server.
  19. 财政分权数据集:省级地级市财政分权度(1999-2021年)
  20. 【 线性回归 Linear-Regression torch模块实现与源码详解 深度学习 Pytorch笔记 B站刘二大人(4/10)】

热门文章

  1. 数据中心液冷方式优缺点对比及浸没式液冷表面强化处理
  2. 谈学习中的改变——有病要诊断,有药要服用
  3. 一个python+flask和SQLite的数字查找以及Dataload命令生成的小工具
  4. 一个3D车道线检测方法PersFormer及其开源OpenLane数据集
  5. 一种根据EI检索结果对比CCF期刊/会议评级的程序
  6. ios 按钮点击无反应
  7. 2018年度最优秀mac软件及游戏推荐,个个万里挑一
  8. echarts 桑基图sankey
  9. Android图片压缩、加水印
  10. 《枪炮、病菌与钢铁》之一