; ---------------------------------------------------------------------------
; prepare_cm0.cmm
; ---------------------------------------------------------------------------
  PMACRO.EXPLICIT

  PRIVATE &resetvector

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

; ---------------------------------------------------------------------------
prepare_cm0:

  ; enable reset vector catch
  InterCom ALL TrOnchip.Set CORERESET ON

  ; workaround, could not stop target in supervisory flash
  SYStem.Option.SYSRESETREQ ON ; software reset during system.up

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

  ; get cm0 reset-vector from CM0_VECTOR_TABLE_BASE
  &resetvector=Data.Long(A:(Data.Long(A:0x40201120)+0x4))

  REPEAT
  (
    ; go until pc reaches resetvector
    Go.direct &resetvector
    WAIT !STATE.RUN() 1s
    IF TIMEOUT()
    (
      PRINT %WARNING "Start vector not reached"
      ENDDO
    )
  )
  WHILE (STATE.TARGET()=="stopped at vector catch")

  ENDDO
