関連記事
「[SDIO] SDIO、SDカード、FatFsファイルシステムに関連する記事の索引」
1. STM32SDIO機能ブロック図
STM32コントローラーにはSDIOがあり、次の図に示すように、SDIOアダプターとAPB2インターフェースの2つの部分で構成されています。SDIOアダプタはSDIOホスト機能を提供し、SDクロックを提供し、コマンドを送信し、データ送信を実行できます。APB2インターフェイスは、コントローラーがSDIOアダプターレジスタにアクセスするために使用し、割り込みとDMA要求信号を生成できます。2つのクロック信号を使用するSDIO。クロックはSDIOアダプター(SDIOCLK = 48MHz)、もう1つはAPB2バスクロック(PCLK2、通常は90MHz )です。
STM32コントローラーのSDIOはMMCカードとSDカードのメインデバイスであるため、8本のデータラインが予約され、最大4本のデータラインがSDカードに使用されます。
SDIOアダプターは5つのユニットで構成されています。つまり:(以下に表示)
- コントロールユニット
- コマンドパスユニット
- データパスユニット
- レジスタユニット
- FIFO
2. STM32SDカードのハードウェア設計
STM32コントローラのSDIOピンは固定するように設計されており、開発ボードの設計は4データラインモードを採用しています。コマンドラインとデータラインにプルアップ抵抗を追加する必要があります。
3.SDカードの読み取りと書き込みのテスト移行
SDカードの読み書きテストをSTM32プラットフォームに移植するのは比較的簡単です。移植用の標準ライブラリにあるSDIOデモを直接参照できます。といった:STM32F4xx_DSP_StdPeriph_Lib_V1.8.0\Project\STM32F4xx_StdPeriph_Examples\SDIO\SDIO_uSDCard
- され
stm324x9i_eval_sdio_sd.c
、それが提供する、現在のプロジェクトに移植SD_Init() 、SD_WriteBlock()とSD_ReadBlock()と私たちが直接使用することができ、他のSDカードの動作機能を、。
- 書き込み
sd_test.c
ファイルは、SDカードを実現するための消去テスト、単一ブロック書き込み動作テストおよびマルチブロックライト動作テストを。
/**
* @brief Configures SDIO IRQ channel.
* @param None
* @retval None
*/
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief Tests the SD card erase operation.
* @param None
* @retval None
*/
static void SD_EraseTest(void)
{
printf("\r\n---->Erase test is starting...\r\n");
/*------------------- Block Erase ------------------------------------------*/
if (Status == SD_OK)
{
/* Erase NumberOfBlocks Blocks of WRITE_BL_LEN(512 Bytes) */
Status = SD_Erase(0x00, (BLOCK_SIZE * NUMBER_OF_BLOCKS));
}
if (Status == SD_OK)
{
Status = SD_ReadMultiBlocks(aBuffer_MultiBlock_Rx, 0x00, BLOCK_SIZE, NUMBER_OF_BLOCKS);
/* Check if the Transfer is finished */
Status = SD_WaitReadOperation();
/* Wait until end of DMA transfer */
while(SD_GetStatus() != SD_TRANSFER_OK);
}
/* Check the correctness of erased blocks */
if (Status == SD_OK)
{
EraseStatus = eBuffercmp(aBuffer_MultiBlock_Rx, MULTI_BUFFER_SIZE);
}
if(EraseStatus == PASSED)
{
LED1(ON);
printf("\tThe earase is successful.\r\n");
}
else
{
LED1(OFF);
LED3(ON);
printf("\tThe earase is fail!!!\r\n");
}
printf("<----Erase test is end.\r\n");
}
/**
* @brief Tests the SD card Single Blocks operations.
* @param None
* @retval None
*/
static void SD_SingleBlockTest(void)
{
printf("\r\n---->Single block test is starting...\r\n");
/*------------------- Block Read/Write --------------------------*/
/* Fill the buffer to send */
Fill_Buffer(aBuffer_Block_Tx, BLOCK_SIZE, 0x320F);
if (Status == SD_OK)
{
/* Write block of 512 bytes on address 0 */
Status = SD_WriteBlock(aBuffer_Block_Tx, 0x00, BLOCK_SIZE);
/* Check if the Transfer is finished */
Status = SD_WaitWriteOperation();
while(SD_GetStatus() != SD_TRANSFER_OK);
}
if (Status == SD_OK)
{
/* Read block of 512 bytes from address 0 */
Status = SD_ReadBlock(aBuffer_Block_Rx, 0x00, BLOCK_SIZE);
/* Check if the Transfer is finished */
Status = SD_WaitReadOperation();
while(SD_GetStatus() != SD_TRANSFER_OK);
}
/* Check the correctness of written data */
if (Status == SD_OK)
{
TransferStatus1 = Buffercmp(aBuffer_Block_Tx, aBuffer_Block_Rx, BLOCK_SIZE);
}
if(TransferStatus1 == PASSED)
{
LED1(ON);
printf("\tThe test is successful.\r\n");
}
else
{
LED1(OFF);
LED3(ON);
printf("\tThe test is fail!!!\r\n");
}
printf("<----Single block test is end.\r\n");
}
/**
* @brief Tests the SD card Multiple Blocks operations.
* @param None
* @retval None
*/
static void SD_MultiBlockTest(void)
{
printf("\r\n---->Multi block test is starting...\r\n");
/* Fill the buffer to send */
Fill_Buffer(aBuffer_MultiBlock_Tx, MULTI_BUFFER_SIZE, 0x0);
if (Status == SD_OK)
{
/* Write multiple block of many bytes on address 0 */
Status = SD_WriteMultiBlocks(aBuffer_MultiBlock_Tx, 0, BLOCK_SIZE, NUMBER_OF_BLOCKS);
/* Check if the Transfer is finished */
Status = SD_WaitWriteOperation();
while(SD_GetStatus() != SD_TRANSFER_OK);
}
if (Status == SD_OK)
{
/* Read block of many bytes from address 0 */
Status = SD_ReadMultiBlocks(aBuffer_MultiBlock_Rx, 0, BLOCK_SIZE, NUMBER_OF_BLOCKS);
/* Check if the Transfer is finished */
Status = SD_WaitReadOperation();
while(SD_GetStatus() != SD_TRANSFER_OK);
}
/* Check the correctness of written data */
if (Status == SD_OK)
{
TransferStatus2 = Buffercmp(aBuffer_MultiBlock_Tx, aBuffer_MultiBlock_Rx, MULTI_BUFFER_SIZE);
}
if(TransferStatus2 == PASSED)
{
LED1(ON);
printf("\tThe test is successful.\r\n");
}
else
{
LED1(OFF);
LED3(ON);
printf("\tThe test is fail!!!\r\n");
}
printf("<----Multi block test is end.\r\n");
}
void SD_Test_Start(void)
{
if(Status != SD_OK){
return;
}
/*-------------------------- SD Erase Test ---------------------------- */
SD_EraseTest();
/*-------------------------- SD Single Block Test --------------------- */
SD_SingleBlockTest();
/*-------------------------- SD Multi Blocks Test --------------------- */
SD_MultiBlockTest();
}
void SD_Test_Init(void)
{
/* NVIC Configuration */
NVIC_Configuration();
/*------------------------------ SD Init ---------------------------------- */
if((Status = SD_Init()) == SD_OK)
{
printf("The SD Card is successfully initialized!!!\r\n");
}else{
LED3(ON);
printf("The SD Card is fail initialized!!!\r\n");
}
}
main.c
SDカードの読み取りと書き込みのテストの呼び出しで。
int main(void)
{
// ...
SD_Test_Init();
SD_Test_Start();
while(1){
// Do nothing!!!
}
//return 0;
}
4.検証テスト
最後に、検証テストは次のように成功します。
5.データダウンロードアドレス
移植を成功させるための完全なコードダウンロードアドレスは次のとおりです:https:
//download.csdn.net/download/ZHONGCAI0901/15265756