AnsweredAssumed Answered

Hard Fault on LPC55S69 single core project

Question asked by Safiullah Hussaini on Jul 2, 2019
Latest reply on Jul 2, 2019 by Sabina Bruce

I have a single core project where I need to turn on the capture and the match functions on timer 0.

 

I turn on the Capture 1 on Timer 0 and everything works fine. But as soon as I turn on the Match 1 with interrupt. I get a hard fault. When I step through the code I can't find where the hard fault is actually generated. Stepping through the code I get no hard faults.

 

The code is also running a USART (USART2) in polling mode to transmit some data.

 

/******************************************************************************
 * Prototypes
 *****************************************************************************/
void ctimer_capture_callback(uint32_t arg_flags);
void ctimer_match_callback(uint32_t arg_flags);

/******************************************************************************
 * Global Variables
 *****************************************************************************/
char g_usart2_str [256];
ctimer_config_t g_ctimer0_config, ctimer1_config;
ctimer_match_config_t ctimer0_match_config;
ctimer_match_config_t ctimer1_match_config;
usart_config_t g_usart2_config;
ctimer_callback_t g_ctimer0_callback[] = {NULL,  ctimer_match_callback, NULL, NULL, NULL, ctimer_capture_callback, ctimer_capture_callback, NULL};
uint32_t g_timer0_val = 0;
uint32_t g_timer0_val_copy = 0;
uint32_t g_timer0_val_prev = 0;
uint8_t g_timer0_overflow = 0;
uint8_t g_timer0_val_valid = 0;
… Some more definitions … 
/******************************************************************************
 * Function Definition
 *****************************************************************************/
void ctimer_capture_callback(uint32_t arg_flags)
{
 CTIMER_Reset(CTIMER0);
 g_timer0_val = CTIMER0->CR[1];
 g_timer0_val_valid = 1;
 g_printf_sig++;
}
void ctimer_match_callback(uint32_t arg_flags)
{
 g_timer0_overflow++;
}
/*
 * @brief   Application entry point.
 */
int main(void) {
 //Declarations
   // Init board hardware.
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();
   // Init FSL debug console.
    BOARD_InitDebugConsole();
    BOARD_BootClockPLL100M();
    CLOCK_AttachClk(kMAIN_CLK_to_CTIMER0);
    CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2);
    PRINTF("Configuring Timer 0...\n");
    const uint32_t port1_pin26_config = ( //Configure as CT_INP3
              IOCON_FUNC3 |
                                            // No addition pin function
           IOCON_MODE_PULLUP |
                                            // Standard mode, output slew rate control is enabled
                                            IOCON_PIO_SLEW_STANDARD |
                                            // Input function is not inverted
                                            IOCON_PIO_INV_DI |
                                            // Enables digital function
                                            IOCON_PIO_DIGITAL_EN |
                                            // Open drain is disabled
                                            IOCON_PIO_OPENDRAIN_DI);
    // PORT1 PIN26
    IOCON_PinMuxSet(IOCON, 1, 26, port1_pin26_config);
    const uint32_t port1_pin24_config = ( //Configure as FC2_USART_RXD
              IOCON_FUNC1 |
                                            // No addition pin function
           IOCON_MODE_INACT |
                                            // Standard mode, output slew rate control is enabled
                                            IOCON_PIO_SLEW_STANDARD |
                                            // Input function is not inverted
                                            IOCON_PIO_INV_DI |
                                            // Enables digital function
                                            IOCON_PIO_DIGITAL_EN |
                                            // Open drain is disabled
                                            IOCON_PIO_OPENDRAIN_DI);
    // PORT1 PIN24
    IOCON_PinMuxSet(IOCON, 1, 24, port1_pin24_config);
    const uint32_t port0_pin27_config = ( //Configure as FC2_USART_RXD
           IOCON_FUNC1 |
           // No addition pin function
           IOCON_MODE_INACT |
           // Standard mode, output slew rate control is enabled
           IOCON_PIO_SLEW_STANDARD |
           // Input function is not inverted
           IOCON_PIO_INV_DI |
           // Enables digital function
           IOCON_PIO_DIGITAL_EN |
           // Open drain is disabled
           IOCON_PIO_OPENDRAIN_DI);
 // PORT0 PIN27
 IOCON_PinMuxSet(IOCON, 0, 27, port0_pin27_config);
 //Set up FLEXCOMM2 as USART2
 RESET_ClearPeripheralReset(kFC2_RST_SHIFT_RSTn);
 USART_GetDefaultConfig(&g_usart2_config);
 g_usart2_config.baudRate_Bps = 115200U;
 g_usart2_config.enableRx = true;
 g_usart2_config.enableTx = true;
 USART_Init(USART2, &g_usart2_config, CLOCK_GetFreq(kCLOCK_Flexcomm2));
    INPUTMUX_Init(INPUTMUX);
    INPUTMUX_AttachSignal(INPUTMUX, 1, kINPUTMUX_CtimerInp3ToTimer0Captsel);
    INPUTMUX_Deinit(INPUTMUX);
    CTIMER_GetDefaultConfig(&g_ctimer0_config);
    CTIMER_Init(CTIMER0, &g_ctimer0_config);
    CTIMER0->CTCR &= 0x0000000F;
    CTIMER0->CTCR |= ((0x2 << 5) | (1 << 4));
    CTIMER_RegisterCallBack(CTIMER0, &g_ctimer0_callback[0], kCTIMER_MultipleCallback);
    // Configuration 0
    ctimer0_match_config.enableCounterReset = true;
    ctimer0_match_config.enableCounterStop = false;
    ctimer0_match_config.matchValue = 0xFFFFFFFF;
    ctimer0_match_config.outControl = kCTIMER_Output_NoAction;
    ctimer0_match_config.outPinInitState = false;
    ctimer0_match_config.enableInterrupt = true;
    CTIMER_SetupMatch(CTIMER0, kCTIMER_Match_0, &ctimer0_match_config);
    CTIMER_SetupCapture(CTIMER0, kCTIMER_Capture_1, kCTIMER_Capture_RiseEdge, true);
    CTIMER_EnableInterrupts(CTIMER0, kCTIMER_Capture1InterruptEnable);
//    CTIMER_EnableInterrupts(CTIMER0, kCTIMER_Match0InterruptEnable);
    CTIMER_StartTimer(CTIMER0);
    int i = 0 ;
    /* Enter an infinite loop, just incrementing a counter. */
    while(1) {
        i++ ;
        if (g_timer0_val_valid){
         … Some Code ….
        }
        if (i % 10000 == 0){
         sprintf(g_usart2_str, … );
         USART_WriteBlocking(USART2, (unsigned char*)(g_usart2_str), strlen(g_usart2_str));
        }
    }
    return 0 ;
}
I should mention that this is a semihost project.

Outcomes