OpenNuvoton / M031BSP

BSP for M031 Series MCU
Apache License 2.0
15 stars 16 forks source link

Cannot read/write LDROM #5

Closed jeromeDms closed 2 years ago

jeromeDms commented 2 years ago

Hi I'm trying to read/write LDROM from my app code in APROM as follow :

// Product ID stored on LDROM second Page
#define LDROM_PRODUCT_ID_ADDRESS      (FMC_LDROM_BASE+FMC_FLASH_PAGE_SIZE)

void checkSetProductIdInLDRom(void)
{
        uint32_t currentProductId;
        FMC_Open(); 

        currentProductId = FMC_Read(LDROM_PRODUCT_ID_ADDRESS);
        if(currentProductId == SYSX_HEADER_BYTE5)
        {
            FMC_Close();
            return;
        }

        // erase second page in LDRom
        FMC_Erase(LDROM_PRODUCT_ID_ADDRESS);

        FMC_Write(LDROM_PRODUCT_ID_ADDRESS, SYSX_HEADER_BYTE5);

        FMC_Close();    
}

Unfortunately FMC_Read() always return 0x0000. The chip setting is set with APROM+IAP. I'm using FMC_Open() before the read().

The weird thing is the read returns 0x0000 and looking memory in Keil at LDROM address 0x00100000 I can only see 0xFFFF.

Any idea ? Thanks

kchuang1 commented 2 years ago

Hi, Please enable LDROM update macro as below in your code:

    FMC_ENABLE_LD_UPDATE();
    // erase second page in LDRom
    FMC_Erase(LDROM_PRODUCT_ID_ADDRESS);

    FMC_Write(LDROM_PRODUCT_ID_ADDRESS, SYSX_HEADER_BYTE5);
    FMC_DISABLE_LD_UPDATE();    
jeromeDms commented 2 years ago

Ahhh great. Will test. Is this macro only required to write operations or read operations as well ? Also, the FMC_Open / Close are still required too ? Is the SYS_UnlockReg() also required ?

kchuang1 commented 2 years ago

Macro is required for erase and write operation. It doesn't need to enable for read operation.

If you want use FMC function, the FMC_Open is required. SYS_UnlockReg() is used to avoid writing some register by accident. For example, some register of FMC, clock and ... If it is not called, it may cause some register unable to update.

Please check the BSP sample for the usage for detail.