www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁(yè) > > 嵌入式技術(shù)開發(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卡讀寫的相關(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移植 底層讀寫函數(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;}
寫函數(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)判斷寫操作是否完成 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)文件的讀寫了,測(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)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

《帶得走的智能制造》暑期課程圓滿落幕 北京2025年7月25日 /美通社/ -- 近日,由國(guó)際獨(dú)立第三方檢測(cè)、檢驗(yàn)和認(rèn)證機(jī)構(gòu)德國(guó)萊茵TÜV大中華區(qū)(以下簡(jiǎn)稱"TÜV萊茵")與北京...

關(guān)鍵字: 智能制造 BSP DMA 信息安全

在實(shí)時(shí)控制系統(tǒng)、高速通信協(xié)議處理及高精度數(shù)據(jù)采集等對(duì)時(shí)間敏感的應(yīng)用場(chǎng)景中,中斷響應(yīng)延遲的優(yōu)化直接決定了系統(tǒng)的可靠性與性能上限。STM32系列微控制器憑借其靈活的嵌套向量中斷控制器(NVIC)、多通道直接內(nèi)存訪問(wèn)(DMA)...

關(guān)鍵字: STM32 DMA

在嵌入式系統(tǒng)、網(wǎng)絡(luò)通信等對(duì)數(shù)據(jù)傳輸效率要求極高的場(chǎng)景中,零拷貝技術(shù)能夠顯著減少數(shù)據(jù)在內(nèi)存中的拷貝次數(shù),降低CPU負(fù)載,提高系統(tǒng)性能。DMA(直接內(nèi)存訪問(wèn))環(huán)形緩沖區(qū)與內(nèi)存池相結(jié)合的雙重優(yōu)化策略,為實(shí)現(xiàn)高效的零拷貝數(shù)據(jù)傳輸...

關(guān)鍵字: 零拷貝 DMA 嵌入式系統(tǒng)

STM32單片機(jī)憑借其高性能、低功耗、豐富的外設(shè)資源等優(yōu)勢(shì),在工業(yè)控制、消費(fèi)電子、汽車電子等領(lǐng)域得到了廣泛應(yīng)用。在嵌入式系統(tǒng)開發(fā)中,高效的數(shù)據(jù)處理和傳輸至關(guān)重要。中斷技術(shù)和DMA技術(shù)作為STM32單片機(jī)中重要的數(shù)據(jù)處理和...

關(guān)鍵字: STM32 DMA

在嵌入式系統(tǒng)中,隨著數(shù)據(jù)量的不斷增加和實(shí)時(shí)性要求的提高,傳統(tǒng)的CPU直接控制數(shù)據(jù)傳輸?shù)姆绞街饾u暴露出效率低下的問(wèn)題。為了應(yīng)對(duì)這一挑戰(zhàn),直接內(nèi)存訪問(wèn)(Direct Memory Access,DMA)技術(shù)應(yīng)運(yùn)而生,成為實(shí)現(xiàn)...

關(guān)鍵字: DMA 嵌入式系統(tǒng) 高速數(shù)據(jù)傳輸

廣州2025年1月21日 /美通社/ -- 在數(shù)字營(yíng)銷領(lǐng)域快速發(fā)展的今天,每一場(chǎng)行業(yè)盛會(huì)都預(yù)示著新的轉(zhuǎn)折與機(jī)遇。2025年1月10日,由DMAA數(shù)字營(yíng)銷獎(jiǎng)主辦,廣州4A聯(lián)合主辦,廣州市廣告行業(yè)協(xié)會(huì)指導(dǎo)的第八屆DMAA國(guó)際...

關(guān)鍵字: DMA AI AI技術(shù) 創(chuàng)始人

在現(xiàn)代計(jì)算機(jī)系統(tǒng)中,直接內(nèi)存訪問(wèn)(DMA)技術(shù)被廣泛應(yīng)用于高速數(shù)據(jù)傳輸,其核心理念在于讓數(shù)據(jù)傳輸不再依賴CPU的參與,從而釋放CPU資源以處理其他任務(wù)。然而,在DMA操作完成后,系統(tǒng)需要一種機(jī)制來(lái)檢測(cè)DMA傳輸是否已完成...

關(guān)鍵字: DMA CPU 輪詢檢測(cè)

之前有個(gè)同事因?yàn)橛么诓樵兎绞桨l(fā)送數(shù)據(jù),被我說(shuō)了一頓,明明有DMA資源,竟然放著不用,對(duì)于魚鷹這種性能強(qiáng)迫癥來(lái)說(shuō),肯定無(wú)法忍受,所以當(dāng)時(shí)就和他說(shuō),有時(shí)間你把它改一下。誰(shuí)知道過(guò)了好幾個(gè)月他才有時(shí)間弄這個(gè),然后還是出了問(wèn)題,...

關(guān)鍵字: DMA 串口

UART(Universal Asynchronous Receiver/Transmitter,通用異步收發(fā)器)是一種常用的串行通信協(xié)議,廣泛應(yīng)用于單片機(jī)或各種嵌入式設(shè)備之間的通信。

關(guān)鍵字: UART DMA

轉(zhuǎn)移數(shù)據(jù)(尤其是轉(zhuǎn)移大量數(shù)據(jù))是可以不需要CPU參與。比如希望外設(shè)A的數(shù)據(jù)拷貝到外設(shè)B,

關(guān)鍵字: CPU DMA 數(shù)據(jù)通路
關(guān)閉