Skip to content

Commit

Permalink
[example] Add STUSB4500 USB-PD example for STM32F072 Discovery board
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Mar 10, 2021
1 parent edde719 commit 1a11b08
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
65 changes: 65 additions & 0 deletions examples/stm32f072_discovery/stusb4500/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <modm/board.hpp>
#include <modm/debug/logger.hpp>
#include <modm/driver/usb/stusb4500.hpp>

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<MyI2cMaster> usb{};

int
main()
{
Board::initialize();

// Enable USART 1 (TX only)
Usart1::connect<GpioOutputA9::Tx>();
Usart1::initialize<Board::SystemClock, 115200_Bd>();

MODM_LOG_INFO << "STM32F072 Discovery Example: USB-PD with STUSB4500 chip" << modm::endl;

MyI2cMaster::connect<Scl::Scl, Sda::Sda>();
MyI2cMaster::initialize<Board::SystemClock, 400_kHz>();

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);
}
}
13 changes: 13 additions & 0 deletions examples/stm32f072_discovery/stusb4500/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<library>
<extends>modm:disco-f072rb</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f072_discovery/stusb4500</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:debug</module>
<module>modm:driver:stusb4500</module>
<module>modm:platform:i2c:1</module>
<module>modm:platform:uart:1</module>
</modules>
</library>

0 comments on commit 1a11b08

Please sign in to comment.