How to realise bidirectional ports in FSMC function of STM32?
Have a look at Section 9.1.4 on page 157:

9.1.4 Alternate functions (AF)
It is necessary to program the Port Bit Configuration Register before
using a default  alternate function.

For alternate function inputs, the port must be configured in Input mode (floating, pullup or pull-down) and the input pin must be driven
externally.

Note: It is also possible to emulate the AFI input pin by software by programming the GPIO  controller. In this case, the port should be
configured in Alternate Function Output mode.  And obviously, the
corresponding port should not be driven externally as it will be
driven by the software using the GPIO controller.

For alternate function outputs, the port must be configured in Alternate Function Output  mode (Push-Pull or Open-Drain).

For bidirectional Alternate Functions, the port bit must be configured in Alternate  Function Output mode (Push-Pull or
Open-Drain). In this case the input driver is  configured in input
floating mode


If you configure a port bit as Alternate Function Output, this
disconnects the output register and connects the pin to the output
signal of an on-chip peripheral.
If software configures a GPIO pin as Alternate Function Output, but
peripheral is not  activated, its output is not specified.

If a pin or a bus is supposed to be bidirectional for an Alternate Function, configure it as an Alternate Function in Output mode and the input configuration happens automatically.
If the pin is supposed to be an input for an Alternate Function, configure it in Input Mode.
If the pin is supposed to be an output for an Alternate Function, configure it in Output mode.
When you're using a pin as GPIO, you have to choose between Input mode or Output mode.