From 93d821f2aaa1036dc349b660abd77a0ff704d712 Mon Sep 17 00:00:00 2001 From: "lichao.ren" Date: Fri, 19 May 2023 16:18:53 +0800 Subject: [PATCH] [Add] Add x2600 PWM DMA function --- drivers/drivers-x2600/ChangeLog | 1 + .../drivers-x2600/include/x2600_hal_pdma.h | 2 +- drivers/drivers-x2600/include/x2600_hal_pwm.h | 25 ++- drivers/drivers-x2600/src/x2600_hal_pwm.c | 80 ++++---- .../Examples/pwm-dma/.vscode/cmake-kits.json | 18 ++ .../Examples/pwm-dma/.vscode/launch.json | 63 +++++++ .../Examples/pwm-dma/.vscode/settings.json | 3 + .../Examples/pwm-dma/.vscode/tasks.json | 12 ++ .../Examples/pwm-dma/CMakeLists.txt | 112 +++++++++++ .../x2660-halley/Examples/pwm-dma/Makefile | 178 ++++++++++++++++++ .../pwm-dma/include/board_eth_phy_conf.h | 75 ++++++++ .../Examples/pwm-dma/include/x16xx_hal_conf.h | 116 ++++++++++++ .../pwm-dma/include/x16xx_sysclk_conf.h | 67 +++++++ projects/x2660-halley/Examples/pwm-dma/main.c | 105 +++++++++++ .../Examples/pwm-dma/riscv32-gcc.cmake | 18 ++ projects/x2660-halley/Examples/pwm/Makefile | 1 + projects/x2660-halley/Examples/pwm/main.c | 4 +- 17 files changed, 838 insertions(+), 42 deletions(-) create mode 100644 projects/x2660-halley/Examples/pwm-dma/.vscode/cmake-kits.json create mode 100644 projects/x2660-halley/Examples/pwm-dma/.vscode/launch.json create mode 100644 projects/x2660-halley/Examples/pwm-dma/.vscode/settings.json create mode 100644 projects/x2660-halley/Examples/pwm-dma/.vscode/tasks.json create mode 100644 projects/x2660-halley/Examples/pwm-dma/CMakeLists.txt create mode 100644 projects/x2660-halley/Examples/pwm-dma/Makefile create mode 100644 projects/x2660-halley/Examples/pwm-dma/include/board_eth_phy_conf.h create mode 100644 projects/x2660-halley/Examples/pwm-dma/include/x16xx_hal_conf.h create mode 100644 projects/x2660-halley/Examples/pwm-dma/include/x16xx_sysclk_conf.h create mode 100644 projects/x2660-halley/Examples/pwm-dma/main.c create mode 100644 projects/x2660-halley/Examples/pwm-dma/riscv32-gcc.cmake diff --git a/drivers/drivers-x2600/ChangeLog b/drivers/drivers-x2600/ChangeLog index cceb8af8..edf8ee24 100644 --- a/drivers/drivers-x2600/ChangeLog +++ b/drivers/drivers-x2600/ChangeLog @@ -1,3 +1,4 @@ +2023-5-19 支持PWM DMA模式 2023-5-12 支持PWM寄存器模式 PWM DMA模式尚未支持 2023-5-11 支持i2c轮询模式和中断模式 i2c DMA模式尚未支持 2023-5-6 支持CPM开关gate 具体模块需要使用配置尚未添加 diff --git a/drivers/drivers-x2600/include/x2600_hal_pdma.h b/drivers/drivers-x2600/include/x2600_hal_pdma.h index 68ebe285..db3bbcad 100755 --- a/drivers/drivers-x2600/include/x2600_hal_pdma.h +++ b/drivers/drivers-x2600/include/x2600_hal_pdma.h @@ -479,7 +479,7 @@ HAL_StatusTypeDef HAL_DMA_UnRegisterCallback( #define DES6 #define DES7 -#define IS_DMA_INSTANCE(INSTANCE) (INSTANCE) == DMA_Instance +#define IS_DMA_INSTANCE(INSTANCE) ((INSTANCE) == DMA_Instance || (INSTANCE) == MCU_DMA_Instance) #define IS_DMA_STRIDE_MODE(STRIDE_MODE) (STRIDE_MODE == DESCRIPTOR || STRIDE_MODE == NO_DESCRIPTOR) #define IS_DMA_LINK(DMA_LINK) (DMA_LINK == NO_LINK || DMA_LINK == LINK_CYCLE) diff --git a/drivers/drivers-x2600/include/x2600_hal_pwm.h b/drivers/drivers-x2600/include/x2600_hal_pwm.h index c13eb82d..3388950d 100644 --- a/drivers/drivers-x2600/include/x2600_hal_pwm.h +++ b/drivers/drivers-x2600/include/x2600_hal_pwm.h @@ -94,6 +94,8 @@ typedef struct __PWM_HandleTypeDef { uint32_t PWMColck; /*!< PWM时钟频率 */ __IO uint32_t Channels; /*!< 所有通道 */ HAL_LockTypeDef Lock; /*!< PWM Lock */ + DMA_HandleTypeDef *DMA_Handle; + DMA_InitChannelConfTypeDef *PWM_DMA_Config; } PWM_HandleTypeDef; /** * @} @@ -133,6 +135,7 @@ typedef struct __PWM_HandleTypeDef { */ #define __HAL_PWM_ENABLE_HW(__HANDLE__, __CHANNEL__) WRITE_REG((__HANDLE__)->Instance->PWMENS, 1 << __CHANNEL__) +#define __HAL_PWM_DMA_ENABLE_HW(__HANDLE__, __CHANNEL__) WRITE_REG((__HANDLE__)->Instance->PWMDRE, 1 << __CHANNEL__) /** @brief 禁用指定的PWM通道。 * @param __HANDLE__ 指定PWM句柄. * @param __CHANNEL__ 指定PWM通道. @@ -156,6 +159,7 @@ HAL_StatusTypeDef HAL_PWM_updateConfig(PWM_HandleTypeDef *hpwm, PWM_InitTypeDef HAL_StatusTypeDef HAL_PWM_DeInit(PWM_HandleTypeDef *hpwm); HAL_StatusTypeDef HAL_PWM_Enable(PWM_HandleTypeDef *hpwm); HAL_StatusTypeDef HAL_PWM_Disable(PWM_HandleTypeDef *hpwm); +void dump_pwm_reg(PWM_HandleTypeDef *hpwm); /** * @} */ @@ -292,7 +296,26 @@ HAL_StatusTypeDef HAL_PWM_Disable(PWM_HandleTypeDef *hpwm); WRITE_REG((__HANDLE__)->Instance->PWMWCn[__CHANNEL__], tmp); \ } while (0) -#define __HAL_PWM_SET_FIFO_THRESHOLD(__HANDLE__, __CHANNEL__) WRITE_REG((__HANDLE__)->Instance->PWMDRTNn(__CHANNEL__), 32); +#define __HAL_PWM_SET_FIFO_THROSHOLD(__HANDLE__, __CHANNEL__) WRITE_REG((__HANDLE__)->Instance->PWMDRTNn[__CHANNEL__], 32); + +#define __HAL_PWM_DMA_UNDER_IRQ_ENBLE(__HANDLE__, __CHANNEL__) \ + do { \ + int tmp = READ_REG((__HANDLE__)->Instance->PWMDFIE); \ + tmp |= 1 << __CHANNEL__; \ + WRITE_REG((__HANDLE__)->Instance->PWMDFIE, tmp); \ + } while (0) + +//#define __HAL_PWM_SET_FIFO_THROSHOLD(__HANDLE__, __CHANNEL__) WRITE_REG((__HANDLE__)->Instance->PWMDRTNn(__CHANNEL__), 32); + +#define __HAL_PWM_DMA_ASYNC_FIFO_FLUSH(__HANDLE__, __CHANNEL__) WRITE_REG((__HANDLE__)->Instance->PWMDAFF, 1 << __CHANNEL__); + +#define __HAL_PWM_DMA_FIFO_FLUSH(__HANDLE__, __CHANNEL__) WRITE_REG((__HANDLE__)->Instance->PWMDCFF, 1 << __CHANNEL__); +/** @brief PWM_DR 寄存器,指向PWM FIFO。 + * * @param __HANDLE__ 指定PWM句柄. + * * @retval 无 + * */ +#define PWM_FIFO(__HANDLE__,num) (&(__HANDLE__)->Instance->PWMDRn[num]) + /** * @} */ diff --git a/drivers/drivers-x2600/src/x2600_hal_pwm.c b/drivers/drivers-x2600/src/x2600_hal_pwm.c index 279776c5..7d51f10c 100644 --- a/drivers/drivers-x2600/src/x2600_hal_pwm.c +++ b/drivers/drivers-x2600/src/x2600_hal_pwm.c @@ -86,7 +86,7 @@ void dump_pwm_reg(PWM_HandleTypeDef *hpwm) prom_printk("PWM_DRE = %08x\n", READ_REG(hpwm->Instance->PWMDRE)); prom_printk("PWM_SS = %08x\n", READ_REG(hpwm->Instance->PWMSS)); prom_printk("PWM_SIE = %08x\n", READ_REG(hpwm->Instance->PWMSIE)); - for (i = 0; i < 8; i++) { + for (i = 0; i < 16; i++) { if (!(READ_REG(hpwm->Instance->PWMEN) & (1 << i))) { continue; } @@ -117,45 +117,44 @@ HAL_StatusTypeDef HAL_PWM_setOneChannel(PWM_HandleTypeDef *hpwm, uint8_t ch) uint64_t dutyus = hpwm->Init[ch].dutyus; uint64_t tmp = 0; uint64_t period = 0,duty = 0; -// uint32_t freq = hpwm->Init[ch].freq; - /* 根据PWM时钟计算周期对应的寄存器count值 */ - //peroid = p_ns / (1000000000 / 200000000) - tmp = periodus * PWMClock; - period = tmp / NS; - // period_cycle = ns / (NS / pwmclk) - /* 周期寄存器count值大于最大值需要进行分频,分频数2^perscale */ - while ((period > PWM_DUTY_MAX_COUNT && perscale < 0xFFFF)) { - //periodCount >>= 1; - period_tmp = (uint32_t)period; - ++perscale; - period = period_tmp / perscale; - } - - /* 最大分频2^7 */ - if (perscale == 0xFFFF) { - prom_printk("pwm perscale bad value\n"); - return HAL_ERROR; - } - - /* 根据周期对应的count值计算占空比部分占的count值 */ - tmp = period * dutyus; - duty = tmp / periodus; - - // prom_printk("dutyus = %d, periodus - dutyus = %d, periodus = %d\n", dutyus, periodus - dutyus, periodus); - // prom_printk("dutyCount = %d, periodCount - dutyCount = %d, periodCount = %d\n", duty, periodCount - dutyCount, period); - // prom_printk("freq = %d\n", hpwm->Init[ch].freq); - // prom_printk("perscale = %d\n", perscale); + // prom_printk("dutyus = %d, periodus - dutyus = %d, periodus = %d\n", dutyus, periodus - dutyus, periodus); + // prom_printk("dutyCount = %d, periodCount - dutyCount = %d, periodCount = %d\n", dutyCount, periodCount - dutyCount, periodCount); + // prom_printk("freq = %d\n", hpwm->Init[ch].freq); + // prom_printk("perscale = %d\n", perscale); __HAL_PWM_CLK_CONFIG(hpwm, ch, perscale); - __HAL_PWM_SET_IDLE_LEVEL(hpwm, ch, !!hpwm->Init[ch].idleLevel); + __HAL_PWM_SET_IDLE_LEVEL(hpwm, ch, !hpwm->Init[ch].idleLevel); __HAL_PWM_SET_INIT_LEVEL(hpwm, ch, !hpwm->Init[ch].idleLevel); __HAL_SET_PWM_UPDATE_MODE(hpwm, ch, hpwm->Init[ch].Mode); - if (hpwm->Init[ch].Mode == commonMode) { - __HAL_PWM_WAVEFORM_HIGH(hpwm, ch, duty); - __HAL_PWM_WAVEFORM_LOW(hpwm, ch, (period - duty)); - } + if (hpwm->Init[ch].Mode == commonMode) { + /* 根据PWM时钟计算周期对应的寄存器count值 */ + //peroid = p_ns / (1000000000 / 200000000) + tmp = periodus * PWMClock; + period = tmp / NS; + // period_cycle = ns / (NS / pwmclk) + /* 周期寄存器count值大于最大值需要进行分频,分频数2^perscale */ + while ((period > PWM_DUTY_MAX_COUNT && perscale < 0xFFFF)) { + //periodCount >>= 1; + period_tmp = (uint32_t)period; + ++perscale; + period = period_tmp / perscale; + } + /* 根据周期对应的count值计算占空比部分占的count值 */ + tmp = period * dutyus; + duty = tmp / periodus; + __HAL_PWM_WAVEFORM_HIGH(hpwm, ch, duty); + __HAL_PWM_WAVEFORM_LOW(hpwm, ch, (period - duty)); + } + + if (hpwm->Init[ch].Mode == dmaMode) { + __HAL_PWM_DMA_UNDER_IRQ_ENBLE(hpwm, ch); + __HAL_PWM_SET_FIFO_THROSHOLD(hpwm, ch); + __HAL_PWM_DMA_ASYNC_FIFO_FLUSH(hpwm, ch); + __HAL_PWM_DMA_FIFO_FLUSH(hpwm, ch); + HAL_DMA_Start(hpwm->DMA_Handle, hpwm->PWM_DMA_Config->Channel); + } } return HAL_OK; @@ -181,11 +180,13 @@ HAL_StatusTypeDef HAL_PWM_setConfig(PWM_HandleTypeDef *hpwm, PWM_InitTypeDef *co __HAL_Lock(&hpwm->Lock); for (uint8_t ch = 0; ch < __HAL_PWM_MAX_CHANNEL; ch++) { if (config->Channels & (0x01U << ch)) { - hpwm->Init[ch].isEnable = ENABLE; + hpwm->Init[ch].isEnable = ENABLE; hpwm->Init[ch].Mode = config->Mode; - hpwm->Init[ch].periodus = config->periodus; - hpwm->Init[ch].freq = NS / config->periodus; - hpwm->Init[ch].dutyus = config->dutyus; + if(config->Mode == commonMode){ + hpwm->Init[ch].periodus = config->periodus; + hpwm->Init[ch].freq = NS / config->periodus; + hpwm->Init[ch].dutyus = config->dutyus; + } } } __HAL_UnLock(&hpwm->Lock); @@ -262,6 +263,9 @@ HAL_StatusTypeDef HAL_PWM_Enable(PWM_HandleTypeDef *hpwm) for (int ch = 0; ch < __HAL_PWM_MAX_CHANNEL; ch++) { if (hpwm->Channels & 0x01U << ch) { + if (hpwm->Init[ch].Mode == dmaMode){ + __HAL_PWM_DMA_ENABLE_HW(hpwm, ch); + } __HAL_PWM_ENABLE_HW(hpwm, ch); } } diff --git a/projects/x2660-halley/Examples/pwm-dma/.vscode/cmake-kits.json b/projects/x2660-halley/Examples/pwm-dma/.vscode/cmake-kits.json new file mode 100644 index 00000000..7c98a0d9 --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/.vscode/cmake-kits.json @@ -0,0 +1,18 @@ +[ + { + "name": "GCC for ingenic cross compile on Windows", + + "toolchainFile": "mips-gcc-sde-elf.cmake", + "preferredGenerator": { + "name":"MinGW Makefiles" + } + }, + { + "name": "GCC for ingenic cross compile on Linux", + "toolchainFile": "mips-gcc-sde-elf.cmake", + "preferredGenerator": { + "name":"Unix Makefiles" + } + } +] + \ No newline at end of file diff --git a/projects/x2660-halley/Examples/pwm-dma/.vscode/launch.json b/projects/x2660-halley/Examples/pwm-dma/.vscode/launch.json new file mode 100644 index 00000000..8ddcfe12 --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/.vscode/launch.json @@ -0,0 +1,63 @@ +{ + "version": "0.2.0", + "configurations": [ + // GDB Debugging: + { + "program": "${command:cmake.launchTargetPath}", + "name": "Launch (gdb)", + "request": "launch", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "internalConsoleOptions": "openOnSessionStart", + "type": "cppdbg", + "MIMode": "gdb", + "miDebuggerPath": "mips-sde-elf-gdb", + "miDebuggerArgs": "", + "miDebuggerServerAddress": "localhost:3333", + "targetArchitecture": "mips", + "preLaunchTask": "adb forward", + "customLaunchSetupCommands": [ + { + "description": "gdb 启用整齐打印", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "text":"cd ${workspaceFolder}", + "ignoreFailures": false + }, + { + "text":"file build/${command:cmake.buildType}/${command:cmake.launchTargetFilename}", + "ignoreFailures": false + }, + { + "text": "target remote localhost:3333", + "ignoreFailures": false + }, + { + "text": "monitor reset halt", + "ignoreFailures": false + }, + { + "text": "monitor x1600_init", + "ignoreFailures": false + }, + { + "text": "load", + "ignoreFailures": false + }, + { + "text": "monitor mips32 invalidate all", + "ignoreFailures": false + } + ], + "logging": { + "engineLogging": false, + "programOutput": true + } + } + ] + } + \ No newline at end of file diff --git a/projects/x2660-halley/Examples/pwm-dma/.vscode/settings.json b/projects/x2660-halley/Examples/pwm-dma/.vscode/settings.json new file mode 100644 index 00000000..e9c0426a --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cmake.buildDirectory": "${workspaceFolder}/build/${buildType}" +} \ No newline at end of file diff --git a/projects/x2660-halley/Examples/pwm-dma/.vscode/tasks.json b/projects/x2660-halley/Examples/pwm-dma/.vscode/tasks.json new file mode 100644 index 00000000..53b4731e --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/.vscode/tasks.json @@ -0,0 +1,12 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "adb forward", + "type": "shell", + "command": "adb forward tcp:3333 tcp:3333", + }, + ] +} \ No newline at end of file diff --git a/projects/x2660-halley/Examples/pwm-dma/CMakeLists.txt b/projects/x2660-halley/Examples/pwm-dma/CMakeLists.txt new file mode 100644 index 00000000..771a25bb --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/CMakeLists.txt @@ -0,0 +1,112 @@ +cmake_minimum_required(VERSION 3.8) +# +# Core project settings +# +Project(pwm) # Modified +enable_language(C CXX ASM) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# Setup compiler settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) +set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +set(SDK_PATH ${PROJ_PATH}/../../../../) +message("Build type: " ${CMAKE_BUILD_TYPE}) + +# Set linker script +set(linker_script_SRC ${SDK_PATH}/cpu/core-riscv/ld.lds) # Modified +set(EXECUTABLE ${CMAKE_PROJECT_NAME}) +set(CPU_PARAMETERS "-march=rv32imc -mabi=ilp32 -Wno-abi") + +set(CMAKE_ASM_FLAGS "${CPU_PARAMETERS} -D_ASSEMBLER_ -D__ASSEMBLY__") + +set(CMAKE_C_FLAGS "${CPU_PARAMETERS} -fno-pic -fno-builtin -fomit-frame-pointer -Wall -nostdlib -Wall -fdata-sections -ffunction-sections") + +# Compiler options + +if(CMAKE_BUILD_TYPE STREQUAL Debug) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -ggdb -DDEBUG") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") +endif() + +set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS}) + +set(CMAKE_LD_FLAGS "${CPU_PARAMETERS}") + + +set(sources_SRCS # Modified + ${SDK_PATH}/cpu/core-riscv/spinlock.c + ${SDK_PATH}/cpu/core-riscv/start.S + ${SDK_PATH}/cpu/core-riscv/genex.S + ${SDK_PATH}/cpu/core-riscv/traps.c + ${SDK_PATH}/cpu/soc-x2600/src/interrupt.c + ${SDK_PATH}/cpu/soc-x2600/src/serial.c + ${SDK_PATH}/cpu/soc-x2600/src/startup.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_hal_def.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_hal_pwm.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_hal_pdma.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_ll_cpm.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_ll_gpio.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_hal_tick_risc_ccu.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_ll_risc_ccu.c + ${SDK_PATH}/lib/libc/minimal/ctype.c + ${SDK_PATH}/lib/libc/minimal/div64.c + ${SDK_PATH}/lib/libc/minimal/string.c + ${SDK_PATH}/lib/libc/minimal/vsprintf.c + main.c +) + +if(CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() + +# +# Include directories +# +#set(include_path_DIRS +# Modified + +include_directories( + ${PROJ_PATH}/include + ${SDK_PATH}/lib/libc/minimal/include + ${SDK_PATH}/drivers/drivers-x2600/include + ${SDK_PATH}/cpu/core-riscv/include + ${SDK_PATH}/cpu/soc-x2600/include + +) + +# +# -L libdirs. +# +link_directories( +#path/to/lib +) + +# Executable files +add_executable(${EXECUTABLE} ${sources_SRCS}) + +# Linker options +target_link_libraries(${EXECUTABLE} PRIVATE + -T${linker_script_SRC} + ${CMAKE_LD_FLAGS} + -Wl,-Map=${CMAKE_PROJECT_NAME}.map,--cref + -Wl,--gc-sections + -Wl,--start-group + -Wl,--end-group + -Wl,--print-memory-usage +) + +# Execute post-build to print size +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_SIZE} $ +) + +# Convert output to hex and binary +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin + ) diff --git a/projects/x2660-halley/Examples/pwm-dma/Makefile b/projects/x2660-halley/Examples/pwm-dma/Makefile new file mode 100644 index 00000000..90f59014 --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/Makefile @@ -0,0 +1,178 @@ +###################################### +# target +###################################### +TARGET = pwm-dma + +SDK_PATH = ../../../../ + + +###################################### +# building variables +###################################### +# debug build? +DEBUG = 1 +# optimization +OPT = -Og -fno-pic -fno-builtin -fomit-frame-pointer -Wall -nostdlib -Werror-implicit-function-declaration + + +####################################### +# paths +####################################### +# Build path +BUILD_DIR = build + +###################################### +# source +###################################### +# C sources +C_SOURCES = \ +$(SDK_PATH)/cpu/core-riscv/traps.c \ +$(SDK_PATH)/cpu/core-riscv/spinlock.c \ +$(SDK_PATH)/cpu/soc-x2600/src/startup.c \ +$(SDK_PATH)/cpu/soc-x2600/src/serial.c \ +$(SDK_PATH)/cpu/soc-x2600/src/interrupt.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_def.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_pwm.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_pdma.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_ll_cpm.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_ll_gpio.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_tick_risc_ccu.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_ll_risc_ccu.c \ +$(SDK_PATH)/lib/libc/minimal/vsprintf.c \ +$(SDK_PATH)/lib/libc/minimal/string.c \ +$(SDK_PATH)/lib/libc/minimal/ctype.c \ +$(SDK_PATH)/lib/libc/minimal/div64.c \ +main.c + +# ASM sources +ASM_SOURCES = \ +$(SDK_PATH)/cpu/core-riscv/start.S \ +$(SDK_PATH)/cpu/core-riscv/genex.S + + +####################################### +# binaries +####################################### +PREFIX = riscv32-ingenicv0-elf- +# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) +# either it can be added to the PATH environment variable. +ifdef GCC_PATH +CC = $(GCC_PATH)/$(PREFIX)gcc +AS = $(GCC_PATH)/$(PREFIX)as +LD = $(GCC_PATH)/$(PREFIX)ld +CP = $(GCC_PATH)/$(PREFIX)objcopy +SZ = $(GCC_PATH)/$(PREFIX)size +else +CC = $(PREFIX)gcc +AS = $(PREFIX)as +LD = $(PREFIX)ld +CP = $(PREFIX)objcopy +SZ = $(PREFIX)size +endif +BIN = $(CP) -O binary -S + +####################################### +# CFLAGS +####################################### +# cpu +CPU = -march=rv32imc -mabi=ilp32 -Wno-abi + +# fpu +FPU = + +# float-abi +FLOAT-ABI = + +# mcu +#MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) +MCU = $(CPU) $(FPU) $(FLOAT-ABI) + +# macros for gcc +# AS defines +AS_DEFS = -D_ASSEMBLER_ -D__ASSEMBLY__ + +# C defines +C_DEFS = + + +# AS includes +AS_INCLUDES = \ +-I$(SDK_PATH)/cpu/core-riscv/include \ +-I$(SDK_PATH)/lib/libc/minimal/include \ + +# C includes +C_INCLUDES = \ +-Iinclude \ +-I$(SDK_PATH)/cpu/core-riscv/include \ +-I$(SDK_PATH)/cpu/soc-x2600/include \ +-I$(SDK_PATH)/lib/libc/minimal/include \ +-I$(SDK_PATH)/drivers/drivers-x2600/include + + +# compile gcc flags +ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +ifeq ($(DEBUG), 1) +CFLAGS += -g -gdwarf-2 -O0 +endif + + +# Generate dependency information +CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" + + +####################################### +# LDFLAGS +####################################### +# link script +LDSCRIPT = $(SDK_PATH)/cpu/core-riscv/ld.lds + +# libraries +#LIBS = -lc -lm -lnosys +LIBDIR = +LDFLAGS = $(MCU) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -nostdlib + +# default action: build all +all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).bin + + +####################################### +# build the application +####################################### +# list of objects +OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) +vpath %.c $(sort $(dir $(C_SOURCES))) +# list of ASM program objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.S=.o))) +vpath %.S $(sort $(dir $(ASM_SOURCES))) + +$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/%.o: %.S Makefile | $(BUILD_DIR) + $(CC) -c $(ASFLAGS) -o $@ $< + +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + $(SZ) $@ + +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(BIN) $< $@ + +$(BUILD_DIR): + mkdir $@ + +####################################### +# clean up +####################################### +clean: + -rm -fR $(BUILD_DIR) + +####################################### +# dependencies +####################################### +-include $(wildcard $(BUILD_DIR)/*.d) + +# *** EOF *** diff --git a/projects/x2660-halley/Examples/pwm-dma/include/board_eth_phy_conf.h b/projects/x2660-halley/Examples/pwm-dma/include/board_eth_phy_conf.h new file mode 100644 index 00000000..4812e374 --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/include/board_eth_phy_conf.h @@ -0,0 +1,75 @@ +#ifndef __ETH_PHY_CONF_H +#define __ETH_PHY_CONF_H + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 0x00U +#define MAC_ADDR1 0x11U +#define MAC_ADDR2 0x22U +#define MAC_ADDR3 0x33U +#define MAC_ADDR4 0x44U +#define MAC_ADDR5 0x55U + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848 PHY Address*/ +#define DP83848_PHY_ADDRESS 0x01U +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FFU) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU) + +#define PHY_READ_TO ((uint32_t)0x0000FFFFU) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFFU) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00U) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01U) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ + +#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ +#define PHY_MICR ((uint16_t)0x11U) /*!< MII Interrupt Control Register */ +#define PHY_MISR ((uint16_t)0x12U) /*!< MII Interrupt Status and Misc. Control Register */ + +#define PHY_LINK_STATUS ((uint16_t)0x0001U) /*!< PHY Link mask */ +#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ + +#define PHY_MICR_INT_EN ((uint16_t)0x0002U) /*!< PHY Enable interrupts */ +#define PHY_MICR_INT_OE ((uint16_t)0x0001U) /*!< PHY Enable output interrupt events */ + +#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020U) /*!< Enable Interrupt on change of link status */ +#define PHY_LINK_INTERRUPT ((uint16_t)0x2000U) /*!< PHY link status interrupt mask */ + +/* ################## Ethernet peripheral configuration ##################### */ + + + +#endif // __ETH_PHY_CONF_H + diff --git a/projects/x2660-halley/Examples/pwm-dma/include/x16xx_hal_conf.h b/projects/x2660-halley/Examples/pwm-dma/include/x16xx_hal_conf.h new file mode 100644 index 00000000..eb86eb35 --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/include/x16xx_hal_conf.h @@ -0,0 +1,116 @@ +#ifndef __X16XX_HAL_CONF_H__ +#define __X16XX_HAL_CONF_H__ +/* TODO: 本文件应该通过工具生成,在配置工程中选择不同的组件时,在此处包含不同的头文件 + 暂时包含全部头文件. +*/ + + +/* 1. Includes ---------------------------------------------------- */ + + +/* Hal Module selections. */ +#define HAL_MSC_ENABLED +#define HAL_I2C_ENABLED +#define HAL_UART_ENABLED +#define HAL_ADC_ENABLED +#define HAL_SPI_ENABLED +#define HAL_WDT_ENABLED +#define HAL_TCU_ENABLED +#define HAL_RTC_ENABLED +#define HAL_EFUSE_ENABLED +#define HAL_PWM_ENABLED +#define HAL_GMAC_ENABLED +#define HAL_USB_ENABLED + + +/* 系统时钟配配置,通过工具生成,随开发板或者平台变化.*/ +#include +#include + +#include "x16xx_hal_tick.h" +#include "x16xx_ll_ost.h" +#include "x16xx_ll_cpm.h" +#include "x16xx_ll_gpio.h" + +#include "x16xx_hal_pdma.h" + +#include "x16xx_hal_sfcnor.h" + +#ifdef HAL_MSC_ENABLED +#include "x16xx_hal_msc.h" +#endif + +#ifdef HAL_I2C_ENABLED +#include "x16xx_hal_i2c.h" +#endif + +#ifdef HAL_UART_ENABLED +#include "x16xx_hal_uart.h" +#endif + +#ifdef HAL_ADC_ENABLED +#include "x16xx_hal_adc.h" +#endif + +#ifdef HAL_SPI_ENABLED +#include "x16xx_hal_spi.h" +#endif + +#ifdef HAL_WDT_ENABLED +#include "x16xx_hal_wdt.h" +#endif + +#ifdef HAL_TCU_ENABLED +#include "x16xx_hal_tcu.h" +#endif + +#ifdef HAL_RTC_ENABLED +#include "x16xx_hal_rtc.h" +#endif + +#ifdef HAL_EFUSE_ENABLED +#include "x16xx_ll_efuse.h" +#include "x16xx_hal_efuse.h" +#endif + +#ifdef HAL_PWM_ENABLED +#include "x16xx_hal_pwm.h" +#endif + +#ifdef HAL_GMAC_ENABLED +#include "x16xx_hal_gmac.h" +#endif + +#ifdef HAL_USB_ENABLED +#include "x16xx_hal_pcd.h" +#include "x16xx_hal_pcd_ex.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* 2. Exported Types ---------------------------------------------- */ + +/* 3. Exported Constants ------------------------------------------ */ + +/* 4. Exported Macros --------------------------------------------- */ + +/* 5. Exported Funcs ---------------------------------------------- */ + +/* 6. Exported Variables ------------------------------------------ */ + +/* 7. Private Types ----------------------------------------------- */ + +/* 8. Private Constants ------------------------------------------- */ + +/* 9. Private Macros ---------------------------------------------- */ + +/* 10. Private Funcs ---------------------------------------------- */ + +/* 11. Private Variables ------------------------------------------ */ + +#ifdef __cplusplus +} +#endif +#endif /* __X16XX_HAL_H__ */ diff --git a/projects/x2660-halley/Examples/pwm-dma/include/x16xx_sysclk_conf.h b/projects/x2660-halley/Examples/pwm-dma/include/x16xx_sysclk_conf.h new file mode 100644 index 00000000..3556642a --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/include/x16xx_sysclk_conf.h @@ -0,0 +1,67 @@ +/** + * @file x16xx_sysclk_conf.h + * @author MPU系统软件部团队 + * @brief + * + * @copyright 版权所有 (北京君正集成电路股份有限公司) {2022} + * @copyright Copyright© 2022 Ingenic Semiconductor Co.,Ltd + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#ifndef __X16XX_SYSCLK_CONF_H__ +#define __X16XX_SYSCLK_CONF_H__ + +#ifdef __cplusplus +extern "C" { +#endif +/* 1. Includes ---------------------------------------------------- */ + +/* 2. Exported Types ---------------------------------------------- */ + + +/* 3. Exported Constants ------------------------------------------ */ + +/* 4. Exported Macros --------------------------------------------- */ +#define SYSCLK_EXTAL (24000000) +#define SYSCLK_APLL (1200000000) +#define SYSCLK_MPLL (1200000000) +#define SystemCoreClock SYSCLK_APLL + +#define CGU_CONFIG_MSC_APLL_24M { \ + .PLLMux = MSC1CDR_SCLK_A, \ + .Div = 24, \ + .Config = 0 } + +#define CGU_CONFIG_MSC_APLL_48M { \ + .PLLMux = MSC1CDR_SCLK_A, \ + .Div = 11, \ + .Config = 0 } + + +#define CGU_CONFIG_SSI_MPLL_500K { \ + .PLLMux = SSICDR_MPLL, \ + .Div = 15, \ + .Config = 0 } + +/* 5. Exported Funcs ---------------------------------------------- */ + +/* 6. Exported Variables ------------------------------------------ */ + +/* 7. Private Types ----------------------------------------------- */ + +/* 8. Private Constants ------------------------------------------- */ + +/* 9. Private Macros ---------------------------------------------- */ + +/* 10. Private Funcs ---------------------------------------------- */ + +/* 11. Private Variables ------------------------------------------ */ + +#ifdef __cplusplus +} +#endif +#endif /* __X16XX_HAL_ADC_H__ */ diff --git a/projects/x2660-halley/Examples/pwm-dma/main.c b/projects/x2660-halley/Examples/pwm-dma/main.c new file mode 100644 index 00000000..9161ca1b --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/main.c @@ -0,0 +1,105 @@ +#include +#include + +#define PWMx PWM_Instance + +PWM_HandleTypeDef PWM_Handle; +PWM_InitTypeDef PWM_Config; + +__align(32) uint32_t TxBuffer[] = { + 0x00320032, +}; + +DMA_HandleTypeDef DMA_Handle; +DMA_InitChannelConfTypeDef PWM_DMA_Config; +__align(32) DMA_DescriptorDef PWM_Tx_desc; +DMA_InitDescConfTypeDef PWM_Tx_descConfig; +void dma_tx_cb(struct __DMA_HandleTypeDef *hdma) +{ + prom_printk("**-------------------dma tx end\n"); + return; +} + +LL_CPM_CGU_ConfigTypeDef CGU_Config_PWM_120000000 = { + 0, 11, 0 +}; // SCLK_A是APLL,1.2G 11+1=12分频,100M +void Pwm_Dma_Mode_Config(void) +{ + PWM_Handle.Instance = PWMx; + PWM_Handle.PWMColck = SYSCLK_APLL / 12; // 100M频率 + PWM_Handle.DMA_Handle = &DMA_Handle; + PWM_Handle.PWM_DMA_Config = &PWM_DMA_Config; + + prom_printk("pwmClock = %d\n", PWM_Handle.PWMColck); + PWM_Config.Channels = CHANNEL_12; + PWM_Config.idleLevel = PWMIdleLow; + PWM_Config.Mode = dmaMode; + + PWM_DMA_Config.XferCpltCallback = dma_tx_cb; + PWM_DMA_Config.data = NULL; + PWM_DMA_Config.DescMode = DESCRIPTOR; + PWM_DMA_Config.desc = &PWM_Tx_desc; + PWM_DMA_Config.descConfig = &PWM_Tx_descConfig; + PWM_DMA_Config.desc_count = sizeof(PWM_Tx_desc) / sizeof(DMA_DescriptorDef); + + PWM_Tx_descConfig.Desc_Interrupt = DMA_INTERRUPT; + PWM_Tx_descConfig.Desc_Link = LINK_CYCLE; + PWM_Tx_descConfig.DescDMATransferType = DMA_RQ_PWM12_TX; + + PWM_Tx_descConfig.DescSrcAddress = TxBuffer; + PWM_Tx_descConfig.DescSrcAddrIncrement = DISABLE; + PWM_Tx_descConfig.DescSrcPortWidth = DMA_PORT_32BIT; + + PWM_Tx_descConfig.DescDstAddress = (void *)PWM_FIFO(&PWM_Handle,12); + PWM_Tx_descConfig.DescDstAddrIncrement = DISABLE; + PWM_Tx_descConfig.DescDstPortWidth = DMA_PORT_32BIT; + + PWM_Tx_descConfig.DescTransferNumByte = 4; + PWM_Tx_descConfig.DataLength = 1; + + DMA_Handle.Instance = MCU_DMA_Instance; +} + +int main(void) +{ + prom_printk("hello world %s, %d\n", __func__, __LINE__); + //SET_BIT(TCU_Instance->TESR, 0x1); + prom_printk("DISABLE: %d\n", DISABLE); + + /* enable pwm clock gate */ + CPM_GATE_Enable(CPM_Instance, CPM_CLKID_PWM); + CPM_GATE_Enable(CPM_Instance, CPM_CLKID_DMAC1); + /* clock generation unit, Divider for PWM clock Frequency */ + CPM_CGU_PWM_Start(CPM_Instance, &CGU_Config_PWM_120000000); + + HAL_InitTick(); + /* PWM12 PC11 func 0*/ + LL_GPIO_getPinLevel(PC_Instance, 11); + LL_GPIO_setPinMode(PC_Instance, 11, GPIO_MODE_FUNCTION0); + /*初始化DMA描述符*/ + Pwm_Dma_Mode_Config(); + /*初始化DMA*/ + HAL_DMA_Init(PWM_Handle.DMA_Handle); + /*申请DMA通道*/ + int ch; + if (PWM_Handle.PWM_DMA_Config != NULL) { + ch = HAL_DMA_requestChannel(PWM_Handle.DMA_Handle, PWM_Handle.PWM_DMA_Config); + prom_printk("--------------------------->>> %s %d tx ch = %d\n", __func__, __LINE__,ch); + } + + /* 设置PWM配置 */ + HAL_PWM_setConfig(&PWM_Handle, &PWM_Config); + + /* 初始化PWM配置 */ + HAL_PWM_Init(&PWM_Handle); + + /* 使能PWM */ + HAL_PWM_Enable(&PWM_Handle); + + while (1) { + HAL_Delay(1000); + HAL_Delay(3000); + } + + return 0; +} diff --git a/projects/x2660-halley/Examples/pwm-dma/riscv32-gcc.cmake b/projects/x2660-halley/Examples/pwm-dma/riscv32-gcc.cmake new file mode 100644 index 00000000..d09813df --- /dev/null +++ b/projects/x2660-halley/Examples/pwm-dma/riscv32-gcc.cmake @@ -0,0 +1,18 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR riscv32) + +# Some default GCC settings +set(TOOLCHAIN_PREFIX "riscv32-ingenicv0-elf-") + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) + +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) + +set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) diff --git a/projects/x2660-halley/Examples/pwm/Makefile b/projects/x2660-halley/Examples/pwm/Makefile index 0949d6d5..a522e679 100644 --- a/projects/x2660-halley/Examples/pwm/Makefile +++ b/projects/x2660-halley/Examples/pwm/Makefile @@ -33,6 +33,7 @@ $(SDK_PATH)/cpu/soc-x2600/src/serial.c \ $(SDK_PATH)/cpu/soc-x2600/src/interrupt.c \ $(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_def.c \ $(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_pwm.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_pdma.c \ $(SDK_PATH)/drivers/drivers-x2600/src/x2600_ll_cpm.c \ $(SDK_PATH)/drivers/drivers-x2600/src/x2600_ll_gpio.c \ $(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_tick_risc_ccu.c \ diff --git a/projects/x2660-halley/Examples/pwm/main.c b/projects/x2660-halley/Examples/pwm/main.c index 89f8a2c9..50d504ba 100644 --- a/projects/x2660-halley/Examples/pwm/main.c +++ b/projects/x2660-halley/Examples/pwm/main.c @@ -31,8 +31,8 @@ int main(void) prom_printk("pwmClock = %d\n", PWM_Handle.PWMColck); PWM_Config.Channels = CHANNEL_12; - PWM_Config.periodus = 50; - PWM_Config.dutyus = 25; + PWM_Config.periodus = 1000; + PWM_Config.dutyus = 500; PWM_Config.idleLevel = PWMIdleLow; /* 设置PWM配置 */ -- Gitee