SD for DISCO_F746NG basic demo

Dependencies:   BSP_DISCO_F746NG

Files at this revision

API Documentation at this revision

Comitter:
Jerome Coutant
Date:
Wed Nov 20 12:55:12 2019 +0100
Parent:
3:33086de19b14
Commit message:
Update with STM32Cube_FW_F7_V1.15.0

Changed in this revision

.hgignore Show annotated file Show diff for this revision Revisions of this file
BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
SD_DISCO_F746NG.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Nov 20 12:55:12 2019 +0100
@@ -0,0 +1,2 @@
+BUILD
+mbed-os/
--- a/BSP_DISCO_F746NG.lib	Fri Jun 09 08:35:40 2017 +0000
+++ b/BSP_DISCO_F746NG.lib	Wed Nov 20 12:55:12 2019 +0100
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/#56384bddaba5
+https://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#1050c589b2ad
--- a/SD_DISCO_F746NG.lib	Fri Jun 09 08:35:40 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/teams/ST/code/SD_DISCO_F746NG/#cf12f3d37081
--- a/main.cpp	Fri Jun 09 08:35:40 2017 +0000
+++ b/main.cpp	Wed Nov 20 12:55:12 2019 +0100
@@ -1,93 +1,98 @@
 #include "mbed.h"
-#include "SD_DISCO_F746NG.h"
-
-SD_DISCO_F746NG sd;
-
-DigitalOut led_green(LED1);
-DigitalOut led_red(LED2);
-
-Serial pc(USBTX, USBRX);
+#include "stm32746g_discovery_sd.h"
 
 #define BLOCK_START_ADDR         0     /* Block start address      */
 #define NUM_OF_BLOCKS            5     /* Total number of blocks   */
 #define BUFFER_WORDS_SIZE        ((BLOCKSIZE * NUM_OF_BLOCKS) >> 2) /* Total data size in bytes */
- 
+
 uint32_t aTxBuffer[BUFFER_WORDS_SIZE];
 uint32_t aRxBuffer[BUFFER_WORDS_SIZE];
+
 /* Private function prototypes -----------------------------------------------*/
 void SD_main_test(void);
 void SD_Detection(void);
 
 static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset);
-static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength);
- 
+static uint8_t Buffercmp(uint32_t *pBuffer1, uint32_t *pBuffer2, uint16_t BufferLength);
+
 int main()
 {
     uint8_t SD_state = MSD_OK;
-    pc.printf("\n\nuSD example start:\n");
-    led_red = 0;
-  
-    SD_state = sd.Init();
-    if(SD_state != MSD_OK){
-        if(SD_state == MSD_ERROR_SD_NOT_PRESENT){
-            pc.printf("SD shall be inserted before running test\n");
+    static uint8_t prev_status = SD_PRESENT;
+
+    printf("\n\nSD example start:\n");
+
+    SD_state = BSP_SD_Init();
+    if (SD_state != MSD_OK) {
+        if (SD_state == MSD_ERROR_SD_NOT_PRESENT) {
+            printf("SD shall be inserted before running test\n");
         } else {
-            pc.printf("SD Initialization : FAIL.\n");
+            printf("SD Initialization : FAIL.\n");
         }
-        pc.printf("SD Test Aborted.\n");
+        printf("SD Test Aborted.\n");
     } else {
-        pc.printf("SD Initialization : OK.\n");
+        printf("SD Initialization : OK.\n");
 
-        SD_state = sd.Erase(BLOCK_START_ADDR, (BLOCK_START_ADDR + NUM_OF_BLOCKS - 1));
+        SD_state = BSP_SD_Erase(BLOCK_START_ADDR, (BLOCK_START_ADDR + NUM_OF_BLOCKS - 1));
 
         /* Wait until SD card is ready to use for new operation */
-        while(sd.GetCardState() != SD_TRANSFER_OK){
+        while (BSP_SD_GetCardState() != SD_TRANSFER_OK) {
         }
-        if (SD_state != MSD_OK){
-            pc.printf("SD ERASE : FAILED.\n");
-            pc.printf("SD Test Aborted.\n");
+        if (SD_state != MSD_OK) {
+            printf("SD ERASE : FAILED.\n");
+            printf("SD Test Aborted.\n");
         } else {
-            pc.printf("SD ERASE : OK.\n");
-          
+            printf("SD ERASE : OK.\n");
+
             /* Fill the buffer to write */
             Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x2300);
-          
-            SD_state = sd.WriteBlocks(aTxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, 10000);
+
+            SD_state = BSP_SD_WriteBlocks(aTxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, 10000);
             /* Wait until SD card is ready to use for new operation */
-            while(sd.GetCardState() != SD_TRANSFER_OK){
+            while (BSP_SD_GetCardState() != SD_TRANSFER_OK) {
             }
 
-            if (SD_state != MSD_OK){
-                pc.printf("SD WRITE : FAILED.\n");
-                pc.printf("SD Test Aborted.\n");
+            if (SD_state != MSD_OK) {
+                printf("SD WRITE : FAILED.\n");
+                printf("SD Test Aborted.\n");
             } else {
-                pc.printf("SD WRITE : OK.\n");
-            
-                SD_state = sd.ReadBlocks(aRxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, 10000);
+                printf("SD WRITE : OK.\n");
+
+                SD_state = BSP_SD_ReadBlocks(aRxBuffer, BLOCK_START_ADDR, NUM_OF_BLOCKS, 10000);
                 /* Wait until SD card is ready to use for new operation */
-                while(sd.GetCardState() != SD_TRANSFER_OK){
+                while (BSP_SD_GetCardState() != SD_TRANSFER_OK) {
                 }
 
-                if (SD_state != MSD_OK){
-                    pc.printf("SD READ : FAILED.\n");
-                    pc.printf("SD Test Aborted.\n");
+                if (SD_state != MSD_OK) {
+                    printf("SD READ : FAILED.\n");
+                    printf("SD Test Aborted.\n");
                 } else {
-                    pc.printf("SD READ : OK.\n");
-                    if(Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) > 0){
-                        pc.printf("SD COMPARE : FAILED.\n");
-                        pc.printf("SD Test Aborted.\n");
+                    printf("SD READ : OK.\n");
+                    if (Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) > 0) {
+                        printf("SD COMPARE : FAILED.\n");
+                        printf("SD Test Aborted.\n");
                     } else {
-                        pc.printf("SD Test : OK.\n");
-                        pc.printf("SD can be removed.\n");
+                        printf("SD Test : OK.\n");
+                        printf("SD can be removed.\n");
                     }
                 }
             }
         }
     }
-  
+
     while (1) {
+        if (BSP_SD_IsDetected() != SD_PRESENT) {
+            if (prev_status != SD_NOT_PRESENT) {
+                BSP_SD_Init();
+                prev_status = SD_NOT_PRESENT;
+                printf("SD removed\n");
+            }
+        } else if (prev_status != SD_PRESENT) {
+            printf("SD detected\n");
+            prev_status = SD_PRESENT;
+        }
     }
-} 
+}
 
 /**
   * @brief  Fills buffer with user predefined data.
@@ -98,15 +103,14 @@
   */
 static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset)
 {
-  uint32_t tmpIndex = 0;
+    uint32_t tmpIndex = 0;
 
-  /* Put in global buffer different values */
-  for (tmpIndex = 0; tmpIndex < uwBufferLength; tmpIndex++ )
-  {
-    pBuffer[tmpIndex] = tmpIndex + uwOffset;
-  }
+    /* Put in global buffer different values */
+    for (tmpIndex = 0; tmpIndex < uwBufferLength; tmpIndex++) {
+        pBuffer[tmpIndex] = tmpIndex + uwOffset;
+    }
 }
- 
+
 /**
   * @brief  Compares two buffers.
   * @param  pBuffer1, pBuffer2: buffers to be compared.
@@ -114,19 +118,17 @@
   * @retval 1: pBuffer identical to pBuffer1
   *         0: pBuffer differs from pBuffer1
   */
-static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength)
+static uint8_t Buffercmp(uint32_t *pBuffer1, uint32_t *pBuffer2, uint16_t BufferLength)
 {
-  while (BufferLength--)
-  {
-    if (*pBuffer1 != *pBuffer2)
-    {
-      return 1;
+    while (BufferLength--) {
+        if (*pBuffer1 != *pBuffer2) {
+            return 1;
+        }
+
+        pBuffer1++;
+        pBuffer2++;
     }
 
-    pBuffer1++;
-    pBuffer2++;
-  }
-
-  return 0;
+    return 0;
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Nov 20 12:55:12 2019 +0100
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#699372421a3b388fe568e9be85b1a985749a438f
--- a/mbed.bld	Fri Jun 09 08:35:40 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/0f02307a0877
\ No newline at end of file