Skip to content

Commit

Permalink
WIP: make example compile
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Apr 5, 2021
1 parent 3b304ce commit 38355d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
36 changes: 10 additions & 26 deletions examples/nucleo_g474re/can/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ using namespace modm::literals;
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::INFO


modm::IOStream&
modm::operator<<(modm::IOStream& out, const modm::can::Message& msg)
{
out << "can::Message<id=" << msg.getIdentifier();
out << msg.isExtended() ? ",extended" : ",standard";
if (msg.isRemoteTransmitRequest()) out << ",rtr";
out << ",dlc=" << msg.getDLC();
out << ",data=" << modm::hex;
for (uint32_t i = 0; i < msg.getLength(); ++i) {
out << msg.data[i];
}
out << modm::ascii << ">";
return out;
}

int
main()
{
Expand All @@ -44,24 +28,24 @@ main()
MODM_LOG_INFO << "Initializing Fdcan1..." << modm::endl;
// Initialize Fdcan1
Fdcan1::connect<GpioB8::Rx, GpioB9::Tx>(Gpio::InputType::PullUp);
Fdcan1::initialize<Board::SystemClock, 125_kbps>(9);
Fdcan1::initialize<Board::SystemClock, 125_kbps, 1_pct, 500_kbps>(9);

MODM_LOG_INFO << "Setting up Filter for Fdcan1..." << modm::endl;
// Receive every message
Fdcan1::setFilter(0, CanFilter::FIFO0,
CanFilter::ExtendedIdentifier(0),
CanFilter::ExtendedFilterMask(0));
// Receive every extended id message
Fdcan1::setExtendedFilter(0, Fdcan1::FilterConfig::Fifo0,
modm::can::ExtendedIdentifier(0),
modm::can::ExtendedMask(0));

MODM_LOG_INFO << "Initializing Fdcan2..." << modm::endl;
// Initialize Fdcan2
Fdcan2::connect<GpioB5::Rx, GpioB6::Tx>(Gpio::InputType::PullUp);
Fdcan2::initialize<Board::SystemClock, 125_kbps>(12);
Fdcan2::initialize<Board::SystemClock, 125_kbps, 1_pct, 500_kbps>(12);

MODM_LOG_INFO << "Setting up Filter for Fdcan2..." << modm::endl;
// Receive every message
//CanFilter::setFilter(14, CanFilter::FIFO0,
// CanFilter::ExtendedIdentifier(0),
// CanFilter::ExtendedFilterMask(0));
Fdcan2::setExtendedFilter(0, Fdcan2::FilterConfig::Fifo0,
modm::can::ExtendedIdentifier(0),
modm::can::ExtendedMask(0));

// Send a message
MODM_LOG_INFO << "Sending message on Fdcan1..." << modm::endl;
Expand All @@ -80,7 +64,7 @@ main()
{
if (Fdcan1::isMessageAvailable())
{
MODM_LOG_INFO << "Fdcan1: Message is available..." << modm::endl << ;
MODM_LOG_INFO << "Fdcan1: Message is available..." << modm::endl;
modm::can::Message message;
Fdcan1::getMessage(message);
MODM_LOG_INFO << message << modm::endl;
Expand Down
2 changes: 2 additions & 0 deletions src/modm/board/nucleo_g474re/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ struct SystemClock {
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

// Select PCLK1 as FDCAN clock (default is Hse)
RCC->CCIPR = (RCC->CCIPR & ~RCC_CCIPR_FDCANSEL) | RCC_CCIPR_FDCANSEL_1;
return true;
}
};
Expand Down

0 comments on commit 38355d9

Please sign in to comment.