diff --git a/examples/pwm_dc_motor/CMakeLists.txt b/examples/pwm_dc_motor/CMakeLists.txt new file mode 100644 index 00000000..bfd0e557 --- /dev/null +++ b/examples/pwm_dc_motor/CMakeLists.txt @@ -0,0 +1,5 @@ +set(mains main.c) +generate_bin() + + + diff --git a/examples/pwm_dc_motor/cdk/pwm_dc_motor.cdkproj b/examples/pwm_dc_motor/cdk/pwm_dc_motor.cdkproj new file mode 100644 index 00000000..4c64de9d --- /dev/null +++ b/examples/pwm_dc_motor/cdk/pwm_dc_motor.cdkproj @@ -0,0 +1,920 @@ + + + CPU: RV32IMAFC +Chip: bl70x +Board: bl70x_iot + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 155 + 104 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + no + 0x23000000 + 0x100000 + + + no + 0x22014000 + 0x4000 + + + no + 0x42018000 + 0x8000 + + + no + + + + + no + + + + + + + yes + 0x42020000 + 0xc000 + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + rv32imafc + no + little + no + no + no + no + + + $(ProjectName) + Executable + no + yes + no + yes + no + yes + + + + no + + + + no + + + + no + $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + ARCH_RISCV; + + Optimize more (-O2) + Default (-g) + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/libc/inc;$(ProjectPath)../../../../common/libc/inc/arm_gcc;$(ProjectPath)../../../../common/libc/inc/bits;$(ProjectPath)../../../../common/libc/inc/sys;$(ProjectPath)../../../../common/libc/src;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc + -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -fno-jump-tables -Wignored-qualifiers -Wswitch-default -Wunused -Wundef -msmall-data-limit=4 + no + no + no + no + no + no + yes + no + yes + no + + + + + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl602_driver/startup;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl602_driver/regs;$(ProjectPath)../../../../drivers/bl602_driver/std_drv/inc + + gdwarf2 + + + yes + yes + $(ProjectPath)../../../../drivers/bl702_driver/bl702_flash.ld + + + + no + + + + yes + OpenOCD + yes + main + + $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init + yes + Hard Reset + 23000000 + no + no + $(ProjectPath)/$(ProjectName).cdkcore + + localhost + 1025 + 0 + 2000 + 10 + 50 + yes + no + no + Normal + Hard Reset + 21000000 + Bare Metal + yes + yes + + Local + -arch riscv + + + + + yes + no + no + + + openocd-hifive + no + 4444 + no + 6666 + -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg + + + + + Erase Sectors + bl70x_flasher.elf + yes + yes + no + Hard Reset + + no + + + + + + + + + no + 0x23000000 + 0x100000 + + + no + 0x22014000 + 0x4000 + + + no + 0x42018000 + 0x8000 + + + no + + + + + no + + + + + + + yes + 0x42020000 + 0xc000 + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + rv32imafc + no + little + no + no + no + no + + + $(ProjectName) + Executable + no + yes + no + yes + no + yes + + + + no + + + + no + + + + no + $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + ARCH_RISCV; + + Optimize more (-O2) + Default (-g) + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/libc/inc;$(ProjectPath)../../../../common/libc/inc/arm_gcc;$(ProjectPath)../../../../common/libc/inc/bits;$(ProjectPath)../../../../common/libc/inc/sys;$(ProjectPath)../../../../common/libc/src;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl602_driver/regs;$(ProjectPath)../../../../drivers/bl602_driver/std_drv/inc + -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -fno-jump-tables -Wignored-qualifiers -Wswitch-default -Wunused -Wundef -msmall-data-limit=4 + no + no + no + no + no + no + yes + no + yes + no + + + + + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl602_driver/startup;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl602_driver/regs;$(ProjectPath)../../../../drivers/bl602_driver/std_drv/inc + + gdwarf2 + + + yes + yes + $(ProjectPath)../../../../drivers/bl702_driver/bl702_flash.ld + + + + no + + + + yes + ICE + yes + main + + $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init + yes + Hard Reset + 23000000 + no + no + $(ProjectPath)/$(ProjectName).cdkcore + + localhost + 1025 + 0 + 2000 + 10 + 50 + yes + no + no + Normal + Hard Reset + 21000000 + Bare Metal + yes + yes + + Local + -arch riscv + + + + + yes + no + no + + + openocd-hifive + no + 4444 + no + 6666 + -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg + + + + + Erase Sectors + bl70x_flasher.elf + yes + yes + no + Hard Reset + + no + + + + + + + + ;;; + ;;MHZ; + + glb + uart + + 1 + 1 + + 100:8;100:8;100:8;100:8; + + + + ;;; + ;;MHZ; + + glb + uart + + 1 + 1 + + 100:8;100:8;100:8;100:8; + + diff --git a/examples/pwm_dc_motor/main.c b/examples/pwm_dc_motor/main.c new file mode 100644 index 00000000..df60f194 --- /dev/null +++ b/examples/pwm_dc_motor/main.c @@ -0,0 +1,87 @@ +/** + * @file pwm_dc_motor.c + * @brief + * + * Copyright (c) 2021 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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 "hal_pwm.h" +#include "hal_gpio.h" +#include "hal_clock.h" + +int main(void) +{ + pwm_dutycycle_config_t pwm_cfg[2]; + + pwm_cfg[0].threshold_low = 0; + pwm_cfg[0].threshold_high = 0; + + pwm_cfg[1].threshold_low = 0; + pwm_cfg[1].threshold_high = 0; + + bflb_platform_init(0); + + pwm_register(PWM_CH0_INDEX, "dc_motor_ch0", DEVICE_OFLAG_RDWR); + pwm_register(PWM_CH1_INDEX, "dc_motor_ch1", DEVICE_OFLAG_RDWR); + + struct device *dc_motor_ch0 = device_find("dc_motor_ch0"); + struct device *dc_motor_ch1 = device_find("dc_motor_ch1"); + + if (dc_motor_ch0) { + PWM_DEV(dc_motor_ch0)->period = 32; //frequence = 32M/1/32 = 1Mhz + PWM_DEV(dc_motor_ch0)->threshold_low = 16; + PWM_DEV(dc_motor_ch0)->threshold_high = 32; + device_open(dc_motor_ch0, DEVICE_OFLAG_STREAM_TX); + pwm_channel_start(dc_motor_ch0); + } + if (dc_motor_ch1) { + PWM_DEV(dc_motor_ch1)->period = 32; //frequence = 32M/1/32 = 1Mhz + PWM_DEV(dc_motor_ch1)->threshold_low = 16; + PWM_DEV(dc_motor_ch1)->threshold_high = 32; + device_open(dc_motor_ch1, DEVICE_OFLAG_STREAM_TX); + pwm_channel_start(dc_motor_ch1); + } + + while (1) { + pwm_cfg[1].threshold_low = 0; + pwm_cfg[1].threshold_high = 0; + device_control(dc_motor_ch1, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[1]); + for (pwm_cfg[0].threshold_high = 16; pwm_cfg[0].threshold_high <= 32; pwm_cfg[0].threshold_high++) { + device_control(dc_motor_ch0, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[0]); + bflb_platform_delay_ms(1000); + } + + for (pwm_cfg[0].threshold_high = 32; 16 <= pwm_cfg[0].threshold_high && pwm_cfg[0].threshold_high <= 32; pwm_cfg[0].threshold_high--) { + device_control(dc_motor_ch0, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[0]); + bflb_platform_delay_ms(1000); + } + + pwm_cfg[0].threshold_low = 0; + pwm_cfg[0].threshold_high = 0; + device_control(dc_motor_ch0, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[0]); + for (pwm_cfg[1].threshold_high = 16; pwm_cfg[1].threshold_high <= 32; pwm_cfg[1].threshold_high++) { + device_control(dc_motor_ch1, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[1]); + bflb_platform_delay_ms(1000); + } + + for (pwm_cfg[1].threshold_high = 32; 16 <= pwm_cfg[1].threshold_high && pwm_cfg[1].threshold_high <= 32; pwm_cfg[1].threshold_high--) { + device_control(dc_motor_ch1, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[1]); + bflb_platform_delay_ms(1000); + } + } +} diff --git a/examples/pwm_dc_motor/readme.md b/examples/pwm_dc_motor/readme.md new file mode 100644 index 00000000..a2db712e --- /dev/null +++ b/examples/pwm_dc_motor/readme.md @@ -0,0 +1,14 @@ +**board/bl706_iot/pinmux_config.h** 中 **CONFIG_GPIO20_FUNC**、**CONFIG_GPIO21_FUNC** 选择 **GPIO_FUN_PWM** + +**board/bl706_iot/clock_config.h** 中 + +- **BSP_PWM_CLOCK_SOURCE** 选择 **ROOT_CLOCK_SOURCE_RC_32K**,也可选择其他时钟源,用其他时钟源时应注意 case 中的设置要匹配 +- **BSP_PWM_CLOCK_DIV** 设置成 **1** + +将两个通道分别接到 H 桥或半桥的两个通道 + +```bash + +$ make APP=pwm_dc_motor BOARD=bl706_iot + +``` \ No newline at end of file diff --git a/examples/pwm_step_motor/CMakeLists.txt b/examples/pwm_step_motor/CMakeLists.txt new file mode 100644 index 00000000..bfd0e557 --- /dev/null +++ b/examples/pwm_step_motor/CMakeLists.txt @@ -0,0 +1,5 @@ +set(mains main.c) +generate_bin() + + + diff --git a/examples/pwm_step_motor/cdk/pwm_step_motor.cdkproj b/examples/pwm_step_motor/cdk/pwm_step_motor.cdkproj new file mode 100644 index 00000000..86d3f338 --- /dev/null +++ b/examples/pwm_step_motor/cdk/pwm_step_motor.cdkproj @@ -0,0 +1,920 @@ + + + CPU: RV32IMAFC +Chip: bl70x +Board: bl70x_iot + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 155 + 104 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + no + 0x23000000 + 0x100000 + + + no + 0x22014000 + 0x4000 + + + no + 0x42018000 + 0x8000 + + + no + + + + + no + + + + + + + yes + 0x42020000 + 0xc000 + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + rv32imafc + no + little + no + no + no + no + + + $(ProjectName) + Executable + no + yes + no + yes + no + yes + + + + no + + + + no + + + + no + $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + ARCH_RISCV; + + Optimize more (-O2) + Default (-g) + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/libc/inc;$(ProjectPath)../../../../common/libc/inc/arm_gcc;$(ProjectPath)../../../../common/libc/inc/bits;$(ProjectPath)../../../../common/libc/inc/sys;$(ProjectPath)../../../../common/libc/src;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc + -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -fno-jump-tables -Wignored-qualifiers -Wswitch-default -Wunused -Wundef -msmall-data-limit=4 + no + no + no + no + no + no + yes + no + yes + no + + + + + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl602_driver/startup;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl602_driver/regs;$(ProjectPath)../../../../drivers/bl602_driver/std_drv/inc + + gdwarf2 + + + yes + yes + $(ProjectPath)../../../../drivers/bl702_driver/bl702_flash.ld + + + + no + + + + yes + OpenOCD + yes + main + + $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init + yes + Hard Reset + 23000000 + no + no + $(ProjectPath)/$(ProjectName).cdkcore + + localhost + 1025 + 0 + 2000 + 10 + 50 + yes + no + no + Normal + Hard Reset + 21000000 + Bare Metal + yes + yes + + Local + -arch riscv + + + + + yes + no + no + + + openocd-hifive + no + 4444 + no + 6666 + -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg + + + + + Erase Sectors + bl70x_flasher.elf + yes + yes + no + Hard Reset + + no + + + + + + + + + no + 0x23000000 + 0x100000 + + + no + 0x22014000 + 0x4000 + + + no + 0x42018000 + 0x8000 + + + no + + + + + no + + + + + + + yes + 0x42020000 + 0xc000 + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + no + + + yes + + + rv32imafc + no + little + no + no + no + no + + + $(ProjectName) + Executable + no + yes + no + yes + no + yes + + + + no + + + + no + + + + no + $(ProjectPath)../../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" + + + + ARCH_RISCV; + + Optimize more (-O2) + Default (-g) + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/libc/inc;$(ProjectPath)../../../../common/libc/inc/arm_gcc;$(ProjectPath)../../../../common/libc/inc/bits;$(ProjectPath)../../../../common/libc/inc/sys;$(ProjectPath)../../../../common/libc/src;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl602_driver/regs;$(ProjectPath)../../../../drivers/bl602_driver/std_drv/inc + -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -fno-jump-tables -Wignored-qualifiers -Wswitch-default -Wunused -Wundef -msmall-data-limit=4 + no + no + no + no + no + no + yes + no + yes + no + + + + + $(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../../components/fatfs;$(ProjectPath)../../../../components/freertos/Source/include;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../components/usb_stack/class/audio;$(ProjectPath)../../../../components/usb_stack/class/cdc;$(ProjectPath)../../../../components/usb_stack/class/hid;$(ProjectPath)../../../../components/usb_stack/class/msc;$(ProjectPath)../../../../components/usb_stack/class/video;$(ProjectPath)../../../../components/usb_stack/class/webusb;$(ProjectPath)../../../../components/usb_stack/class/winusb;$(ProjectPath)../../../../components/usb_stack/common;$(ProjectPath)../../../../components/usb_stack/core;$(ProjectPath)../../../../bsp/board/bl706_iot;$(ProjectPath)../../../../bsp/bsp_common/platform;$(ProjectPath)../../../../common/device;$(ProjectPath)../../../../common/list;$(ProjectPath)../../../../common/memheap;$(ProjectPath)../../../../common/misc;$(ProjectPath)../../../../common/ring_buffer;$(ProjectPath)../../../../common/soft_crc;$(ProjectPath)../../../../components/shell;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl702_driver/regs;$(ProjectPath)../../../../drivers/bl702_driver/startup;$(ProjectPath)../../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../../drivers/bl602_driver/startup;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../../drivers/bl602_driver/regs;$(ProjectPath)../../../../drivers/bl602_driver/std_drv/inc + + gdwarf2 + + + yes + yes + $(ProjectPath)../../../../drivers/bl702_driver/bl702_flash.ld + + + + no + + + + yes + ICE + yes + main + + $(ProjectPath)/../../../../tools/openocd/bl70x_gdb.init + yes + Hard Reset + 23000000 + no + no + $(ProjectPath)/$(ProjectName).cdkcore + + localhost + 1025 + 0 + 2000 + 10 + 50 + yes + no + no + Normal + Hard Reset + 21000000 + Bare Metal + yes + yes + + Local + -arch riscv + + + + + yes + no + no + + + openocd-hifive + no + 4444 + no + 6666 + -f ../../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../../tools/openocd/tgt_702.cfg + + + + + Erase Sectors + bl70x_flasher.elf + yes + yes + no + Hard Reset + + no + + + + + + + + ;;; + ;;MHZ; + + glb + uart + + 1 + 1 + + 100:8;100:8;100:8;100:8; + + + + ;;; + ;;MHZ; + + glb + uart + + 1 + 1 + + 100:8;100:8;100:8;100:8; + + diff --git a/examples/pwm_step_motor/main.c b/examples/pwm_step_motor/main.c new file mode 100644 index 00000000..f8d1ae7a --- /dev/null +++ b/examples/pwm_step_motor/main.c @@ -0,0 +1,139 @@ +/** + * @file pwm_step_motor.c + * @brief + * + * Copyright (c) 2021 Bouffalolab team + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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 "hal_pwm.h" +#include "hal_gpio.h" +#include "hal_clock.h" +/* 一二相励磁:八拍(A+B+,B+,B+A-,A-,A-B-,B-,B-A+,A+。。。。) + ___ ___ ___ +CH0 |___ ___ ___ ___ ___| + ___ ___ ___ +CH1 ___| |___ ___ ___ ___ + ___ ___ ___ +CH2 ___ ___ ___| |___ ___ + ___ ___ ___ +CH3 ___ ___ ___ ___ ___| + +*/ + +struct device *motor_ch0; +struct device *motor_ch1; +struct device *motor_ch2; +struct device *motor_ch3; + +enum motor_dir_type { + CW, + CCW, + STOP +}; + +void motor_set_dir(enum motor_dir_type dir) +{ + pwm_dutycycle_config_t pwm_cfg[4]; + + if (dir == CW) { + pwm_cfg[0].threshold_low = 2; + pwm_cfg[0].threshold_high = 7; + pwm_cfg[1].threshold_low = 1; + pwm_cfg[1].threshold_high = 4; + pwm_cfg[2].threshold_low = 3; + pwm_cfg[2].threshold_high = 6; + pwm_cfg[3].threshold_low = 5; + pwm_cfg[3].threshold_high = 8; + } + + else if (dir == CCW) { + pwm_cfg[0].threshold_low = 2; + pwm_cfg[0].threshold_high = 7; + pwm_cfg[1].threshold_low = 5; + pwm_cfg[1].threshold_high = 8; + pwm_cfg[2].threshold_low = 3; + pwm_cfg[2].threshold_high = 6; + pwm_cfg[3].threshold_low = 1; + pwm_cfg[3].threshold_high = 4; + } else if (dir == STOP) { + pwm_cfg[0].threshold_low = 0; + pwm_cfg[0].threshold_high = 0; + pwm_cfg[1].threshold_low = 0; + pwm_cfg[1].threshold_high = 0; + pwm_cfg[2].threshold_low = 0; + pwm_cfg[2].threshold_high = 0; + pwm_cfg[3].threshold_low = 0; + pwm_cfg[3].threshold_high = 0; + } + device_control(motor_ch0, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[0]); + device_control(motor_ch1, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[1]); + device_control(motor_ch2, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[2]); + device_control(motor_ch3, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[3]); +} + +int main(void) +{ + bflb_platform_init(0); + + pwm_register(PWM_CH0_INDEX, "motor_ch0", DEVICE_OFLAG_RDWR); + pwm_register(PWM_CH1_INDEX, "motor_ch1", DEVICE_OFLAG_RDWR); + pwm_register(PWM_CH2_INDEX, "motor_ch2", DEVICE_OFLAG_RDWR); + pwm_register(PWM_CH3_INDEX, "motor_ch3", DEVICE_OFLAG_RDWR); + + motor_ch0 = device_find("motor_ch0"); + motor_ch1 = device_find("motor_ch1"); + motor_ch2 = device_find("motor_ch2"); + motor_ch3 = device_find("motor_ch3"); + + if (motor_ch0) { + PWM_DEV(motor_ch0)->period = 8; //frequence = 32K/32/8 = 125hz + PWM_DEV(motor_ch0)->threshold_low = 2; + PWM_DEV(motor_ch0)->threshold_high = 7; + PWM_DEV(motor_ch0)->polarity_invert_mode = ENABLE; + device_open(motor_ch0, DEVICE_OFLAG_STREAM_TX); + } + if (motor_ch1) { + PWM_DEV(motor_ch1)->period = 8; //frequence = 32K/32/8 = 125hz + PWM_DEV(motor_ch1)->threshold_low = 1; + PWM_DEV(motor_ch1)->threshold_high = 4; + device_open(motor_ch1, DEVICE_OFLAG_STREAM_TX); + } + if (motor_ch2) { + PWM_DEV(motor_ch2)->period = 8; //frequence = 32K/32/8 = 125hz + PWM_DEV(motor_ch2)->threshold_low = 3; + PWM_DEV(motor_ch2)->threshold_high = 6; + device_open(motor_ch2, DEVICE_OFLAG_STREAM_TX); + } + if (motor_ch3) { + PWM_DEV(motor_ch3)->period = 8; //frequence = 32K/32/8 = 125hz + PWM_DEV(motor_ch3)->threshold_low = 5; + PWM_DEV(motor_ch3)->threshold_high = 8; + device_open(motor_ch3, DEVICE_OFLAG_STREAM_TX); + } + pwm_channel_start(motor_ch0); + pwm_channel_start(motor_ch1); + pwm_channel_start(motor_ch2); + pwm_channel_start(motor_ch3); + + while (1) { + motor_set_dir(CW); + bflb_platform_delay_ms(5000); + motor_set_dir(CCW); + bflb_platform_delay_ms(5000); + } +} diff --git a/examples/pwm_step_motor/readme.md b/examples/pwm_step_motor/readme.md new file mode 100644 index 00000000..d00accf3 --- /dev/null +++ b/examples/pwm_step_motor/readme.md @@ -0,0 +1,17 @@ +**board/bl706_iot/pinmux_config.h** 中, 以下宏设置成 **GPIO_FUN_PWM** + +- **CONFIG_GPIO10_FUNC** +- **CONFIG_GPIO11_FUNC** +- **CONFIG_GPIO12_FUNC** +- **CONFIG_GPIO3_FUNC** + +**board/bl706_iot/clock_config.h** 中 + +- **BSP_PWM_CLOCK_SOURCE** 选择 **ROOT_CLOCK_SOURCE_RC_32K**, +- **BSP_PWM_CLOCK_DIV** 设置成 **32** + +```bash + +$ make APP=pwm_it BOARD=bl706_iot + +``` \ No newline at end of file