SDRAM for DISCO_F746NG basic example
Dependencies: BSP_DISCO_F746NG
Revision 3:2bd1b98de6ec, committed 2019-11-20
- Comitter:
- Jerome Coutant
- Date:
- Wed Nov 20 13:27:16 2019 +0100
- Parent:
- 2:a4fa4bf7871d
- Commit message:
- Update with STM32Cube_FW_F7_V1.15.0
Changed in this revision
diff -r a4fa4bf7871d -r 2bd1b98de6ec .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Nov 20 13:27:16 2019 +0100 @@ -0,0 +1,2 @@ +BUILD +mbed-os/
diff -r a4fa4bf7871d -r 2bd1b98de6ec BSP_DISCO_F746NG.lib --- a/BSP_DISCO_F746NG.lib Thu Jun 08 07:58:28 2017 +0000 +++ b/BSP_DISCO_F746NG.lib Wed Nov 20 13:27:16 2019 +0100 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/#ee089790cdbb +https://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#1050c589b2ad
diff -r a4fa4bf7871d -r 2bd1b98de6ec SDRAM_DISCO_F746NG.lib --- a/SDRAM_DISCO_F746NG.lib Thu Jun 08 07:58:28 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/ST/code/SDRAM_DISCO_F746NG/#370f402a2219
diff -r a4fa4bf7871d -r 2bd1b98de6ec main.cpp --- a/main.cpp Thu Jun 08 07:58:28 2017 +0000 +++ b/main.cpp Wed Nov 20 13:27:16 2019 +0100 @@ -1,76 +1,56 @@ #include "mbed.h" -#include "SDRAM_DISCO_F746NG.h" - -SDRAM_DISCO_F746NG sdram; - -DigitalOut led_green(LED1); -DigitalOut led_red(LED2); - -Serial pc(USBTX, USBRX); +#include "stm32746g_discovery_sdram.h" #define BUFFER_SIZE ((uint32_t)0x0100) #define WRITE_READ_ADDR ((uint32_t)0x0800) - + void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Offset); -uint8_t CompareBuffer(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength); - +uint8_t CompareBuffer(uint32_t *pBuffer1, uint32_t *pBuffer2, uint16_t BufferLength); + int main() { uint32_t WriteBuffer[BUFFER_SIZE]; uint32_t ReadBuffer[BUFFER_SIZE]; FMC_SDRAM_CommandTypeDef SDRAMCommandStructure; - - pc.printf("\n\nSDRAM demo started\n"); - led_red = 0; - + + printf("\n\nSDRAM demo started\n"); + + BSP_SDRAM_Init(); + // Fill the write buffer FillBuffer(WriteBuffer, BUFFER_SIZE, 0xA244250F); - + // Write buffer - sdram.WriteData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, WriteBuffer, BUFFER_SIZE); - pc.printf("Write data DONE\n"); - + BSP_SDRAM_WriteData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, WriteBuffer, BUFFER_SIZE); + printf("Write data DONE\n"); + // Issue self-refresh command to SDRAM device SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_SELFREFRESH_MODE; SDRAMCommandStructure.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK2; SDRAMCommandStructure.AutoRefreshNumber = 1; SDRAMCommandStructure.ModeRegisterDefinition = 0; - if (sdram.Sendcmd(&SDRAMCommandStructure) != HAL_OK) - { - led_red = 1; - error("BSP_SDRAM_Sendcmd FAILED\n"); + if (BSP_SDRAM_Sendcmd(&SDRAMCommandStructure) != HAL_OK) { + error("BSP_SDRAM_Sendcmd FAILED\n"); } - + // SDRAM memory read back access SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_NORMAL_MODE; - if (sdram.Sendcmd(&SDRAMCommandStructure) != HAL_OK) - { - led_red = 1; - error("BSP_SDRAM_Sendcmd FAILED\n"); + if (BSP_SDRAM_Sendcmd(&SDRAMCommandStructure) != HAL_OK) { + error("BSP_SDRAM_Sendcmd FAILED\n"); } - - while(1) { - - // Read back data from the SDRAM memory - sdram.ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, ReadBuffer, BUFFER_SIZE); - pc.printf("\nRead data DONE\n"); - - // Checking data integrity - if (CompareBuffer(WriteBuffer, ReadBuffer, BUFFER_SIZE) != 0) - { - led_red = !led_red; - pc.printf("Write/Read buffers are different\n"); - } - else - { - led_green = !led_green; - pc.printf("Write/Read buffers are identical\n"); - } - - wait(1); + + // Read back data from the SDRAM memory + BSP_SDRAM_ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, ReadBuffer, BUFFER_SIZE); + printf("Read data DONE\n"); + + // Checking data integrity + if (CompareBuffer(WriteBuffer, ReadBuffer, BUFFER_SIZE) != 0) { + printf("Write/Read buffers are different\n"); + } else { + printf("Write/Read buffers are identical\n"); } } - + /** * @brief Fills buffer with user predefined data. * @param pBuffer: pointer on the buffer to fill @@ -80,15 +60,14 @@ */ void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Value) { - uint32_t tmpIndex = 0; - - /* Put in global buffer different values */ - for (tmpIndex = 0; tmpIndex < BufferLength; tmpIndex++ ) - { - pBuffer[tmpIndex] = tmpIndex + Value; - } -} - + uint32_t tmpIndex = 0; + + /* Put in global buffer different values */ + for (tmpIndex = 0; tmpIndex < BufferLength; tmpIndex++) { + pBuffer[tmpIndex] = tmpIndex + Value; + } +} + /** * @brief Compares two buffers. * @param pBuffer1, pBuffer2: buffers to be compared. @@ -96,18 +75,16 @@ * @retval 0: pBuffer2 identical to pBuffer1 * 1: pBuffer2 differs from pBuffer1 */ -uint8_t CompareBuffer(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength) +uint8_t CompareBuffer(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; }
diff -r a4fa4bf7871d -r 2bd1b98de6ec mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Wed Nov 20 13:27:16 2019 +0100 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#699372421a3b388fe568e9be85b1a985749a438f
diff -r a4fa4bf7871d -r 2bd1b98de6ec mbed.bld --- a/mbed.bld Thu Jun 08 07:58:28 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/6c34061e7c34 \ No newline at end of file