I am using code composer studio version 6.1 with TM4C123GH6PM. When dubugging and executing it goes to a function called FaultISR() and then stuck in an infinite loop When trying to see the registers values it display an error message instead of the value of the register:
Error: unable to read
and in the console displays :
CORTEX_M4_0: Trouble Reading Memory Block at 0x400253fc on Page 0 of Length 0x4: Debug Port error occurred.
as the following picture says.
edit
that is my code: It is a led blinking consisting of four files: - DIO.h and DIO.c : which is a driver to the input/output hardware - Reg_Macros.h - blink.c : the app
DIO.h
#ifndef DIO_H_
#define DIO_H_
#include "BasicTypes.h"
/*Values of Port Name*/
#define PA 0
#define PB 1
#define PC 2
#define PD 3
#define PE ox20
#define PF 0x21
/*Pad Current Control*/
#define CRT_2M 0x00
#define CRT_4M 0x01
#define CRT_8M 0x02
/*Pad Input resistance control*/
#define RES_NO 0x00
#define RES_PU 0x01
#define RES_PD 0x02
typedef struct
{
unsigned int PortName;
unsigned int PortMask;
unsigned int PortDirection;
unsigned int InterRes;
unsigned int PadCrnt;
}DIO_InitParamtersType;
typedef struct
{
unsigned int PortName;
unsigned int PortMask;
unsigned int PortData;
}DIO_WriteParametersType;
void DIO_Init(DIO_InitParamtersType* InitParamters);
void DIO_Write(DIO_WriteParametersType* WriteParamters);
#endif /* DIO_H_ */
DIO.c
#include "DIO.h"
#include "Reg_Macros.h"
/*Register addresses calculation macros*/
#define REG_ADD_BIT_BANDING(PORT_ID,PORT_MASK,REG_OFFSET) ((volatile uint32_t *)(((PORT_MASK) << 2) + ((PORT_ID) << 12) + (REG_OFFSET) + (GPIO_APB_REG_ADD_BASE)))
#define REG_ADD(PORT_ID,REG_OFFSET) ((volatile uint32_t *)(((PORT_ID) << 12) + (REG_OFFSET) + (GPIO_APB_REG_ADD_BASE)))
/*Enable Port clock macro*/
#define ENABLE_PORT_CLOCK(PORT_ID) SYSCTL_RCGC2_R |= 1 << (PORT_ID)
/*Write Data Macro*/
#define DIO_WRITE_DATA(PORT_ID,PORT_MASK,PORTD_DATA) *REG_ADD_BIT_BANDING((PORT_ID),(PORT_MASK),(GPIODATA_REG_OFFSET))= PORTD_DATA
/*Init Direction macro*/
#define DIO_INIT_DIRECTION(PORT_ID,PORT_MASK,PORT_DIRECTION) *(REG_ADD((PORT_ID),(GPIODIR_REG_OFFSET))) &= ~(PORT_MASK); \
*(REG_ADD((PORT_ID),(GPIODIR_REG_OFFSET))) |= (PORT_DIRECTION & PORT_MASK)
/*Init Output Current macro*/
#define DIO_INIT_PAD_CRNT(PORT_ID,PORT_MASK,CRT_ID) *REG_ADD((PORT_ID),((GPIOCRT_CTRL_REG_OFFSET) + ((CRT_ID)*4))) |= (PORT_MASK)
/*Init Input Resistor macro*/
#define DIO_INIT_PAD_RES(PORT_ID,PORT_MASK,RES_ID) *REG_ADD((PORT_ID),((GPIORESISTOR_CTRL_REG_OFFSET) + ((RES_ID)*4))) |= (PORT_MASK)
/*Activate and Deactivate Digital Enable macro*/
#define DIO_ACTIVATE_DEGITAL_ENABLE(PORT_ID,PORT_MASK) *REG_ADD((PORT_ID),(GPIODEN_REG_OFFSET)) |= (PORT_MASK)
#define DIO_DEACTIVATE_DIGITAL_ENABLE(PORT_ID,PORT_MASK) *REG_ADD((PORT_ID),(GPIODEN_REG_OFFSET)) &= ~(PORT_MASK)
/*Activate and DeAcivate Alternate function*/
#define DIO_ACTIVATE_ALTERNATE_FUNC(PORT_ID,PORT_MASK) *REG_ADD(PORT_ID,GPIOAFSEL_REG_OFFSET) |= PORT_MASK
#define DIO_DEACTIVATE_ALTERNATE_FUNC(PORT_ID,PORT_MASK) *REG_ADD(PORT_ID,GPIOAFSEL_REG_OFFSET) |= *(PORT_MASK)
void DIO_Init(DIO_InitParamtersType* InitParamters)
{
/*Enable Port Clock*/
ENABLE_PORT_CLOCK(InitParamters->PortName);
/*Init PortDirection Direction*/
DIO_INIT_DIRECTION(InitParamters->PortName,InitParamters->PortMask,InitParamters->PortDirection);
/*Init Pad Current*/
DIO_INIT_PAD_CRNT(InitParamters->PortName,InitParamters->PortMask,InitParamters->PadCrnt);
/*Init Pad Input Resistance*/
DIO_INIT_PAD_RES(InitParamters->PortName,InitParamters->PortMask,InitParamters->InterRes);
/*Activate Digital Enable of Port*/
DIO_ACTIVATE_DEGITAL_ENABLE(InitParamters->PortName,InitParamters->PortMask);
}
void DIO_Write(DIO_WriteParametersType* WriteParamters)
{
DIO_WRITE_DATA(WriteParamters->PortName,WriteParamters->PortMask,WriteParamters->PortData);
}
Reg_Macros.h
#ifndef REG_MACROS_H_
#define REG_MACROS_H_
#include <stdint.h>
/*System control registers*/
#define SYSCTL_RCGC2_R (*((volatile unsigned int *)0x400FE108))
/*GPIO APB Regesters address base*/
#define GPIO_APB_REG_ADD_BASE 0x40004000
/*GPIO DIO Registers Offsets*/
#define GPIODATA_REG_OFFSET 0x000
#define GPIODIR_REG_OFFSET 0x400
#define GPIOCRT_CTRL_REG_OFFSET 0x500
#define GPIORESISTOR_CTRL_REG_OFFSET 0x50C
#define GPIODEN_REG_OFFSET 0x51C
#define GPIOAFSEL_REG_OFFSET 0x420
#define GPIOLOCK_REG_OFFSET 0x520
#define GPIOCR_REG_OFFSET 0x524
#endif
blink.c
#include "DIO.h"
void ISRGPIOA(void){
}
int main(void)
{
DIO_InitParamtersType x;
DIO_WriteParametersType DataON;
DIO_WriteParametersType DataOFF;
x.PortName = PF;
x.PortDirection = 0xff;
x.PortMask = 0x0E;
x.PadCrnt = CRT_2M;
x.InterRes = RES_NO;
DataON.PortName = PF;
DataON.PortMask = 0x02;
DataON.PortData = 0xff;
DataOFF.PortName = PF;
DataOFF.PortMask = 0x02;
DataOFF.PortData = 0x00;
unsigned int Delay = 0;
DIO_Init(&x);
while(1)
{
//LED ON
DIO_Write(&DataOFF);
for(Delay = 0 ; Delay < 2000000 ; Delay ++){
}
//LED OFF
DIO_Write(&DataON);
for(Delay = 0 ; Delay < 2000000 ; Delay ++){
}
}
}
#define PE ox20
but I don't think you use that, so it isn't the cause of your current problem. However that obviously reduces my confidence in the code. || I don't see the code which sets-up the system clock register, but it may be in startup code. || Some of the macros look suspicious to me, but those are not being used. || When you single-step the code, which specific source line causes it to enterFaultISR()
? \$\endgroup\$ – SamGibson Sep 11 '16 at 3:03