MicroSD SDIO. Fire. QQ Firestm32.blog - Chinaunix.net STM32 ST3.0.0 PC8-SDIO-D0 DATA0 PC9-SDIO-D1 DATA1
MicroSD SDIO. Fire. QQ Firestm32.blog - Chinaunix.net STM32 ST3.0.0 PC8-SDIO-D0 DATA0 PC9-SDIO-D1 DATA1
com
㗙 fire
E-Mail [email protected]
QQ 313303034
मᅶ firestm32.blog.chinaunix.net
ᑧ⠜
⠜ᴀ ST3.0.0
⹀ӊ䖲˖PC8-SDIO-D0 ˖DATA0
PC9-SDIO-D1 ˖DATA1
PC10-SDIO-D2 ˖DATA2
PC11-SDIO-D3 ˖CD/DATA3
PC12-SDIO-CLK˖CLK
PD2-SDIO-CMD ˖CMD
ᑧ᭛ӊ ˖startup/start_stm32f10x_hd.c
CMSIS/core_cm3.c
CMSIS/system_stm32f10x.c
FWlib/stm32f10x_gpio.c
FWlib/stm32f10x_rcc.c
FWlib/stm32f10x_usart.c
FWlib/stm32f10x_sdio.c
FWlib/stm32f10x_dma.c
FWlib/misc.c
1/8
䞢☿ stm32 ᓔথᵓ⎬ᅱᅬᮍϧप˖http://firestm32.taobao.com
⫼᠋᭛ӊ: USER/main.c
USER/stm32f10x_it.c
USER/usart.c
USER/sdcard.c
SDIO ㅔҟ->
2/8
䞢☿ stm32 ᓔথᵓ⎬ᅱᅬᮍϧप˖http://firestm32.taobao.com
ᅲ偠䆆㾷->
佪ܜᎹЁ⏏ࡴ៥Ӏ᠔䳔㽕ⱘᑧ᭛ӊ˖
FWlib/stm32f10x_gpio.c
FWlib/stm32f10x_rcc.c
FWlib/stm32f10x_usart.c
FWlib/stm32f10x_sdio.c
FWlib/stm32f10x_dma.c
FWlib/misc.c
1. /* Includes ------------------------------------------------------------------
*/
2. /* Uncomment the line below to enable peripheral header file inclusion */
3. /* #include "stm32f10x_adc.h" */
4. /* #include "stm32f10x_bkp.h" */
5. /* #include "stm32f10x_can.h" */
6. /* #include "stm32f10x_crc.h" */
7. /* #include "stm32f10x_dac.h" */
8. /* #include "stm32f10x_dbgmcu.h" */
9. #include "stm32f10x_dma.h"
10. /* #include "stm32f10x_exti.h" */
11. /*#include "stm32f10x_flash.h"*/
12. /* #include "stm32f10x_fsmc.h" */
13. #include "stm32f10x_gpio.h"
14. /* #include "stm32f10x_i2c.h" */
15. /* #include "stm32f10x_iwdg.h" */
16. /* #include "stm32f10x_pwr.h" */
17. #include "stm32f10x_rcc.h"
18. /* #include "stm32f10x_rtc.h" */
19. #include "stm32f10x_sdio.h"
20. /* #include "stm32f10x_spi.h" */
21. /* #include "stm32f10x_tim.h" */
22. #include "stm32f10x_usart.h"
23. /* #include "stm32f10x_wwdg.h" */
24. #include "misc.h" /* High level functions for NVIC and SysTick (add-
25. on to CMSIS functions) */
3/8
䞢☿ stm32 ᓔথᵓ⎬ᅱᅬᮍϧप˖http://firestm32.taobao.com
1. /*
2. * ߑ᭄ৡ˖main
3. * ᦣ䗄 ˖᮴
4. * 䕧ܹ ˖᮴
5. * 䕧ߎ ˖᮴
6. */
7. int main(void)
8. {
9. /* config the sysclock to 72M */
10. SystemInit();
11.
12. /* USART1 config */
13. USART1_Config();
14.
15. /* Interrupt Config */
16. NVIC_Configuration();
17.
18. printf( "\r\n 䖭ᰃϔϾ MicroSD वᅲ偠(≵᳝䎥᭛ӊ㋏㒳)......... " );
19.
20. /*-------------------------- SD Init ----------------------------- */
21. Status = SD_Init();
22.
23. if (Status == SD_OK)
24. {
25. /*----------------- Read CSD/CID MSD registers ------------------*/
26. printf( " \r\n SD_Init is ok " );
27. Status = SD_GetCardInfo(&SDCardInfo);
28. }
29.
30. //printf( " \r\n SD_GetCardInfo Status is: %d ", Status );
31. printf( " \r\n CardType is ˖%d ", SDCardInfo.CardType );
32. printf( " \r\n CardCapacity is ˖%d ", SDCardInfo.CardCapacity );
33. printf( " \r\n CardBlockSize is ˖%d ", SDCardInfo.CardBlockSize );
34. printf( " \r\n RCA is ˖%d ", SDCardInfo.RCA);
35. printf( " \r\n ManufacturerID is ˖%d ", SDCardInfo.SD_cid.ManufacturerID )
;
36.
37. if (Status == SD_OK)
38. {
39. printf("\r\n SD_GetCardInfo is ok ");
40. /*----------------- Select Card --------------------------------*/
41. Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));
42. }
43.
44. if (Status == SD_OK)
45. {
46. printf(" \r\n SD_SelectDeselect is ok ");
47. // SDIO_BusWide_4b Ӯ䖯ܹ⅏ᕾ⦃,㟇Ҟ䖬㾷އ
48. Status = SD_EnableWideBusOperation(SDIO_BusWide_1b);
49. }
50.
51. /*------------------- Block Erase -------------------------------*/
52. if (Status == SD_OK)
53. {
54. /* Erase NumberOfBlocks Blocks of WRITE_BL_LEN(512 Bytes) */
55. Status = SD_Erase(0x00, (BlockSize * NumberOfBlocks));
56. }
57.
58. if (Status == SD_OK)
59. {
60. printf(" \r\n SD_Erase is ok ");
61. Status = SD_SetDeviceMode(SD_DMA_MODE);
62. }
63.
64. if (Status == SD_OK)
65. {
66. printf(" \r\n SD_SetDeviceMode is ok ");
67. // 4bit ᓣᯊӮذ䖭䞠њˈ䖯ܹ⅏ᕾ⦃ˈ1bit ᓣᯊ߭ৃҹ䇏প៤ࡳ
68. Status = SD_ReadMultiBlocks(0x00, Buffer_MultiBlock_Rx, BlockSize, NumberO
fBlocks);
69. }
70.
71. if (Status == SD_OK)
72. {
4/8
䞢☿ stm32 ᓔথᵓ⎬ᅱᅬᮍϧप˖http://firestm32.taobao.com
5/8
䞢☿ stm32 ᓔথᵓ⎬ᅱᅬᮍϧप˖http://firestm32.taobao.com
main ߑ᭄᳝⚍䭓ˈԚ䅸ⳳߚᵤϟ䖬ᰃᕜད⧚㾷ⱘˈӭ㒭⚍㗤ᖗˈ⫼ࠄⱘᕜ䛑
ᰃᑧ᪡ˈ䛑ᰃ ST ⱘᎹᏜЎ⫼᠋ݭདⱘDŽ
佪ˈܜ៥Ӏ䖬ᰃϔབ᮶ᕔഄܜ䇗⫼៥Ӏⱘᑧߑ᭄ SystemInit();ᇚ៥Ӏⱘ㋏㒳ᯊ䩳
䆒㕂Ў 72MHZDŽߑ᭄ USART1_Config();⫼ᴹ߱ྟ࣪៥Ӏ㽕⫼ࠄⱘІষDŽ݇Ѣ䖭ϸϾߑ᭄
ⱘ䆺㒚䆆㾷ৃখ㗗ࠡ䴶ⱘᬭˈ䖭䞠ϡ䆺䗄DŽ
SD_DMA_MODEǃSD_POLLING_MODEǃSD_INTERRUPT_MODEˈ݊ЁᎹЁᮁᓣᯊህ䳔㽕䆒㕂Ё
)DŽ
পϢवⱘሲᗻ᳝݇ⱘֵᙃDŽ㋻ⴔ䗮䖛Іষᇚ䖭ѯֵᙃ⬉㛥ⱘ䍙㑻㒜ッЁᠧ
ॄߎᴹDŽ
3->㦋পࠄवⱘℷ⹂ֵᙃৢˈ䇗⫼ߑ᭄
4->⹂ᅮདⳂᷛवПৢˈ䇗⫼ߑ᭄ SD_EnableWideBusOperation(SDIO_BusWide_1b);
Ў 4 ԡᓣ៥䖬≵᳝䇗䆩៤ࡳˈҡ䳔ࡾਔʽ
Ў DMA ᮍᓣDŽ
6/8
䞢☿ stm32 ᓔথᵓ⎬ᅱᅬᮍϧप˖http://firestm32.taobao.com
6->ࠄњ䖭䞠Ϣव᳝݇ⱘ߱ྟ࣪䛑Ꮖᅠ៤ˈ؛བᑣ㛑䖤㸠ࠄ䖭䞠ⱘ䆱ˈवⱘ᪡
ᴀϞᏆ㒣៤ࡳњϔञDŽ
8->᳔ৢᠧॄ䇗䆩ֵᙃDŽ
⊼ᛣ˖䖭Ͼ՟ᰃ≵᳝䎥᭛ӊ㋏㒳ⱘˈ㗠ᰃⳈህএ䇏वⱘ blockˈ䖭ḋⱘ䆱ህӮ⸈
ണवⱘߚऎˈᅲ偠ᅠ៤ПৢˈԴݡᡞवᦦࠄ⬉㛥Ϟᯊˈ⬉㛥Ӯᦤ⼎Դ㽕䞡
ᮄ߱ྟ࣪वˈ䖭ᰃℷᐌᛇ䈵ˈᑊϡᰃᴀᅲ偠ᡞԴⱘवᓘണњDŽԚ䎥᭛ӊ㋏㒳
ᯊህϡӮߎ⦄䖭⾡䯂乬ˈ᳝݇᭛ӊ㋏㒳ⱘ᪡ᇚϟϔ䆆ⱘᬭЁ䆆㾷DŽ
7/8
䞢☿ stm32 ᓔথᵓ⎬ᅱᅬᮍϧप˖http://firestm32.taobao.com
ᅲ偠⦄䈵->
ᅲ偠䆆㾷ᅠ↩ˈ䞢☿⼱ᆊᄺдᛝᖿ^_^DŽ
8/8