about s32k144 flash write/read

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

about s32k144 flash write/read

861件の閲覧回数
alice_th
Contributor III

when i test flash_partitioning_s32k144 example , i find HardFault.

could you help to check it.

Connection from "127.0.0.1" via 127.0.0.1. Connection from port "63674" to 6224 Connection from "127.0.0.1" via 127.0.0.1. Connection from port "63675" to 7224 Searching for Kernel Symbols... rsp_qC - qSymbol: 5F74785F7468726561645F63757272656E745F707472 _tx_thread_current_ptr not found. ThreadX analysis not enabled. rsp_qC - qSymbol: 707843757272656E74544342 pxCurrentTCB not found. FreeRTOS analysis not enabled. UsageFault: An instruction executed with an invalid EPSR.T or EPSR.IT field. HardFault: A fault has been escalated to a hard fault.

alice_thanks_1-1718606693759.png

 

ラベル(1)
0 件の賞賛
返信
5 返答(返信)

838件の閲覧回数
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @alice_th,

Are you using the OpenSDA to debug the program? 

The FlexNVM memory is partitioned to EEPROM use and is blocked for some erase commands (Erase Sector and Erase Block). As a consequence, loading the program to flash memory may fail on some debuggers. Please perform a mass erase operation on Flash to remove this partitioning after running the example to be able to update your application on target.

You can update OpenSDA to J-Link, I've tested the program with an external J-Link debugger, through RAM build configuration and it works correctly.

Best regards,
Julián

0 件の賞賛
返信

836件の閲覧回数
alice_th
Contributor III

actually, my application need to download to flash, and i need part of the flash space to store some parameters when running. 

i just init flash in main and run flash_read_write_test()

hal_init_flash ();

flash_read_write_test();

i find it will crash at hal_erase_flash_sector(); 

could you help to check it.

 

void dflash_init()
{
#ifndef FLASH_TARGET
#ifdef S32K144_SERIES
    MSCM->OCMDR[0u] |= MSCM_OCMDR_OCM1(0x3u);
    MSCM->OCMDR[1u] |= MSCM_OCMDR_OCM1(0x3u);
#endif /* S32K144_SERIES */
#endif /* FLASH_TARGET */
    hal_init_flash ();
#if 0
    /* Install interrupt for Flash Command Complete event */
    INT_SYS_InstallHandler(FTFC_IRQn, CCIF_Handler, (isr_t*) 0);
    INT_SYS_EnableIRQ(FTFC_IRQn);
   
    /* Enable global interrupt */
    INT_SYS_EnableIRQGlobal();
#endif
}

status_t hal_init_flash (void)
{
return FLASH_DRV_Init (&Flash1_InitConfig0, &ssdConfig);
}

status_t hal_erase_flash_sector (uint32_t address, uint32_t length)
{
return FLASH_DRV_EraseSector (&ssdConfig, address, length);
}

status_t hal_write_to_flash (uint32_t address, const uint8_t *p_bufSrc,
uint32_t length)
{
status_t ret = STATUS_SUCCESS;
bool lenAligned = (length & (FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE - 1U))
== 0U;
bool addrAligned = (address & (FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE - 1U))
== 0U;
bool inBoundaries = (address >= Flash1_InitConfig0.DFlashBase)
&& ((address + length)
< (Flash1_InitConfig0.DFlashBase + FEATURE_FLS_DF_BLOCK_SIZE));

if (!lenAligned || !addrAligned || !inBoundaries)
{
ret = STATUS_ERROR;
return ret;
}
else
{

bool multiplePages = ((address % FEATURE_FLS_DF_BLOCK_SECTOR_SIZE)
+ length) > FEATURE_FLS_DF_BLOCK_SECTOR_SIZE;

if (!multiplePages) // single sector write
{
ret = hal_write_to_flash_single_sector (address, p_bufSrc, length);
}
else
{
// Write first part - could be not aligned with sector start address
uint16_t lenOfFirstWrite = FEATURE_FLS_DF_BLOCK_SECTOR_SIZE
- (address % FEATURE_FLS_DF_BLOCK_SECTOR_SIZE);
ret = hal_write_to_flash_single_sector (address, p_bufSrc,
lenOfFirstWrite);

length -= lenOfFirstWrite;
address += lenOfFirstWrite;
p_bufSrc += lenOfFirstWrite;

// Write other part of the data, which is aligned with the sector start address
while ((length > 0) & (ret == STATUS_SUCCESS))
{
ret = hal_write_to_flash_single_sector (address, p_bufSrc,
length);
address += FEATURE_FLS_DF_BLOCK_SECTOR_SIZE;
p_bufSrc += FEATURE_FLS_DF_BLOCK_SECTOR_SIZE;
length =
(length > FEATURE_FLS_DF_BLOCK_SECTOR_SIZE) ?
(length - FEATURE_FLS_DF_BLOCK_SECTOR_SIZE) : 0;
}

}
}
return ret;
}

#define FAC_CALIB_SECTOR_ADDRESS  (0x10000000U)
#define FAC_CALIB_SPACE  (2 * FEATURE_FLS_DF_BLOCK_SECTOR_SIZE)  //4KB

 

uint8_t flash_read_write_test()
{
    int ret = 0;
    int i;
    dflash_init();
    int read_count = 188;
    uint8_t fac_buf[read_count];
    uint8_t read_buf[1024];
    int read_pos = 0;
    int test_time = 1;
    int tmp_buf_len = (read_count/8) * 8;
    uint8_t tmp_buf[tmp_buf_len];
    int remain_len = 0;
    int old_remain_len = 0;
    memset(read_buf,0,1024);
    hal_erase_flash_sector (FAC_CALIB_SECTOR_ADDRESS,FAC_CALIB_SPACE);
    for(i=0;i<test_time;i++)
    {
        memset(fac_buf,(i+10),read_count);
        memcpy(&tmp_buf[remain_len],fac_buf,tmp_buf_len-remain_len);
        remain_len = read_count - tmp_buf_len + old_remain_len;
       
        ret = hal_write_to_flash((FAC_CALIB_SECTOR_ADDRESS + i * tmp_buf_len),tmp_buf,tmp_buf_len);
        //ret = hal_read_from_flash((FAC_CALIB_SECTOR_ADDRESS + i * tmp_buf_len),(read_buf + i * tmp_buf_len),tmp_buf_len);
        memset(tmp_buf,0,tmp_buf_len);
        if(tmp_buf_len > old_remain_len)
            memcpy(tmp_buf,&fac_buf[tmp_buf_len-old_remain_len],remain_len);
        else
        {
            printf("out of range\n");
        }
        old_remain_len = remain_len;
    }
    if(remain_len)
    {
        ret = hal_write_to_flash(FAC_CALIB_SECTOR_ADDRESS+ i * tmp_buf_len,tmp_buf,tmp_buf_len);
        //ret = hal_read_from_flash((CALIB_SECTOR_ADDRESS + i * tmp_buf_len),(read_buf + i * tmp_buf_len),remain_len);
    }
    for(i=0;i<test_time;i++)
    {
        ret = hal_read_from_flash((FAC_CALIB_SECTOR_ADDRESS + i * read_count),(read_buf + i * read_count),read_count);
    }

    return ret;

}

 

タグ(1)
0 件の賞賛
返信

819件の閲覧回数
Julián_AragónM
NXP TechSupport
NXP TechSupport

This kind of issues is usually caused by Read-While-Write error. Let me copy here from the reference manual:

Read while Write is allowed within a module and is determined based on block boundaries. Read while Write partitions are used to determine locations for valid read-while-write (RWW) operations. While the embedded flash memory performs a write (program or erase) to a given partition, it can simultaneously perform a read from any other partition. For program and erase operations, only the address specified by an interlock write determines the partition being written (sector or super sector locking does not determine the RWW partitions being written).

Could you try disabling interrupts before launching erase operations?

Also, could you share what you see in the core registers? It could provide enough details to find the source of bus/hard fault. 

 

Julin_AragnM_1-1718836457185.png

Best regards,
Julián

0 件の賞賛
返信

752件の閲覧回数
alice_th
Contributor III

i didn't see that register you show, see below,

 

alice_thanks_0-1719300416877.png

 

0 件の賞賛
返信

730件の閲覧回数
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @alice_th,

If you are trying to download into flash, please follow the documentation. 

Julin_AragnM_0-1719435391909.png

 

0 件の賞賛
返信