AnsweredAssumed Answered

STM32F4Discovery (FSMC) + FT2232H

Question asked by MN on Sep 12, 2013
Latest reply on Dec 27, 2013 by vard
Hello,

I have paired up an STM32F4Discovery board with an FT2232H part from FTDI.  The purpose of this is to use the CPU-FIFO mode of the FTDI part for faster USB data transfer.  I made the necessary modifications to the hardware (ie removed pull-up resistors on shared FSMC signals).  I completed a driver and have it working for the most part.  Reading data from a PC by the Discovery board works quite well.  However, I am having an issue sending data to the PC.  All of my bytes make it across, however, for reasons unknown I am always seeing an extra 8 bytes of 0x00 prepended to all my messages.

eg [0x00, 0x00, 0x00, 0x00, 0x000x00, 0x00, 0x00, <my data ...>]

A little background about the driver:
       
  • it is interfaced with the Discovery board using the FSMC configured in 8-bit wide data and using the PSRAM configuration (ie FMSC address lines are treated as control lines to the FT2232H).
  •    
  • Address bit A16 of the FSMC line is always kept low (for reads and writes to the FT2232H as specified in their datasheet), hence, only one RAM address is used for reading/writing (ie 0x60000000)
  •    
  • FSMC Bank1 is mapped to the FT2232H device
My test program reads a 256 byte payload from the PC and echoes it back.  Using a USB analyzer I can see the packets going back to the PC and noticed the extra 8 bytes of 0x00 are prepended to my messages.  However, when I single step with the ST-Link I see the correct payload being written to the starting address of 0x60000000.  I am hoping this is a configuration issue with my driver.  Please see my driver code below.

001./* Private define ------------------------------------------------------------*/
002.#define FT2232H_RAM              ((uint32_t)0x60000000) /* Write/Read Enable use the same address as per FT2232H spec sheet*/
003. 
004./*******************************************************************************
005.* Function Name  : Ft2232hGpioConfig
006.* Description    : Configures FT2232H Control lines (FSMC Pins) in alternate function
007.                   Push-Pull mode.
008.* Input          : None
009.* Output         : None
010.* Return         : None
011.* Attention      : None
012.*******************************************************************************/
013.void Ft2232hGpioConfig(void)
014.{
015.    GPIO_InitTypeDef GPIO_InitStructure;
016.     
017.    /* Enable GPIOs clock */
018.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE , ENABLE);
019.     
020.    /* Enable FSMC clock */
021.    RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
022. 
023.    /*-- GPIOs Configuration ------------------------------------------------------*/
024.    /*
025.    +-------------------+--------------------+------------------+------------------+
026.    +                       SRAM pins assignment                                   +
027. 
028.    +-------------------+--------------------+
029.    */
030.    /* GPIOD configuration */
031.        /* Set PD.00(FSMC_D2), PD.01(FSMC_D3), PD.04(FSMC_NOE), PD.05(FSMC_NWE),
032.     PD.07(FSMC_NE1), PD.11(FSMC_A16), PD.14(FSMC_D0), PD.15(FSMC_D1) as alternate function push pull */
033.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource0,  GPIO_AF_FSMC);
034.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource1,  GPIO_AF_FSMC);
035.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource4,  GPIO_AF_FSMC);
036.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource5,  GPIO_AF_FSMC);
037.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource7,  GPIO_AF_FSMC);
038.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC);
039.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);
040.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);
041.     
042.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1  | GPIO_Pin_4  | GPIO_Pin_5 |
043.                                  GPIO_Pin_7 | GPIO_Pin_11 | GPIO_Pin_14 | GPIO_Pin_15;
044.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
045.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
046.    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
047.    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP; //GPIO_PuPd_DOWN;
048.     
049.    GPIO_Init(GPIOD, &GPIO_InitStructure);
050.     
051.    /* Set PE.07(FSMC_D4), PE.08(FSMC_D5), PE.09(FSMC_D6), PE.10(FSMC_D7) as alternate function push pull */   
052.    /* GPIOE configuration */
053.    GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC);
054.    GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC);
055.    GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC);
056.    GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_FSMC);
057.     
058.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8  | GPIO_Pin_9  | GPIO_Pin_10;
059.     
060.    GPIO_Init(GPIOE, &GPIO_InitStructure); 
061.}
062. 
063. 
064./*******************************************************************************
065.* Function Name  : Ft2232hInit
066.* Description    : Configures FT2232H FSMC properties
067.* Input          : None
068.* Output         : None
069.* Return         : None
070.* Attention      : None
071.*******************************************************************************/
072.void Ft2232hInit(void)
073.{
074.  FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
075.  FSMC_NORSRAMTimingInitTypeDef  p;
076.  
077. 
078./*-- FSMC Configuration ------------------------------------------------------*/
079. 
080.#if 1   
081.  p.FSMC_AddressSetupTime = 5;
082.  p.FSMC_AddressHoldTime = 5; // 0;
083.  p.FSMC_DataSetupTime = 5;
084.  p.FSMC_BusTurnAroundDuration = 0;
085.  p.FSMC_CLKDivision = 0;
086.  p.FSMC_DataLatency = 0;
087.#endif   
088.   
089.  p.FSMC_AccessMode = FSMC_AccessMode_A;   
090. 
091.  FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
092.  FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //FSMC_DataAddressMux_Enable;
093.  FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; //FSMC_MemoryType_PSRAM;
094.  FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; //FSMC_MemoryDataWidth_16b;
095.  FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
096.  FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; 
097.  FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
098.  FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
099.  FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
100.  FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
101.  FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
102.  FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable;
103.  FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
104.  FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
105.  FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
106. 
107.  FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
108. 
109.  /*!< Enable FSMC Bank1_SRAM2 Bank */
110.  FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
111.}
112. 
113./**
114.  * @brief  Writes a Half-word buffer to the FSMC SRAM memory.
115.  * @param  pBuffer : pointer to buffer.
116.  * @param  WriteAddr : SRAM memory internal address from which the data will be
117.  *         written.
118.  * @param  NumHalfwordToWrite : number of half-words to write.
119.  * @retval None
120.  */
121.void FsmcWriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint32_t NumWordToWrite)
122.{
123.  for (; NumWordToWrite != 0; NumWordToWrite--) /* while there is data to write */
124.  {
125.    /* Transfer data to the memory */
126.    *(uint8_t *) (FT2232H_RAM + WriteAddr) = *pBuffer++;
127. 
128.    /* Increment the address*/
129.    WriteAddr += 1;
130.  }
131.}
132. 
133. 
134./**
135.  * @brief  Reads a block of data from the FSMC SRAM memory.
136.  * @param  pBuffer : pointer to the buffer that receives the data read from the
137.  *         SRAM memory.
138.  * @param  ReadAddr : SRAM memory internal address to read from.
139.  * @param  NumHalfwordToRead : number of half-words to read.
140.  * @retval None
141.  */
142.void FsmcReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint32_t NumWordToRead)
143.{
144.     
145.  for (; NumWordToRead != 0; NumWordToRead--) /* while there is data to read */
146.  {
147.    /* Read a half-word from the memory */
148.    *pBuffer++ = *(__IO uint8_t*) (FT2232H_RAM + ReadAddr);
149. 
150.    /* Increment the address*/
151.    ReadAddr +=1;
152.  }
153.}


The FsmcWriteBuffer() function is responsible for sending the bytes to the FT2232H.

Any suggestions or feedback would be greatly appreciated.  Thank you!

Outcomes