Skip to main content
yldzmuhammed
Associate III
July 16, 2020
Question

STM32F7 FMC Nor Flash Problem

  • July 16, 2020
  • 1 reply
  • 1338 views

Hello everyone,

I have designed a board with STM32F750N8, 22 Bit Parallel Nor Flash, 13 Bit SDRAM, QSPI Nor Flash.

Now i am trying to read, write data, read device id from fmc nor flash (other memories not enabled). But when i try to read device id, getting 0x90 as Manufacturer Code, 0x2FC as Dev Code 1, 2, 3.

When i read back what i wrote, i am getting 0xF0 as first word (16bit), 0x2FC as rest of the 4096 word (16bit).

I think nor flash works but somehow there is a problem and cause this. What am i missing? I coppied STM32756G_EVAL FMC Nor example. Even timings.

I have attached my nor flash schematic, cubemx project, some codes.

I used MT28EW128ABA1HPC-0SIT flash memory IC.

What am i missing? Why 0x02FC is everywhere?

NOT: I am using internal RC oscillator with 216 MHz.

Here is FMC Init function with msp and mpu init:

/* FMC initialization function */
static void MX_FMC_Init(void)
{
 FMC_NORSRAM_TimingTypeDef Timing = {0};
 
 /** Perform the NOR1 memory initialization sequence */
 /* Timing */
 Timing.CLKDivision = 2;
 Timing.DataLatency = 2;
 Timing.DataSetupTime = 8;
 Timing.AddressHoldTime = 3;
 Timing.AddressSetupTime = 4;
 Timing.BusTurnAroundDuration = 1;
 Timing.AccessMode = FMC_ACCESS_MODE_A;
 
 /* hnor1.Init */
 hnor1.Instance = FMC_NORSRAM_DEVICE;
 hnor1.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
 
 hnor1.Init.PageSize = FMC_PAGE_SIZE_NONE;
 hnor1.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;
 
 hnor1.Init.NSBank = FMC_NORSRAM_BANK1;
 hnor1.Init.MemoryType = FMC_MEMORY_TYPE_NOR;
 hnor1.Init.WaitSignal = FMC_WAIT_SIGNAL_ENABLE;
 hnor1.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
 hnor1.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
 hnor1.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
 hnor1.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
 hnor1.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
 hnor1.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
 hnor1.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_ENABLE;
 hnor1.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
 hnor1.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
 hnor1.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ASYNC;
 /* ExtTiming */
 
 if (HAL_NOR_Init(&hnor1, &Timing, NULL) != HAL_OK)
 {
 Error_Handler( );
 }
}
 
 
static void HAL_FMC_MspInit(void){
 GPIO_InitTypeDef GPIO_InitStruct ={0};
 if (FMC_Initialized) {
 return;
 }
 FMC_Initialized = 1;
 /* Peripheral clock enable */
 __HAL_RCC_FMC_CLK_ENABLE();
 
 /** FMC GPIO Configuration 
 PE4 ------> FMC_A20
 PE3 ------> FMC_A19
 PD7 ------> FMC_NE1
 PE5 ------> FMC_A21
 PD6 ------> FMC_NWAIT
 PD0 ------> FMC_D2
 PD5 ------> FMC_NWE
 PD1 ------> FMC_D3
 PF0 ------> FMC_A0
 PD4 ------> FMC_NOE
 PF1 ------> FMC_A1
 PF2 ------> FMC_A2
 PF3 ------> FMC_A3
 PF4 ------> FMC_A4
 PF5 ------> FMC_A5
 PD15 ------> FMC_D1
 PD10 ------> FMC_D15
 PD14 ------> FMC_D0
 PD9 ------> FMC_D14
 PD8 ------> FMC_D13
 PF12 ------> FMC_A6
 PG1 ------> FMC_A11
 PF15 ------> FMC_A9
 PD12 ------> FMC_A17
 PD13 ------> FMC_A18
 PG3 ------> FMC_A13
 PG2 ------> FMC_A12
 PF13 ------> FMC_A7
 PG0 ------> FMC_A10
 PE8 ------> FMC_D5
 PD11 ------> FMC_A16
 PG5 ------> FMC_A15
 PG4 ------> FMC_A14
 PF14 ------> FMC_A8
 PE9 ------> FMC_D6
 PE11 ------> FMC_D8
 PE14 ------> FMC_D11
 PE7 ------> FMC_D4
 PE10 ------> FMC_D7
 PE12 ------> FMC_D9
 PE15 ------> FMC_D12
 PE13 ------> FMC_D10
 */
// GPIO_InitStruct.Pull = GPIO_PULLUP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 
 GPIO_InitStruct.Pin = FMC_A20_Pin|FMC_A19_Pin|FMC_A21_Pin|FMC_D5_Pin 
 |FMC_D6_Pin|FMC_D8_Pin|FMC_D11_Pin|FMC_D4_Pin 
 |FMC_D7_Pin|FMC_D9_Pin|FMC_D12_Pin|FMC_D10_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
 
 GPIO_InitStruct.Pin = FMC_NE_Pin|FMC_NWAIT_Pin|FMC_D2_Pin|FMC_NWE_Pin 
 |FMC_D3_Pin|FMC_NOE_Pin|FMC_D1_Pin|FMC_D15_Pin 
 |FMC_D0_Pin|FMC_D14_Pin|FMC_D13_Pin|FMC_A17_Pin 
 |FMC_A18_Pin|FMC_A16_Pin;
 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
 GPIO_InitStruct.Pin = FMC_A0_Pin|FMC_A1_Pin|FMC_A2_Pin|FMC_A3_Pin 
 |FMC_A4_Pin|FMC_A5_Pin|FMC_A6_Pin|FMC_A9_Pin 
 |FMC_A7_Pin|FMC_A8_Pin;
 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
 GPIO_InitStruct.Pin = FMC_A11_Pin|FMC_A13_Pin|FMC_A12_Pin|FMC_A10_Pin 
 |FMC_A15_Pin|FMC_A14_Pin;
 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
}
 
 
/**
 * @brief Configure the MPU attributes as as device for NOR.
 * @note The Base Address is 0x60000000.
 * The Region Size is 16MBytes, it is related to NOR memory size.
 * @param None
 * @retval None
 */
static void MPU_ConfigNOR(void)
{
 MPU_Region_InitTypeDef MPU_InitStruct;
 
 /* Disable the MPU */
 HAL_MPU_Disable();
 
 /* Configure the MPU attributes as WT for SRAM */
// MPU_InitStruct.SubRegionDisable = 0x00;
// MPU_InitStruct.BaseAddress = 0x68000000;
// MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
// MPU_InitStruct.Enable = MPU_REGION_ENABLE;
// MPU_InitStruct.Number = MPU_REGION_NUMBER1;
// MPU_InitStruct.Size = MPU_REGION_SIZE_8MB;
 
 MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
 MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
 
 /* Configure the MPU attributes as device for NOR */
 MPU_InitStruct.SubRegionDisable = 0x00;
 MPU_InitStruct.BaseAddress = 0x60000000;
 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
 MPU_InitStruct.Enable = MPU_REGION_ENABLE;
 MPU_InitStruct.Number = MPU_REGION_NUMBER1;
 MPU_InitStruct.Size = MPU_REGION_SIZE_16MB;
 
// MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
// MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
// MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
// MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
// MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
 HAL_MPU_ConfigRegion(&MPU_InitStruct);
 
 /* Enable the MPU */
 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
//

And here is my main function:

int main(void)
{
 /* USER CODE BEGIN 1 */
 
 /* Set MPU NOR region */
 MPU_ConfigNOR();
 
 /* Enable the CPU Cache */
// CPU_CACHE_Enable();
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* Configure the system clock */
 SystemClock_Config();
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_FMC_Init();
 /* USER CODE BEGIN 2 */
 
// BSP_NOR_Init();
 
	/* Read NOR memory ID */
	if(HAL_NOR_Read_ID(&hnor1, &NOR_Id) != HAL_OK)
	{
		/* NOR read ID Error */
		Error_Handler();
	}
	/* Test the NOR ID correctness */
	if(	(NOR_Id.Manufacturer_Code 	!= (uint16_t)MANUFACTURER_CODE) ||
 (NOR_Id.Device_Code1 		 != (uint16_t)DEVICE_CODE1) 			||
 (NOR_Id.Device_Code2 		 != (uint16_t)DEVICE_CODE2) 			||
 (NOR_Id.Device_Code3 		 != (uint16_t)DEVICE_CODE3))
	{
		/* NOR ID not correct */
		Error_Handler();
	}
	/* Return to read mode */
 BSP_NOR_ReturnToReadMode();
 
 /* Fill the buffer to write */
 Fill_Buffer(aTxBuffer, BUFFER_SIZE, 0x2323);
 
 /* Erase block */
 BSP_NOR_Erase_Block(WRITE_READ_ADDR);
 
 /* Write data to the NOR memory */
 for (uwIndex = 0; uwIndex < BUFFER_SIZE; uwIndex++)
 {
 /* Write data to NOR */
 HAL_NOR_Program(&hnor1, (uint32_t *)(NOR_BANK_ADDR + WRITE_READ_ADDR + 2*uwIndex), &aTxBuffer[uwIndex]);
 
 /* Read NOR device status */
 if(HAL_NOR_GetStatus(&hnor1, NOR_BANK_ADDR, PROGRAM_TIMEOUT) != HAL_NOR_STATUS_SUCCESS)
 {
 return HAL_NOR_STATUS_ERROR;
 }
 }
 
 /* Read back data from the NOR memory */
 if(HAL_NOR_ReadBuffer(&hnor1, NOR_BANK_ADDR + WRITE_READ_ADDR, &aRxBuffer[0], BUFFER_SIZE) != HAL_OK)
 {
 return HAL_ERROR;
 }
 uwWriteReadStatus = Buffercmp(aTxBuffer, aRxBuffer, BUFFER_SIZE);
 
 if (uwWriteReadStatus != PASSED)
 {
 while(1)
 {
 }
 }
 while (1)
 {
 }
}

This topic has been closed for replies.

1 reply

yldzmuhammed
Associate III
July 17, 2020

No body have any idea?