In RT1020-EVK, 'FLEXSPI_SoftwareReset' hangs and 'Hard Fault' occurs.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

In RT1020-EVK, 'FLEXSPI_SoftwareReset' hangs and 'Hard Fault' occurs.

Jump to solution
2,447 Views
stanley-kylee
Contributor II

Hello. 

Sorry for my poor English skills.

# Development Environment
- IDE : MCUXpresso IDE v11.5.0 [Build 7232] [2022-01-11]
- Board : MIMXRT1020-EVK (Rev.B1)

# Symptom
- In 'driver_examples' of 'SDK Import' menu, if 'FlexSPI' is integrated into 'igpio_led_output', Hang and Hard Fault occur in 'FLEXSPI_SoftwareReset'.

# Other information
- 'flexspi_nor_polling_transfer' in 'driver_examples' works very fine.
- If 'FlexSPI' is integrated into 'dev_printer_virtual_plain_text_bm' of 'usb_examples', there is no problem.
- When compiling the FlexSPI example source, it was confirmed that the 'SRAM_DTC' and 'SRAM_ITC' areas were used. However, the LED example source integrating FlexSPI uses only 'SRAM_DTC' when compiled.
- Among the attached files, there is no 'linkscripts' folder in the LED example source. It is because the linkscripts folder of the FlexSPI sample source is not booted properly.
- Other options (compile options, RAM settings) are the same.
- If 'Link application to RAM' or 'Plain load image' was checked or set, it did not boot normally.
- I tried setting 'Heap', 'Stack' or 'Global data placement', but the symptoms were the same.

# Attachments
- FlexSPI example source (evkmimxrt1020_flexspi_nor_polling_transfer__20220519.zip)
- Current working LED example source (evkmimxrt1020_igpio_led_output_FlexSPI_20220610.zip)

When AT_QUICKACCESS_SECTION_CODE was applied to the FLEXSPI_SoftwareReset function, it came out of the while statement. However, it stops at the part where configValue is set in 'base->MCR0'.

The SPI source and compilation options are the same. No matter how much I think about it, it should work normally, but it's very frustrating because it doesn't.

I am very curious as to which part of the setting is wrong, so that Hang occurs in FLEXSPI_SoftwareReset, and whether Hard Fault occurs nearby.

Please help me........... I've been struggling with this problem for over 2 weeks.

Thanks for the reply. I wish everyone who reads this article a happy day and good luck.

 

Labels (1)
0 Kudos
1 Solution
2,419 Views
cgarcia1
Contributor II

Maybe he is referring to the fact that if your i.MX RT1020 is executing instructions from FLEXSPI, if you are writing/erasing it (or simply resetting the FLEXSPI controller), it will not be able to load more instructions, what perfectly makes sense.

To solve this problem we may place FLEXSPI_XXX functions in RAM instead of flash. To do so we can refer to the example provided by NXP (flexspi_nor_polling_transfer, for example) and look in the Linker File:

 

In .text (which is finally flash) they exclude the .o related to FLEXSPI interaction:

 

*(EXCLUDE_FILE(*flexspi_nor_flash_ops.o *fsl_flexspi.o) .text*)       *(.rodata .rodata.* .constdata .constdata.*)

 

 

And in .data_RAM2 they add the same .o, do that those functions end up in RAM and execute from there:

 

    /* DATA section for SRAM_ITC */

    .data_RAM2 : ALIGN(4)
    {
        FILL(0xff)
        PROVIDE(__start_data_RAM2 = .) ;
        PROVIDE(__start_data_SRAM_ITC = .) ;
        *(.ramfunc.$RAM2)
        *(.ramfunc.$SRAM_ITC)
        
        *flexspi_nor_flash_ops.o(.text*)
        *fsl_flexspi.o(.text*)
        . = ALIGN(4) ;
        PROVIDE(__end_data_RAM2 = .) ;
        PROVIDE(__end_data_SRAM_ITC = .) ;
     } > SRAM_ITC AT>PROGRAM_FLASH

 

 

Doing this in my project solved the underlying thing. I'm now able to properly handle FLEXSPI with or without optimizations and it works 100% of times. I would then suggest taking as a reference the Linker File from the example.

View solution in original post

0 Kudos
9 Replies
346 Views
m1raculix
Contributor I

Hi all,

i have the same issue. MIMXRT1024 EVK Board, evkmimxrt1024_flexspi_nor_polling_transfer example project working. But when i create a new project and only add the FlexSPI peripheral to it, i get a hard fault error after "BOARD_InitBootPeripherals();"

I have tried the method with the linker script (please see the attached .ld file).

I added:

*(EXCLUDE_FILE(*peripherals.o *fsl_flexspi.o) .text*) - in .text

*peripherals.o(.text*)
*fsl_flexspi.o(.text*) - in .data_RAM2, after *(.data.$SRAM_ITC)

 

One time i got it working, but all other tries failed the same way with hard fault. I can't even reproduce the one time it worked.

 

Thank you very much,

Regards

Maximilian

0 Kudos
2,436 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @stanley-kylee ,

The code is execute in flexspi. If you reset flexspi, how can M7 read code?

In the flexspi example, it put flexspi_nor_flash_ops.c and fsl_flexspi.c in ITCM. Please see the link file of the flexspi example.

.data_RAM2 : ALIGN(4)
{
FILL(0xff)
PROVIDE(__start_data_RAM2 = .) ;
PROVIDE(__start_data_SRAM_ITC = .) ;
*(.ramfunc.$RAM2)
*(.ramfunc.$SRAM_ITC)

*flexspi_nor_flash_ops.o(.text*)
*fsl_flexspi.o(.text*)
. = ALIGN(4) ;
PROVIDE(__end_data_RAM2 = .) ;
PROVIDE(__end_data_SRAM_ITC = .) ;
} > SRAM_ITC AT>PROGRAM_FLASH

 

Regards,

Jing

0 Kudos
2,422 Views
stanley-kylee
Contributor II

Hello Jing.

 

I do not understand the following sentence. -> "how can M7 read code?"

I am a beginner in NXP MCU. Can you explain it easily?

 

Where can I see the contents of 'data_RAM2' you mentioned? Are you talking about the linkscript folder?

 

Thanks in advance for your reply.

0 Kudos
2,420 Views
cgarcia1
Contributor II

Maybe he is referring to the fact that if your i.MX RT1020 is executing instructions from FLEXSPI, if you are writing/erasing it (or simply resetting the FLEXSPI controller), it will not be able to load more instructions, what perfectly makes sense.

To solve this problem we may place FLEXSPI_XXX functions in RAM instead of flash. To do so we can refer to the example provided by NXP (flexspi_nor_polling_transfer, for example) and look in the Linker File:

 

In .text (which is finally flash) they exclude the .o related to FLEXSPI interaction:

 

*(EXCLUDE_FILE(*flexspi_nor_flash_ops.o *fsl_flexspi.o) .text*)       *(.rodata .rodata.* .constdata .constdata.*)

 

 

And in .data_RAM2 they add the same .o, do that those functions end up in RAM and execute from there:

 

    /* DATA section for SRAM_ITC */

    .data_RAM2 : ALIGN(4)
    {
        FILL(0xff)
        PROVIDE(__start_data_RAM2 = .) ;
        PROVIDE(__start_data_SRAM_ITC = .) ;
        *(.ramfunc.$RAM2)
        *(.ramfunc.$SRAM_ITC)
        
        *flexspi_nor_flash_ops.o(.text*)
        *fsl_flexspi.o(.text*)
        . = ALIGN(4) ;
        PROVIDE(__end_data_RAM2 = .) ;
        PROVIDE(__end_data_SRAM_ITC = .) ;
     } > SRAM_ITC AT>PROGRAM_FLASH

 

 

Doing this in my project solved the underlying thing. I'm now able to properly handle FLEXSPI with or without optimizations and it works 100% of times. I would then suggest taking as a reference the Linker File from the example.

0 Kudos
2,415 Views
stanley-kylee
Contributor II

Thanks for your reply!

I checked the contents of '.text' and '.data_RAM2' in the '.ld' file in the Debug folder of the project.

I checked that the contents of the '.ld' file of the FlexSPI project and the '.ld' file of the GPIO project are different.

Because the '.ld' file is an automatically generated file, it is not reflected even if the '.ld' file is modified.

Please tell me which menu to enter to edit the '.text' area and the 'data_RAM2' area like the corresponding contents.

Or, if you give me a link that I can refer to, I'll follow it.

 

Thank you. It seems we have finally reached the end of the problem.

0 Kudos
2,412 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi, @stanley-kylee ,

You can copy the three linkscript files (*.ldt) from RT1020_flexspi_nor_polling_transfer to your project. The IDE can import these files and modify the .ld file.

jingpan_0-1655101356068.png

Please refer to MCUXpresso_IDE_User_Guide.pdf which is in your install directory.

 

Regards,

Jing

 

0 Kudos
2,409 Views
stanley-kylee
Contributor II

Thanks for the detailed and kind explanation.

I put
"*(EXCLUDE_FILE(*flexspi_nor_flash_ops.o *fsl_flexspi.o) .text*) *(.rodata .rodata.* .constdata .constdata.*)"
in 'main_text.ldt' of the linkscripts folder,

I put '.o' in 'data.ldt' and set the #if statement to be limited to 'RAM2'.
Then I confirmed that it was working normally.

Thank you very much.

I can sleep well from today.

0 Kudos
2,440 Views
cgarcia1
Contributor II

We are in the same boat. I observed the same behaviour: FLEXSPI_SoftwareReset causes a hardfault, but somehow it works with optimizations enabled.

So, with -O0 FLEXSPI_SoftwareReset() just crashes like happens to you. In my scenario, with -O2 it works just fine.

This will not help to solve the underlying problem that might be there, but at least in that particular case optimizing with -O2 will overcome the hurdle.

 

If you are debugging (like it is my case) optimizations are undesired. What I did is copying the contents of FLEXSPI_SoftwareReset() where I did call it (since that function is "inline") and then optimize with __attribute__((optimize("-O2"))) the function where I initialize FLEXSPI.

0 Kudos
2,423 Views
stanley-kylee
Contributor II

Hello cgarcia1.

Thanks for your reply.

 

I will refer to your answer.

As you said, "-O2" optimization is undesirable, so I'm only going to use it in the worst case.

0 Kudos