This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129ENCPDT: Throwing exceptions on PWMClockSet or SysCtlPWMClockSet

Part Number: TM4C129ENCPDT
Other Parts Discussed in Thread: EK-TM4C129EXL,

Hello all,

I'm using the EK-TM4C129EXL (rev A) launch pad board.

I'm using IAR and I started this project with an example project from IAR called "project".  This is main() starter that setups and blinks a GPIO pin.  That all worked ok.  Then I started setting up a PWM generator block.  It started out working ok, but later, as I tweaked up the settings and I used PWMClockSet (indented for non-TM4C123x) , and it started throwing exceptions.  If I remark out that line, the code sometimes works, however it still seems to throw exception sometimes and other times not.  Out of desperation I tried SysCtlPWMClockSet (intended for TM4C123x), and that worked without throwing an exception - the first time.  Later that line did seem to throw an exception.  

I had a similar problem with CSS some months ago, but I don't really remember the particulars.  

Bellow is my code.  Could this problem be related to driverlib?  Maybe an out of date rev?

Many thanks!!  George 

#define PART_TM4C129ENCPDT

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Simple Project (project)</h1>
//!
//! A very simple example that can be used as a starting point for more complex
//! projects. Most notably, this project is fully TI BSD licensed, so any and
//! all of the code (including the startup code) can be used as allowed by that
//! license.
//!
//! The provided code simply toggles a GPIO using the Tiva Peripheral Driver
//! Library.
//
//*****************************************************************************

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif


int main(void)
{

    //
    // Set system clock frequency to 120MHz
    //
    SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000);

    //
    // Enable the GPIO module.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_GPION));
    //
    // Configure PN1 as an output.
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);


    PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
    // SysCtlPWMClockSet(SYSCTL_PWMDIV_2);
    //
    // Enable the PWM module.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0));
    //
    // Enable the GPIO module port F for the PWM.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF));

    //
    // Configure PF2 and PF3 as outputs for the PWM.
    //
    // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    
    ROM_GPIOPinConfigure(GPIO_PF2_M0PWM2);
    ROM_GPIOPinConfigure(GPIO_PF3_M0PWM3);
    ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    //
    // Configure the PWM generator for count down mode with immediate updates to the parameters.
    //
    ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
    //
    // Set the period.
    //
    ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 200);
    //
    // Set the pulse width of PWM2.
    //
    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 0);
    //
    // Set the pulse width of PWM3.
    //
    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 100);
    //
    // Enable the outputs.
    //
    ROM_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true);
    //
    // Start the timers in generator 1.
    //
    ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);

    int period = 0;

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Set the GPIO high.
        //
        ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1);

        //
        // Delay for a while.
        //
        ROM_SysCtlDelay(1000000);

        //
        // Set the GPIO low.
        //
        ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0);

        //
        // Delay for a while.
        //
        ROM_SysCtlDelay(1000000);

        //
        // Set the pulse width of PWM2.
        //
        ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, period);
        if (period == 200)
            period = 0;
        else
            ++period;

    }
}

  • I edited your post and inserted your code using the </> option so that syntax highlighting,  and spacing is preserved. It also adds line numbers.

    In line 58 you called PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1); but you have not yet enabled the clocks to the PWM module with a call to SysCtlPeripheralEnable(). If you will C step your code from the beginning of main, you will quickly find the line of code that causes the abort. Look at which peripheral it is accessing and verify that you have enabled that peripheral. 

    Here is an application note that provides more help on diagnosing system faults:

    http://www.ti.com/lit/an/spma043/spma043.pdf

  • Greetings,

    Code edits appear insightful & correcting.    Our group's staff believes that poster would benefit by adopting "KISS" - which then enables a "far sooner detection" of "Problem Code."    (i.e. smaller & more quickly test/verified code blocks prove far easier & efficient to 'debug!')

    May it be also noted that:

    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 0);    // vendor's (updated) line 90

    often yields "inconsistent results" - as many similar ARM MCUs (multi-vendors) demand "special treatment" at/around PWM Duty Cycle Extremes!    (i.e. at around 0 or 100% duty)

    and lines 134-136 (vendor updated) continue poster's practice of commanding "extreme duty cycle"

    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, period);   // in which period may be reset to 0 upon reaching 200 

    Poster was unlikely to have such (duty cycle issue awareness) - this issue has arisen many times here - and "Forum Search Box" reveals several corrective paths...

  • Hello and thank you Bob for your help,

    I did as you suggested.  I read the link and it was insightful, but I still have some learning curve to get my head around it. 

    In the meantime, I put SysCtlPeripherlEnable() above PWMClockSet(), and all ran fine.  Then I tweaked some numbers for pulse width and such.  It all worked for a several makes, but then it crashed again.  This was the same scenario as before.  It faults after I click the "Download and Debug" button.  Then, in the debugger, the GO button is dimed.  When I click the Break button I get "HardFault exception", "The processor has escalated a configurable-priority exception to HardFault,    The processor has attempted to execute an undefined instruction (CFSR.UNDEFINSTR). Exception occured at PC = 0x86a, LR = 0xffffffff,  See the call stack for more information."

    And the call stack says...

     " FaultISR ,   <Exception frame> ,   [IntDefaultHandler + 0x1] "

    I tried rewriting my code to before this happened, but I still get the fault. 

    George

    PS Is there any truth to what the other poster said about 0 or period = pulse width?

  • Bob,

    BTW,  I just tried remarking out all the PWM related code, but I still get the same fault scenario verbatim as I mentioned in my last post.

    Then I powered down the Launchpad board and powered up again and it started working.

    However, I closed IAR and restarted it again, and again got the same fault.

    George

  • Re:

    george dorian said:
    Is there any truth to what the other poster said about 0 or period = pulse width?

    Might it more properly be asked, "Has the questioning poster made sufficient effort (i.e. any effort - via the forum's Search Box) to confirm such truth?

    e2e.ti.com/.../2317756
    e2e.ti.com/.../2927385

    Fear not - my tech group will avoid further attempts to "Advise & Inform!"    (some diplomacy was expected...)

  • I am at a disadvantage to give you clear instructions as I do not use the IAR debugger. (I work for TI, so of course I use the TI tools.)  Can you look at a disassembly window and identify what code is executing at address 0x86A? Can you reset the device, and starting from reset step through the code to see where the fault occurs?