Trackdown the exceptions in MQX

Document created by Jerry Fan Employee on Apr 14, 2013Last modified by Martin Kojtal on May 14, 2013
Version 4Show Document
  • View in full screen mode

When working on Cortex-M4 platform, an exception which has not been expected (an interrupt without ISR, an access to an illegal address, etc).

The code below shows how to implement it.


static void expt_frm_dump(pointer ext_frm_ptr)
  static char *expt_name[] = {
    "Debug Monitor",

  uint_32 excpt_num = __get_PSR() & 0x1FF;
  printf("Opps, bad thing happened.\n");
  if(excpt_num < 16){
    printf("The exception [%s] invoked in TASK 0x%x\n",
         expt_name[excpt_num] , _task_get_id());

    printf("Dump the exception frame as :\n");
    printf("R0:\t0x%08x\n", *((uint_32 *)ext_frm_ptr));
    printf("R1:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 1));
    printf("R2:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 2));
    printf("R3:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 3));
    printf("R12:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 4));
    printf("LR:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 5));
    printf("PC:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 6));
    printf("PSR:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 7));
    printf("The external interrupt %d occured while no handler to serve it.\n");

void  task_exception_handler(_mqx_uint para, pointer stack_ptr)
    pointer expt_frm_ptr = (pointer)__get_PSP();

void test_task(unsigned long para)
  unsigned int *p_bad = (unsigned int *)0;

  printf("Install the _int_exception_isr to replace the _int_default_isr\n");

  /* Set the exception handler of the task */
  _task_set_exception_handler(_task_get_id(), task_exception_handler);

  *p_bad = 0;     // an access to address 0