cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4Discovery (FSMC) + FT2232H

mehmoodn
Associate
Posted on September 12, 2013 at 04:07

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.


/* Private define ------------------------------------------------------------*/

#define FT2232H_RAM ((uint32_t)0x60000000) /* Write/Read Enable use the same address as per FT2232H spec sheet*/


/*******************************************************************************

* Function Name : Ft2232hGpioConfig

* Description : Configures FT2232H Control lines (FSMC Pins) in alternate function

Push-Pull mode.

* Input : None

* Output : None

* Return : None

* Attention : None

*******************************************************************************/

void Ft2232hGpioConfig(void)

{

GPIO_InitTypeDef GPIO_InitStructure; 


/* Enable GPIOs clock */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE , ENABLE);


/* Enable FSMC clock */

RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); 


/*-- GPIOs Configuration ------------------------------------------------------*/

/*

+-------------------+--------------------+------------------+------------------+

+ SRAM pins assignment +


+-------------------+--------------------+

*/

/* GPIOD configuration */

/* Set PD.00(FSMC_D2), PD.01(FSMC_D3), PD.04(FSMC_NOE), PD.05(FSMC_NWE), 

PD.07(FSMC_NE1), PD.11(FSMC_A16), PD.14(FSMC_D0), PD.15(FSMC_D1) as alternate function push pull */

GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | 

GPIO_Pin_7 | GPIO_Pin_11 | GPIO_Pin_14 | GPIO_Pin_15;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //GPIO_PuPd_DOWN;


GPIO_Init(GPIOD, &GPIO_InitStructure);


/* Set PE.07(FSMC_D4), PE.08(FSMC_D5), PE.09(FSMC_D6), PE.10(FSMC_D7) as alternate function push pull */ 

/* GPIOE configuration */

GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC);

GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_FSMC);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;


GPIO_Init(GPIOE, &GPIO_InitStructure); 

}



/*******************************************************************************

* Function Name : Ft2232hInit

* Description : Configures FT2232H FSMC properties

* Input : None

* Output : None

* Return : None

* Attention : None

*******************************************************************************/

void Ft2232hInit(void)

{

FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;

FSMC_NORSRAMTimingInitTypeDef p;



/*-- FSMC Configuration ------------------------------------------------------*/


#if 1 

p.FSMC_AddressSetupTime = 5;

p.FSMC_AddressHoldTime = 5; // 0;

p.FSMC_DataSetupTime = 5;

p.FSMC_BusTurnAroundDuration = 0;

p.FSMC_CLKDivision = 0;

p.FSMC_DataLatency = 0;

#endif 


p.FSMC_AccessMode = FSMC_AccessMode_A; 


FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;

FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //FSMC_DataAddressMux_Enable;

FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; //FSMC_MemoryType_PSRAM;

FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; //FSMC_MemoryDataWidth_16b;

FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;

FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; 

FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;

FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;

FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;

FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;

FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;

FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable;

FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;

FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;

FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;


FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); 


/*!< Enable FSMC Bank1_SRAM2 Bank */

FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); 

}


/**

* @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 FsmcWriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint32_t NumWordToWrite)

{

for (; NumWordToWrite != 0; NumWordToWrite--) /* while there is data to write */

{

/* Transfer data to the memory */

*(uint8_t *) (FT2232H_RAM + WriteAddr) = *pBuffer++;


/* Increment the address*/

WriteAddr += 1;

}

}



/**

* @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 FsmcReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint32_t NumWordToRead)

{


for (; NumWordToRead != 0; NumWordToRead--) /* while there is data to read */

{

/* Read a half-word from the memory */

*pBuffer++ = *(__IO uint8_t*) (FT2232H_RAM + ReadAddr);


/* Increment the address*/

ReadAddr +=1;

}

}

The FsmcWriteBuffer() function is responsible for sending the bytes to the FT2232H. Any suggestions or feedback would be greatly appreciated. Thank you! #fsmc
1 REPLY 1
vlad
Associate
Posted on December 27, 2013 at 16:46

Hi MN,

I was planning to do exactly the same thing, except that I was going to use an FT232H instead of the dual FT2232H, so I did a bit of research and found your message. Have you ever found the reason why 8 bytes would be prepended to a message?

I have an USB sniffer and a logic analyser and after reading your message I was going to try and find the issue, but I thought I would ask you first and save some time in case you already found the problem.

Thanks!

Vard