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.

CCS/CC1312R: LED control problem: How to switch GPIO output mode and PWM mode?

Part Number: CC1312R

Tool/software: Code Composer Studio

Hi,

I just try PWM driver for control LED and it works well.

Then I found that it spend a lot of power when I change state to WoR mode even I set PWM duty to 100% and 0%.

(LED0 configured as high active, LED1 configured as low active).

I try to set LED pin to gpio output when go to WoR mode and set LED pin to PWM when wake up form WoR but not working.

My driver usage:

static PWM_Handle pwm1 = NULL;

pwm1 = PWM_open(Board_PWM0, &params);

PWM_start(pwm1);

PWM_stop(pwm1);

PWM_close(pwm1);

GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH); // set to gpio mode

pwm1 = PWM_open(Board_PWM0, &params); // here return NULL

PWM_start(pwm1);// If skip PWM_open, just try PWM_start() still doesn't work.

Thank you.

  • Hi Chris,

    The PWM driver requires the LED pin to be free in order to allocate it during the open call. When adding the configuration to the GPIO driver, you are also allocating the pin. This means you would have to perform a GPIOCC26XX_release() in order to free the pin again (you have to add the GPIOCC26XX.h header to access it).

    If possible, I would recommend you use the PIN driver instead as this gives you more control of the pin you use compared to the GPIO driver (which wraps the PIN driver).
  • Hi M-W,

    It seems if only configures one led could work well by GPIOCC26xx_release(CC1312R1_LAUNCHXL_PWMPIN0);

    If I use the second LED the API PWM_open(Board_PWM1, &params); still return 0(below code line 52).

    static PWM_Handle pwm1 = NULL;
    static PWM_Handle pwm2 = NULL;
    
        PWM_Params_init(&params);
        params.dutyUnits = PWM_DUTY_US;
        params.dutyValue = pwmPeriod;
        params.periodUnits = PWM_PERIOD_US;
        params.periodValue = pwmPeriod;
        pwm1 = PWM_open(Board_PWM0, &params);
        if (pwm1 == NULL) {
            /* Board_PWM0 did not open */
            while (1);
        }
        PWM_start(pwm1);
    
        params.dutyValue = 0;
    
        pwm2 = PWM_open(Board_PWM1, &params);
        if (pwm2 == NULL) {
            /* Board_PWM0 did not open */
            while (1);
        }
        PWM_start(pwm2);
    
        sleep(1);
        PWM_stop(pwm1);
        PWM_stop(pwm2);
        PWM_close(pwm1);
        PWM_close(pwm2);
    
        sleep(1);
        GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
        GPIO_setConfig(Board_GPIO_LED1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        GPIOCC26xx_release(CC1312R1_LAUNCHXL_PWMPIN0);
        GPIOCC26xx_release(CC1312R1_LAUNCHXL_PWMPIN1);
    
        PWM_Params_init(&params);
        params.dutyUnits = PWM_DUTY_US;
        params.dutyValue = pwmPeriod;
        params.periodUnits = PWM_PERIOD_US;
        params.periodValue = pwmPeriod;
        pwm1 = PWM_open(Board_PWM0, &params);
        if (pwm1 == NULL) {
            /* Board_PWM0 did not open */
            while (1);
        }
        PWM_start(pwm1);
    
        params.dutyValue = 0;
    
        pwm2 = PWM_open(Board_PWM1, &params); // return 0
        if (pwm2 == NULL) {
            /* Board_PWM0 did not open */
            while (1);
        }
        PWM_start(pwm2);
    
    

  • Hi Chris,

    If you are set to use the GPIO driver, you should also use the GPIO enumerator to access the IOs.
    For example, you use "Board_GPIO_LED0" to configure the IO which corresponds to "CC1352R1_LAUNCHXL_GPIO_LED_GREEN" which has the the value "4". You then try to release the IO again using the "CC1312R1_LAUNCHXL_PWMPIN0" define which is defined as "IOID_6" (or value 6), which is not the index of the GPIO configuration you want to release.

    In short, when using the GPIO driver, you are passing the index of the IO defined in the GPIO configuration table (gpioPinConfigs). In your example, this means that changing "CC1312R1_LAUNCHXL_PWMPIN0/1" to "Board_GPIO_LED0/1" should fix your issue.
  • Hi M-W,

    Thanks for your help.
    I got another problem about PWM close function.

    After call (LINE 28)

    PWM_stop(pwm1);
    PWM_close(pwm1);

    The LED0 is lighting.

    On my board the LED0 is configured as low active, does this means after PWM_stop(), PWM_close(),
    pin is configured to gpio output low?
    If yes, can I change the state after PWM_close()?
    Because even I call

    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);

    immediately the LED0 is still lighting for a very short time.

    Thanks

  • Hi Chris,

    You can setup the "default" value of any PIN should have when not in use by adding them to the PIN_Config table (BoardGpioInitTable) in the board file. If you look at this table, you should find that the LED pins are set to default low in our LaunchPad board files.

    Keep in mind that this table belongs to the PIN Driver, which means you address IOs by their actual DIO number and not the enumerator like in the GPIO Driver scenario.
  • Hi M-W:

    I found another problem.
    After PWM close, set GPIO output, then release GPIO, set PWM mode,
    the AESCBC_oneStepDecrypt() can't decrypt data correctly....
  • Hi Chris,

    Could you elaborate, your code above does not show anything on how you use the AESCBC driver.
    I would suggest you create a new thread for this question using the "Ask a related question" so that we can separate the two issues.