diff --git a/examples/stm32f072_discovery/stusb4500/main.cpp b/examples/stm32f072_discovery/stusb4500/main.cpp new file mode 100644 index 0000000000..86bdd3d699 --- /dev/null +++ b/examples/stm32f072_discovery/stusb4500/main.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, Raphael Lehmann + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#include +#include +#include + +modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; +#undef MODM_LOG_LEVEL +#define MODM_LOG_LEVEL modm::log::INFO +modm::log::Logger modm::log::debug(loggerDevice); +modm::log::Logger modm::log::info(loggerDevice); +modm::log::Logger modm::log::warning(loggerDevice); +modm::log::Logger modm::log::error(loggerDevice); + +using Sda = GpioB7; +using Scl = GpioB6; +using MyI2cMaster = I2cMaster1; + +modm::Stusb4500 usb{}; + +int +main() +{ + Board::initialize(); + + // Enable USART 1 (TX only) + Usart1::connect(); + Usart1::initialize(); + + MODM_LOG_INFO << "STM32F072 Discovery Example: USB-PD with STUSB4500 chip" << modm::endl; + + MyI2cMaster::connect(); + MyI2cMaster::initialize(); + + Board::LedUp::set(); + + RF_CALL_BLOCKING(usb.configurePdo(1, 5000, 500)); // must be set to 5V according to USB standard + RF_CALL_BLOCKING(usb.configurePdo(2, 20000, 1500)); // 20V, 1.5A -> 30W + RF_CALL_BLOCKING(usb.configurePdo(3, 20000, 4000)); // 20V, 4A -> 80W + + RF_CALL_BLOCKING(usb.setValidPdo(3)); // we prefer PDO 3 (more current) + + modm::delay(200ms); + + // check results + modm::stusb4500::RdoRegStatusData status = RF_CALL_BLOCKING(usb.getRdoRegStatus()); + + MODM_LOG_INFO << "Maximum current: " << status.MaxCurrent << " mA" << modm::endl; + + Board::LedDown::set(); + + while (true) { + Board::LedRight::toggle(); + modm::delay(1000ms); + } +} diff --git a/examples/stm32f072_discovery/stusb4500/project.xml b/examples/stm32f072_discovery/stusb4500/project.xml new file mode 100644 index 0000000000..89a6908eaa --- /dev/null +++ b/examples/stm32f072_discovery/stusb4500/project.xml @@ -0,0 +1,13 @@ + + modm:disco-f072rb + + + + + modm:build:scons + modm:debug + modm:driver:stusb4500 + modm:platform:i2c:1 + modm:platform:uart:1 + +