Library 14- Working with SDRAM on STM32F429 Discovery
STM32F429 Discovery board has external 64Mbits or 8MBytes SDRAM chip ISSI IS42S16400.
STM32F429 has a FMC (Flexible Memory Control) peripheral to driving external SDRAM with hardware. FMC hardware is able to store up to 32bits variables at same time.
Variable size | Max value | Max address | Max variables stored |
---|---|---|---|
8bit | 0xFF | 0x7FFFFF | 8388608 |
16bit | 0xFFFF | 0x7FFFFE | 4194304 |
32bit | 0xFFFFFFFF | 0x7FFFFC | 2097152 |
Note: This library does not work on STM32F4 Discovery, because this MCU does not have FMC peripheral.
8MByte is a lot for that microcontroller, but can be very useful if you are working with LCD (storing images, …) which can increase LCD’s refresh rate.
In Standard Peripheral libraries pack is also included FMC example for SDRAM. I modified settings for our board and make a simple library.
SDRAM library
Features
- Operates with external 64Mb SDRAM
- Functions to read/write 8, 16 or 32bit variable at a time
- Version 1.1 – November 23, 2014
- Functions for read/write are now defined as macros. This allows you to increase speed performance because you don’t need to call functions and put data to the stack
- Supports STM32F429-Discovery or STM324x9-EVAL boards
Dependencies
- CMSIS
- STM32F4xx
- STM32F4xx RCC
- STM32F4xx GPIO
- STM32F4xx FMC
- TM
- TM GPIO
- defines.h
- attributes.h
- TM GPIO
STM324x9-EVAL support
By default, library is designed for low cost STM32F429-Discovery board. If you want to use this library on STM324x9-EVAL board, open defines.h file and add define:
1 2 |
/* Use SDRAM on STM324x9-EVAL board */ #define SDRAM_USE_STM324x9_EVAL |
Initialize
As always, here is the same. First we have to initialize SDRAM library. This is done with
1 2 3 4 |
//Initialize SDRAM if (TM_SDRAM_Init()) { //Initialization is ok } |
Function returns 1 if sdram was properly initialized, to check this, function just simple write data to SDRAM’s location and read it back. If they are the same, everything is OK.
Write operation
For writing data to SDRAM I made 3 functions.
1 2 3 4 5 6 |
//Write 8bit variable to SDRAM TM_SDRAM_Write8(location, 8bitvalue); //Write 16bit variable to SDRAM TM_SDRAM_Write16(location, 16bitvalue); //Write 32bit variable to SDRAM TM_SDRAM_Write32(location, 32bitvalue); |
Read operation
1 2 3 4 5 6 |
//Read 8bit variable from SDRAM 8bitvalue = TM_SDRAM_Read8(location); //Read 16bit variable from SDRAM 16bitvalue = TM_SDRAM_Read16(location); //Read 32bit variable from SDRAM 32bitvalue = TM_SDRAM_Read32(location); |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
/** * Keil project for SDRAM connected on STM32F429 Discovery board * * Works only for STM32F429-Discovery board or STM324x9-EVAL boards * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision 5 * @packs STM32F4xx Keil packs version 2.2.0 or greater required * @stdperiph STM32F4xx Standard peripheral drivers version 1.4.0 or greater required */ /* Include core modules */ #include "stm32f4xx.h" /* Include my libraries here */ #include "defines.h" #include "tm_stm32f4_disco.h" #include "tm_stm32f4_sdram.h" #include "tm_stm32f4_delay.h" int main(void) { uint16_t write, read; uint8_t i; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize leds */ TM_DISCO_LedInit(); /* Initialize SDRAM */ if (TM_SDRAM_Init()) { TM_DISCO_LedOn(LED_GREEN); } else { TM_DISCO_LedOn(LED_RED); } /* Some delay */ Delayms(2000); write = 1234; /* Write 16bit value to SDRAM at location 0x3214 */ TM_SDRAM_Write16(0x3214, write); /* Read from location 0x3214 */ read = TM_SDRAM_Read16(0x3214); /* Check if read data is the same as written data */ if (write == read) { TM_DISCO_LedOff(LED_GREEN | LED_RED); /* Blink leds to indicate that reading and writing was correct */ for (i = 0; i < 10; i++) { TM_DISCO_LedToggle(LED_GREEN | LED_RED); Delayms(100); } } while (1) { } } |
Project available on Github, download library below.
External SDRAM on STM32F429 Discovery board
Recent comments