一、描述你遇到的问题
device\bearpi\bearpi_hm_nano2\app\B3_basic_pwm_led\pwm_example.c
使用这个例子编译烧录后,板子上的led只是微微闪了一下,就没有反应了,我试了延长usleep时间到2ms,也不行。前面点亮led的实验是没问题的。为什么pwm不行呢?
下面是代码,我只是加了一些打印语句。
/*
- Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
*/
#include <stdio.h>
#include <unistd.h>
#include "cmsis_os2.h"
#include "iot_gpio.h"
#include "iot_gpio_ex.h"
#include "iot_pwm.h"
#include "ohos_init.h"
#define LED_GPIO 2
#define THREAD_STACK_SIZE (1024 * 4)
#define THREAD_PRIO 25
#define PWM_PORT_PWM2 2
#define PWM_CHANGE_TIMES 100
#define PWM_FREQ 40000 // init value is 40000
#define PWM_DELAY_10US 10
#define PWM_DELAY_10000US 20000 // cc
/**
- @brief pwm task output PWM with different duty cycle
*/
static void PwmTask(void)
{
unsigned int i;
// init gpio of LED
IoTGpioInit(LED_GPIO);
printf("LED_GPIO %d is Init.\n", LED_GPIO);
// set the GPIO_2 multiplexing function to PWM
unsigned int IoTGpioSetFunc_isOk = 1;
IoTGpioSetFunc_isOk = IoTGpioSetFunc(LED_GPIO, IOT_GPIO_FUNC_GPIO_2_PWM2_OUT);
printf("LED_GPIO %d is IoTGpioSetFunc: %d , IoTGpioSetFunc_isOk = %d \n", LED_GPIO, IOT_GPIO_FUNC_GPIO_2_PWM2_OUT, IoTGpioSetFunc_isOk);
// set GPIO_2 is output mode
IoTGpioSetDir(LED_GPIO, IOT_GPIO_DIR_OUT);
printf("LED_GPIO %d is IoTGpioSetDir %d .\n", LED_GPIO, LED_GPIO, IOT_GPIO_DIR_OUT);
// init PWM2
unsigned int IotPwmInit_isOk = 6;
IotPwmInit_isOk = IoTPwmInit(PWM_PORT_PWM2);
printf("IoTPwmInit is Init, IotPwmInit_isOk = %d .\n", IotPwmInit_isOk);
// IoTPwmStop(LED_GPIO); // cc --
while (1)
{
for (i = 0; i < PWM_CHANGE_TIMES; i++)
{
// output PWM with different duty cycle
IoTPwmStart(LED_GPIO, i, PWM_FREQ);
// printf("LED_GPIO %d is IoTPwmStart, i= %d ,PWM_FREQ = %d .\n", LED_GPIO, i, PWM_FREQ);
// usleep(PWM_DELAY_10US);
usleep(PWM_DELAY_10000US); // cc
IoTPwmStop(LED_GPIO);
// printf("LED_GPIO %d is IoTPwmStop i= %d .\n", LED_GPIO, i);
}
i = 0;
}
}
/**
- @brief Main Entry of the Pwm Example
*/
static void PwmExampleEntry(void)
{
osThreadAttr_t attr;
attr.name = "PwmTask";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = THREAD_STACK_SIZE;
attr.priority = THREAD_PRIO;
printf("PwmExampleEntry is Start!-------------\n");
// usleep(PWM_DELAY_10US * 100000); // cc --wait 1s
if (osThreadNew((osThreadFunc_t)PwmTask, NULL, &attr) == NULL)
{
printf("Failed to create PwmTask!\n");
}
}
APP_FEATURE_INIT(PwmExampleEntry);
二、你具体做的所有步骤结果截图
请插入图片
三、当前开发板状态全景照片
请插入图片
四、开发板串口所有日志
请在此处粘贴串口日志
boot.
Flash Init Fail! ret = 0x80001341
verify_public_rootkey secure verify disable!
verify_params_key_area secure verify disable!
verify_params_area_info secure verify disable!
verify_image_key_area secure verify disable!
verify_image_code_info secure verify disable!
SSB Uart Init Succ!
SSB Flash Init Succ!
verify_image_key_area secure verify disable!
verify_image_code_info secure verify disable!
Flashboot Uart Init Succ!
Flashboot Malloc Init Succ!
Flash Init Succ!
No need to fix SR!
flashboot version : 1.10.101
[UPG] upgrade init OK!
No need to upgrade...
flash_encrypt disable.
verify_image_key_area secure verify disable!
verify_image_code_info secure verify disable!
APP|Debug uart init succ.
[UPG] upgrade init OK!
APP|init_dev_addr, mac_addr:0x a,0x 0,0x73,0x20,0x**,0x**,
xo_trim_temp_comp val:0 0
[osal_irq_request:68]:LOS_HwiCreate failed! irq[53] ret = 0x2000904.
APP|AT uart init succ.
los_at_plt_cmd_register EXCUTE
[osal_msg_queue_create:36]:qName:dfx_msg qID=0x0
APP|=========FS MOUNT=========
APP|=========FS READY=========
APP|WARNING: main_initialise::thread[11] func is null
hilog will init.
hievent will init.
hievent init success.
LFS [E]:lfs_file_open failed, ret = -2, name = tmp_persist_parameters
Please implement the interface according to the platform!
cpu 0 entering scheduler
[osal_msg_queue_create:36]:qName:BthChannel qID=0x4
[osal_msg_queue_create:36]:qName:BtcChannel qID=0x5
[osal_msg_queue_create:36]:qName:BthChannel qID=0x6
[osal_msg_queue_create:36]:qName:BtcChannel qID=0x7
[osal_irq_request:68]:LOS_HwiCreate failed! irq[46] ret = 0x2000904.
APP|btc open
hiview init success.
PwmExampleEntry is Start!-------------
LED_GPIO 2 is Init.
LED_GPIO 2 is IoTGpioSetFunc: 1 , IoTGpioSetFunc_isOk = 0
LED_GPIO 2 is IoTGpioSetDir 2 .
IoTPwmInit is Init, IotPwmInit_isOk = 0 .
[RADAR_LOG] alg ctrl read from nv [1][2][0][0][1][1][20]
[osal_kthread_set_priority:70]:parameter invalid!
[osal_kthread_set_priority:70]:parameter invalid!
device_main_init: 0!
===hal_initialize_phy===225===
device_module_init:: succ!
cali_set_cali_mask:old[0x0] -> new[0x1fa2]
fe_rf_initialize
cali_offline_cali_entry enter
cali_set_cali_done_flag:old[0x0] -> new[0x1]
rf cali OK. time cost:23, ret:0
xo update temp:3,diff:0,xo:0x3083c
APP|[SYS INFO] mem: used:124868, free:209136; log: drop/all[0/0], at_recv 0.
APP|[SYS INFO] mem: used:124868, free:209136; log: drop/all[0/0], at_recv 0.
APP|[SYS INFO] mem: used:124868, free:209136; log: drop/all[0/0], at_recv 0.
APP|[SYS INFO] mem: used:124868, free:209136; log: drop/all[0/0], at_recv 0.
APP|[SYS INFO] mem: used:124868, free:209136; log: drop/all[0/0], at_recv 0.
APP|[SYS INFO] mem: used:124868, free:209136; log: drop/all[0/0], at_recv 0.
APP|[SYS INFO] mem: used:124868, free:209136; log: drop/all[0/0], at_recv 0.