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