1# Copyright (c) 2023, Zephyr Project 2# SPDX-License-Identifier: Apache-2.0 3 4description: | 5 TI SimpleLink CC13xx/CC26xx GPT timer PWM Controller Node 6 7 To configure a PWM node, you first need to define a board overlay with a 8 pinctrl configuration for the pin on which the PWM signal should be present: 9 10 &pinctrl { 11 gpt0_pwm: gpt0_pwm { 12 pinmux = <25 IOC_PORT_MCU_PORT_EVENT1>; 13 bias-disable; 14 drive-strength = <8>; /* in mA, can be 2, 4 or 8 */ 15 }; 16 }; 17 18 Please be aware that the port event depends on the GPT instance chosen. The 19 following port events must be used for PWM: 20 - GPT0: IOC_PORT_MCU_PORT_EVENT1 21 - GPT1: IOC_PORT_MCU_PORT_EVENT3 22 - GPT2: IOC_PORT_MCU_PORT_EVENT5 23 - GPT3: IOC_PORT_MCU_PORT_EVENT7 24 25 Be careful not to choose a pin that is already in use on your board, this 26 might irreversible damage to your board as the given pin will be configured as 27 output and actively driven by the PWM driver. 28 29 Then enable the corresponding timer and PWM nodes and add a reference to the 30 pinctrl entry: 31 32 &gpt0 { 33 status = "okay"; 34 }; 35 36 &pwm0 { 37 status = "okay"; 38 pinctrl-0 = <&gpt0_pwm>; 39 pinctrl-names = "default"; 40 }; 41 42 Now you can programmatically enable the PWM signal in your code: 43 44 static const struct device *pwm = DEVICE_DT_GET(DT_NODELABEL(pwm0)); 45 46 int init_pwm(void) 47 { 48 uint32_t pwm_period_ns, pwm_pulse_ns; 49 uint32_t pwm_duty_percent = 50U; 50 uint32_t pwm_frequency = 1000U; /* 1kHz */ 51 52 if (!device_is_ready(pwm)) { 53 LOG_ERR("Error: PWM device %s is not ready\n", pwm->name); 54 return -ENODEV; 55 } 56 57 pwm_period_ns = NSEC_PER_SEC / pwm_frequency; 58 pwm_pulse_ns = (pwm_duty_percent * pwm_period_ns) / 100; 59 60 return pwm_set(pwm, 0, pwm_period_ns, pwm_pulse_ns, 0); 61 } 62 63compatible: "ti,cc13xx-cc26xx-timer-pwm" 64 65include: [base.yaml, pwm-controller.yaml, pinctrl-device.yaml] 66 67properties: 68 pinctrl-0: 69 required: true 70 71pwm-cells: 72- period 73