SDRAM demo, Think this is needed to store the audio and vibration before it gets wriitten to the SD.

Dependencies:   BSP_DISCO_F769NI

Committer:
matthewlezcano
Date:
Fri Jul 10 20:30:30 2020 +0000
Revision:
0:b1919ed2e9f3
none;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matthewlezcano 0:b1919ed2e9f3 1 #include "mbed.h"
matthewlezcano 0:b1919ed2e9f3 2 #include "stm32f769i_discovery_lcd.h"
matthewlezcano 0:b1919ed2e9f3 3 #include "stm32f769i_discovery_sdram.h"
matthewlezcano 0:b1919ed2e9f3 4
matthewlezcano 0:b1919ed2e9f3 5 static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset);
matthewlezcano 0:b1919ed2e9f3 6 static uint8_t Buffercmp(uint32_t *pBuffer1, uint32_t *pBuffer2, uint16_t BufferLength);
matthewlezcano 0:b1919ed2e9f3 7
matthewlezcano 0:b1919ed2e9f3 8 #define BUFFER_SIZE ((uint32_t)0x0100)
matthewlezcano 0:b1919ed2e9f3 9 #define WRITE_READ_ADDR ((uint32_t)0x0800)
matthewlezcano 0:b1919ed2e9f3 10 #define SDRAM_WRITE_READ_ADDR ((uint32_t)0xC0177000)
matthewlezcano 0:b1919ed2e9f3 11
matthewlezcano 0:b1919ed2e9f3 12 uint32_t sdram_aTxBuffer[BUFFER_SIZE];
matthewlezcano 0:b1919ed2e9f3 13 uint32_t sdram_aRxBuffer[BUFFER_SIZE];
matthewlezcano 0:b1919ed2e9f3 14
matthewlezcano 0:b1919ed2e9f3 15 int main()
matthewlezcano 0:b1919ed2e9f3 16 {
matthewlezcano 0:b1919ed2e9f3 17 printf("\n\n SDRAM EXAMPLE FOR DISCO-F769NI START:\n");
matthewlezcano 0:b1919ed2e9f3 18
matthewlezcano 0:b1919ed2e9f3 19 /* Init LCD and display example information */
matthewlezcano 0:b1919ed2e9f3 20 BSP_LCD_Init();
matthewlezcano 0:b1919ed2e9f3 21 BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
matthewlezcano 0:b1919ed2e9f3 22 BSP_LCD_Clear(LCD_COLOR_WHITE);
matthewlezcano 0:b1919ed2e9f3 23 BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
matthewlezcano 0:b1919ed2e9f3 24 BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40);
matthewlezcano 0:b1919ed2e9f3 25 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
matthewlezcano 0:b1919ed2e9f3 26 BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
matthewlezcano 0:b1919ed2e9f3 27 BSP_LCD_SetFont(&Font24);
matthewlezcano 0:b1919ed2e9f3 28 BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"SDRAM basic example", CENTER_MODE);
matthewlezcano 0:b1919ed2e9f3 29
matthewlezcano 0:b1919ed2e9f3 30 HAL_Delay(2000);
matthewlezcano 0:b1919ed2e9f3 31
matthewlezcano 0:b1919ed2e9f3 32 /* SDRAM device configuration */
matthewlezcano 0:b1919ed2e9f3 33 if (BSP_SDRAM_Init() != SDRAM_OK) {
matthewlezcano 0:b1919ed2e9f3 34 BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SDRAM Initialization : FAILED", LEFT_MODE);
matthewlezcano 0:b1919ed2e9f3 35 } else {
matthewlezcano 0:b1919ed2e9f3 36 BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"SDRAM Initialization : OK", LEFT_MODE);
matthewlezcano 0:b1919ed2e9f3 37 }
matthewlezcano 0:b1919ed2e9f3 38 /* Fill the buffer to write */
matthewlezcano 0:b1919ed2e9f3 39 Fill_Buffer(sdram_aTxBuffer, BUFFER_SIZE, 0xA244250F);
matthewlezcano 0:b1919ed2e9f3 40
matthewlezcano 0:b1919ed2e9f3 41 HAL_Delay(2000);
matthewlezcano 0:b1919ed2e9f3 42
matthewlezcano 0:b1919ed2e9f3 43 /* Write data to the SDRAM memory */
matthewlezcano 0:b1919ed2e9f3 44 if (BSP_SDRAM_WriteData(SDRAM_WRITE_READ_ADDR + WRITE_READ_ADDR, sdram_aTxBuffer, BUFFER_SIZE) != SDRAM_OK) {
matthewlezcano 0:b1919ed2e9f3 45 BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SDRAM WRITE : FAILED", LEFT_MODE);
matthewlezcano 0:b1919ed2e9f3 46 } else {
matthewlezcano 0:b1919ed2e9f3 47 BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"SDRAM WRITE : OK", LEFT_MODE);
matthewlezcano 0:b1919ed2e9f3 48 }
matthewlezcano 0:b1919ed2e9f3 49
matthewlezcano 0:b1919ed2e9f3 50 HAL_Delay(2000);
matthewlezcano 0:b1919ed2e9f3 51
matthewlezcano 0:b1919ed2e9f3 52 /* Read back data from the SDRAM memory */
matthewlezcano 0:b1919ed2e9f3 53 if (BSP_SDRAM_ReadData(SDRAM_WRITE_READ_ADDR + WRITE_READ_ADDR, sdram_aRxBuffer, BUFFER_SIZE) != SDRAM_OK) {
matthewlezcano 0:b1919ed2e9f3 54 BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SDRAM READ : FAILED", LEFT_MODE);
matthewlezcano 0:b1919ed2e9f3 55 } else {
matthewlezcano 0:b1919ed2e9f3 56 BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"SDRAM READ : OK", LEFT_MODE);
matthewlezcano 0:b1919ed2e9f3 57 }
matthewlezcano 0:b1919ed2e9f3 58
matthewlezcano 0:b1919ed2e9f3 59 HAL_Delay(2000);
matthewlezcano 0:b1919ed2e9f3 60
matthewlezcano 0:b1919ed2e9f3 61 if (Buffercmp(sdram_aTxBuffer, sdram_aRxBuffer, BUFFER_SIZE) > 0) {
matthewlezcano 0:b1919ed2e9f3 62 BSP_LCD_DisplayStringAt(20, 190, (uint8_t *)"SDRAM COMPARE : FAILED", LEFT_MODE);
matthewlezcano 0:b1919ed2e9f3 63 } else {
matthewlezcano 0:b1919ed2e9f3 64 BSP_LCD_DisplayStringAt(20, 190, (uint8_t *)"SDRAM Test : OK", LEFT_MODE);
matthewlezcano 0:b1919ed2e9f3 65 }
matthewlezcano 0:b1919ed2e9f3 66
matthewlezcano 0:b1919ed2e9f3 67 while (1) {
matthewlezcano 0:b1919ed2e9f3 68
matthewlezcano 0:b1919ed2e9f3 69 }
matthewlezcano 0:b1919ed2e9f3 70 }
matthewlezcano 0:b1919ed2e9f3 71
matthewlezcano 0:b1919ed2e9f3 72
matthewlezcano 0:b1919ed2e9f3 73 /**
matthewlezcano 0:b1919ed2e9f3 74 * @brief Fills buffer with user predefined data.
matthewlezcano 0:b1919ed2e9f3 75 * @param pBuffer: pointer on the buffer to fill
matthewlezcano 0:b1919ed2e9f3 76 * @param uwBufferLenght: size of the buffer to fill
matthewlezcano 0:b1919ed2e9f3 77 * @param uwOffset: first value to fill on the buffer
matthewlezcano 0:b1919ed2e9f3 78 * @retval None
matthewlezcano 0:b1919ed2e9f3 79 */
matthewlezcano 0:b1919ed2e9f3 80 static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset)
matthewlezcano 0:b1919ed2e9f3 81 {
matthewlezcano 0:b1919ed2e9f3 82 uint32_t tmpIndex = 0;
matthewlezcano 0:b1919ed2e9f3 83
matthewlezcano 0:b1919ed2e9f3 84 /* Put in global buffer different values */
matthewlezcano 0:b1919ed2e9f3 85 for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++) {
matthewlezcano 0:b1919ed2e9f3 86 pBuffer[tmpIndex] = tmpIndex + uwOffset;
matthewlezcano 0:b1919ed2e9f3 87 }
matthewlezcano 0:b1919ed2e9f3 88 }
matthewlezcano 0:b1919ed2e9f3 89
matthewlezcano 0:b1919ed2e9f3 90 /**
matthewlezcano 0:b1919ed2e9f3 91 * @brief Compares two buffers.
matthewlezcano 0:b1919ed2e9f3 92 * @param pBuffer1, pBuffer2: buffers to be compared.
matthewlezcano 0:b1919ed2e9f3 93 * @param BufferLength: buffer's length
matthewlezcano 0:b1919ed2e9f3 94 * @retval 1: pBuffer identical to pBuffer1
matthewlezcano 0:b1919ed2e9f3 95 * 0: pBuffer differs from pBuffer1
matthewlezcano 0:b1919ed2e9f3 96 */
matthewlezcano 0:b1919ed2e9f3 97 static uint8_t Buffercmp(uint32_t *pBuffer1, uint32_t *pBuffer2, uint16_t BufferLength)
matthewlezcano 0:b1919ed2e9f3 98 {
matthewlezcano 0:b1919ed2e9f3 99 while (BufferLength--) {
matthewlezcano 0:b1919ed2e9f3 100 if (*pBuffer1 != *pBuffer2) {
matthewlezcano 0:b1919ed2e9f3 101 return 1;
matthewlezcano 0:b1919ed2e9f3 102 }
matthewlezcano 0:b1919ed2e9f3 103
matthewlezcano 0:b1919ed2e9f3 104 pBuffer1++;
matthewlezcano 0:b1919ed2e9f3 105 pBuffer2++;
matthewlezcano 0:b1919ed2e9f3 106 }
matthewlezcano 0:b1919ed2e9f3 107
matthewlezcano 0:b1919ed2e9f3 108 return 0;
matthewlezcano 0:b1919ed2e9f3 109 }