Is there some code or information that must remain on the FLASH in order to run?

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

Is there some code or information that must remain on the FLASH in order to run?

928 Views
adamwieseler
Contributor I

I am using the MK24FN1M0VLL12, and I am able to get my code execute directly from FLASH, However when I attempt to move my code into RAM to start executing from RAM (In order to free up the FLASH for (READ, WRITE, ERASE commands)) I keep getting a constant reset. Is there some code or information that must remain on the FLASH in order to run?

For more clarification the only thing I leave in FLASH is vector table and InRoot$$Sections.

Labels (1)
0 Kudos
7 Replies

674 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Adam,

    All the code can be put into the RAM, could you tell me how did you put your code into RAM?

    When you went in the reset, did you check the reset type, which source caused this reset.

    Please also copy your vector table to the RAM.

Wish it helps you!


Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

674 Views
adamwieseler
Contributor I

Jingjing,

I have a scatter load file that specifies all the code to be placed in RAM location.

I am not sure how to check the reset type.

I also move the vector table to RAM but that does not happen until I start my __main()

It appears that I have to leave the object files that contain the code in the "hwm_pwrp_init" function in FLASH for this to function but not sure why. I did not think the scatter file was even used until the __main() is called.

here is my reset isr code:

;-----------------------------------------------------------------------------------------------

;                                          EXPORTS

;-----------------------------------------------------------------------------------------------

    EXPORT  hwm_reset_isr

;-----------------------------------------------------------------------------------------------

;                                          IMPORTS

;-----------------------------------------------------------------------------------------------

    IF ( :DEF:HWM_BOOT_TEST )

        IMPORT hwm_pwrp

    ELSE

        IMPORT  __main

    ENDIF

    IMPORT  hwm_pwrp_init

;-----------------------------------------------------------------------------------------------

;                                       GENERAL INCLUDES

;-----------------------------------------------------------------------------------------------

    INCLUDE hwm_pub_mem_map.h2i

;-----------------------------------------------------------------------------------------------

;                                    DESIGN ASSURANCE LEVEL

;-----------------------------------------------------------------------------------------------

; ASSERT_LEVEL_B( hwm_boot )

;-----------------------------------------------------------------------------------------------

;                                       LITERAL CONSTANTS

;-----------------------------------------------------------------------------------------------

;-----------------------------------------------------------------------------

; Internal watchdog controls

;-----------------------------------------------------------------------------

ADDR_WDOG_CTRL  EQU     0x40052000          ; watchdog control register address

ADDR_WDOG_UNLK  EQU     0x4005200E          ; watchdog unlock register address

WDOG_DIS_VAL_1  EQU     0xC520              ; first value to disable watchdog

WDOG_DIS_VAL_2  EQU     0xD928              ; second value to disable watchdog

WDOG_EN_VAL     EQU     1                   ; bit to clear in WDOG_CONTROL

STACK_FILL_SIZE EQU     0x20                ; number of bytes written at once

                                            ;  (8 32-bit registers)

                                            ; NOTE: Assumes the stack is a

                                            ; multiple of 0x20 bytes.

;-----------------------------------------------------------------------------------------------

;                                       MEMORY CONSTANTS

;-----------------------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------------------

;                                           VARIABLES

;-----------------------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------------------

;                                             MACROS

;-----------------------------------------------------------------------------------------------

    PRESERVE8

    THUMB

    AREA    |.text|, CODE, READONLY

;-----------------------------------------------------------------------------------------------

;                                           PROCEDURES

;-----------------------------------------------------------------------------------------------

;*************************************************************************************

;

;   PROCEDURE NAME:

;       hwm_reset_isr

;

;   DESCRIPTION:

;       Reset vector

;

;*************************************************************************************

;-----------------------------------------------------------------------------

;void hwm_reset_isr

;    (

;    void

;    );

;-----------------------------------------------------------------------------

    PRESERVE8

hwm_reset_isr   PROC

    ;-------------------------------------------------------------------------

    ; Write the first watchdog unlock value

    ;-------------------------------------------------------------------------

    ldr     r0, =ADDR_WDOG_UNLK

    ldr     r1, =WDOG_DIS_VAL_1

    strh    r1, [r0]

    ;-------------------------------------------------------------------------

    ; Write the second watchdog unlock value

    ; NOTE: We must wait 1 op after unlocking [ref 24.3.1]

    ;-------------------------------------------------------------------------

    ldr     r1, =WDOG_DIS_VAL_2

    strh    r1, [r0]

    nop

    ;-------------------------------------------------------------------------

    ; Disable the watchdog now that it is unlocked

    ;-------------------------------------------------------------------------

    ldr     r0, =ADDR_WDOG_CTRL

    ldrh    r1, [r0]

    bic     r1, r1, #WDOG_EN_VAL

    strh    r1, [r0]

;-----------------------------------------------------------------------------

; Reset the master stack pointer since its not done automatically when

; transitioning to the system image

;-----------------------------------------------------------------------------

    ldr     r0, =HWM_MEM_STACK_MSP_BASE

    add     r0, r0, #HWM_MEM_STACK_MSP_SIZE

    msr     msp, r0

;-----------------------------------------------------------------------------

; Call hwm_pwrp_init() to perform basic hardware powerup

;-----------------------------------------------------------------------------

    bl      hwm_pwrp_init

;-----------------------------------------------------------------------------

; Initialize the master stack to known values we can check the max stack usage

; NOTE: Assumes the stack is a multiple of 0x20 bytes!

;-----------------------------------------------------------------------------

    ldr     r0, =HWM_MEM_STACK_MSP_BASE

    ldr     r1, =HWM_MEM_STACK_MSP_SIZE

    ldr     r2, =TSK_STACK_FILL_VAL

    mov     r3, r2

    mov     r4, r2

    mov     r5, r2

    mov     r6, r2

    mov     r7, r2

    mov     r8, r2

    mov     r9, r2

stack_init

    stm     r0!, { r2-r9 }

    subs    r1, r1, #STACK_FILL_SIZE

    bgt     stack_init

;-------------------------------------------------------------------------

; Branch to __main() to perform library initialization

; It will branch to main() upon completion and never return

;-------------------------------------------------------------------------

    IF ( :DEF:HWM_BOOT_TEST )

        ldr     r0, =hwm_pwrp

    ELSE

        ldr     r0, =__main

    ENDIF

    bx      r0

;-----------------------------------------------------------------------------

; We should never return here.  If we do, the watchdog will reset the unit.

;-----------------------------------------------------------------------------

    b       .

    ENDP    ; hwm_reset_isr()

    ALIGN

    END


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos

674 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Could you upload your project, and tell me your IDE?

I would like to help you to check it.

Best Regards,

Jingjing

0 Kudos

674 Views
adamwieseler
Contributor I

The IDE I am using is CodeWarrior. I would rather not upload my project because of proprietary code mixed in all over the code. Does the fact that scatter loading happens at __main() call, mean that I can not move the functions in the reset ISR?

0 Kudos

674 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Adam,

    Ok,  I understand it if your project mixed a lot of proprietary code.

    Did you debug it step by step? Just to check which code will cause the reset problem.

    You should add the main in the reset ISR, because after reset, the code need enter in the main function, now whether your code can enter the main? Or will reset before enter in the main function?

  Besides, did you disable the watchdog, whether this reset is caused by the hardware watchdog?


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

674 Views
adamwieseler
Contributor I

Jingjing,

There are 3 object code files that contain functions defined in the reset

ISR above and if I have those object files moved to SRAM in scatter file

when I power cycle the board after uploading BIN to flash the code does not

even appear to get to the reset ISR. With this scenario I can not even

start the debug process.

Also the watchdog is disabled in the reset ISR as posted before.

On Tue, Jun 7, 2016 at 2:13 AM kerryzhou <admin@community.freescale.com>

0 Kudos

674 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Adam,

    I attach a project of K60 which can run from the RAM, you can refer to that code to modify your code.

    Besides, could you tell me your code size? If you want to run from RAM, you should make sure your code size is smaller than the chip's RAM size.

  If you still not OK, you can copy a project, and delete your important code, just leave a main with the basic code or empty project, and test the run from RAM directly, after this empty project can run from RAM successfully, then add your own code.


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos