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