ST / Mbed 2 deprecated DISCO_F413ZH-PSRAM-demo

Dependencies:   BSP_DISCO_F413ZH mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "stm32f413h_discovery.h"
00003 #include "stm32f413h_discovery_lcd.h"
00004 #include "stm32f413h_discovery_psram.h"
00005 
00006 #define BUFFER_SIZE         ((uint32_t)0x1000)
00007 #define PSRAM_WRITE_READ_ADDR     ((uint32_t)0x0800)
00008 
00009 uint16_t sram_aTxBuffer[BUFFER_SIZE];
00010 uint16_t sram_aRxBuffer[BUFFER_SIZE];
00011 
00012 uint8_t ubSramWrite = 0, ubSramRead = 0, ubSramInit = 0, ubCompare = 0;
00013 __IO uint8_t  write_complete = 0;
00014 
00015 static void print_demo_title(void);
00016 static void Fill_Buffer(uint16_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset);
00017 static uint8_t Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength);
00018 
00019 int main()
00020 {
00021   print_demo_title();
00022 
00023   /*##-1- Configure the PSRAM device ##########################################*/
00024   if (BSP_PSRAM_Init() != PSRAM_OK)
00025   {
00026     ubSramInit++;
00027   }
00028 
00029   /*##-2- PSRAM memory read/write access ######################################*/
00030   /* Fill the buffer to write */
00031   Fill_Buffer(sram_aTxBuffer, BUFFER_SIZE, 0xC20F);
00032 
00033   /* Write data to the PSRAM memory */
00034   if (BSP_PSRAM_WriteData(PSRAM_DEVICE_ADDR + PSRAM_WRITE_READ_ADDR, sram_aTxBuffer, BUFFER_SIZE) != PSRAM_OK)
00035   {
00036     ubSramWrite++;
00037   }
00038 
00039   /* Read back data from the PSRAM memory */
00040   if (BSP_PSRAM_ReadData(PSRAM_DEVICE_ADDR + PSRAM_WRITE_READ_ADDR, sram_aRxBuffer, BUFFER_SIZE) != PSRAM_OK)
00041   {
00042     ubSramRead++;
00043   }
00044 
00045   /*##-3- Checking data integrity ############################################*/
00046   /* Enable the LCD */
00047   BSP_LCD_DisplayOn();
00048 
00049   if (ubSramInit != 0)
00050   {
00051     BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"PSRAM Initialization FAIL", LEFT_MODE);
00052     BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM Test Aborted", LEFT_MODE);
00053     while(1);
00054   }
00055   else
00056   {
00057     BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"PSRAM Initialization OK", LEFT_MODE);
00058   }
00059   
00060   if (ubSramWrite != 0)
00061   {
00062     BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM WRITE FAIL", LEFT_MODE);
00063     BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM Test Aborted", LEFT_MODE);
00064     while(1);
00065   }
00066   else
00067   {
00068     BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM WRITE OK", LEFT_MODE);
00069   }
00070 
00071   if (ubSramRead != 0)
00072   {
00073     BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM READ FAIL", LEFT_MODE);
00074     BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM Test Aborted", LEFT_MODE);
00075     while(1);
00076   }
00077   else
00078   {
00079     BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM READ OK", LEFT_MODE);
00080   }
00081 
00082   if (Buffercmp(sram_aRxBuffer, sram_aTxBuffer, BUFFER_SIZE) > 0)
00083   {
00084     BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM COMPARE FAIL", LEFT_MODE);
00085     BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"PSRAM Test Aborted", LEFT_MODE);
00086     while(1);
00087   }
00088   else
00089   {
00090     BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM Test OK", LEFT_MODE);
00091   }
00092 
00093   BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)"Demo finished OK", CENTER_MODE);
00094   while(1);
00095 }
00096 
00097 static void print_demo_title(void)
00098 {
00099   BSP_LCD_Init();
00100 
00101   /* Clear the LCD */
00102   BSP_LCD_Clear(LCD_COLOR_WHITE);
00103 
00104   /* Set LCD Demo description */
00105   BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
00106   BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 80);
00107   BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
00108   BSP_LCD_SetBackColor(LCD_COLOR_GREEN);
00109   BSP_LCD_SetFont(&Font24);
00110   BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"PSRAM", CENTER_MODE);
00111   BSP_LCD_SetFont(&Font12);
00112   BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"This example shows how to write", CENTER_MODE);
00113   BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"and read data on the PSRAM", CENTER_MODE);
00114 
00115    /* Set the LCD Text Color */
00116   BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
00117   BSP_LCD_DrawRect(10, 90, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize()- 100);
00118   BSP_LCD_DrawRect(11, 91, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize()- 102);
00119 
00120   BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
00121   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
00122   
00123   /* Disable the LCD to avoid refresh from the SDRAM */
00124   BSP_LCD_DisplayOff();
00125 }
00126 
00127 /**
00128   * @brief  Fills buffer with user predefined data.
00129   * @param  pBuffer: pointer on the buffer to fill
00130   * @param  uwBufferLength: size of the buffer to fill
00131   * @param  uwOffset: first value to fill on the buffer
00132   * @retval None
00133   */
00134 static void Fill_Buffer(uint16_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset)
00135 {
00136   uint32_t tmpindex = 0;
00137 
00138   /* Put in global buffer different values */
00139   for (tmpindex = 0; tmpindex < uwBufferLength; tmpindex++ )
00140   {
00141     pBuffer[tmpindex] = tmpindex + uwOffset;
00142   }
00143 }
00144 
00145 /**
00146   * @brief  Compares two buffers.
00147   * @param  pBuffer1, pBuffer2: buffers to be compared.
00148   * @param  BufferLength: buffer's length
00149   * @retval 1: pBuffer identical to pBuffer1
00150   *         0: pBuffer differs from pBuffer1
00151   */
00152 static uint8_t Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength)
00153 {
00154   while (BufferLength--)
00155   {
00156     if (*pBuffer1 != *pBuffer2)
00157     {
00158       return 1;
00159     }
00160 
00161     pBuffer1++;
00162     pBuffer2++;
00163   }
00164 
00165   return 0;
00166 }