void EXTI2_IRQHandler(void) { BSP_SD_DETECT_IRQHandler(0); } void SDMMC1_IRQHandler(void) { BSP_SD_IRQHandler(0); } 4、添加sd测试函数: 复制#include "main.h" #include "stdio.h" #define SD_CARD_PRESENCE_POLLING_MODE 0 #define SD_CARD_PRESENCE_INTERRUPT_MODE 1 #define SD_CARD_PRESENCE_VALIDATION_MODE SD_CARD_PRESENCE_INTERRUPT_MODE #define BLOCK_START_ADDR 0 /* Block start address */ #define NUM_OF_BLOCKS 5 /* Total number of blocks */ #define BUFFER_WORDS_SIZE ((BLOCKSIZE * NUM_OF_BLOCKS) >> 2) /* Total data size in bytes */ __IO uint32_t SDWriteStatus = 0, SDReadStatus = 0, SDDetectStatus = 0, SDDetectIT = 0; void SD_demo(void) { int32_t SD_state = BSP_ERROR_NONE; SD_state = BSP_SD_Init(0); #if (SD_CARD_PRESENCE_VALIDATION_MODE == SD_CARD_PRESENCE_INTERRUPT_MODE) if (SD_state == BSP_ERROR_NONE) { SD_state = BSP_SD_DetectITConfig(0); } #endif if (SD_state != BSP_ERROR_NONE) { if (SD_state == BSP_ERROR_UNKNOWN_COMPONENT) { printf("SD shall be inserted before"); printf("running test.\r\n"); printf("SD Test Aborted.\r\n"); } else { printf("SD Initialization : FAIL.\r\n"); printf("SD Test Aborted.\r\n"); } } else { printf("SD Initialization : OK.\r\n"); } } /** * [url=home.php?mod=space&uid=247401]@brief[/url] Tx Transfer completed callback * @param Instance SD Instance * @retval None */ void BSP_SD_WriteCpltCallback(uint32_t Instance) { if (Instance == 0) { SDWriteStatus = 1; } } /** * @brief Rx Transfer completed callback * @param Instance SD Instance * @retval None */ void BSP_SD_ReadCpltCallback(uint32_t Instance) { if (Instance == 0) { SDReadStatus = 1; } } /** * @brief BSP SD Callback. * @param Instance SD Instance * @param Status Pin status * @retval None. */ void BSP_SD_DetectCallback(uint32_t Instance, uint32_t Status) { if (Instance == 0) { SDDetectIT = 1; SDDetectStatus = Status; } } /** * @brief SDMMC error callback * @param None * @retval None */ void HAL_SD_ErrorCallback(SD_HandleTypeDef *hsd) { Error_Handler(); } 在main.c中添加sd_demo 下载到开发板上,可以看到SD初始化成功:
#include "main.h" #include "stdio.h" #define SD_CARD_PRESENCE_POLLING_MODE 0 #define SD_CARD_PRESENCE_INTERRUPT_MODE 1 #define SD_CARD_PRESENCE_VALIDATION_MODE SD_CARD_PRESENCE_INTERRUPT_MODE #define BLOCK_START_ADDR 0 /* Block start address */ #define NUM_OF_BLOCKS 5 /* Total number of blocks */ #define BUFFER_WORDS_SIZE ((BLOCKSIZE * NUM_OF_BLOCKS) >> 2) /* Total data size in bytes */ __IO uint32_t SDWriteStatus = 0, SDReadStatus = 0, SDDetectStatus = 0, SDDetectIT = 0; void SD_demo(void) { int32_t SD_state = BSP_ERROR_NONE; SD_state = BSP_SD_Init(0); #if (SD_CARD_PRESENCE_VALIDATION_MODE == SD_CARD_PRESENCE_INTERRUPT_MODE) if (SD_state == BSP_ERROR_NONE) { SD_state = BSP_SD_DetectITConfig(0); } #endif if (SD_state != BSP_ERROR_NONE) { if (SD_state == BSP_ERROR_UNKNOWN_COMPONENT) { printf("SD shall be inserted before"); printf("running test.\r\n"); printf("SD Test Aborted.\r\n"); } else { printf("SD Initialization : FAIL.\r\n"); printf("SD Test Aborted.\r\n"); } } else { printf("SD Initialization : OK.\r\n"); } } /** * [url=home.php?mod=space&uid=247401]@brief[/url] Tx Transfer completed callback * @param Instance SD Instance * @retval None */ void BSP_SD_WriteCpltCallback(uint32_t Instance) { if (Instance == 0) { SDWriteStatus = 1; } } /** * @brief Rx Transfer completed callback * @param Instance SD Instance * @retval None */ void BSP_SD_ReadCpltCallback(uint32_t Instance) { if (Instance == 0) { SDReadStatus = 1; } } /** * @brief BSP SD Callback. * @param Instance SD Instance * @param Status Pin status * @retval None. */ void BSP_SD_DetectCallback(uint32_t Instance, uint32_t Status) { if (Instance == 0) { SDDetectIT = 1; SDDetectStatus = Status; } } /** * @brief SDMMC error callback * @param None * @retval None */ void HAL_SD_ErrorCallback(SD_HandleTypeDef *hsd) { Error_Handler(); } 在main.c中添加sd_demo 下载到开发板上,可以看到SD初始化成功:
举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
180
830
12
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号