Other Parts Discussed in Thread: LM4120, TM4C123GH6PM
I'm trying to get PWM working on an EK-TM4C123GXL Launchapd using port PF0. I'm aware that this is a locked pin for NMI purposes and have put the required code in to unlock the pin. However, I get stuck waiting for SysCtlPeripheralReady(SYSCTL_PERIPH_PWM1) to go true. I get stuck in the highlighted loop. I've tried everything, even copy and pasting it to another project and recompiling. I just don't know where the code is wrong. I've based this code on a TM4C1294 code using PF1 which works perfectly. I've changed processors and ports, but it should work!
For reference, the TM4C123G's PF0 PWM details are as follows:
Here's the complete code:
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "inc/hw_types.h"
#include "driverlib/pwm.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "utils/ustdlib.h"
#include "driverlib/pin_map.h"
#include "driverlib/systick.h"
int main(void)
{
// Set the system clock to run at 80Mhz off PLL with external crystal as reference.
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
// Enable all the GPIO peripherals.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
while (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF))
{
}
// Unlock PF0, which is a locked pin (NMI)
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= GPIO_PIN_0;
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; // re-lock it to prevent further changes
// Configure PWM clock
SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // configure the PWM clock
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); // enable PWM Module 1
while (!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM1))
{
}
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
GPIOPinConfigure(GPIO_PF0_M1PWM4);
PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, SysCtlClockGet() / 10); // set default period to give 10 Hz
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, SysCtlClockGet() / 20); // set default pulse width to give 50% duty cycle
PWMOutputState(PWM1_BASE, PWM_OUT_4_BIT, false); // enabled when required
PWMGenEnable(PWM1_BASE, PWM_GEN_2); // Start the timers in Generator 2
while(1)
{
}
}