How to identify an exception handler: K70 with MQX

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

How to identify an exception handler: K70 with MQX

2,794 Views
garylynch
Contributor IV

I am trying to modify what is supposed to be a debugged, functional application that runs on the K70 processor and uses MQX. I am using IAR's Embedded Workbench in debug mode.

After seeing it go off in the weeds consistently I tracked down the instruction that instigates this. It is an attempt to read the UART4 status register 1:
    s1Save = UART_S1_REG(channel);

The equivalent in the disassembly window is:
    LDRB R0, [R4,#0x4]

when I single-step in disassembly mode, it apparently triggers an exception handler, as the next address in the PC is 0x26DE2. Single-stepping in here pulls up an assembly source file: dispatch.S, containing these instructions:
ASM_LABEL(_int_kernel_isr)
cpsid.n i
push {lr}

GET_KERNEL_DATA r3 /* get the kernel data address */

/* increment in interrupt counter */
ldrh r1, [r3, #KD_IN_ISR]
add r1, r1, #1
strh r1, [r3, #KD_IN_ISR]

/* create interrupt content */
ldr r0, =0 /* error code (set 0) */
push {r0} /* store in stack */
mrs r2, BASEPRI /* actual priority */
mrs r1, IPSR /* exception number */
ldr r0, [r3, #KD_INTERRUPT_CONTEXT_PTR] /* previous interrupt content */

I single-stepped down to the 'mrs r1, IPSR', just to see what gets loaded into r1, and the value is 3.

I am new to MQX, have mostly debugged Cortex M4 at the C level and am looking for clues what the long-gone prior developer has done to make UART4 unreachable. Have I uncovered anything relevant? What better approach is there to finding this?

Thanks.

0 Kudos
Reply
9 Replies

2,741 Views
garylynch
Contributor IV

Daniel,

Thank you for your follow-up.  I changed that line in user_config.h to:

#define BSPCFG_ENABLE_TTYE 0
#define BSPCFG_ENABLE_ITTYE 1 /* Enable UART4 for interrupt-driven I/O */

but it made no difference. My app still winds up in the exception handler.

Is there a list I can consult that shows which registers must be initialized before I can access the UART? I would rather not assume that MQX will do everything for me, as I can't talk to the original programmer.

Thanks again for your help.

0 Kudos
Reply

2,734 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi  @garylynch :

 

I just test this feature on my side,

what you need to do is :

1)  user_config.h

 #define BSPCFG_ENABLE_ITTYE 1 /* Enable UART4 for interrupt-driven I/O */

2)in your application, you need to open and init this driver

MQX_FILE_PTR  uart4_handle;

 uart4_handle = fopen( "ittye:", NULL );

3) rebuild bsp, and psp. and your application.

4) then you can access the uart4 registers.

 

uart-reg.png

 

Regards

Daniel

2,736 Views
danielchen
NXP TechSupport
NXP TechSupport

 

After you modified the user_config.h

you should make clean bsp and psp, and rebuild bsp and psp again.

 

Regards

Daniel

0 Kudos
Reply

2,771 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi  

 Uart 4 is not enabled in your user_config.h file,   uart4  is  BSPCFG_ENABLE_TTYE

 

#define BSPCFG_ENABLE_TTYE 0
#define BSPCFG_ENABLE_ITTYE 0

 

If you use interrupt mode uart , please enable it like:

 

#define BSPCFG_ENABLE_ITTYE 1

 

Please try it again.

 

0 Kudos
Reply

2,784 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Gary:

Most of the time , hardware fault is resulted from illegal memory accesses. There is one document describes the Coretex-M fault exceptions.

Please refer to below document:

https://www.keil.com/appnotes/files/apnt209.pdf

 

Regards

Daniel

0 Kudos
Reply

2,791 Views
garylynch
Contributor IV

Since my initial posting I have found a table of exception numbers and number 3 corresponds to 'HardFault." I am still working on how that applies to the UART and trying to read a status register.

0 Kudos
Reply

2,784 Views
danielchen
NXP TechSupport
NXP TechSupport

 

Please also check whether UART4 is enabled in user_config.h ?

If the uart clock is not enabled, the access for UART4 register will result in an hardfault.

 

Regards

Daniel

0 Kudos
Reply

2,778 Views
garylynch
Contributor IV

Daniel,

Thank you for the input. I am still searching for the point where UART initialization was removed. I suspected this and searched for it in the:

  • K70 Sub-Family Reference Manual with Addendum, and

  • Cortex-M4, Revision r0p0, Technical Reference Manual

before I wrote this post. Is this info in one of those manuals and I simply couldn't find it, or can the answer only be obtained on forums like this one?

I scanned my user_config.h file but could see nothing relevant to UARTs or clocks. I also checked:

  • Freescale MQX™ RTOS User's Guide,

  • Getting Started with Freescale MQX™ RTOS

but came up empty. I will post the whole file here and ask what is missing:

/*HEADER**********************************************************************
*
* Copyright 2008 Freescale Semiconductor, Inc.
*
* This software is owned or controlled by Freescale Semiconductor.
* Use of this software is governed by the Freescale MQX RTOS License
* distributed with this Material.
* See the MQX_RTOS_LICENSE file distributed for more details.
*
* Brief License Summary:
* This software is provided in source form for you to use free of charge,
* but it is not open source software. You are allowed to use this software
* but you cannot redistribute it or derivative works of it in source form.
* The software may be used only in connection with a product containing
* a Freescale microprocessor, microcontroller, or digital signal processor.
* See license agreement file for full license terms including other
* restrictions.
*****************************************************************************
*
* Comments:
*
* User configuration for MQX components
*
*END**************************************************************************/

#ifndef __user_config_h__
#define __user_config_h__

/* mandatory CPU identification */
#define MQX_CPU PSP_CPU_MK70F120M

/* Silicon version number */
#define MK70_REV_1_0 1

/* MGCT: <generated_code> */
//#define BSPCFG_ENABLE_TTYX 1

#define BSPCFG_ENABLE_TTYA 0
#define BSPCFG_ENABLE_ITTYA 0
#define BSPCFG_ENABLE_TTYB 0
#define BSPCFG_ENABLE_ITTYB 0
#define BSPCFG_ENABLE_TTYC 0
#define BSPCFG_ENABLE_ITTYC 0
#define BSPCFG_ENABLE_TTYD 0
#define BSPCFG_ENABLE_ITTYD 1
#define BSPCFG_ENABLE_TTYE 0
#define BSPCFG_ENABLE_ITTYE 0
#define BSPCFG_ENABLE_TTYF 0
#define BSPCFG_ENABLE_ITTYF 0
#define BSPCFG_ENABLE_I2C0 1 // I2C0 should be enabled for communication to HUB
#define BSPCFG_ENABLE_II2C0 1
#define BSPCFG_ENABLE_I2C1 0
#define BSPCFG_ENABLE_II2C1 0
#define BSPCFG_ENABLE_SPI0 0
#define BSPCFG_ENABLE_SPI1 0
#define BSPCFG_ENABLE_SPI2 0
#define BSPCFG_ENABLE_RTCDEV 0
#define BSPCFG_ENABLE_PCFLASH 0
#define BSPCFG_ENABLE_ADC0 0
#define BSPCFG_ENABLE_ADC1 0
#define BSPCFG_ENABLE_ADC2 0
#define BSPCFG_ENABLE_ADC3 0
#define BSPCFG_ENABLE_FLASHX 1
#define BSPCFG_ENABLE_ESDHC 1
#define BSPCFG_ENABLE_IODEBUG 0
#define BSPCFG_ENABLE_NANDFLASH 0
#define BSPCFG_ENABLE_SAI 0

#define BSPCFG_HAS_SRAM_POOL 1
#define BSPCFG_ENET_SRAM_BUF 0

#define MQX_ROM_VECTORS 0
#define MQX_USE_IDLE_TASK 1
#define MQX_TASK_DESTRUCTION 1
#define MQX_HAS_TIME_SLICE 1
#define MQX_USE_TIMER 1

#define MQX_KERNEL_LOGGING 0
#define MQX_USE_LOGS 0
#define MQX_USE_LWLOGS 0

#define MQX_ENABLE_LOW_POWER 0
#define MQX_IS_MULTI_PROCESSOR 0
#define MQX_USE_IPC 0

#define MQX_USE_UNCACHED_MEM 1
#define MQX_USE_LWMEM_ALLOCATOR 0

#define MQXCFG_ENABLE_FP 1
#define MQX_INCLUDE_FLOATING_POINT_IO 1

#define MQX_SAVE_FP_ALWAYS 1

#define MFSCFG_READ_ONLY 0
#define MFSCFG_MINIMUM_FOOTPRINT 1

#define RTCSCFG_ENABLE_ICMP 1
#define RTCSCFG_ENABLE_UDP 1
#define RTCSCFG_ENABLE_TCP 1
#define RTCSCFG_ENABLE_STATS 1
#define RTCSCFG_ENABLE_GATEWAYS 1
#define FTPDCFG_USES_MFS 1
#define RTCSCFG_ENABLE_SNMP 0

#define TELNETDCFG_NOWAIT FALSE

#define HTTPDCFG_POLL_MODE 0
#define HTTPDCFG_STATIC_TASKS 0
#define HTTPDCFG_DYNAMIC_TASKS 0

/* MGCT: </generated_code> */

#define ENETCFG_SUPPORT_PTP 0

/*
** include common settings
*/
#define MQX_USE_IO_OLD 1


/* use the rest of defaults from small-RAM-device profile */
#include "small_ram_config.h"

/* and enable verification checks in kernel */
#include "verif_enabled_config.h"

#endif /* __user_config_h__ */

Anything stand out? (Thanks again).

0 Kudos
Reply

2,750 Views
danielchen
NXP TechSupport
NXP TechSupport

 

Please enable

#define BSPCFG_ENABLE_ITTYE 1

in user_config.h

 

0 Kudos
Reply