![](/media/cache/profiles/1f50893f80d6830d62765ffad7721742.50x50_q85.jpg)
Quick but comprehensive memory test for the LPC4088's 32MB of SDRAM. The demonstration program executes a single test pass, though it can be easily modified for multiple passes. If a memory error is detected, the test stops immediately and displays failed results. A single pass is performed in less than one second and every memory location contains unique data.
main.cpp@0:947ff5fa24c6, 2013-12-31 (annotated)
- Committer:
- loopsva
- Date:
- Tue Dec 31 17:38:48 2013 +0000
- Revision:
- 0:947ff5fa24c6
- Child:
- 1:b2b9d3920781
Initial release of a demonstration memory test for the LPC4088.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
loopsva | 0:947ff5fa24c6 | 1 | #include "mbed.h" |
loopsva | 0:947ff5fa24c6 | 2 | #include "sdram.h" |
loopsva | 0:947ff5fa24c6 | 3 | |
loopsva | 0:947ff5fa24c6 | 4 | Serial pc(USBTX, USBRX); //Serial USB communications over mbed USB port |
loopsva | 0:947ff5fa24c6 | 5 | DigitalOut led1(LED1); |
loopsva | 0:947ff5fa24c6 | 6 | |
loopsva | 0:947ff5fa24c6 | 7 | //--------------------------------------------------------------------------------------------------------------------------------------// |
loopsva | 0:947ff5fa24c6 | 8 | //Test the SDRAM array with pseudo-random data |
loopsva | 0:947ff5fa24c6 | 9 | //memory size = 0x00800000 (8388608 locations * 4 bytes wide = 33.554432 MB |
loopsva | 0:947ff5fa24c6 | 10 | |
loopsva | 0:947ff5fa24c6 | 11 | #define DRAMBASEADDR 0xa0000000 |
loopsva | 0:947ff5fa24c6 | 12 | #define DRAMSIZE 0x00800000 |
loopsva | 0:947ff5fa24c6 | 13 | |
loopsva | 0:947ff5fa24c6 | 14 | int testSDRAM(uint32_t seed) { |
loopsva | 0:947ff5fa24c6 | 15 | volatile uint32_t * const ramBaseAddr = (uint32_t *) DRAMBASEADDR; |
loopsva | 0:947ff5fa24c6 | 16 | uint32_t lfsr = seed; |
loopsva | 0:947ff5fa24c6 | 17 | uint32_t offsAddr = 0; |
loopsva | 0:947ff5fa24c6 | 18 | |
loopsva | 0:947ff5fa24c6 | 19 | //Fill all memory with pseudo-random data |
loopsva | 0:947ff5fa24c6 | 20 | pc.printf(" - Filling all memory, starting with PR seed 0x%08x... ", lfsr); |
loopsva | 0:947ff5fa24c6 | 21 | for(offsAddr = 0; offsAddr < DRAMSIZE; offsAddr += 4) { |
loopsva | 0:947ff5fa24c6 | 22 | lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xD0000001u); |
loopsva | 0:947ff5fa24c6 | 23 | ramBaseAddr[offsAddr] = lfsr; |
loopsva | 0:947ff5fa24c6 | 24 | } |
loopsva | 0:947ff5fa24c6 | 25 | |
loopsva | 0:947ff5fa24c6 | 26 | //force error at highest memory location |
loopsva | 0:947ff5fa24c6 | 27 | //ramBaseAddr[0x007ffffc] = 0x12345678; |
loopsva | 0:947ff5fa24c6 | 28 | |
loopsva | 0:947ff5fa24c6 | 29 | //Now compare all that has been written |
loopsva | 0:947ff5fa24c6 | 30 | pc.printf("done\r\n - Comparing all memory locations... "); |
loopsva | 0:947ff5fa24c6 | 31 | lfsr = seed; |
loopsva | 0:947ff5fa24c6 | 32 | for(offsAddr = 0; offsAddr < DRAMSIZE; offsAddr += 4) { |
loopsva | 0:947ff5fa24c6 | 33 | lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xD0000001u); |
loopsva | 0:947ff5fa24c6 | 34 | if(ramBaseAddr[offsAddr] != lfsr) { |
loopsva | 0:947ff5fa24c6 | 35 | pc.printf("\r\n### Memory compare error!!! addr: %08x sent: %08x recvd: %08x\r\n", offsAddr + DRAMBASEADDR, lfsr, ramBaseAddr[offsAddr]); |
loopsva | 0:947ff5fa24c6 | 36 | return -1; |
loopsva | 0:947ff5fa24c6 | 37 | } |
loopsva | 0:947ff5fa24c6 | 38 | } |
loopsva | 0:947ff5fa24c6 | 39 | |
loopsva | 0:947ff5fa24c6 | 40 | //print first DRAM locations |
loopsva | 0:947ff5fa24c6 | 41 | pc.printf("done\r\n"); |
loopsva | 0:947ff5fa24c6 | 42 | |
loopsva | 0:947ff5fa24c6 | 43 | //Option to print out first few locations of SDRAM |
loopsva | 0:947ff5fa24c6 | 44 | //for(offsAddr = 0; offsAddr < 1024; offsAddr += 16) { |
loopsva | 0:947ff5fa24c6 | 45 | // pc.printf("addr: %08x 0: %08x 4: %08x 8: %08x c: %08x\r\n", DRAMBASEADDR + offsAddr, ramBaseAddr[offsAddr], |
loopsva | 0:947ff5fa24c6 | 46 | // ramBaseAddr[offsAddr + 4], ramBaseAddr[offsAddr + 8], ramBaseAddr[offsAddr + 12]); |
loopsva | 0:947ff5fa24c6 | 47 | //} |
loopsva | 0:947ff5fa24c6 | 48 | return 0; |
loopsva | 0:947ff5fa24c6 | 49 | } |
loopsva | 0:947ff5fa24c6 | 50 | |
loopsva | 0:947ff5fa24c6 | 51 | //--------------------------------------------------------------------------------------------------------------------------------------// |
loopsva | 0:947ff5fa24c6 | 52 | //Initialize the 32MB SDRAM and test it. |
loopsva | 0:947ff5fa24c6 | 53 | |
loopsva | 0:947ff5fa24c6 | 54 | #define ONEMBDRAMSIZE (1024*1024) |
loopsva | 0:947ff5fa24c6 | 55 | |
loopsva | 0:947ff5fa24c6 | 56 | int alloccount = 0; |
loopsva | 0:947ff5fa24c6 | 57 | unsigned char *ptr[100] ; |
loopsva | 0:947ff5fa24c6 | 58 | |
loopsva | 0:947ff5fa24c6 | 59 | int initSDRAM() { |
loopsva | 0:947ff5fa24c6 | 60 | pc.printf("Initializing 32MB SDRAM\r\n"); |
loopsva | 0:947ff5fa24c6 | 61 | if (sdram_init() == 1) { |
loopsva | 0:947ff5fa24c6 | 62 | pc.printf(" - Failed to initialize SDRAM\r\n"); |
loopsva | 0:947ff5fa24c6 | 63 | return 1; |
loopsva | 0:947ff5fa24c6 | 64 | } |
loopsva | 0:947ff5fa24c6 | 65 | |
loopsva | 0:947ff5fa24c6 | 66 | while(1) { |
loopsva | 0:947ff5fa24c6 | 67 | ptr[alloccount] = (unsigned char *)malloc(ONEMBDRAMSIZE); |
loopsva | 0:947ff5fa24c6 | 68 | //pc.printf (" - Allocated Address = %08x %2d\r\n", ptr[alloccount], alloccount); |
loopsva | 0:947ff5fa24c6 | 69 | if(ptr[alloccount] == NULL) { |
loopsva | 0:947ff5fa24c6 | 70 | pc.printf(" - Maximum allocatable DRAM memory %dMB\r\n", alloccount); |
loopsva | 0:947ff5fa24c6 | 71 | for (int i = 0; i < alloccount; i++) { |
loopsva | 0:947ff5fa24c6 | 72 | free(ptr[i]); |
loopsva | 0:947ff5fa24c6 | 73 | } |
loopsva | 0:947ff5fa24c6 | 74 | alloccount = 0; |
loopsva | 0:947ff5fa24c6 | 75 | uint32_t StartSeed = 0xbad1deaf; |
loopsva | 0:947ff5fa24c6 | 76 | int testresult = testSDRAM(StartSeed); |
loopsva | 0:947ff5fa24c6 | 77 | if(testresult) return(testresult); |
loopsva | 0:947ff5fa24c6 | 78 | break; |
loopsva | 0:947ff5fa24c6 | 79 | } else { |
loopsva | 0:947ff5fa24c6 | 80 | alloccount++ ; |
loopsva | 0:947ff5fa24c6 | 81 | } |
loopsva | 0:947ff5fa24c6 | 82 | } |
loopsva | 0:947ff5fa24c6 | 83 | return 0; |
loopsva | 0:947ff5fa24c6 | 84 | } |
loopsva | 0:947ff5fa24c6 | 85 | |
loopsva | 0:947ff5fa24c6 | 86 | //--------------------------------------------------------------------------------------------------------------------------------------// |
loopsva | 0:947ff5fa24c6 | 87 | //--------------------------------------------------------------------------------------------------------------------------------------// |
loopsva | 0:947ff5fa24c6 | 88 | |
loopsva | 0:947ff5fa24c6 | 89 | int main(void) { |
loopsva | 0:947ff5fa24c6 | 90 | |
loopsva | 0:947ff5fa24c6 | 91 | pc.baud(460800); |
loopsva | 0:947ff5fa24c6 | 92 | pc.printf("\r\n\r\nLPC4088 SDRAM memory test\r\n"); |
loopsva | 0:947ff5fa24c6 | 93 | initSDRAM(); |
loopsva | 0:947ff5fa24c6 | 94 | |
loopsva | 0:947ff5fa24c6 | 95 | while(1) { |
loopsva | 0:947ff5fa24c6 | 96 | wait_ms(500); |
loopsva | 0:947ff5fa24c6 | 97 | led1 = !led1; |
loopsva | 0:947ff5fa24c6 | 98 | } |
loopsva | 0:947ff5fa24c6 | 99 | } |
loopsva | 0:947ff5fa24c6 | 100 | |
loopsva | 0:947ff5fa24c6 | 101 |