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.

Can't make GPIO_PF0_M1PWM4 pwm output work

Hello,

I'm trying to get M1PWM2-5 working on a LM4F232H5QD (EK-LM4F232 Keil). I can get PA6, PA7 and PF1 
working but can't get any signal from PF0. I have tried everything I could think of and still no luck. 
Can anyone please go through this and tell me if there is something wrong with this code? Thanks!

	// set pwm system clock
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

// enable peripherals
SysCtlPeripheralEnable(SYSCTL_PERIPH2_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH2_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

// enable alternate function
GPIOPinConfigure(GPIO_PA6_M1PWM2);
GPIOPinConfigure(GPIO_PA7_M1PWM3);
GPIOPinConfigure(GPIO_PF0_M1PWM4);
GPIOPinConfigure(GPIO_PF1_M1PWM5);

// configure pads
GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1);

// configure PWM generators
PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);

// set PWM generators periods
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, 1666);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, 1666);

// set pulse width
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, 1666 / 2);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, 1666 / 2);

// enable deadband
PWMDeadBandEnable(PWM1_BASE, PWM_GEN_1, 10, 10);
PWMDeadBandEnable(PWM1_BASE, PWM_GEN_2, 10, 10);

// enable PWM bits
PWMOutputState(PWM1_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT, true);

// enable the generators
PWMGenEnable(PWM1_BASE, PWM_GEN_1);
PWMGenEnable(PWM1_BASE, PWM_GEN_2);

// sync the time base (execute after enabling generators)
PWMSyncTimeBase(PWM1_BASE, PWM_GEN_1_BIT | PWM_GEN_2_BIT);
  • You have bumped against one of this new MCU's errata - PF0 is an NMI pin (defaults to such) - must receive "special  treatment" to re-purpose.

    W/in the GPIO chapter the Unlock method is described - once you've unlocked pin PF0 you can repurpose it to your PWM selection.  You then re-lock the pin and it will retain your desired PWM mode.

    We encountered this issue when attempting to use PF0 on a variant 4F MCU - in our case we employed PF0 as an Analog Comparator output.

    Prefer you to review the MCU datasheet - if you have further issues will assist as/if/when able...

  • Thank you. For anyone else having the same problem, this has solved the problem:

    // enable peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH2_GPIOF);
    
    // unlock GPIO PF0
    GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY;
    GPIO_PORTF_CR_R = GPIO_PIN_0;

    // enable alternate function
    GPIOPinConfigure(GPIO_PF0_M1PWM4);
  • Paul GML said:
    GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY;

    Glad to have assisted - the many new benefits afforded by these new MCUs sometimes add complexity.

    However - our unlocking code is different:  (shown is extract from hw_gpio.h, Rev 8555 - which I believe to be most current release)  In our case we employed GPIO_LOCK_KEY_DD

    // The following are defines for the bit fields in the GPIO_O_LOCK register.
    //
    //*****************************************************************************
    #define GPIO_LOCK_M             0xFFFFFFFF  // GPIO Lock
    #define GPIO_LOCK_UNLOCKED      0x00000000  // The GPIOCR register is unlocked
                                                // and may be modified
    #define GPIO_LOCK_LOCKED        0x00000001  // The GPIOCR register is locked
                                                // and may not be modified
    #define GPIO_LOCK_KEY           0x1ACCE551  // Unlocks the GPIO_CR register
    #define GPIO_LOCK_KEY_DD        0x4C4F434B  // Unlocks the GPIO_CR register on
                                                // DustDevil-class devices and
                                                // later

    Beyond this - we attended to GPIO_O_AFSEL & GPIO_O_DEN - while the device was "unlocked" - to achieve our desired re-purpose functionality.

    May prove of value to learn the actual value of your, "GPIO_LOCK_KEY."  (w/in IAR we just highlight the expression and then "go to definition" reveals...)

  • Hello guys,

    Thank you for the post.

    We could not figured out why MIPWM4 on PORTF PIN 0 was not working

    and finally come across your post.   Our problem was related to the new TIVA C parts,

    TM4C123 parts but same concept applied and it worked.

    Here is how we got the PORTF PIN 0 or F0 unlock and configure for PWM function.

        //
        //    GPIO_PF0 is a NMI pin that must be unlock
        //
        // unlock GPIO PF0
        HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
        HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = GPIO_PIN_0;

        // enable alternate function
        ROM_GPIOPinConfigure(GPIO_PF0_M1PWM4);        //PWM4

    I hope this is helpful to some one as it was for us.

  • @ Moises,

    Very nice that you expanded upon this earlier issue - should help many - thank you.

    Should state that earlier use of: "GPIO_LOCK_KEY_DD" - which worked for us - has been "deprecated" and your use of, "GPIO_LOCK_KEY" is now appropriate and proper.

    Great that you "searched" the forum - and that you cared enough to share your findings to the benefit of many others...  Someday/some planet - MCU manuals will "adopt" long urged suggestion to, "better highlight" the identification of NMI pins - and corrective actions required to, "their repurpose."