Tool/software: Code Composer Studio
I am trying to use PWM on my TI board. I found this problem when I used single step into in the debug mode. My codes are shown below:
#include "inc/tm4c123gh6pm.h" #include <stdbool.h> #include <stdint.h> #include "inc/hw_memmap.h" #include "driverlib/pwm.h" #include "driverlib/gpio.h" #include "inc/hw_GPIO.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" void PWMInitTom(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // Enable the PWM0 peripheral //while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0)) {/* Wait for the PWM0 module to be ready.*/} SysCtlPWMClockSet(SYSCTL_PWMDIV_1); //Set the PWM clock to the system clock SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Enable GPIOB GPIOPinConfigure(GPIO_PB6_M0PWM0); // configure the GPIO pin to select PWM0 functions GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6); // Configure the PWM function for this pin. //Configure the PWM generator for count down mode with immediate updates to the parameters. PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); // Set the period. For a 50 KHz frequency, the period = 1/50,000, or 20 // microseconds. For a 20 MHz clock, this translates to 400 clock ticks. // Use this value to set the period. PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 400); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 100); //Set the pulse width of PWM0 for a 25% duty cycle. PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 300); //Set the pulse width of PWM1 for a 75% duty cycle. PWMGenEnable(PWM0_BASE, PWM_GEN_0); // Start the timers in generator 0 PWMOutputState(PWM0_BASE, (PWM_OUT_6_BIT | PWM_OUT_7_BIT), true); // Enable the output for PWM6 and PWM7 on Module 0 } unsigned long freq, width, period, pwmfreq; int main(void) { SysCtlClockSet( SYSCTL_USE_PLL |SYSCTL_SYSDIV_10| SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN); //set clock to 20MHz freq = SysCtlClockGet(); PWMInitTom(); pwmfreq = SysCtlPWMClockGet(); width = PWMPulseWidthGet(PWM0_BASE, PWM_OUT_0); period = PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0); while (1) { } }
So when CCS tried to compile PWMGenConfigure, it would jump into FaultISR and stuck at there forever.
And when I used the example file (invert.c), I had this same problem. And PWMGenConfigure caused the problem.
I have included pwm.c , sysctl.c , gpio.c to my project.
Can anyone explain?
Thanks