mirror of
https://github.com/modelec/alim_STM32.git
synced 2026-01-18 16:27:24 +01:00
Nouveaux messages + ajout middleware USBPD
This commit is contained in:
70
.cproject
70
.cproject
@@ -23,7 +23,7 @@
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.970867134" name="Floating-point unit" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.fpv4-sp-d16" valueType="enumerated"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.1666975731" name="Floating-point ABI" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1344835580" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1587383513" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G491KEUx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32G4xx_HAL_Driver/Inc | ../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32G4xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32G491xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32G491KEUX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1587383513" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G491KEUx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32G4xx_HAL_Driver/Inc | ../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32G4xx/Include | ../Drivers/CMSIS/Include | ../USBPD/App | ../USBPD | ../Middlewares/ST/STM32_USBPD_Library/Core/inc | ../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/inc || || || USE_HAL_DRIVER | STM32G491xx | USE_FULL_LL_DRIVER | USBPD_PORT_COUNT=1 | _SRC | USBPDCORE_LIB_PD3_FULL || || Drivers | Core/Startup | USBPD | Middlewares | Core || || ../Middlewares/ST/STM32_USBPD_Library/Core/lib/USBPDCORE_PD3_FULL_CM4_wc32.a || ${workspace_loc:/${ProjName}/STM32G491KEUX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1534741263" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="72" valueType="string"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.745974692" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
||||
<builder buildPath="${workspace_loc:/pcb_alim}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.719748171" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
||||
@@ -41,6 +41,10 @@
|
||||
<listOptionValue builtIn="false" value="DEBUG"/>
|
||||
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="STM32G491xx"/>
|
||||
<listOptionValue builtIn="false" value="USE_FULL_LL_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="USBPD_PORT_COUNT=1"/>
|
||||
<listOptionValue builtIn="false" value="_SRC"/>
|
||||
<listOptionValue builtIn="false" value="USBPDCORE_LIB_PD3_FULL"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths.397230116" name="Include paths (-I)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value="../Core/Inc"/>
|
||||
@@ -48,6 +52,10 @@
|
||||
<listOptionValue builtIn="false" value="../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32G4xx/Include"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
|
||||
<listOptionValue builtIn="false" value="../USBPD/App"/>
|
||||
<listOptionValue builtIn="false" value="../USBPD"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Core/inc"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/inc"/>
|
||||
</option>
|
||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1031222915" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
|
||||
</tool>
|
||||
@@ -58,6 +66,10 @@
|
||||
<listOptionValue builtIn="false" value="DEBUG"/>
|
||||
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="STM32G491xx"/>
|
||||
<listOptionValue builtIn="false" value="USE_FULL_LL_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="USBPD_PORT_COUNT=1"/>
|
||||
<listOptionValue builtIn="false" value="_SRC"/>
|
||||
<listOptionValue builtIn="false" value="USBPDCORE_LIB_PD3_FULL"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.includepaths.302488918" name="Include paths (-I)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.includepaths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value="../Core/Inc"/>
|
||||
@@ -65,12 +77,29 @@
|
||||
<listOptionValue builtIn="false" value="../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32G4xx/Include"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
|
||||
<listOptionValue builtIn="false" value="../USBPD/App"/>
|
||||
<listOptionValue builtIn="false" value="../USBPD"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Core/inc"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/inc"/>
|
||||
</option>
|
||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.input.cpp.389247630" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.input.cpp"/>
|
||||
</tool>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.1983147086" name="MCU/MPU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker"/>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.1983147086" name="MCU/MPU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker">
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories.649226700" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Core/lib"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries.216829312" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries" valueType="libs">
|
||||
<listOptionValue builtIn="false" value=":USBPDCORE_PD3_FULL_CM4_wc32.a"/>
|
||||
</option>
|
||||
</tool>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.1605737230" name="MCU/MPU G++ Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker">
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script.1355932755" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script" value="${workspace_loc:/${ProjName}/STM32G491KEUX_FLASH.ld}" valueType="string"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.directories.115149719" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.directories" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Core/lib"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.libraries.2017483705" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.libraries" valueType="libs">
|
||||
<listOptionValue builtIn="false" value=":USBPDCORE_PD3_FULL_CM4_wc32.a"/>
|
||||
</option>
|
||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.input.851615422" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
@@ -88,6 +117,8 @@
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="USBPD"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
@@ -116,7 +147,7 @@
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.1792112701" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.fpv4-sp-d16" valueType="enumerated"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.1705326624" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1600277484" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.568048205" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G491KEUx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32G4xx_HAL_Driver/Inc | ../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32G4xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32G491xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32G491KEUX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.568048205" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G491KEUx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32G4xx_HAL_Driver/Inc | ../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32G4xx/Include | ../Drivers/CMSIS/Include | ../USBPD/App | ../USBPD | ../Middlewares/ST/STM32_USBPD_Library/Core/inc | ../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/inc || || || USE_HAL_DRIVER | STM32G491xx | USE_FULL_LL_DRIVER | USBPD_PORT_COUNT=1 | _SRC | USBPDCORE_LIB_PD3_FULL || || Drivers | Core/Startup | USBPD | Middlewares | Core || || ../Middlewares/ST/STM32_USBPD_Library/Core/lib/USBPDCORE_PD3_FULL_CM4_wc32.a || ${workspace_loc:/${ProjName}/STM32G491KEUX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1613134491" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="72" valueType="string"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.1674598563" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
||||
<builder buildPath="${workspace_loc:/pcb_alim}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1370931433" managedBuildOn="true" name="Gnu Make Builder.Release" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
||||
@@ -130,6 +161,10 @@
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.1991410594" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="STM32G491xx"/>
|
||||
<listOptionValue builtIn="false" value="USE_FULL_LL_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="USBPD_PORT_COUNT=1"/>
|
||||
<listOptionValue builtIn="false" value="_SRC"/>
|
||||
<listOptionValue builtIn="false" value="USBPDCORE_LIB_PD3_FULL"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths.529384047" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value="../Core/Inc"/>
|
||||
@@ -137,6 +172,10 @@
|
||||
<listOptionValue builtIn="false" value="../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32G4xx/Include"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
|
||||
<listOptionValue builtIn="false" value="../USBPD/App"/>
|
||||
<listOptionValue builtIn="false" value="../USBPD"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Core/inc"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/inc"/>
|
||||
</option>
|
||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1603193579" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
|
||||
</tool>
|
||||
@@ -146,6 +185,10 @@
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols.1107872922" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="STM32G491xx"/>
|
||||
<listOptionValue builtIn="false" value="USE_FULL_LL_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="USBPD_PORT_COUNT=1"/>
|
||||
<listOptionValue builtIn="false" value="_SRC"/>
|
||||
<listOptionValue builtIn="false" value="USBPDCORE_LIB_PD3_FULL"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.includepaths.670362010" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.includepaths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value="../Core/Inc"/>
|
||||
@@ -153,12 +196,29 @@
|
||||
<listOptionValue builtIn="false" value="../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32G4xx/Include"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
|
||||
<listOptionValue builtIn="false" value="../USBPD/App"/>
|
||||
<listOptionValue builtIn="false" value="../USBPD"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Core/inc"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/inc"/>
|
||||
</option>
|
||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.input.cpp.904889893" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.input.cpp"/>
|
||||
</tool>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.786995719" name="MCU/MPU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker"/>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.786995719" name="MCU/MPU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker">
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories.701513337" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Core/lib"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries.242697029" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries" valueType="libs">
|
||||
<listOptionValue builtIn="false" value=":USBPDCORE_PD3_FULL_CM4_wc32.a"/>
|
||||
</option>
|
||||
</tool>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.910235295" name="MCU/MPU G++ Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker">
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script.1360440850" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script" value="${workspace_loc:/${ProjName}/STM32G491KEUX_FLASH.ld}" valueType="string"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.directories.45603235" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.directories" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USBPD_Library/Core/lib"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.libraries.1108474165" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.libraries" valueType="libs">
|
||||
<listOptionValue builtIn="false" value=":USBPDCORE_PD3_FULL_CM4_wc32.a"/>
|
||||
</option>
|
||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.input.2021934519" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
@@ -176,6 +236,8 @@
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="USBPD"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
|
||||
52
.mxproject
52
.mxproject
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="684846818429178185" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="425014813477960383" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
@@ -16,7 +16,7 @@
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="684846818429178185" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="425014813477960383" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
||||
34
Core/Inc/alim.h
Normal file
34
Core/Inc/alim.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* alim.h
|
||||
*
|
||||
* Created on: May 11, 2025
|
||||
* Author: allan
|
||||
*/
|
||||
|
||||
#ifndef INC_ALIM_H_
|
||||
#define INC_ALIM_H_
|
||||
|
||||
extern UART_HandleTypeDef huart2;
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
|
||||
typedef enum i2cAdress {
|
||||
I2C_TEMP = 0x18,
|
||||
I2C_IN1 = 0x48,
|
||||
I2C_IN2 = 0x4A,
|
||||
I2C_OUT5V = 0x43,
|
||||
I2C_OUT5V1 = 0x40,
|
||||
I2C_OUT12V = 0x41,
|
||||
I2C_OUT24V = 0x4B
|
||||
} i2cAdress;
|
||||
|
||||
|
||||
// Prototypes
|
||||
HAL_StatusTypeDef read_bau_state(int* val);
|
||||
HAL_StatusTypeDef read_mcp9808_temp(float* val);
|
||||
HAL_StatusTypeDef ina236_write_reg(i2cAdress address, uint8_t reg, uint16_t value);
|
||||
HAL_StatusTypeDef ina236_read_reg(i2cAdress address, uint8_t reg, uint16_t *value);
|
||||
HAL_StatusTypeDef ina236_init(i2cAdress address, float r_shunt, float current_lsb);
|
||||
HAL_StatusTypeDef read_ina236_voltage(i2cAdress address, float *voltage);
|
||||
HAL_StatusTypeDef read_ina236_current(i2cAdress address, float currentLSB, float *current);
|
||||
|
||||
#endif /* INC_ALIM_H_ */
|
||||
20
Core/Inc/comm.h
Normal file
20
Core/Inc/comm.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* comm.h
|
||||
*
|
||||
* Created on: May 12, 2025
|
||||
* Author: allan
|
||||
*/
|
||||
|
||||
#ifndef INC_COMM_H_
|
||||
#define INC_COMM_H_
|
||||
|
||||
#define RX_BUFFER_SIZE 128
|
||||
|
||||
// Prototypes
|
||||
void handle_uart_message(const char *msg);
|
||||
void handle_get(const char *xxx, const char *yyy);
|
||||
void handle_set(const char *xxx, const char *yyy, const char *val);
|
||||
void send_set_response(const char *xxx, const char *yyy, int val);
|
||||
void send_error_response(void);
|
||||
|
||||
#endif /* INC_COMM_H_ */
|
||||
@@ -29,6 +29,18 @@ extern "C" {
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_hal.h"
|
||||
|
||||
#include "stm32g4xx_ll_ucpd.h"
|
||||
#include "stm32g4xx_ll_bus.h"
|
||||
#include "stm32g4xx_ll_cortex.h"
|
||||
#include "stm32g4xx_ll_rcc.h"
|
||||
#include "stm32g4xx_ll_system.h"
|
||||
#include "stm32g4xx_ll_utils.h"
|
||||
#include "stm32g4xx_ll_pwr.h"
|
||||
#include "stm32g4xx_ll_gpio.h"
|
||||
#include "stm32g4xx_ll_dma.h"
|
||||
|
||||
#include "stm32g4xx_ll_exti.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
@@ -59,6 +71,8 @@ void Error_Handler(void);
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define TCPP02_EN_Pin GPIO_PIN_9
|
||||
#define TCPP02_EN_GPIO_Port GPIOA
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
|
||||
53
Core/Inc/stm32_assert.h
Normal file
53
Core/Inc/stm32_assert.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32_assert.h
|
||||
* @author MCD Application Team
|
||||
* @brief STM32 assert file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32_ASSERT_H
|
||||
#define __STM32_ASSERT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t *file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32_ASSERT_H */
|
||||
|
||||
@@ -56,8 +56,11 @@ void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void EXTI1_IRQHandler(void);
|
||||
void DMA1_Channel1_IRQHandler(void);
|
||||
void DMA1_Channel2_IRQHandler(void);
|
||||
void EXTI9_5_IRQHandler(void);
|
||||
void USART2_IRQHandler(void);
|
||||
void UCPD1_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
87
Core/Src/alim.c
Normal file
87
Core/Src/alim.c
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "main.h"
|
||||
#include "alim.h"
|
||||
#include "comm.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
HAL_StatusTypeDef read_bau_state(int* val){
|
||||
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_SET){
|
||||
*val = 0;
|
||||
return HAL_ERROR;
|
||||
} else {
|
||||
*val = 1;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef read_mcp9808_temp(float* temp) {
|
||||
uint8_t reg = 0x05;
|
||||
uint8_t data[2];
|
||||
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, I2C_TEMP << 1, ®, 1, HAL_MAX_DELAY) != HAL_OK){
|
||||
return HAL_ERROR;
|
||||
}
|
||||
if (HAL_I2C_Master_Receive(&hi2c1, I2C_TEMP << 1, data, 2, HAL_MAX_DELAY) != HAL_OK){
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
uint16_t raw = (data[0] << 8) | data[1];
|
||||
raw &= 0x1FFF;
|
||||
|
||||
*temp = raw & 0x1000 ? (raw - 8192) * 0.0625f : raw * 0.0625f;
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef ina236_write_reg(i2cAdress address, uint8_t reg, uint16_t value) {
|
||||
uint8_t data[3];
|
||||
data[0] = reg;
|
||||
data[1] = (value >> 8);
|
||||
data[2] = (value & 0xFF);
|
||||
return HAL_I2C_Master_Transmit(&hi2c1, address << 1, data, 3, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef ina236_read_reg(i2cAdress address, uint8_t reg, uint16_t *value) {
|
||||
uint8_t data[2];
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, address << 1, ®, 1, HAL_MAX_DELAY) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
if (HAL_I2C_Master_Receive(&hi2c1, address << 1, data, 2, HAL_MAX_DELAY) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
|
||||
*value = (data[0] << 8) | data[1];
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef ina236_init(i2cAdress address, float r_shunt, float current_lsb) {
|
||||
uint16_t calibration = (uint16_t)(0.00512 / (r_shunt * current_lsb));
|
||||
if(ina236_write_reg(address, 0x05, calibration) != HAL_OK){
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
uint16_t config = 0x4127; // Exemple: moyenne x4, conversion 1.1ms, mode shunt+bus continuous
|
||||
if(ina236_write_reg(address, 0x00, config) != HAL_OK){
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef read_ina236_voltage(i2cAdress address, float *voltage) {
|
||||
uint16_t raw;
|
||||
if (ina236_read_reg(address, 0x02, &raw) != HAL_OK){
|
||||
return HAL_ERROR;
|
||||
}
|
||||
*voltage = (raw * 1.25f); // 1.25 mV/bit → en mV
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef read_ina236_current(i2cAdress address, float currentLSB, float *current) {
|
||||
uint16_t raw;
|
||||
if (ina236_read_reg(address, 0x04, &raw) != HAL_OK){
|
||||
return HAL_ERROR;
|
||||
}
|
||||
*current = ((int16_t)raw) * currentLSB * 1000; // en mA
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
150
Core/Src/comm.c
150
Core/Src/comm.c
@@ -1,33 +1,17 @@
|
||||
#include "comm.h"
|
||||
#include "main.h"
|
||||
#include "alim.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
extern UART_HandleTypeDef huart2;
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
|
||||
typedef enum errorCode {
|
||||
COMM_SUCCESS,
|
||||
COMM_ERROR
|
||||
} errorCode ;
|
||||
|
||||
#define RX_BUFFER_SIZE 128
|
||||
static char rxBuffer[RX_BUFFER_SIZE];
|
||||
static uint8_t rxIndex = 0;
|
||||
static char rxChar;
|
||||
|
||||
// Prototypes
|
||||
void handle_uart_message(const char *msg);
|
||||
void handle_get(const char *xxx, const char *yyy);
|
||||
void handle_set(const char *xxx, const char *yyy, const char *val);
|
||||
void send_set_response(const char *xxx, const char *yyy, int val);
|
||||
void send_error_response(void);
|
||||
errorCode read_bau_state(int* val);
|
||||
errorCode read_mcp9808_temp(float* val);
|
||||
|
||||
|
||||
// Lancer la réception UART
|
||||
void uart_start_reception() {
|
||||
HAL_UART_Receive_IT(&huart2, (uint8_t *)&rxChar, 1);
|
||||
@@ -71,19 +55,94 @@ void handle_uart_message(const char *msg) {
|
||||
void handle_get(const char *xxx, const char *yyy) {
|
||||
if (strcmp(xxx, "BAU") == 0 && strcmp(yyy, "STATE") == 0) {
|
||||
int val = 0;
|
||||
errorCode res = read_bau_state(&val);
|
||||
if(res == COMM_SUCCESS){
|
||||
HAL_StatusTypeDef res = read_bau_state(&val);
|
||||
if(res == HAL_OK){
|
||||
send_set_response(xxx, yyy, val);
|
||||
return;
|
||||
}
|
||||
} else if (strcmp(xxx, "TEMP") == 0 && strcmp(yyy, "CELS") == 0) {
|
||||
float temp = -1000.0f;
|
||||
errorCode res = read_mcp9808_temp(&temp);
|
||||
if (res == COMM_SUCCESS) {
|
||||
HAL_StatusTypeDef res = read_mcp9808_temp(&temp);
|
||||
if (res == HAL_OK) {
|
||||
int temp_dixieme = (int)(temp * 10.0f + 0.5f);
|
||||
send_set_response(xxx, yyy, temp_dixieme);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Concerne les entrees sorties
|
||||
|
||||
i2cAdress address;
|
||||
float currentLSB;
|
||||
bool validZone = false;
|
||||
uint16_t controlPin;
|
||||
uint16_t validPin;
|
||||
|
||||
// Selection zone mesure
|
||||
if(strcmp(xxx, "IN1") == 0){
|
||||
address = I2C_IN1;
|
||||
currentLSB = 0.000610f;
|
||||
validPin = GPIO_PIN_5;
|
||||
validZone = true;
|
||||
} else if (strcmp(xxx, "IN2") == 0){
|
||||
address = I2C_IN2;
|
||||
currentLSB = 0.000610f;
|
||||
validPin = GPIO_PIN_6;
|
||||
validZone = true;
|
||||
} else if (strcmp(xxx, "OUT5V") == 0){
|
||||
address = I2C_OUT5V;
|
||||
currentLSB = 0.000185f;
|
||||
controlPin = GPIO_PIN_0;
|
||||
validZone = true;
|
||||
} else if (strcmp(xxx, "OUT5V1") == 0){
|
||||
address = I2C_OUT5V1;
|
||||
currentLSB = 0.000185f;
|
||||
validZone = true;
|
||||
} else if (strcmp(xxx, "OUT12V") == 0){
|
||||
address = I2C_OUT12V;
|
||||
currentLSB = 0.000125f;
|
||||
controlPin = GPIO_PIN_10;
|
||||
validZone = true;
|
||||
} else if (strcmp(xxx, "OUT24") == 0){
|
||||
address = I2C_OUT24V;
|
||||
currentLSB = 0.000040f;
|
||||
controlPin = GPIO_PIN_11;
|
||||
validZone = true;
|
||||
}
|
||||
|
||||
// Selection type mesure
|
||||
if(strcmp(yyy, "VOLT") == 0 && validZone){
|
||||
float val = 0.0f;
|
||||
HAL_StatusTypeDef res = read_ina236_voltage(address, &val);
|
||||
if (res == HAL_OK) {
|
||||
send_set_response(xxx, yyy, val);
|
||||
return;
|
||||
}
|
||||
} else if (strcmp(yyy, "AMPS") == 0 && validZone){
|
||||
float val = 0.0f;
|
||||
HAL_StatusTypeDef res = read_ina236_current(address, currentLSB, &val);
|
||||
if (res == HAL_OK) {
|
||||
send_set_response(xxx, yyy, val);
|
||||
return;
|
||||
}
|
||||
} else if (strcmp(yyy, "VALID") == 0 && validZone){
|
||||
int val = 0;
|
||||
if((strcmp(xxx, "IN1") == 0) || (strcmp(xxx, "IN2") == 0)){
|
||||
val = (HAL_GPIO_ReadPin(GPIOA, validPin) == GPIO_PIN_RESET) ? 1 : 0;
|
||||
} else {
|
||||
val = 1;
|
||||
}
|
||||
send_set_response(xxx, yyy, val);
|
||||
return;
|
||||
} else if (strcmp(yyy, "STATE") == 0 && validZone){
|
||||
int val = 0;
|
||||
if((strcmp(xxx, "OUT5V") == 0) || (strcmp(xxx, "OUT12V") == 0) || (strcmp(xxx, "OUT24V") == 0)){
|
||||
val = (HAL_GPIO_ReadPin(GPIOA, controlPin) == GPIO_PIN_RESET) ? 1 : 0;
|
||||
} else {
|
||||
val = 1;
|
||||
}
|
||||
send_set_response(xxx, yyy, val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
send_error_response();
|
||||
}
|
||||
@@ -97,9 +156,20 @@ void handle_set(const char *xxx, const char *yyy, const char *val) {
|
||||
(strcmp(xxx, "OUT12V") == 0 && strcmp(yyy, "STATE") == 0) ||
|
||||
(strcmp(xxx, "OUT24V") == 0 && strcmp(yyy, "STATE") == 0))) {
|
||||
|
||||
// Appliquer commande...
|
||||
GPIO_PinState pin_state = (v == 1) ? GPIO_PIN_RESET : GPIO_PIN_SET; // Niveau actif bas
|
||||
int success = 0;
|
||||
|
||||
if (strcmp(xxx, "OUT5V") == 0 && strcmp(yyy, "STATE") == 0) {
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, pin_state);
|
||||
success = 1;
|
||||
} else if (strcmp(xxx, "OUT12V") == 0 && strcmp(yyy, "STATE") == 0) {
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, pin_state);
|
||||
success = 1;
|
||||
} else if (strcmp(xxx, "OUT24V") == 0 && strcmp(yyy, "STATE") == 0) {
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, pin_state);
|
||||
success = 1;
|
||||
}
|
||||
|
||||
int success = 1;
|
||||
if (success) {
|
||||
char msg[64];
|
||||
snprintf(msg, sizeof(msg), "OK;%s;%s;%d\n", xxx, yyy, v);
|
||||
@@ -124,33 +194,3 @@ void send_error_response() {
|
||||
const char *msg = "KO;PARSE;ERROR;0\n";
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *)msg, strlen(msg), HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
errorCode read_bau_state(int* val){
|
||||
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_SET){
|
||||
*val = 0;
|
||||
return COMM_SUCCESS;
|
||||
} else {
|
||||
*val = 1;
|
||||
return COMM_SUCCESS;
|
||||
}
|
||||
return COMM_ERROR;
|
||||
}
|
||||
|
||||
errorCode read_mcp9808_temp(float* temp) {
|
||||
uint8_t reg = 0x05;
|
||||
uint8_t data[2];
|
||||
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, 0x18 << 1, ®, 1, HAL_MAX_DELAY) != HAL_OK){
|
||||
return COMM_ERROR;
|
||||
}
|
||||
if (HAL_I2C_Master_Receive(&hi2c1, 0x18 << 1, data, 2, HAL_MAX_DELAY) != HAL_OK){
|
||||
return COMM_ERROR;
|
||||
}
|
||||
|
||||
uint16_t raw = (data[0] << 8) | data[1];
|
||||
raw &= 0x1FFF;
|
||||
|
||||
*temp = raw & 0x1000 ? (raw - 8192) * 0.0625f : raw * 0.0625f;
|
||||
return COMM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
142
Core/Src/main.c
142
Core/Src/main.c
@@ -18,9 +18,11 @@
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "usbpd.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "alim.h"
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
|
||||
@@ -53,9 +55,11 @@ UART_HandleTypeDef huart2;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_DMA_Init(void);
|
||||
static void MX_TIM3_Init(void);
|
||||
static void MX_USART2_UART_Init(void);
|
||||
static void MX_I2C1_Init(void);
|
||||
static void MX_UCPD1_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
@@ -94,20 +98,33 @@ int main(void)
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_TIM3_Init();
|
||||
MX_USART2_UART_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_UCPD1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_SET){
|
||||
BAU_State = 0;
|
||||
}else{
|
||||
BAU_State = 1;
|
||||
}
|
||||
|
||||
ina236_init(I2C_IN1, 0.004f, 0.000610f); // Rshunt = 4 mOhm, currentLSB = 610 uA (maxCurrent = 20A)
|
||||
ina236_init(I2C_IN2, 0.004f, 0.000610f); // Rshunt = 4 mOhm, currentLSB = 610 uA (maxCurrent = 20A)
|
||||
ina236_init(I2C_OUT5V, 0.013f, 0.000185f); // Rshunt = 13 mOhm, currentLSB = 185 uA (maxCurrent = 6A)
|
||||
ina236_init(I2C_OUT5V1, 0.013f, 0.000185f); // Rshunt = 13 mOhm, currentLSB = 185 uA (maxCurrent = 6A)
|
||||
ina236_init(I2C_OUT12V, 0.020f, 0.000125f); // Rshunt = 20 mOhm, currentLSB = 305 uA (maxCurrent = 4A)
|
||||
ina236_init(I2C_OUT24V, 0.062f, 0.000040f); // Rshunt = 62 mOhm, currentLSB = 40 uA (maxCurrent = 1A25)
|
||||
|
||||
uart_start_reception();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* USBPD initialisation ---------------------------------*/
|
||||
MX_USBPD_Init();
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
@@ -118,6 +135,7 @@ int main(void)
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
HAL_Delay(500);*/
|
||||
/* USER CODE END WHILE */
|
||||
USBPD_DPM_Run();
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
@@ -277,6 +295,87 @@ static void MX_TIM3_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UCPD1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_UCPD1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN UCPD1_Init 0 */
|
||||
|
||||
/* USER CODE END UCPD1_Init 0 */
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* Peripheral clock enable */
|
||||
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UCPD1);
|
||||
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
|
||||
/**UCPD1 GPIO Configuration
|
||||
PB4 ------> UCPD1_CC2
|
||||
PB6 ------> UCPD1_CC1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_4;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* UCPD1 DMA Init */
|
||||
|
||||
/* UCPD1_RX Init */
|
||||
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_UCPD1_RX);
|
||||
|
||||
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
|
||||
|
||||
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW);
|
||||
|
||||
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_NORMAL);
|
||||
|
||||
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
|
||||
|
||||
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
|
||||
|
||||
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_BYTE);
|
||||
|
||||
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_BYTE);
|
||||
|
||||
/* UCPD1_TX Init */
|
||||
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_2, LL_DMAMUX_REQ_UCPD1_TX);
|
||||
|
||||
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
|
||||
|
||||
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_LOW);
|
||||
|
||||
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MODE_NORMAL);
|
||||
|
||||
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT);
|
||||
|
||||
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT);
|
||||
|
||||
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE);
|
||||
|
||||
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE);
|
||||
|
||||
/* UCPD1 interrupt Init */
|
||||
NVIC_SetPriority(UCPD1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
||||
NVIC_EnableIRQ(UCPD1_IRQn);
|
||||
|
||||
/* USER CODE BEGIN UCPD1_Init 1 */
|
||||
|
||||
/* USER CODE END UCPD1_Init 1 */
|
||||
/* USER CODE BEGIN UCPD1_Init 2 */
|
||||
|
||||
/* USER CODE END UCPD1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART2 Initialization Function
|
||||
* @param None
|
||||
@@ -325,6 +424,26 @@ static void MX_USART2_UART_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA controller clock
|
||||
*/
|
||||
static void MX_DMA_Init(void)
|
||||
{
|
||||
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMAMUX1_CLK_ENABLE();
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||
NVIC_SetPriority(DMA1_Channel1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
||||
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
/* DMA1_Channel2_IRQn interrupt configuration */
|
||||
NVIC_SetPriority(DMA1_Channel2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
||||
NVIC_EnableIRQ(DMA1_Channel2_IRQn);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
@@ -340,6 +459,16 @@ static void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|TCPP02_EN_Pin|GPIO_PIN_10|GPIO_PIN_11, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : PA0 PA10 PA11 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_10|GPIO_PIN_11;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PA1 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
@@ -352,6 +481,19 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : TCPP02_EN_Pin */
|
||||
GPIO_InitStruct.Pin = TCPP02_EN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(TCPP02_EN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PA12 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_12;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PB5 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "stm32g4xx_it.h"
|
||||
#include "usbpd.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE END Includes */
|
||||
@@ -186,6 +187,7 @@ void SysTick_Handler(void)
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
USBPD_DPM_TimerCounter();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
@@ -212,6 +214,32 @@ void EXTI1_IRQHandler(void)
|
||||
/* USER CODE END EXTI1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel1 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel1_IRQn 0 */
|
||||
/* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel2 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel2_IRQn 0 */
|
||||
/* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI line[9:5] interrupts.
|
||||
*/
|
||||
@@ -240,6 +268,21 @@ void USART2_IRQHandler(void)
|
||||
/* USER CODE END USART2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles UCPD1 interrupt / UCPD1 wake-up interrupt through EXTI line 43.
|
||||
*/
|
||||
void UCPD1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UCPD1_IRQn 0 */
|
||||
|
||||
/* USER CODE END UCPD1_IRQn 0 */
|
||||
USBPD_PORT0_IRQHandler();
|
||||
|
||||
/* USER CODE BEGIN UCPD1_IRQn 1 */
|
||||
|
||||
/* USER CODE END UCPD1_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
1874
Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_ll_ucpd.h
Normal file
1874
Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_ll_ucpd.h
Normal file
File diff suppressed because it is too large
Load Diff
376
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_dma.c
Normal file
376
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_dma.c
Normal file
@@ -0,0 +1,376 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32g4xx_ll_dma.c
|
||||
* @author MCD Application Team
|
||||
* @brief DMA LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_ll_dma.h"
|
||||
#include "stm32g4xx_ll_bus.h"
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/** @addtogroup STM32G4xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (DMA1) || defined (DMA2)
|
||||
|
||||
/** @defgroup DMA_LL DMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @addtogroup DMA_LL_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#define IS_LL_DMA_DIRECTION(__VALUE__) (((__VALUE__) == LL_DMA_DIRECTION_PERIPH_TO_MEMORY) || \
|
||||
((__VALUE__) == LL_DMA_DIRECTION_MEMORY_TO_PERIPH) || \
|
||||
((__VALUE__) == LL_DMA_DIRECTION_MEMORY_TO_MEMORY))
|
||||
|
||||
#define IS_LL_DMA_MODE(__VALUE__) (((__VALUE__) == LL_DMA_MODE_NORMAL) || \
|
||||
((__VALUE__) == LL_DMA_MODE_CIRCULAR))
|
||||
|
||||
#define IS_LL_DMA_PERIPHINCMODE(__VALUE__) (((__VALUE__) == LL_DMA_PERIPH_INCREMENT) || \
|
||||
((__VALUE__) == LL_DMA_PERIPH_NOINCREMENT))
|
||||
|
||||
#define IS_LL_DMA_MEMORYINCMODE(__VALUE__) (((__VALUE__) == LL_DMA_MEMORY_INCREMENT) || \
|
||||
((__VALUE__) == LL_DMA_MEMORY_NOINCREMENT))
|
||||
|
||||
#define IS_LL_DMA_PERIPHDATASIZE(__VALUE__) (((__VALUE__) == LL_DMA_PDATAALIGN_BYTE) || \
|
||||
((__VALUE__) == LL_DMA_PDATAALIGN_HALFWORD) || \
|
||||
((__VALUE__) == LL_DMA_PDATAALIGN_WORD))
|
||||
|
||||
#define IS_LL_DMA_MEMORYDATASIZE(__VALUE__) (((__VALUE__) == LL_DMA_MDATAALIGN_BYTE) || \
|
||||
((__VALUE__) == LL_DMA_MDATAALIGN_HALFWORD) || \
|
||||
((__VALUE__) == LL_DMA_MDATAALIGN_WORD))
|
||||
|
||||
#define IS_LL_DMA_NBDATA(__VALUE__) ((__VALUE__) <= (uint32_t)0x0000FFFFU)
|
||||
|
||||
#define IS_LL_DMA_PERIPHREQUEST(__VALUE__) ((__VALUE__) <= 115U)
|
||||
|
||||
#define IS_LL_DMA_PRIORITY(__VALUE__) (((__VALUE__) == LL_DMA_PRIORITY_LOW) || \
|
||||
((__VALUE__) == LL_DMA_PRIORITY_MEDIUM) || \
|
||||
((__VALUE__) == LL_DMA_PRIORITY_HIGH) || \
|
||||
((__VALUE__) == LL_DMA_PRIORITY_VERYHIGH))
|
||||
|
||||
#if defined (DMA1_Channel8)
|
||||
#define IS_LL_DMA_ALL_CHANNEL_INSTANCE(INSTANCE, CHANNEL) ((((INSTANCE) == DMA1) && \
|
||||
(((CHANNEL) == LL_DMA_CHANNEL_1) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_2) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_3) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_4) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_5) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_6) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_7) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_8))) || \
|
||||
(((INSTANCE) == DMA2) && \
|
||||
(((CHANNEL) == LL_DMA_CHANNEL_1) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_2) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_3) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_4) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_5) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_6) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_7) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_8))))
|
||||
#elif defined (DMA1_Channel6)
|
||||
#define IS_LL_DMA_ALL_CHANNEL_INSTANCE(INSTANCE, CHANNEL) ((((INSTANCE) == DMA1) && \
|
||||
(((CHANNEL) == LL_DMA_CHANNEL_1) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_2) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_3) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_4) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_5) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_6))) || \
|
||||
(((INSTANCE) == DMA2) && \
|
||||
(((CHANNEL) == LL_DMA_CHANNEL_1) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_2) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_3) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_4) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_5) || \
|
||||
((CHANNEL) == LL_DMA_CHANNEL_6))))
|
||||
#endif /* DMA1_Channel8 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup DMA_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup DMA_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-initialize the DMA registers to their default reset values.
|
||||
* @param DMAx DMAx Instance
|
||||
* @param Channel This parameter can be one of the following values:
|
||||
* @arg @ref LL_DMA_CHANNEL_1
|
||||
* @arg @ref LL_DMA_CHANNEL_2
|
||||
* @arg @ref LL_DMA_CHANNEL_3
|
||||
* @arg @ref LL_DMA_CHANNEL_4
|
||||
* @arg @ref LL_DMA_CHANNEL_5
|
||||
* @arg @ref LL_DMA_CHANNEL_6
|
||||
* @arg @ref LL_DMA_CHANNEL_7 (*)
|
||||
* @arg @ref LL_DMA_CHANNEL_8 (*)
|
||||
* @arg @ref LL_DMA_CHANNEL_ALL
|
||||
* (*) Not on all G4 devices
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: DMA registers are de-initialized
|
||||
* - ERROR: DMA registers are not de-initialized
|
||||
*/
|
||||
uint32_t LL_DMA_DeInit(DMA_TypeDef *DMAx, uint32_t Channel)
|
||||
{
|
||||
DMA_Channel_TypeDef *tmp;
|
||||
ErrorStatus status = SUCCESS;
|
||||
|
||||
/* Check the DMA Instance DMAx and Channel parameters*/
|
||||
assert_param(IS_LL_DMA_ALL_CHANNEL_INSTANCE(DMAx, Channel) || (Channel == LL_DMA_CHANNEL_ALL));
|
||||
|
||||
if (Channel == LL_DMA_CHANNEL_ALL)
|
||||
{
|
||||
if (DMAx == DMA1)
|
||||
{
|
||||
/* Force reset of DMA clock */
|
||||
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA1);
|
||||
|
||||
/* Release reset of DMA clock */
|
||||
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA1);
|
||||
}
|
||||
else if (DMAx == DMA2)
|
||||
{
|
||||
/* Force reset of DMA clock */
|
||||
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA2);
|
||||
|
||||
/* Release reset of DMA clock */
|
||||
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA2);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (DMA_Channel_TypeDef *)(__LL_DMA_GET_CHANNEL_INSTANCE(DMAx, Channel));
|
||||
|
||||
/* Disable the selected DMAx_Channely */
|
||||
CLEAR_BIT(tmp->CCR, DMA_CCR_EN);
|
||||
|
||||
/* Reset DMAx_Channely control register */
|
||||
WRITE_REG(tmp->CCR, 0U);
|
||||
|
||||
/* Reset DMAx_Channely remaining bytes register */
|
||||
WRITE_REG(tmp->CNDTR, 0U);
|
||||
|
||||
/* Reset DMAx_Channely peripheral address register */
|
||||
WRITE_REG(tmp->CPAR, 0U);
|
||||
|
||||
/* Reset DMAx_Channely memory address register */
|
||||
WRITE_REG(tmp->CMAR, 0U);
|
||||
|
||||
/* Reset Request register field for DMAx Channel */
|
||||
LL_DMA_SetPeriphRequest(DMAx, Channel, LL_DMAMUX_REQ_MEM2MEM);
|
||||
|
||||
if (Channel == LL_DMA_CHANNEL_1)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel1 */
|
||||
LL_DMA_ClearFlag_GI1(DMAx);
|
||||
}
|
||||
else if (Channel == LL_DMA_CHANNEL_2)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel2 */
|
||||
LL_DMA_ClearFlag_GI2(DMAx);
|
||||
}
|
||||
else if (Channel == LL_DMA_CHANNEL_3)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel3 */
|
||||
LL_DMA_ClearFlag_GI3(DMAx);
|
||||
}
|
||||
else if (Channel == LL_DMA_CHANNEL_4)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel4 */
|
||||
LL_DMA_ClearFlag_GI4(DMAx);
|
||||
}
|
||||
else if (Channel == LL_DMA_CHANNEL_5)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel5 */
|
||||
LL_DMA_ClearFlag_GI5(DMAx);
|
||||
}
|
||||
|
||||
else if (Channel == LL_DMA_CHANNEL_6)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel6 */
|
||||
LL_DMA_ClearFlag_GI6(DMAx);
|
||||
}
|
||||
#if defined (DMA1_Channel7)
|
||||
else if (Channel == LL_DMA_CHANNEL_7)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel7 */
|
||||
LL_DMA_ClearFlag_GI7(DMAx);
|
||||
}
|
||||
#endif /* DMA1_Channel7 */
|
||||
#if defined (DMA1_Channel8)
|
||||
else if (Channel == LL_DMA_CHANNEL_8)
|
||||
{
|
||||
/* Reset interrupt pending bits for DMAx Channel8 */
|
||||
LL_DMA_ClearFlag_GI8(DMAx);
|
||||
}
|
||||
#endif /* DMA1_Channel8 */
|
||||
else
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return (uint32_t)status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the DMA registers according to the specified parameters in DMA_InitStruct.
|
||||
* @note To convert DMAx_Channely Instance to DMAx Instance and Channely, use helper macros :
|
||||
* @arg @ref __LL_DMA_GET_INSTANCE
|
||||
* @arg @ref __LL_DMA_GET_CHANNEL
|
||||
* @param DMAx DMAx Instance
|
||||
* @param Channel This parameter can be one of the following values:
|
||||
* @arg @ref LL_DMA_CHANNEL_1
|
||||
* @arg @ref LL_DMA_CHANNEL_2
|
||||
* @arg @ref LL_DMA_CHANNEL_3
|
||||
* @arg @ref LL_DMA_CHANNEL_4
|
||||
* @arg @ref LL_DMA_CHANNEL_5
|
||||
* @arg @ref LL_DMA_CHANNEL_6
|
||||
* @arg @ref LL_DMA_CHANNEL_7 (*)
|
||||
* @arg @ref LL_DMA_CHANNEL_8 (*)
|
||||
* (*) Not on all G4 devices
|
||||
* @param DMA_InitStruct pointer to a @ref LL_DMA_InitTypeDef structure.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: DMA registers are initialized
|
||||
* - ERROR: Not applicable
|
||||
*/
|
||||
uint32_t LL_DMA_Init(DMA_TypeDef *DMAx, uint32_t Channel, LL_DMA_InitTypeDef *DMA_InitStruct)
|
||||
{
|
||||
/* Check the DMA Instance DMAx and Channel parameters*/
|
||||
assert_param(IS_LL_DMA_ALL_CHANNEL_INSTANCE(DMAx, Channel));
|
||||
|
||||
/* Check the DMA parameters from DMA_InitStruct */
|
||||
assert_param(IS_LL_DMA_DIRECTION(DMA_InitStruct->Direction));
|
||||
assert_param(IS_LL_DMA_MODE(DMA_InitStruct->Mode));
|
||||
assert_param(IS_LL_DMA_PERIPHINCMODE(DMA_InitStruct->PeriphOrM2MSrcIncMode));
|
||||
assert_param(IS_LL_DMA_MEMORYINCMODE(DMA_InitStruct->MemoryOrM2MDstIncMode));
|
||||
assert_param(IS_LL_DMA_PERIPHDATASIZE(DMA_InitStruct->PeriphOrM2MSrcDataSize));
|
||||
assert_param(IS_LL_DMA_MEMORYDATASIZE(DMA_InitStruct->MemoryOrM2MDstDataSize));
|
||||
assert_param(IS_LL_DMA_NBDATA(DMA_InitStruct->NbData));
|
||||
assert_param(IS_LL_DMA_PERIPHREQUEST(DMA_InitStruct->PeriphRequest));
|
||||
assert_param(IS_LL_DMA_PRIORITY(DMA_InitStruct->Priority));
|
||||
|
||||
/*---------------------------- DMAx CCR Configuration ------------------------
|
||||
* Configure DMAx_Channely: data transfer direction, data transfer mode,
|
||||
* peripheral and memory increment mode,
|
||||
* data size alignment and priority level with parameters :
|
||||
* - Direction: DMA_CCR_DIR and DMA_CCR_MEM2MEM bits
|
||||
* - Mode: DMA_CCR_CIRC bit
|
||||
* - PeriphOrM2MSrcIncMode: DMA_CCR_PINC bit
|
||||
* - MemoryOrM2MDstIncMode: DMA_CCR_MINC bit
|
||||
* - PeriphOrM2MSrcDataSize: DMA_CCR_PSIZE[1:0] bits
|
||||
* - MemoryOrM2MDstDataSize: DMA_CCR_MSIZE[1:0] bits
|
||||
* - Priority: DMA_CCR_PL[1:0] bits
|
||||
*/
|
||||
LL_DMA_ConfigTransfer(DMAx, Channel, DMA_InitStruct->Direction | \
|
||||
DMA_InitStruct->Mode | \
|
||||
DMA_InitStruct->PeriphOrM2MSrcIncMode | \
|
||||
DMA_InitStruct->MemoryOrM2MDstIncMode | \
|
||||
DMA_InitStruct->PeriphOrM2MSrcDataSize | \
|
||||
DMA_InitStruct->MemoryOrM2MDstDataSize | \
|
||||
DMA_InitStruct->Priority);
|
||||
|
||||
/*-------------------------- DMAx CMAR Configuration -------------------------
|
||||
* Configure the memory or destination base address with parameter :
|
||||
* - MemoryOrM2MDstAddress: DMA_CMAR_MA[31:0] bits
|
||||
*/
|
||||
LL_DMA_SetMemoryAddress(DMAx, Channel, DMA_InitStruct->MemoryOrM2MDstAddress);
|
||||
|
||||
/*-------------------------- DMAx CPAR Configuration -------------------------
|
||||
* Configure the peripheral or source base address with parameter :
|
||||
* - PeriphOrM2MSrcAddress: DMA_CPAR_PA[31:0] bits
|
||||
*/
|
||||
LL_DMA_SetPeriphAddress(DMAx, Channel, DMA_InitStruct->PeriphOrM2MSrcAddress);
|
||||
|
||||
/*--------------------------- DMAx CNDTR Configuration -----------------------
|
||||
* Configure the peripheral base address with parameter :
|
||||
* - NbData: DMA_CNDTR_NDT[15:0] bits
|
||||
*/
|
||||
LL_DMA_SetDataLength(DMAx, Channel, DMA_InitStruct->NbData);
|
||||
|
||||
/*--------------------------- DMAMUXx CCR Configuration ----------------------
|
||||
* Configure the DMA request for DMA Channels on DMAMUX Channel x with parameter :
|
||||
* - PeriphRequest: DMA_CxCR[7:0] bits
|
||||
*/
|
||||
LL_DMA_SetPeriphRequest(DMAx, Channel, DMA_InitStruct->PeriphRequest);
|
||||
|
||||
return (uint32_t)SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_DMA_InitTypeDef field to default value.
|
||||
* @param DMA_InitStruct Pointer to a @ref LL_DMA_InitTypeDef structure.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_DMA_StructInit(LL_DMA_InitTypeDef *DMA_InitStruct)
|
||||
{
|
||||
/* Set DMA_InitStruct fields to default values */
|
||||
DMA_InitStruct->PeriphOrM2MSrcAddress = (uint32_t)0x00000000U;
|
||||
DMA_InitStruct->MemoryOrM2MDstAddress = (uint32_t)0x00000000U;
|
||||
DMA_InitStruct->Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY;
|
||||
DMA_InitStruct->Mode = LL_DMA_MODE_NORMAL;
|
||||
DMA_InitStruct->PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
||||
DMA_InitStruct->MemoryOrM2MDstIncMode = LL_DMA_MEMORY_NOINCREMENT;
|
||||
DMA_InitStruct->PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_BYTE;
|
||||
DMA_InitStruct->MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_BYTE;
|
||||
DMA_InitStruct->NbData = (uint32_t)0x00000000U;
|
||||
DMA_InitStruct->PeriphRequest = LL_DMAMUX_REQ_MEM2MEM;
|
||||
DMA_InitStruct->Priority = LL_DMA_PRIORITY_LOW;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* DMA1 || DMA2 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
||||
|
||||
296
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_exti.c
Normal file
296
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_exti.c
Normal file
@@ -0,0 +1,296 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32g4xx_ll_exti.c
|
||||
* @author MCD Application Team
|
||||
* @brief EXTI LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_ll_exti.h"
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/** @addtogroup STM32G4xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (EXTI)
|
||||
|
||||
/** @defgroup EXTI_LL EXTI
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @addtogroup EXTI_LL_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
|
||||
#define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
|
||||
|
||||
#define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
|
||||
|| ((__VALUE__) == LL_EXTI_MODE_EVENT) \
|
||||
|| ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
|
||||
|
||||
|
||||
#define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
|
||||
|| ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
|
||||
|| ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
|
||||
|| ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup EXTI_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup EXTI_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-initialize the EXTI registers to their default reset values.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - 0x00: EXTI registers are de-initialized
|
||||
*/
|
||||
uint32_t LL_EXTI_DeInit(void)
|
||||
{
|
||||
/* Interrupt mask register set to default reset values */
|
||||
LL_EXTI_WriteReg(IMR1, 0x1F840000U);
|
||||
/* Event mask register set to default reset values */
|
||||
LL_EXTI_WriteReg(EMR1, 0x00000000U);
|
||||
/* Rising Trigger selection register set to default reset values */
|
||||
LL_EXTI_WriteReg(RTSR1, 0x00000000U);
|
||||
/* Falling Trigger selection register set to default reset values */
|
||||
LL_EXTI_WriteReg(FTSR1, 0x00000000U);
|
||||
/* Software interrupt event register set to default reset values */
|
||||
LL_EXTI_WriteReg(SWIER1, 0x00000000U);
|
||||
/* Pending register clear */
|
||||
LL_EXTI_WriteReg(PR1, 0x007DFFFFU);
|
||||
|
||||
/* Interrupt mask register 2 set to default reset values */
|
||||
#if defined(LL_EXTI_LINE_32) && defined(LL_EXTI_LINE_33) && defined(LL_EXTI_LINE_35) && defined(LL_EXTI_LINE_42)
|
||||
LL_EXTI_WriteReg(IMR2, 0x0000043CU);
|
||||
#else
|
||||
LL_EXTI_WriteReg(IMR2, 0x00000034U);
|
||||
#endif /* LL_EXTI_LINE_xx */
|
||||
/* Event mask register 2 set to default reset values */
|
||||
LL_EXTI_WriteReg(EMR2, 0x00000000U);
|
||||
/* Rising Trigger selection register 2 set to default reset values */
|
||||
LL_EXTI_WriteReg(RTSR2, 0x00000000U);
|
||||
/* Falling Trigger selection register 2 set to default reset values */
|
||||
LL_EXTI_WriteReg(FTSR2, 0x00000000U);
|
||||
/* Software interrupt event register 2 set to default reset values */
|
||||
LL_EXTI_WriteReg(SWIER2, 0x00000000U);
|
||||
/* Pending register 2 clear */
|
||||
LL_EXTI_WriteReg(PR2, 0x00000078U);
|
||||
|
||||
return 0x00u;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
|
||||
* @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - 0x00: EXTI registers are initialized
|
||||
* - any other value : wrong configuration
|
||||
*/
|
||||
uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
|
||||
{
|
||||
uint32_t status = 0x00u;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
|
||||
assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
|
||||
assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
|
||||
assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
|
||||
|
||||
/* ENABLE LineCommand */
|
||||
if (EXTI_InitStruct->LineCommand != DISABLE)
|
||||
{
|
||||
assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
|
||||
|
||||
/* Configure EXTI Lines in range from 0 to 31 */
|
||||
if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
|
||||
{
|
||||
switch (EXTI_InitStruct->Mode)
|
||||
{
|
||||
case LL_EXTI_MODE_IT:
|
||||
/* First Disable Event on provided Lines */
|
||||
LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
|
||||
/* Then Enable IT on provided Lines */
|
||||
LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
|
||||
break;
|
||||
case LL_EXTI_MODE_EVENT:
|
||||
/* First Disable IT on provided Lines */
|
||||
LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
|
||||
/* Then Enable Event on provided Lines */
|
||||
LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
|
||||
break;
|
||||
case LL_EXTI_MODE_IT_EVENT:
|
||||
/* Directly Enable IT on provided Lines */
|
||||
LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
|
||||
/* Directly Enable Event on provided Lines */
|
||||
LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
|
||||
break;
|
||||
default:
|
||||
status = 0x01u;
|
||||
break;
|
||||
}
|
||||
if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
|
||||
{
|
||||
switch (EXTI_InitStruct->Trigger)
|
||||
{
|
||||
case LL_EXTI_TRIGGER_RISING:
|
||||
/* First Disable Falling Trigger on provided Lines */
|
||||
LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
||||
/* Then Enable Rising Trigger on provided Lines */
|
||||
LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
||||
break;
|
||||
case LL_EXTI_TRIGGER_FALLING:
|
||||
/* First Disable Rising Trigger on provided Lines */
|
||||
LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
||||
/* Then Enable Falling Trigger on provided Lines */
|
||||
LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
||||
break;
|
||||
case LL_EXTI_TRIGGER_RISING_FALLING:
|
||||
/* Enable Rising Trigger on provided Lines */
|
||||
LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
||||
/* Enable Falling Trigger on provided Lines */
|
||||
LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
||||
break;
|
||||
default:
|
||||
status |= 0x02u;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Configure EXTI Lines in range from 32 to 63 */
|
||||
if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
|
||||
{
|
||||
switch (EXTI_InitStruct->Mode)
|
||||
{
|
||||
case LL_EXTI_MODE_IT:
|
||||
/* First Disable Event on provided Lines */
|
||||
LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
|
||||
/* Then Enable IT on provided Lines */
|
||||
LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
|
||||
break;
|
||||
case LL_EXTI_MODE_EVENT:
|
||||
/* First Disable IT on provided Lines */
|
||||
LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
|
||||
/* Then Enable Event on provided Lines */
|
||||
LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
|
||||
break;
|
||||
case LL_EXTI_MODE_IT_EVENT:
|
||||
/* Directly Enable IT on provided Lines */
|
||||
LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
|
||||
/* Directly Enable IT on provided Lines */
|
||||
LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
|
||||
break;
|
||||
default:
|
||||
status |= 0x04u;
|
||||
break;
|
||||
}
|
||||
if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
|
||||
{
|
||||
switch (EXTI_InitStruct->Trigger)
|
||||
{
|
||||
case LL_EXTI_TRIGGER_RISING:
|
||||
/* First Disable Falling Trigger on provided Lines */
|
||||
LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
|
||||
/* Then Enable IT on provided Lines */
|
||||
LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
|
||||
break;
|
||||
case LL_EXTI_TRIGGER_FALLING:
|
||||
/* First Disable Rising Trigger on provided Lines */
|
||||
LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
|
||||
/* Then Enable Falling Trigger on provided Lines */
|
||||
LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
|
||||
break;
|
||||
case LL_EXTI_TRIGGER_RISING_FALLING:
|
||||
/* Enable Rising Trigger on provided Lines */
|
||||
LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
|
||||
/* Enable Falling Trigger on provided Lines */
|
||||
LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
|
||||
break;
|
||||
default:
|
||||
status |= 0x05u;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* DISABLE LineCommand */
|
||||
else
|
||||
{
|
||||
/* De-configure IT EXTI Lines in range from 0 to 31 */
|
||||
LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
|
||||
/* De-configure Event EXTI Lines in range from 0 to 31 */
|
||||
LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
|
||||
/* De-configure IT EXTI Lines in range from 32 to 63 */
|
||||
LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
|
||||
/* De-configure Event EXTI Lines in range from 32 to 63 */
|
||||
LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
|
||||
* @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
|
||||
{
|
||||
EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
|
||||
EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
|
||||
EXTI_InitStruct->LineCommand = DISABLE;
|
||||
EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
|
||||
EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* defined (EXTI) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
||||
|
||||
270
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_gpio.c
Normal file
270
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_gpio.c
Normal file
@@ -0,0 +1,270 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32g4xx_ll_gpio.c
|
||||
* @author MCD Application Team
|
||||
* @brief GPIO LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_ll_gpio.h"
|
||||
#include "stm32g4xx_ll_bus.h"
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/** @addtogroup STM32G4xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG)
|
||||
|
||||
/** @addtogroup GPIO_LL
|
||||
* @{
|
||||
*/
|
||||
/** MISRA C:2012 deviation rule has been granted for following rules:
|
||||
* Rule-12.2 - Medium: RHS argument is in interval [0,INF] which is out of
|
||||
* range of the shift operator in following API :
|
||||
* LL_GPIO_Init
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @addtogroup GPIO_LL_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
|
||||
|
||||
#define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
|
||||
((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
|
||||
((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
|
||||
((__VALUE__) == LL_GPIO_MODE_ANALOG))
|
||||
|
||||
#define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
|
||||
((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
|
||||
|
||||
#define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
|
||||
((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
|
||||
((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
|
||||
((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
|
||||
|
||||
#define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
|
||||
((__VALUE__) == LL_GPIO_PULL_UP) ||\
|
||||
((__VALUE__) == LL_GPIO_PULL_DOWN))
|
||||
|
||||
#define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_1 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_2 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_3 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_4 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_5 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_6 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_7 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_8 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_9 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_10 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_11 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_12 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_13 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_14 ) ||\
|
||||
((__VALUE__) == LL_GPIO_AF_15 ))
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup GPIO_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup GPIO_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-initialize GPIO registers (Registers restored to their default values).
|
||||
* @param GPIOx GPIO Port
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: GPIO registers are de-initialized
|
||||
* - ERROR: Wrong GPIO Port
|
||||
*/
|
||||
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
ErrorStatus status = SUCCESS;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
|
||||
/* Force and Release reset on clock of GPIOx Port */
|
||||
if (GPIOx == GPIOA)
|
||||
{
|
||||
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOA);
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOA);
|
||||
}
|
||||
else if (GPIOx == GPIOB)
|
||||
{
|
||||
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOB);
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOB);
|
||||
}
|
||||
else if (GPIOx == GPIOC)
|
||||
{
|
||||
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOC);
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOC);
|
||||
}
|
||||
else if (GPIOx == GPIOD)
|
||||
{
|
||||
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOD);
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOD);
|
||||
}
|
||||
else if (GPIOx == GPIOE)
|
||||
{
|
||||
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOE);
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOE);
|
||||
}
|
||||
else if (GPIOx == GPIOF)
|
||||
{
|
||||
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOF);
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOF);
|
||||
}
|
||||
else if (GPIOx == GPIOG)
|
||||
{
|
||||
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOG);
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOG);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
|
||||
* @param GPIOx GPIO Port
|
||||
* @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
|
||||
* that contains the configuration information for the specified GPIO peripheral.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
|
||||
* - ERROR: Not applicable
|
||||
*/
|
||||
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
|
||||
{
|
||||
uint32_t pinpos;
|
||||
uint32_t currentpin;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
||||
assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
|
||||
assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
|
||||
assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
|
||||
|
||||
/* ------------------------- Configure the port pins ---------------- */
|
||||
/* Initialize pinpos on first pin set */
|
||||
pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
|
||||
|
||||
/* Configure the port pins */
|
||||
while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
|
||||
{
|
||||
/* Get current io position */
|
||||
currentpin = (GPIO_InitStruct->Pin) & (0x00000001UL << pinpos);
|
||||
|
||||
if (currentpin != 0x00u)
|
||||
{
|
||||
if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
|
||||
{
|
||||
/* Check Speed mode parameters */
|
||||
assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
|
||||
|
||||
/* Speed mode configuration */
|
||||
LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
|
||||
|
||||
/* Check Output mode parameters */
|
||||
assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
|
||||
|
||||
/* Output mode configuration*/
|
||||
LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
|
||||
}
|
||||
|
||||
/* Pull-up Pull down resistor configuration*/
|
||||
LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
|
||||
|
||||
if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
|
||||
{
|
||||
/* Check Alternate parameter */
|
||||
assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
|
||||
|
||||
/* Speed mode configuration */
|
||||
if (currentpin < LL_GPIO_PIN_8)
|
||||
{
|
||||
LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
|
||||
}
|
||||
}
|
||||
|
||||
/* Pin Mode configuration */
|
||||
LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
|
||||
}
|
||||
pinpos++;
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
|
||||
* @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
|
||||
* whose fields will be set to default values.
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
|
||||
{
|
||||
/* Reset GPIO init structure parameters values */
|
||||
GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
|
||||
GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
|
||||
GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
||||
|
||||
83
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_pwr.c
Normal file
83
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_pwr.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32g4xx_ll_pwr.c
|
||||
* @author MCD Application Team
|
||||
* @brief PWR LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_ll_pwr.h"
|
||||
#include "stm32g4xx_ll_bus.h"
|
||||
|
||||
/** @addtogroup STM32G4xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(PWR)
|
||||
|
||||
/** @defgroup PWR_LL PWR
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup PWR_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup PWR_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-initialize the PWR registers to their default reset values.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: PWR registers are de-initialized
|
||||
* - ERROR: not applicable
|
||||
*/
|
||||
ErrorStatus LL_PWR_DeInit(void)
|
||||
{
|
||||
/* Force reset of PWR clock */
|
||||
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_PWR);
|
||||
|
||||
/* Release reset of PWR clock */
|
||||
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_PWR);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* defined(PWR) */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
||||
|
||||
1382
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_tim.c
Normal file
1382
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_tim.c
Normal file
File diff suppressed because it is too large
Load Diff
169
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_ucpd.c
Normal file
169
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_ucpd.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32g4xx_ll_ucpd.c
|
||||
* @author MCD Application Team
|
||||
* @brief UCPD LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#if defined(USE_FULL_LL_DRIVER)
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_ll_ucpd.h"
|
||||
#include "stm32g4xx_ll_bus.h"
|
||||
#include "stm32g4xx_ll_rcc.h"
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/** @addtogroup STM32G4xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
#if defined (UCPD1)
|
||||
/** @addtogroup UCPD_LL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @defgroup UCPD_LL_Private_Constants UCPD Private Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @defgroup UCPD_LL_Private_Macros UCPD Private Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup UCPD_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup UCPD_LL_EF_Init
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief De-initialize the UCPD registers to their default reset values.
|
||||
* @param UCPDx ucpd Instance
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: ucpd registers are de-initialized
|
||||
* - ERROR: ucpd registers are not de-initialized
|
||||
*/
|
||||
ErrorStatus LL_UCPD_DeInit(UCPD_TypeDef *UCPDx)
|
||||
{
|
||||
ErrorStatus status = ERROR;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
|
||||
|
||||
LL_UCPD_Disable(UCPDx);
|
||||
|
||||
if (UCPD1 == UCPDx)
|
||||
{
|
||||
/* Force reset of ucpd clock */
|
||||
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_UCPD1);
|
||||
|
||||
/* Release reset of ucpd clock */
|
||||
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_UCPD1);
|
||||
|
||||
/* Disable ucpd clock */
|
||||
LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_UCPD1);
|
||||
|
||||
status = SUCCESS;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct.
|
||||
* @note As some bits in ucpd configuration registers can only be written when the ucpd is disabled
|
||||
* (ucpd_CR1_SPE bit =0), UCPD peripheral should be in disabled state prior calling this function.
|
||||
* Otherwise, ERROR result will be returned.
|
||||
* @param UCPDx UCPD Instance
|
||||
* @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure that contains
|
||||
* the configuration information for the UCPD peripheral.
|
||||
* @retval An ErrorStatus enumeration value. (Return always SUCCESS)
|
||||
*/
|
||||
ErrorStatus LL_UCPD_Init(UCPD_TypeDef *UCPDx, const LL_UCPD_InitTypeDef *UCPD_InitStruct)
|
||||
{
|
||||
/* Check the ucpd Instance UCPDx*/
|
||||
assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
|
||||
|
||||
if (UCPD1 == UCPDx)
|
||||
{
|
||||
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UCPD1);
|
||||
}
|
||||
|
||||
|
||||
LL_UCPD_Disable(UCPDx);
|
||||
|
||||
/*---------------------------- UCPDx CFG1 Configuration ------------------------*/
|
||||
MODIFY_REG(UCPDx->CFG1,
|
||||
UCPD_CFG1_PSC_UCPDCLK | UCPD_CFG1_TRANSWIN | UCPD_CFG1_IFRGAP | UCPD_CFG1_HBITCLKDIV,
|
||||
UCPD_InitStruct->psc_ucpdclk | (UCPD_InitStruct->transwin << UCPD_CFG1_TRANSWIN_Pos) |
|
||||
(UCPD_InitStruct->IfrGap << UCPD_CFG1_IFRGAP_Pos) | UCPD_InitStruct->HbitClockDiv);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set each @ref LL_UCPD_InitTypeDef field to default value.
|
||||
* @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure
|
||||
* whose fields will be set to default values.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_UCPD_StructInit(LL_UCPD_InitTypeDef *UCPD_InitStruct)
|
||||
{
|
||||
/* Set UCPD_InitStruct fields to default values */
|
||||
UCPD_InitStruct->psc_ucpdclk = LL_UCPD_PSC_DIV2;
|
||||
UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */
|
||||
UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */
|
||||
UCPD_InitStruct->HbitClockDiv = 0x0D; /* Divide by 14 to produce HBITCLK */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* defined (UCPD1) */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USE_FULL_LL_DRIVER */
|
||||
|
||||
708
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.c
Normal file
708
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.c
Normal file
@@ -0,0 +1,708 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32g4xx_ll_utils.c
|
||||
* @author MCD Application Team
|
||||
* @brief UTILS LL module driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_ll_utils.h"
|
||||
#include "stm32g4xx_ll_rcc.h"
|
||||
#include "stm32g4xx_ll_system.h"
|
||||
#include "stm32g4xx_ll_pwr.h"
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#include "stm32_assert.h"
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/** @addtogroup STM32G4xx_LL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup UTILS_LL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private types -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup UTILS_LL_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
#define UTILS_MAX_FREQUENCY_SCALE1 170000000U /*!< Maximum frequency for system clock at power scale1, in Hz */
|
||||
#define UTILS_MAX_FREQUENCY_SCALE2 26000000U /*!< Maximum frequency for system clock at power scale2, in Hz */
|
||||
|
||||
/* Defines used for PLL range */
|
||||
#define UTILS_PLLVCO_INPUT_MIN 2660000U /*!< Frequency min for PLLVCO input, in Hz */
|
||||
#define UTILS_PLLVCO_INPUT_MAX 16000000U /*!< Frequency max for PLLVCO input, in Hz */
|
||||
#define UTILS_PLLVCO_OUTPUT_MIN 64000000U /*!< Frequency min for PLLVCO output, in Hz */
|
||||
#define UTILS_PLLVCO_OUTPUT_MAX 344000000U /*!< Frequency max for PLLVCO output, in Hz */
|
||||
|
||||
/* Defines used for HSE range */
|
||||
#define UTILS_HSE_FREQUENCY_MIN 4000000U /*!< Frequency min for HSE frequency, in Hz */
|
||||
#define UTILS_HSE_FREQUENCY_MAX 48000000U /*!< Frequency max for HSE frequency, in Hz */
|
||||
|
||||
/* Defines used for FLASH latency according to HCLK Frequency */
|
||||
#define UTILS_SCALE1_LATENCY1_BOOST_FREQ 34000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 1 */
|
||||
#define UTILS_SCALE1_LATENCY2_BOOST_FREQ 68000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 1 */
|
||||
#define UTILS_SCALE1_LATENCY3_BOOST_FREQ 102000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 1 */
|
||||
#define UTILS_SCALE1_LATENCY4_BOOST_FREQ 136000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 1 */
|
||||
#define UTILS_SCALE1_LATENCY5_BOOST_FREQ 170000000U /*!< HCLK frequency to set FLASH latency 5 in power scale 1 */
|
||||
|
||||
#define UTILS_SCALE1_LATENCY1_FREQ 30000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 1 normal mode */
|
||||
#define UTILS_SCALE1_LATENCY2_FREQ 60000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 1 normal mode */
|
||||
#define UTILS_SCALE1_LATENCY3_FREQ 90000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 1 normal mode */
|
||||
#define UTILS_SCALE1_LATENCY4_FREQ 120000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 1 normal mode */
|
||||
#define UTILS_SCALE1_LATENCY5_FREQ 150000000U /*!< HCLK frequency to set FLASH latency 5 in power scale 1 normal mode */
|
||||
|
||||
#define UTILS_SCALE2_LATENCY1_FREQ 12000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 2 */
|
||||
#define UTILS_SCALE2_LATENCY2_FREQ 24000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 2 */
|
||||
#define UTILS_SCALE2_LATENCY3_FREQ 26000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 2 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @addtogroup UTILS_LL_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#define IS_LL_UTILS_SYSCLK_DIV(__VALUE__) (((__VALUE__) == LL_RCC_SYSCLK_DIV_1) \
|
||||
|| ((__VALUE__) == LL_RCC_SYSCLK_DIV_2) \
|
||||
|| ((__VALUE__) == LL_RCC_SYSCLK_DIV_4) \
|
||||
|| ((__VALUE__) == LL_RCC_SYSCLK_DIV_8) \
|
||||
|| ((__VALUE__) == LL_RCC_SYSCLK_DIV_16) \
|
||||
|| ((__VALUE__) == LL_RCC_SYSCLK_DIV_64) \
|
||||
|| ((__VALUE__) == LL_RCC_SYSCLK_DIV_128) \
|
||||
|| ((__VALUE__) == LL_RCC_SYSCLK_DIV_256) \
|
||||
|| ((__VALUE__) == LL_RCC_SYSCLK_DIV_512))
|
||||
|
||||
#define IS_LL_UTILS_APB1_DIV(__VALUE__) (((__VALUE__) == LL_RCC_APB1_DIV_1) \
|
||||
|| ((__VALUE__) == LL_RCC_APB1_DIV_2) \
|
||||
|| ((__VALUE__) == LL_RCC_APB1_DIV_4) \
|
||||
|| ((__VALUE__) == LL_RCC_APB1_DIV_8) \
|
||||
|| ((__VALUE__) == LL_RCC_APB1_DIV_16))
|
||||
|
||||
#define IS_LL_UTILS_APB2_DIV(__VALUE__) (((__VALUE__) == LL_RCC_APB2_DIV_1) \
|
||||
|| ((__VALUE__) == LL_RCC_APB2_DIV_2) \
|
||||
|| ((__VALUE__) == LL_RCC_APB2_DIV_4) \
|
||||
|| ((__VALUE__) == LL_RCC_APB2_DIV_8) \
|
||||
|| ((__VALUE__) == LL_RCC_APB2_DIV_16))
|
||||
|
||||
#define IS_LL_UTILS_PLLM_VALUE(__VALUE__) (((__VALUE__) == LL_RCC_PLLM_DIV_1) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_2) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_3) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_4) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_5) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_6) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_7) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_8) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_9) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_10) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_11) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_12) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_13) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_14) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_15) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLM_DIV_16))
|
||||
|
||||
#define IS_LL_UTILS_PLLN_VALUE(__VALUE__) ((8U <= (__VALUE__)) && ((__VALUE__) <= 127U))
|
||||
|
||||
#define IS_LL_UTILS_PLLR_VALUE(__VALUE__) (((__VALUE__) == LL_RCC_PLLR_DIV_2) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLR_DIV_4) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLR_DIV_6) \
|
||||
|| ((__VALUE__) == LL_RCC_PLLR_DIV_8))
|
||||
|
||||
#define IS_LL_UTILS_PLLVCO_INPUT(__VALUE__) ((UTILS_PLLVCO_INPUT_MIN <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_INPUT_MAX))
|
||||
|
||||
#define IS_LL_UTILS_PLLVCO_OUTPUT(__VALUE__) ((UTILS_PLLVCO_OUTPUT_MIN <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_OUTPUT_MAX))
|
||||
|
||||
#define IS_LL_UTILS_PLL_FREQUENCY(__VALUE__) ((LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE1) ? ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE1) : \
|
||||
((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE2))
|
||||
|
||||
#define IS_LL_UTILS_HSE_BYPASS(__STATE__) (((__STATE__) == LL_UTILS_HSEBYPASS_ON) \
|
||||
|| ((__STATE__) == LL_UTILS_HSEBYPASS_OFF))
|
||||
|
||||
#define IS_LL_UTILS_HSE_FREQUENCY(__FREQUENCY__) (((__FREQUENCY__) >= UTILS_HSE_FREQUENCY_MIN) && ((__FREQUENCY__) <= UTILS_HSE_FREQUENCY_MAX))
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @defgroup UTILS_LL_Private_Functions UTILS Private functions
|
||||
* @{
|
||||
*/
|
||||
static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency,
|
||||
LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct);
|
||||
static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
|
||||
static ErrorStatus UTILS_PLL_IsBusy(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup UTILS_LL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup UTILS_LL_EF_DELAY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the Cortex-M SysTick source to have 1ms time base.
|
||||
* @note When a RTOS is used, it is recommended to avoid changing the Systick
|
||||
* configuration by calling this function, for a delay use rather osDelay RTOS service.
|
||||
* @param HCLKFrequency HCLK frequency in Hz
|
||||
* @note HCLK frequency can be calculated thanks to RCC helper macro or function @ref LL_RCC_GetSystemClocksFreq
|
||||
* @retval None
|
||||
*/
|
||||
void LL_Init1msTick(uint32_t HCLKFrequency)
|
||||
{
|
||||
/* Use frequency provided in argument */
|
||||
LL_InitTick(HCLKFrequency, 1000U);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function provides accurate delay (in milliseconds) based
|
||||
* on SysTick counter flag
|
||||
* @note When a RTOS is used, it is recommended to avoid using blocking delay
|
||||
* and use rather osDelay service.
|
||||
* @note To respect 1ms timebase, user should call @ref LL_Init1msTick function which
|
||||
* will configure Systick to 1ms
|
||||
* @param Delay specifies the delay time length, in milliseconds.
|
||||
* @retval None
|
||||
*/
|
||||
void LL_mDelay(uint32_t Delay)
|
||||
{
|
||||
__IO uint32_t tmp = SysTick->CTRL; /* Clear the COUNTFLAG first */
|
||||
uint32_t tmpDelay; /* MISRAC2012-Rule-17.8 */
|
||||
/* Add this code to indicate that local variable is not used */
|
||||
((void)tmp);
|
||||
tmpDelay = Delay;
|
||||
/* Add a period to guaranty minimum wait */
|
||||
if(tmpDelay < LL_MAX_DELAY)
|
||||
{
|
||||
tmpDelay++;
|
||||
}
|
||||
|
||||
while (tmpDelay != 0U)
|
||||
{
|
||||
if((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) != 0U)
|
||||
{
|
||||
tmpDelay--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup UTILS_EF_SYSTEM
|
||||
* @brief System Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### System Configuration functions #####
|
||||
===============================================================================
|
||||
[..]
|
||||
System, AHB and APB buses clocks configuration
|
||||
|
||||
(+) The maximum frequency of the SYSCLK, HCLK, PCLK1 and PCLK2 is
|
||||
170000000 Hz for STM32G4xx.
|
||||
@endverbatim
|
||||
@internal
|
||||
Depending on the device voltage range, the maximum frequency should be
|
||||
adapted accordingly:
|
||||
|
||||
+----------------------------------------------------------------------------+
|
||||
| Latency | HCLK clock frequency (MHz) |
|
||||
| |----------------------------------------------------------|
|
||||
| | voltage range 1 | voltage range 1 | voltage range 2 |
|
||||
| | boost mode 1.28 V | normal mode 1.2 V | 1.0 V |
|
||||
|-----------------|-------------------|-------------------|------------------|
|
||||
|0WS(1 CPU cycles)| HCLK <= 34 | HCLK <= 30 | HCLK <= 12 |
|
||||
|-----------------|-------------------|-------------------|------------------|
|
||||
|1WS(2 CPU cycles)| HCLK <= 68 | HCLK <= 60 | HCLK <= 24 |
|
||||
|-----------------|-------------------|-------------------|------------------|
|
||||
|2WS(3 CPU cycles)| HCLK <= 102 | HCLK <= 90 | HCLK <= 26 |
|
||||
|-----------------|-------------------|-------------------|------------------|
|
||||
|3WS(4 CPU cycles)| HCLK <= 136 | HCLK <= 120 | - |
|
||||
|-----------------|-------------------|-------------------|------------------|
|
||||
|4WS(5 CPU cycles)| HCLK <= 170 | HCLK <= 150 | - |
|
||||
+----------------------------------------------------------------------------+
|
||||
|
||||
|
||||
@endinternal
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function sets directly SystemCoreClock CMSIS variable.
|
||||
* @note Variable can be calculated also through SystemCoreClockUpdate function.
|
||||
* @param HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
|
||||
* @retval None
|
||||
*/
|
||||
void LL_SetSystemCoreClock(uint32_t HCLKFrequency)
|
||||
{
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock = HCLKFrequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update number of Flash wait states in line with new frequency and current
|
||||
voltage range.
|
||||
* @param HCLKFrequency HCLK frequency
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: Latency has been modified
|
||||
* - ERROR: Latency cannot be modified
|
||||
*/
|
||||
ErrorStatus LL_SetFlashLatency(uint32_t HCLKFrequency)
|
||||
{
|
||||
uint32_t timeout;
|
||||
uint32_t getlatency;
|
||||
ErrorStatus status = SUCCESS;
|
||||
uint32_t regulatorstatus = LL_PWR_GetRegulVoltageScaling();
|
||||
uint32_t regulatorbooststatus = LL_PWR_IsEnabledRange1BoostMode();
|
||||
|
||||
uint32_t latency = LL_FLASH_LATENCY_0; /* default value 0WS */
|
||||
|
||||
/* Frequency cannot be equal to 0 or greater than max clock */
|
||||
if((HCLKFrequency == 0U) || (HCLKFrequency > UTILS_SCALE1_LATENCY5_BOOST_FREQ))
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((regulatorstatus == LL_PWR_REGU_VOLTAGE_SCALE1) && (regulatorbooststatus == 1U))
|
||||
{
|
||||
if(HCLKFrequency > UTILS_SCALE1_LATENCY4_BOOST_FREQ)
|
||||
{
|
||||
/* 136 < HCLK <= 170 => 4WS (5 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_4;
|
||||
}
|
||||
else if(HCLKFrequency > UTILS_SCALE1_LATENCY3_BOOST_FREQ)
|
||||
{
|
||||
/* 102 < HCLK <= 136 => 3WS (4 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_3;
|
||||
}
|
||||
else if(HCLKFrequency > UTILS_SCALE1_LATENCY2_BOOST_FREQ)
|
||||
{
|
||||
/* 68 < HCLK <= 102 => 2WS (3 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(HCLKFrequency > UTILS_SCALE1_LATENCY1_BOOST_FREQ)
|
||||
{
|
||||
/* 34 < HCLK <= 68 => 1WS (2 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_1;
|
||||
}
|
||||
/* else HCLKFrequency <= 10MHz default LL_FLASH_LATENCY_0 0WS */
|
||||
}
|
||||
}
|
||||
/* SCALE1 normal mode*/
|
||||
else if(regulatorstatus == LL_PWR_REGU_VOLTAGE_SCALE1)
|
||||
{
|
||||
if(HCLKFrequency > UTILS_SCALE1_LATENCY4_FREQ)
|
||||
{
|
||||
/* 120 < HCLK <= 150 => 4WS (5 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_4;
|
||||
}
|
||||
else if(HCLKFrequency > UTILS_SCALE1_LATENCY3_FREQ)
|
||||
{
|
||||
/* 90 < HCLK <= 120 => 3WS (4 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_3;
|
||||
}
|
||||
else if(HCLKFrequency > UTILS_SCALE1_LATENCY2_FREQ)
|
||||
{
|
||||
/* 60 < HCLK <= 90 => 2WS (3 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(HCLKFrequency > UTILS_SCALE1_LATENCY1_FREQ)
|
||||
{
|
||||
/* 30 < HCLK <= 60 => 1WS (2 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_1;
|
||||
}
|
||||
/* else HCLKFrequency <= 10MHz default LL_FLASH_LATENCY_0 0WS */
|
||||
}
|
||||
}
|
||||
/* SCALE2 */
|
||||
else if(regulatorstatus == LL_PWR_REGU_VOLTAGE_SCALE2)
|
||||
{
|
||||
if(HCLKFrequency > UTILS_SCALE2_LATENCY2_FREQ)
|
||||
{
|
||||
/* 24 < HCLK <= 26 => 2WS (3 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(HCLKFrequency > UTILS_SCALE2_LATENCY1_FREQ)
|
||||
{
|
||||
/* 12 < HCLK <= 24 => 1WS (2 CPU cycles) */
|
||||
latency = LL_FLASH_LATENCY_1;
|
||||
}
|
||||
/* else HCLKFrequency <= 8MHz default LL_FLASH_LATENCY_0 0WS */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
if (status != ERROR)
|
||||
{
|
||||
LL_FLASH_SetLatency(latency);
|
||||
|
||||
/* Check that the new number of wait states is taken into account to access the Flash
|
||||
memory by reading the FLASH_ACR register */
|
||||
timeout = 2U;
|
||||
do
|
||||
{
|
||||
/* Wait for Flash latency to be updated */
|
||||
getlatency = LL_FLASH_GetLatency();
|
||||
timeout--;
|
||||
} while ((getlatency != latency) && (timeout > 0U));
|
||||
|
||||
if(getlatency != latency)
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function configures system clock at maximum frequency with HSI as clock source of the PLL
|
||||
* @note The application need to ensure that PLL is disabled.
|
||||
* @note Function is based on the following formula:
|
||||
* - PLL output frequency = (((HSI frequency / PLLM) * PLLN) / PLLR)
|
||||
* - PLLM: ensure that the VCO input frequency ranges from 2.66 to 8 MHz (PLLVCO_input = HSI frequency / PLLM)
|
||||
* - PLLN: ensure that the VCO output frequency is between 64 and 344 MHz (PLLVCO_output = PLLVCO_input * PLLN)
|
||||
* - PLLR: ensure that max frequency at 170000000 Hz is reach (PLLVCO_output / PLLR)
|
||||
* @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains
|
||||
* the configuration information for the PLL.
|
||||
* @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains
|
||||
* the configuration information for the BUS prescalers.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: Max frequency configuration done
|
||||
* - ERROR: Max frequency configuration not done
|
||||
*/
|
||||
ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
|
||||
LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
|
||||
{
|
||||
ErrorStatus status;
|
||||
uint32_t pllfreq;
|
||||
uint32_t hpre = LL_RCC_SYSCLK_DIV_1;
|
||||
|
||||
/* Check if one of the PLL is enabled */
|
||||
if(UTILS_PLL_IsBusy() == SUCCESS)
|
||||
{
|
||||
/* Calculate the new PLL output frequency */
|
||||
pllfreq = UTILS_GetPLLOutputFrequency(HSI_VALUE, UTILS_PLLInitStruct);
|
||||
|
||||
/* Enable HSI if not enabled */
|
||||
if(LL_RCC_HSI_IsReady() != 1U)
|
||||
{
|
||||
LL_RCC_HSI_Enable();
|
||||
while (LL_RCC_HSI_IsReady() != 1U)
|
||||
{
|
||||
/* Wait for HSI ready */
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure PLL */
|
||||
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN,
|
||||
UTILS_PLLInitStruct->PLLR);
|
||||
|
||||
/* Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2 */
|
||||
if(pllfreq > 80000000U)
|
||||
{
|
||||
if (UTILS_ClkInitStruct->AHBCLKDivider == LL_RCC_SYSCLK_DIV_1)
|
||||
{
|
||||
UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;
|
||||
hpre = LL_RCC_SYSCLK_DIV_2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable PLL and switch system clock to PLL */
|
||||
status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct);
|
||||
|
||||
/* Apply definitive AHB prescaler value if necessary */
|
||||
if ((status == SUCCESS) && (hpre != LL_RCC_SYSCLK_DIV_1))
|
||||
{
|
||||
/* Set FLASH latency to highest latency */
|
||||
status = LL_SetFlashLatency(pllfreq);
|
||||
if (status == SUCCESS)
|
||||
{
|
||||
UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
|
||||
LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
|
||||
LL_SetSystemCoreClock(pllfreq);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Current PLL configuration cannot be modified */
|
||||
status = ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function configures system clock with HSE as clock source of the PLL
|
||||
* @note The application need to ensure that PLL is disabled.
|
||||
* @note Function is based on the following formula:
|
||||
* - PLL output frequency = (((HSE frequency / PLLM) * PLLN) / PLLR)
|
||||
* - PLLM: ensure that the VCO input frequency ranges from 2.66 to 8 MHz (PLLVCO_input = HSE frequency / PLLM)
|
||||
* - PLLN: ensure that the VCO output frequency is between 64 and 344 MHz (PLLVCO_output = PLLVCO_input * PLLN)
|
||||
* - PLLR: ensure that max frequency at 170000000 Hz is reached (PLLVCO_output / PLLR)
|
||||
* @param HSEFrequency Value between Min_Data = 4000000 and Max_Data = 48000000
|
||||
* @param HSEBypass This parameter can be one of the following values:
|
||||
* @arg @ref LL_UTILS_HSEBYPASS_ON
|
||||
* @arg @ref LL_UTILS_HSEBYPASS_OFF
|
||||
* @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains
|
||||
* the configuration information for the PLL.
|
||||
* @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains
|
||||
* the configuration information for the BUS prescalers.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: Max frequency configuration done
|
||||
* - ERROR: Max frequency configuration not done
|
||||
*/
|
||||
ErrorStatus LL_PLL_ConfigSystemClock_HSE(uint32_t HSEFrequency, uint32_t HSEBypass,
|
||||
LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
|
||||
{
|
||||
ErrorStatus status;
|
||||
uint32_t pllfreq;
|
||||
uint32_t hpre = LL_RCC_SYSCLK_DIV_1;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_LL_UTILS_HSE_FREQUENCY(HSEFrequency));
|
||||
assert_param(IS_LL_UTILS_HSE_BYPASS(HSEBypass));
|
||||
|
||||
/* Check if one of the PLL is enabled */
|
||||
if(UTILS_PLL_IsBusy() == SUCCESS)
|
||||
{
|
||||
/* Calculate the new PLL output frequency */
|
||||
pllfreq = UTILS_GetPLLOutputFrequency(HSEFrequency, UTILS_PLLInitStruct);
|
||||
|
||||
/* Enable HSE if not enabled */
|
||||
if(LL_RCC_HSE_IsReady() != 1U)
|
||||
{
|
||||
/* Check if need to enable HSE bypass feature or not */
|
||||
if(HSEBypass == LL_UTILS_HSEBYPASS_ON)
|
||||
{
|
||||
LL_RCC_HSE_EnableBypass();
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_RCC_HSE_DisableBypass();
|
||||
}
|
||||
|
||||
/* Enable HSE */
|
||||
LL_RCC_HSE_Enable();
|
||||
while (LL_RCC_HSE_IsReady() != 1U)
|
||||
{
|
||||
/* Wait for HSE ready */
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure PLL */
|
||||
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN,
|
||||
UTILS_PLLInitStruct->PLLR);
|
||||
|
||||
/* Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2 */
|
||||
if(pllfreq > 80000000U)
|
||||
{
|
||||
if (UTILS_ClkInitStruct->AHBCLKDivider == LL_RCC_SYSCLK_DIV_1)
|
||||
{
|
||||
UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;
|
||||
hpre = LL_RCC_SYSCLK_DIV_2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable PLL and switch system clock to PLL */
|
||||
status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct);
|
||||
|
||||
/* Apply definitive AHB prescaler value if necessary */
|
||||
if ((status == SUCCESS) && (hpre != LL_RCC_SYSCLK_DIV_1))
|
||||
{
|
||||
/* Set FLASH latency to highest latency */
|
||||
status = LL_SetFlashLatency(pllfreq);
|
||||
if (status == SUCCESS)
|
||||
{
|
||||
UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
|
||||
LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
|
||||
LL_SetSystemCoreClock(pllfreq);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Current PLL configuration cannot be modified */
|
||||
status = ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup UTILS_LL_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Function to check that PLL can be modified
|
||||
* @param PLL_InputFrequency PLL input frequency (in Hz)
|
||||
* @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains
|
||||
* the configuration information for the PLL.
|
||||
* @retval PLL output frequency (in Hz)
|
||||
*/
|
||||
static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct)
|
||||
{
|
||||
uint32_t pllfreq;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_LL_UTILS_PLLM_VALUE(UTILS_PLLInitStruct->PLLM));
|
||||
assert_param(IS_LL_UTILS_PLLN_VALUE(UTILS_PLLInitStruct->PLLN));
|
||||
assert_param(IS_LL_UTILS_PLLR_VALUE(UTILS_PLLInitStruct->PLLR));
|
||||
|
||||
/* Check different PLL parameters according to RM */
|
||||
/* - PLLM: ensure that the VCO input frequency ranges from 2.66 to 8 MHz. */
|
||||
pllfreq = PLL_InputFrequency / (((UTILS_PLLInitStruct->PLLM >> RCC_PLLCFGR_PLLM_Pos) + 1U));
|
||||
assert_param(IS_LL_UTILS_PLLVCO_INPUT(pllfreq));
|
||||
|
||||
/* - PLLN: ensure that the VCO output frequency is between 64 and 344 MHz.*/
|
||||
pllfreq = pllfreq * (UTILS_PLLInitStruct->PLLN & (RCC_PLLCFGR_PLLN >> RCC_PLLCFGR_PLLN_Pos));
|
||||
assert_param(IS_LL_UTILS_PLLVCO_OUTPUT(pllfreq));
|
||||
|
||||
/* - PLLR: ensure that max frequency at 170000000 Hz is reached */
|
||||
pllfreq = pllfreq / (((UTILS_PLLInitStruct->PLLR >> RCC_PLLCFGR_PLLR_Pos) + 1U) * 2U);
|
||||
assert_param(IS_LL_UTILS_PLL_FREQUENCY(pllfreq));
|
||||
|
||||
return pllfreq;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to check that PLL can be modified
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: PLL modification can be done
|
||||
* - ERROR: PLL is busy
|
||||
*/
|
||||
static ErrorStatus UTILS_PLL_IsBusy(void)
|
||||
{
|
||||
ErrorStatus status = SUCCESS;
|
||||
|
||||
/* Check if PLL is busy*/
|
||||
if(LL_RCC_PLL_IsReady() != 0U)
|
||||
{
|
||||
/* PLL configuration cannot be modified */
|
||||
status = ERROR;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to enable PLL and switch system clock to PLL
|
||||
* @param SYSCLK_Frequency SYSCLK frequency
|
||||
* @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains
|
||||
* the configuration information for the BUS prescalers.
|
||||
* @retval An ErrorStatus enumeration value:
|
||||
* - SUCCESS: No problem to switch system to PLL
|
||||
* - ERROR: Problem to switch system to PLL
|
||||
*/
|
||||
static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct)
|
||||
{
|
||||
ErrorStatus status = SUCCESS;
|
||||
uint32_t hclk_frequency;
|
||||
|
||||
assert_param(IS_LL_UTILS_SYSCLK_DIV(UTILS_ClkInitStruct->AHBCLKDivider));
|
||||
assert_param(IS_LL_UTILS_APB1_DIV(UTILS_ClkInitStruct->APB1CLKDivider));
|
||||
assert_param(IS_LL_UTILS_APB2_DIV(UTILS_ClkInitStruct->APB2CLKDivider));
|
||||
|
||||
/* Calculate HCLK frequency */
|
||||
hclk_frequency = __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, UTILS_ClkInitStruct->AHBCLKDivider);
|
||||
|
||||
/* Increasing the number of wait states because of higher CPU frequency */
|
||||
if(SystemCoreClock < hclk_frequency)
|
||||
{
|
||||
/* Set FLASH latency to highest latency */
|
||||
status = LL_SetFlashLatency(hclk_frequency);
|
||||
}
|
||||
|
||||
/* Update system clock configuration */
|
||||
if(status == SUCCESS)
|
||||
{
|
||||
/* Enable PLL */
|
||||
LL_RCC_PLL_Enable();
|
||||
LL_RCC_PLL_EnableDomain_SYS();
|
||||
while (LL_RCC_PLL_IsReady() != 1U)
|
||||
{
|
||||
/* Wait for PLL ready */
|
||||
}
|
||||
|
||||
/* Sysclk activation on the main PLL */
|
||||
LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
|
||||
while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
|
||||
{
|
||||
/* Wait for system clock switch to PLL */
|
||||
}
|
||||
|
||||
/* Set APB1 & APB2 prescaler*/
|
||||
LL_RCC_SetAPB1Prescaler(UTILS_ClkInitStruct->APB1CLKDivider);
|
||||
LL_RCC_SetAPB2Prescaler(UTILS_ClkInitStruct->APB2CLKDivider);
|
||||
}
|
||||
|
||||
/* Decreasing the number of wait states because of lower CPU frequency */
|
||||
if(SystemCoreClock > hclk_frequency)
|
||||
{
|
||||
/* Set FLASH latency to lowest latency */
|
||||
status = LL_SetFlashLatency(hclk_frequency);
|
||||
}
|
||||
|
||||
/* Update SystemCoreClock variable */
|
||||
if(status == SUCCESS)
|
||||
{
|
||||
LL_SetSystemCoreClock(hclk_frequency);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
86
Middlewares/ST/STM32_USBPD_Library/Core/LICENSE.txt
Normal file
86
Middlewares/ST/STM32_USBPD_Library/Core/LICENSE.txt
Normal file
@@ -0,0 +1,86 @@
|
||||
This software component is provided to you as part of a software package and
|
||||
applicable license terms are in the Package_license file. If you received this
|
||||
software component outside of a package or without applicable license terms,
|
||||
the terms of the SLA0044 license shall apply and are fully reproduced below:
|
||||
|
||||
SLA0044 Rev5/February 2018
|
||||
|
||||
Software license agreement
|
||||
|
||||
ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT
|
||||
|
||||
BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE
|
||||
OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS
|
||||
INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES
|
||||
(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON
|
||||
BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES
|
||||
TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT.
|
||||
|
||||
Under STMicroelectronics’ intellectual property rights, the redistribution,
|
||||
reproduction and use in source and binary forms of the software or any part
|
||||
thereof, with or without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
1. Redistribution of source code (modified or not) must retain any copyright
|
||||
notice, this list of conditions and the disclaimer set forth below as items 10
|
||||
and 11.
|
||||
|
||||
2. Redistributions in binary form, except as embedded into microcontroller or
|
||||
microprocessor device manufactured by or for STMicroelectronics or a software
|
||||
update for such device, must reproduce any copyright notice provided with the
|
||||
binary code, this list of conditions, and the disclaimer set forth below as
|
||||
items 10 and 11, in documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
3. Neither the name of STMicroelectronics nor the names of other contributors to
|
||||
this software may be used to endorse or promote products derived from this
|
||||
software or part thereof without specific written permission.
|
||||
|
||||
4. This software or any part thereof, including modifications and/or derivative
|
||||
works of this software, must be used and execute solely and exclusively on or in
|
||||
combination with a microcontroller or microprocessor device manufactured by or
|
||||
for STMicroelectronics.
|
||||
|
||||
5. No use, reproduction or redistribution of this software partially or totally
|
||||
may be done in any manner that would subject this software to any Open Source
|
||||
Terms. “Open Source Terms” shall mean any open source license which requires as
|
||||
part of distribution of software that the source code of such software is
|
||||
distributed therewith or otherwise made available, or open source license that
|
||||
substantially complies with the Open Source definition specified at
|
||||
www.opensource.org and any other comparable open source license such as for
|
||||
example GNU General Public License (GPL), Eclipse Public License (EPL), Apache
|
||||
Software License, BSD license or MIT license.
|
||||
|
||||
6. STMicroelectronics has no obligation to provide any maintenance, support or
|
||||
updates for the software.
|
||||
|
||||
7. The software is and will remain the exclusive property of STMicroelectronics
|
||||
and its licensors. The recipient will not take any action that jeopardizes
|
||||
STMicroelectronics and its licensors' proprietary rights or acquire any rights
|
||||
in the software, except the limited rights specified hereunder.
|
||||
|
||||
8. The recipient shall comply with all applicable laws and regulations affecting
|
||||
the use of the software or any part thereof including any applicable export
|
||||
control law or regulation.
|
||||
|
||||
9. Redistribution and use of this software or any part thereof other than as
|
||||
permitted under this license is void and will automatically terminate your
|
||||
rights under this license.
|
||||
|
||||
10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE
|
||||
DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL
|
||||
STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER
|
||||
EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY
|
||||
RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY.
|
||||
|
||||
1188
Middlewares/ST/STM32_USBPD_Library/Core/inc/usbpd_core.h
Normal file
1188
Middlewares/ST/STM32_USBPD_Library/Core/inc/usbpd_core.h
Normal file
File diff suppressed because it is too large
Load Diff
3470
Middlewares/ST/STM32_USBPD_Library/Core/inc/usbpd_def.h
Normal file
3470
Middlewares/ST/STM32_USBPD_Library/Core/inc/usbpd_def.h
Normal file
File diff suppressed because it is too large
Load Diff
318
Middlewares/ST/STM32_USBPD_Library/Core/inc/usbpd_tcpm.h
Normal file
318
Middlewares/ST/STM32_USBPD_Library/Core/inc/usbpd_tcpm.h
Normal file
@@ -0,0 +1,318 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_tcpm.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file containing functions prototypes of USBPD TCPM library.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBPD_TCPM_H
|
||||
#define __USBPD_TCPM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#if defined(USBPDCORE_TCPM_SUPPORT)
|
||||
|
||||
#include "string.h"
|
||||
#include "usbpd_def.h"
|
||||
#include "tcpc.h"
|
||||
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_CORE_TCPM
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/** @defgroup USBPD_CORE_TCPM_Exported_TypesDefinitions USBPD CORE TCPM Exported Types Definitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief CallBacks exposed by the @ref USBPD_CORE_TCPM to the @ref USBPD_CORE_PRL
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
* @brief Reports that a message has been received on a specified port.
|
||||
* @param hport: The handle of the port
|
||||
* @param Type: The type of the message received
|
||||
* @retval None
|
||||
* @note Received data are stored inside hport->pRxBuffPtr
|
||||
*/
|
||||
void (*USBPD_TCPM_MessageReceived)(uint8_t hport, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that a Reset received from channel.
|
||||
* @param hport: The handle of the port
|
||||
* @param Type: The type of reset performed
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_TCPM_ResetIndication)(uint8_t hport, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that a Reset operation has been completed.
|
||||
* @param hport: The handle of the port
|
||||
* @param Type: The type of reset performed
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_TCPM_ResetCompleted)(uint8_t hport, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that a Bist operation has been completed.
|
||||
* @param hport: The handle of the port
|
||||
* @param Type: The type of Bist performed
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_TCPM_BistCompleted)(uint8_t hport, USBPD_BISTMsg_TypeDef bistmode);
|
||||
|
||||
/**
|
||||
* @brief USB-PD message sent callback from TCPC
|
||||
* @param PortNum port number value
|
||||
* @param Status Status of the transmission
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_TCPM_MessageReceivedTC)(uint8_t PortNum, uint32_t status);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that an FRS has been detected.
|
||||
* @param PortNum: The handle of the port
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_PHY_FastRoleSwapReception)(uint8_t PortNum);
|
||||
|
||||
} USBPD_PHY_Callbacks;
|
||||
|
||||
/**
|
||||
* @brief Initialization structure exposed by the @ref USBPD_CORE_TCPM to the @ref USBPD_CORE_PRL
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *pRxBuffer; /*!< Pointer to @ref USBPD_CORE_PRL RX Buffer for the current port */
|
||||
const USBPD_PHY_Callbacks *pCallbacks; /*!< TCPM Callbacks */
|
||||
} USBPD_TCPM_HandleTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup USBPD_CORE_TCPM_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBPD_CORE_TCPM_Exported_Functions_Grp2 USBPD CORE TCPM Exported Functions to PRL
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Initialize TCPC devices
|
||||
* @param PortNum Number of the port
|
||||
* @param pCallbacks TCPM callbacks
|
||||
* @param pRxBuffer Pointer on the RX buffer
|
||||
* @param PowerRole Power role can be one of the following values:
|
||||
* @arg @ref USBPD_PORTPOWERROLE_SNK
|
||||
* @arg @ref USBPD_PORTPOWERROLE_SRC
|
||||
* @param SupportedSOP Supported SOP
|
||||
* @retval HAL status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_Init(uint8_t PortNum, const USBPD_PHY_Callbacks *pCallbacks, uint8_t *pRxBuffer,
|
||||
USBPD_PortPowerRole_TypeDef PowerRole, uint32_t SupportedSOP);
|
||||
|
||||
/**
|
||||
* @brief Reset the PHY of a specified port.
|
||||
* @param PortNum Number of the port.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PHY_Reset(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief function to set the supported SOP
|
||||
* @param PortNum Number of the port.
|
||||
* @param SOPSupported List of the supported SOP
|
||||
* @retval None.
|
||||
*/
|
||||
void USBPD_PHY_SOPSupported(uint8_t PortNum, uint32_t SOPSupported);
|
||||
|
||||
/**
|
||||
* @brief De-initialize TCPC devices
|
||||
* @param PortNum Number of the port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_TCPM_DeInit(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Get CC line for PD connection
|
||||
* @param PortNum Number of the port
|
||||
* @param CC1_Level Pointer of status of the CC1 line
|
||||
* @param CC2_Level Pointer of status of the CC2 line
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_TCPM_get_cc(uint32_t PortNum, uint32_t *CC1_Level, uint32_t *CC2_Level);
|
||||
|
||||
/**
|
||||
* @brief Set the polarity of the CC lines
|
||||
* @param PortNum Number of the port
|
||||
* @param Polarity Polarity
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_TCPM_set_polarity(uint32_t PortNum, uint32_t Polarity);
|
||||
|
||||
/**
|
||||
* @brief Set power and data role et PD message header
|
||||
* @param PortNum Number of the port
|
||||
* @param PowerRole Power role
|
||||
* @param DataRole Data role
|
||||
* @param Specification PD Specification version
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_TCPM_set_msg_header(uint32_t PortNum, USBPD_PortPowerRole_TypeDef PowerRole,
|
||||
USBPD_PortDataRole_TypeDef DataRole,
|
||||
USBPD_SpecRev_TypeDef Specification);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable PD reception
|
||||
* @param PortNum Number of the port
|
||||
* @param Pull Value of the CC pin to configure based on @ref TCPC_CC_Pull_TypeDef
|
||||
* @param State Activation or deactivation of RX
|
||||
* @param SupportedSOP Supported SOP by PRL
|
||||
* @param HardReset Hard reset status based on @ref TCPC_hard_reset
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_TCPM_set_rx_state(uint32_t PortNum, TCPC_CC_Pull_TypeDef Pull, USBPD_FunctionalState State,
|
||||
uint32_t SupportedSOP, TCPC_hard_reset HardReset);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the PD message
|
||||
* @param PortNum Number of the port
|
||||
* @param Payload Pointer on the payload
|
||||
* @param Type Pointer on the message type
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_TCPM_get_message(uint32_t PortNum, uint8_t *Payload, uint8_t *Type);
|
||||
|
||||
/**
|
||||
* @brief Transmit the PD message
|
||||
* @param PortNum Number of the port
|
||||
* @param Type Message type
|
||||
* @param pData Pointer on the data message
|
||||
* @param RetryNumber Number of retry
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_TCPM_transmit(uint32_t PortNum, USBPD_SOPType_TypeDef Type, const uint8_t *pData,
|
||||
uint32_t RetryNumber);
|
||||
|
||||
/**
|
||||
* @brief Send bist pattern.
|
||||
* @param PortNum Number of the port
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_Send_BIST_Pattern(uint32_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Request a Reset on a specified port.
|
||||
* @param PortNum Number of the port
|
||||
* @param Type The type of reset (hard or cable reset).
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_ResetRequest(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief Request TCPC to enter a specific BIST test mode.
|
||||
* @param PortNum Number of the port
|
||||
* @param State Enable BIST carrier mode 2
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_TCPM_Send_BIST_Pattern(uint8_t PortNum, USBPD_FunctionalState State);
|
||||
|
||||
/**
|
||||
* @brief function to set the SinkTxNg
|
||||
* @param PortNum Number of the port.
|
||||
* @retval none.
|
||||
*/
|
||||
void USBPD_PHY_SetResistor_SinkTxNG(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief function to set the SinkTxOK
|
||||
* @param PortNum Number of the port.
|
||||
* @retval none.
|
||||
*/
|
||||
void USBPD_PHY_SetResistor_SinkTxOK(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief function to check if SinkTxOK
|
||||
* @param PortNum Number of the port.
|
||||
* @retval USBPD_TRUE or USBPD_FALSE
|
||||
*/
|
||||
uint8_t USBPD_PHY_IsResistor_SinkTxOk(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Trigger in Fast role swap signalling
|
||||
* @param PortNum Number of the port.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PHY_FastRoleSwapSignalling(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Enable RX
|
||||
* @param PortNum Number of the port.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PHY_EnableRX(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Disable RX
|
||||
* @param PortNum Number of the port.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PHY_DisableRX(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* USBPDCORE_TCPM_SUPPORT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __USBPD_TCPM_H */
|
||||
|
||||
152
Middlewares/ST/STM32_USBPD_Library/Core/inc/usbpd_trace.h
Normal file
152
Middlewares/ST/STM32_USBPD_Library/Core/inc/usbpd_trace.h
Normal file
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_trace.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for usbpd_trace.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef USBPD_TRACE_H_
|
||||
#define USBPD_TRACE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_core.h"
|
||||
#ifndef _STDIO
|
||||
#include "stdio.h"
|
||||
#endif /* _STDIO */
|
||||
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_CORE_TRACE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
/** @defgroup USBPD_CORE_TRACE_Exported_Defines USBPD CORE TRACE Exported Defines
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
TCPM_TRACE_CORE_ALERT, /*!< ALERT_TASK */
|
||||
TCPM_TRACE_ALERT, /*!< USBPD_TCPM_alert */
|
||||
TCPM_TRACE_ALERT_CLEAR, /*!< USBPD_TCPM_alert: tcpc_clear_alert */
|
||||
TCPM_TRACE_ALERT_GET_POWER_STATUS, /*!< USBPD_TCPM_alert: get_power_status */
|
||||
TCPM_TRACE_ALERT_GET_FAULT_STATUS, /*!< USBPD_TCPM_alert: get_fault_status */
|
||||
TCPM_TRACE_ALERT_SET_FAULT_STATUS, /*!< USBPD_TCPM_alert: set_fault_status */
|
||||
TCPM_TRACE_ALERT_READ_ALERT, /*!< USBPD_TCPM_alert: set_fault_status */
|
||||
TCPM_TRACE_HW_INIT, /*!< USBPD_TCPM_HWInit */
|
||||
TCPM_TRACE_SET_CC, /*!< USBPD_TCPM_set_cc */
|
||||
TCPM_TRACE_VBUS_GET_VOLTAGE, /*!< USBPD_TCPM_VBUS_GetVoltage */
|
||||
TCPM_TRACE_VBUS_IS_VSAFE0V, /*!< USBPD_TCPM_VBUS_IsVsafe0V */
|
||||
TCPM_TRACE_VBUS_IS_VSAFEEV, /*!< USBPD_TCPM_VBUS_IsVsafe5V */
|
||||
TCPM_TRACE_VBUS_ENABLE, /*!< USBPD_TCPM_VBUS_Enable */
|
||||
TCPM_TRACE_VBUS_DISABLE, /*!< USBPD_TCPM_VBUS_Disable */
|
||||
TCPM_TRACE_INIT, /*USBPD_PHY_Init*/
|
||||
TCPM_TRACE_DEINIT, /*USBPD_PHY_Deinit*/
|
||||
TCPM_TRACE_RESET, /*USBPD_PHY_Reset*/
|
||||
TCPM_TRACE_SOP_SUPPORTED, /*USBPD_PHY_SOPSupported*/
|
||||
TCPM_TRACE_GET_CC, /*USBPD_TCPM_get_cc*/
|
||||
TCPM_TRACE_SET_POLARITY, /*USBPD_TCPM_set_polarity*/
|
||||
TCPM_TRACE_SET_VCONN, /*USBPD_TCPM_set_vconn*/
|
||||
TCPM_TRACE_SET_MSG_HEADER, /*USBPD_TCPM_set_msg_header*/
|
||||
TCPM_TRACE_SET_RX_STATE, /*USBPD_TCPM_set_rx_state*/
|
||||
TCPM_TRACE_SET_GET_MESSAGE, /*USBPD_TCPM_get_message*/
|
||||
TCPM_TRACE_TRANSMIT, /*USBPD_TCPM_transmit*/
|
||||
TCPM_TRACE_RESET_REQUEST, /*USBPD_PHY_ResetRequest*/
|
||||
TCPM_TRACE_SEND_BIST, /*USBPD_PHY_Send_BIST_Pattern*/
|
||||
TCPM_TRACE_SEND_BIST_PATTERN, /*USBPD_TCPM_Send_BIST_Pattern*/
|
||||
TCPM_TRACE_SINK_TXNG, /*USBPD_PHY_SetResistor_SinkTxNG*/
|
||||
TCPM_TRACE_SINK_TXOK, /*USBPD_PHY_SetResistor_SinkTxOK*/
|
||||
TCPM_TRACE_SINK_IF_TXOK, /*USBPD_PHY_IsResistor_SinkTxOk*/
|
||||
TCPM_TRACE_FAST_ROLE_SWAP, /*USBPD_PHY_FastRoleSwapSignalling*/
|
||||
TCPM_TRACE_ENABLE_RX, /* tcpc_EnableRx */
|
||||
TCPM_TRACE_DISABLE_RX, /* tcpc_DisableRx */
|
||||
TCPM_TRACE_SET_PIN_ROLE, /* tcpc_tcpc_set_cc */
|
||||
} USBPD_TCPM_TRACE;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/** @defgroup USBPD_CORE_TRACE_Exported_Variables USBPD CORE TRACE Exported Variables
|
||||
* @{
|
||||
*/
|
||||
extern TRACE_ENTRY_POINT USBPD_Trace;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup USBPD_CORE_TRACE_Exported_Functions USBPD CORE TRACE Exported Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Initialize the TRACE module
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_TRACE_Init(void);
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the TRACE module
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_TRACE_DeInit(void);
|
||||
|
||||
/**
|
||||
* @brief Add information in debug trace buffer
|
||||
* @param Type Trace Type based on @ref TRACE_EVENT
|
||||
* @param PortNum Port number value
|
||||
* @param Sop SOP type
|
||||
* @param Ptr Pointer on the data to send
|
||||
* @param Size Size of the data to send
|
||||
* @retval None.
|
||||
*/
|
||||
void USBPD_TRACE_Add(TRACE_EVENT Type, uint8_t PortNum, uint8_t Sop, uint8_t *Ptr, uint32_t Size);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBPD_CAD_H_ */
|
||||
|
||||
Binary file not shown.
213
Middlewares/ST/STM32_USBPD_Library/Core/src/usbpd_trace.c
Normal file
213
Middlewares/ST/STM32_USBPD_Library/Core/src/usbpd_trace.c
Normal file
@@ -0,0 +1,213 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_trace.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains trace control functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#define USBPD_TRACE_C
|
||||
|
||||
#include "usbpd_def.h"
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_trace.h"
|
||||
#ifdef _TRACE
|
||||
#include "tracer_emb.h"
|
||||
#endif /* _TRACE */
|
||||
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_CORE_TRACE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private enums -------------------------------------------------------------*/
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup USBPD_CORE_TRACE_Private_Defines USBPD CORE TRACE Private Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define TRACE_SIZE_HEADER_TRACE 9u /* Type + Time x 2 + PortNum + Sop + Size */
|
||||
|
||||
#define TRACE_PORT_BIT_POSITION 5u /* Bit position of port number in TAG id */
|
||||
|
||||
#define TLV_SOF (uint8_t)0xFDu
|
||||
#define TLV_EOF (uint8_t)0xA5u
|
||||
#define TLV_SIZE_MAX 256u
|
||||
#define TLV_HEADER_SIZE 3u /* Size of TLV header (TAG(1) + LENGTH(2) */
|
||||
#define TLV_SOF_SIZE 4u /* TLV_SOF * 4 */
|
||||
#define TLV_EOF_SIZE 4u /* TLV_EOF * 4 */
|
||||
|
||||
#define DEBUG_STACK_MESSAGE 0x12u
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/** @defgroup USBPD_CORE_TRACE_Private_Macros USBPD CORE TRACE Private Macros
|
||||
* @{
|
||||
*/
|
||||
#define TRACE_SET_TAG_ID(_PORT_, _TAG_) (((_PORT_) << TRACE_PORT_BIT_POSITION) | (_TAG_))
|
||||
|
||||
#define TRACER_EMB_WRITE_DATA(_POSITION_,_DATA_) do { \
|
||||
TRACER_EMB_WriteData((_POSITION_),(_DATA_));\
|
||||
(_POSITION_) = ((_POSITION_) + 1u); \
|
||||
} while(0)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/** @defgroup USBPD_CORE_TRACE_Private_Variables USBPD CORE TRACE Private Variables
|
||||
* @{
|
||||
*/
|
||||
extern uint32_t HAL_GetTick(void);
|
||||
extern void USBPD_DPM_TraceWakeUp(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions ---------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup USBPD_CORE_TRACE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
void USBPD_TRACE_Init(void)
|
||||
{
|
||||
#if defined(_TRACE)
|
||||
static const uint8_t OverFlow_String[] =
|
||||
{
|
||||
TLV_SOF, TLV_SOF, TLV_SOF, TLV_SOF, /* Buffer header */
|
||||
0x32, /* Tag id */
|
||||
0x0, 0x18, /* Length */
|
||||
0x6, /* Type */
|
||||
0x0, 0x0, 0x0, 0x0, /* Time */
|
||||
0x0, /* PortNum */
|
||||
0x0, /* SOP */
|
||||
0x0, 0x0F, /* Size */
|
||||
'T', 'R', 'A', 'C', 'E', ' ', 'O', 'V', 'E', 'R', '_', 'F', 'L', 'O', 'W', /* Data */
|
||||
TLV_EOF, TLV_EOF, TLV_EOF, TLV_EOF /* Buffer end */
|
||||
};
|
||||
|
||||
/* initialize tracer module */
|
||||
TRACER_EMB_Init();
|
||||
|
||||
/* Initialize PE trace */
|
||||
USBPD_PE_SetTrace(USBPD_TRACE_Add, 3u);
|
||||
|
||||
/* Initialize the overflow detection */
|
||||
(void)TRACER_EMB_EnableOverFlow(OverFlow_String, (uint8_t)sizeof(OverFlow_String));
|
||||
#else
|
||||
return;
|
||||
#endif /* _TRACE */
|
||||
}
|
||||
|
||||
void USBPD_TRACE_DeInit(void)
|
||||
{
|
||||
/* Nothing to do */
|
||||
return;
|
||||
}
|
||||
|
||||
void USBPD_TRACE_Add(TRACE_EVENT Type, uint8_t PortNum, uint8_t Sop, uint8_t *Ptr, uint32_t Size)
|
||||
{
|
||||
#if defined(_TRACE)
|
||||
uint32_t _time;
|
||||
int32_t _allocation;
|
||||
uint16_t index;
|
||||
|
||||
/* Get trace timing */
|
||||
_time = HAL_GetTick();
|
||||
|
||||
TRACER_EMB_Lock();
|
||||
|
||||
/* Data are encapsulate inside a TLV string*/
|
||||
/* Allocate buffer Size */
|
||||
_allocation = TRACER_EMB_AllocateBufer(Size + TRACE_SIZE_HEADER_TRACE +
|
||||
TLV_HEADER_SIZE + TLV_SOF_SIZE + TLV_EOF_SIZE);
|
||||
|
||||
/* Check allocation */
|
||||
if (_allocation != -1)
|
||||
{
|
||||
uint16_t _writepos = (uint16_t)_allocation;
|
||||
|
||||
/* Copy SOF bytes */
|
||||
for (index = 0u; index < TLV_SOF_SIZE; index++)
|
||||
{
|
||||
TRACER_EMB_WRITE_DATA(_writepos, TLV_SOF);
|
||||
}
|
||||
/* Copy the TAG */
|
||||
TRACER_EMB_WRITE_DATA(_writepos, TRACE_SET_TAG_ID((PortNum + 1u), DEBUG_STACK_MESSAGE));
|
||||
/* Copy the LENGTH */
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)((Size + TRACE_SIZE_HEADER_TRACE) >> 8u));
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)(Size + TRACE_SIZE_HEADER_TRACE));
|
||||
|
||||
/* Trace type */
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)Type);
|
||||
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)_time);
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)(_time >> 8u));
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)(_time >> 16u));
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)(_time >> 24u));
|
||||
|
||||
TRACER_EMB_WRITE_DATA(_writepos, PortNum);
|
||||
TRACER_EMB_WRITE_DATA(_writepos, Sop);
|
||||
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)(Size >> 8u));
|
||||
TRACER_EMB_WRITE_DATA(_writepos, (uint8_t)Size);
|
||||
|
||||
/* initialize the Ptr for Read/Write */
|
||||
for (index = 0u; index < Size; index++)
|
||||
{
|
||||
TRACER_EMB_WRITE_DATA(_writepos, Ptr[index]);
|
||||
}
|
||||
|
||||
/* Copy EOF bytes */
|
||||
for (index = 0u; index < TLV_EOF_SIZE; index++)
|
||||
{
|
||||
TRACER_EMB_WRITE_DATA(_writepos, TLV_EOF);
|
||||
}
|
||||
}
|
||||
|
||||
TRACER_EMB_UnLock();
|
||||
|
||||
TRACER_EMB_SendData();
|
||||
#else
|
||||
return;
|
||||
#endif /* _TRACE */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
This software component is provided to you as part of a software package and
|
||||
applicable license terms are in the Package_license file. If you received this
|
||||
software component outside of a package or without applicable license terms,
|
||||
the terms of the SLA0044 license shall apply and are fully reproduced below:
|
||||
|
||||
SLA0044 Rev5/February 2018
|
||||
|
||||
Software license agreement
|
||||
|
||||
ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT
|
||||
|
||||
BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE
|
||||
OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS
|
||||
INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES
|
||||
(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON
|
||||
BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES
|
||||
TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT.
|
||||
|
||||
Under STMicroelectronics’ intellectual property rights, the redistribution,
|
||||
reproduction and use in source and binary forms of the software or any part
|
||||
thereof, with or without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
1. Redistribution of source code (modified or not) must retain any copyright
|
||||
notice, this list of conditions and the disclaimer set forth below as items 10
|
||||
and 11.
|
||||
|
||||
2. Redistributions in binary form, except as embedded into microcontroller or
|
||||
microprocessor device manufactured by or for STMicroelectronics or a software
|
||||
update for such device, must reproduce any copyright notice provided with the
|
||||
binary code, this list of conditions, and the disclaimer set forth below as
|
||||
items 10 and 11, in documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
3. Neither the name of STMicroelectronics nor the names of other contributors to
|
||||
this software may be used to endorse or promote products derived from this
|
||||
software or part thereof without specific written permission.
|
||||
|
||||
4. This software or any part thereof, including modifications and/or derivative
|
||||
works of this software, must be used and execute solely and exclusively on or in
|
||||
combination with a microcontroller or microprocessor device manufactured by or
|
||||
for STMicroelectronics.
|
||||
|
||||
5. No use, reproduction or redistribution of this software partially or totally
|
||||
may be done in any manner that would subject this software to any Open Source
|
||||
Terms. “Open Source Terms” shall mean any open source license which requires as
|
||||
part of distribution of software that the source code of such software is
|
||||
distributed therewith or otherwise made available, or open source license that
|
||||
substantially complies with the Open Source definition specified at
|
||||
www.opensource.org and any other comparable open source license such as for
|
||||
example GNU General Public License (GPL), Eclipse Public License (EPL), Apache
|
||||
Software License, BSD license or MIT license.
|
||||
|
||||
6. STMicroelectronics has no obligation to provide any maintenance, support or
|
||||
updates for the software.
|
||||
|
||||
7. The software is and will remain the exclusive property of STMicroelectronics
|
||||
and its licensors. The recipient will not take any action that jeopardizes
|
||||
STMicroelectronics and its licensors' proprietary rights or acquire any rights
|
||||
in the software, except the limited rights specified hereunder.
|
||||
|
||||
8. The recipient shall comply with all applicable laws and regulations affecting
|
||||
the use of the software or any part thereof including any applicable export
|
||||
control law or regulation.
|
||||
|
||||
9. Redistribution and use of this software or any part thereof other than as
|
||||
permitted under this license is void and will automatically terminate your
|
||||
rights under this license.
|
||||
|
||||
10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE
|
||||
DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL
|
||||
STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER
|
||||
EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY
|
||||
RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY.
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_cad_hw_if.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the headers of usbpd_cad_hw_if.c for Cable Attach-Detach
|
||||
* controls.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef __USBPD_CAD_HW_IF_H_
|
||||
#define __USBPD_CAD_HW_IF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_core.h"
|
||||
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_CAD_HW_IF
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
#if defined(_LOW_POWER) || defined(USBPDM1_VCC_FEATURE_ENABLED)
|
||||
#define CAD_DELAY_READ_CC_STATUS (300U)
|
||||
#endif /* _LOW_POWER || USBPDM1_VCC_FEATURE_ENABLED */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#if defined(USBPDCORE_DRP) || defined(USBPDCORE_SRC)
|
||||
/* Keep for legacy */
|
||||
uint32_t CAD_Set_ResistorRp(uint8_t PortNum, CAD_RP_Source_Current_Adv_Typedef RpValue);
|
||||
#endif /* USBPDCORE_DRP || USBPDCORE_SRC */
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_CAD_HW_IF_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
void CAD_Init(uint8_t PortNum, USBPD_SettingsTypeDef *Settings,
|
||||
USBPD_ParamsTypeDef *Params, void (*PtrWakeUp)(void));
|
||||
uint32_t CAD_StateMachine(uint8_t PortNum, USBPD_CAD_EVENT *Event, CCxPin_TypeDef *CCXX);
|
||||
void CAD_Enter_ErrorRecovery(uint8_t PortNum);
|
||||
#if defined(USBPDCORE_DRP) || defined(USBPDCORE_SRC)
|
||||
uint32_t CAD_SRC_Set_ResistorRp(uint8_t PortNum, CAD_RP_Source_Current_Adv_Typedef RpValue);
|
||||
#endif /* USBPDCORE_DRP || USBPDCORE_SRC */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_CAD_HW_IF_H_ */
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_hw.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains interface hw control.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __USBPD_HW_H_
|
||||
#define __USBPD_HW_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Variable containing ADC conversions results */
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
UCPD_TypeDef *USBPD_HW_GetUSPDInstance(uint8_t PortNum);
|
||||
DMA_Channel_TypeDef *USBPD_HW_Init_DMARxInstance(uint8_t PortNum);
|
||||
void USBPD_HW_DeInit_DMARxInstance(uint8_t PortNum);
|
||||
DMA_Channel_TypeDef *USBPD_HW_Init_DMATxInstance(uint8_t PortNum);
|
||||
void USBPD_HW_DeInit_DMATxInstance(uint8_t PortNum);
|
||||
uint32_t USBPD_HW_GetRpResistorValue(uint8_t Portnum);
|
||||
void USBPD_HW_SetFRSSignalling(uint8_t Portnum, uint8_t cc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_HW_H_ */
|
||||
@@ -0,0 +1,380 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_hw_if.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the headers of usbpd_hw_if.h for USB-PD Hardware
|
||||
Interface layer. This file is specific for each device.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __USBPD_HW_IF_H_
|
||||
#define __USBPD_HW_IF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_def.h"
|
||||
#include "usbpd_devices_conf.h"
|
||||
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_HW_IF
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
/** @defgroup USBPD_DEVICE_DEVICE_HW_IF_Exported_Types USBPD DEVICE HW_IF Exported Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enum used to get the status of decoding
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
USBPD_PHY_RX_STATUS_NONE,
|
||||
USBPD_PHY_RX_STATUS_OK,
|
||||
USBPD_PHY_RX_STATUS_SOP_DETECTING,
|
||||
USBPD_PHY_RX_STATUS_DATA,
|
||||
USBPD_PHY_RX_STATUS_MESSAGE_READY,
|
||||
USBPD_PHY_RX_STATUS_ERROR,
|
||||
USBPD_PHY_RX_STATUS_ERROR_UNSUPPORTED_SOP,
|
||||
USBPD_PHY_RX_STATUS_ERROR_INVALID_SOP,
|
||||
USBPD_PHY_RX_STATUS_ERROR_INVALID_SYMBOL,
|
||||
USBPD_PHY_RX_STATUS_ERROR_EOP_NOT_FOUND,
|
||||
USBPD_PHY_RX_STATUS_ERROR_CRC_FAILED,
|
||||
}
|
||||
USBPD_PHY_RX_Status_TypeDef;
|
||||
|
||||
/**
|
||||
* @brief CallBacks exposed by the HW_IF to the PHY
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
* @brief The message transfer has been completed
|
||||
* @param PortNum Port number
|
||||
* @param Status (0 means OK)
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_HW_IF_TxCompleted)(uint8_t PortNum, uint32_t Status);
|
||||
|
||||
/**
|
||||
* @brief Bist data sent callback from PHY_HW_IF
|
||||
* @param PortNum Port number
|
||||
* @param bistmode: Bist mode
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_HW_IF_BistCompleted)(uint8_t PortNum, USBPD_BISTMsg_TypeDef bistmode);
|
||||
|
||||
/**
|
||||
* @brief The reception phase of an hard reset is completed notify it.
|
||||
* @param PortNum Port number
|
||||
* @param SOPType SOP Message Type based on @ref USBPD_SOPType_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_HW_IF_RX_ResetIndication)(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief The reception phase of the current message is completed and notify it.
|
||||
* @param PortNum Port number
|
||||
* @param MsgType Message Type
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_HW_IF_RX_Completed)(uint8_t PortNum, uint32_t MsgType);
|
||||
|
||||
/**
|
||||
* @brief The emission of HRST has been completed.
|
||||
* @param PortNum Port number
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_HW_IF_TX_HardResetCompleted)(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief FRS reception.
|
||||
* @param PortNum Port number
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_HW_IF_TX_FRSReception)(uint8_t PortNum);
|
||||
|
||||
} USBPD_HW_IF_Callbacks_TypeDef;
|
||||
|
||||
/** @defgroup USBPD_PORT_HandleTypeDef USB PD handle Structure definition for USBPD_PHY_HW_IF
|
||||
* @brief USBPD PORT handle Structure definition
|
||||
* @{
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
UCPD_TypeDef *husbpd; /*!< UCPD Handle parameters */
|
||||
DMA_Channel_TypeDef *hdmatx; /*!< Tx DMA Handle parameters */
|
||||
DMA_Channel_TypeDef *hdmarx; /*!< Rx DMA Handle parameters */
|
||||
|
||||
USBPD_SettingsTypeDef *settings;
|
||||
USBPD_ParamsTypeDef *params;
|
||||
USBPD_HW_IF_Callbacks_TypeDef cbs; /*!< USBPD_PHY_HW_IF callbacks */
|
||||
|
||||
void (*USBPD_CAD_WakeUp)(void); /*!< function used to wakeup cad task */
|
||||
|
||||
uint8_t *ptr_RxBuff; /*!< Pointer to Raw Rx transfer Buffer */
|
||||
|
||||
CCxPin_TypeDef CCx; /*!< CC pin used for communication */
|
||||
__IO uint8_t RXStatus; /*!< Tracks the reception of a message to forbid any new
|
||||
TX transaction until message completion */
|
||||
} USBPD_PORT_HandleTypeDef;
|
||||
|
||||
extern USBPD_PORT_HandleTypeDef Ports[USBPD_PORT_COUNT];
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
|
||||
/** @defgroup USBPD_DEVICE_DEVICE_HW_IF_Exported_Defines USBPD DEVICE HW_IF Exported Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define SIZE_MAX_PD_TRANSACTION_CHUNK 30u
|
||||
#define SIZE_MAX_PD_TRANSACTION_UNCHUNK (260u + 4u)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup USBPD_DEVICE_DEVICE_HW_IF_Exported_Functions USBPD DEVICE HW_IF Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable the interrupt for the reception.
|
||||
* @param PortNum The handle of the port.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_RX_EnableInterrupt(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief stop bist carrier mode 2.
|
||||
* @param PortNum The port handle.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_StopBISTMode2(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Initialize specific peripheral for the APP.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_GlobalHwInit(void);
|
||||
|
||||
/**
|
||||
* @brief Send a Buffer .
|
||||
* @note The data will be converted in bmc and send through the line
|
||||
* @param PortNum The port handle.
|
||||
* @param Type SOP Message Type based on @ref USBPD_SOPType_TypeDef
|
||||
* @param pBuffer Data buffer to be transmitted
|
||||
* @param Bitsize The number of bits to be transmitted
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_HW_IF_SendBuffer(uint8_t PortNum, USBPD_SOPType_TypeDef Type, uint8_t *pBuffer,
|
||||
uint32_t Bitsize);
|
||||
|
||||
#if defined(_SRC) || defined(_DRP)
|
||||
/**
|
||||
* @brief Enable the VBUS on a specified port.
|
||||
* @param PortNum The port handle.
|
||||
* @param State ENABLE or DISABLE.
|
||||
* @param Cc CC pin based on @ref CCxPin_TypeDef
|
||||
* @param VconnState VCONN State activation
|
||||
* @param role The role of the port.
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef HW_IF_PWR_Enable(uint8_t PortNum, USBPD_FunctionalState State, CCxPin_TypeDef Cc,
|
||||
uint32_t VconnState, USBPD_PortPowerRole_TypeDef role);
|
||||
#endif /* _SRC || _DRP */
|
||||
|
||||
/**
|
||||
* @brief Retrieve the VBUS status for a specified port.
|
||||
* @param PortNum The port handle.
|
||||
* @retval FunctionalState
|
||||
*/
|
||||
USBPD_FunctionalState HW_IF_PWR_VBUSIsEnabled(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Set the VBUS voltage level on a specified port.
|
||||
* @param PortNum The port handle.
|
||||
* @param Voltage voltage value to be set.
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef HW_IF_PWR_SetVoltage(uint8_t PortNum, uint16_t Voltage);
|
||||
|
||||
/**
|
||||
* @brief Get the voltage level on a specified port.
|
||||
* @param PortNum The port handle.
|
||||
* @retval The voltage value
|
||||
*/
|
||||
uint16_t HW_IF_PWR_GetVoltage(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Get the current level on a specified port.
|
||||
* @param PortNum The port handle.
|
||||
* @retval The current value
|
||||
*/
|
||||
int16_t HW_IF_PWR_GetCurrent(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Connect the Rp resistors on the CC lines
|
||||
* @param PortNum The port handle.
|
||||
* @retval none
|
||||
*/
|
||||
void USBPDM1_AssertRp(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Disconnect the Rp resistors on the CC lines
|
||||
* @param PortNum The port handle.
|
||||
* @retval none
|
||||
*/
|
||||
void USBPDM1_DeAssertRp(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Connect the Rd resistors on the CC lines
|
||||
* @param PortNum The port handle.
|
||||
* @retval none
|
||||
*/
|
||||
void USBPDM1_AssertRd(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Disconnect the Rd resistors on the CC lines
|
||||
* @param PortNum The port handle.
|
||||
* @retval none
|
||||
*/
|
||||
void USBPDM1_DeAssertRd(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Set the CCx pin.
|
||||
* @param PortNum The port handle.
|
||||
* @param cc Specify the ccx to be selected.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_Set_CC(uint8_t PortNum, CCxPin_TypeDef cc);
|
||||
|
||||
/**
|
||||
* @brief Sends the BIST pattern
|
||||
* @param PortNum The port handle.
|
||||
* @retval none
|
||||
*/
|
||||
void USBPD_HW_IF_Send_BIST_Pattern(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Sends a detachemnt signal.
|
||||
* @param PortNum The port handle.
|
||||
* @retval none
|
||||
*/
|
||||
void HW_SignalDetachment(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Sends an Attachment signal.
|
||||
* @param PortNum The port handle.
|
||||
* @param cc the PD pin.
|
||||
* @retval none
|
||||
*/
|
||||
void HW_SignalAttachement(uint8_t PortNum, CCxPin_TypeDef cc);
|
||||
|
||||
/**
|
||||
* @brief Set SinkTxNG resistor.
|
||||
* @param PortNum The port handle.
|
||||
* @retval none
|
||||
*/
|
||||
void USBPD_HW_IF_SetResistor_SinkTxNG(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Set SinkTxOk resistor.
|
||||
* @param PortNum The port handle.
|
||||
* @retval none
|
||||
*/
|
||||
void USBPD_HW_IF_SetResistor_SinkTxOK(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Is SinkTxOk resistor.
|
||||
* @param PortNum The port handle.
|
||||
* @retval TRUE FALSE
|
||||
*/
|
||||
uint8_t USBPD_HW_IF_IsResistor_SinkTxOk(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief send a Fast Role swap signalling.
|
||||
* @param PortNum The port handle.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_FastRoleSwapSignalling(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief enter in error recovery state.
|
||||
* @param PortNum The port handle.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_EnterErrorRecovery(uint8_t PortNum);
|
||||
|
||||
|
||||
void USBPD_PORT0_IRQHandler(void);
|
||||
void USBPD_PORT1_IRQHandler(void);
|
||||
|
||||
/**
|
||||
* @brief Enable RX
|
||||
* @param PortNum The port handle.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_EnableRX(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Disable RX
|
||||
* @param PortNum The port handle.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_DisableRX(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_HW_IF_H_ */
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_phy.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the headers of usbpd_phy.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __USBPD_PHY_H_
|
||||
#define __USBPD_PHY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_PHY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
/** @defgroup USBPD_DEVICE_PHY_Exported_TypeDef USBPD DEVICE PHY Exported TypeDef
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief CallBacks exposed by the @ref USBPD_DEVICE_PHY to the USBPD_CORE_PRL
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
* @brief Reports that a message has been received on a specified port.
|
||||
* @note Received data are stored inside PortNum->pRxBuffPtr
|
||||
* function called in the interrupt context
|
||||
* @param PortNum The handle of the port
|
||||
* @param Type The type of the message received @ref USBPD_SOPType_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_PHY_MessageReceived)(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that a Reset received from channel.
|
||||
* @param PortNum The handle of the port
|
||||
* @param Type The type of reset performed @ref USBPD_SOPTYPE_HARD_RESET or @ref USBPD_SOPTYPE_CABLE_RESET
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_PHY_ResetIndication)(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that a Reset operation has been completed.
|
||||
* @param PortNum The handle of the port
|
||||
* @param Type The type of reset performed @ref USBPD_SOPTYPE_HARD_RESET or @ref USBPD_SOPTYPE_CABLE_RESET
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_PHY_ResetCompleted)(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that a Bist operation has been completed.
|
||||
* @param PortNum The handle of the port
|
||||
* @param Type The type of Bist performed @ref USBPD_BISTMsg_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_PHY_BistCompleted)(uint8_t PortNum, USBPD_BISTMsg_TypeDef bistmode);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that a tx operation has been completed.
|
||||
* @param PortNum: The handle of the port
|
||||
* @param Status: 0 if no error else error
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_PHY_TxCompleted)(uint8_t PortNum, uint32_t Status);
|
||||
|
||||
/**
|
||||
* @brief Reports to the PRL that an FRS has been detected.
|
||||
* @param PortNum: The handle of the port
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_PHY_FastRoleSwapReception)(uint8_t PortNum);
|
||||
|
||||
} USBPD_PHY_Callbacks;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_PHY_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_Init(uint8_t PortNum, const USBPD_PHY_Callbacks *cbs, uint8_t *pRxBuffer,
|
||||
USBPD_PortPowerRole_TypeDef role, uint32_t SupportedSOP);
|
||||
void USBPD_PHY_Reset(uint8_t PortNum);
|
||||
uint16_t USBPD_PHY_GetRetryTimerValue(uint8_t PortNum);
|
||||
uint16_t USBPD_PHY_GetMinGOODCRCTimerValue(uint8_t PortNum);
|
||||
|
||||
USBPD_StatusTypeDef USBPD_PHY_ResetRequest(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
USBPD_StatusTypeDef USBPD_PHY_SendMessage(uint8_t PortNum, USBPD_SOPType_TypeDef Type, uint8_t *pBuffer, uint16_t Size);
|
||||
USBPD_StatusTypeDef USBPD_PHY_Send_BIST_Pattern(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_PHY_ExitTransmit(uint8_t PortNum, USBPD_SOPType_TypeDef BistType);
|
||||
void USBPD_PHY_SetResistor_SinkTxNG(uint8_t PortNum);
|
||||
void USBPD_PHY_SetResistor_SinkTxOK(uint8_t PortNum);
|
||||
uint8_t USBPD_PHY_IsResistor_SinkTxOk(uint8_t PortNum);
|
||||
void USBPD_PHY_FastRoleSwapSignalling(uint8_t PortNum);
|
||||
void USBPD_PHY_SOPSupported(uint8_t PortNum, uint32_t SOPSupported);
|
||||
|
||||
void USBPD_PHY_EnableRX(uint8_t PortNum);
|
||||
void USBPD_PHY_DisableRX(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_PHY_H_ */
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_timersserver.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the headers of usbpd_timerserver.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __USBPD_TIMERSSERVER_H_
|
||||
#define __USBPD_TIMERSSERVER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_TIMESERVER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
TIM_PORT0_CRC,
|
||||
TIM_PORT0_RETRY,
|
||||
TIM_PORT1_CRC,
|
||||
TIM_PORT1_RETRY,
|
||||
TIM_MAX
|
||||
}
|
||||
TIM_identifier;
|
||||
|
||||
#define TIM_MAX_TIME 10000u /*time in us, means 10 ms */
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* External variables --------------------------------------------------------*/
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
void USBPD_TIM_Init(void);
|
||||
void USBPD_TIM_DeInit(void);
|
||||
void USBPD_TIM_Start(TIM_identifier Id, uint32_t TimeUs);
|
||||
uint32_t USBPD_TIM_IsExpired(TIM_identifier Id);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_TIMERSSERVER_H_ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_phy_hw_if.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains phy interface control functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#define USBPD_HW_C
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_devices_conf.h"
|
||||
#include "usbpd_hw.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Variable containing ADC conversions results */
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
UCPD_TypeDef *USBPD_HW_GetUSPDInstance(uint8_t PortNum)
|
||||
{
|
||||
return UCPD_INSTANCE0;
|
||||
}
|
||||
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
DMA_Channel_TypeDef *USBPD_HW_Init_DMARxInstance(uint8_t PortNum)
|
||||
{
|
||||
LL_DMA_InitTypeDef DMA_InitStruct;
|
||||
|
||||
/* Initialise the DMA */
|
||||
LL_DMA_StructInit(&DMA_InitStruct);
|
||||
DMA_InitStruct.Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY;
|
||||
DMA_InitStruct.Mode = LL_DMA_MODE_NORMAL;
|
||||
DMA_InitStruct.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
||||
DMA_InitStruct.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
|
||||
DMA_InitStruct.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_BYTE;
|
||||
DMA_InitStruct.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_BYTE;
|
||||
DMA_InitStruct.NbData = 0;
|
||||
DMA_InitStruct.MemoryOrM2MDstAddress = 0x0;
|
||||
DMA_InitStruct.PeriphOrM2MSrcAddress = 0x0;
|
||||
DMA_InitStruct.Priority = LL_DMA_PRIORITY_HIGH;
|
||||
|
||||
/* Enable the clock */
|
||||
UCPDDMA_INSTANCE0_CLOCKENABLE_RX;
|
||||
|
||||
/* Initialise the DMA */
|
||||
DMA_InitStruct.PeriphRequest = UCPDDMA_INSTANCE0_REQUEST_RX;
|
||||
|
||||
(void)LL_DMA_Init(UCPDDMA_INSTANCE0_DMA_RX, UCPDDMA_INSTANCE0_LL_CHANNEL_RX, &DMA_InitStruct);
|
||||
return UCPDDMA_INSTANCE0_CHANNEL_RX;
|
||||
}
|
||||
|
||||
void USBPD_HW_DeInit_DMARxInstance(uint8_t PortNum)
|
||||
{
|
||||
(void)PortNum;
|
||||
}
|
||||
|
||||
DMA_Channel_TypeDef *USBPD_HW_Init_DMATxInstance(uint8_t PortNum)
|
||||
{
|
||||
LL_DMA_InitTypeDef DMA_InitStruct;
|
||||
|
||||
/* Initialise the DMA */
|
||||
LL_DMA_StructInit(&DMA_InitStruct);
|
||||
DMA_InitStruct.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
|
||||
DMA_InitStruct.Mode = LL_DMA_MODE_NORMAL;
|
||||
DMA_InitStruct.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
||||
DMA_InitStruct.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
|
||||
DMA_InitStruct.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_BYTE;
|
||||
DMA_InitStruct.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_BYTE;
|
||||
DMA_InitStruct.NbData = 0;
|
||||
DMA_InitStruct.MemoryOrM2MDstAddress = 0x0;
|
||||
DMA_InitStruct.PeriphOrM2MSrcAddress = 0x0;
|
||||
|
||||
/* Enable the clock */
|
||||
UCPDDMA_INSTANCE0_CLOCKENABLE_TX;
|
||||
|
||||
DMA_InitStruct.PeriphRequest = UCPDDMA_INSTANCE0_REQUEST_TX;
|
||||
DMA_InitStruct.Priority = LL_DMA_PRIORITY_MEDIUM;
|
||||
(void)LL_DMA_Init(UCPDDMA_INSTANCE0_DMA_TX, UCPDDMA_INSTANCE0_LL_CHANNEL_TX, &DMA_InitStruct);
|
||||
return UCPDDMA_INSTANCE0_CHANNEL_TX;
|
||||
}
|
||||
|
||||
void USBPD_HW_DeInit_DMATxInstance(uint8_t PortNum)
|
||||
{
|
||||
(void)PortNum;
|
||||
}
|
||||
#endif /* !USBPDCORE_LIB_NO_PD */
|
||||
|
||||
uint32_t USBPD_HW_GetRpResistorValue(uint8_t PortNum)
|
||||
{
|
||||
(void)PortNum;
|
||||
return LL_UCPD_RESISTOR_3_0A;
|
||||
}
|
||||
|
||||
void USBPD_HW_SetFRSSignalling(uint8_t PortNum, uint8_t cc)
|
||||
{
|
||||
(void)PortNum;
|
||||
|
||||
/* Configure FRSTX GPIO */
|
||||
if (1u == cc)
|
||||
{
|
||||
/* FRS_TX common */
|
||||
UCPDFRS_INSTANCE0_FRSCC1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* FRS_TX common */
|
||||
UCPDFRS_INSTANCE0_FRSCC2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_hw_if_it.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains HW interface interrupt routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_devices_conf.h"
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_hw_if.h"
|
||||
#include "usbpd_trace.h"
|
||||
#if defined(_LOW_POWER)
|
||||
#include "usbpd_lowpower.h"
|
||||
#endif /* _LOW_POWER */
|
||||
#if defined(_FRS)
|
||||
#include "usbpd_timersserver.h"
|
||||
#endif /* _FRS */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
void PORTx_IRQHandler(uint8_t PortNum);
|
||||
|
||||
void USBPD_PORT0_IRQHandler(void)
|
||||
{
|
||||
PORTx_IRQHandler(USBPD_PORT_0);
|
||||
}
|
||||
|
||||
void PORTx_IRQHandler(uint8_t PortNum)
|
||||
{
|
||||
UCPD_TypeDef *hucpd = Ports[PortNum].husbpd;
|
||||
uint32_t _interrupt = LL_UCPD_ReadReg(hucpd, SR);
|
||||
static uint8_t ovrflag = 0;
|
||||
|
||||
if ((hucpd->IMR & _interrupt) != 0u)
|
||||
{
|
||||
/* TXIS no need to enable it all the transfer are done by DMA */
|
||||
if (UCPD_SR_TXMSGDISC == (_interrupt & UCPD_SR_TXMSGDISC))
|
||||
{
|
||||
/* Message has been discarded */
|
||||
LL_UCPD_ClearFlag_TxMSGDISC(hucpd);
|
||||
CLEAR_BIT(Ports[PortNum].hdmatx->CCR, DMA_CCR_EN);
|
||||
while ((Ports[PortNum].hdmatx->CCR & DMA_CCR_EN) == DMA_CCR_EN);
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_TxCompleted(PortNum, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UCPD_SR_TXMSGSENT == (_interrupt & UCPD_SR_TXMSGSENT))
|
||||
{
|
||||
/* Message has been fully transferred */
|
||||
LL_UCPD_ClearFlag_TxMSGSENT(hucpd);
|
||||
CLEAR_BIT(Ports[PortNum].hdmatx->CCR, DMA_CCR_EN);
|
||||
while ((Ports[PortNum].hdmatx->CCR & DMA_CCR_EN) == DMA_CCR_EN);
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_TxCompleted(PortNum, 0);
|
||||
|
||||
#if defined(_LOW_POWER)
|
||||
UTIL_LPM_SetStopMode(0 == PortNum ? LPM_PE_0 : LPM_PE_1, UTIL_LPM_ENABLE);
|
||||
#endif /* _LOW_POWER */
|
||||
return;
|
||||
}
|
||||
|
||||
if (UCPD_SR_TXMSGABT == (_interrupt & UCPD_SR_TXMSGABT))
|
||||
{
|
||||
LL_UCPD_ClearFlag_TxMSGABT(hucpd);
|
||||
CLEAR_BIT(Ports[PortNum].hdmatx->CCR, DMA_CCR_EN);
|
||||
while ((Ports[PortNum].hdmatx->CCR & DMA_CCR_EN) == DMA_CCR_EN);
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_TxCompleted(PortNum, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
/* HRSTDISC : hard reset sending has been discarded */
|
||||
if (UCPD_SR_HRSTDISC == (_interrupt & UCPD_SR_HRSTDISC))
|
||||
{
|
||||
LL_UCPD_ClearFlag_TxHRSTDISC(hucpd);
|
||||
return;
|
||||
}
|
||||
|
||||
/* TXUND : tx underrun detected */
|
||||
if (UCPD_SR_HRSTSENT == (_interrupt & UCPD_SR_HRSTSENT))
|
||||
{
|
||||
/* Answer not expected by the stack */
|
||||
LL_UCPD_ClearFlag_TxHRSTSENT(hucpd);
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_TX_HardResetCompleted(PortNum, USBPD_SOPTYPE_HARD_RESET);
|
||||
return;
|
||||
}
|
||||
|
||||
/* TXUND : tx underrun detected */
|
||||
if (UCPD_SR_TXUND == (_interrupt & UCPD_SR_TXUND))
|
||||
{
|
||||
/* Nothing to do.
|
||||
The port partner checks the message integrity with CRC, so PRL will repeat the sending.
|
||||
Can be used for debugging purpose */
|
||||
LL_UCPD_ClearFlag_TxUND(hucpd);
|
||||
return;
|
||||
}
|
||||
|
||||
/* RXNE : not needed the stack only perform transfer by DMA */
|
||||
/* RXORDDET: not needed so stack will not enabled this interrupt */
|
||||
if (UCPD_SR_RXORDDET == (_interrupt & UCPD_SR_RXORDDET))
|
||||
{
|
||||
if (LL_UCPD_RXORDSET_CABLE_RESET == hucpd->RX_ORDSET)
|
||||
{
|
||||
/* Cable reset detected */
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_RX_ResetIndication(PortNum, USBPD_SOPTYPE_CABLE_RESET);
|
||||
}
|
||||
LL_UCPD_ClearFlag_RxOrderSet(hucpd);
|
||||
#if defined(_LOW_POWER)
|
||||
UTIL_LPM_SetStopMode(0 == PortNum ? LPM_PE_0 : LPM_PE_1, UTIL_LPM_DISABLE);
|
||||
#endif /* _LOW_POWER */
|
||||
|
||||
/* Forbid message sending */
|
||||
Ports[PortNum].RXStatus = USBPD_TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check RXHRSTDET */
|
||||
if (UCPD_SR_RXHRSTDET == (_interrupt & UCPD_SR_RXHRSTDET))
|
||||
{
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_RX_ResetIndication(PortNum, USBPD_SOPTYPE_HARD_RESET);
|
||||
LL_UCPD_ClearFlag_RxHRST(hucpd);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check RXOVR */
|
||||
if (UCPD_SR_RXOVR == (_interrupt & UCPD_SR_RXOVR))
|
||||
{
|
||||
/* Nothing to do, the message will be discarded and port Partner will try sending again. */
|
||||
ovrflag = 1;
|
||||
LL_UCPD_ClearFlag_RxOvr(hucpd);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check RXMSGEND an Rx message has been received */
|
||||
if (UCPD_SR_RXMSGEND == (_interrupt & UCPD_SR_RXMSGEND))
|
||||
{
|
||||
Ports[PortNum].RXStatus = USBPD_FALSE;
|
||||
|
||||
/* For DMA mode, add a check to ensure the number of data received matches
|
||||
the number of data received by UCPD */
|
||||
LL_UCPD_ClearFlag_RxMsgEnd(hucpd);
|
||||
|
||||
/* Disable DMA */
|
||||
CLEAR_BIT(Ports[PortNum].hdmarx->CCR, DMA_CCR_EN);
|
||||
while ((Ports[PortNum].hdmarx->CCR & DMA_CCR_EN) == DMA_CCR_EN);
|
||||
|
||||
/* Ready for next transaction */
|
||||
WRITE_REG(Ports[PortNum].hdmarx->CMAR, (uint32_t)Ports[PortNum].ptr_RxBuff);
|
||||
WRITE_REG(Ports[PortNum].hdmarx->CNDTR, SIZE_MAX_PD_TRANSACTION_UNCHUNK);
|
||||
|
||||
/* Enable the DMA */
|
||||
SET_BIT(Ports[PortNum].hdmarx->CCR, DMA_CCR_EN);
|
||||
#if defined(_LOW_POWER)
|
||||
UTIL_LPM_SetStopMode(0 == PortNum ? LPM_PE_0 : LPM_PE_1, UTIL_LPM_ENABLE);
|
||||
#endif /* _LOW_POWER */
|
||||
|
||||
if (((_interrupt & UCPD_SR_RXERR) == 0u) && (ovrflag == 0u))
|
||||
{
|
||||
/* Rx message has been received without error */
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_RX_Completed(PortNum, hucpd->RX_ORDSET & UCPD_RX_ORDSET_RXORDSET);
|
||||
}
|
||||
ovrflag = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check TYPECEVT1IE/TYPECEVT1IE || check TYPECEVT2IE/TYPECEVT2IE */
|
||||
if ((UCPD_SR_TYPECEVT1 == (_interrupt & UCPD_SR_TYPECEVT1))
|
||||
|| (UCPD_SR_TYPECEVT2 == (_interrupt & UCPD_SR_TYPECEVT2)))
|
||||
{
|
||||
/* Clear both interrupt */
|
||||
LL_UCPD_ClearFlag_TypeCEventCC1(hucpd);
|
||||
LL_UCPD_ClearFlag_TypeCEventCC2(hucpd);
|
||||
Ports[PortNum].USBPD_CAD_WakeUp();
|
||||
/* Wakeup CAD to check the detection event */
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(_FRS)
|
||||
/* Check FRSEVTIE */
|
||||
if (UCPD_SR_FRSEVT == (_interrupt & UCPD_SR_FRSEVT))
|
||||
{
|
||||
LL_UCPD_ClearFlag_FRS(hucpd);
|
||||
if ((USBPD_PORTPOWERROLE_SNK == Ports[PortNum].params->PE_PowerRole)
|
||||
&& (Ports[PortNum].params->PE_SwapOngoing == USBPD_FALSE))
|
||||
{
|
||||
/* Confirm the FRS by checking if an RP is always present on the current CC line.
|
||||
We should wait for maximum FRS timing */
|
||||
USBPD_TIM_Start((TIM_identifier)(2 * PortNum), 150);
|
||||
while ((USBPD_TIM_IsExpired((TIM_identifier)(2u * PortNum)) == 0u));
|
||||
|
||||
if ((0 != (hucpd->SR & (UCPD_SR_TYPEC_VSTATE_CC1 | UCPD_SR_TYPEC_VSTATE_CC2))) &&
|
||||
(USBPD_POWER_EXPLICITCONTRACT == Ports[PortNum].params->PE_Power))
|
||||
{
|
||||
/* Switch the power to take the control of VBUS.
|
||||
When VBUS go under VSAFE5V the sink shall switch ON VBUS in timing < tSrcFRSwap */
|
||||
BSP_USBPD_PWR_FRSVBUSEnable(PortNum);
|
||||
USBPD_TRACE_Add(USBPD_TRACE_DEBUG, PortNum, 0, "FRS received", 12u);
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_TX_FRSReception(PortNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* _FRS */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,390 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_phy.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains PHY layer functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_def.h"
|
||||
#include "usbpd_phy.h"
|
||||
#include "usbpd_hw_if.h"
|
||||
#include "usbpd_pwr_if.h"
|
||||
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_PHY
|
||||
* @brief This file contains PHY layer functions.
|
||||
* @details Receive from PRL a message and create a structured packet (according to the USBPD specifications):
|
||||
* |SOP|DATA:[HEADER|DATAOBJECTS]|CRC|EOP|
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/** @defgroup USBPD_DEVICE_PHY_Private_typedef USBPD DEVICE PHY Private typedef
|
||||
* @brief Structures and enums internally used by the PHY layer
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle to support the data of the layer
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
* @brief Reports that a message has been received on a specified port.
|
||||
* @note Received data are stored inside PortNum->pRxBuffPtr
|
||||
* function called in the interrupt context
|
||||
* @param PortNum The handle of the port
|
||||
* @param Type The type of the message received @ref USBPD_SOPType_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
void (*USBPD_PHY_MessageReceived)(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
|
||||
uint32_t SupportedSOP; /*!<bit field SOP"Debug SOP'Debug SOP" SOP' SOP */
|
||||
} PHY_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* @brief prototype definition shared in several callbacks
|
||||
*/
|
||||
typedef void (*PHY_CB_t)(uint8_t PortNum, USBPD_SOPType_TypeDef Type); /*!< Common callback definition */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private define and macro --------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/** @defgroup USBPD_DEVICE_PHY_Private_variables USBPD DEVICE PHY Private variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Internal struct for RXTX */
|
||||
static PHY_HandleTypeDef PHY_Ports[USBPD_PORT_COUNT];
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @defgroup USBPD_DEVICE_PHY_Private_functions USBPD DEVICE PHY Private functions
|
||||
* @{
|
||||
*/
|
||||
USBPD_StatusTypeDef PHY_PortInit(uint8_t PortNum, const USBPD_PHY_Callbacks *cbs, uint8_t *pRxBuffer,
|
||||
uint32_t SupportedSOP);
|
||||
void PHY_ResetCompleted(uint8_t PortNum, USBPD_SOPType_TypeDef Type);
|
||||
void PHY_Rx_HardReset(uint8_t PortNum);
|
||||
void PHY_Rx_Completed(uint8_t PortNum, uint32_t MsgType);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup USBPD_DEVICE_PHY_Exported_Functions USBPD DEVICE PHY Exported functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Initialize the PHY of a specified port.
|
||||
* @param PortNum Number of the port.
|
||||
* @param pCallbacks PHY callbacks
|
||||
* @param pRxBuffer Buffer to storage received message.
|
||||
* @param PowerRole Power Role of the board.
|
||||
* @param SupportedSOP bit field of the supported SOP
|
||||
* @retval status @ref USBPD_OK
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_Init(uint8_t PortNum, const USBPD_PHY_Callbacks *pCallbacks, uint8_t *pRxBuffer,
|
||||
USBPD_PortPowerRole_TypeDef PowerRole, uint32_t SupportedSOP)
|
||||
{
|
||||
(void)PowerRole;
|
||||
|
||||
/* Set all callbacks */
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_TxCompleted = pCallbacks->USBPD_PHY_TxCompleted;
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_BistCompleted = pCallbacks->USBPD_PHY_BistCompleted;
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_RX_ResetIndication = pCallbacks->USBPD_PHY_ResetIndication;
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_RX_Completed = PHY_Rx_Completed;
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_TX_HardResetCompleted = pCallbacks->USBPD_PHY_ResetCompleted;
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_TX_FRSReception = pCallbacks->USBPD_PHY_FastRoleSwapReception;
|
||||
/* Initialize the hardware for the port */
|
||||
Ports[PortNum].ptr_RxBuff = pRxBuffer;
|
||||
|
||||
/* Initialize port related functionalities inside this layer */
|
||||
PHY_Ports[PortNum].SupportedSOP = SupportedSOP;
|
||||
PHY_Ports[PortNum].USBPD_PHY_MessageReceived = pCallbacks->USBPD_PHY_MessageReceived;
|
||||
|
||||
return USBPD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function return the retry counter value in us.
|
||||
* @note time used to determine when the protocol layer must re-send a message not acknowledged by a goodCRC
|
||||
* @param PortNum Number of the port.
|
||||
* @retval retry counter value in us.
|
||||
*/
|
||||
uint16_t USBPD_PHY_GetRetryTimerValue(uint8_t PortNum)
|
||||
{
|
||||
(void)PortNum;
|
||||
return 905u;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function return the min time to wait before sending a goodCRC to ack a message (in us).
|
||||
* @note time used to guarantee the min time of 26us between two PD message.
|
||||
* @param PortNum Number of the port.
|
||||
* @retval value in us.
|
||||
*/
|
||||
uint16_t USBPD_PHY_GetMinGOODCRCTimerValue(uint8_t PortNum)
|
||||
{
|
||||
return 30u;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the PHY of a specified port.
|
||||
* @param PortNum Number of the port.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PHY_Reset(uint8_t PortNum)
|
||||
{
|
||||
(void)PortNum;
|
||||
/* Reset PHY layer */
|
||||
/* Reset HW_IF layer */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request to send a reset on a port.
|
||||
* @param PortNum Number of the port
|
||||
* @param Type Type of reset (hard or cable reset) @ref USBPD_SOPTYPE_HARD_RESET or @ref USBPD_SOPTYPE_CABLE_RESET
|
||||
* @retval status @ref USBPD_OK
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_ResetRequest(uint8_t PortNum, USBPD_SOPType_TypeDef Type)
|
||||
{
|
||||
/* Send the requested reset */
|
||||
return USBPD_PHY_SendMessage(PortNum, Type, NULL, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send a Message.
|
||||
* @param PortNum Number of the port
|
||||
* @param Type Type of the message
|
||||
* @param pBuffer Pointer to the buffer to be transmitted
|
||||
* @param Size Size of the buffer (bytes)
|
||||
* @retval status @ref USBPD_OK
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_SendMessage(uint8_t PortNum, USBPD_SOPType_TypeDef Type, uint8_t *pBuffer, uint16_t Size)
|
||||
{
|
||||
/* Trace to track message */
|
||||
return USBPD_HW_IF_SendBuffer(PortNum, Type, pBuffer, Size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send BIST pattern.
|
||||
* @param PortNum Number of the port
|
||||
* @retval status @ref USBPD_OK
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_Send_BIST_Pattern(uint8_t PortNum)
|
||||
{
|
||||
/* Call the low-level function (HW_IF) to accomplish the BIST Carrier Mode Transmission */
|
||||
USBPD_HW_IF_Send_BIST_Pattern(PortNum);
|
||||
return USBPD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request PHY to exit of BIST mode 2
|
||||
* @param PortNum port number value
|
||||
* @param mode SOP BIST MODE 2
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PHY_ExitTransmit(uint8_t PortNum, USBPD_SOPType_TypeDef mode)
|
||||
{
|
||||
if (USBPD_SOPTYPE_BIST_MODE_2 == mode)
|
||||
{
|
||||
USBPD_HW_IF_StopBISTMode2(PortNum);
|
||||
}
|
||||
return USBPD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the SinkTxNg value of the resistor,
|
||||
* @note used to manage the collision avoidance
|
||||
* @param PortNum Number of the port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PHY_SetResistor_SinkTxNG(uint8_t PortNum)
|
||||
{
|
||||
USBPD_HW_IF_SetResistor_SinkTxNG(PortNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function to set the SinkTxOK
|
||||
* @note used to manage the collision avoidance
|
||||
* @param PortNum Number of the port.
|
||||
* @retval none.
|
||||
*/
|
||||
void USBPD_PHY_SetResistor_SinkTxOK(uint8_t PortNum)
|
||||
{
|
||||
USBPD_HW_IF_SetResistor_SinkTxOK(PortNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function to set the supported SOP
|
||||
* @param PortNum Number of the port.
|
||||
* @param SOPSupported List of the supported SOP
|
||||
* @retval None.
|
||||
*/
|
||||
void USBPD_PHY_SOPSupported(uint8_t PortNum, uint32_t SOPSupported)
|
||||
{
|
||||
PHY_Ports[PortNum].SupportedSOP = SOPSupported;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if SinkTxOK is set or not
|
||||
* @note used to manage the collision avoidance
|
||||
* @param PortNum Number of the port.
|
||||
* @retval USBPD_TRUE or USBPD_FALSE
|
||||
*/
|
||||
uint8_t USBPD_PHY_IsResistor_SinkTxOk(uint8_t PortNum)
|
||||
{
|
||||
return USBPD_HW_IF_IsResistor_SinkTxOk(PortNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function to generate an FRS signalling
|
||||
* @param PortNum Number of the port.
|
||||
* @retval None.
|
||||
*/
|
||||
void USBPD_PHY_FastRoleSwapSignalling(uint8_t PortNum)
|
||||
{
|
||||
USBPD_HW_IF_FastRoleSwapSignalling(PortNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function used to enable RX
|
||||
* @param PortNum Number of the port.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PHY_EnableRX(uint8_t PortNum)
|
||||
{
|
||||
USBPD_HW_IF_EnableRX(PortNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function used to disable RX
|
||||
* @param PortNum Number of the port.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PHY_DisableRX(uint8_t PortNum)
|
||||
{
|
||||
USBPD_HW_IF_DisableRX(PortNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_PHY_Private_functions
|
||||
* @brief PHY internally used functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Callback to notify the end of the current reception
|
||||
* @param PortNum Number of the port.
|
||||
* @param MsgType SOP Message Type
|
||||
* @retval None.
|
||||
*/
|
||||
void PHY_Rx_Completed(uint8_t PortNum, uint32_t MsgType)
|
||||
{
|
||||
const USBPD_SOPType_TypeDef tab_sop_value[] =
|
||||
{
|
||||
USBPD_SOPTYPE_SOP, USBPD_SOPTYPE_SOP1, USBPD_SOPTYPE_SOP2,
|
||||
USBPD_SOPTYPE_SOP1_DEBUG, USBPD_SOPTYPE_SOP2_DEBUG, USBPD_SOPTYPE_CABLE_RESET
|
||||
};
|
||||
USBPD_SOPType_TypeDef _msgtype;
|
||||
|
||||
_msgtype = tab_sop_value[MsgType];
|
||||
|
||||
/* Check if the message must be forwarded to usbpd stack */
|
||||
switch (_msgtype)
|
||||
{
|
||||
case USBPD_SOPTYPE_CABLE_RESET :
|
||||
if (0x1Eu == (PHY_Ports[PortNum].SupportedSOP & 0x1Eu))
|
||||
{
|
||||
/* Nothing to do the message will be discarded and the port partner retry the send */
|
||||
Ports[PortNum].cbs.USBPD_HW_IF_RX_ResetIndication(PortNum, USBPD_SOPTYPE_CABLE_RESET);
|
||||
}
|
||||
break;
|
||||
case USBPD_SOPTYPE_SOP :
|
||||
case USBPD_SOPTYPE_SOP1 :
|
||||
case USBPD_SOPTYPE_SOP2 :
|
||||
case USBPD_SOPTYPE_SOP1_DEBUG :
|
||||
case USBPD_SOPTYPE_SOP2_DEBUG :
|
||||
if (!((uint8_t)(0x1u << _msgtype) != (PHY_Ports[PortNum].SupportedSOP & (uint8_t)(0x1u << _msgtype))))
|
||||
{
|
||||
PHY_Ports[PortNum].USBPD_PHY_MessageReceived(PortNum, _msgtype);
|
||||
}
|
||||
#if defined(DEBUG_NOTFWD)
|
||||
else
|
||||
{
|
||||
typedef union
|
||||
{
|
||||
uint16_t d16;
|
||||
struct
|
||||
{
|
||||
uint16_t MessageType :5; /*!< Message Header's message Type */
|
||||
uint16_t PortDataRole :1; /*!< Message Header's Port Data Role */
|
||||
uint16_t SpecificationRevision :2; /*!< Message Header's Spec Revision */
|
||||
uint16_t PortPowerRole_CablePlug:1; /*!< Message Header's Port Power Role/Cable Plug field */
|
||||
uint16_t MessageID :3; /*!< Message Header's message ID */
|
||||
uint16_t NumberOfDataObjects :3; /*!< Message Header's Number of data object */
|
||||
uint16_t Extended :1; /*!< Reserved */
|
||||
}
|
||||
b;
|
||||
} USBPD_MsgHeader_TypeDef;
|
||||
|
||||
USBPD_MsgHeader_TypeDef header_rx;
|
||||
header_rx.d16 = USBPD_LE16(Ports[PortNum].ptr_RxBuff);
|
||||
USBPD_TRACE_Add(USBPD_TRACE_PHY_NOTFRWD, PortNum, _msgtype, Ports[PortNum].ptr_RxBuff,
|
||||
2u + (header_rx.b.NumberOfDataObjects * 4u));
|
||||
}
|
||||
#endif /* DEBUG_NOTFWD */
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,509 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_phy_hw_if.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains phy interface control functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#define USBPD_PHY_HW_IF_C
|
||||
|
||||
#include "usbpd_devices_conf.h"
|
||||
#include "usbpd_hw.h"
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_hw_if.h"
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
#include "usbpd_timersserver.h"
|
||||
#endif /* !USBPDCORE_LIB_NO_PD */
|
||||
#if defined(_LOW_POWER)
|
||||
#include "usbpd_lowpower.h"
|
||||
#include "usbpd_cad_hw_if.h"
|
||||
#endif /* _LOW_POWER */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
#define PHY_ENTER_CRITICAL_SECTION() uint32_t primask = __get_PRIMASK(); \
|
||||
__disable_irq();
|
||||
|
||||
#define PHY_LEAVE_CRITICAL_SECTION() __set_PRIMASK(primask);
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
USBPD_PORT_HandleTypeDef Ports[USBPD_PORT_COUNT];
|
||||
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
|
||||
void USBPD_HW_IF_GlobalHwInit(void)
|
||||
{
|
||||
/* PWR register access (for disabling dead battery feature) */
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_CRC);
|
||||
|
||||
}
|
||||
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
void USBPD_HW_IF_StopBISTMode2(uint8_t PortNum)
|
||||
{
|
||||
uint32_t _cr = READ_REG(Ports[PortNum].husbpd->CR) & ~(UCPD_CR_TXMODE | UCPD_CR_TXSEND);
|
||||
|
||||
LL_UCPD_Disable(Ports[PortNum].husbpd);
|
||||
LL_UCPD_Enable(Ports[PortNum].husbpd);
|
||||
|
||||
Ports[PortNum].husbpd->CR = _cr;
|
||||
}
|
||||
|
||||
USBPD_StatusTypeDef USBPD_HW_IF_SendBuffer(uint8_t PortNum, USBPD_SOPType_TypeDef Type, uint8_t *pBuffer, uint32_t Size)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_OK;
|
||||
|
||||
if (USBPD_SOPTYPE_HARD_RESET == Type)
|
||||
{
|
||||
LL_UCPD_SendHardReset(Ports[PortNum].husbpd);
|
||||
}
|
||||
else
|
||||
{
|
||||
PHY_ENTER_CRITICAL_SECTION()
|
||||
|
||||
/* If RX is ongoing or if a DMA transfer is active then discard the buffer sending */
|
||||
if ((Ports[PortNum].RXStatus == USBPD_TRUE) || ((Ports[PortNum].hdmatx->CCR & DMA_CCR_EN) == DMA_CCR_EN))
|
||||
{
|
||||
PHY_LEAVE_CRITICAL_SECTION()
|
||||
_status = USBPD_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
PHY_LEAVE_CRITICAL_SECTION()
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case USBPD_SOPTYPE_SOP :
|
||||
{
|
||||
LL_UCPD_WriteTxOrderSet(Ports[PortNum].husbpd, LL_UCPD_ORDERED_SET_SOP);
|
||||
LL_UCPD_SetTxMode(Ports[PortNum].husbpd, LL_UCPD_TXMODE_NORMAL);
|
||||
break;
|
||||
}
|
||||
case USBPD_SOPTYPE_SOP1 :
|
||||
{
|
||||
LL_UCPD_WriteTxOrderSet(Ports[PortNum].husbpd, LL_UCPD_ORDERED_SET_SOP1);
|
||||
LL_UCPD_SetTxMode(Ports[PortNum].husbpd, LL_UCPD_TXMODE_NORMAL);
|
||||
break;
|
||||
}
|
||||
case USBPD_SOPTYPE_SOP2 :
|
||||
{
|
||||
LL_UCPD_WriteTxOrderSet(Ports[PortNum].husbpd, LL_UCPD_ORDERED_SET_SOP2);
|
||||
LL_UCPD_SetTxMode(Ports[PortNum].husbpd, LL_UCPD_TXMODE_NORMAL);
|
||||
break;
|
||||
}
|
||||
case USBPD_SOPTYPE_CABLE_RESET :
|
||||
{
|
||||
LL_UCPD_SetTxMode(Ports[PortNum].husbpd, LL_UCPD_TXMODE_CABLE_RESET);
|
||||
break;
|
||||
}
|
||||
case USBPD_SOPTYPE_BIST_MODE_2 :
|
||||
{
|
||||
LL_UCPD_SetTxMode(Ports[PortNum].husbpd, LL_UCPD_TXMODE_BIST_CARRIER2);
|
||||
break;
|
||||
}
|
||||
default :
|
||||
_status = USBPD_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
if (USBPD_OK == _status)
|
||||
{
|
||||
#if defined(_LOW_POWER)
|
||||
UTIL_LPM_SetStopMode(0 == PortNum ? LPM_PE_0 : LPM_PE_1, UTIL_LPM_DISABLE);
|
||||
#endif /* _LOW_POWER */
|
||||
CLEAR_BIT(Ports[PortNum].hdmatx->CCR, DMA_CCR_EN);
|
||||
while ((Ports[PortNum].hdmatx->CCR & DMA_CCR_EN) == DMA_CCR_EN);
|
||||
|
||||
WRITE_REG(Ports[PortNum].hdmatx->CMAR, (uint32_t)pBuffer);
|
||||
WRITE_REG(Ports[PortNum].hdmatx->CNDTR, Size);
|
||||
SET_BIT(Ports[PortNum].hdmatx->CCR, DMA_CCR_EN);
|
||||
|
||||
LL_UCPD_WriteTxPaySize(Ports[PortNum].husbpd, Size);
|
||||
LL_UCPD_SendMessage(Ports[PortNum].husbpd);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _status;
|
||||
}
|
||||
|
||||
void USBPD_HW_IF_Send_BIST_Pattern(uint8_t PortNum)
|
||||
{
|
||||
LL_UCPD_SetTxMode(Ports[PortNum].husbpd, LL_UCPD_TXMODE_BIST_CARRIER2);
|
||||
LL_UCPD_SendMessage(Ports[PortNum].husbpd);
|
||||
}
|
||||
#endif /* !USBPDCORE_LIB_NO_PD */
|
||||
|
||||
/**
|
||||
* @brief Assert Rp resistors
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_AssertRp(uint8_t PortNum)
|
||||
{
|
||||
switch (Ports[PortNum].params->RpResistor)
|
||||
{
|
||||
case vRp_Default :
|
||||
LL_UCPD_SetRpResistor(Ports[PortNum].husbpd, LL_UCPD_RESISTOR_DEFAULT);
|
||||
break;
|
||||
case vRp_1_5A:
|
||||
LL_UCPD_SetRpResistor(Ports[PortNum].husbpd, LL_UCPD_RESISTOR_1_5A);
|
||||
break;
|
||||
case vRp_3_0A:
|
||||
LL_UCPD_SetRpResistor(Ports[PortNum].husbpd, LL_UCPD_RESISTOR_3_0A);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd, LL_UCPD_CCENABLE_NONE);
|
||||
LL_UCPD_SetSRCRole(Ports[PortNum].husbpd);
|
||||
if (CCNONE == Ports[PortNum].CCx)
|
||||
{
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd, LL_UCPD_CCENABLE_CC1CC2);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd,
|
||||
(Ports[PortNum].CCx == CC1) ? LL_UCPD_CCENABLE_CC1 : LL_UCPD_CCENABLE_CC2);
|
||||
}
|
||||
|
||||
#if defined(TCPP0203_SUPPORT)
|
||||
BSP_USBPD_PWR_SetRole(PortNum, POWER_ROLE_SOURCE);
|
||||
#endif /* TCPP0203_SUPPORT */
|
||||
}
|
||||
/**
|
||||
* @brief De-assert Rp resistors
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_DeAssertRp(uint8_t PortNum)
|
||||
{
|
||||
/* Not needed on STM32G4xx, so nothing to do, keep only for compatibility */
|
||||
UNUSED(PortNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assert Rd resistors
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_AssertRd(uint8_t PortNum)
|
||||
{
|
||||
LL_UCPD_TypeCDetectionCC2Disable(Ports[PortNum].husbpd);
|
||||
LL_UCPD_TypeCDetectionCC1Disable(Ports[PortNum].husbpd);
|
||||
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd, LL_UCPD_CCENABLE_NONE);
|
||||
LL_UCPD_SetSNKRole(Ports[PortNum].husbpd);
|
||||
if (CCNONE == Ports[PortNum].CCx)
|
||||
{
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd, LL_UCPD_CCENABLE_CC1CC2);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd,
|
||||
(Ports[PortNum].CCx == CC1) ? LL_UCPD_CCENABLE_CC1 : LL_UCPD_CCENABLE_CC2);
|
||||
}
|
||||
|
||||
HAL_Delay(1);
|
||||
|
||||
#ifndef _LOW_POWER
|
||||
LL_UCPD_TypeCDetectionCC2Enable(Ports[PortNum].husbpd);
|
||||
LL_UCPD_TypeCDetectionCC1Enable(Ports[PortNum].husbpd);
|
||||
#endif /* _LOW_POWER */
|
||||
|
||||
#if defined(TCPP0203_SUPPORT)
|
||||
BSP_USBPD_PWR_SetRole(PortNum, POWER_ROLE_SINK);
|
||||
#endif /* TCPP0203_SUPPORT */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assert Rd resistors
|
||||
* @param PortNum Port
|
||||
* @retval none
|
||||
*/
|
||||
void USBPDM1_DeAssertRd(uint8_t PortNum)
|
||||
{
|
||||
/* Not needed on STM32G4xx, so nothing to do, keep only for compatibility */
|
||||
UNUSED(PortNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter error recovery
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_EnterErrorRecovery(uint8_t PortNum)
|
||||
{
|
||||
LL_UCPD_SetSRCRole(Ports[PortNum].husbpd);
|
||||
LL_UCPD_SetRpResistor(Ports[PortNum].husbpd, LL_UCPD_RESISTOR_NONE);
|
||||
LL_UCPD_RxDisable(Ports[PortNum].husbpd);
|
||||
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
if (Ports[PortNum].settings->PE_PD3_Support.d.PE_FastRoleSwapSupport == USBPD_TRUE)
|
||||
{
|
||||
/* Set GPIO to disallow the FRS RX handling */
|
||||
LL_UCPD_FRSDetectionDisable(Ports[PortNum].husbpd);
|
||||
}
|
||||
#endif /* USBPDCORE_LIB_NO_PD */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the correct CC pin on the comparator
|
||||
* @param PortNum Port
|
||||
* @param cc CC pin based on @ref CCxPin_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_Set_CC(uint8_t PortNum, CCxPin_TypeDef cc)
|
||||
{
|
||||
/* Set the correct pin on the comparator */
|
||||
Ports[PortNum].CCx = cc;
|
||||
LL_UCPD_SetCCPin(Ports[PortNum].husbpd, (cc == CC1) ? LL_UCPD_CCPIN_CC1 : LL_UCPD_CCPIN_CC2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable RX interrupt
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPDM1_RX_EnableInterrupt(uint8_t PortNum)
|
||||
{
|
||||
/* Enable the RX interrupt process */
|
||||
MODIFY_REG(Ports[PortNum].husbpd->IMR,
|
||||
UCPD_IMR_RXORDDETIE | UCPD_IMR_RXHRSTDETIE | UCPD_IMR_RXOVRIE | UCPD_IMR_RXMSGENDIE,
|
||||
UCPD_IMR_RXORDDETIE | UCPD_IMR_RXHRSTDETIE | UCPD_IMR_RXOVRIE | UCPD_IMR_RXMSGENDIE);
|
||||
LL_UCPD_RxDMAEnable(Ports[PortNum].husbpd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable RX
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_EnableRX(uint8_t PortNum)
|
||||
{
|
||||
LL_UCPD_RxEnable(Ports[PortNum].husbpd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable RX
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_DisableRX(uint8_t PortNum)
|
||||
{
|
||||
LL_UCPD_RxDisable(Ports[PortNum].husbpd);
|
||||
}
|
||||
|
||||
void HW_SignalAttachement(uint8_t PortNum, CCxPin_TypeDef cc)
|
||||
{
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
uint32_t _temp;
|
||||
|
||||
/* Init timer to detect the reception of goodCRC */
|
||||
USBPD_TIM_Init();
|
||||
|
||||
/* Prepare ucpd to handle PD message
|
||||
RX message start listen
|
||||
TX prepare the DMA to be transfer ready
|
||||
Detection listen only the line corresponding CC=Rd for SRC/SNK */
|
||||
Ports[PortNum].hdmatx = USBPD_HW_Init_DMATxInstance(PortNum);
|
||||
Ports[PortNum].hdmarx = USBPD_HW_Init_DMARxInstance(PortNum);
|
||||
|
||||
/* Set the RX dma to allow reception */
|
||||
_temp = (uint32_t)&Ports[PortNum].husbpd->RXDR;
|
||||
WRITE_REG(Ports[PortNum].hdmarx->CPAR, _temp);
|
||||
WRITE_REG(Ports[PortNum].hdmarx->CMAR, (uint32_t)Ports[PortNum].ptr_RxBuff);
|
||||
Ports[PortNum].hdmarx->CNDTR = SIZE_MAX_PD_TRANSACTION_UNCHUNK;
|
||||
Ports[PortNum].hdmarx->CCR |= DMA_CCR_EN;
|
||||
|
||||
/* Set the TX dma only UCPD address */
|
||||
_temp = (uint32_t)&Ports[PortNum].husbpd->TXDR;
|
||||
Ports[PortNum].hdmatx->CPAR = _temp;
|
||||
|
||||
/* Disabled non Rd line set CC line enable */
|
||||
#define INTERRUPT_MASK UCPD_IMR_TXMSGDISCIE | UCPD_IMR_TXMSGSENTIE | UCPD_IMR_HRSTDISCIE | UCPD_IMR_HRSTSENTIE | \
|
||||
UCPD_IMR_TXMSGABTIE | UCPD_IMR_TXUNDIE | UCPD_IMR_RXORDDETIE | UCPD_IMR_RXHRSTDETIE | \
|
||||
UCPD_IMR_RXOVRIE | UCPD_IMR_RXMSGENDIE
|
||||
|
||||
MODIFY_REG(Ports[PortNum].husbpd->IMR, INTERRUPT_MASK, INTERRUPT_MASK);
|
||||
#endif /* !USBPDCORE_LIB_NO_PD */
|
||||
|
||||
/* Handle CC enable */
|
||||
Ports[PortNum].CCx = cc;
|
||||
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
/* Set CC pin for PD message */
|
||||
LL_UCPD_SetCCPin(Ports[PortNum].husbpd, (Ports[PortNum].CCx == CC1) ? LL_UCPD_CCPIN_CC1 : LL_UCPD_CCPIN_CC2);
|
||||
|
||||
|
||||
#if defined(_VCONN_SUPPORT)
|
||||
/* Initialize Vconn management */
|
||||
(void)BSP_USBPD_PWR_VCONNInit(PortNum, (Ports[PortNum].CCx == CC1) ? 1u : 2u);
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
|
||||
if (Ports[PortNum].settings->PE_PD3_Support.d.PE_FastRoleSwapSupport == USBPD_TRUE)
|
||||
{
|
||||
/* Set GPIO to allow the FRS TX handling */
|
||||
USBPD_HW_SetFRSSignalling(PortNum, (Ports[PortNum].CCx == CC1) ? 1u : 2u);
|
||||
/* Enable FRS RX */
|
||||
LL_UCPD_FRSDetectionEnable(Ports[PortNum].husbpd);
|
||||
Ports[PortNum].husbpd->IMR |= UCPD_IMR_FRSEVTIE;
|
||||
}
|
||||
|
||||
/* Disable the Resistor on Vconn PIN */
|
||||
if (Ports[PortNum].CCx == CC1)
|
||||
{
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd, LL_UCPD_CCENABLE_CC1);
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd, LL_UCPD_CCENABLE_CC2);
|
||||
}
|
||||
|
||||
/* Prepare the rx processing */
|
||||
LL_UCPD_SetRxMode(Ports[PortNum].husbpd, LL_UCPD_RXMODE_NORMAL);
|
||||
LL_UCPD_RxDMAEnable(Ports[PortNum].husbpd);
|
||||
LL_UCPD_TxDMAEnable(Ports[PortNum].husbpd);
|
||||
#endif /* !USBPDCORE_LIB_NO_PD */
|
||||
}
|
||||
|
||||
|
||||
void HW_SignalDetachment(uint8_t PortNum)
|
||||
{
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
/* Stop DMA RX/TX */
|
||||
LL_UCPD_RxDMADisable(Ports[PortNum].husbpd);
|
||||
LL_UCPD_TxDMADisable(Ports[PortNum].husbpd);
|
||||
LL_UCPD_RxDisable(Ports[PortNum].husbpd);
|
||||
|
||||
#if !defined(_LOW_POWER) && !defined(USBPDM1_VCC_FEATURE_ENABLED)
|
||||
/* Enable only detection interrupt */
|
||||
WRITE_REG(Ports[PortNum].husbpd->IMR, UCPD_IMR_TYPECEVT1IE | UCPD_IMR_TYPECEVT2IE);
|
||||
#elif defined(_LOW_POWER)
|
||||
#if !defined(_DRP)
|
||||
if (USBPD_PORTPOWERROLE_SRC == Ports[PortNum].params->PE_PowerRole)
|
||||
{
|
||||
/* Enable detection interrupt */
|
||||
WRITE_REG(Ports[PortNum].husbpd->IMR, UCPD_IMR_TYPECEVT1IE | UCPD_IMR_TYPECEVT2IE);
|
||||
}
|
||||
#endif /* !_DRP */
|
||||
#endif /* !_LOW_POWER && !USBPDM1_VCC_FEATURE_ENABLED */
|
||||
|
||||
USBPD_HW_DeInit_DMATxInstance(PortNum);
|
||||
USBPD_HW_DeInit_DMARxInstance(PortNum);
|
||||
|
||||
LL_UCPD_SetccEnable(Ports[PortNum].husbpd, LL_UCPD_CCENABLE_CC1CC2);
|
||||
|
||||
if (USBPD_PORTPOWERROLE_SNK == Ports[PortNum].params->PE_PowerRole)
|
||||
{
|
||||
#if defined(_VCONN_SUPPORT)
|
||||
/* DeInitialize Vconn management */
|
||||
(void)BSP_USBPD_PWR_VCONNDeInit(PortNum, (Ports[PortNum].CCx == CC1) ? 1u : 2u);
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
/* DeInitialise VBUS power */
|
||||
(void)BSP_USBPD_PWR_VBUSDeInit(PortNum);
|
||||
}
|
||||
|
||||
if (Ports[PortNum].settings->PE_PD3_Support.d.PE_FastRoleSwapSupport == USBPD_TRUE)
|
||||
{
|
||||
/* Set GPIO to disallow the FRS RX handling */
|
||||
LL_UCPD_FRSDetectionDisable(Ports[PortNum].husbpd);
|
||||
}
|
||||
|
||||
#endif /* !USBPDCORE_LIB_NO_PD */
|
||||
Ports[PortNum].CCx = CCNONE;
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
/* DeInit timer to detect the reception of goodCRC */
|
||||
USBPD_TIM_DeInit();
|
||||
#endif /* !USBPDCORE_LIB_NO_PD */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set resistors to SinkTxNG
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_SetResistor_SinkTxNG(uint8_t PortNum)
|
||||
{
|
||||
/* Set the resistor SinkTxNG 1.5A5V */
|
||||
LL_UCPD_SetRpResistor(Ports[PortNum].husbpd, LL_UCPD_RESISTOR_1_5A);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set resistors to SinkTxOk
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_SetResistor_SinkTxOK(uint8_t PortNum)
|
||||
{
|
||||
/* Set the resistor SinkTxNG 3.0A5V */
|
||||
LL_UCPD_SetRpResistor(Ports[PortNum].husbpd, LL_UCPD_RESISTOR_3_0A);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if resistors are set to SinkTxOk
|
||||
* @param PortNum Port
|
||||
* @retval USBPD_TRUE if resistor is set to SinkTxOk, else USBPD_FALSE
|
||||
*/
|
||||
uint8_t USBPD_HW_IF_IsResistor_SinkTxOk(uint8_t PortNum)
|
||||
{
|
||||
#if defined(_LOW_POWER)
|
||||
/* When in low power mode, the type C state machine is turned off.
|
||||
To retrieve any potential updates of the SR register, the state machine needs to be re-enabled briefly. */
|
||||
|
||||
/* Enable type C state machine */
|
||||
CLEAR_BIT(Ports[PortNum].husbpd->CR, (UCPD_CR_CC1TCDIS | UCPD_CR_CC2TCDIS));
|
||||
|
||||
/* Let time for internal state machine to refresh his state */
|
||||
for (uint32_t index = 0; index < CAD_DELAY_READ_CC_STATUS; index++)
|
||||
{
|
||||
__DSB();
|
||||
}
|
||||
|
||||
/* Disable type C state machine */
|
||||
SET_BIT(Ports[PortNum].husbpd->CR, (UCPD_CR_CC1TCDIS | UCPD_CR_CC2TCDIS));
|
||||
#endif /* _LOW_POWER */
|
||||
|
||||
switch (Ports[PortNum].CCx)
|
||||
{
|
||||
case CC1 :
|
||||
if ((Ports[PortNum].husbpd->SR & UCPD_SR_TYPEC_VSTATE_CC1) == LL_UCPD_SNK_CC1_VRP30A)
|
||||
{
|
||||
return USBPD_TRUE;
|
||||
}
|
||||
break;
|
||||
case CC2 :
|
||||
if ((Ports[PortNum].husbpd->SR & UCPD_SR_TYPEC_VSTATE_CC2) == LL_UCPD_SNK_CC2_VRP30A)
|
||||
{
|
||||
return USBPD_TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return USBPD_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Signal a Fast Role Swap
|
||||
* @param PortNum Port
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_HW_IF_FastRoleSwapSignalling(uint8_t PortNum)
|
||||
{
|
||||
LL_UCPD_SignalFRSTX(Ports[PortNum].husbpd);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_pwr_hw_if.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains power hardware interface functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_hw_if.h"
|
||||
|
||||
|
||||
#define _USBPD_POWER_DEBUG
|
||||
#if defined(_TRACE)
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_trace.h"
|
||||
#endif /* _TRACE */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#if defined(_TRACE)
|
||||
#define POWER_DEBUG(__MSG__,__SIZE__) USBPD_TRACE_Add(USBPD_TRACE_DEBUG, PortNum, 0,__MSG__,__SIZE__);
|
||||
#else
|
||||
#define POWER_DEBUG(__MSG__,__SIZE__)
|
||||
#endif /* _TRACE */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
USBPD_StatusTypeDef HW_IF_PWR_SetVoltage(uint8_t PortNum, uint16_t voltage)
|
||||
{
|
||||
UNUSED(PortNum);
|
||||
UNUSED(voltage);
|
||||
return USBPD_OK;
|
||||
}
|
||||
|
||||
uint16_t HW_IF_PWR_GetVoltage(uint8_t PortNum)
|
||||
{
|
||||
uint32_t _voltage;
|
||||
BSP_USBPD_PWR_VBUSGetVoltage(PortNum, &_voltage);
|
||||
return (uint16_t)_voltage;
|
||||
}
|
||||
|
||||
int16_t HW_IF_PWR_GetCurrent(uint8_t PortNum)
|
||||
{
|
||||
int32_t _current;
|
||||
BSP_USBPD_PWR_VBUSGetCurrent(PortNum, &_current);
|
||||
return (int16_t)_current;
|
||||
}
|
||||
|
||||
#if defined(_SRC) || defined(_DRP)
|
||||
USBPD_StatusTypeDef HW_IF_PWR_Enable(uint8_t PortNum, USBPD_FunctionalState state, CCxPin_TypeDef Cc,
|
||||
uint32_t VconnState, USBPD_PortPowerRole_TypeDef role)
|
||||
{
|
||||
UNUSED(role);
|
||||
int32_t status;
|
||||
if (USBPD_ENABLE == state)
|
||||
{
|
||||
#if defined(_VCONN_SUPPORT)
|
||||
if (USBPD_TRUE == VconnState)
|
||||
{
|
||||
POWER_DEBUG((uint8_t *)"VCONN ON", 8);
|
||||
(void)BSP_USBPD_PWR_VCONNOn(PortNum, Cc);
|
||||
}
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
POWER_DEBUG((uint8_t *)"VBUS ON", 7);
|
||||
status = BSP_USBPD_PWR_VBUSOn(PortNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(_VCONN_SUPPORT)
|
||||
if (VconnState == USBPD_TRUE)
|
||||
{
|
||||
POWER_DEBUG((uint8_t *)"VCONN OFF", 9);
|
||||
(void)BSP_USBPD_PWR_VCONNOff(PortNum, Cc);
|
||||
}
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
POWER_DEBUG((uint8_t *)"VBUS OFF", 8);
|
||||
status = BSP_USBPD_PWR_VBUSOff(PortNum);
|
||||
}
|
||||
return (status == BSP_ERROR_NONE) ? USBPD_OK : USBPD_FAIL;
|
||||
}
|
||||
#endif /* _SRC || _DRP */
|
||||
|
||||
USBPD_FunctionalState HW_IF_PWR_VBUSIsEnabled(uint8_t PortNum)
|
||||
{
|
||||
#if defined(_SRC)||defined(_DRP)
|
||||
uint8_t _state;
|
||||
BSP_USBPD_PWR_VBUSIsOn(PortNum, &_state);
|
||||
return (_state == BSP_ERROR_NONE) ? USBPD_DISABLE : USBPD_ENABLE;
|
||||
#else
|
||||
return USBPD_DISABLE;
|
||||
#endif /* _SRC || _DRP */
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_timersserver.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains timer server functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_devices_conf.h"
|
||||
#include "usbpd_timersserver.h"
|
||||
|
||||
/** @addtogroup STM32_USBPD_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_DEVICE_TIMESERVER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
int8_t timer_initcounter = 0;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Initialize a timer to manage timing in us
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_TIM_Init(void)
|
||||
{
|
||||
if (0 == timer_initcounter)
|
||||
{
|
||||
TIMX_CLK_ENABLE;
|
||||
/***************************/
|
||||
/* Time base configuration */
|
||||
/***************************/
|
||||
/* Counter mode: select up-counting mode */
|
||||
LL_TIM_SetCounterMode(TIMX, LL_TIM_COUNTERMODE_UP);
|
||||
|
||||
#if defined(TIMX_CLK_FREQ)
|
||||
/* Set the pre-scaler value to have TIMx counter clock equal to 1 MHz */
|
||||
LL_TIM_SetPrescaler(TIMX, __LL_TIM_CALC_PSC(TIMX_CLK_FREQ, 1000000u));
|
||||
|
||||
/* Set the auto-reload value to have a counter frequency of 100Hz */
|
||||
LL_TIM_SetAutoReload(TIMX, __LL_TIM_CALC_ARR(TIMX_CLK_FREQ, LL_TIM_GetPrescaler(TIMX), 100u));
|
||||
#else
|
||||
/* Set the pre-scaler value to have TIMx counter clock equal to 1 MHz */
|
||||
LL_TIM_SetPrescaler(TIMX, __LL_TIM_CALC_PSC(SystemCoreClock, 1000000u));
|
||||
|
||||
/* Set the auto-reload value to have a counter frequency of 100Hz */
|
||||
LL_TIM_SetAutoReload(TIMX, __LL_TIM_CALC_ARR(SystemCoreClock, LL_TIM_GetPrescaler(TIMX), 100u));
|
||||
#endif /* TIMX_CLK_FREQ */
|
||||
|
||||
/*********************************/
|
||||
/* Output waveform configuration */
|
||||
/*********************************/
|
||||
/* Set output compare mode: TOGGLE */
|
||||
LL_TIM_OC_SetMode(TIMX, TIMX_CHANNEL_CH1, LL_TIM_OCMODE_TOGGLE);
|
||||
LL_TIM_OC_SetMode(TIMX, TIMX_CHANNEL_CH2, LL_TIM_OCMODE_TOGGLE);
|
||||
LL_TIM_OC_SetMode(TIMX, TIMX_CHANNEL_CH3, LL_TIM_OCMODE_TOGGLE);
|
||||
LL_TIM_OC_SetMode(TIMX, TIMX_CHANNEL_CH4, LL_TIM_OCMODE_TOGGLE);
|
||||
|
||||
/* Set output channel polarity: OC is active high */
|
||||
LL_TIM_OC_SetPolarity(TIMX, TIMX_CHANNEL_CH1, LL_TIM_OCPOLARITY_HIGH);
|
||||
LL_TIM_OC_SetPolarity(TIMX, TIMX_CHANNEL_CH2, LL_TIM_OCPOLARITY_HIGH);
|
||||
LL_TIM_OC_SetPolarity(TIMX, TIMX_CHANNEL_CH3, LL_TIM_OCPOLARITY_HIGH);
|
||||
LL_TIM_OC_SetPolarity(TIMX, TIMX_CHANNEL_CH4, LL_TIM_OCPOLARITY_HIGH);
|
||||
|
||||
/* Enable counter */
|
||||
LL_TIM_EnableCounter(TIMX);
|
||||
}
|
||||
|
||||
/* Enable the timer counter */
|
||||
timer_initcounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UnInitialize a timer to manage timing in us
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_TIM_DeInit(void)
|
||||
{
|
||||
timer_initcounter--;
|
||||
if (0 == timer_initcounter)
|
||||
{
|
||||
TIMX_CLK_DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief start the timer counting
|
||||
* @param timer id @TIM_identifier
|
||||
* @param time in us
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_TIM_Start(TIM_identifier Id, uint32_t TimeUs)
|
||||
{
|
||||
/* Positionne l'evenement pour sa detection */
|
||||
switch (Id)
|
||||
{
|
||||
case TIM_PORT0_CRC:
|
||||
TIMX_CHANNEL1_SETEVENT;
|
||||
break;
|
||||
case TIM_PORT0_RETRY:
|
||||
TIMX_CHANNEL2_SETEVENT;
|
||||
break;
|
||||
case TIM_PORT1_CRC:
|
||||
TIMX_CHANNEL3_SETEVENT;
|
||||
break;
|
||||
case TIM_PORT1_RETRY:
|
||||
TIMX_CHANNEL4_SETEVENT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief check timer expiration
|
||||
* @param timer id @TIM_identifier
|
||||
* @retval None
|
||||
*/
|
||||
uint32_t USBPD_TIM_IsExpired(TIM_identifier Id)
|
||||
{
|
||||
uint32_t _expired = 1u;
|
||||
switch (Id)
|
||||
{
|
||||
case TIM_PORT0_CRC:
|
||||
_expired = TIMX_CHANNEL1_GETFLAG(TIMX);
|
||||
break;
|
||||
case TIM_PORT0_RETRY:
|
||||
_expired = TIMX_CHANNEL2_GETFLAG(TIMX);
|
||||
break;
|
||||
case TIM_PORT1_CRC:
|
||||
_expired = TIMX_CHANNEL3_GETFLAG(TIMX);
|
||||
break;
|
||||
case TIM_PORT1_RETRY:
|
||||
_expired = TIMX_CHANNEL4_GETFLAG(TIMX);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return _expired;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
79
USBPD/App/usbpd.c
Normal file
79
USBPD/App/usbpd.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file app/usbpd.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the device define.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
/* USER CODE END 2 */
|
||||
/* USBPD init function */
|
||||
void MX_USBPD_Init(void)
|
||||
{
|
||||
|
||||
/* Global Init of USBPD HW */
|
||||
USBPD_HW_IF_GlobalHwInit();
|
||||
|
||||
/* Initialize the Device Policy Manager */
|
||||
if (USBPD_OK != USBPD_DPM_InitCore())
|
||||
{
|
||||
while(1);
|
||||
}
|
||||
|
||||
/* Initialise the DPM application */
|
||||
if (USBPD_OK != USBPD_DPM_UserInit())
|
||||
{
|
||||
while(1);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
/* USER CODE END 3 */
|
||||
|
||||
if (USBPD_OK != USBPD_DPM_InitOS())
|
||||
{
|
||||
while(1);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN EnableIRQ */
|
||||
/* Enable IRQ which has been disabled by FreeRTOS services */
|
||||
__enable_irq();
|
||||
/* USER CODE END EnableIRQ */
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
59
USBPD/App/usbpd.h
Normal file
59
USBPD/App/usbpd.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file app/usbpd.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the device define.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __usbpd_H
|
||||
#define __usbpd_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_dpm_core.h"
|
||||
#include "usbpd_dpm_conf.h"
|
||||
#include "usbpd_hw_if.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* Global variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* USBPD init function */
|
||||
void MX_USBPD_Init(void);
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
/* USER CODE END 2 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__usbpd_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
125
USBPD/usbpd_devices_conf.h
Normal file
125
USBPD/usbpd_devices_conf.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_devices_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the device define.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* CubeMX Generated */
|
||||
#define CUBEMX_GENERATED
|
||||
|
||||
#ifndef USBPD_DEVICE_CONF_H
|
||||
#define USBPD_DEVICE_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_ll_bus.h"
|
||||
#include "stm32g4xx_ll_dma.h"
|
||||
#include "stm32g4xx_ll_gpio.h"
|
||||
#include "stm32g4xx_ll_rcc.h"
|
||||
#include "stm32g4xx_ll_ucpd.h"
|
||||
#include "stm32g4xx_ll_pwr.h"
|
||||
#include "stm32g4xx_ll_tim.h"
|
||||
#include "usbpd_pwr_user.h"
|
||||
#include "usbpd_pwr_if.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
usbpd_hw.c
|
||||
-------------------------------------------------------------------------------*/
|
||||
|
||||
/* defined used to configure function : BSP_USBPD_GetUSPDInstance */
|
||||
#define UCPD_INSTANCE0 UCPD1
|
||||
|
||||
/* defined used to configure function : BSP_USBPD_Init_DMARxInstance,BSP_USBPD_DeInit_DMARxInstance */
|
||||
#define UCPDDMA_INSTANCE0_CLOCKENABLE_RX LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1)
|
||||
|
||||
#define UCPDDMA_INSTANCE0_DMA_RX DMA1
|
||||
|
||||
#define UCPDDMA_INSTANCE0_REQUEST_RX DMA_REQUEST_UCPD1_RX
|
||||
|
||||
#define UCPDDMA_INSTANCE0_LL_CHANNEL_RX LL_DMA_CHANNEL_1
|
||||
|
||||
#define UCPDDMA_INSTANCE0_CHANNEL_RX DMA1_Channel1
|
||||
|
||||
/* defined used to configure function : BSP_USBPD_Init_DMATxInstance, BSP_USBPD_DeInit_DMATxInstance */
|
||||
#define UCPDDMA_INSTANCE0_CLOCKENABLE_TX LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1)
|
||||
|
||||
#define UCPDDMA_INSTANCE0_DMA_TX DMA1
|
||||
|
||||
#define UCPDDMA_INSTANCE0_REQUEST_TX DMA_REQUEST_UCPD1_TX
|
||||
|
||||
#define UCPDDMA_INSTANCE0_LL_CHANNEL_TX LL_DMA_CHANNEL_2
|
||||
|
||||
#define UCPDDMA_INSTANCE0_CHANNEL_TX DMA1_Channel2
|
||||
/* defined used to configure BSP_USBPD_SetFRSSignalling */
|
||||
#define UCPDFRS_INSTANCE0_FRSCC1
|
||||
#define UCPDFRS_INSTANCE0_FRSCC2
|
||||
|
||||
#define UCPD_INSTANCE0_ENABLEIRQ do{ \
|
||||
NVIC_SetPriority(UCPD1_IRQn,4); \
|
||||
NVIC_EnableIRQ(UCPD1_IRQn); \
|
||||
} while(0)
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
Definitions for timer service feature
|
||||
-------------------------------------------------------------------------------*/
|
||||
|
||||
#define TIMX TIM1
|
||||
#define TIMX_CLK_ENABLE LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1)
|
||||
#define TIMX_CLK_DISABLE LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM1)
|
||||
#define TIMX_CHANNEL_CH1 LL_TIM_CHANNEL_CH1
|
||||
#define TIMX_CHANNEL_CH2 LL_TIM_CHANNEL_CH2
|
||||
#define TIMX_CHANNEL_CH3 LL_TIM_CHANNEL_CH3
|
||||
#define TIMX_CHANNEL_CH4 LL_TIM_CHANNEL_CH4
|
||||
#define TIMX_CHANNEL1_SETEVENT do{ \
|
||||
LL_TIM_OC_SetCompareCH1(TIMX, (TimeUs + TIMX->CNT) % TIM_MAX_TIME);\
|
||||
LL_TIM_ClearFlag_CC1(TIMX); \
|
||||
}while(0)
|
||||
#define TIMX_CHANNEL2_SETEVENT do{ \
|
||||
LL_TIM_OC_SetCompareCH2(TIMX, (TimeUs + TIMX->CNT) % TIM_MAX_TIME);\
|
||||
LL_TIM_ClearFlag_CC2(TIMX); \
|
||||
}while(0)
|
||||
#define TIMX_CHANNEL3_SETEVENT do{ \
|
||||
LL_TIM_OC_SetCompareCH3(TIMX, (TimeUs + TIMX->CNT) % TIM_MAX_TIME);\
|
||||
LL_TIM_ClearFlag_CC3(TIMX); \
|
||||
}while(0)
|
||||
#define TIMX_CHANNEL4_SETEVENT do{ \
|
||||
LL_TIM_OC_SetCompareCH4(TIMX, (TimeUs + TIMX->CNT) % TIM_MAX_TIME);\
|
||||
LL_TIM_ClearFlag_CC4(TIMX); \
|
||||
}while(0)
|
||||
#define TIMX_CHANNEL1_GETFLAG LL_TIM_IsActiveFlag_CC1
|
||||
#define TIMX_CHANNEL2_GETFLAG LL_TIM_IsActiveFlag_CC2
|
||||
#define TIMX_CHANNEL3_GETFLAG LL_TIM_IsActiveFlag_CC3
|
||||
#define TIMX_CHANNEL4_GETFLAG LL_TIM_IsActiveFlag_CC4
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBPD_DEVICE_CONF_H */
|
||||
|
||||
150
USBPD/usbpd_dpm_conf.h
Normal file
150
USBPD/usbpd_dpm_conf.h
Normal file
@@ -0,0 +1,150 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_dpm_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for stack/application settings file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef __USBPD_DPM_CONF_H_
|
||||
#define __USBPD_DPM_CONF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_pdo_defs.h"
|
||||
#include "usbpd_dpm_user.h"
|
||||
#include "usbpd_vdm_user.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* Section where include file can be added */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Define ------------------------------------------------------------------*/
|
||||
/* Define VID, PID,... manufacturer parameters */
|
||||
#define USBPD_VID (0x0483u) /*!< Vendor ID (assigned by the USB-IF) */
|
||||
#define USBPD_PID (0x0002u) /*!< Product ID (assigned by the manufacturer) */
|
||||
#define USBPD_XID (0xF0000003u) /*!< Value provided by the USB-IF assigned to the product */
|
||||
|
||||
/* USER CODE BEGIN Define */
|
||||
/* Section where Define can be added */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Typedef */
|
||||
/* Section where Typedef can be added */
|
||||
|
||||
/* USER CODE END Typedef */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
#ifndef __USBPD_DPM_CORE_C
|
||||
extern USBPD_SettingsTypeDef DPM_Settings[USBPD_PORT_COUNT];
|
||||
extern USBPD_IdSettingsTypeDef DPM_ID_Settings[USBPD_PORT_COUNT];
|
||||
extern USBPD_USER_SettingsTypeDef DPM_USER_Settings[USBPD_PORT_COUNT];
|
||||
#else /* __USBPD_DPM_CORE_C */
|
||||
USBPD_SettingsTypeDef DPM_Settings[USBPD_PORT_COUNT] =
|
||||
{
|
||||
{
|
||||
.PE_SupportedSOP = USBPD_SUPPORTED_SOP_SOP , /* Supported SOP : SOP, SOP' SOP" SOP'Debug SOP"Debug */
|
||||
.PE_SpecRevision = USBPD_SPECIFICATION_REV3,/* spec revision value */
|
||||
.PE_DefaultRole = USBPD_PORTPOWERROLE_SRC, /* Default port role */
|
||||
.PE_RoleSwap = USBPD_FALSE, /* support port role swap */
|
||||
.PE_VDMSupport = USBPD_FALSE,
|
||||
.PE_RespondsToDiscovSOP = USBPD_FALSE, /*!< Can respond successfully to a Discover Identity */
|
||||
.PE_AttemptsDiscovSOP = USBPD_FALSE, /*!< Can send a Discover Identity */
|
||||
.PE_PingSupport = USBPD_FALSE, /* support Ping (only for PD3.0) */
|
||||
.PE_CapscounterSupport = USBPD_FALSE, /* support caps counter */
|
||||
.CAD_RoleToggle = USBPD_FALSE, /* CAD role toggle */
|
||||
.CAD_DefaultResistor = 0x00u,
|
||||
.CAD_TryFeature = 0, /* CAD try feature */
|
||||
.CAD_AccesorySupport = USBPD_FALSE, /* CAD accessory support */
|
||||
.PE_PD3_Support.d = /*!< PD3 SUPPORT FEATURE */
|
||||
{
|
||||
.PE_UnchunkSupport = USBPD_FALSE, /* support Unchunked mode (valid only spec revision 3.0) */
|
||||
.PE_FastRoleSwapSupport = USBPD_FALSE, /* support fast role swap only spec revision 3.0 */
|
||||
.Is_GetPPSStatus_Supported = USBPD_FALSE, /*!< PPS message NOT supported by PE stack */
|
||||
.Is_SrcCapaExt_Supported = USBPD_FALSE, /*!< Source_Capabilities_Extended message supported or not by DPM */
|
||||
.Is_Alert_Supported = USBPD_FALSE, /*!< Alert message supported or not by DPM */
|
||||
.Is_GetStatus_Supported = USBPD_FALSE, /*!< Status message supported or not by DPM (Is_Alert_Supported should be enabled) */
|
||||
.Is_GetManufacturerInfo_Supported = USBPD_FALSE, /*!< Manufacturer_Info message supported or not by DPM */
|
||||
.Is_GetCountryCodes_Supported = USBPD_FALSE, /*!< Country_Codes message supported or not by DPM */
|
||||
.Is_GetCountryInfo_Supported = USBPD_FALSE, /*!< Country_Info message supported or not by DPM */
|
||||
.Is_SecurityRequest_Supported = USBPD_FALSE, /*!< Security_Response message supported or not by DPM */
|
||||
.Is_FirmUpdateRequest_Supported = USBPD_FALSE, /*!< Firmware update response message supported by PE */
|
||||
.Is_GetBattery_Supported = USBPD_FALSE, /*!< Get Battery Capabitity and Status messages supported by PE */
|
||||
},
|
||||
|
||||
.CAD_SRCToggleTime = 0, /* uint8_t CAD_SRCToggleTime; */
|
||||
.CAD_SNKToggleTime = 0, /* uint8_t CAD_SNKToggleTime; */
|
||||
}
|
||||
};
|
||||
|
||||
USBPD_IdSettingsTypeDef DPM_ID_Settings[USBPD_PORT_COUNT] =
|
||||
{
|
||||
{
|
||||
.XID = USBPD_XID, /*!< Value provided by the USB-IF assigned to the product */
|
||||
.VID = USBPD_VID, /*!< Vendor ID (assigned by the USB-IF) */
|
||||
.PID = USBPD_PID, /*!< Product ID (assigned by the manufacturer) */
|
||||
},
|
||||
};
|
||||
|
||||
USBPD_USER_SettingsTypeDef DPM_USER_Settings[USBPD_PORT_COUNT] =
|
||||
{
|
||||
{
|
||||
.PE_DataSwap = USBPD_FALSE, /* support data swap */
|
||||
.PE_VconnSwap = USBPD_FALSE, /* support VCONN swap */
|
||||
.PE_DR_Swap_To_DFP = USBPD_TRUE, /* Support of DR Swap to DFP */
|
||||
.PE_DR_Swap_To_UFP = USBPD_TRUE, /* Support of DR Swap to UFP */
|
||||
#if defined(USBPD_REV30_SUPPORT)
|
||||
#if _MANU_INFO
|
||||
.DPM_ManuInfoPort = /*!< Manufacturer information used for the port */
|
||||
{
|
||||
.VID = USBPD_VID, /*!< Vendor ID (assigned by the USB-IF) */
|
||||
.PID = USBPD_PID, /*!< Product ID (assigned by the manufacturer) */
|
||||
.ManuString = "STMicroelectronics", /*!< Vendor defined byte array */
|
||||
},
|
||||
#endif /* _MANU_INFO */
|
||||
#endif /* USBPD_REV30_SUPPORT */
|
||||
},
|
||||
};
|
||||
|
||||
#endif /* !__USBPD_DPM_CORE_C */
|
||||
|
||||
/* USER CODE BEGIN Variable */
|
||||
/* Section where Variable can be added */
|
||||
|
||||
/* USER CODE END Variable */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Constant */
|
||||
/* Section where Constant can be added */
|
||||
|
||||
/* USER CODE END Constant */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
/* Section where Macro can be added */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_DPM_CONF_H_ */
|
||||
463
USBPD/usbpd_dpm_core.c
Normal file
463
USBPD/usbpd_dpm_core.c
Normal file
@@ -0,0 +1,463 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_dpm_core.c
|
||||
* @author MCD Application Team
|
||||
* @brief USBPD dpm core file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#define __USBPD_DPM_CORE_C
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_trace.h"
|
||||
#include "usbpd_dpm_core.h"
|
||||
#include "usbpd_dpm_conf.h"
|
||||
#include "usbpd_dpm_user.h"
|
||||
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
#include "utilities_conf.h"
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
|
||||
/* Generic STM32 prototypes */
|
||||
extern uint32_t HAL_GetTick(void);
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* !FREERTOS */
|
||||
void USBPD_CAD_Task(void);
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
void TimerCADfunction(void *);
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
void USBPD_PE_Task_P0(void);
|
||||
void USBPD_PE_Task_P1(void);
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
void TimerPE0function(void *pArg);
|
||||
void TimerPE1function(void *pArg);
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
void USBPD_TaskUser(void);
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* !_RTOS */
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
UTIL_TIMER_Object_t TimerCAD;
|
||||
UTIL_TIMER_Object_t TimerPE0, TimerPE1;
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
#define CHECK_PE_FUNCTION_CALL(_function_) _retr = _function_; \
|
||||
if(USBPD_OK != _retr) {return _retr;}
|
||||
#define CHECK_CAD_FUNCTION_CALL(_function_) if(USBPD_CAD_OK != _function_) {return USBPD_ERROR;}
|
||||
|
||||
#if defined(_DEBUG_TRACE)
|
||||
#define DPM_CORE_DEBUG_TRACE(_PORTNUM_, __MESSAGE__) USBPD_TRACE_Add(USBPD_TRACE_DEBUG, _PORTNUM_, 0u, (uint8_t *)(__MESSAGE__), sizeof(__MESSAGE__) - 1u);
|
||||
#else
|
||||
#define DPM_CORE_DEBUG_TRACE(_PORTNUM_, __MESSAGE__)
|
||||
#endif /* _DEBUG_TRACE */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
#if !defined(USE_STM32_UTILITY_OS)
|
||||
#define OFFSET_CAD 1U
|
||||
static uint32_t DPM_Sleep_time[USBPD_PORT_COUNT + OFFSET_CAD];
|
||||
static uint32_t DPM_Sleep_start[USBPD_PORT_COUNT + OFFSET_CAD];
|
||||
#endif /* !USE_STM32_UTILITY_OS */
|
||||
|
||||
USBPD_ParamsTypeDef DPM_Params[USBPD_PORT_COUNT];
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void USBPD_PE_TaskWakeUp(uint8_t PortNum);
|
||||
static void DPM_ManageAttachedState(uint8_t PortNum, USBPD_CAD_EVENT State, CCxPin_TypeDef Cc);
|
||||
void USBPD_DPM_CADCallback(uint8_t PortNum, USBPD_CAD_EVENT State, CCxPin_TypeDef Cc);
|
||||
static void USBPD_DPM_CADTaskWakeUp(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize the core stack (port power role, PWR_IF, CAD and PE Init procedures)
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_InitCore(void)
|
||||
{
|
||||
/* variable to get dynamique memory allocated by usbpd stack */
|
||||
uint32_t stack_dynamemsize;
|
||||
USBPD_StatusTypeDef _retr = USBPD_OK;
|
||||
|
||||
static const USBPD_PE_Callbacks dpmCallbacks =
|
||||
{
|
||||
USBPD_DPM_SetupNewPower,
|
||||
USBPD_DPM_HardReset,
|
||||
NULL,
|
||||
USBPD_DPM_Notification,
|
||||
USBPD_DPM_ExtendedMessageReceived,
|
||||
USBPD_DPM_GetDataInfo,
|
||||
USBPD_DPM_SetDataInfo,
|
||||
USBPD_DPM_EvaluateRequest,
|
||||
NULL,
|
||||
NULL,
|
||||
USBPD_PE_TaskWakeUp,
|
||||
#if defined(_VCONN_SUPPORT)
|
||||
USBPD_DPM_EvaluateVconnSwap,
|
||||
USBPD_DPM_PE_VconnPwr,
|
||||
#else
|
||||
NULL,
|
||||
NULL,
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
USBPD_DPM_EnterErrorRecovery,
|
||||
USBPD_DPM_EvaluateDataRoleSwap,
|
||||
USBPD_DPM_IsPowerReady
|
||||
};
|
||||
|
||||
static const USBPD_CAD_Callbacks CAD_cbs =
|
||||
{
|
||||
USBPD_DPM_CADCallback,
|
||||
USBPD_DPM_CADTaskWakeUp
|
||||
};
|
||||
|
||||
/* Check the lib selected */
|
||||
if (USBPD_TRUE != USBPD_PE_CheckLIB(_LIB_ID))
|
||||
{
|
||||
return USBPD_ERROR;
|
||||
}
|
||||
|
||||
/* to get how much memory are dynamically allocated by the stack
|
||||
the memory return is corresponding to 2 ports so if the application
|
||||
managed only one port divide the value return by 2 */
|
||||
stack_dynamemsize = USBPD_PE_GetMemoryConsumption();
|
||||
|
||||
/* done to avoid warning */
|
||||
(void)stack_dynamemsize;
|
||||
|
||||
for (uint8_t _port_index = 0; _port_index < USBPD_PORT_COUNT; ++_port_index)
|
||||
{
|
||||
/* Variable to be sure that DPM is correctly initialized */
|
||||
DPM_Params[_port_index].DPM_Initialized = USBPD_FALSE;
|
||||
|
||||
/* check the stack settings */
|
||||
DPM_Params[_port_index].PE_SpecRevision = DPM_Settings[_port_index].PE_SpecRevision;
|
||||
DPM_Params[_port_index].PE_PowerRole = DPM_Settings[_port_index].PE_DefaultRole;
|
||||
DPM_Params[_port_index].PE_SwapOngoing = USBPD_FALSE;
|
||||
DPM_Params[_port_index].ActiveCCIs = CCNONE;
|
||||
DPM_Params[_port_index].VconnCCIs = CCNONE;
|
||||
DPM_Params[_port_index].VconnStatus = USBPD_FALSE;
|
||||
|
||||
/* CAD SET UP : Port 0 */
|
||||
CHECK_CAD_FUNCTION_CALL(USBPD_CAD_Init(_port_index, (USBPD_CAD_Callbacks *)&CAD_cbs,
|
||||
(USBPD_SettingsTypeDef *)&DPM_Settings[_port_index], &DPM_Params[_port_index]));
|
||||
|
||||
/* PE SET UP : Port 0 */
|
||||
CHECK_PE_FUNCTION_CALL(USBPD_PE_Init(_port_index, (USBPD_SettingsTypeDef *)&DPM_Settings[_port_index],
|
||||
&DPM_Params[_port_index], &dpmCallbacks));
|
||||
|
||||
/* DPM is correctly initialized */
|
||||
DPM_Params[_port_index].DPM_Initialized = USBPD_TRUE;
|
||||
|
||||
/* Enable CAD on Port 0 */
|
||||
USBPD_CAD_PortEnable(_port_index, USBPD_CAD_ENABLE);
|
||||
}
|
||||
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
/* initialise timer server */
|
||||
UTIL_TIMER_Init();
|
||||
|
||||
/* initialize the sequencer */
|
||||
UTIL_SEQ_Init();
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
|
||||
return _retr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the OS parts (task, queue,... )
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_InitOS(void)
|
||||
{
|
||||
|
||||
return USBPD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the OS parts (port power role, PWR_IF, CAD and PE Init procedures)
|
||||
* @retval None
|
||||
*/
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
/**
|
||||
* @brief Task for CAD processing
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_CAD_Task(void)
|
||||
{
|
||||
UTIL_TIMER_Stop(&TimerCAD);
|
||||
uint32_t _timing = USBPD_CAD_Process();
|
||||
UTIL_TIMER_SetPeriod(&TimerCAD, _timing);
|
||||
UTIL_TIMER_Start(&TimerCAD);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief timer function to wakeup CAD Task
|
||||
* @param pArg Pointer on an argument
|
||||
* @retval None
|
||||
*/
|
||||
void TimerCADfunction(void *pArg)
|
||||
{
|
||||
UTIL_SEQ_SetTask(TASK_CAD, 0);
|
||||
}
|
||||
|
||||
#if !defined(USBPDCORE_LIB_NO_PD)
|
||||
/**
|
||||
* @brief timer function to wakeup PE_0 Task
|
||||
* @param pArg Pointer on an argument
|
||||
* @retval None
|
||||
*/
|
||||
void TimerPE0function(void *pArg)
|
||||
{
|
||||
UTIL_SEQ_SetTask(TASK_PE_0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief timer function to wakeup PE_1 Task
|
||||
* @param pArg Pointer on an argument
|
||||
* @retval None
|
||||
*/
|
||||
void TimerPE1function(void *pArg)
|
||||
{
|
||||
UTIL_SEQ_SetTask(TASK_PE_1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Task for PE_0 processing
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PE_Task_P0(void)
|
||||
{
|
||||
UTIL_TIMER_Stop(&TimerPE0);
|
||||
uint32_t _timing =
|
||||
USBPD_PE_StateMachine_SRC(USBPD_PORT_0);
|
||||
if (_timing != 0xFFFFFFFF)
|
||||
{
|
||||
UTIL_TIMER_SetPeriod(&TimerPE0, _timing);
|
||||
UTIL_TIMER_Start(&TimerPE0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Task for PE_1 processing
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PE_Task_P1(void)
|
||||
{
|
||||
UTIL_TIMER_Stop(&TimerPE1);
|
||||
uint32_t _timing =
|
||||
USBPD_PE_StateMachine_SRC(USBPD_PORT_1);
|
||||
if (_timing != 0xFFFFFFFF)
|
||||
{
|
||||
UTIL_TIMER_SetPeriod(&TimerPE1, _timing);
|
||||
UTIL_TIMER_Start(&TimerPE1);
|
||||
}
|
||||
}
|
||||
#endif /* !USBPDCORE_LIB_NO_PD */
|
||||
|
||||
/**
|
||||
* @brief Task for DPM_USER processing
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_TaskUser(void)
|
||||
{
|
||||
USBPD_DPM_UserExecute(NULL);
|
||||
}
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
|
||||
void USBPD_DPM_Run(void)
|
||||
{
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
UTIL_SEQ_RegTask(TASK_CAD, 0, USBPD_CAD_Task);
|
||||
UTIL_SEQ_SetTask(TASK_CAD, 0);
|
||||
UTIL_TIMER_Create(&TimerCAD, 10, UTIL_TIMER_ONESHOT, TimerCADfunction, NULL);
|
||||
|
||||
UTIL_SEQ_RegTask(TASK_PE_0, 0, USBPD_PE_Task_P0);
|
||||
UTIL_SEQ_PauseTask(TASK_PE_0);
|
||||
UTIL_TIMER_Create(&TimerPE0, 10, UTIL_TIMER_ONESHOT, TimerPE0function, NULL);
|
||||
#if USBPD_PORT_COUNT == 2
|
||||
UTIL_SEQ_RegTask(TASK_PE_1, 0, USBPD_PE_Task_P1);
|
||||
UTIL_SEQ_PauseTask(TASK_PE_1);
|
||||
UTIL_TIMER_Create(&TimerPE1, 10, UTIL_TIMER_ONESHOT, TimerPE1function, NULL);
|
||||
#endif /* USBPD_PORT_COUNT == 2 */
|
||||
/* !USBPDCORE_LIB_NO_PD */
|
||||
|
||||
UTIL_SEQ_RegTask(TASK_USER, 0, USBPD_TaskUser);
|
||||
UTIL_SEQ_SetTask(TASK_USER, 0);
|
||||
|
||||
do
|
||||
{
|
||||
UTIL_SEQ_Run(~0);
|
||||
} while (1u == 1u);
|
||||
#else /* !USE_STM32_UTILITY_OS */
|
||||
do
|
||||
{
|
||||
|
||||
if ((HAL_GetTick() - DPM_Sleep_start[USBPD_PORT_COUNT]) >= DPM_Sleep_time[USBPD_PORT_COUNT])
|
||||
{
|
||||
DPM_Sleep_time[USBPD_PORT_COUNT] = USBPD_CAD_Process();
|
||||
DPM_Sleep_start[USBPD_PORT_COUNT] = HAL_GetTick();
|
||||
}
|
||||
|
||||
uint32_t port = 0;
|
||||
|
||||
for (port = 0; port < USBPD_PORT_COUNT; port++)
|
||||
{
|
||||
if ((HAL_GetTick() - DPM_Sleep_start[port]) >= DPM_Sleep_time[port])
|
||||
{
|
||||
DPM_Sleep_time[port] =
|
||||
USBPD_PE_StateMachine_SRC(port);
|
||||
DPM_Sleep_start[port] = HAL_GetTick();
|
||||
}
|
||||
}
|
||||
|
||||
USBPD_DPM_UserExecute(NULL);
|
||||
|
||||
} while (1u == 1u);
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize DPM (port power role, PWR_IF, CAD and PE Init procedures)
|
||||
* @retval USBPD status
|
||||
*/
|
||||
void USBPD_DPM_TimerCounter(void)
|
||||
{
|
||||
/* Call PE/PRL timers functions only if DPM is initialized */
|
||||
if (USBPD_TRUE == DPM_Params[USBPD_PORT_0].DPM_Initialized)
|
||||
{
|
||||
USBPD_DPM_UserTimerCounter(USBPD_PORT_0);
|
||||
USBPD_PE_TimerCounter(USBPD_PORT_0);
|
||||
USBPD_PRL_TimerCounter(USBPD_PORT_0);
|
||||
}
|
||||
#if USBPD_PORT_COUNT==2
|
||||
if (USBPD_TRUE == DPM_Params[USBPD_PORT_1].DPM_Initialized)
|
||||
{
|
||||
USBPD_DPM_UserTimerCounter(USBPD_PORT_1);
|
||||
USBPD_PE_TimerCounter(USBPD_PORT_1);
|
||||
USBPD_PRL_TimerCounter(USBPD_PORT_1);
|
||||
}
|
||||
#endif /* USBPD_PORT_COUNT == 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief WakeUp PE task
|
||||
* @param PortNum port number
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_PE_TaskWakeUp(uint8_t PortNum)
|
||||
{
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
UTIL_SEQ_SetTask(PortNum == 0 ? TASK_PE_0 : TASK_PE_1, 0);
|
||||
#else
|
||||
DPM_Sleep_time[PortNum] = 0;
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief WakeUp CAD task
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_DPM_CADTaskWakeUp(void)
|
||||
{
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
UTIL_SEQ_SetTask(TASK_CAD, 0);
|
||||
#else
|
||||
DPM_Sleep_time[USBPD_PORT_COUNT] = 0;
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CallBack reporting events on a specified port from CAD layer.
|
||||
* @param PortNum The handle of the port
|
||||
* @param State CAD state
|
||||
* @param Cc The Communication Channel for the USBPD communication
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_CADCallback(uint8_t PortNum, USBPD_CAD_EVENT State, CCxPin_TypeDef Cc)
|
||||
{
|
||||
|
||||
switch (State)
|
||||
{
|
||||
case USBPD_CAD_EVENT_ATTEMC :
|
||||
{
|
||||
#ifdef _VCONN_SUPPORT
|
||||
DPM_Params[PortNum].VconnStatus = USBPD_TRUE;
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
DPM_ManageAttachedState(PortNum, State, Cc);
|
||||
#ifdef _VCONN_SUPPORT
|
||||
DPM_CORE_DEBUG_TRACE(PortNum, "Note: VconnStatus=TRUE");
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
break;
|
||||
}
|
||||
case USBPD_CAD_EVENT_ATTACHED :
|
||||
DPM_ManageAttachedState(PortNum, State, Cc);
|
||||
break;
|
||||
case USBPD_CAD_EVENT_DETACHED :
|
||||
case USBPD_CAD_EVENT_EMC :
|
||||
{
|
||||
/* The ufp is detached */
|
||||
(void)USBPD_PE_IsCableConnected(PortNum, 0);
|
||||
/* Terminate PE task */
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
UTIL_SEQ_PauseTask(PortNum == 0 ? TASK_PE_0 : TASK_PE_1);
|
||||
#else
|
||||
DPM_Sleep_time[PortNum] = 0xFFFFFFFFU;
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
DPM_Params[PortNum].PE_SwapOngoing = USBPD_FALSE;
|
||||
DPM_Params[PortNum].ActiveCCIs = CCNONE;
|
||||
DPM_Params[PortNum].PE_Power = USBPD_POWER_NO;
|
||||
USBPD_DPM_UserCableDetection(PortNum, State);
|
||||
#ifdef _VCONN_SUPPORT
|
||||
DPM_Params[PortNum].VconnCCIs = CCNONE;
|
||||
DPM_Params[PortNum].VconnStatus = USBPD_FALSE;
|
||||
DPM_CORE_DEBUG_TRACE(PortNum, "Note: VconnStatus=FALSE");
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
break;
|
||||
}
|
||||
default :
|
||||
/* nothing to do */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void DPM_ManageAttachedState(uint8_t PortNum, USBPD_CAD_EVENT State, CCxPin_TypeDef Cc)
|
||||
{
|
||||
#ifdef _VCONN_SUPPORT
|
||||
if (CC1 == Cc)
|
||||
{
|
||||
DPM_Params[PortNum].VconnCCIs = CC2;
|
||||
}
|
||||
if (CC2 == Cc)
|
||||
{
|
||||
DPM_Params[PortNum].VconnCCIs = CC1;
|
||||
}
|
||||
#endif /* _VCONN_SUPPORT */
|
||||
DPM_Params[PortNum].ActiveCCIs = Cc;
|
||||
(void)USBPD_PE_IsCableConnected(PortNum, 1);
|
||||
|
||||
USBPD_DPM_UserCableDetection(PortNum, State);
|
||||
|
||||
#if defined(USE_STM32_UTILITY_OS)
|
||||
/* Resume the task */
|
||||
UTIL_SEQ_ResumeTask(PortNum == 0 ? TASK_PE_0 : TASK_PE_1);
|
||||
/* Enable task execution */
|
||||
UTIL_SEQ_SetTask(PortNum == 0 ? TASK_PE_0 : TASK_PE_1, 0);
|
||||
#else
|
||||
DPM_Sleep_time[PortNum] = 0U;
|
||||
#endif /* USE_STM32_UTILITY_OS */
|
||||
}
|
||||
74
USBPD/usbpd_dpm_core.h
Normal file
74
USBPD/usbpd_dpm_core.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_dpm_core.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for usbpd_dpm_core.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef __USBPD_DPM_CORE_H_
|
||||
#define __USBPD_DPM_CORE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN typedef */
|
||||
|
||||
/* USER CODE END typedef */
|
||||
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN define */
|
||||
|
||||
/* USER CODE END define */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN constants */
|
||||
|
||||
/* USER CODE END constants */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN macro */
|
||||
|
||||
/* USER CODE END macro */
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
extern USBPD_ParamsTypeDef DPM_Params[USBPD_PORT_COUNT];
|
||||
/* USER CODE BEGIN variables */
|
||||
|
||||
/* USER CODE END variables */
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_InitCore(void);
|
||||
USBPD_StatusTypeDef USBPD_DPM_InitOS(void);
|
||||
void USBPD_DPM_Run(void);
|
||||
void USBPD_DPM_TimerCounter(void);
|
||||
__WEAK void USBPD_DPM_ErrorHandler(void);
|
||||
/* USER CODE BEGIN functions */
|
||||
|
||||
/* USER CODE END functions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_DPM_CORE_H_ */
|
||||
993
USBPD/usbpd_dpm_user.c
Normal file
993
USBPD/usbpd_dpm_user.c
Normal file
@@ -0,0 +1,993 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_dpm_user.c
|
||||
* @author MCD Application Team
|
||||
* @brief USBPD DPM user code
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#define USBPD_DPM_USER_C
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_dpm_user.h"
|
||||
#include "usbpd_pdo_defs.h"
|
||||
#include "usbpd_dpm_core.h"
|
||||
#include "usbpd_dpm_conf.h"
|
||||
#include "usbpd_vdm_user.h"
|
||||
#include "usbpd_pwr_if.h"
|
||||
#include "usbpd_pwr_user.h"
|
||||
#if defined(_TRACE)
|
||||
#include "usbpd_trace.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#endif /* _TRACE */
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_DPM_USER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Private_Typedef */
|
||||
|
||||
/* USER CODE END Private_Typedef */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup USBPD_USER_PRIVATE_DEFINES USBPD USER Private Defines
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN Private_Define */
|
||||
|
||||
/* USER CODE END Private_Define */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/** @defgroup USBPD_USER_PRIVATE_MACROS USBPD USER Private Macros
|
||||
* @{
|
||||
*/
|
||||
#if defined(_TRACE)
|
||||
#define DPM_USER_DEBUG_TRACE_SIZE 50u
|
||||
#define DPM_USER_DEBUG_TRACE(_PORT_, ...) do { \
|
||||
char _str[DPM_USER_DEBUG_TRACE_SIZE]; \
|
||||
uint8_t _size = snprintf(_str, DPM_USER_DEBUG_TRACE_SIZE, __VA_ARGS__); \
|
||||
if (_size < DPM_USER_DEBUG_TRACE_SIZE) \
|
||||
USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (uint8_t)(_PORT_), 0, (uint8_t*)_str, strlen(_str)); \
|
||||
else \
|
||||
USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (uint8_t)(_PORT_), 0, (uint8_t*)_str, DPM_USER_DEBUG_TRACE_SIZE); \
|
||||
} while(0)
|
||||
|
||||
#define DPM_USER_ERROR_TRACE(_PORT_, _STATUS_, ...) do { \
|
||||
if (USBPD_OK != _STATUS_) { \
|
||||
char _str[DPM_USER_DEBUG_TRACE_SIZE]; \
|
||||
uint8_t _size = snprintf(_str, DPM_USER_DEBUG_TRACE_SIZE, __VA_ARGS__); \
|
||||
if (_size < DPM_USER_DEBUG_TRACE_SIZE) \
|
||||
USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (uint8_t)(_PORT_), 0, (uint8_t*)_str, strlen(_str)); \
|
||||
else \
|
||||
USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (uint8_t)(_PORT_), 0, (uint8_t*)_str, DPM_USER_DEBUG_TRACE_SIZE); \
|
||||
} \
|
||||
} while(0)
|
||||
#else
|
||||
#define DPM_USER_DEBUG_TRACE(_PORT_, ...)
|
||||
#define DPM_USER_ERROR_TRACE(_PORT_, _STATUS_, ...)
|
||||
#endif /* _TRACE */
|
||||
/* USER CODE BEGIN Private_Macro */
|
||||
|
||||
/* USER CODE END Private_Macro */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/** @defgroup USBPD_USER_PRIVATE_VARIABLES USBPD USER Private Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN Private_Variables */
|
||||
|
||||
/* USER CODE END Private_Variables */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @defgroup USBPD_USER_PRIVATE_FUNCTIONS USBPD USER Private Functions
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
|
||||
|
||||
/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported functions ------- ------------------------------------------------*/
|
||||
/** @defgroup USBPD_USER_EXPORTED_FUNCTIONS USBPD USER Exported Functions
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN USBPD_USER_EXPORTED_FUNCTIONS */
|
||||
|
||||
/* USER CODE END USBPD_USER_EXPORTED_FUNCTIONS */
|
||||
|
||||
/** @defgroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP1 USBPD USER Exported Functions called by DPM CORE
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN USBPD_USER_EXPORTED_FUNCTIONS_GROUP1 */
|
||||
|
||||
/* USER CODE END USBPD_USER_EXPORTED_FUNCTIONS_GROUP1 */
|
||||
|
||||
/**
|
||||
* @brief Initialize DPM (port power role, PWR_IF, CAD and PE Init procedures)
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_UserInit(void)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_UserInit */
|
||||
return USBPD_OK;
|
||||
/* USER CODE END USBPD_DPM_UserInit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief User delay implementation which is OS dependent
|
||||
* @param Time time in ms
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_WaitForTime(uint32_t Time)
|
||||
{
|
||||
HAL_Delay(Time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief User processing time, it is recommended to avoid blocking task for long time
|
||||
* @param argument DPM User event
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_UserExecute(void const *argument)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_UserExecute */
|
||||
|
||||
/* USER CODE END USBPD_DPM_UserExecute */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UserCableDetection reporting events on a specified port from CAD layer.
|
||||
* @param PortNum The handle of the port
|
||||
* @param State CAD state
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_UserCableDetection(uint8_t PortNum, USBPD_CAD_EVENT State)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_UserCableDetection */
|
||||
DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_UserCableDetection");
|
||||
switch(State)
|
||||
{
|
||||
case USBPD_CAD_EVENT_ATTACHED:
|
||||
case USBPD_CAD_EVENT_ATTEMC:
|
||||
{
|
||||
if (USBPD_OK != USBPD_PWR_IF_VBUSEnable(PortNum))
|
||||
{
|
||||
/* Should not occur */
|
||||
HAL_Delay(6000);
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case USBPD_CAD_EVENT_DETACHED :
|
||||
case USBPD_CAD_EVENT_EMC :
|
||||
default :
|
||||
{
|
||||
if (USBPD_OK != USBPD_PWR_IF_VBUSDisable(PortNum))
|
||||
{
|
||||
/* Should not occur */
|
||||
while(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* USER CODE END USBPD_DPM_UserCableDetection */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function used to manage user timer.
|
||||
* @param PortNum Port number
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_UserTimerCounter(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_UserTimerCounter */
|
||||
|
||||
/* USER CODE END USBPD_DPM_UserTimerCounter */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP2 USBPD USER Exported Callbacks functions called by PE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Callback function called by PE to inform DPM about PE event.
|
||||
* @param PortNum The current port number
|
||||
* @param EventVal @ref USBPD_NotifyEventValue_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_Notification(uint8_t PortNum, USBPD_NotifyEventValue_TypeDef EventVal)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_Notification */
|
||||
/* Manage event notified by the stack? */
|
||||
switch(EventVal)
|
||||
{
|
||||
// case USBPD_NOTIFY_POWER_EXPLICIT_CONTRACT :
|
||||
// break;
|
||||
// case USBPD_NOTIFY_REQUEST_ACCEPTED:
|
||||
// break;
|
||||
// case USBPD_NOTIFY_REQUEST_REJECTED:
|
||||
// case USBPD_NOTIFY_REQUEST_WAIT:
|
||||
// break;
|
||||
// case USBPD_NOTIFY_POWER_SWAP_TO_SNK_DONE:
|
||||
// break;
|
||||
// case USBPD_NOTIFY_STATE_SNK_READY:
|
||||
// break;
|
||||
// case USBPD_NOTIFY_HARDRESET_RX:
|
||||
// case USBPD_NOTIFY_HARDRESET_TX:
|
||||
// break;
|
||||
// case USBPD_NOTIFY_STATE_SRC_DISABLED:
|
||||
// break;
|
||||
// case USBPD_NOTIFY_ALERT_RECEIVED :
|
||||
// break;
|
||||
// case USBPD_NOTIFY_CABLERESET_REQUESTED :
|
||||
// break;
|
||||
// case USBPD_NOTIFY_MSG_NOT_SUPPORTED :
|
||||
// break;
|
||||
// case USBPD_NOTIFY_PE_DISABLED :
|
||||
// break;
|
||||
// case USBPD_NOTIFY_USBSTACK_START:
|
||||
// break;
|
||||
// case USBPD_NOTIFY_USBSTACK_STOP:
|
||||
// break;
|
||||
// case USBPD_NOTIFY_DATAROLESWAP_DFP :
|
||||
// break;
|
||||
// case USBPD_NOTIFY_DATAROLESWAP_UFP :
|
||||
// break;
|
||||
default:
|
||||
DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: USBPD_DPM_Notification:%d", EventVal);
|
||||
break;
|
||||
}
|
||||
/* USER CODE END USBPD_DPM_Notification */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback function called by PE layer when HardReset message received from PRL
|
||||
* @param PortNum The current port number
|
||||
* @param CurrentRole the current role
|
||||
* @param Status status on hard reset event
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_HardReset(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_HR_Status_TypeDef Status)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_HardReset */
|
||||
DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_HardReset");
|
||||
/* USER CODE END USBPD_DPM_HardReset */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the DPM to setup the new power level.
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_SetupNewPower(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_SetupNewPower */
|
||||
return USBPD_PWR_IF_SetProfile(PortNum);
|
||||
/* USER CODE END USBPD_DPM_SetupNewPower */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DPM callback to allow PE to retrieve information from DPM/PWR_IF.
|
||||
* @param PortNum Port number
|
||||
* @param DataId Type of data to be updated in DPM based on @ref USBPD_CORE_DataInfoType_TypeDef
|
||||
* @param Ptr Pointer on address where DPM data should be written (u8 pointer)
|
||||
* @param Size Pointer on nb of u8 written by DPM
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_GetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t *Size)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_GetDataInfo */
|
||||
/* Check type of information targeted by request */
|
||||
switch(DataId)
|
||||
{
|
||||
// case USBPD_CORE_DATATYPE_REQ_VOLTAGE: /*!< Get voltage value requested for BIST tests, expect 5V*/
|
||||
// *Size = 4;
|
||||
// (void)memcpy((uint8_t *)Ptr, (uint8_t *)&DPM_Ports[PortNum].DPM_RequestedVoltage, *Size);
|
||||
// break;
|
||||
// case USBPD_CORE_DATATYPE_SRC_PDO: /*!< Handling of port Source PDO */
|
||||
// break;
|
||||
// case USBPD_CORE_PPS_STATUS: /*!< PPS Status message content */
|
||||
// break;
|
||||
// case USBPD_CORE_SNK_EXTENDED_CAPA: /*!< Retrieve of Sink Extended capability message content*/
|
||||
// break;
|
||||
// case USBPD_CORE_INFO_STATUS: /*!< Information status message content */
|
||||
// break;
|
||||
// case USBPD_CORE_MANUFACTURER_INFO: /*!< Retrieve of Manufacturer info message content */
|
||||
// break;
|
||||
// case USBPD_CORE_BATTERY_STATUS: /*!< Retrieve of Battery status message content */
|
||||
// break;
|
||||
// case USBPD_CORE_BATTERY_CAPABILITY: /*!< Retrieve of Battery capability message content */
|
||||
// break;
|
||||
default:
|
||||
DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_GetDataInfo:%d", DataId);
|
||||
break;
|
||||
}
|
||||
/* USER CODE END USBPD_DPM_GetDataInfo */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DPM callback to allow PE to update information in DPM/PWR_IF.
|
||||
* @param PortNum Port number
|
||||
* @param DataId Type of data to be updated in DPM based on @ref USBPD_CORE_DataInfoType_TypeDef
|
||||
* @param Ptr Pointer on the data
|
||||
* @param Size Nb of bytes to be updated in DPM
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_SetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t Size)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_SetDataInfo */
|
||||
/* Check type of information targeted by request */
|
||||
switch(DataId)
|
||||
{
|
||||
// case USBPD_CORE_DATATYPE_RDO_POSITION: /*!< Reset the PDO position selected by the sink only */
|
||||
// break;
|
||||
// case USBPD_CORE_DATATYPE_RCV_SRC_PDO: /*!< Storage of Received Source PDO values */
|
||||
// break;
|
||||
// case USBPD_CORE_DATATYPE_RCV_SNK_PDO: /*!< Storage of Received Sink PDO values */
|
||||
// break;
|
||||
// case USBPD_CORE_DATATYPE_RCV_REQ_PDO : /*!< Storage of Received Sink Request PDO value */
|
||||
// if (Size == 4)
|
||||
// {
|
||||
// memcpy((uint8_t *)&DPM_Ports[PortNum].DPM_RcvRequestDOMsg, Ptr, 4);
|
||||
// }
|
||||
// break;
|
||||
// case USBPD_CORE_INFO_STATUS: /*!< Information status message content */
|
||||
// break;
|
||||
// case USBPD_CORE_ALERT: /*!< Storing of received Alert message content */
|
||||
// break;
|
||||
// case USBPD_CORE_GET_MANUFACTURER_INFO: /*!< Storing of received Get Manufacturer info message content */
|
||||
// break;
|
||||
// case USBPD_CORE_GET_BATTERY_STATUS: /*!< Storing of received Get Battery status message content */
|
||||
// break;
|
||||
// case USBPD_CORE_GET_BATTERY_CAPABILITY: /*!< Storing of received Get Battery capability message content*/
|
||||
// break;
|
||||
// case USBPD_CORE_SNK_EXTENDED_CAPA: /*!< Storing of Sink Extended capability message content */
|
||||
// break;
|
||||
default:
|
||||
DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_SetDataInfo:%d", DataId);
|
||||
break;
|
||||
}
|
||||
/* USER CODE END USBPD_DPM_SetDataInfo */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Evaluate received Request Message from Sink port
|
||||
* @param PortNum Port number
|
||||
* @param PtrPowerObject Pointer on the power data object
|
||||
* @retval USBPD status : USBPD_ACCEPT, USBPD_REJECT, USBPD_WAIT, USBPD_GOTOMIN
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_EvaluateRequest(uint8_t PortNum, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObject)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_EvaluateRequest */
|
||||
/*
|
||||
Set power data object to initialize value.
|
||||
This parameter is used by the stack to start or not tPPSTimeout
|
||||
(in case of USBPD_CORE_PDO_TYPE_APDO, stack will wait for periodic request
|
||||
from the port partner in PPS mode).
|
||||
*/
|
||||
*PtrPowerObject = USBPD_CORE_PDO_TYPE_FIXED;
|
||||
|
||||
DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_EvaluateRequest");
|
||||
return USBPD_REJECT;
|
||||
/* USER CODE END USBPD_DPM_EvaluateRequest */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback to be used by PE to evaluate a Vconn swap
|
||||
* @param PortNum Port number
|
||||
* @retval USBPD_ACCEPT, USBPD_REJECT, USBPD_WAIT
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_EvaluateVconnSwap(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_EvaluateVconnSwap */
|
||||
USBPD_StatusTypeDef status = USBPD_REJECT;
|
||||
if (USBPD_TRUE == DPM_USER_Settings[PortNum].PE_VconnSwap)
|
||||
{
|
||||
status = USBPD_ACCEPT;
|
||||
}
|
||||
|
||||
return status;
|
||||
/* USER CODE END USBPD_DPM_EvaluateVconnSwap */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback to be used by PE to manage VConn
|
||||
* @param PortNum Port number
|
||||
* @param State Enable or Disable VConn on CC lines
|
||||
* @retval USBPD_ACCEPT, USBPD_REJECT
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_PE_VconnPwr(uint8_t PortNum, USBPD_FunctionalState State)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_PE_VconnPwr */
|
||||
return USBPD_ERROR;
|
||||
/* USER CODE END USBPD_DPM_PE_VconnPwr */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DPM callback to allow PE to forward extended message information.
|
||||
* @param PortNum Port number
|
||||
* @param MsgType Type of message to be handled in DPM
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref USBPD_EXT_SECURITY_REQUEST Security Request extended message
|
||||
* @arg @ref USBPD_EXT_SECURITY_RESPONSE Security Response extended message
|
||||
* @param ptrData Pointer on address Extended Message data could be read (u8 pointer)
|
||||
* @param DataSize Nb of u8 that compose Extended message
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_ExtendedMessageReceived(uint8_t PortNum, USBPD_ExtendedMsg_TypeDef MsgType, uint8_t *ptrData, uint16_t DataSize)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_ExtendedMessageReceived */
|
||||
|
||||
/* USER CODE END USBPD_DPM_ExtendedMessageReceived */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DPM callback to allow PE to enter ERROR_RECOVERY state.
|
||||
* @param PortNum Port number
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_DPM_EnterErrorRecovery(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_EnterErrorRecovery */
|
||||
/* Inform CAD to enter recovery mode */
|
||||
USBPD_CAD_EnterErrorRecovery(PortNum);
|
||||
/* USER CODE END USBPD_DPM_EnterErrorRecovery */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback used to ask application the reply status for a DataRoleSwap request
|
||||
* @note if the callback is not set (ie NULL) the stack will automatically reject the request
|
||||
* @param PortNum Port number
|
||||
* @retval Returned values are:
|
||||
@ref USBPD_ACCEPT if DRS can be accepted
|
||||
@ref USBPD_REJECT if DRS is not accepted in one data role (DFP or UFP) or in PD2.0 config
|
||||
@ref USBPD_NOTSUPPORTED if DRS is not supported at all by the application (in both data roles) - P3.0 only
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_EvaluateDataRoleSwap(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_EvaluateDataRoleSwap */
|
||||
USBPD_StatusTypeDef status = USBPD_REJECT;
|
||||
/* Sent NOT_SUPPORTED if DRS is not supported at all by the application (in both data roles) - P3.0 only */
|
||||
if ((USBPD_FALSE == DPM_USER_Settings[PortNum].PE_DataSwap)
|
||||
|| ((USBPD_FALSE == DPM_USER_Settings[PortNum].PE_DR_Swap_To_DFP)
|
||||
&& (USBPD_FALSE == DPM_USER_Settings[PortNum].PE_DR_Swap_To_UFP)))
|
||||
{
|
||||
status = USBPD_NOTSUPPORTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ACCEPT DRS if at least supported by 1 data role */
|
||||
if (((USBPD_TRUE == DPM_USER_Settings[PortNum].PE_DR_Swap_To_DFP) && (USBPD_PORTDATAROLE_UFP == DPM_Params[PortNum].PE_DataRole))
|
||||
|| ((USBPD_TRUE == DPM_USER_Settings[PortNum].PE_DR_Swap_To_UFP) && (USBPD_PORTDATAROLE_DFP == DPM_Params[PortNum].PE_DataRole)))
|
||||
{
|
||||
status = USBPD_ACCEPT;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
/* USER CODE END USBPD_DPM_EvaluateDataRoleSwap */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback to be used by PE to check is VBUS is ready or present
|
||||
* @param PortNum Port number
|
||||
* @param Vsafe Vsafe status based on @ref USBPD_VSAFE_StatusTypeDef
|
||||
* @retval USBPD_DISABLE or USBPD_ENABLE
|
||||
*/
|
||||
USBPD_FunctionalState USBPD_DPM_IsPowerReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_DPM_IsPowerReady */
|
||||
return ((USBPD_OK == USBPD_PWR_IF_SupplyReady(PortNum, Vsafe)) ? USBPD_ENABLE : USBPD_DISABLE);
|
||||
/* USER CODE END USBPD_DPM_IsPowerReady */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP3 USBPD USER Functions PD messages requests
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a hard reset
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestHardReset(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_HardReset(PortNum);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "HARD RESET not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a cable reset.
|
||||
* @note Only a DFP Shall generate Cable Reset Signaling. A DFP Shall only generate Cable Reset Signaling within an Explicit Contract.
|
||||
The DFP has to be supplying VCONN prior to a Cable Reset
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestCableReset(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CableReset(PortNum);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "CABLE RESET not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a GOTOMIN message
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGotoMin(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GOTOMIN, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GOTOMIN not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a PING message
|
||||
* @note In USB-PD stack, only ping management for P3.0 is implemented.
|
||||
* If PD2.0 is used, PING timer needs to be implemented on user side.
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestPing(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_PING, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "PING not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a request message.
|
||||
* @param PortNum The current port number
|
||||
* @param IndexSrcPDO Index on the selected SRC PDO (value between 1 to 7)
|
||||
* @param RequestedVoltage Requested voltage (in MV and use mainly for APDO)
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestMessageRequest(uint8_t PortNum, uint8_t IndexSrcPDO, uint16_t RequestedVoltage)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_ERROR;
|
||||
/* USER CODE BEGIN USBPD_DPM_RequestMessageRequest */
|
||||
/* To be adapted to call the PE function */
|
||||
/* _status = USBPD_PE_Send_Request(PortNum, rdo.d32, pdo_object);*/
|
||||
DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_RequestMessageRequest");
|
||||
/* USER CODE END USBPD_DPM_RequestMessageRequest */
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "REQUEST not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a GET_SRC_CAPA message
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetSourceCapability(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_SRC_CAP, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_SRC_CAPA not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a GET_SNK_CAPA message
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapability(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_SNK_CAP, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_SINK_CAPA not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to perform a Data Role Swap.
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestDataRoleSwap(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_DR_SWAP, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "DRS not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to perform a Power Role Swap.
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestPowerRoleSwap(uint8_t PortNum)
|
||||
{
|
||||
DPM_USER_ERROR_TRACE(PortNum, USBPD_ERROR, "PRS not accepted by the stack");
|
||||
return USBPD_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to perform a VCONN Swap.
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVconnSwap(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_VCONN_SWAP, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "VCS not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a soft reset
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type based on @ref USBPD_SOPType_TypeDef
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestSoftReset(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_SOFT_RESET, SOPType);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "SOFT_RESET not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a Source Capability message.
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestSourceCapability(uint8_t PortNum)
|
||||
{
|
||||
/* PE will directly get the PDO saved in structure @ref PWR_Port_PDO_Storage */
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_DataMessage(PortNum, USBPD_DATAMSG_SRC_CAPABILITIES, NULL);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "SRC_CAPA not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a VDM discovery identity
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoveryIdentify(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_ERROR;
|
||||
/* USER CODE BEGIN USBPD_DPM_RequestVDM_DiscoveryIdentify */
|
||||
if (USBPD_SOPTYPE_SOP == SOPType)
|
||||
{
|
||||
_status = USBPD_PE_SVDM_RequestIdentity(PortNum, SOPType);
|
||||
}
|
||||
/* USER CODE END USBPD_DPM_RequestVDM_DiscoveryIdentify */
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "VDM Discovery Ident not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a VDM discovery SVID
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoverySVID(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestSVID(PortNum, SOPType);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "VDM discovery SVID not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to perform a VDM Discovery mode message on one SVID.
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @param SVID SVID used for discovery mode message
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoveryMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestMode(PortNum, SOPType, SVID);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "VDM Discovery mode not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to perform a VDM mode enter.
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @param SVID SVID used for discovery mode message
|
||||
* @param ModeIndex Index of the mode to be entered
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_EnterMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint8_t ModeIndex)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestModeEnter(PortNum, SOPType, SVID, ModeIndex);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "VDM mode enter not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to perform a VDM mode exit.
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @param SVID SVID used for discovery mode message
|
||||
* @param ModeIndex Index of the mode to be exit
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_ExitMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint8_t ModeIndex)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestModeExit(PortNum, SOPType, SVID, ModeIndex);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "VDM mode exit not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a Display Port status
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @param SVID Used SVID
|
||||
* @param pDPStatus Pointer on DP Status data (32 bit)
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestDisplayPortStatus(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint32_t *pDPStatus)
|
||||
{
|
||||
USBPD_StatusTypeDef _status;
|
||||
/* USER CODE BEGIN USBPD_DPM_RequestDisplayPortStatus */
|
||||
/*USBPD_VDM_FillDPStatus(PortNum, (USBPD_DPStatus_TypeDef*)pDPStatus);*/
|
||||
/* USER CODE END USBPD_DPM_RequestDisplayPortStatus */
|
||||
_status = USBPD_PE_SVDM_RequestSpecific(PortNum, SOPType, SVDM_SPECIFIC_1, SVID);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "Display Port status not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
/**
|
||||
* @brief Request the PE to send a Display Port Config
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @param SVID Used SVID
|
||||
* @param pDPConfig Pointer on DP Config data (32 bit)
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestDisplayPortConfig(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint32_t *pDPConfig)
|
||||
{
|
||||
USBPD_StatusTypeDef _status;
|
||||
/* USER CODE BEGIN USBPD_DPM_RequestDisplayPortConfig */
|
||||
/*USBPD_VDM_FillDPConfig(PortNum, (USBPD_DPConfig_TypeDef*)pDPConfig);*/
|
||||
/* USER CODE END USBPD_DPM_RequestDisplayPortConfig */
|
||||
_status = USBPD_PE_SVDM_RequestSpecific(PortNum, SOPType, SVDM_SPECIFIC_2, SVID);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "Display Port Config not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to perform a VDM Attention.
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @param SVID Used SVID
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestAttention(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestAttention(PortNum, SOPType, SVID);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "VDM ATTENTION not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send an ALERT to port partner
|
||||
* @param PortNum The current port number
|
||||
* @param Alert Alert based on @ref USBPD_ADO_TypeDef
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestAlert(uint8_t PortNum, USBPD_ADO_TypeDef Alert)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_DataMessage(PortNum, USBPD_DATAMSG_ALERT, (uint32_t*)&Alert.d32);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "ALERT not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to get a source capability extended
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetSourceCapabilityExt(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_SRC_CAPEXT, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_SRC_CAPA_EXT not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to get a sink capability extended
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapabilityExt(uint8_t PortNum)
|
||||
{
|
||||
DPM_USER_ERROR_TRACE(PortNum, USBPD_ERROR, "GET_SINK_CAPA_EXT not accepted by the stack");
|
||||
return USBPD_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to get a manufacturer info
|
||||
* @param PortNum The current port number
|
||||
* @param SOPType SOP Type
|
||||
* @param pManuInfoData Pointer on manufacturer info based on @ref USBPD_GMIDB_TypeDef
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetManufacturerInfo(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint8_t* pManuInfoData)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_ERROR;
|
||||
if (USBPD_SOPTYPE_SOP == SOPType)
|
||||
{
|
||||
_status = USBPD_PE_SendExtendedMessage(PortNum, SOPType, USBPD_EXT_GET_MANUFACTURER_INFO, (uint8_t*)pManuInfoData, sizeof(USBPD_GMIDB_TypeDef));
|
||||
}
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_MANU_INFO not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to request a GET_PPS_STATUS
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetPPS_Status(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_PPS_STATUS, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_PPS_STATUS not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to request a GET_STATUS
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetStatus(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_STATUS, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_STATUS not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to perform a Fast Role Swap.
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestFastRoleSwap(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_FR_SWAP, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "FRS not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a GET_COUNTRY_CODES message
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetCountryCodes(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_COUNTRY_CODES, USBPD_SOPTYPE_SOP);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_COUNTRY_CODES not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a GET_COUNTRY_INFO message
|
||||
* @param PortNum The current port number
|
||||
* @param CountryCode Country code (1st character and 2nd of the Alpha-2 Country)
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetCountryInfo(uint8_t PortNum, uint16_t CountryCode)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_Request_DataMessage(PortNum, USBPD_DATAMSG_GET_COUNTRY_INFO, (uint32_t*)&CountryCode);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_COUNTRY_INFO not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a GET_BATTERY_CAPA
|
||||
* @param PortNum The current port number
|
||||
* @param pBatteryCapRef Pointer on the Battery Capability reference
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetBatteryCapability(uint8_t PortNum, uint8_t *pBatteryCapRef)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_SendExtendedMessage(PortNum, USBPD_SOPTYPE_SOP, USBPD_EXT_GET_BATTERY_CAP, (uint8_t*)pBatteryCapRef, 1);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_BATTERY_CAPA not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a GET_BATTERY_STATUS
|
||||
* @param PortNum The current port number
|
||||
* @param pBatteryStatusRef Pointer on the Battery Status reference
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetBatteryStatus(uint8_t PortNum, uint8_t *pBatteryStatusRef)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_PE_SendExtendedMessage(PortNum, USBPD_SOPTYPE_SOP, USBPD_EXT_GET_BATTERY_STATUS, (uint8_t*)pBatteryStatusRef, 1);
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "GET_BATTERY_STATUS not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request the PE to send a SECURITY_REQUEST
|
||||
* @param PortNum The current port number
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestSecurityRequest(uint8_t PortNum)
|
||||
{
|
||||
USBPD_StatusTypeDef _status = USBPD_ERROR;
|
||||
DPM_USER_ERROR_TRACE(PortNum, _status, "SECURITY_REQUEST not accepted by the stack");
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_USER_PRIVATE_FUNCTIONS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS */
|
||||
|
||||
/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
180
USBPD/usbpd_dpm_user.h
Normal file
180
USBPD/usbpd_dpm_user.h
Normal file
@@ -0,0 +1,180 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_dpm_user.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for usbpd_dpm_user.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef __USBPD_DPM_USER_H_
|
||||
#define __USBPD_DPM_USER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Include */
|
||||
|
||||
/* USER CODE END Include */
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_DPM_USER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t PE_DataSwap : 1U; /*!< support data swap */
|
||||
uint32_t PE_VconnSwap : 1U; /*!< support VCONN swap */
|
||||
uint32_t PE_DR_Swap_To_DFP : 1U; /*!< If supported, DR Swap to DFP can be accepted or not by the user else directly rejected */
|
||||
uint32_t PE_DR_Swap_To_UFP : 1U; /*!< If supported, DR Swap to UFP can be accepted or not by the user else directly rejected */
|
||||
uint32_t Reserved1 :28U; /*!< Reserved bits */
|
||||
uint32_t Reserved_ReqPower[6]; /*!< Reserved bits to match with Resquested power information */
|
||||
USBPD_MIDB_TypeDef DPM_ManuInfoPort; /*!< Manufacturer information used for the port */
|
||||
uint32_t ReservedSnkCapa[6]; /*!< Reserved bits to match with SnkCapaExt information */
|
||||
uint16_t ReservedManu; /*!< Reserved bits to match with Manufacturer information */
|
||||
} USBPD_USER_SettingsTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t XID; /*!< Value provided by the USB-IF assigned to the product */
|
||||
uint16_t VID; /*!< Vendor ID (assigned by the USB-IF) */
|
||||
uint16_t PID; /*!< Product ID (assigned by the manufacturer) */
|
||||
} USBPD_IdSettingsTypeDef;
|
||||
/* USER CODE BEGIN Typedef */
|
||||
|
||||
/* USER CODE END Typedef */
|
||||
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Constant */
|
||||
|
||||
/* USER CODE END Constant */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Private_Variables */
|
||||
|
||||
/* USER CODE END Private_Variables */
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup USBPD_USER_EXPORTED_FUNCTIONS
|
||||
* @{
|
||||
*/
|
||||
/** @addtogroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP1
|
||||
* @{
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_UserInit(void);
|
||||
void USBPD_DPM_WaitForTime(uint32_t Time);
|
||||
void USBPD_DPM_UserExecute(void const *argument);
|
||||
void USBPD_DPM_UserCableDetection(uint8_t PortNum, USBPD_CAD_EVENT State);
|
||||
void USBPD_DPM_UserTimerCounter(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP2
|
||||
* @{
|
||||
*/
|
||||
void USBPD_DPM_Notification(uint8_t PortNum, USBPD_NotifyEventValue_TypeDef EventVal);
|
||||
USBPD_StatusTypeDef USBPD_DPM_SetupNewPower(uint8_t PortNum);
|
||||
void USBPD_DPM_HardReset(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_HR_Status_TypeDef Status);
|
||||
void USBPD_DPM_ExtendedMessageReceived(uint8_t PortNum, USBPD_ExtendedMsg_TypeDef MsgType, uint8_t *ptrData, uint16_t DataSize);
|
||||
void USBPD_DPM_GetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId , uint8_t *Ptr, uint32_t *Size);
|
||||
void USBPD_DPM_SetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId , uint8_t *Ptr, uint32_t Size);
|
||||
USBPD_StatusTypeDef USBPD_DPM_EvaluateRequest(uint8_t PortNum, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObject);
|
||||
USBPD_StatusTypeDef USBPD_DPM_EvaluateVconnSwap(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_PE_VconnPwr(uint8_t PortNum, USBPD_FunctionalState State);
|
||||
void USBPD_DPM_EnterErrorRecovery(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_EvaluateDataRoleSwap(uint8_t PortNum);
|
||||
USBPD_FunctionalState USBPD_DPM_IsPowerReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP3
|
||||
* @{
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestHardReset(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestCableReset(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGotoMin(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestPing(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestMessageRequest(uint8_t PortNum, uint8_t IndexSrcPDO, uint16_t RequestedVoltage);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetSourceCapability(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapability(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestDataRoleSwap(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestPowerRoleSwap(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVconnSwap(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestSoftReset(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestSourceCapability(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoveryIdentify(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoverySVID(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoveryMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_EnterMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint8_t ModeIndex);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestVDM_ExitMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint8_t ModeIndex);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestDisplayPortStatus(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint32_t *pDPStatus);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestDisplayPortConfig(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint32_t *pDPConfig);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestAttention(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestAlert(uint8_t PortNum, USBPD_ADO_TypeDef Alert);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetSourceCapabilityExt(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapabilityExt(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetManufacturerInfo(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint8_t* pManuInfoData);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetStatus(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestFastRoleSwap(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetPPS_Status(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetCountryCodes(uint8_t PortNum);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetCountryInfo(uint8_t PortNum, uint16_t CountryCode);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetBatteryCapability(uint8_t PortNum, uint8_t *pBatteryCapRef);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestGetBatteryStatus(uint8_t PortNum, uint8_t *pBatteryStatusRef);
|
||||
USBPD_StatusTypeDef USBPD_DPM_RequestSecurityRequest(uint8_t PortNum);
|
||||
/* USER CODE BEGIN Function */
|
||||
|
||||
/* USER CODE END Function */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_DPM_USER_H_ */
|
||||
149
USBPD/usbpd_pdo_defs.h
Normal file
149
USBPD/usbpd_pdo_defs.h
Normal file
@@ -0,0 +1,149 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_pdo_defs.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for definition of PDO/APDO values for 2 ports(DRP/SNK) configuration
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef __USBPD_PDO_DEF_H_
|
||||
#define __USBPD_PDO_DEF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_def.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Define ------------------------------------------------------------------*/
|
||||
#define PORT0_NB_SOURCEPDO 1U /* Number of Source PDOs (applicable for port 0) */
|
||||
#define PORT0_NB_SINKPDO 0U /* Number of Sink PDOs (applicable for port 0) */
|
||||
#define PORT1_NB_SOURCEPDO 0U /* Number of Source PDOs (applicable for port 1) */
|
||||
#define PORT1_NB_SINKPDO 0U /* Number of Sink PDOs (applicable for port 1) */
|
||||
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN typedef */
|
||||
/**
|
||||
* @brief USBPD Port PDO Structure definition
|
||||
*
|
||||
*/
|
||||
/* USER CODE END typedef */
|
||||
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN Exported_Define */
|
||||
|
||||
#define USBPD_CORE_PDO_SRC_FIXED_MAX_CURRENT 3
|
||||
#define USBPD_CORE_PDO_SNK_FIXED_MAX_CURRENT 1500
|
||||
|
||||
/* USER CODE END Exported_Define */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN constants */
|
||||
|
||||
/* USER CODE END constants */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN macro */
|
||||
|
||||
/* USER CODE END macro */
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN variables */
|
||||
/* USER CODE END variables */
|
||||
|
||||
#ifndef __USBPD_PWR_IF_C
|
||||
extern uint32_t PORT0_PDO_ListSRC[USBPD_MAX_NB_PDO];
|
||||
extern uint32_t PORT0_PDO_ListSNK[USBPD_MAX_NB_PDO];
|
||||
#else
|
||||
/* Definition of Source PDO for Port 0 */
|
||||
uint32_t PORT0_PDO_ListSRC[USBPD_MAX_NB_PDO] =
|
||||
{
|
||||
/* PDO 1 */
|
||||
(
|
||||
USBPD_PDO_TYPE_FIXED | /* Fixed supply PDO */
|
||||
|
||||
USBPD_PDO_SRC_FIXED_SET_VOLTAGE(5000U) | /* Voltage in mV */
|
||||
USBPD_PDO_SRC_FIXED_SET_MAX_CURRENT(5000U) | /* Max current in mA */
|
||||
USBPD_PDO_SRC_FIXED_PEAKCURRENT_EQUAL | /* Peak Current info */
|
||||
|
||||
/* Common definitions applicable to all PDOs, defined only in PDO 1 */
|
||||
USBPD_PDO_SRC_FIXED_UNCHUNK_NOT_SUPPORTED | /* Unchunked Extended Messages */
|
||||
USBPD_PDO_SRC_FIXED_DRD_SUPPORTED | /* Dual-Role Data */
|
||||
USBPD_PDO_SRC_FIXED_USBCOMM_NOT_SUPPORTED | /* USB Communications */
|
||||
USBPD_PDO_SRC_FIXED_EXT_POWER_NOT_AVAILABLE | /* External Power */
|
||||
USBPD_PDO_SRC_FIXED_USBSUSPEND_NOT_SUPPORTED | /* USB Suspend Supported */
|
||||
USBPD_PDO_SRC_FIXED_DRP_NOT_SUPPORTED /* Dual-Role Power */
|
||||
),
|
||||
|
||||
/* PDO 2 */ (0x00000000U),
|
||||
|
||||
/* PDO 3 */ (0x00000000U),
|
||||
|
||||
/* PDO 4 */ (0x00000000U),
|
||||
|
||||
/* PDO 5 */ (0x00000000U),
|
||||
|
||||
/* PDO 6 */ (0x00000000U),
|
||||
|
||||
/* PDO 7 */ (0x00000000U),
|
||||
|
||||
};
|
||||
|
||||
/* Definition of Sink PDO for Port 0 */
|
||||
uint32_t PORT0_PDO_ListSNK[USBPD_MAX_NB_PDO] =
|
||||
{
|
||||
|
||||
/* PDO 1 */ (0x00000000U),
|
||||
|
||||
/* PDO 2 */ (0x00000000U),
|
||||
|
||||
/* PDO 3 */ (0x00000000U),
|
||||
|
||||
/* PDO 4 */ (0x00000000U),
|
||||
|
||||
/* PDO 5 */ (0x00000000U),
|
||||
|
||||
/* PDO 6 */ (0x00000000U),
|
||||
|
||||
/* PDO 7 */ (0x00000000U),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN functions */
|
||||
|
||||
/* USER CODE END functions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_PDO_DEF_H_ */
|
||||
389
USBPD/usbpd_pwr_if.c
Normal file
389
USBPD/usbpd_pwr_if.c
Normal file
@@ -0,0 +1,389 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_pwr_if.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains power interface control functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#define __USBPD_PWR_IF_C
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_pwr_if.h"
|
||||
#include "usbpd_hw_if.h"
|
||||
#include "usbpd_dpm_core.h"
|
||||
#include "usbpd_dpm_conf.h"
|
||||
#include "usbpd_pdo_defs.h"
|
||||
#include "usbpd_core.h"
|
||||
#if defined(_TRACE)
|
||||
#include "usbpd_trace.h"
|
||||
#endif /* _TRACE */
|
||||
#include "string.h"
|
||||
/* USER CODE BEGIN Include */
|
||||
|
||||
/* USER CODE END Include */
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_TypeDef
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN Private_Typedef */
|
||||
|
||||
/* USER CODE END Private_Typedef */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN Private_Define */
|
||||
|
||||
/* USER CODE END Private_Define */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macros ------------------------------------------------------------*/
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#if defined(_TRACE)
|
||||
#define PWR_IF_DEBUG_TRACE(_PORT_, __MESSAGE__) USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (_PORT_), 0u, (uint8_t*)(__MESSAGE__), sizeof(__MESSAGE__) - 1u)
|
||||
#else
|
||||
#define PWR_IF_DEBUG_TRACE(_PORT_, __MESSAGE__)
|
||||
#endif /* _TRACE */
|
||||
/* USER CODE BEGIN Private_Macro */
|
||||
|
||||
/* USER CODE END Private_Macro */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN Private_Variables */
|
||||
|
||||
/* USER CODE END Private_Variables */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
|
||||
|
||||
/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize structures and variables related to power board profiles
|
||||
* used by Sink and Source, for all available ports.
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_Init(void)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_Init */
|
||||
return USBPD_ERROR;
|
||||
/* USER CODE END USBPD_PWR_IF_Init */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the required power profile, now it works only with Fixed ones
|
||||
* @param PortNum Port number
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_SetProfile(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_SetProfile */
|
||||
USBPD_StatusTypeDef _status = USBPD_ERROR;
|
||||
PWR_IF_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_PWR_IF_SetProfile");
|
||||
/* if (BSP_ERROR_NONE == BSP_USBPD_PWR_VBUSSetVoltage_Fixed(PortNum, 5000, 3000, 3000))
|
||||
{
|
||||
_status = USBPD_OK;
|
||||
}
|
||||
*/
|
||||
return _status;
|
||||
/* USER CODE END USBPD_PWR_IF_SetProfile */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the power on a specified port is ready
|
||||
* @param PortNum Port number
|
||||
* @param Vsafe Vsafe status based on @ref USBPD_VSAFE_StatusTypeDef
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_SupplyReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_SupplyReady */
|
||||
USBPD_StatusTypeDef status = USBPD_ERROR;
|
||||
uint32_t _voltage;
|
||||
|
||||
/* check for valid port */
|
||||
if (!USBPD_PORT_IsValid(PortNum))
|
||||
{
|
||||
return USBPD_ERROR;
|
||||
}
|
||||
|
||||
BSP_USBPD_PWR_VBUSGetVoltage(PortNum, &_voltage);
|
||||
if (USBPD_VSAFE_0V == Vsafe)
|
||||
{
|
||||
/* Vsafe0V */
|
||||
status = ((_voltage < USBPD_PWR_LOW_VBUS_THRESHOLD) ? USBPD_OK : USBPD_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Vsafe5V */
|
||||
status = ((_voltage > USBPD_PWR_HIGH_VBUS_THRESHOLD) ? USBPD_OK : USBPD_ERROR);
|
||||
}
|
||||
|
||||
return status;
|
||||
/* USER CODE END USBPD_PWR_IF_SupplyReady */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables VBUS power on a specified port
|
||||
* @param PortNum Port number
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSEnable(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_VBUSEnable */
|
||||
USBPD_StatusTypeDef _status = (USBPD_StatusTypeDef)HW_IF_PWR_Enable(PortNum, USBPD_ENABLE, CCNONE, USBPD_FALSE, USBPD_PORTPOWERROLE_SRC);
|
||||
return _status;
|
||||
/* USER CODE END USBPD_PWR_IF_VBUSEnable */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable VBUS/VCONN the power on a specified port
|
||||
* @param PortNum Port number
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSDisable(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_VBUSDisable */
|
||||
USBPD_StatusTypeDef _status = (USBPD_StatusTypeDef)HW_IF_PWR_Enable(PortNum, USBPD_DISABLE, CCNONE, USBPD_FALSE, USBPD_PORTPOWERROLE_SRC);
|
||||
return _status;
|
||||
/* USER CODE END USBPD_PWR_IF_VBUSDisable */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the power on a specified port is enabled
|
||||
* @param PortNum Port number
|
||||
* @retval USBPD_ENABLE or USBPD_DISABLE
|
||||
*/
|
||||
USBPD_FunctionalState USBPD_PWR_IF_VBUSIsEnabled(uint8_t PortNum)
|
||||
{
|
||||
/* Get the Status of the port */
|
||||
return USBPD_PORT_IsValid(PortNum) ? (USBPD_FunctionalState)HW_IF_PWR_VBUSIsEnabled(PortNum) : USBPD_DISABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads the voltage and the current on a specified port
|
||||
* @param PortNum Port number
|
||||
* @param pVoltage: The Voltage in mV
|
||||
* @param pCurrent: The Current in mA
|
||||
* @retval USBPD_ERROR or USBPD_OK
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_ReadVA(uint8_t PortNum, uint16_t *pVoltage, uint16_t *pCurrent)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_ReadVA */
|
||||
return USBPD_ERROR;
|
||||
/* USER CODE END USBPD_PWR_IF_ReadVA */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the VConn on the port.
|
||||
* @param PortNum Port number
|
||||
* @param CC Specifies the CCx to be selected based on @ref CCxPin_TypeDef structure
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_Enable_VConn(uint8_t PortNum, CCxPin_TypeDef CC)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_Enable_VConn */
|
||||
return USBPD_ERROR;
|
||||
/* USER CODE END USBPD_PWR_IF_Enable_VConn */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the VConn on the port.
|
||||
* @param PortNum Port number
|
||||
* @param CC Specifies the CCx to be selected based on @ref CCxPin_TypeDef structure
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_Disable_VConn(uint8_t PortNum, CCxPin_TypeDef CC)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_Disable_VConn */
|
||||
return USBPD_ERROR;
|
||||
/* USER CODE END USBPD_PWR_IF_Disable_VConn */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allow PDO data reading from PWR_IF storage.
|
||||
* @param PortNum Port number
|
||||
* @param DataId Type of data to be read from PWR_IF
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref USBPD_CORE_DATATYPE_SRC_PDO Source PDO reading requested
|
||||
* @arg @ref USBPD_CORE_DATATYPE_SNK_PDO Sink PDO reading requested
|
||||
* @param Ptr Pointer on address where PDO values should be written (u8 pointer)
|
||||
* @param Size Pointer on nb of u32 written by PWR_IF (nb of PDOs)
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_GetPortPDOs(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t *Size)
|
||||
{
|
||||
if (DataId == USBPD_CORE_DATATYPE_SRC_PDO)
|
||||
{
|
||||
*Size = PORT0_NB_SOURCEPDO;
|
||||
memcpy(Ptr,PORT0_PDO_ListSRC, sizeof(uint32_t) * PORT0_NB_SOURCEPDO);
|
||||
}
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_GetPortPDOs */
|
||||
|
||||
/* USER CODE END USBPD_PWR_IF_GetPortPDOs */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Find out SRC PDO pointed out by a position provided in a Request DO (from Sink).
|
||||
* @param PortNum Port number
|
||||
* @param RdoPosition RDO Position in list of provided PDO
|
||||
* @param Pdo Pointer on PDO value pointed out by RDO position (u32 pointer)
|
||||
* @retval Status of search
|
||||
* USBPD_OK : Src PDO found for requested DO position (output Pdo parameter is set)
|
||||
* USBPD_FAIL : Position is not compliant with current Src PDO for this port (no corresponding PDO value)
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_SearchRequestedPDO(uint8_t PortNum, uint32_t RdoPosition, uint32_t *Pdo)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_SearchRequestedPDO */
|
||||
return USBPD_FAIL;
|
||||
/* USER CODE END USBPD_PWR_IF_SearchRequestedPDO */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function called in case of critical issue is detected to switch in safety mode.
|
||||
* @param ErrorType Type of error detected by monitoring (based on @ref USBPD_PWR_IF_ERROR)
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_AlarmType(USBPD_PWR_IF_ERROR ErrorType)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_AlarmType */
|
||||
|
||||
/* USER CODE END USBPD_PWR_IF_AlarmType */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief the function is called in case of critical issue is detected to switch in safety mode.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_Alarm()
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_Alarm */
|
||||
|
||||
/* USER CODE END USBPD_PWR_IF_Alarm */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function is called to get VBUS power status.
|
||||
* @param PortNum Port number
|
||||
* @param PowerTypeStatus Power type status based on @ref USBPD_VBUSPOWER_STATUS
|
||||
* @retval UBBPD_TRUE or USBPD_FALSE
|
||||
*/
|
||||
uint8_t USBPD_PWR_IF_GetVBUSStatus(uint8_t PortNum, USBPD_VBUSPOWER_STATUS PowerTypeStatus)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_GetVBUSStatus */
|
||||
uint8_t _status = USBPD_FALSE;
|
||||
uint32_t _vbus = HW_IF_PWR_GetVoltage(PortNum);
|
||||
|
||||
switch(PowerTypeStatus)
|
||||
{
|
||||
case USBPD_PWR_BELOWVSAFE0V :
|
||||
if (_vbus < USBPD_PWR_LOW_VBUS_THRESHOLD) _status = USBPD_TRUE;
|
||||
break;
|
||||
case USBPD_PWR_VSAFE5V :
|
||||
if (_vbus >= USBPD_PWR_HIGH_VBUS_THRESHOLD) _status = USBPD_TRUE;
|
||||
break;
|
||||
case USBPD_PWR_SNKDETACH:
|
||||
if (_vbus < USBPD_PWR_HIGH_VBUS_THRESHOLD) _status = USBPD_TRUE;
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
return _status;
|
||||
/* USER CODE END USBPD_PWR_IF_GetVBUSStatus */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function is called to set the VBUS threshold when a request has been accepted.
|
||||
* @param PortNum Port number
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_UpdateVbusThreshold(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_UpdateVbusThreshold */
|
||||
/* USER CODE END USBPD_PWR_IF_UpdateVbusThreshold */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function is called to reset the VBUS threshold when there is a power reset.
|
||||
* @param PortNum Port number
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_ResetVbusThreshold(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_PWR_IF_ResetVbusThreshold */
|
||||
/* USER CODE END USBPD_PWR_IF_ResetVbusThreshold */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN USBPD_USER_EXPORTED_FUNCTIONS_Definition */
|
||||
|
||||
/* USER CODE END USBPD_USER_EXPORTED_FUNCTIONS_Definition */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS_Definition */
|
||||
|
||||
/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS_Definition */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
362
USBPD/usbpd_pwr_if.h
Normal file
362
USBPD/usbpd_pwr_if.h
Normal file
@@ -0,0 +1,362 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_pwr_if.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the headers of usbpd_pw_if.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef __USBPD_PW_IF_H_
|
||||
#define __USBPD_PW_IF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_def.h"
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/** @defgroup USBPD_USER_PWR_IF_Exported_Macros USBPD PWR IF Exported Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* enumeration of the different power status available for VBUS */
|
||||
typedef enum
|
||||
{
|
||||
USBPD_PWR_BELOWVSAFE0V,
|
||||
USBPD_PWR_VSAFE5V,
|
||||
USBPD_PWR_SNKDETACH
|
||||
} USBPD_VBUSPOWER_STATUS;
|
||||
|
||||
/* Enumeration of the different errors detected by power IF */
|
||||
typedef enum{
|
||||
USBPD_PWR_IF_OTHER = 0U,
|
||||
USBPD_PWR_IF_NMI = 2U,
|
||||
USBPD_PWR_IF_HARD_FAULT = 3U,
|
||||
USBPD_PWR_IF_OVER_CURRENT = 4U,
|
||||
} USBPD_PWR_IF_ERROR;
|
||||
|
||||
/* Macros used to convert values into PDO representation */
|
||||
#define PWR_V_20MV(_V_) ((uint16_t)(( (_V_) * 1000) / 20)) /* From Volt to 20mV multiples */
|
||||
#define PWR_V_50MV(_V_) ((uint16_t)(( (_V_) * 1000) / 50)) /* From Volt to 50mV multiples */
|
||||
#define PWR_V_100MV(_V_) ((uint16_t)(( (_V_) * 1000) / 100)) /* From Volt to 100mV multiples */
|
||||
#define PWR_A_10MA(_A_) ((uint16_t)(( (_A_) * 1000) / 10)) /* From Ampere to 10mA multiples */
|
||||
#define PWR_A_50MA(_A_) ((uint16_t)(( (_A_) * 1000) / 50)) /* From Ampere to 50mA multiples */
|
||||
#define PWR_W(_W_) ((uint16_t)(( (_W_) * 1000) / 250)) /* From Watt to 250mW multiples */
|
||||
|
||||
/* Macros used to get values from PDO representation */
|
||||
#define PWR_DECODE_50MV(_Value_) ((uint16_t)(((_Value_) * 50))) /* From 50mV multiples to mV */
|
||||
#define PWR_DECODE_100MV(_Value_) ((uint16_t)(((_Value_) * 100))) /* From 100mV multiples to mV */
|
||||
#define PWR_DECODE_10MA(_Value_) ((uint16_t)(((_Value_) * 10))) /* From 10mA multiples to mA */
|
||||
#define PWR_DECODE_50MA(_Value_) ((uint16_t)(((_Value_) * 50))) /* From 50mA multiples to mA */
|
||||
#define PWR_DECODE_MW(_Value_) ((uint16_t)(((_Value_) * 250))) /* From 250mW multiples to mW */
|
||||
|
||||
/* Macros used to describe the parameters in a PDO list */
|
||||
/* ---------------------------- FIXED --------------------------- */
|
||||
|
||||
/* Set voltage in mV in SRC Fixed PDO */
|
||||
#define USBPD_PDO_SRC_FIXED_SET_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_FIXED_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SRC_FIXED_VOLTAGE_Msk))
|
||||
|
||||
/* Set max current in mA in SRC Fixed PDO */
|
||||
#define USBPD_PDO_SRC_FIXED_SET_MAX_CURRENT(_MA_) (((PWR_A_10MA((_MA_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_FIXED_MAX_CURRENT_Pos) \
|
||||
& (USBPD_PDO_SRC_FIXED_MAX_CURRENT_Msk))
|
||||
|
||||
/* Set voltage in mV in SNK Fixed PDO */
|
||||
#define USBPD_PDO_SNK_FIXED_SET_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_FIXED_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SNK_FIXED_VOLTAGE_Msk))
|
||||
|
||||
/* Set operating current in mA in SNK Fixed PDO */
|
||||
#define USBPD_PDO_SNK_FIXED_SET_OP_CURRENT(_MA_) (((PWR_A_10MA((_MA_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_FIXED_OP_CURRENT_Pos) \
|
||||
& (USBPD_PDO_SNK_FIXED_OP_CURRENT_Msk))
|
||||
|
||||
/* ---------------------------- VARIABLE ------------------------ */
|
||||
|
||||
/* Set max voltage in mV in SRC VARIABLE PDO */
|
||||
#define USBPD_PDO_SRC_VARIABLE_SET_MAX_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_VARIABLE_MAX_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SRC_VARIABLE_MAX_VOLTAGE_Msk))
|
||||
|
||||
/* Set min voltage in mV in SRC VARIABLE PDO */
|
||||
#define USBPD_PDO_SRC_VARIABLE_SET_MIN_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_VARIABLE_MIN_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SRC_VARIABLE_MIN_VOLTAGE_Msk))
|
||||
|
||||
/* Set max current in mA in SRC VARIABLE PDO */
|
||||
#define USBPD_PDO_SRC_VARIABLE_SET_MAX_CURRENT(_MA_) (((PWR_A_10MA((_MA_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_VARIABLE_MAX_CURRENT_Pos) \
|
||||
& (USBPD_PDO_SRC_VARIABLE_MAX_CURRENT_Msk))
|
||||
|
||||
/* Set max voltage in mV in SNK VARIABLE PDO */
|
||||
#define USBPD_PDO_SNK_VARIABLE_SET_MAX_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_VARIABLE_MAX_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SNK_VARIABLE_MAX_VOLTAGE_Msk))
|
||||
|
||||
/* Set min voltage in mV in SNK VARIABLE PDO */
|
||||
#define USBPD_PDO_SNK_VARIABLE_SET_MIN_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_VARIABLE_MIN_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SNK_VARIABLE_MIN_VOLTAGE_Msk))
|
||||
|
||||
/* Set operating current in mA in SNK VARIABLE */
|
||||
#define USBPD_PDO_SNK_VARIABLE_SET_OP_CURRENT(_MA_) (((PWR_A_10MA((_MA_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_VARIABLE_OP_CURRENT_Pos) \
|
||||
& (USBPD_PDO_SNK_VARIABLE_OP_CURRENT_Msk))
|
||||
|
||||
/* ---------------------------- BATTERY ------------------------ */
|
||||
|
||||
/* Set max voltage in mV in SRC BATTERY PDO */
|
||||
#define USBPD_PDO_SRC_BATTERY_SET_MAX_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_BATTERY_MAX_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SRC_BATTERY_MAX_VOLTAGE_Msk))
|
||||
|
||||
/* Set min voltage in mV in SRC BATTERY PDO */
|
||||
#define USBPD_PDO_SRC_BATTERY_SET_MIN_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_BATTERY_MIN_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SRC_BATTERY_MIN_VOLTAGE_Msk))
|
||||
|
||||
/* Set max power in mW in SRC BATTERY PDO */
|
||||
#define USBPD_PDO_SRC_BATTERY_SET_MAX_POWER(_MA_) (((PWR_W((_MA_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_BATTERY_MAX_POWER_Pos) \
|
||||
& (USBPD_PDO_SRC_BATTERY_MAX_POWER_Msk))
|
||||
|
||||
/* Set max voltage in mV in SNK BATTERY PDO */
|
||||
#define USBPD_PDO_SNK_BATTERY_SET_MAX_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_BATTERY_MAX_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SNK_BATTERY_MAX_VOLTAGE_Msk))
|
||||
|
||||
/* Set min voltage in mV in SNK BATTERY PDO */
|
||||
#define USBPD_PDO_SNK_BATTERY_SET_MIN_VOLTAGE(_MV_) (((PWR_V_50MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_BATTERY_MIN_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SNK_BATTERY_MIN_VOLTAGE_Msk))
|
||||
|
||||
/* Set operating power in mW in SNK BATTERY PDO */
|
||||
#define USBPD_PDO_SNK_BATTERY_SET_OP_POWER(_MA_) (((PWR_W((_MA_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_BATTERY_OP_POWER_Pos) \
|
||||
& (USBPD_PDO_SNK_BATTERY_OP_POWER_Msk))
|
||||
|
||||
/* ---------------------------- APDO ---------------------------- */
|
||||
|
||||
/* Set min voltage in mV in SRC APDO */
|
||||
#define USBPD_PDO_SRC_APDO_SET_MIN_VOLTAGE(_MV_) (((PWR_V_100MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_APDO_MIN_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SRC_APDO_MIN_VOLTAGE_Msk))
|
||||
|
||||
/* Set max voltage in mV in SRC APDO */
|
||||
#define USBPD_PDO_SRC_APDO_SET_MAX_VOLTAGE(_MV_) (((PWR_V_100MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_APDO_MAX_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SRC_APDO_MAX_VOLTAGE_Msk))
|
||||
|
||||
/* Set max current in mA in SRC APDO */
|
||||
#define USBPD_PDO_SRC_APDO_SET_MAX_CURRENT(_MA_) (((PWR_A_50MA((_MA_) / 1000.0)) \
|
||||
<< USBPD_PDO_SRC_APDO_MAX_CURRENT_Pos) \
|
||||
& (USBPD_PDO_SRC_APDO_MAX_CURRENT_Msk))
|
||||
|
||||
/* Set min voltage in mV in SNK APDO */
|
||||
#define USBPD_PDO_SNK_APDO_SET_MIN_VOLTAGE(_MV_) (((PWR_V_100MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_APDO_MIN_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SNK_APDO_MIN_VOLTAGE_Msk))
|
||||
|
||||
/* Set max voltage in mV in SNK APDO */
|
||||
#define USBPD_PDO_SNK_APDO_SET_MAX_VOLTAGE(_MV_) (((PWR_V_100MV((_MV_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_APDO_MAX_VOLTAGE_Pos) \
|
||||
& (USBPD_PDO_SNK_APDO_MAX_VOLTAGE_Msk))
|
||||
|
||||
/* Set max current in mA in SNK APDO */
|
||||
#define USBPD_PDO_SNK_APDO_SET_MAX_CURRENT(_MA_) (((PWR_A_50MA((_MA_) / 1000.0)) \
|
||||
<< USBPD_PDO_SNK_APDO_MAX_CURRENT_Pos) \
|
||||
& (USBPD_PDO_SNK_APDO_MAX_CURRENT_Msk))
|
||||
|
||||
#define USBPD_PORT_IsValid(__Port__) ((__Port__) < (USBPD_PORT_COUNT))
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN variables */
|
||||
|
||||
/* USER CODE END variables */
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup STM32_USBPD_APPLICATION_POWER_IF_Exported_Functions USBPD PWR IF Exported Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Initialize structures and variables related to power board profiles
|
||||
* used by Sink and Source, for all available ports.
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_Init(void);
|
||||
|
||||
/**
|
||||
* @brief Sets the required power profile
|
||||
* @param PortNum Port number
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_SetProfile(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Checks if the power on a specified port is ready
|
||||
* @param PortNum Port number
|
||||
* @param Vsafe Vsafe status based on @ref USBPD_VSAFE_StatusTypeDef
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_SupplyReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe);
|
||||
|
||||
/**
|
||||
* @brief Enable VBUS power on a specified port
|
||||
* @param PortNum Port number
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSEnable(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Disable VBUS power on a specified port
|
||||
* @param PortNum Port number
|
||||
* @retval USBPD status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSDisable(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Checks if the power on a specified port is enabled
|
||||
* @param PortNum Port number
|
||||
* @retval ENABLE or DISABLE
|
||||
*/
|
||||
USBPD_FunctionalState USBPD_PWR_IF_VBUSIsEnabled(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Reads the voltage and the current on a specified port
|
||||
* @param PortNum Port number
|
||||
* @param pVoltage The Voltage in mV
|
||||
* @param pCurrent The Current in mA
|
||||
* @retval ENABLE or DISABLE
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_ReadVA(uint8_t PortNum, uint16_t *pVoltage, uint16_t *pCurrent);
|
||||
|
||||
/**
|
||||
* @brief Enables the VConn on the port.
|
||||
* @param PortNum Port number
|
||||
* @param CC Specifies the CCx to be selected based on @ref CCxPin_TypeDef structure
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_Enable_VConn(uint8_t PortNum, CCxPin_TypeDef CC);
|
||||
|
||||
/**
|
||||
* @brief Disable the VConn on the port.
|
||||
* @param PortNum Port number
|
||||
* @param CC Specifies the CCx to be selected based on @ref CCxPin_TypeDef structure
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_Disable_VConn(uint8_t PortNum, CCxPin_TypeDef CC);
|
||||
|
||||
/**
|
||||
* @brief Allow PDO data reading from PWR_IF storage.
|
||||
* @param PortNum Port number
|
||||
* @param DataId Type of data to be read from PWR_IF
|
||||
* This parameter can be one of the following values:
|
||||
* @arg @ref USBPD_CORE_DATATYPE_SRC_PDO Source PDO reading requested
|
||||
* @arg @ref USBPD_CORE_DATATYPE_SNK_PDO Sink PDO reading requested
|
||||
* @param Ptr Pointer on address where PDO values should be written (u8 pointer)
|
||||
* @param Size Pointer on nb of u32 written by PWR_IF (nb of PDOs)
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_GetPortPDOs(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t *Size);
|
||||
|
||||
/**
|
||||
* @brief Find out SRC PDO pointed out by a position provided in a Request DO (from Sink).
|
||||
* @param PortNum Port number
|
||||
* @param RdoPosition RDO Position in list of provided PDO
|
||||
* @param Pdo Pointer on PDO value pointed out by RDO position (u32 pointer)
|
||||
* @retval Status of search
|
||||
* USBPD_OK : Src PDO found for requested DO position (output Pdo parameter is set)
|
||||
* USBPD_FAIL : Position is not compliant with current Src PDO for this port (no corresponding PDO value)
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_PWR_IF_SearchRequestedPDO(uint8_t PortNum, uint32_t RdoPosition, uint32_t *Pdo);
|
||||
|
||||
/**
|
||||
* @brief Function called in case of critical issue is detected to switch in safety mode.
|
||||
* @param ErrorType Type of error detected by monitoring (based on @ref USBPD_PWR_IF_ERROR)
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_AlarmType(USBPD_PWR_IF_ERROR ErrorType);
|
||||
|
||||
/**
|
||||
* @brief Function called in case of critical issue is detected to switch in safety mode.
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_Alarm(void);
|
||||
|
||||
/**
|
||||
* @brief Function is called to get VBUS power status.
|
||||
* @param PortNum Port number
|
||||
* @param PowerTypeStatus Power type status based on @ref USBPD_VBUSPOWER_STATUS
|
||||
* @retval UBBPD_TRUE or USBPD_FALSE
|
||||
*/
|
||||
uint8_t USBPD_PWR_IF_GetVBUSStatus(uint8_t PortNum, USBPD_VBUSPOWER_STATUS PowerTypeStatus);
|
||||
|
||||
/**
|
||||
* @brief Function is called to set the VBUS threshold when a request has been accepted.
|
||||
* @param PortNum Port number
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_UpdateVbusThreshold(uint8_t PortNum);
|
||||
|
||||
/**
|
||||
* @brief Function is called to reset the VBUS threshold when there is a power reset.
|
||||
* @param PortNum Port number
|
||||
* @retval None
|
||||
*/
|
||||
void USBPD_PWR_IF_ResetVbusThreshold(uint8_t PortNum);
|
||||
|
||||
/* USER CODE BEGIN Exported Functions */
|
||||
|
||||
/* USER CODE END Exported Functions */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_PW_IF_H_ */
|
||||
|
||||
802
USBPD/usbpd_pwr_user.c
Normal file
802
USBPD/usbpd_pwr_user.c
Normal file
@@ -0,0 +1,802 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_pwr_user.c
|
||||
* @author MCD Application Team
|
||||
* @brief USBPD PWR user code
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_pwr_user.h"
|
||||
#include "stm32g4xx_hal.h"
|
||||
#if defined(_TRACE)
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_trace.h"
|
||||
#endif /* _TRACE */
|
||||
|
||||
/* USER CODE BEGIN include */
|
||||
|
||||
/* USER CODE END include */
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup POWER
|
||||
* @{
|
||||
*/
|
||||
/** @defgroup POWER_Private_Typedef Private Typedef
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN POWER_Private_Typedef */
|
||||
|
||||
/* USER CODE END POWER_Private_Typedef */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup POWER_Private_Constants Private Constants
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN POWER_Private_Constants */
|
||||
#define TCPP_EN_GPIO_Port GPIOA
|
||||
#define TCPP_EN_Pin GPIO_PIN_9
|
||||
/* USER CODE END POWER_Private_Constants */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup POWER_Private_Macros Private Macros
|
||||
* @{
|
||||
*/
|
||||
#if defined(_TRACE)
|
||||
#define PWR_DEBUG_TRACE(_PORT_, __MESSAGE__) USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (_PORT_), 0u, (uint8_t*)(__MESSAGE__), sizeof(__MESSAGE__) - 1u)
|
||||
#else
|
||||
#define PWR_DEBUG_TRACE(_PORT_, __MESSAGE__)
|
||||
#endif /* _TRACE */
|
||||
/* USER CODE BEGIN POWER_Private_Macros */
|
||||
|
||||
/* USER CODE END POWER_Private_Macros */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup POWER_Private_Variables Private Variables
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN POWER_Private_Variables */
|
||||
|
||||
/* USER CODE END POWER_Private_Variables */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup POWER_Private_Functions Private Functions
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN POWER_Private_Prototypes */
|
||||
|
||||
/* USER CODE END POWER_Private_Prototypes */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup POWER_Exported_Variables Exported Variables
|
||||
* @{
|
||||
*/
|
||||
/* USER CODE BEGIN POWER_Exported_Variables */
|
||||
|
||||
/* USER CODE END POWER_Exported_Variables */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup POWER_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Global initialization of PWR resource used by USB-PD
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_Init(uint32_t Instance)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_Init */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_Init */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Global de-initialization of PWR resource used by USB-PD
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_Deinit(uint32_t Instance)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_Deinit */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_Deinit");
|
||||
}
|
||||
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_Deinit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assign Power role for current Port (Source or Sink)
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param Role Type-C port role
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref POWER_ROLE_SOURCE
|
||||
* @arg @ref POWER_ROLE_SINK
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_SetRole(uint32_t Instance, USBPD_PWR_PowerRoleTypeDef Role)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_SetRole */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_SetRole");
|
||||
}
|
||||
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_SetRole */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set operating mode of Port regarding power saving constraints
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param PwrMode Type-C port power saving mode
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_MODE_OFF
|
||||
* @arg @ref USBPD_PWR_MODE_HIBERNATE
|
||||
* @arg @ref USBPD_PWR_MODE_LOWPOWER
|
||||
* @arg @ref USBPD_PWR_MODE_NORMAL
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_SetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef PwrMode)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_SetPowerMode */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_SetPowerMode");
|
||||
}
|
||||
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_SetPowerMode */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get operating mode of Port regarding power saving constraints
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param PwrMode Pointer on current Type-C port power saving mode value
|
||||
* Following values are available :
|
||||
* @arg @ref USBPD_PWR_MODE_OFF
|
||||
* @arg @ref USBPD_PWR_MODE_HIBERNATE
|
||||
* @arg @ref USBPD_PWR_MODE_LOWPOWER
|
||||
* @arg @ref USBPD_PWR_MODE_NORMAL
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_GetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef *PwrMode)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_GetPowerMode */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_GetPowerMode");
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_GetPowerMode */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the hardware resources used by the Type-C power delivery (PD)
|
||||
* controller.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSInit(uint32_t Instance)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSInit */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSInit");
|
||||
}
|
||||
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSInit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release the hardware resources used by the Type-C power delivery (PD)
|
||||
* controller.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSDeInit(uint32_t Instance)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSDeInit */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSDeInit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable power supply over VBUS.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSOn(uint32_t Instance)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSOn */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin(TCPP_EN_GPIO_Port, TCPP_EN_Pin, GPIO_PIN_SET);
|
||||
return BSP_ERROR_NONE;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSOn */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable power supply over VBUS.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSOff(uint32_t Instance)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSOff */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin(TCPP_EN_GPIO_Port, TCPP_EN_Pin, GPIO_PIN_RESET);
|
||||
return BSP_ERROR_NONE;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSOff */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a fixed/variable PDO and manage the power control.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param VbusTargetInmv the vbus Target (in mV)
|
||||
* @param OperatingCurrent the Operating Current (in mA)
|
||||
* @param MaxOperatingCurrent the Max Operating Current (in mA)
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Fixed(uint32_t Instance,
|
||||
uint32_t VbusTargetInmv,
|
||||
uint32_t OperatingCurrent,
|
||||
uint32_t MaxOperatingCurrent)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Fixed */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Fixed */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a fixed/variable PDO and manage the power control.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param VbusTargetMinInmv the vbus Target min (in mV)
|
||||
* @param VbusTargetMaxInmv the vbus Target max (in mV)
|
||||
* @param OperatingCurrent the Operating Current (in mA)
|
||||
* @param MaxOperatingCurrent the Max Operating Current (in mA)
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Variable(uint32_t Instance,
|
||||
uint32_t VbusTargetMinInmv,
|
||||
uint32_t VbusTargetMaxInmv,
|
||||
uint32_t OperatingCurrent,
|
||||
uint32_t MaxOperatingCurrent)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Variable */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Variable */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a Battery PDO and manage the power control.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param VbusTargetMin the vbus Target min (in mV)
|
||||
* @param VbusTargetMax the vbus Target max (in mV)
|
||||
* @param OperatingPower the Operating Power (in mW)
|
||||
* @param MaxOperatingPower the Max Operating Power (in mW)
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Battery(uint32_t Instance,
|
||||
uint32_t VbusTargetMin,
|
||||
uint32_t VbusTargetMax,
|
||||
uint32_t OperatingPower,
|
||||
uint32_t MaxOperatingPower)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Battery */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Battery */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a APDO and manage the power control.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param VbusTargetInmv the vbus Target (in mV)
|
||||
* @param OperatingCurrent the Operating current (in mA)
|
||||
* @param Delta Delta between with previous APDO (in mV), 0 means APDO start
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_APDO(uint32_t Instance,
|
||||
uint32_t VbusTargetInmv,
|
||||
uint32_t OperatingCurrent,
|
||||
int32_t Delta)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_APDO */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_APDO */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get actual voltage level measured on the VBUS line.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param pVoltage Pointer on measured voltage level (in mV)
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSGetVoltage(uint32_t Instance, uint32_t *pVoltage)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSGetVoltage */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret;
|
||||
uint32_t val = 0U;
|
||||
|
||||
if ((Instance >= USBPD_PWR_INSTANCES_NBR) || (NULL == pVoltage))
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSGetVoltage");
|
||||
}
|
||||
*pVoltage = val;
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSGetVoltage */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get actual current level measured on the VBUS line.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param pCurrent Pointer on measured current level (in mA)
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSGetCurrent(uint32_t Instance, int32_t *pCurrent)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSGetCurrent */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret;
|
||||
|
||||
if ((Instance >= USBPD_PWR_INSTANCES_NBR) || (NULL == pCurrent))
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pCurrent = 0;
|
||||
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSGetCurrent */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize VCONN sourcing.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param CCPinId Type-C CC pin identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC1
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC2
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VCONNInit(uint32_t Instance,
|
||||
uint32_t CCPinId)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VCONNInit */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VCONNInit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Un-Initialize VCONN sourcing.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param CCPinId Type-C CC pin identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC1
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC2
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VCONNDeInit(uint32_t Instance,
|
||||
uint32_t CCPinId)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VCONNDeInit */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VCONNDeInit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable VCONN sourcing.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param CCPinId Type-C CC pin identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC1
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC2
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VCONNOn(uint32_t Instance,
|
||||
uint32_t CCPinId)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VCONNOn */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VCONNOn */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable VCONN sourcing.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param CCPinId CC pin identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC1
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC2
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VCONNOff(uint32_t Instance,
|
||||
uint32_t CCPinId)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VCONNOff */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VCONNOff */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get actual VCONN status.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param CCPinId Type-C CC pin identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC1
|
||||
* @arg @ref USBPD_PWR_TYPE_C_CC2
|
||||
* @param pState VCONN status (1: On, 0: Off)
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VCONNIsOn(uint32_t Instance,
|
||||
uint32_t CCPinId, uint8_t *pState)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VCONNIsOn */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
*pState = 0u;
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VCONNIsOn */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the VBUS disconnection voltage threshold.
|
||||
* @note Callback function registered through BSP_USBPD_PWR_RegisterVBUSDetectCallback
|
||||
* function call is invoked when VBUS falls below programmed threshold.
|
||||
* @note By default VBUS disconnection threshold is set to 3.3V
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param VoltageThreshold VBUS disconnection voltage threshold (in mV)
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_SetVBUSDisconnectionThreshold(uint32_t Instance,
|
||||
uint32_t VoltageThreshold)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_SetVBUSDisconnectionThreshold */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_SetVBUSDisconnectionThreshold */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register USB Type-C Current callback function.
|
||||
* @note Callback function invoked when VBUS rises above 4V (VBUS present) or
|
||||
* when VBUS falls below programmed threshold (VBUS absent).
|
||||
* @note Callback function is un-registered when callback function pointer
|
||||
* argument is NULL.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param pfnVBUSDetectCallback callback function pointer
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_RegisterVBUSDetectCallback(uint32_t Instance,
|
||||
USBPD_PWR_VBUSDetectCallbackFunc *pfnVBUSDetectCallback)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_RegisterVBUSDetectCallback */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_RegisterVBUSDetectCallback */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get actual VBUS status.
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param pState VBUS status (1: On, 0: Off)
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VBUSIsOn(uint32_t Instance, uint8_t *pState)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VBUSIsOn */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret;
|
||||
uint8_t state = 0U;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSIsOn");
|
||||
}
|
||||
*pState = state;
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VBUSIsOn */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set state of VCC (specific functions)
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @param State VCC state
|
||||
* @retval BSP status
|
||||
*/
|
||||
__weak int32_t BSP_USBPD_PWR_VCCSetState(uint32_t Instance, uint32_t State)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_VCCSetState */
|
||||
/* Check if instance is valid */
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if (Instance >= USBPD_PWR_INSTANCES_NBR)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VCCSetState");
|
||||
}
|
||||
return ret;
|
||||
/* USER CODE END BSP_USBPD_PWR_VCCSetState */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBPD PWR callback used to notify a asynchronous PWR event.
|
||||
* (This callback caould be called fromp an IT routine, associated to
|
||||
* any PWR related event detection mechanism)
|
||||
* @param Instance Type-C port identifier
|
||||
* This parameter can be take one of the following values:
|
||||
* @arg @ref USBPD_PWR_TYPE_C_PORT_1
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_USBPD_PWR_EventCallback(uint32_t Instance)
|
||||
{
|
||||
/* USER CODE BEGIN BSP_USBPD_PWR_EventCallback */
|
||||
PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_EventCallback");
|
||||
/* USER CODE END BSP_USBPD_PWR_EventCallback */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup POWER_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN POWER_Private_Functions */
|
||||
|
||||
/* USER CODE END POWER_Private_Functions */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
269
USBPD/usbpd_pwr_user.h
Normal file
269
USBPD/usbpd_pwr_user.h
Normal file
@@ -0,0 +1,269 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_pwr_user.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for usbpd_pwr_user.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef USBPD_PWR_USER_H_
|
||||
#define USBPD_PWR_USER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup POWER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup POWER_Exported_Types Exported Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Power role
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
POWER_ROLE_SOURCE = 0,
|
||||
POWER_ROLE_SINK,
|
||||
POWER_ROLE_DUAL
|
||||
} USBPD_PWR_PowerRoleTypeDef;
|
||||
|
||||
/**
|
||||
* @brief Voltage control mode
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
DCDC_CTRL_MODE_UNKNOWN = 0,
|
||||
DCDC_CTRL_MODE_GPIO,
|
||||
DCDC_CTRL_MODE_PWM,
|
||||
} USBPD_PWR_DCDCCtrlModeTypeDef;
|
||||
|
||||
/**
|
||||
* @brief Low Power Mode of TypeC ports
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
USBPD_PWR_MODE_OFF = 0,
|
||||
USBPD_PWR_MODE_HIBERNATE,
|
||||
USBPD_PWR_MODE_LOWPOWER,
|
||||
USBPD_PWR_MODE_NORMAL
|
||||
} USBPD_PWR_PowerModeTypeDef;
|
||||
|
||||
/**
|
||||
* @brief VBUS connection status
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
VBUS_CONNECTED = 0,
|
||||
VBUS_NOT_CONNECTED
|
||||
} USBPD_PWR_VBUSConnectionStatusTypeDef;
|
||||
|
||||
/**
|
||||
* @brief VBUS Detection Callback
|
||||
*/
|
||||
typedef void USBPD_PWR_VBUSDetectCallbackFunc(uint32_t Instance,
|
||||
USBPD_PWR_VBUSConnectionStatusTypeDef VBUSConnectionStatus);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup POWER_Exported_Constants Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/* Common Error codes */
|
||||
#define BSP_ERROR_NONE 0
|
||||
#define BSP_ERROR_NO_INIT -1
|
||||
#define BSP_ERROR_WRONG_PARAM -2
|
||||
#define BSP_ERROR_BUSY -3
|
||||
#define BSP_ERROR_PERIPH_FAILURE -4
|
||||
#define BSP_ERROR_COMPONENT_FAILURE -5
|
||||
#define BSP_ERROR_UNKNOWN_FAILURE -6
|
||||
#define BSP_ERROR_UNKNOWN_COMPONENT -7
|
||||
#define BSP_ERROR_BUS_FAILURE -8
|
||||
#define BSP_ERROR_CLOCK_FAILURE -9
|
||||
#define BSP_ERROR_MSP_FAILURE -10
|
||||
#define BSP_ERROR_FEATURE_NOT_SUPPORTED -11
|
||||
|
||||
/**
|
||||
* @brief Number of TypeC ports
|
||||
*/
|
||||
#define USBPD_PWR_INSTANCES_NBR (1U)
|
||||
|
||||
/**
|
||||
* @brief Type-C port identifier
|
||||
*/
|
||||
#define USBPD_PWR_TYPE_C_PORT_1 (0U)
|
||||
|
||||
/**
|
||||
* @brief CC pin identifier
|
||||
*/
|
||||
#define USBPD_PWR_TYPE_C_CC1 (1U)
|
||||
#define USBPD_PWR_TYPE_C_CC2 (2U)
|
||||
|
||||
/**
|
||||
* @brief VBUS disconnection threshold values (in mV)
|
||||
*/
|
||||
#define USBPD_PWR_HIGH_VBUS_THRESHOLD (2800U)
|
||||
#define USBPD_PWR_LOW_VBUS_THRESHOLD (750U)
|
||||
#define USBPD_PWR_VBUS_THRESHOLD_5V (2150U)
|
||||
#define USBPD_PWR_VBUS_THRESHOLD_9V (7000U)
|
||||
#define USBPD_PWR_VBUS_THRESHOLD_15V (12500U)
|
||||
#define USBPD_PWR_VBUS_THRESHOLD_20V (17000U)
|
||||
#define USBPD_PWR_VBUS_THRESHOLD_APDO (2150U)
|
||||
|
||||
/**
|
||||
* @brief VBUS discharge parameters
|
||||
*/
|
||||
#define USBPD_PWR_DISCHARGE_MARGIN (500U)
|
||||
#define USBPD_PWR_DISCHARGE_TIME (6U)
|
||||
|
||||
/**
|
||||
* @brief Calibration settings
|
||||
*/
|
||||
#define USBPD_PWR_DCDC_PRECISION (40U) /* DCDC output precision set to 40mV (Noise)*/
|
||||
#define USBPD_PWR_CALIBRATION_ENABLED (1U)
|
||||
#define USBPD_PWR_CALIBRATION_DISABLED (0U)
|
||||
|
||||
/**
|
||||
* @brief Standard VBUS voltage levels
|
||||
*/
|
||||
#define USBPD_PWR_VBUS_5V 5000U
|
||||
#define USBPD_PWR_VBUS_9V 9000U
|
||||
#define USBPD_PWR_VBUS_15V 15000U
|
||||
|
||||
/**
|
||||
* @brief power timeout
|
||||
*/
|
||||
#define USBPD_PWR_TIMEOUT_PDO 250U /* Timeout for PDO to PDO or PDO to APDO at 250ms*/
|
||||
#define USBPD_PWR_TIMEOUT_APDO 25U /* Timeout for APDO to APDO at 25ms*/
|
||||
|
||||
/**
|
||||
* @brief Invalid value set during issue with voltage setting
|
||||
*/
|
||||
#define USBPD_PWR_INVALID_VALUE 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup POWER_Exported_Functions Exported Functions
|
||||
* @{
|
||||
*/
|
||||
/* Common functions */
|
||||
int32_t BSP_USBPD_PWR_Init(uint32_t Instance);
|
||||
|
||||
int32_t BSP_USBPD_PWR_Deinit(uint32_t Instance);
|
||||
|
||||
int32_t BSP_USBPD_PWR_SetRole(uint32_t Instance, USBPD_PWR_PowerRoleTypeDef Role);
|
||||
|
||||
int32_t BSP_USBPD_PWR_SetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef PwrMode);
|
||||
|
||||
int32_t BSP_USBPD_PWR_GetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef *PwrMode);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSInit(uint32_t Instance);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSDeInit(uint32_t Instance);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSOn(uint32_t Instance);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSOff(uint32_t Instance);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSSetVoltage_Fixed(uint32_t Instance,
|
||||
uint32_t VbusTargetInmv,
|
||||
uint32_t OperatingCurrent,
|
||||
uint32_t MaxOperatingCurrent);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSSetVoltage_Variable(uint32_t Instance,
|
||||
uint32_t VbusTargetMaxInmv,
|
||||
uint32_t VbusTargetMinInmv,
|
||||
uint32_t OperatingCurrent,
|
||||
uint32_t MaxOperatingCurrent);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSSetVoltage_Battery(uint32_t Instance,
|
||||
uint32_t VbusTargetMin,
|
||||
uint32_t VbusTargetMax,
|
||||
uint32_t OperatingPower,
|
||||
uint32_t MaxOperatingPower);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSSetVoltage_APDO(uint32_t Instance,
|
||||
uint32_t VbusTargetInmv,
|
||||
uint32_t OperatingCurrent,
|
||||
int32_t Delta);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSGetVoltage(uint32_t Instance, uint32_t *pVoltage);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSGetCurrent(uint32_t Instance, int32_t *pCurrent);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VCONNInit(uint32_t Instance,
|
||||
uint32_t CCPinId);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VCONNDeInit(uint32_t Instance,
|
||||
uint32_t CCPinId);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VCONNOn(uint32_t Instance,
|
||||
uint32_t CCPinId);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VCONNOff(uint32_t Instance,
|
||||
uint32_t CCPinId);
|
||||
|
||||
int32_t BSP_USBPD_PWR_SetVBUSDisconnectionThreshold(uint32_t Instance,
|
||||
uint32_t VoltageThreshold);
|
||||
|
||||
int32_t BSP_USBPD_PWR_RegisterVBUSDetectCallback(uint32_t Instance,
|
||||
USBPD_PWR_VBUSDetectCallbackFunc *pfnVBUSDetectCallback);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VBUSIsOn(uint32_t Instance, uint8_t *pState);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VCONNIsOn(uint32_t Instance,
|
||||
uint32_t CCPinId, uint8_t *pState);
|
||||
|
||||
int32_t BSP_USBPD_PWR_VCCSetState(uint32_t Instance, uint32_t State);
|
||||
|
||||
void BSP_USBPD_PWR_EventCallback(uint32_t Instance);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBPD_PWR_USER_H_ */
|
||||
|
||||
488
USBPD/usbpd_vdm_user.c
Normal file
488
USBPD/usbpd_vdm_user.c
Normal file
@@ -0,0 +1,488 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_vdm_user.c
|
||||
* @author MCD Application Team
|
||||
* @brief USBPD provider demo file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbpd_core.h"
|
||||
#include "usbpd_dpm_conf.h"
|
||||
#include "usbpd_vdm_user.h"
|
||||
#include "usbpd_dpm_user.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_VDM_USER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Private_define */
|
||||
|
||||
/* USER CODE END Private_define */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Private_typedef */
|
||||
|
||||
/* USER CODE END Private_typedef */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Private_macro */
|
||||
|
||||
/* USER CODE END Private_macro */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static USBPD_StatusTypeDef USBPD_VDM_DiscoverIdentity(uint8_t PortNum, USBPD_DiscoveryIdentity_TypeDef *pIdentity);
|
||||
static USBPD_StatusTypeDef USBPD_VDM_DiscoverSVIDs(uint8_t PortNum, uint16_t **p_SVID_Info, uint8_t *nb);
|
||||
static USBPD_StatusTypeDef USBPD_VDM_DiscoverModes(uint8_t PortNum, uint16_t SVID, uint32_t **p_ModeInfo, uint8_t *nbMode);
|
||||
static USBPD_StatusTypeDef USBPD_VDM_ModeEnter(uint8_t PortNum, uint16_t SVID, uint32_t ModeIndex);
|
||||
static USBPD_StatusTypeDef USBPD_VDM_ModeExit(uint8_t PortNum, uint16_t SVID, uint32_t ModeIndex);
|
||||
static void USBPD_VDM_SendAttention(uint8_t PortNum, uint8_t *NbData, uint32_t *VDO);
|
||||
static void USBPD_VDM_ReceiveAttention(uint8_t PortNum, uint8_t NbData, uint32_t VDO);
|
||||
static USBPD_StatusTypeDef USBPD_VDM_ReceiveSpecific(uint8_t PortNum, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *NbData, uint32_t *VDO);
|
||||
static void USBPD_VDM_InformIdentity(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_DiscoveryIdentity_TypeDef *pIdentity);
|
||||
static void USBPD_VDM_InformSVID(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_SVIDInfo_TypeDef *pListSVID);
|
||||
static void USBPD_VDM_InformMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_ModeInfo_TypeDef *pModesInfo);
|
||||
static void USBPD_VDM_InformModeEnter(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, uint16_t SVID, uint32_t ModeIndex);
|
||||
static void USBPD_VDM_InformModeExit(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, uint16_t SVID, uint32_t ModeIndex);
|
||||
static void USBPD_VDM_InformSpecific(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *NbData, uint32_t *VDO);
|
||||
static void USBPD_VDM_SendSpecific(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *NbData, uint32_t *VDO);
|
||||
static void USBPD_VDM_SendUVDM(uint8_t PortNum, USBPD_UVDMHeader_TypeDef *pUVDM_Header, uint8_t *pNbData, uint32_t *pVDO);
|
||||
static USBPD_StatusTypeDef USBPD_VDM_ReceiveUVDM(uint8_t PortNum, USBPD_UVDMHeader_TypeDef UVDM_Header, uint8_t *pNbData, uint32_t *pVDO);
|
||||
|
||||
/* USER CODE BEGIN Private_prototypes */
|
||||
|
||||
/* USER CODE END Private_prototypes */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
USBPD_VDM_SettingsTypeDef DPM_VDM_Settings[USBPD_PORT_COUNT] =
|
||||
{
|
||||
{
|
||||
.VDM_XID_SOP = USBPD_XID, /*!< A decimal number assigned by USB-IF before certification */
|
||||
.VDM_USB_VID_SOP = USBPD_VID, /*!< A decimal number assigned by USB-IF before certification */
|
||||
.VDM_PID_SOP = USBPD_PID, /*!< A unique number assigned by the Vendor ID holder identifying the product. */
|
||||
.VDM_ModalOperation = MODAL_OPERATION_NONSUPP, /*!< Product support Modes based on @ref USBPD_ModalOp_TypeDef */
|
||||
.VDM_bcdDevice_SOP = 0xAAAA, /*!< A unique number assigned by the Vendor ID holder containing identity information relevant to the release version of the product. */
|
||||
.VDM_USBHostSupport = USB_NOTCAPABLE, /*!< Indicates whether the UUT is capable of enumerating USB Host */
|
||||
.VDM_USBDeviceSupport = USB_NOTCAPABLE, /*!< Indicates whether the UUT is capable of enumerating USB Devices */
|
||||
.VDM_ProductTypeUFPorCP = PRODUCT_TYPE_UNDEFINED, /*!< Product type UFP or CablePlug of the UUT based on @ref USBPD_ProductType_TypeDef */
|
||||
}
|
||||
};
|
||||
|
||||
/* USER CODE BEGIN Private_variables */
|
||||
const USBPD_VDM_Callbacks vdmCallbacks =
|
||||
{
|
||||
USBPD_VDM_DiscoverIdentity,
|
||||
USBPD_VDM_DiscoverSVIDs,
|
||||
USBPD_VDM_DiscoverModes,
|
||||
USBPD_VDM_ModeEnter,
|
||||
USBPD_VDM_ModeExit,
|
||||
USBPD_VDM_InformIdentity,
|
||||
USBPD_VDM_InformSVID,
|
||||
USBPD_VDM_InformMode,
|
||||
USBPD_VDM_InformModeEnter,
|
||||
USBPD_VDM_InformModeExit,
|
||||
USBPD_VDM_SendAttention,
|
||||
USBPD_VDM_ReceiveAttention,
|
||||
USBPD_VDM_SendSpecific,
|
||||
USBPD_VDM_ReceiveSpecific,
|
||||
USBPD_VDM_InformSpecific,
|
||||
USBPD_VDM_SendUVDM,
|
||||
USBPD_VDM_ReceiveUVDM,
|
||||
};
|
||||
/* USER CODE END Private_variables */
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief VDM Discovery identity callback
|
||||
* @note Function is called to get Discovery identity information linked to the device and answer
|
||||
* to SVDM Discovery identity init message sent by port partner
|
||||
* @param PortNum current port number
|
||||
* @param pIdentity Pointer on @ref USBPD_DiscoveryIdentity_TypeDef structure
|
||||
* @retval USBPD status: @ref USBPD_ACK or @ref USBPD_BUSY
|
||||
*/
|
||||
static USBPD_StatusTypeDef USBPD_VDM_DiscoverIdentity(uint8_t PortNum, USBPD_DiscoveryIdentity_TypeDef *pIdentity)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_DiscoverIdentity */
|
||||
return USBPD_NAK;
|
||||
/* USER CODE END USBPD_VDM_DiscoverIdentity */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Discover SVID callback
|
||||
* @note Function is called to retrieve SVID supported by device and answer
|
||||
* to SVDM Discovery SVID init message sent by port partner
|
||||
* @param PortNum current port number
|
||||
* @param p_SVID_Info Pointer on @ref USBPD_SVIDInfo_TypeDef structure
|
||||
* @param pNbSVID Pointer on number of SVID
|
||||
* @retval USBPD status @ref USBPD_BUSY or @ref USBPD_ACK or @ref USBPD_NAK
|
||||
*/
|
||||
static USBPD_StatusTypeDef USBPD_VDM_DiscoverSVIDs(uint8_t PortNum, uint16_t **p_SVID_Info, uint8_t *pNbSVID)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_DiscoverSVIDs */
|
||||
return USBPD_NAK;
|
||||
/* USER CODE END USBPD_VDM_DiscoverSVIDs */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Discover Mode callback (report all the modes supported by SVID)
|
||||
* @note Function is called to report all the modes supported by selected SVID and answer
|
||||
* to SVDM Discovery Mode init message sent by port partner
|
||||
* @param PortNum current port number
|
||||
* @param SVID SVID value
|
||||
* @param p_ModeTab Pointer on the mode value
|
||||
* @param NumberOfMode Number of mode available
|
||||
* @retval USBPD status
|
||||
*/
|
||||
static USBPD_StatusTypeDef USBPD_VDM_DiscoverModes(uint8_t PortNum, uint16_t SVID, uint32_t **p_ModeTab, uint8_t *NumberOfMode)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_DiscoverModes */
|
||||
return USBPD_NAK;
|
||||
/* USER CODE END USBPD_VDM_DiscoverModes */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Mode enter callback
|
||||
* @note Function is called to check if device can enter in the mode received for the selected SVID in the
|
||||
* SVDM enter mode init message sent by port partner
|
||||
* @param PortNum current port number
|
||||
* @param SVID SVID value
|
||||
* @param ModeIndex Index of the mode to be entered
|
||||
* @retval USBPD status @ref USBPD_ACK/@ref USBPD_NAK
|
||||
*/
|
||||
static USBPD_StatusTypeDef USBPD_VDM_ModeEnter(uint8_t PortNum, uint16_t SVID, uint32_t ModeIndex)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_ModeEnter */
|
||||
return USBPD_NAK;
|
||||
/* USER CODE END USBPD_VDM_ModeEnter */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Mode exit callback
|
||||
* @note Function is called to check if device can exit from the mode received for the selected SVID in the
|
||||
* SVDM exit mode init message sent by port partner
|
||||
* @param PortNum current port number
|
||||
* @param SVID SVID value
|
||||
* @param ModeIndex Index of the mode to be exited
|
||||
* @retval USBPD status @ref USBPD_ACK/@ref USBPD_NAK
|
||||
*/
|
||||
static USBPD_StatusTypeDef USBPD_VDM_ModeExit(uint8_t PortNum, uint16_t SVID, uint32_t ModeIndex)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_ModeExit */
|
||||
return USBPD_NAK;
|
||||
/* USER CODE END USBPD_VDM_ModeExit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send VDM Attention message callback
|
||||
* @note Function is called when device wants to send a SVDM attention message to port partner
|
||||
* (for instance DP status can be filled through this function)
|
||||
* @param PortNum current port number
|
||||
* @param pNbData Pointer of number of VDO to send
|
||||
* @param pVDO Pointer of VDO to send
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_SendAttention(uint8_t PortNum, uint8_t *pNbData, uint32_t *pVDO)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_SendAttention */
|
||||
|
||||
/* USER CODE END USBPD_VDM_SendAttention */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive VDM Attention callback
|
||||
* @note Function is called when a SVDM attention init message has been received from port partner
|
||||
* (for instance, save DP status data through this function)
|
||||
* @param PortNum current port number
|
||||
* @param NbData Number of received VDO
|
||||
* @param VDO Received VDO
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_ReceiveAttention(uint8_t PortNum, uint8_t NbData, uint32_t VDO)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_ReceiveAttention */
|
||||
|
||||
/* USER CODE END USBPD_VDM_ReceiveAttention */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Receive Specific message callback
|
||||
* @note Function is called to answer to a SVDM specific init message received by port partner.
|
||||
* (for instance, retrieve DP status or DP configure data through this function)
|
||||
* @param PortNum Current port number
|
||||
* @param VDMCommand VDM command based on @ref USBPD_VDM_Command_Typedef
|
||||
* @param pNbData Pointer of number of received VDO and used for the answer
|
||||
* @param pVDO Pointer of received VDO and use for the answer
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
static USBPD_StatusTypeDef USBPD_VDM_ReceiveSpecific(uint8_t PortNum, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *pNbData, uint32_t *pVDO)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_ReceiveSpecific */
|
||||
return USBPD_NAK;
|
||||
/* USER CODE END USBPD_VDM_ReceiveSpecific */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inform identity callback
|
||||
* @note Function is called to save Identity information received in Discovery identity from port partner
|
||||
(answer to SVDM discovery identity sent by device)
|
||||
* @param PortNum current port number
|
||||
* @param SOPType SOP type
|
||||
* @param CommandStatus Command status based on @ref USBPD_VDM_CommandType_Typedef
|
||||
* @param pIdentity Pointer on the discovery identity information based on @ref USBPD_DiscoveryIdentity_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_InformIdentity(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_DiscoveryIdentity_TypeDef *pIdentity)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_InformIdentity */
|
||||
switch(CommandStatus)
|
||||
{
|
||||
case SVDM_RESPONDER_ACK :
|
||||
break;
|
||||
case SVDM_RESPONDER_NAK :
|
||||
break;
|
||||
case SVDM_RESPONDER_BUSY :
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
/* USER CODE END USBPD_VDM_InformIdentity */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inform SVID callback
|
||||
* @note Function is called to save list of SVID received in Discovery SVID from port partner
|
||||
(answer to SVDM discovery SVID sent by device)
|
||||
* @param PortNum current port number
|
||||
* @param SOPType SOP type
|
||||
* @param CommandStatus Command status based on @ref USBPD_VDM_CommandType_Typedef
|
||||
* @param pListSVID Pointer of list of SVID based on @ref USBPD_SVIDInfo_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_InformSVID(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_SVIDInfo_TypeDef *pListSVID)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_InformSVID */
|
||||
switch(CommandStatus)
|
||||
{
|
||||
case SVDM_RESPONDER_ACK :
|
||||
break;
|
||||
case SVDM_RESPONDER_NAK :
|
||||
break;
|
||||
case SVDM_RESPONDER_BUSY :
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
/* USER CODE END USBPD_VDM_InformSVID */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inform Mode callback ( received in Discovery Modes ACK)
|
||||
* @note Function is called to save list of modes linked to SVID received in Discovery mode from port partner
|
||||
(answer to SVDM discovery mode sent by device)
|
||||
* @param PortNum current port number
|
||||
* @param SOPType SOP type
|
||||
* @param CommandStatus Command status based on @ref USBPD_VDM_CommandType_Typedef
|
||||
* @param pModesInfo Pointer of Modes info based on @ref USBPD_ModeInfo_TypeDef
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_InformMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_ModeInfo_TypeDef *pModesInfo)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_InformMode */
|
||||
switch(CommandStatus)
|
||||
{
|
||||
case SVDM_RESPONDER_ACK :
|
||||
break;
|
||||
case SVDM_RESPONDER_NAK :
|
||||
break;
|
||||
case SVDM_RESPONDER_BUSY :
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
/* USER CODE END USBPD_VDM_InformMode */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inform Mode enter callback
|
||||
* @note Function is called to inform if port partner accepted or not to enter in the mode
|
||||
* specified in the SVDM enter mode sent by the device
|
||||
* @param PortNum current port number
|
||||
* @param SOPType SOP type
|
||||
* @param CommandStatus Command status based on @ref USBPD_VDM_CommandType_Typedef
|
||||
* @param SVID SVID ID
|
||||
* @param ModeIndex Index of the mode to be entered
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_InformModeEnter(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, uint16_t SVID, uint32_t ModeIndex)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_InformModeEnter */
|
||||
switch(CommandStatus)
|
||||
{
|
||||
case SVDM_RESPONDER_ACK :
|
||||
break;
|
||||
case SVDM_RESPONDER_NAK :
|
||||
break;
|
||||
case SVDM_RESPONDER_BUSY :
|
||||
/* retry in 50ms */
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
/* USER CODE END USBPD_VDM_InformModeEnter */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inform Exit enter callback
|
||||
* @param PortNum current port number
|
||||
* @param SVID SVID ID
|
||||
* @param ModeIndex Index of the mode to be entered
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_InformModeExit(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, uint16_t SVID, uint32_t ModeIndex)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_InformModeExit */
|
||||
switch(CommandStatus)
|
||||
{
|
||||
case SVDM_RESPONDER_ACK :
|
||||
break;
|
||||
case SVDM_RESPONDER_NAK :
|
||||
break;
|
||||
case SVDM_RESPONDER_BUSY :
|
||||
/* retry in 50ms */
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
/* USER CODE END USBPD_VDM_InformModeExit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Send Specific message callback
|
||||
* @note Function is called when device wants to send a SVDM specific init message to port partner
|
||||
* (for instance DP status or DP configure can be filled through this function)
|
||||
* @param PortNum current port number
|
||||
* @param SOPType SOP type
|
||||
* @param VDMCommand VDM command based on @ref USBPD_VDM_Command_Typedef
|
||||
* @param pNbData Pointer of number of VDO to send
|
||||
* @param pVDO Pointer of VDO to send
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_SendSpecific(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *pNbData, uint32_t *pVDO)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_SendSpecific */
|
||||
|
||||
/* USER CODE END USBPD_VDM_SendSpecific */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Specific message callback to inform user of reception of VDM specific message
|
||||
* @note Function is called when answer from SVDM specific init message has been received by the device
|
||||
* (for instance, save DP status and DP configure data through this function)
|
||||
* @param PortNum current port number
|
||||
* @param SOPType SOP type
|
||||
* @param VDMCommand VDM command based on @ref USBPD_VDM_Command_Typedef
|
||||
* @param pNbData Pointer of number of received VDO
|
||||
* @param pVDO Pointer of received VDO
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_InformSpecific(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *pNbData, uint32_t *pVDO)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_InformSpecific */
|
||||
|
||||
/* USER CODE END USBPD_VDM_InformSpecific */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Send Unstructured message callback
|
||||
* @note Aim of this function is to fill the UVDM message which contains 1 VDM Header + 6 VDO
|
||||
* This callback will be called when user requests to send a UVDM message thanks
|
||||
* to USBPD_DPM_RequestUVDMMessage function
|
||||
* @param PortNum current port number
|
||||
* @param pUVDM_Header Pointer on UVDM header based on @ref USBPD_UVDMHeader_TypeDef
|
||||
* @param pNbData Pointer of number of VDO to send (max size must be equal to 6)
|
||||
* @param pVDO Pointer of VDO to send (up to 6 x uint32_t)
|
||||
* @retval None
|
||||
*/
|
||||
static void USBPD_VDM_SendUVDM(uint8_t PortNum, USBPD_UVDMHeader_TypeDef *pUVDM_Header, uint8_t *pNbData, uint32_t *pVDO)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_SendUVDM */
|
||||
|
||||
/* USER CODE END USBPD_VDM_SendUVDM */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unstructured VDM message callback to inform user of reception of UVDM message
|
||||
* @param PortNum current port number
|
||||
* @param UVDM_Header UVDM header based on @ref USBPD_UVDMHeader_TypeDef
|
||||
* @param pNbData Pointer of number of received VDO
|
||||
* @param pVDO Pointer of received VDO
|
||||
* @retval USBPD Status
|
||||
*/
|
||||
static USBPD_StatusTypeDef USBPD_VDM_ReceiveUVDM(uint8_t PortNum, USBPD_UVDMHeader_TypeDef UVDM_Header, uint8_t *pNbData, uint32_t *pVDO)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_ReceiveUVDM */
|
||||
return USBPD_ERROR;
|
||||
/* USER CODE END USBPD_VDM_ReceiveUVDM */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Private_functions */
|
||||
|
||||
/* USER CODE END Private_functions */
|
||||
|
||||
/* Exported functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief VDM Initialization function
|
||||
* @param PortNum Index of current used port
|
||||
* @retval status
|
||||
*/
|
||||
USBPD_StatusTypeDef USBPD_VDM_UserInit(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_UserInit */
|
||||
return USBPD_OK;
|
||||
/* USER CODE END USBPD_VDM_UserInit */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VDM Reset function
|
||||
* @param PortNum Index of current used port
|
||||
* @retval status
|
||||
*/
|
||||
void USBPD_VDM_UserReset(uint8_t PortNum)
|
||||
{
|
||||
/* USER CODE BEGIN USBPD_VDM_UserReset */
|
||||
|
||||
/* USER CODE END USBPD_VDM_UserReset */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Exported_functions */
|
||||
|
||||
/* USER CODE END Exported_functions */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
78
USBPD/usbpd_vdm_user.h
Normal file
78
USBPD/usbpd_vdm_user.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbpd_vdm_user.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for usbpd_vdm_user.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef __USBPD_VDM_USER_H_
|
||||
#define __USBPD_VDM_USER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/** @addtogroup STM32_USBPD_APPLICATION
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_USBPD_APPLICATION_VDM_USER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t VDM_XID_SOP :32; /*!< A decimal number assigned by USB-IF before certification */
|
||||
uint32_t VDM_USB_VID_SOP :16; /*!< A unique 16-bit number, assigned to the Vendor by USB-IF. */
|
||||
uint32_t VDM_PID_SOP :16; /*!< A unique number assigned by the Vendor ID holder identifying the product. */
|
||||
uint32_t VDM_bcdDevice_SOP :16; /*!< A unique number assigned by the Vendor ID holder containing identity information relevant to the release version of the product. */
|
||||
USBPD_ModalOp_TypeDef VDM_ModalOperation : 1; /*!< Product support Modes based on @ref USBPD_ModalOp_TypeDef */
|
||||
USBPD_USBCapa_TypeDef VDM_USBHostSupport : 1; /*!< Indicates whether the UUT is capable of enumerating USB Host */
|
||||
USBPD_USBCapa_TypeDef VDM_USBDeviceSupport: 1; /*!< Indicates whether the UUT is capable of enumerating USB Devices */
|
||||
USBPD_ProductType_TypeDef VDM_ProductTypeUFPorCP : 3; /*!< Product type UFP or CablePlug of the UUT based on @ref USBPD_ProductType_TypeDef */
|
||||
USBPD_ProductType_TypeDef VDM_ProductTypeDFP : 3; /*!< Product type DFP of the UUT based on @ref USBPD_ProductType_TypeDef */
|
||||
uint32_t Reserved3 : 7; /*!< Reserved bits */
|
||||
} USBPD_VDM_SettingsTypeDef;
|
||||
/* USER CODE BEGIN typedef */
|
||||
|
||||
/* USER CODE END typedef */
|
||||
|
||||
/* Exported define -----------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
USBPD_StatusTypeDef USBPD_VDM_UserInit(uint8_t PortNum);
|
||||
void USBPD_VDM_UserReset(uint8_t PortNum);
|
||||
/* USER CODE BEGIN Exported functions */
|
||||
/* USER CODE END Exported functions */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBPD_VDM_USER_H_ */
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.debug_auth_permission" value=""/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.debug_auth_pwd_file" value=""/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_live_expr" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="true"/>
|
||||
<intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.formatVersion" value="2"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
|
||||
@@ -37,7 +37,7 @@
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.haltonexception" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swd_mode" value="true"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_port" value="61235"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_trace_hclk" value="16000000"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_trace_hclk" value="32000000"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.useRemoteTarget" value="true"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.vector_table" value=""/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.verify_flash_download" value="true"/>
|
||||
|
||||
132
pcb_alim.ioc
132
pcb_alim.ioc
@@ -2,6 +2,43 @@
|
||||
CAD.formats=
|
||||
CAD.pinconfig=
|
||||
CAD.provider=
|
||||
Dma.Request0=UCPD1_RX
|
||||
Dma.Request1=UCPD1_TX
|
||||
Dma.RequestsNb=2
|
||||
Dma.UCPD1_RX.0.Direction=DMA_PERIPH_TO_MEMORY
|
||||
Dma.UCPD1_RX.0.EventEnable=DISABLE
|
||||
Dma.UCPD1_RX.0.Instance=DMA1_Channel1
|
||||
Dma.UCPD1_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE
|
||||
Dma.UCPD1_RX.0.MemInc=DMA_MINC_ENABLE
|
||||
Dma.UCPD1_RX.0.Mode=DMA_NORMAL
|
||||
Dma.UCPD1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
|
||||
Dma.UCPD1_RX.0.PeriphInc=DMA_PINC_DISABLE
|
||||
Dma.UCPD1_RX.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING
|
||||
Dma.UCPD1_RX.0.Priority=DMA_PRIORITY_LOW
|
||||
Dma.UCPD1_RX.0.RequestNumber=1
|
||||
Dma.UCPD1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber
|
||||
Dma.UCPD1_RX.0.SignalID=NONE
|
||||
Dma.UCPD1_RX.0.SyncEnable=DISABLE
|
||||
Dma.UCPD1_RX.0.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT
|
||||
Dma.UCPD1_RX.0.SyncRequestNumber=1
|
||||
Dma.UCPD1_RX.0.SyncSignalID=NONE
|
||||
Dma.UCPD1_TX.1.Direction=DMA_MEMORY_TO_PERIPH
|
||||
Dma.UCPD1_TX.1.EventEnable=DISABLE
|
||||
Dma.UCPD1_TX.1.Instance=DMA1_Channel2
|
||||
Dma.UCPD1_TX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE
|
||||
Dma.UCPD1_TX.1.MemInc=DMA_MINC_ENABLE
|
||||
Dma.UCPD1_TX.1.Mode=DMA_NORMAL
|
||||
Dma.UCPD1_TX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
|
||||
Dma.UCPD1_TX.1.PeriphInc=DMA_PINC_DISABLE
|
||||
Dma.UCPD1_TX.1.Polarity=HAL_DMAMUX_REQ_GEN_RISING
|
||||
Dma.UCPD1_TX.1.Priority=DMA_PRIORITY_LOW
|
||||
Dma.UCPD1_TX.1.RequestNumber=1
|
||||
Dma.UCPD1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber
|
||||
Dma.UCPD1_TX.1.SignalID=NONE
|
||||
Dma.UCPD1_TX.1.SyncEnable=DISABLE
|
||||
Dma.UCPD1_TX.1.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT
|
||||
Dma.UCPD1_TX.1.SyncRequestNumber=1
|
||||
Dma.UCPD1_TX.1.SyncSignalID=NONE
|
||||
File.Version=6
|
||||
GPIO.groupedBy=Group By Peripherals
|
||||
I2C1.IPParameters=Timing
|
||||
@@ -9,35 +46,50 @@ I2C1.Timing=0x10C18DCC
|
||||
KeepUserPlacement=false
|
||||
Mcu.CPN=STM32G491KEU6
|
||||
Mcu.Family=STM32G4
|
||||
Mcu.IP0=I2C1
|
||||
Mcu.IP1=NVIC
|
||||
Mcu.IP2=RCC
|
||||
Mcu.IP3=SYS
|
||||
Mcu.IP4=TIM3
|
||||
Mcu.IP5=USART2
|
||||
Mcu.IPNb=6
|
||||
Mcu.IP0=DMA
|
||||
Mcu.IP1=I2C1
|
||||
Mcu.IP2=NVIC
|
||||
Mcu.IP3=RCC
|
||||
Mcu.IP4=SYS
|
||||
Mcu.IP5=TIM3
|
||||
Mcu.IP6=UCPD1
|
||||
Mcu.IP7=USART2
|
||||
Mcu.IP8=USBPD
|
||||
Mcu.IPNb=9
|
||||
Mcu.Name=STM32G491K(C-E)Ux
|
||||
Mcu.Package=UFQFPN32
|
||||
Mcu.Pin0=PA1
|
||||
Mcu.Pin1=PA2
|
||||
Mcu.Pin10=VP_SYS_VS_Systick
|
||||
Mcu.Pin11=VP_SYS_VS_DBSignals
|
||||
Mcu.Pin12=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin2=PA3
|
||||
Mcu.Pin3=PA4
|
||||
Mcu.Pin4=PA5
|
||||
Mcu.Pin5=PA6
|
||||
Mcu.Pin6=PB0
|
||||
Mcu.Pin7=PA15
|
||||
Mcu.Pin8=PB5
|
||||
Mcu.Pin9=PB7
|
||||
Mcu.PinsNb=13
|
||||
Mcu.Pin0=PA0
|
||||
Mcu.Pin1=PA1
|
||||
Mcu.Pin10=PA11
|
||||
Mcu.Pin11=PA12
|
||||
Mcu.Pin12=PA15
|
||||
Mcu.Pin13=PB4
|
||||
Mcu.Pin14=PB5
|
||||
Mcu.Pin15=PB6
|
||||
Mcu.Pin16=PB7
|
||||
Mcu.Pin17=VP_SYS_VS_Systick
|
||||
Mcu.Pin18=VP_SYS_VS_DBSignals
|
||||
Mcu.Pin19=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin2=PA2
|
||||
Mcu.Pin20=VP_USBPD_VS_USBPD1
|
||||
Mcu.Pin21=VP_USBPD_VS_PD3FULL
|
||||
Mcu.Pin22=VP_USBPD_VS_usbpd_tim1
|
||||
Mcu.Pin3=PA3
|
||||
Mcu.Pin4=PA4
|
||||
Mcu.Pin5=PA5
|
||||
Mcu.Pin6=PA6
|
||||
Mcu.Pin7=PB0
|
||||
Mcu.Pin8=PA9
|
||||
Mcu.Pin9=PA10
|
||||
Mcu.PinsNb=23
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32G491KEUx
|
||||
MxCube.Version=6.13.0
|
||||
MxDb.Version=DB.6.0.130
|
||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
||||
NVIC.DMA1_Channel2_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.EXTI1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.EXTI9_5_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
@@ -49,12 +101,32 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
||||
NVIC.UCPD1_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true
|
||||
NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
PA0.GPIOParameters=GPIO_PuPd,GPIO_ModeDefaultOutputPP
|
||||
PA0.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PA0.GPIO_PuPd=GPIO_NOPULL
|
||||
PA0.Locked=true
|
||||
PA0.Signal=GPIO_Output
|
||||
PA1.GPIOParameters=GPIO_ModeDefaultEXTI
|
||||
PA1.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING
|
||||
PA1.Locked=true
|
||||
PA1.Signal=GPXTI1
|
||||
PA10.GPIOParameters=GPIO_PuPd,GPIO_ModeDefaultOutputPP
|
||||
PA10.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PA10.GPIO_PuPd=GPIO_NOPULL
|
||||
PA10.Locked=true
|
||||
PA10.Signal=GPIO_Output
|
||||
PA11.GPIOParameters=GPIO_PuPd,GPIO_ModeDefaultOutputPP
|
||||
PA11.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
PA11.GPIO_PuPd=GPIO_NOPULL
|
||||
PA11.Locked=true
|
||||
PA11.Signal=GPIO_Output
|
||||
PA12.GPIOParameters=GPIO_PuPd
|
||||
PA12.GPIO_PuPd=GPIO_PULLUP
|
||||
PA12.Locked=true
|
||||
PA12.Signal=GPIO_Input
|
||||
PA15.Locked=true
|
||||
PA15.Mode=I2C
|
||||
PA15.Signal=I2C1_SCL
|
||||
@@ -70,12 +142,20 @@ PA5.Locked=true
|
||||
PA5.Signal=GPIO_Input
|
||||
PA6.Locked=true
|
||||
PA6.Signal=GPIO_Input
|
||||
PA9.GPIOParameters=GPIO_Label
|
||||
PA9.GPIO_Label=TCPP02_EN
|
||||
PA9.Locked=true
|
||||
PA9.Signal=GPIO_Output
|
||||
PB0.Locked=true
|
||||
PB0.Signal=S_TIM3_CH3
|
||||
PB4.Mode=Source_AllSignals
|
||||
PB4.Signal=UCPD1_CC2
|
||||
PB5.GPIOParameters=GPIO_ModeDefaultEXTI
|
||||
PB5.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
|
||||
PB5.Locked=true
|
||||
PB5.Signal=GPXTI5
|
||||
PB6.Mode=Source_AllSignals
|
||||
PB6.Signal=UCPD1_CC1
|
||||
PB7.Locked=true
|
||||
PB7.Mode=I2C
|
||||
PB7.Signal=I2C1_SDA
|
||||
@@ -110,7 +190,7 @@ ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_TIM3_Init-TIM3-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_TIM3_Init-TIM3-false-HAL-true,5-MX_USART2_UART_Init-USART2-false-HAL-true,6-MX_I2C1_Init-I2C1-false-HAL-true,7-MX_UCPD1_Init-UCPD1-false-LL-true,8-MX_USBPD_Init-USBPD-false-HAL-false
|
||||
RCC.ADC12Freq_Value=72000000
|
||||
RCC.ADC345Freq_Value=72000000
|
||||
RCC.AHBFreq_Value=72000000
|
||||
@@ -165,11 +245,19 @@ TIM3.IPParameters=Prescaler,Channel-PWM Generation3 CH3,AutoReloadPreload
|
||||
TIM3.Prescaler=71
|
||||
USART2.IPParameters=VirtualMode-Asynchronous
|
||||
USART2.VirtualMode-Asynchronous=VM_ASYNC
|
||||
USBPD.IPParameters=USBPD_PORT0_PDO_SRC_FIXED_SET_MAX_CURRENT_0
|
||||
USBPD.USBPD_PORT0_PDO_SRC_FIXED_SET_MAX_CURRENT_0=5000
|
||||
VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals
|
||||
VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals
|
||||
VP_SYS_VS_Systick.Mode=SysTick
|
||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||
VP_TIM3_VS_ClockSourceINT.Mode=Internal
|
||||
VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT
|
||||
VP_USBPD_VS_PD3FULL.Mode=PD3_Full_Stack
|
||||
VP_USBPD_VS_PD3FULL.Signal=USBPD_VS_PD3FULL
|
||||
VP_USBPD_VS_USBPD1.Mode=USBPD_P0
|
||||
VP_USBPD_VS_USBPD1.Signal=USBPD_VS_USBPD1
|
||||
VP_USBPD_VS_usbpd_tim1.Mode=TIM1
|
||||
VP_USBPD_VS_usbpd_tim1.Signal=USBPD_VS_usbpd_tim1
|
||||
board=custom
|
||||
isbadioc=false
|
||||
|
||||
Reference in New Issue
Block a user