cancel
Showing results for 
Search instead for 
Did you mean: 

problem using STM32F407 FSMC with NOR flash

minh3192
Associate II
Posted on January 28, 2016 at 09:53

Hi all,

I am trying to interface with JR28F064M29EW NOR flash (

https://www.micron.com/~/media/documents/products/data-sheet/nor-flash/parallel/m29ew/m29ew_32mb_128mb.pdf

) using the STM32F407 MCU. However, I couldn't read the correct device ID from the NOR IC. So I want to ask whether there is anything wrong with my initialization code?

Here is the initialization code:

  GPIO_InitTypeDef GPIO_Init_Structure;

  /* Enable FSMC clock */

  __HAL_RCC_FSMC_CLK_ENABLE();

  __HAL_RCC_FSMC_FORCE_RESET();

  __HAL_RCC_FSMC_RELEASE_RESET();

  /* Enable GPIOs clock */

  __HAL_RCC_GPIOD_CLK_ENABLE();

  __HAL_RCC_GPIOE_CLK_ENABLE();

  __HAL_RCC_GPIOF_CLK_ENABLE();

  __HAL_RCC_GPIOG_CLK_ENABLE();

  /* Common GPIO configuration */

  GPIO_Init_Structure.Mode      = GPIO_MODE_AF_PP;

  GPIO_Init_Structure.Pull      = GPIO_PULLUP;

  GPIO_Init_Structure.Alternate = GPIO_AF12_FSMC;

  GPIO_Init_Structure.Speed     = GPIO_SPEED_HIGH;

  /* GPIOD configuration */

  GPIO_Init_Structure.Pin   = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 |

                              GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 |

                              GPIO_PIN_14 | GPIO_PIN_15;

  HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure);

  /* GPIOE configuration */

  GPIO_Init_Structure.Pin   = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7 |

                              GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 |

                              GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;

  HAL_GPIO_Init(GPIOE, &GPIO_Init_Structure);

  /* GPIOF configuration */

  GPIO_Init_Structure.Pin   = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 |

                              GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;

  HAL_GPIO_Init(GPIOF, &GPIO_Init_Structure);

  /* GPIOG configuration */

  GPIO_Init_Structure.Pin   = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 |

                              GPIO_PIN_5 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_12;

  HAL_GPIO_Init(GPIOG, &GPIO_Init_Structure);

hNor.Instance  = FSMC_NORSRAM_DEVICE;

hNor.Extended  = FSMC_NORSRAM_EXTENDED_DEVICE;

/* NOR device configuration */

NOR_Timing.AddressSetupTime       = 6;

NOR_Timing.AddressHoldTime        = 2;

NOR_Timing.DataSetupTime          = 8;

NOR_Timing.BusTurnAroundDuration  = 0;

NOR_Timing.CLKDivision            = 2;

NOR_Timing.DataLatency            = 2;

NOR_Timing.AccessMode             = FSMC_ACCESS_MODE_B;

hNor.Init.NSBank                 = FSMC_NORSRAM_BANK3;

hNor.Init.DataAddressMux         = FSMC_DATA_ADDRESS_MUX_DISABLE;

hNor.Init.MemoryType             = FSMC_MEMORY_TYPE_NOR;

hNor.Init.MemoryDataWidth        = FSMC_NORSRAM_MEM_BUS_WIDTH_16;

hNor.Init.BurstAccessMode        = FSMC_BURST_ACCESS_MODE_DISABLE;

hNor.Init.WaitSignalPolarity     = FSMC_WAIT_SIGNAL_POLARITY_LOW;

hNor.Init.WrapMode               = FSMC_WRAP_MODE_DISABLE;

hNor.Init.WaitSignalActive       = FSMC_WAIT_TIMING_BEFORE_WS;

hNor.Init.WriteOperation         = FSMC_WRITE_OPERATION_ENABLE;

hNor.Init.WaitSignal             = FSMC_WAIT_SIGNAL_DISABLE;

hNor.Init.ExtendedMode           = FSMC_EXTENDED_MODE_DISABLE;

hNor.Init.AsynchronousWait       = FSMC_ASYNCHRONOUS_WAIT_DISABLE;

hNor.Init.WriteBurst             = FSMC_WRITE_BURST_DISABLE;

/* Initialize the NOR controller */

if(HAL_NOR_Init(&hNor, &NOR_Timing, &NOR_Timing) != HAL_OK)

{

/* Initialization Error */

Error_Handler();

}

#nor #fsmc #stm32f407
4 REPLIES 4
Posted on January 28, 2016 at 10:46

Is it only the ID you can't read correctly, or also the content of memory?

Post the content of relevant GPIO and FSMC registers after the initialization.

JW
minh3192
Associate II
Posted on January 28, 2016 at 14:31

Here are the content of the registers

GPIOD_MODER   0x40020C00  AAAAAA0A

GPIOD_OTYPER  0x40020C04  00000000

GPIOD_OSPEEDR 0x40020C08  FFFFFF0F

GPIOD_PUPDR   0x40020C0C  55555505

GPIOD_IDR     0x40020C10  0000C7FF

GPIOD_ODR     0x40020C14  00000000

GPIOD_BSRR    0x40020C18  00000000

GPIOD_LCKR    0x40020C1C  00000000

GPIOD_AFRL    0x40020C20  CCCC00CC

GPIOD_AFRH    0x40020C24  CCCCCCCC

GPIOE_MODER   0x40021000  AAAA8A90

GPIOE_OTYPER  0x40021004  00000000

GPIOE_OSPEEDR 0x40021008  FFFFCFE0

GPIOE_PUPDR   0x4002100C  55554550

GPIOE_IDR     0x40021010  0000FFC0

GPIOE_ODR     0x40021014  00000000

GPIOE_BSRR    0x40021018  00000000

GPIOE_LCKR    0x4002101C  00000000

GPIOE_AFRL    0x40021020  C0CCC000

GPIOE_AFRH    0x40021024  CCCCCCCC

GPIOF_MODER   0x40021400  AA000AAA

GPIOF_OTYPER  0x40021404  00000000

GPIOF_OSPEEDR 0x40021408  FF000FFF

GPIOF_PUPDR   0x4002140C  55000555

GPIOF_IDR     0x40021410  00000FC0

GPIOF_ODR     0x40021414  00000000

GPIOF_BSRR    0x40021418  00000000

GPIOF_LCKR    0x4002141C  00000000

GPIOF_AFRL    0x40021420  00CCCCCC

GPIOF_AFRH    0x40021424  CCCC0000

GPIOG_MODER   0x40021800  02280AAA

GPIOG_OTYPER  0x40021804  00000000

GPIOG_OSPEEDR 0x40021808  033C0FFF

GPIOG_PUPDR   0x4002180C  01140555

GPIOG_IDR     0x40021810  000017C0

GPIOG_ODR     0x40021814  00000000

GPIOG_BSRR    0x40021818  00000000

GPIOG_LCKR    0x4002181C  00000000

GPIOG_AFRL    0x40021820  00CCCCCC

GPIOG_AFRH    0x40021824  000C0CC0

FSMC_BCR1 0xA0000000  00000000

FSMC_BTR1 0xA0000004  00000000

FSMC_BCR2 0xA0000008  00000000

FSMC_BTR2 0xA000000C  00000000

FSMC_BCR3 0xA0000010  000010D9

FSMC_BTR3 0xA0000014  10100826

FSMC_BCR4 0xA0000018  000030D2

FSMC_BTR4 0xA000001C  0FFFFFFF

FSMC_BWTR1 0xA0000104  0FFFFFFF

FSMC_BWTR2 0xA000010C  0FFFFFFF

FSMC_BWTR3 0xA0000114  0FFFFFFF

FSMC_BWTR4 0xA000011C  0FFFFFFF

The content can't be read either.

Posted on January 28, 2016 at 17:43

Looks reasonable. However, it's strange that for chipselects 1 and 2 there are 0s in the registers instead of their reset values; it's also strange that you initialize all 4 chipselects.

How exactly is your memory connected? And how exactly do you access it?

JW

minh3192
Associate II
Posted on January 30, 2016 at 01:20

Hi waclawek.jan,

Thanks for the help. I finally managed to resolve the problem. It turned out to be some issue with the NOR IC. Replacing the NOR IC and it works.