我在调试BL702 IOT开发板的PWM时候,依照MCU sdk例子进行PWM配置
1、#define BSP_USING_PWM_CH2 ;
2、pinmux_config.h文件中 CONFIG_GPIO17_FUNC GPIO_FUN_PWM;
使用GPIO17用着PWM输出,观察波形,没有波形?
代码如下:
int main(void)
{
pwm_dutycycle_config_t pwm_cfg = {
.threshold_low = 0,
.threshold_high = 0
};
bflb_platform_init(0);
gpio_set_mode(GPIO_PIN_17, GPIO_OUTPUT_PP_MODE);
gpio_write(GPIO_PIN_17, 0);
pwm_register(PWM_CH2_INDEX, "pwm");
struct device *pwm = device_find("pwm");
if (pwm) {
PWM_DEV(pwm)->period = 32; //frequence = 32M/1/8 = 4M
PWM_DEV(pwm)->threshold_low = 16;
PWM_DEV(pwm)->threshold_high = 32;
device_open(pwm, DEVICE_OFLAG_STREAM_TX);
pwm_channel_start(pwm);
}
while (1) {
for (pwm_cfg.threshold_high = 0; pwm_cfg.threshold_high <= 32; pwm_cfg.threshold_high++) {
device_control(pwm, DEVICE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg);
bflb_platform_delay_ms(50);
}
for (pwm_cfg.threshold_high = 32; 0 <= pwm_cfg.threshold_high && pwm_cfg.threshold_high <= 32; pwm_cfg.threshold_high--) {
device_control(pwm, DEVICE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg);
bflb_platform_delay_ms(50);
}
}
}
其中log输出:
[16:27:39.006] -------------------
[16:27:39.006]
[16:27:39.226] ____ __ __ _ _ _
[16:27:39.226] | _ \ / _|/ | | | | | | |
[16:27:39.226] | |) | ___ _ | || |_ __ _| | ___ | | __ _| |__
[16:27:39.226] | _ < / _ | | | | _| _/ | |/ _ \| |/ _
| ' \
[16:27:39.226] | |) | () | || | | | || (| | | () | | (| | |) |
[16:27:39.226] |/ _/ _,|| || _,||_/||_,|./
[16:27:39.226]
[16:27:39.226] Build:16:24:03,Oct 22 2022
[16:27:39.226] Copyright (c) 2021 Bouffalolab team
[16:27:39.226] root clock:144M
[16:27:39.226] fclk clock:144M
[16:27:39.226] bclk clock:72M
[16:27:39.226] uart clock:96M
[16:27:39.226] spi clock:72M
[16:27:39.226] i2c clock:72M
[16:27:39.226] adc clock:32M
[16:27:39.226] dac clock:8M
[16:27:39.226] i2s clock:24M
[16:27:39.226] pwm clock:32000000hz
[16:27:39.226] cam clock:0M
[16:27:39.226] timer0 clock:144M
[16:27:39.226] timer1 clock:144M
[16:27:39.226] dynamic memory init success,heap size = 102 Kbyte
[16:27:39.226] show flash cfg:
[16:27:39.226] jedec id 0xC22014
[16:27:39.226] mid 0xC2
[16:27:39.226] iomode 0x11
[16:27:39.226] clk delay 0x01
[16:27:39.226] clk invert 0x01
[16:27:39.226] read reg cmd0 0x05
[16:27:39.226] read reg cmd1 0x00
[16:27:39.226] write reg cmd0 0x01
[16:27:39.226] write reg cmd1 0x00
[16:27:39.226] qe write len 0x01
[16:27:39.226] cread support 0x00
[16:27:39.226] cread code 0x20
[16:27:39.226] burst wrap cmd 0x77
[16:27:39.226] -------------------
求助!!!