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.

RTOS/MSP432E401Y: Adding new PWM driver instance

Part Number: MSP432E401Y
Other Parts Discussed in Thread: MSP-EXP432E401Y

Tool/software: TI-RTOS

This is my first post so Hello everyone!

These are my first steps with TI-RTOS and MSP432E401Y (TI Launchpad).

When reviewing examples from TI resource explorer I got stuck with adding a driver when extending pwmled1 example. The pwmled1 controls onboard led with PWM0. I would like to extend i.e. add new driver instance for PWM1 to use both PWM0 and PWM1.

What I did:

  • added an enum (file: MSP_EXP432E401Y.h):
typedef enum MSP_EXP432E401Y_PWMName {
    MSP_EXP432E401Y_PWM0 = 0,
    MSP_EXP432E401Y_PWM1,           /*newly added*/

    MSP_EXP432E401Y_PWMCOUNT
} MSP_EXP432E401Y_PWMName;
  • extended arrays (file MSP_EXP432E401.c):
const PWMMSP432E4_HWAttrs pwmMSP432E4HWAttrs[MSP_EXP432E401Y_PWMCOUNT] = {
    {
        .pwmBaseAddr = PWM0_BASE,
        .pwmOutput = PWM_OUT_0,
        .pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN,
        .pinConfig = PWMMSP432E4_PF0_M0PWM0
    },

    { /*newly added*/
        .pwmBaseAddr = PWM0_BASE,
        .pwmOutput = PWM_OUT_1,
        .pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN,
        .pinConfig = PWMMSP432E4_PF1_M0PWM1
    }
};

const PWM_Config PWM_config[MSP_EXP432E401Y_PWMCOUNT] = {
    {
        .fxnTablePtr = &PWMMSP432E4_fxnTable,
        .object = &pwmMSP432E4Objects[MSP_EXP432E401Y_PWM0],
        .hwAttrs = &pwmMSP432E4HWAttrs[MSP_EXP432E401Y_PWM0]
    },

    { /*newly added*/
        .fxnTablePtr = &PWMMSP432E4_fxnTable,
        .object = &pwmMSP432E4Objects[MSP_EXP432E401Y_PWM1],
        .hwAttrs = &pwmMSP432E4HWAttrs[MSP_EXP432E401Y_PWM1]
    }
};
  • added line in board.h file:
#define Board_PWM0                  MSP_EXP432E401Y_PWM0
#define Board_PWM1                  MSP_EXP432E401Y_PWM1    /*new line*/
  • and finally intializet and populated structures with parameters in pwmled1.c:
void *mainThread(void *arg0)
{
    /* Period and duty in microseconds */
    uint16_t   pwm1Period = 3000;
    uint16_t   pwm1duty = 0;
    uint16_t   pwm1dutyInc = 100;

    uint16_t   pwm2Period = 3000;
    uint16_t   pwm2duty = 0;
    uint16_t   pwm2dutyInc = 100;


    /* Sleep time in microseconds */
    uint32_t   time = 50000;
    PWM_Handle pwm1 = NULL;
    PWM_Params pwm1params;

    PWM_Handle pwm2 = NULL;
    PWM_Params pwm2params;

    /* Call driver init functions. */
    PWM_init();

    PWM_Params_init(&pwm1params);
    pwm1params.dutyUnits = PWM_DUTY_US;
    pwm1params.dutyValue = 0;
    pwm1params.periodUnits = PWM_PERIOD_US;
    pwm1params.periodValue = pwm1Period;
    pwm1 = PWM_open(Board_PWM0, &pwm1params);
    if (pwm1 == NULL) {
        /* Board_PWM0 did not open */
        while (1);
    }

    PWM_Params_init(&pwm2params);
    pwm2params.dutyUnits = PWM_DUTY_US;
    pwm2params.dutyValue = 0;
    pwm2params.periodUnits = PWM_PERIOD_US;
    pwm2params.periodValue = pwm2Period;
    pwm2 = PWM_open(Board_PWM1, &pwm2params);
    if (pwm2 == NULL) {
        /* Board_PWM1 did not open */
        while (1);
    }

    PWM_start(pwm1);
    PWM_start(pwm2);

    /* Loop forever incrementing the PWM duty */
    while (1) {
        PWM_setDuty(pwm1, pwm1duty);

        pwm1duty = (pwm1duty + pwm1dutyInc);

        if (pwm1duty == pwm1Period || (!pwm1duty)) {
            pwm1dutyInc = - pwm1dutyInc;
        }

        PWM_setDuty(pwm2, pwm2duty);

        pwm2duty = (pwm2duty + pwm2dutyInc);

        if (pwm2duty == pwm2Period || (!pwm2duty)) {
            pwm2dutyInc = - pwm2dutyInc;
        }

        usleep(time);
    }
}

Effects: neither my new PWM1 nor PWM0 works.

Thank you in advance for telling me what I did wrong or/and lead me to proper solution.

Tomasz

  • Hello Tomasz,

    The configuration to add the new PWM pin looks good. Just to confirm, based on the configuration, you should see some activity on PWM0 (PF0) and PWM1 (PF1).

    When you say "neither my new PWM1 nor PWM0 works", can you explain?

    Are you not seeing any activity on the pins, or does the code crash, etc.

    Thanks,
    Sai
  • Hello Sai,

    Thank you for looking in my code. While on a business trip I was waiting impatiently to write back.

    So...

    I mean, that there is no activity on PWM0 and PWM1 channel at all after program upload.

    It seems (when debugging) that the programm stops at PWM_init() function.

    I've noticed, that it runs the below code of PWM_init() looping two times the for loop (once for PWM0 config and then for PWM1 as I understand the docs because of my enum wher I've added my new PWM1)

    void PWM_init(void)
    {
        uint_least8_t i;
        uint_fast32_t key;
    
        key = HwiP_disable();
    
        if (!isInitialized) {
            isInitialized = (bool) true;
    
            /* Call each driver's init function */
            for (i = 0; i < PWM_count; i++) {
                PWM_config[i].fxnTablePtr->initFxn((PWM_Handle) &(PWM_config[i]));
            }
        }

    but, when I run:

    PWM_config[i].fxnTablePtr->initFxn((PWM_Handle) &(PWM_config[i]));

    for the second time, the only thing I can do after is SUSPEND or STOP debugging, no step over, no step into options available..

    So when I SUSPEND debugging it jumps and shows me that it is now i Hwi.c file in the while line spinning:

    /*
     *  ======== Hwi_excHandler ========
     */
    Void Hwi_excHandler(UInt *excStack, UInt lr)
    {
        Hwi_module->excActive[0] = TRUE;
    
        /* spin here if no exception handler is plugged */
        while (Hwi_excHandlerFunc == NULL) {
    	;
        }
    
        Hwi_excHandlerFunc(excStack, lr);
    }

    and that's why i think it stops, and the program doesn't even touch my custom PWM parameters defined and PWM_start() functions after the PWM_init(). SO that is the reason for no activity on both pins... I suppose.

    Regards,

    Tomasz

  • Hello Tomasz,

    I tried to reproduce the behavior that you mention here, but I don't get the error that you mentioned.

    The following are the steps I followed:
    * Import the project ""pwmled1_MSP_EXP432E401Y_tirtos_ccs" into CCS
    * Add the code that you provided in the first post (to Board.h, MSP-EXP432E401Y.c/.h and pwmled1.c)
    * Build and program in debug mode.

    The following is what I notice when I run the application in debug mode.
    * LED D4 blinks (same as without the changes)
    * When a breakpoint is placed inside while(1), execution stops at the breakpoint.

    The following are the version of the SDK and CCS.
    * CCS v8.0
    * SimpleLink MSP432E4 SDK v2.20.0.20

    Can you try this on a different MSP-EXP432E401Y LaunchPad board?

    thanks,
    Sai

**Attention** This is a public forum