Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed SD_DISCO_F469NI BSP_DISCO_F469NI
main.cpp
00001 #include "mbed.h" 00002 #include "SD_DISCO_F469NI.h" 00003 00004 SD_DISCO_F469NI sd; 00005 00006 DigitalOut led_green(LED1); 00007 DigitalOut led_red(LED2); 00008 00009 Serial pc(USBTX, USBRX); 00010 00011 #define BLOCK_START_ADDR 0 /* Block start address */ 00012 #define NUM_OF_BLOCKS 5 /* Total number of blocks */ 00013 #define BUFFER_WORDS_SIZE ((512 * NUM_OF_BLOCKS) >> 2) /* Total data size in bytes */ 00014 00015 uint32_t aTxBuffer[BUFFER_WORDS_SIZE]; 00016 uint32_t aRxBuffer[BUFFER_WORDS_SIZE]; 00017 /* Private function prototypes -----------------------------------------------*/ 00018 void SD_main_test(void); 00019 void SD_Detection(void); 00020 00021 static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset); 00022 static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength); 00023 00024 int main() { 00025 uint8_t SD_state = MSD_OK; 00026 pc.printf("SD\n"); 00027 pc.printf("This example shows how to write\n"); 00028 pc.printf("and read data on the microSD and also\n"); 00029 pc.printf("how to detect the presence of the card\n"); 00030 led_red = 0; 00031 00032 SD_state = sd.Init(); 00033 if(SD_state != MSD_OK){ 00034 if(SD_state == MSD_ERROR_SD_NOT_PRESENT){ 00035 pc.printf("SD shall be inserted before running test\n"); 00036 } else { 00037 pc.printf("SD Initialization : FAIL.\n"); 00038 } 00039 pc.printf("SD Test Aborted.\n"); 00040 } else { 00041 pc.printf("SD Initialization : OK.\n"); 00042 00043 if(sd.Erase(BLOCK_START_ADDR, (512 * NUM_OF_BLOCKS)) != MSD_OK){ 00044 pc.printf("SD ERASE : FAILED.\n"); 00045 pc.printf("SD Test Aborted.\n"); 00046 } else { 00047 pc.printf("SD ERASE : OK.\n"); 00048 00049 /* Fill the buffer to write */ 00050 Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF); 00051 00052 if(sd.WriteBlocks(aTxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, SD_DATATIMEOUT) != MSD_OK){ 00053 pc.printf("SD WRITE : FAILED.\n"); 00054 pc.printf("SD Test Aborted.\n"); 00055 } else { 00056 pc.printf("SD WRITE : OK.\n"); 00057 00058 if(sd.ReadBlocks(aRxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, SD_DATATIMEOUT)!= MSD_OK){ 00059 pc.printf("SD READ : FAILED.\n"); 00060 pc.printf("SD Test Aborted.\n"); 00061 } else { 00062 pc.printf("SD READ : OK.\n"); 00063 if(Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) > 0){ 00064 pc.printf("SD COMPARE : FAILED.\n"); 00065 pc.printf("SD Test Aborted.\n"); 00066 } else { 00067 pc.printf("SD Test : OK.\n"); 00068 pc.printf("SD can be removed.\n"); 00069 } 00070 } 00071 } 00072 } 00073 } 00074 00075 // while (1) {} 00076 } 00077 00078 /** 00079 * @brief Fills buffer with user predefined data. 00080 * @param pBuffer: pointer on the buffer to fill 00081 * @param uwBufferLenght: size of the buffer to fill 00082 * @param uwOffset: first value to fill on the buffer 00083 * @retval None 00084 */ 00085 static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset) { 00086 uint32_t tmpIndex = 0; 00087 00088 /* Put in global buffer different values */ 00089 for (tmpIndex = 0; tmpIndex < uwBufferLength; tmpIndex++ ){ 00090 pBuffer[tmpIndex] = tmpIndex + uwOffset; 00091 } 00092 } 00093 00094 /** 00095 * @brief Compares two buffers. 00096 * @param pBuffer1, pBuffer2: buffers to be compared. 00097 * @param BufferLength: buffer's length 00098 * @retval 1: pBuffer identical to pBuffer1 00099 * 0: pBuffer differs from pBuffer1 00100 */ 00101 static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength) { 00102 while (BufferLength--) { 00103 if (*pBuffer1 != *pBuffer2) { 00104 return 1; 00105 } 00106 00107 pBuffer1++; 00108 pBuffer2++; 00109 } 00110 00111 return 0; 00112 }
Generated on Sun Aug 28 2022 08:24:27 by
1.7.2