SD demo
Dependencies: BSP_DISCO_F413ZH mbed
main.cpp
- Committer:
- arostm
- Date:
- 2017-05-17
- Revision:
- 0:7708007ed23b
- Child:
- 1:8973a7ad5524
File content as of revision 0:7708007ed23b:
#include "mbed.h" #include "stm32f413h_discovery.h" #include "stm32f413h_discovery_lcd.h" #include "stm32f413h_discovery_sd.h" int main() { uint8_t SD_state = MSD_OK; static uint8_t prev_status = 2; /* Init LCD and display example information */ BSP_LCD_Init(); BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_SetBackColor(LCD_COLOR_GREEN); BSP_LCD_SetFont(&Font16); /* SD init */ SD_state = BSP_SD_Init(); if (SD_state != MSD_OK) { BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Inserte SD before running test", CENTER_MODE); } else { BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD Initialization : OK", LEFT_MODE); SD_state = BSP_SD_Erase(0, (BLOCKSIZE * 50)); /* Wait until SD card is ready to use for new operation */ while(BSP_SD_GetCardState() != SD_TRANSFER_OK) { } if (SD_state != MSD_OK) { BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD ERASE : FAILED.", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD ERASE : OK.", LEFT_MODE); } } BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Inserte or Removed SD", CENTER_MODE); while (1) { if (BSP_SD_IsDetected() != SD_PRESENT) { if(prev_status != SD_NOT_PRESENT) { BSP_SD_Init(); prev_status = SD_NOT_PRESENT; BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize() - 30, (uint8_t *)"SD Not Connected", LEFT_MODE); } } else if (prev_status != SD_PRESENT) { BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize() - 30, (uint8_t *)"SD Connected ", LEFT_MODE); prev_status = SD_PRESENT; } } }