SD basic example for DISCO-F769NI
Dependencies: BSP_DISCO_F769NI
main.cpp@0:b134be2534a3, 2017-04-11 (annotated)
- Committer:
- jeromecoutant
- Date:
- Tue Apr 11 14:32:52 2017 +0000
- Revision:
- 0:b134be2534a3
- Child:
- 2:4c7f351406d3
SD basic example for DISCO-F769NI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jeromecoutant | 0:b134be2534a3 | 1 | #include "mbed.h" |
jeromecoutant | 0:b134be2534a3 | 2 | #include "stm32f769i_discovery.h" |
jeromecoutant | 0:b134be2534a3 | 3 | #include "stm32f769i_discovery_lcd.h" |
jeromecoutant | 0:b134be2534a3 | 4 | #include "stm32f769i_discovery_sd.h" |
jeromecoutant | 0:b134be2534a3 | 5 | |
jeromecoutant | 0:b134be2534a3 | 6 | int main() |
jeromecoutant | 0:b134be2534a3 | 7 | { |
jeromecoutant | 0:b134be2534a3 | 8 | uint8_t SD_state = MSD_OK; |
jeromecoutant | 0:b134be2534a3 | 9 | static uint8_t prev_status = 2; |
jeromecoutant | 0:b134be2534a3 | 10 | |
jeromecoutant | 0:b134be2534a3 | 11 | printf("\n\n SD EXAMPLE FOR DISCO-F769NI START:\n"); |
jeromecoutant | 0:b134be2534a3 | 12 | |
jeromecoutant | 0:b134be2534a3 | 13 | /* Init LCD and display example information */ |
jeromecoutant | 0:b134be2534a3 | 14 | BSP_LCD_Init(); |
jeromecoutant | 0:b134be2534a3 | 15 | BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); |
jeromecoutant | 0:b134be2534a3 | 16 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
jeromecoutant | 0:b134be2534a3 | 17 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
jeromecoutant | 0:b134be2534a3 | 18 | BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40); |
jeromecoutant | 0:b134be2534a3 | 19 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
jeromecoutant | 0:b134be2534a3 | 20 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
jeromecoutant | 0:b134be2534a3 | 21 | BSP_LCD_SetFont(&Font24); |
jeromecoutant | 0:b134be2534a3 | 22 | BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"SD basic example", CENTER_MODE); |
jeromecoutant | 0:b134be2534a3 | 23 | |
jeromecoutant | 0:b134be2534a3 | 24 | /* SD init */ |
jeromecoutant | 0:b134be2534a3 | 25 | SD_state = BSP_SD_Init(); |
jeromecoutant | 0:b134be2534a3 | 26 | printf("BSP_SD_Init return %d\n", SD_state); |
jeromecoutant | 0:b134be2534a3 | 27 | |
jeromecoutant | 0:b134be2534a3 | 28 | if (SD_state != MSD_OK) { |
jeromecoutant | 0:b134be2534a3 | 29 | BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD shall be inserted before running test", LEFT_MODE); |
jeromecoutant | 0:b134be2534a3 | 30 | |
jeromecoutant | 0:b134be2534a3 | 31 | } else { |
jeromecoutant | 0:b134be2534a3 | 32 | BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD Initialization : OK", LEFT_MODE); |
jeromecoutant | 0:b134be2534a3 | 33 | |
jeromecoutant | 0:b134be2534a3 | 34 | SD_state = BSP_SD_Erase(0, (BLOCKSIZE * 50)); |
jeromecoutant | 0:b134be2534a3 | 35 | /* Wait until SD card is ready to use for new operation */ |
jeromecoutant | 0:b134be2534a3 | 36 | while(BSP_SD_GetCardState() != SD_TRANSFER_OK) { |
jeromecoutant | 0:b134be2534a3 | 37 | } |
jeromecoutant | 0:b134be2534a3 | 38 | if (SD_state != MSD_OK) { |
jeromecoutant | 0:b134be2534a3 | 39 | BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD ERASE : FAILED.", LEFT_MODE); |
jeromecoutant | 0:b134be2534a3 | 40 | } else { |
jeromecoutant | 0:b134be2534a3 | 41 | BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD ERASE : OK.", LEFT_MODE); |
jeromecoutant | 0:b134be2534a3 | 42 | } |
jeromecoutant | 0:b134be2534a3 | 43 | } |
jeromecoutant | 0:b134be2534a3 | 44 | |
jeromecoutant | 0:b134be2534a3 | 45 | BSP_LCD_DisplayStringAt(20, 250, (uint8_t *)"SD can be inserted or removed now", LEFT_MODE); |
jeromecoutant | 0:b134be2534a3 | 46 | |
jeromecoutant | 0:b134be2534a3 | 47 | while (1) { |
jeromecoutant | 0:b134be2534a3 | 48 | if (BSP_SD_IsDetected() != SD_PRESENT) { |
jeromecoutant | 0:b134be2534a3 | 49 | if(prev_status != SD_NOT_PRESENT) { |
jeromecoutant | 0:b134be2534a3 | 50 | BSP_SD_Init(); |
jeromecoutant | 0:b134be2534a3 | 51 | prev_status = SD_NOT_PRESENT; |
jeromecoutant | 0:b134be2534a3 | 52 | BSP_LCD_SetTextColor(LCD_COLOR_RED); |
jeromecoutant | 0:b134be2534a3 | 53 | BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize() - 30, (uint8_t *)"SD Not Connected", LEFT_MODE); |
jeromecoutant | 0:b134be2534a3 | 54 | } |
jeromecoutant | 0:b134be2534a3 | 55 | } else if (prev_status != SD_PRESENT) { |
jeromecoutant | 0:b134be2534a3 | 56 | BSP_LCD_SetTextColor(LCD_COLOR_GREEN); |
jeromecoutant | 0:b134be2534a3 | 57 | BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize() - 30, (uint8_t *)"SD Connected ", LEFT_MODE); |
jeromecoutant | 0:b134be2534a3 | 58 | prev_status = SD_PRESENT; |
jeromecoutant | 0:b134be2534a3 | 59 | } |
jeromecoutant | 0:b134be2534a3 | 60 | |
jeromecoutant | 0:b134be2534a3 | 61 | } |
jeromecoutant | 0:b134be2534a3 | 62 | } |