cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 FSCM can't read Id of Nand

carlogulliani
Associate III
Posted on December 15, 2015 at 18:57

Hi everybody, I'm trying to read/write data on and flash

So, I init gpio and handler, I use 8 bit bus

void initGPIO(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__GPIOE_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
HAL_NVIC_SetPriority(FSMC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(FSMC_IRQn);
}
void initHandler(void)
{
FSMC_NAND_PCC_TimingTypeDef ComSpaceTiming;
FSMC_NAND_PCC_TimingTypeDef AttSpaceTiming;
/** Perform the NAND1 memory initialization sequence
*/
hnand.Instance = FSMC_NAND_DEVICE;
/* hnand.Init */
hnand.Init.NandBank = FSMC_NAND_BANK2;
hnand.Init.Waitfeature = FSMC_NAND_PCC_WAIT_FEATURE_DISABLE;
hnand.Init.MemoryDataWidth = FSMC_NAND_PCC_MEM_BUS_WIDTH_8;
hnand.Init.EccComputation = FSMC_NAND_ECC_DISABLE;
hnand.Init.ECCPageSize = FSMC_NAND_ECC_PAGE_SIZE_256BYTE;
hnand.Init.TCLRSetupTime = 0;
hnand.Init.TARSetupTime = 0;
/* hnand.Info */
/* ComSpaceTiming */
ComSpaceTiming.SetupTime = 252;
ComSpaceTiming.WaitSetupTime = 252;
ComSpaceTiming.HoldSetupTime = 252;
ComSpaceTiming.HiZSetupTime = 252;
/* AttSpaceTiming */
AttSpaceTiming.SetupTime = 252;
AttSpaceTiming.WaitSetupTime = 252;
AttSpaceTiming.HoldSetupTime = 252;
AttSpaceTiming.HiZSetupTime = 252;
HAL_NAND_Init(&hnand, &ComSpaceTiming, &AttSpaceTiming);
}
void readId(void)
{
NAND_IDTypeDef NAND_ID;
char buf[100];
if (HAL_NAND_Read_ID(&hnand, &NAND_ID) == HAL_OK)
{
sprintf(buf, ''Nand Flash ID = %02X,%02X,%02X,%02X\n'',NAND_ID.Maker_Id, NAND_ID.Device_Id, NAND_ID.Third_Id, NAND_ID.Fourth_Id);
print(but);
}
}

When I call readId method I can see, that all NAND_ID's values equal 0 Documentation pointed that Marker_Id has to be 0xEC and Device_Id has to be 0xF1 It means that Marker_Id and other = 0

I use SamsungK9G1G08U0D

2 REPLIES 2
Posted on December 15, 2015 at 19:27

If I were you, I'd get the NAND documentation, and use the FSMC (External Bus) and confirm I can actually talk to the memory device directly. If the device is not accessible and responsive no amount of gyrations later are going to produce useful results.

Confirm the FSMC settings, and bus level pin interactions, use a scope or logic analyzer as appropriate.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
carlogulliani
Associate III
Posted on December 16, 2015 at 10:59

Yes, I did as you mentioned.

So, now I have Nand Flash ID = 6B,4A,00,08 According the docs it should start with EC, but ok, it works... I wrote erase, read and write functions and tried to call them. If I write the next string ''How are you?'' I get ''ow are you?'' Also I put another string ''Open On-Chip Debugger: OpenOCD User's Guide'' and got ''Chip Debugger: OpenOCD User's Guide''. You can see that it moves the index while writing and it depends on length of string. I used debugger and checked it happens when I write into nand, not when I read. Before writing I completly erase block Here is my code example

void eraseBlock()
{
WriteReadAddr.Zone = 0x00;
WriteReadAddr.Block = 0x00;
WriteReadAddr.Page = 0x00;
HAL_NAND_Erase_Block(&hnand, &WriteReadAddr);
}
void writePage(uint8_t *TxBuffer)
{
HAL_NAND_Write_Page(&hnand, &WriteReadAddr, TxBuffer, 1);
print(''Data has been written 

'');
}
#define NAND_PAGE_SIZE ((uint16_t)0x0800)
void readPage()
{
uint8_t RxBuffer [NAND_PAGE_SIZE];
HAL_NAND_Read_Page (&hnand, &WriteReadAddr, RxBuffer, 1);
print(''Read data 

'');
char buf[100];
sprintf(buf, ''%s '', RxBuffer);
print(buf);
}