PSRAM example.
Dependencies: BSP_DISCO_F413ZH mbed
Revision 1:61482ef96890, committed 2017-09-27
- Comitter:
- bcostm
- Date:
- Wed Sep 27 07:47:28 2017 +0000
- Parent:
- 0:e86d70f1f2ce
- Commit message:
- Add mbed library v151 + BSP library + improvements
Changed in this revision
diff -r e86d70f1f2ce -r 61482ef96890 BSP_DISCO_F413ZH.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BSP_DISCO_F413ZH.lib Wed Sep 27 07:47:28 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/BSP_DISCO_F413ZH/#0f07a9ac06f7
diff -r e86d70f1f2ce -r 61482ef96890 main.cpp --- a/main.cpp Tue May 23 10:50:50 2017 +0200 +++ b/main.cpp Wed Sep 27 07:47:28 2017 +0000 @@ -3,48 +3,25 @@ #include "stm32f413h_discovery_lcd.h" #include "stm32f413h_discovery_psram.h" -/** @addtogroup STM32F7xx_HAL_Examples - * @{ - */ - -/** @addtogroup BSP - * @{ - */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ #define BUFFER_SIZE ((uint32_t)0x1000) #define PSRAM_WRITE_READ_ADDR ((uint32_t)0x0800) -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ + uint16_t sram_aTxBuffer[BUFFER_SIZE]; uint16_t sram_aRxBuffer[BUFFER_SIZE]; + uint8_t ubSramWrite = 0, ubSramRead = 0, ubSramInit = 0, ubCompare = 0; __IO uint8_t write_complete = 0; -/* Private function prototypes -----------------------------------------------*/ -static void PSRAM_SetHint(void); + +static void print_demo_title(void); static void Fill_Buffer(uint16_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset); static uint8_t Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); -static uint8_t CheckForUserInput(void); -/* Private functions ---------------------------------------------------------*/ -/** - * @brief PSRAM Demo - * @param None - * @retval None - */ int main() { - BSP_LCD_Init(); - - PSRAM_SetHint(); - - /* Disable the LCD to avoid the refrech from the SDRAM */ - BSP_LCD_DisplayOff(); + print_demo_title(); /*##-1- Configure the PSRAM device ##########################################*/ - /* PSRAM device configuration */ - if(BSP_PSRAM_Init() != PSRAM_OK) + if (BSP_PSRAM_Init() != PSRAM_OK) { ubSramInit++; } @@ -54,13 +31,13 @@ Fill_Buffer(sram_aTxBuffer, BUFFER_SIZE, 0xC20F); /* Write data to the PSRAM memory */ - if(BSP_PSRAM_WriteData(PSRAM_DEVICE_ADDR + PSRAM_WRITE_READ_ADDR, sram_aTxBuffer, BUFFER_SIZE) != PSRAM_OK) + if (BSP_PSRAM_WriteData(PSRAM_DEVICE_ADDR + PSRAM_WRITE_READ_ADDR, sram_aTxBuffer, BUFFER_SIZE) != PSRAM_OK) { ubSramWrite++; } /* Read back data from the PSRAM memory */ - if(BSP_PSRAM_ReadData(PSRAM_DEVICE_ADDR + PSRAM_WRITE_READ_ADDR, sram_aRxBuffer, BUFFER_SIZE) != PSRAM_OK) + if (BSP_PSRAM_ReadData(PSRAM_DEVICE_ADDR + PSRAM_WRITE_READ_ADDR, sram_aRxBuffer, BUFFER_SIZE) != PSRAM_OK) { ubSramRead++; } @@ -69,158 +46,58 @@ /* Enable the LCD */ BSP_LCD_DisplayOn(); - if(ubSramInit != 0) - { - BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"PSRAM Initialization : FAILED.", LEFT_MODE); - BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM Test Aborted.", LEFT_MODE); - ubSramInit = 0xFF; - } - else + if (ubSramInit != 0) { - BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"PSRAM Initialization : OK.", LEFT_MODE); - ubSramInit = 0; - } - if(ubSramWrite != 0) - { - BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM WRITE : FAILED.", LEFT_MODE); - BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM Test Aborted.", LEFT_MODE); - ubSramWrite = 0xFF; + BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"PSRAM Initialization FAIL", LEFT_MODE); + BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM Test Aborted", LEFT_MODE); + while(1); } else { - BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM WRITE : OK.", LEFT_MODE); - ubSramWrite = 0; - } - if(ubSramRead != 0) - { - BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM READ : FAILED.", LEFT_MODE); - BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM Test Aborted.", LEFT_MODE); - ubSramRead = 0xFF; + BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"PSRAM Initialization OK", LEFT_MODE); } - else + + if (ubSramWrite != 0) { - BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM READ : OK.", LEFT_MODE); - ubSramRead = 0; - } - - if(Buffercmp(sram_aRxBuffer, sram_aTxBuffer, BUFFER_SIZE) > 0) - { - BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM COMPARE : FAILED.", LEFT_MODE); - BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"PSRAM Test Aborted.", LEFT_MODE); - ubCompare ++; + BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM WRITE FAIL", LEFT_MODE); + BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM Test Aborted", LEFT_MODE); + while(1); } else { - BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM Test : OK.", LEFT_MODE); - ubCompare =0; + BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM WRITE OK", LEFT_MODE); } - while (1) - { - if(CheckForUserInput() > 0) - { - return 0; - } - } -} - -/** - * @brief PSRAM Demo - * @param None - * @retval None - */ -void PSRAM_DMA_demo (void) -{ - PSRAM_SetHint(); - - /* Disable the LCD to avoid the refrech from the PSRAM */ - BSP_LCD_DisplayOff(); - - /*##-1- Configure the PSRAM device ##########################################*/ - /* PSRAM device configuration */ - if(BSP_PSRAM_Init() != PSRAM_OK) + if (ubSramRead != 0) { - ubSramInit++; - } - - /*##-2- PSRAM memory read/write access ######################################*/ - /* Fill the buffer to write */ - Fill_Buffer(sram_aTxBuffer, BUFFER_SIZE, 0xC20F); - - /* Write data to the PSRAM memory */ - if(BSP_PSRAM_WriteData_DMA(PSRAM_DEVICE_ADDR + PSRAM_WRITE_READ_ADDR, sram_aTxBuffer, BUFFER_SIZE) != PSRAM_OK) - { - ubSramWrite++; - } - - - /* Wait for Transfer complete */ - while(write_complete == 0); - - /* Read back data from the PSRAM memory */ - if(BSP_PSRAM_ReadData_DMA(PSRAM_DEVICE_ADDR + PSRAM_WRITE_READ_ADDR, sram_aRxBuffer, BUFFER_SIZE) != PSRAM_OK) - { - ubSramRead++; - } - - /*##-3- Checking data integrity ############################################*/ - /* Enable the LCD */ - BSP_LCD_DisplayOn(); - - if(ubSramInit != 0) - { - BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"PSRAM Initialization : FAILED.", LEFT_MODE); - BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM Test Aborted.", LEFT_MODE); + BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM READ FAIL", LEFT_MODE); + BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM Test Aborted", LEFT_MODE); + while(1); } else { - BSP_LCD_DisplayStringAt(20, 100, (uint8_t *)"PSRAM Initialization : OK.", LEFT_MODE); - } - if(ubSramWrite != 0) - { - BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM WRITE : FAILED.", LEFT_MODE); - BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM Test Aborted.", LEFT_MODE); + BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM READ OK", LEFT_MODE); } - else + + if (Buffercmp(sram_aRxBuffer, sram_aTxBuffer, BUFFER_SIZE) > 0) { - BSP_LCD_DisplayStringAt(20, 115, (uint8_t *)"PSRAM WRITE : OK.", LEFT_MODE); - } - if(ubSramRead != 0) - { - BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM READ : FAILED.", LEFT_MODE); - BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM Test Aborted.", LEFT_MODE); + BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM COMPARE FAIL", LEFT_MODE); + BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"PSRAM Test Aborted", LEFT_MODE); + while(1); } else { - BSP_LCD_DisplayStringAt(20, 130, (uint8_t *)"PSRAM READ : OK.", LEFT_MODE); - } - - if(Buffercmp(sram_aRxBuffer, sram_aTxBuffer, BUFFER_SIZE) > 0) - { - BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM COMPARE : FAILED.", LEFT_MODE); - BSP_LCD_DisplayStringAt(20, 160, (uint8_t *)"PSRAM Test Aborted.", LEFT_MODE); - } - else - { - BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM Test : OK.", LEFT_MODE); + BSP_LCD_DisplayStringAt(20, 145, (uint8_t *)"PSRAM Test OK", LEFT_MODE); } - while (1) - { - if(CheckForUserInput() > 0) - { - return; - } - } + BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)"Demo finished OK", CENTER_MODE); + while(1); } -/** - * @brief Display PSRAM Demo Hint - * @param None - * @retval None - */ -static void PSRAM_SetHint(void) +static void print_demo_title(void) { + BSP_LCD_Init(); + /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); @@ -242,6 +119,9 @@ BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); + + /* Disable the LCD to avoid refresh from the SDRAM */ + BSP_LCD_DisplayOff(); } /** @@ -284,32 +164,3 @@ return 0; } - -/** - * @brief DMA transfer complete callback. - * @param hdma: pointer to a SRAM_HandleTypeDef structure that contains - * the configuration information for SRAM module. - * @retval None - */ -void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma) -{ - write_complete = 1; -} - -uint8_t CheckForUserInput(void) -{ - if(BSP_PB_GetState(BUTTON_WAKEUP) != GPIO_PIN_RESET) - { - while (BSP_PB_GetState(BUTTON_WAKEUP) != GPIO_PIN_RESET); - return 1 ; - } - return 0; -} -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff -r e86d70f1f2ce -r 61482ef96890 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 27 07:47:28 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/675da3299148 \ No newline at end of file