Boot Loader to Auto-Size RAM

We have two boards, one with 32-bit RAM, one with 16-bit RAM, and I’d like to have one boot loader that handles both. The code below detects 16 vs 32, but for some reason doesn’t switch to the 16-bit bus. What am I doing wrong? RAMLOAD EQU 0x00010000 MEM_CS1_CSAR EQU 0xffc00020 ; cs1 = sdram MEM_CS1_CSAR_v EQU 0x0000022d ; mapped to 0 MEM_CS1_CSOR EQU 0xffc00024 ; x,2,2,2 16MB SDRAM space MEM_CS1_CSOR_32 EQU 0xf3000070 ; x,2,2,2 8MB SDRAM space MEM_CS1_CSOR_16 EQU 0xf3800074 ; Map CS1 for either 16MB of 32-bit RAM ; or 8MB of 16-bit RAM. ldr r0, =MEM_CS1_CSOR ; Assume 32 bit ldr r1, =MEM_CS1_CSOR_32 str r1, [r0] ldr r0, =MEM_CS1_CSAR ldr r1, =MEM_CS1_CSAR_v str r1, [r0] ldr r2, =RAMLOAD ; Write a 32-bit ldr r1, =0xDEADBEEF ; random value 8o) str r1, [r2] ldr r3, [r2] cmp r1, r3 ; Read back same? beq ram_configured ldr r0, =MEM_CS1_CSOR ; Make it 16-bit ldr r1, =MEM_CS1_CSOR_16 str r1, [r0] ldr r0, =MEM_CS1_CSAR ldr r1, =MEM_CS1_CSAR_v str r1, [r0]

In the past we used one of the gpio lines to detect which board we had and we set the SDRAM accordingly. The init.s file explains this by all means and after that we attempt auto-detect the type of RAM which is attached to the CS1 peripheral like below: You should refer to this… Configure DRAM Refresh for a 15uS Period using an external DRAM multiplexer. If RAM can be found, let’s use this configuration. (*NCC_MEM).mmcr.reg = 0x0dd00000; LDR R0, =MEM_MMCR LDR R1, =MEM_MMCR_v STR R1, [R0] try_SDRAM_32: LDR R6, =MEM_CS1_CSAR LDR R7, =MEM_CS1_CSOR MOV R8, #0 # clear cs1 Address Register [stored in R6] STR R8, [R6] # cs1 Option Register [stored in R7] LDR R1, =0xffc00070 STR R1, [R7] # setup cs1 Address Register [stored in R6] to SDRAM type – store in R9 LDR R9, =0x0000022d STR R9, [R6] # run the burst test BL ram_test_burst # if it returns zero – then the RAM type is 32 bit SD RAM CMP R0, #0 BEQ cs1_configured # Let’s see if we have 16-bit SDRAM Available try_SDRAM_16: # clear cs1 Address Register [stored in R6] STR R8, [R6] # cs1 Option Register [stored in R7] LDR R1, =0xffc00074 STR R1, [R7] # setup cs1 Address Register [stored in R6] to SDRAM type – stored in R9 STR R9, [R6] # run the burst test – burst test succeeds if r0 == 0 BL ram_test_burst # if it returns zero – then the RAM type is 16 bit SD RAM CMP R0, #0 BEQ cs1_configured

I’m doing all exactly the same things (for SDRAM), except I’m not resetting the MEM_CS1_CSAR to zero before trying to switch to 16-bit mode. I added that in and it made no difference. I’m still stumped. It’s not really critical, but very annoying.

you have to set valid bit to 0 before you change the register value then ,set it back to one, then it will take effect