cancel
Showing results for 
Search instead for 
Did you mean: 

didn't properly able to read and write of FMC_norflash @0x60000000

jr_engr_mbed
Associate III

Screenshot (1264).png

HI,

For testing and debugging FMC_norflash(MT28EW01aba) with custom h753 board, I used h743i-eval example as it is for read,write,erase, hence, i could read Manufactring code in memory browser, but in live expression i see address is different, so, where should i check for proper tx and rx data to be match.


<

#include "main.h"

#include "stm32h7xx_hal.h"

#include "stdio.h"

 

#define BUFFER_SIZE ((uint32_t)0x1000) // Buffer size for read/write operations

 

#define NOR_BANK_ADDR ((uint32_t)0x60000000) // Base address of the NOR flash

#define ERASE_TIMEOUT 0x00A00000U // Timeout for erase operation

#define PROGRAM_TIMEOUT 0x00001000U // Timeout for program operation

#define WRITE_READ_ADDR ((uint32_t)0x8000) // Address offset for read/write operations

 

#define MANUFACTURER_CODE ((uint16_t)0x0089) // Expected Manufacturer code

#define DEVICE_CODE1 ((uint16_t)0x227E) // Expected Device code 1

#define DEVICE_CODE2 ((uint16_t)0x2221) // Expected Device code 2

#define DEVICE_CODE3 ((uint16_t)0x2200) // Expected Device code 3

#define NOR_STATUS_READ_ID_ERROR 0x01 // Custom error code for read ID error

#define NOR_STATUS_ID_ERROR 0x02 // Custom error code for ID mismatch

 

/* Private variables ---------------------------------------------------------*/

uint16_t aTxBuffer[BUFFER_SIZE];

uint16_t aRxBuffer[BUFFER_SIZE];

__IO uint32_t uwWriteReadStatus = 0;

uint32_t uwIndex = 0;

 

NOR_HandleTypeDef hnor1;

NOR_IDTypeDef NOR_Id;

FMC_NORSRAM_TimingTypeDef NOR_Timing;

 

/* Private typedef -----------------------------------------------------------*/

typedef enum

{

FAILED = 0,

PASSED = !FAILED

} TestStatus;

 

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

HAL_StatusTypeDef MX_FMC_Init(void);

void Error_Handler(void);

static void Fill_Buffer(uint16_t *pBuffer, uint32_t uwBufferLenght, uint16_t uwOffset);

static TestStatus Buffercmp(uint16_t *pBuffer1, uint16_t *pBuffer2, uint16_t BufferLength);

static void CPU_CACHE_Enable(void);

static void MPU_Config(void);

 

/* Main Program --------------------------------------------------------------*/

int main(void)

{

/* Enable CPU Cache */

CPU_CACHE_Enable();

 

/* MPU Configuration */

MPU_Config();

 

/* HAL Initialization */

HAL_Init();

 

/* Configure the system clock */

SystemClock_Config();

 

/* Initialize GPIO */

MX_GPIO_Init();

 

/* Initialize FMC (NOR flash) */

if (MX_FMC_Init() != HAL_OK)

{

Error_Handler();

}

 

/* Fill the buffer to write */

Fill_Buffer(aTxBuffer, BUFFER_SIZE, 0xD20F);

for (int i = 0; i < BUFFER_SIZE; i++) {

printf("aTxBuffer[%d] = 0x%X\n", i, aTxBuffer[i]);

}

 

/* Erase the NOR flash block */

if (HAL_NOR_Erase_Block(&hnor1, WRITE_READ_ADDR, NOR_BANK_ADDR) != HAL_OK)

{

Error_Handler();

}

 

/* Wait until NOR is ready */

if(HAL_NOR_GetStatus(&hnor1, NOR_BANK_ADDR, ERASE_TIMEOUT) != HAL_NOR_STATUS_SUCCESS)

{

Error_Handler();

}

 

/* Write data to the NOR memory */

for (uwIndex = 0; uwIndex < BUFFER_SIZE; uwIndex++)

{

if (HAL_NOR_Program(&hnor1, (uint32_t *)(NOR_BANK_ADDR + WRITE_READ_ADDR + 2 * uwIndex), &aTxBuffer[uwIndex]) != HAL_OK)

{

Error_Handler();

}

 

/* Check the status after each write operation */

if(HAL_NOR_GetStatus(&hnor1, NOR_BANK_ADDR, PROGRAM_TIMEOUT) != HAL_NOR_STATUS_SUCCESS)

{

Error_Handler();

}

}

 

/* Read data back from NOR flash */

if(HAL_NOR_ReadBuffer(&hnor1, NOR_BANK_ADDR + WRITE_READ_ADDR, aRxBuffer, BUFFER_SIZE) != HAL_OK)

{

Error_Handler();

}

 

/* Checking data integrity */

uwWriteReadStatus = Buffercmp(aTxBuffer, aRxBuffer, BUFFER_SIZE);

 

if (uwWriteReadStatus != PASSED)

{

/* Toggle the LED connected to GPIOI Pin 8 to indicate an error */

while(1)

{

HAL_GPIO_TogglePin(GPIOI, GPIO_PIN_8);

HAL_Delay(500);

}

}

else

{

// Optionally, indicate success by turning on an LED or similar

HAL_GPIO_WritePin(GPIOI, GPIO_PIN_8, GPIO_PIN_SET);

}

 

/* Infinite loop */

while (1)

{

}

}

 

/* Helper Functions ----------------------------------------------------------*/

 

/* Function to fill the buffer with test data */

static void Fill_Buffer(uint16_t *pBuffer, uint32_t uwBufferLenght, uint16_t uwOffset)

{

uint16_t tmpIndex = 0;

 

/* Put in global buffer different values */

for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++ )

{

pBuffer[tmpIndex] = tmpIndex + uwOffset;

}

}

 

/* Function to compare two buffers */

static TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength)

{

while (BufferLength--)

{

if (*pBuffer1 != *pBuffer2)

{

return FAILED;

}

pBuffer1++;

pBuffer2++;

}

return PASSED;

}

HAL_StatusTypeDef MX_FMC_Init(void)

{

FMC_NORSRAM_TimingTypeDef Timing = {0};

 

hnor1.Instance = FMC_NORSRAM_DEVICE;

hnor1.Extended = FMC_NORSRAM_EXTENDED_DEVICE;

hnor1.Init.NSBank = FMC_NORSRAM_BANK1;

hnor1.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;

hnor1.Init.MemoryType = FMC_MEMORY_TYPE_NOR;

hnor1.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;

hnor1.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;

hnor1.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;

hnor1.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;

hnor1.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;

hnor1.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;

hnor1.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;

hnor1.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_ENABLE;

hnor1.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;

hnor1.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;

hnor1.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;

hnor1.Init.PageSize = FMC_PAGE_SIZE_NONE;

 

Timing.AddressSetupTime = 15;

Timing.AddressHoldTime = 15;

Timing.DataSetupTime = 255;

Timing.BusTurnAroundDuration = 15;

Timing.CLKDivision = 16;

Timing.DataLatency = 17;

Timing.AccessMode = FMC_ACCESS_MODE_A;

 

if (HAL_NOR_Init(&hnor1, &Timing, NULL) != HAL_OK)

{

Error_Handler();

}

 

/* Read & Check the NOR device IDs */

if (HAL_NOR_Read_ID(&hnor1, &NOR_Id) != HAL_OK)

{

/* NOR read ID Error */

return NOR_STATUS_READ_ID_ERROR;

}

 

/* Test the NOR ID correctness */

if ((NOR_Id.Manufacturer_Code != MANUFACTURER_CODE) ||

(NOR_Id.Device_Code1 != DEVICE_CODE1) ||

(NOR_Id.Device_Code2 != DEVICE_CODE2) ||

(NOR_Id.Device_Code3 != DEVICE_CODE3))

{

/* NOR ID not correct */

return NOR_STATUS_ID_ERROR;

}

 

printf("Manufacturer Code: 0x%X\n", NOR_Id.Manufacturer_Code);

printf("Device Code 1: 0x%X\n", NOR_Id.Device_Code1);

printf("Device Code 2: 0x%X\n", NOR_Id.Device_Code2);

printf("Device Code 3: 0x%X\n", NOR_Id.Device_Code3);

 

return HAL_OK;

}

 

 

 

>

0 REPLIES 0