cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to erase external NOR flash memory while read, write works.

Klassic
Associate III

I am using STM32L496ZG to interface ISSI IS29GL064-70TLET nor flash by using HAL library. I used CUBE MX to generate the code and running code on Keil compiler. I am able to detect device ID, write and read block. But unable to erase data. I have used example code provided in application note AN4761.

Erase code snippet is below:

WRITE_READ_ADDR 0x8000

NOR_BANK_ADDR 0x64000000

HAL_NOR_ReturnToReadMode(&hnor1);

/* Erase the NOR memory block to write on */

HAL_NOR_Erase_Block(&hnor1, WRITE_READ_ADDR, NOR_BANK_ADDR);

/* Return the NOR memory status */

if(HAL_NOR_GetStatus(&hnor1, NOR_BANK_ADDR, NOR_TIMEOUT_VALUE) !=

HAL_NOR_STATUS_SUCCESS)

{

/* Erase Error */

HAL_UART_Transmit(&huart2, (uint8_t *) "Erase error" , 12, 100);

  return NOR_STATUS_ERASE_ERROR;

}

The status returns erase success. But the bits are still the same, they don't turn to ones at all.

Can any one please help me out on this?

29 REPLIES 29

Thanks again Pavel. Will try it out and let you know.
Also, I had to change write_cycle of block erase function according to 64Mb. Or is it same for both? Can u plz check if its ok:

unsigned EXTFL_Block_erase(uint8_t nblk)
{
    uint16_t volatile *p = EXTFL_block_and_offset_to_addr(nblk, 0);
    if (!p)
        return 1;
    unsigned start_tick = HAL_GetTick();

    // Write unlock
    extfl_write_unlock_();
    // Write start erase
    p[0] = 0x30;
    // Poll for completion - simplified. Rely on data toggling.
   /* bool done = false; //omitted polling since HAL lib GetStatus() used after eraseBlock func
    do {
        if (FL_ReadStatus(nblk, 0) == 0) {
            done = true;
            break;
        }
    } while ((HAL_GetTick() - start_tick) <= EXTFL_ERASE_TMO); */
    Reset_Seq();
    extfl_cmd_reset_(); // return to read state
   /* if (!done) {
        if (FL_ReadStatus(0, 0) != 0) {
            return (2|8); // bad status after reset
        }
        return 2; // timeout
    }*/

    // Verify that all bytes are 0xFF
    // ......
    return 0;
}

// Block#, offset in block -> physical address casted to u16 ptr
// Offset must be even.
static inline uint16_t *EXTFL_block_and_offset_to_addr(uint8_t blk, unsigned offs)
{
  return (uint16_t *) (NOR_BANK_ADDR + blk * EXTFL_ERASE_BLK_SIZE + offs);
}


// send RESET cmd [1, pg.50]
static void extfl_cmd_reset_(void)
{
    uint16_t volatile *p = EXTFL_block_and_offset_to_addr(0, 0);
    p[0] = 0xF0;
    __DMB();
    __DSB();
}

static void Reset_Seq(void)
{
    uint16_t volatile *p = EXTFL_block_and_offset_to_addr(0, 0);
    p[0x555] = 0xAA;
    __DSB();
    p[0x2AA] = 0x55;
    __DSB();
}

// write unlock cmd 555/AA,2AA/55
static void extfl_write_unlock_(void)
{
    uint16_t volatile *p = EXTFL_block_and_offset_to_addr(0, 0);
    p[0x555] = 0xAA;
    __DSB();
    p[0x2AA] = 0x55;
    __DSB();
   
    p[0x555] = 0x80;
    __DSB();
    p[0x555] = 0xAA;
    __DSB();
    p[0x2AA] = 0x55;
    __DSB();
}

I no longer have a board with such flash. Just test, step with debugger... Especially check if there are unexplainable long "hangs" when the MCU is totally unresponsible.

 

Klassic
Associate III

@Pavel A. actually both the codes (HAL lib and the one you provided) looks same and the problem of erase still remains. 
              The polling sub routine returned ok in Erase block, and there are no hangs. 
I feel there is something else I need to check which I am unable to trace due to lack of my knowledge. 
Plz help.

Pavel A.
Evangelist III

I could help if I had the board. This kind of problems are hard to debug remotely. For sure you've scanned the flash documentation, checked the commands. Try to request example code from ISSI support.

What about mass erase, did it work?

Mass erase did not work either. No error message to check.
The datasheet says there are 128 sectors with 32KW, meaning 37627 (8000 in hex) locations for each sector. 

Klassic_0-1691036939540.png

  Is it ok to set address location as multiples of 0x8000 in erase block function for sector erase? Or  something else need to be included in code ?

Thanks

 

Pavel A.
Evangelist III

32 KW = 64 Kbytes = 0x10000

FMC maps the NOR so that even in 16-bit mode it looks to the CPU "normally". 64 Kbytes sector occupies 64Kbytes in the FMC address space.

Ok. Also, Can u plz tell me how do I debug the erase operation? What registers do I need to look at while sending erase cmd? This may be more helpful in solving.

Thanks

Pavel A.
Evangelist III

You just step thru the code and watch the variables. Maybe, use debug prints. While writing/erasing, avoid interference of the debugger in the flash access cycles (simply speaking, do not open debugger memory views on the flash). Hope the FMC esoteric timing parameters are already correct, as reads and writes work. Good luck.

 

KMINH.1
Associate III

Thanks everyone for your answers.
The erase operation worked when I shortened the long wires I was using between stm board and flash IC. Perhaps the signal transmission was failing or weak signals.

Anyways, am grateful for the support I got from u all.

Hi @KMINH.1 ,

I'm not sure if you are speaking about the initially described issue by @Klassic . I wanted to mark your reply as accepted solution but I need your confirmation first.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.