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.
main.cpp
00001 #include "mbed.h" 00002 #include "stm32l496g_discovery.h" 00003 #include "stm32l496g_discovery_lcd.h" 00004 #include "stm32l496g_discovery_sd.h" 00005 00006 #define NUM_OF_BLOCKS 5 00007 #define BLOCK_START_ADDR 0 00008 #define BLOCK_SIZE 512 00009 #define BLOCK_END_ADDR (BLOCK_SIZE * NUM_OF_BLOCKS) 00010 #define BUFFER_WORDS_SIZE ((BLOCK_SIZE * NUM_OF_BLOCKS) >> 2) // Total data size in bytes 00011 00012 uint32_t aTxBuffer[BUFFER_WORDS_SIZE]; 00013 uint32_t aRxBuffer[BUFFER_WORDS_SIZE]; 00014 00015 static void print_demo_title(void); 00016 static void print_PASS(void); 00017 static void print_FAIL(void); 00018 static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset); 00019 static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength); 00020 00021 int main() 00022 { 00023 uint8_t status; 00024 print_demo_title(); 00025 wait(0.2); 00026 00027 // Initialization 00028 status = BSP_SD_Init(); 00029 if (status == MSD_OK) { 00030 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"SD INIT OK", LEFT_MODE); 00031 } 00032 else if (status == MSD_ERROR_SD_NOT_PRESENT) { 00033 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"SD CARD NOT FOUND", LEFT_MODE); 00034 print_FAIL(); 00035 } 00036 else { 00037 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"SD INIT FAIL", LEFT_MODE); 00038 print_FAIL(); 00039 } 00040 00041 // Erase 00042 status = BSP_SD_Erase(BLOCK_START_ADDR, BLOCK_END_ADDR); 00043 if (status == MSD_OK) { 00044 BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"SD ERASE OK", LEFT_MODE); 00045 } 00046 else { 00047 BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"SD ERASE FAIL", LEFT_MODE); 00048 print_FAIL(); 00049 } 00050 00051 // Prepare the buffer to write 00052 Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF); 00053 00054 // Write 00055 status = BSP_SD_WriteBlocks(aTxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, SD_DATATIMEOUT); 00056 if (status == MSD_OK) { 00057 BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)"SD WRITE OK", LEFT_MODE); 00058 } 00059 else { 00060 BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)"SD WRITE FAIL", LEFT_MODE); 00061 print_FAIL(); 00062 } 00063 00064 // Read 00065 status = BSP_SD_ReadBlocks(aRxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, SD_DATATIMEOUT); 00066 if (status == MSD_OK) { 00067 BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"SD READ OK", LEFT_MODE); 00068 } 00069 else { 00070 BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)"SD READ FAIL", LEFT_MODE); 00071 print_FAIL(); 00072 } 00073 00074 // Compare data 00075 if (Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) == 0) { 00076 BSP_LCD_DisplayStringAt(0, LINE(9), (uint8_t *)"SD DATA OK", LEFT_MODE); 00077 } 00078 else { 00079 BSP_LCD_DisplayStringAt(0, LINE(9), (uint8_t *)"SD DATA FAIL", LEFT_MODE); 00080 print_FAIL(); 00081 } 00082 00083 print_PASS(); 00084 } 00085 00086 static void print_demo_title(void) 00087 { 00088 BSP_LCD_Init(); 00089 BSP_LCD_Clear(LCD_COLOR_WHITE); 00090 BSP_LCD_SetTextColor(LCD_COLOR_BLUE); 00091 BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 80); 00092 BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 00093 BSP_LCD_SetBackColor(LCD_COLOR_BLUE); 00094 BSP_LCD_SetFont(&Font24); 00095 BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"SDCARD", CENTER_MODE); 00096 BSP_LCD_SetFont(&Font12); 00097 BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"This example shows how to write", CENTER_MODE); 00098 BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"and read data on the SDCard", CENTER_MODE); 00099 BSP_LCD_SetFont(&Font20); 00100 } 00101 00102 static void print_PASS(void) 00103 { 00104 BSP_LCD_SetTextColor(LCD_COLOR_BLACK); 00105 BSP_LCD_SetBackColor(LCD_COLOR_GREEN); 00106 BSP_LCD_DisplayStringAt(0, LINE(11), (uint8_t *)"Demo OK", CENTER_MODE); 00107 while(1); 00108 } 00109 00110 static void print_FAIL(void) 00111 { 00112 BSP_LCD_SetBackColor(LCD_COLOR_RED); 00113 BSP_LCD_DisplayStringAt(0, LINE(11), (uint8_t *)"Demo FAILED", CENTER_MODE); 00114 while(1); 00115 } 00116 00117 /** 00118 * @brief Fills buffer with user predefined data. 00119 * @param pBuffer: pointer on the buffer to fill 00120 * @param uwBufferLenght: size of the buffer to fill 00121 * @param uwOffset: first value to fill on the buffer 00122 * @retval None 00123 */ 00124 static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset) 00125 { 00126 uint32_t tmpIndex = 0; 00127 /* Put in global buffer different values */ 00128 for (tmpIndex = 0; tmpIndex < uwBufferLength; tmpIndex++ ) { 00129 pBuffer[tmpIndex] = tmpIndex + uwOffset; 00130 } 00131 } 00132 00133 /** 00134 * @brief Compares two buffers. 00135 * @param pBuffer1, pBuffer2: buffers to be compared. 00136 * @param BufferLength: buffer's length 00137 * @retval 0: pBuffer2 identical to pBuffer1 00138 * 1: pBuffer2 differs from pBuffer1 00139 */ 00140 static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength) 00141 { 00142 while (BufferLength--) { 00143 if (*pBuffer1 != *pBuffer2) { 00144 return 1; 00145 } 00146 pBuffer1++; 00147 pBuffer2++; 00148 } 00149 return 0; 00150 }
Generated on Mon Jul 18 2022 02:51:18 by
1.7.2