; ---------------------------------------------------------------------------
; prepare_cm4.cmm
; ---------------------------------------------------------------------------
  PMACRO.EXPLICIT

  PRIVATE &resetvector

  ; show path and name of this script (present practice file)
  ECHO ""
  ECHO %COLOR.BLUE "### " OS.PPF() " ###"

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

  ; disable reset vector catch for Cortex-M0
  TrOnchip.Set CORERESET OFF

  ; enable reset vector catch for Cortex-M4
  InterCom M4 TrOnchip.Set CORERESET ON

  ; reset target system (cm0 and cm4)
  SYStem.Up
  DO prepare_system.cmm

  ; attch to Cortex-M4
  InterCom M4 SYStem.Attach

  ; let Cortex-M0+ run
  Go.direct

  ; CM4 should be stopped at reset vector catch
  InterCom.WAIT M4 !STATE.RUN()

  ; get CM4 resetvector out of CM4_VECTOR_TABLE_BASE register
  &resetvector=Data.Long(A:(Data.Long(A:0x40200200)+0x4))

  ; CM4: go until pc reaches resetvector
  InterCom M4 Go.direct &resetvector
  InterCom.WAIT M4 !STATE.RUN()

  ECHO %COLOR.GREEN "CM4 Core ready!"

  ENDDO

