This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MCBSTM32F400 external ram

I'm using the Keil MCBSTM32F400 development board and I'd like to start using the external SRAM.

From the user's guide the SRAM uses the following pins and is at the following location:
SRAM FSMC_NE3 / PG10 0x68000000 - 0x681FFFFF

I'm having trouble accessing the memory. When trying to write, nothing happens and when reading back I always get 0xFF.

Does anyone have an example of setting up the FSMC for the Keil development board to use its external SRAM?

Is there a Keil example application that shows how to use the memory?

What I've tried so far:

In the standard system_stm32f4xx.c file, I enabled the external memory by defining DATA_IN_ExtSRAM (uncommenting).

In the SystemInit_ExtMemCtl() function I commented out three lines where they were directly configuring the FSMC_Bank1 timing and control registers; uncommented the FSMC_NORSRAMInitStructure; changed FSMC_Bank1_NORSRAM2 to FSMC_Bank1_NORSRAM3; called teh FSMC_NORSRAMInit() function with the structure; and finally added a call to FSMC_NORSRAMCmd() to enable.

I did not change any of the GPIO alternate function setup from what is in the standard system file.

I have not looked into the timing settings for the SRAM on the Keil board vs. the timing for the G_EVAL board external SRAM to see if they're different enough to change.

Any help would be greatly appreciated.

Parents
  • Hello John, Nice to meet you.

    I've got the same problem as you.

    I pasted your code but unfortunately it didn't work.

    did you do another thing apart of re-work the code?

    for exemple: in "options for target" I put in the off-chip memory Areas the address of the external SRAM memory. in the datasheet says that starts in 0x60000000 so I put this value and in size I put 0x20000(1MB)

Reply
  • Hello John, Nice to meet you.

    I've got the same problem as you.

    I pasted your code but unfortunately it didn't work.

    did you do another thing apart of re-work the code?

    for exemple: in "options for target" I put in the off-chip memory Areas the address of the external SRAM memory. in the datasheet says that starts in 0x60000000 so I put this value and in size I put 0x20000(1MB)

Children
  • I'm only using the external ram as a large buffer so I'm just assigning a pointer to address 0x68000000 then using it to store some data. I'm not trying to relocate code or data segments there.

    I did not modify the options for target although I've seen that done using the .sct file.

    If this is the Keil board, the external ram address is 0x68000000 not 0x60000000.

    In your system_stm32f4xx.c you have to uncomment #define DATA_IN_ExtSRAM.

    Hope that helps.

    John.

  • Hello all!
    Today I understood the whole day with the code proposed by John.
      But, unfortunately, was not able to make it work - even my project did not start!
    I'm also in the in "options for target", said the value of the start address 0x68000000 and size 0x200000 (not 0x20000!) - This corresponds 2MB.
    And, of course, uncomment # define DATA_IN_ExtSRAM in the file. But it did not help. All I was able to achieve - is an inscription in Keil: "Cannot access Memory" in Debug mode.

  • Do you create the pointer to the address like this: ?

     #define Bank1_SRAM2_ADDR  ((uint32_t)0x68000000)
    
    
    
    
    

  • I was working at at byte level and just hacking together something, so I used the code snippet below to write three values.

    uint8_t * p_block_addr;

    p_block_addr = (uint8_t *)0x68000000;

    *p_block_addr = 0x00;
    *(p_block_addr + 1) = 0x01;
    *(p_block_addr + 2) = 0x02;

  • And

    *p_block_addr = 0x00;
    *(p_block_addr + 1) = 0x01;
    *(p_block_addr + 2) = 0x02;
    


    can be written as

    p_block_addr[0] = 0x00;
    p_block_addr[1] = 0x01;
    p_block_addr[2] = 0x02;
    

  • Well, maybe the reason your code did,t work in my programm is because you have the data width cofigured to 8 bits instead of 16 bits like me. I'll try to run your program changing to your datawidth.

  • Excellent! Can I use an external memory to read / write the data from there.
    In system_stm32f4xx.c add this code:

    #define Bank1_NOSRAM3_ADDR  ((uint32_t)0x68000000)
    
    /**
      * @brief  Writes a Half-word buffer to the FSMC SRAM memory.
      * @param  pBuffer : pointer to buffer.
      * @param  WriteAddr : SRAM memory internal address from which the data will be
      *         written.
      * @param  NumHalfwordToWrite : number of half-words to write.
      * @retval None
      */
    void SRAM_WriteBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite)
    {
      for (; NumHalfwordToWrite != 0; NumHalfwordToWrite--) /* while there is data to write */
      {
        /* Transfer data to the memory */
        *(uint16_t *) (Bank1_NOSRAM3_ADDR + WriteAddr) = *pBuffer++;
    
        /* Increment the address*/
        WriteAddr += 2;
      }
    }
    
    /**
      * @brief  Reads a block of data from the FSMC SRAM memory.
      * @param  pBuffer : pointer to the buffer that receives the data read from the
      *         SRAM memory.
      * @param  ReadAddr : SRAM memory internal address to read from.
      * @param  NumHalfwordToRead : number of half-words to read.
      * @retval None
      */
    void SRAM_ReadBuffer(uint16_t* pBuffer, uint32_t ReadAddr, uint32_t NumHalfwordToRead)
    {
      for (; NumHalfwordToRead != 0; NumHalfwordToRead--) /* while there is data to read */
      {
        /* Read a half-word from the memory */
        *pBuffer++ = *(__IO uint16_t*) (Bank1_NOSRAM3_ADDR + ReadAddr);
    
        /* Increment the address*/
        ReadAddr += 2;
      }
    }
    
    
    

    If I write in "target option" off-chip RAM1 start address 0x68000000 and size 0x200000, then I get an error because the data (in my case, the variable "p") will be written to this address before the memory is configured.
    Image:
    gyazo.com/aa6a48e0341b3fc8042d85a2d216154f

    But I want to use it transparently, using the RL-RTX.
    Can anybody tell how to do it?

  • Are you wanting ALL of your variables to use the external RAM, or just a single variable?

  • I will explain:
    I'm using RT-RTX and graphics library emWin (from Segger). Memory for this all you need much. Accordingly, I would like to expand the memory external SRAM memory.
    So I wish that RT-RTX and emWin could use for their needs external memory. And, of course, that I could put some of my variables to external memory, but that it was not noticeable to me.

  • Hello everybody. It works at last!!!!!!

    For those that are using the exemples of Keil and particularly "FSMC->RAM" here are the conclusions:

    1. to run this exemple properly It's not neccessary to uncomment /* #define DATA_IN_ExtSRAM */
    2.the start address for the external SRAM mounted on MCBSTM32F400 is 0x68000000
    3. quit the write protection to "stm324xg_eval_fsmc_sram.c" and:

    3.a change #define Bank1_SRAM2_ADDR ((uint32_t)0x64000000) by #define Bank1_SRAM3_ADDR ((uint32_t)0x68000000)

    3.b change FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; by FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;

    3.c change FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; by FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;

    3.d change FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); by FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);

    3.4 Of course update the references to the new variables in functions SRAM_WriteBuffer() and SRAM_ReadBuffer()

    4.Finally, in GPIOG configuration change //GPIO_PinAFConfig(GPIOG, GPIO_PinSource9 , GPIO_AF_FSMC); by GPIO_PinAFConfig(GPIOG, GPIO_PinSource10 , GPIO_AF_FSMC);

    From here, I want to thank you John Michel and toff toff for their contibution.

    Yes, we together can

  • Anderson, this is great!
    Can anyone advise how to use it with RTX Kernel by Keil?

  • Guys, I really want to thank you all. Information on how to work the FSMC was so scarce in the internet, this was the only thread that helped me.

    I used the information you shared here to get the 8 mbit sram on a Hayou STM32F2 board to work. It took a lot of detective work because there was so little data given.

    This was the chinese eval board I used:

    " RAM in Keil settings is a KILLER ! It ends up in hard fault always. I was debugging like crazy, switching on peripheral clocks in different order etc. Thank you for pointing the right way.

    If I find the solution to the RTX problem I will let you know.

  • Write in file startup_stm32f4xx.s in line 38 (in my case) this line:

    __initial_sp    EQU 0x20000000+Stack_Size
    

  • Did anyone ever find out how to set this up so that ALL of the user data memory is in the RAM from the start? I do not want to have to use the SRAM_WriteBuffer and SRAM_ReadBuffer functions to get data in and out of the RAM. What I am looking for is a way to set the project up to have data always reside in the RAM. Thanks in advance.

  • Chris Kern, You need to adjust the memory as it was stated a few posts above and added a line from my previous post. In this case would not need to use Write_ and Read_ Buffer