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