日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > > 嵌入式技術(shù)開(kāi)發(fā)
[導(dǎo)讀]SWM32S單片機(jī)有1個(gè)SDIO接口,支持多媒體卡(MMC)、SD 存儲(chǔ)卡、SDIO 卡等設(shè)備,可以使用軟件方法或者 DMA 方法(SDIO 模塊內(nèi)部 DMA,與芯片 DMA 模塊無(wú)關(guān))進(jìn)行數(shù)據(jù)傳輸。

SWM32S單片機(jī)有1個(gè)SDIO接口,支持多媒體卡(MMC)、SD 存儲(chǔ)卡、SDIO 卡等設(shè)備,可以使用軟件方法或者 DMA 方法(SDIO 模塊內(nèi)部 DMA,與芯片 DMA 模塊無(wú)關(guān))進(jìn)行數(shù)據(jù)傳輸。其特點(diǎn)如下:



1.SDIO配置 SDIO的引腳不像UART和SPI等數(shù)字外設(shè)一樣可以靈活配置,它是固定的幾個(gè)引腳,如下圖 使用起來(lái)也比較簡(jiǎn)單,相關(guān)的庫(kù)函數(shù)已經(jīng)封裝好了,直接調(diào)用就行。 首先需要配置一下相關(guān)引腳的復(fù)用功能為SDIO:
 PORT_Init(PORTB, PIN1, PORTB_PIN1_SD_CLK, 0); PORT_Init(PORTB, PIN2, PORTB_PIN2_SD_CMD, 1); PORT_Init(PORTB, PIN3, PORTB_PIN3_SD_D0,  1); PORT_Init(PORTB, PIN4, PORTB_PIN4_SD_D1,  1); PORT_Init(PORTB, PIN5, PORTB_PIN5_SD_D2,  1); PORT_Init(PORTB, PIN6, PORTB_PIN6_SD_D3,  1);

然后直接調(diào)用初始化的函數(shù)就行:
result = SDIO_Init(10000000);

其中形參為SDIO的時(shí)鐘頻率。 SD卡讀寫(xiě)的相關(guān)函數(shù)也已經(jīng)封裝好了,包括DMA和非DMA方式,直接調(diào)用即可:
uint32_t SDIO_BlockWrite(uint32_t block_addr, uint32_t buff[]);uint32_t SDIO_BlockRead(uint32_t block_addr, uint32_t buff[]);uint32_t SDIO_MultiBlockWrite(uint32_t block_addr, uint16_t block_cnt, uint32_t buff[]);uint32_t SDIO_MultiBlockRead(uint32_t block_addr, uint16_t block_cnt, uint32_t buff[]);uint32_t SDIO_DMABlockWrite(uint32_t block_addr, uint16_t block_cnt, uint32_t buff[]);uint32_t SDIO_DMABlockRead(uint32_t block_addr, uint16_t block_cnt, uint32_t buff[]);



2.FatFs移植 底層讀寫(xiě)函數(shù)有了以后,移植FatFs也就比較簡(jiǎn)單了,首先將FatFs的相關(guān)文件添加到工程中: 我們需要實(shí)現(xiàn)的接口函數(shù)在diskio.c文件中,包括至少以下3個(gè)函數(shù): 初始化函數(shù),直接將端口配置、SDIO初始化添加到該函數(shù)中:
DSTATUS disk_initialize ( BYTE pdrv        /* Physical drive nmuber to identify the drive */){ DSTATUS stat; int result;  switch (pdrv) { case DEV_RAM : //result = RAM_disk_initialize(); // translate the reslut code here stat = STA_NOINIT; return stat; case DEV_MMC : //result = MMC_disk_initialize(); // translate the reslut code here PORT_Init(PORTB, PIN1, PORTB_PIN1_SD_CLK, 0); PORT_Init(PORTB, PIN2, PORTB_PIN2_SD_CMD, 1); PORT_Init(PORTB, PIN3, PORTB_PIN3_SD_D0,  1); PORT_Init(PORTB, PIN4, PORTB_PIN4_SD_D1,  1); PORT_Init(PORTB, PIN5, PORTB_PIN5_SD_D2,  1); PORT_Init(PORTB, PIN6, PORTB_PIN6_SD_D3,  1);  result = SDIO_Init(10000000); if(result == SD_RES_OK) { stat = RES_OK; sd_initialized = 1; } else { stat = STA_NOINIT; sd_initialized = 0; } return stat; case DEV_USB : //result = USB_disk_initialize(); // translate the reslut code here stat = STA_NOINIT; return stat; } return STA_NOINIT;}
讀函數(shù)
DRESULT disk_read ( BYTE pdrv,    /* Physical drive nmuber to identify the drive */ BYTE *buff,    /* Data buffer to store read data */ LBA_t sector,  /* Start sector in LBA */ UINT count    /* Number of sectors to read */){ DRESULT res; int result;  switch (pdrv) { case DEV_RAM : // translate the arguments here //result = RAM_disk_read(buff, sector, count); // translate the reslut code here res = RES_PARERR; return res; case DEV_MMC :  if(count == 1) { result = SDIO_BlockRead(sector, (uint32_t *)buff); } else { //result = SDIO_MultiBlockRead(sector, count, (uint32_t *)buff); result = SDIO_DMABlockRead(sector, count, (uint32_t *)buff);//使用DMA或非DMA模式均可 }  if(result == SD_RES_OK) res = RES_OK; else res = RES_ERROR;  return res; case DEV_USB : // translate the arguments here //result = USB_disk_read(buff, sector, count); // translate the reslut code here  res = RES_PARERR; return res; } return RES_PARERR;}
寫(xiě)函數(shù)
DRESULT disk_write ( BYTE pdrv,      /* Physical drive nmuber to identify the drive */ const BYTE *buff,  /* Data to be written */ LBA_t sector,    /* Start sector in LBA */ UINT count      /* Number of sectors to write */){ DRESULT res; int result;  switch (pdrv) { case DEV_RAM : // translate the arguments here //result = RAM_disk_write(buff, sector, count); // translate the reslut code here res = RES_PARERR; return res; case DEV_MMC : if(count == 1) { result = SDIO_BlockWrite(sector, (uint32_t *)buff); } else { //result = SDIO_MultiBlockWrite(sector, count, (uint32_t *)buff); result = SDIO_DMABlockWrite(sector, count, (uint32_t *)buff);//使用DMA或非DMA模式均可 } if(result == SD_RES_OK) res = RES_OK; else res = RES_ERROR; return res; case DEV_USB : // translate the arguments here //result = USB_disk_write(buff, sector, count); // translate the reslut code here res = RES_PARERR; return res; } return RES_PARERR;}
還有一個(gè)函數(shù)是用戶獲取SD卡容量等信息的,如下:
DRESULT disk_ioctl ( BYTE pdrv,    /* Physical drive nmuber (0..) */ BYTE cmd,    /* Control code */ void *buff    /* Buffer to send/receive control data */){ DRESULT res; //int result;  switch (pdrv) { case DEV_RAM : // Process of the command for the RAM drive res = RES_PARERR; return res; case DEV_MMC : switch ( cmd )  {      //fatfs內(nèi)核使用cmd調(diào)用 case GET_SECTOR_COUNT:  //sector count *(DWORD*)buff = SD_cardInfo.CardCapacity / 512; return RES_OK; case GET_SECTOR_SIZE:  //sector size, 傳入block size(SD),單位bytes *(DWORD*)buff = 512; return RES_OK; case GET_BLOCK_SIZE:  //block size, 由上文可得,對(duì)于SD2.0卡最大8192,最小 1 *(DWORD*)buff = 1;  //單位為 sector(FatFs) return RES_OK; case CTRL_SYNC:      //同步命令,貌似FatFs內(nèi)核用來(lái)判斷寫(xiě)操作是否完成 return RES_OK; } res = RES_OK; return res; case DEV_USB : // Process of the command the USB drive res = RES_PARERR; return res; } return RES_PARERR;}
接口部分實(shí)現(xiàn)后,就可以調(diào)用相關(guān)的函數(shù)實(shí)現(xiàn)文件的讀寫(xiě)了,測(cè)試程序如下:
res = f_mount(&fatfs, "sd:", 1);if(res != FR_OK){ printf("sdcard init fail!\r\n");}res = f_open(&filw, "sd:test.txt", FA_CREATE_ALWAYS | FA_WRITE);if(res != FR_OK){ printf("create file fail!\r\n");}res = f_write(&filw, str, strlen(str), &len);if(res != FR_OK){ printf("write file fail!\r\n");}f_close(&filw);

文件系統(tǒng)的配置可以在"ffconf.h"文件中根據(jù)實(shí)際需求進(jìn)行修改。

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專(zhuān)欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀

特朗普集團(tuán)近日取消了其新推出的T1智能手機(jī)“將在美國(guó)制造”的宣傳標(biāo)語(yǔ),此舉源于外界對(duì)這款手機(jī)能否以當(dāng)前定價(jià)在美國(guó)本土生產(chǎn)的質(zhì)疑。

關(guān)鍵字: 特朗普 蘋(píng)果 AI

美國(guó)總統(tǒng)特朗普在公開(kāi)場(chǎng)合表示,他已要求蘋(píng)果公司CEO蒂姆·庫(kù)克停止在印度建廠,矛頭直指該公司生產(chǎn)多元化的計(jì)劃。

關(guān)鍵字: 特朗普 蘋(píng)果 AI

4月10日消息,據(jù)媒體報(bào)道,美國(guó)總統(tǒng)特朗普宣布,美國(guó)對(duì)部分貿(mào)易伙伴暫停90天執(zhí)行新關(guān)稅政策,同時(shí)對(duì)中國(guó)的關(guān)稅提高到125%,該消息公布后蘋(píng)果股價(jià)飆升了15%。這次反彈使蘋(píng)果市值增加了4000多億美元,目前蘋(píng)果市值接近3萬(wàn)...

關(guān)鍵字: 特朗普 AI 人工智能 特斯拉

3月25日消息,據(jù)報(bào)道,當(dāng)?shù)貢r(shí)間3月20日,美國(guó)總統(tǒng)特朗普在社交媒體平臺(tái)“真實(shí)社交”上發(fā)文寫(xiě)道:“那些被抓到破壞特斯拉的人,將有很大可能被判入獄長(zhǎng)達(dá)20年,這包括資助(破壞特斯拉汽車(chē))者,我們正在尋找你?!?/p> 關(guān)鍵字: 特朗普 AI 人工智能 特斯拉

1月22日消息,剛剛,新任美國(guó)總統(tǒng)特朗普放出重磅消息,將全力支持美國(guó)AI發(fā)展。

關(guān)鍵字: 特朗普 AI 人工智能

特朗普先生有兩件事一定會(huì)載入史冊(cè),一個(gè)是筑墻,一個(gè)是挖坑。在美墨邊境筑墻的口號(hào)確保邊境安全,降低因非法移民引起的犯罪率過(guò)高問(wèn)題;在中美科技產(chǎn)業(yè)之間挖坑的口號(hào)也是安全,美國(guó)企業(yè)不得使用對(duì)美國(guó)國(guó)家安全構(gòu)成威脅的電信設(shè)備,總統(tǒng)...

關(guān)鍵字: 特朗普 孤立主義 科技產(chǎn)業(yè)

據(jù)路透社1月17日消息顯示,知情人士透露,特朗普已通知英特爾、鎧俠在內(nèi)的幾家華為供應(yīng)商,將要撤銷(xiāo)其對(duì)華為的出貨的部分許可證,同時(shí)將拒絕其他數(shù)十個(gè)向華為供貨的申請(qǐng)。據(jù)透露,共有4家公司的8份許可被撤銷(xiāo)。另外,相關(guān)公司收到撤...

關(guān)鍵字: 華為 芯片 特朗普

曾在2018年時(shí)被美國(guó)總統(tǒng)特朗普稱(chēng)作“世界第八奇跡”的富士康集團(tuán)在美國(guó)威斯康星州投資建設(shè)的LCD顯示屏工廠項(xiàng)目,如今卻因?yàn)楦皇靠祵㈨?xiàng)目大幅縮水并拒絕簽訂新的合同而陷入了僵局。這也導(dǎo)致富士康無(wú)法從當(dāng)?shù)卣抢铽@得約40億美...

關(guān)鍵字: 特朗普 富士康

今年5月,因自己發(fā)布的推文被貼上“無(wú)確鑿依據(jù)”標(biāo)簽而與推特發(fā)生激烈爭(zhēng)執(zhí)后,美國(guó)總統(tǒng)特朗普簽署了一項(xiàng)行政令,下令要求重審《通信規(guī)范法》第230條。

關(guān)鍵字: 谷歌 facebook 特朗普

眾所周知,寄往白宮的所有郵件在到達(dá)白宮之前都會(huì)在他地進(jìn)行分類(lèi)和篩選。9月19日,根據(jù)美國(guó)相關(guān)執(zhí)法官員的通報(bào),本周早些時(shí)候,執(zhí)法人員截獲了一個(gè)寄給特朗普總統(tǒng)的包裹,該包裹內(nèi)包含蓖麻毒蛋白。

關(guān)鍵字: 美國(guó) 白宮 特朗普
關(guān)閉