AnsweredAssumed Answered

STM32F407 FSMC SRAM & LCD

Question asked by postuchow.jack on Aug 17, 2015
Latest reply on Aug 18, 2015 by postuchow.jack
I'm new to ARM microcontrollers, and having a bit of trouble understanding something.  I have an LCD with the SSD1963 controller and external SRAM (AS6C1616) connected in parallel using the FSMC.  The SSD1963 is currently using PD7 (FSMC_NE1) for its chip select and PF0 (FSMC_A0) for its data/command signal. The SRAM is using PG9 (FSMC_NE2) for its chip select.

I've managed to get the SSD1963 up and running using the FSMC, but I am unable to get the FSMC working with the SRAM and this is where it gets confusing for me.  The SSD1963 starts at 0x60000000, which sets up the FSMC to automatically set the CS (FSMC_NE1) when writing/reading to/from the SSD1963.  Since I want to use FSMC_NE2 for the CS of the SRAM, that needs to start at 0x64000000, or that is how I've understood it, but the SRAM only has 19 address lines.  Which is probably causing my microcontroller to go into its default handler when I try to write to the SRAM.

So my question is, how do I manage to get the FSMC to automatically set FSMC_NE2 without having to start at 0x64000000, or am I totally misunderstanding this concept?

Here is my code that I'm using:
001./* FSMC initialization function */
002.void MX_FSMC_Init(void)
003.{
004.  FSMC_NORSRAM_TimingTypeDef Timing;
005. 
006.  /** Perform the SRAM1 memory initialization sequence
007.  */
008.  hsram1.Instance = FSMC_NORSRAM_DEVICE;
009.  hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
010.  /* hsram1.Init */
011.  hsram1.Init.NSBank = FSMC_NORSRAM_BANK1;
012.  hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
013.  hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
014.  hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
015.  hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
016.  hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
017.  hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
018.  hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
019.  hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
020.  hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
021.  hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
022.  hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
023.  hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
024.  /* Timing */
025.  Timing.AddressSetupTime = 15;
026.  Timing.AddressHoldTime = 15;
027.  Timing.DataSetupTime = 255;
028.  Timing.BusTurnAroundDuration = 15;
029.  Timing.CLKDivision = 16;
030.  Timing.DataLatency = 17;
031.  Timing.AccessMode = FSMC_ACCESS_MODE_A;
032.  /* ExtTiming */
033. 
034.  HAL_SRAM_Init(&hsram1, &Timing, NULL);
035. 
036.  /** Perform the SRAM2 memory initialization sequence
037.  */
038.  hsram2.Instance = FSMC_NORSRAM_DEVICE;
039.  hsram2.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
040.  /* hsram2.Init */
041.  hsram2.Init.NSBank = FSMC_NORSRAM_BANK2;
042.  hsram2.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
043.  hsram2.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
044.  hsram2.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
045.  hsram2.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
046.  hsram2.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
047.  hsram2.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
048.  hsram2.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
049.  hsram2.Init.WriteOperation = FSMC_WRITE_OPERATION_DISABLE;
050.  hsram2.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
051.  hsram2.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
052.  hsram2.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
053.  hsram2.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
054.  /* Timing */
055.  Timing.AddressSetupTime = 15;
056.  Timing.AddressHoldTime = 15;
057.  Timing.DataSetupTime = 255;
058.  Timing.BusTurnAroundDuration = 15;
059.  Timing.CLKDivision = 16;
060.  Timing.DataLatency = 17;
061.  Timing.AccessMode = FSMC_ACCESS_MODE_A;
062.  /* ExtTiming */
063. 
064.  HAL_SRAM_Init(&hsram2, &Timing, NULL);
065. 
066.}
067. 
068.static void HAL_FSMC_MspInit(void){
069.  /* USER CODE BEGIN FSMC_MspInit 0 */
070. 
071.  /* USER CODE END FSMC_MspInit 0 */
072.  GPIO_InitTypeDef GPIO_InitStruct;
073.  if (FSMC_Initialized) {
074.    return;
075.  }
076.  FSMC_Initialized = 1;
077.  /* Peripheral clock enable */
078.  __FSMC_CLK_ENABLE();
079.   
080.  /** FSMC GPIO Configuration 
081.  PF0   ------> FSMC_A0
082.  PF1   ------> FSMC_A1
083.  PF2   ------> FSMC_A2
084.  PF3   ------> FSMC_A3
085.  PF4   ------> FSMC_A4
086.  PF5   ------> FSMC_A5
087.  PF12   ------> FSMC_A6
088.  PF13   ------> FSMC_A7
089.  PF14   ------> FSMC_A8
090.  PF15   ------> FSMC_A9
091.  PG0   ------> FSMC_A10
092.  PG1   ------> FSMC_A11
093.  PE7   ------> FSMC_D4
094.  PE8   ------> FSMC_D5
095.  PE9   ------> FSMC_D6
096.  PE10   ------> FSMC_D7
097.  PE11   ------> FSMC_D8
098.  PE12   ------> FSMC_D9
099.  PE13   ------> FSMC_D10
100.  PE14   ------> FSMC_D11
101.  PE15   ------> FSMC_D12
102.  PD8   ------> FSMC_D13
103.  PD9   ------> FSMC_D14
104.  PD10   ------> FSMC_D15
105.  PD11   ------> FSMC_A16
106.  PD12   ------> FSMC_A17
107.  PD13   ------> FSMC_A18
108.  PD14   ------> FSMC_D0
109.  PD15   ------> FSMC_D1
110.  PG2   ------> FSMC_A12
111.  PG3   ------> FSMC_A13
112.  PG4   ------> FSMC_A14
113.  PG5   ------> FSMC_A15
114.  PD0   ------> FSMC_D2
115.  PD1   ------> FSMC_D3
116.  PD4   ------> FSMC_NOE
117.  PD5   ------> FSMC_NWE
118.  PD7   ------> FSMC_NE1
119.  PG9   ------> FSMC_NE2
120.  PE0   ------> FSMC_NBL0
121.  PE1   ------> FSMC_NBL1
122.  */
123.  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
124.                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12|GPIO_PIN_13
125.                          |GPIO_PIN_14|GPIO_PIN_15;
126.  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
127.  GPIO_InitStruct.Pull = GPIO_NOPULL;
128.  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
129.  GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
130.  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
131. 
132.  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
133.                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_9;
134.  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
135.  GPIO_InitStruct.Pull = GPIO_NOPULL;
136.  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
137.  GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
138.  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
139. 
140.  GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
141.                          |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
142.                          |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
143.  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
144.  GPIO_InitStruct.Pull = GPIO_NOPULL;
145.  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
146.  GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
147.  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
148. 
149.  GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
150.                          |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
151.                          |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5
152.                          |GPIO_PIN_7;
153.  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
154.  GPIO_InitStruct.Pull = GPIO_NOPULL;
155.  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
156.  GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
157.  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
158. 
159.  /* USER CODE BEGIN FSMC_MspInit 1 */
160. 
161.  /* USER CODE END FSMC_MspInit 1 */
162.}
163. 
164.#define SRAM_BASE_ADDRESS ((uint32_t)0x64000000)
165. 
166.uint32_t *sram_ptr;
167. 
168.static void sram_write(uint32_t addr, uint16_t val){
169.    sram_ptr = (uint32_t *)(SRAM_BASE_ADDRESS + addr);
170.    *sram_ptr = val;
171.}
172. 
173.static uint16_t sram_read(uint32_t addr){
174.    sram_ptr = (uint32_t *)(SRAM_BASE_ADDRESS + addr);
175.    return *sram_ptr;
176.}

Outcomes