Skip to content

Commit b05a3a2

Browse files
committed
[board] Add CAN support to SAMV71-XPLAINED board
1 parent 518e557 commit b05a3a2

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/modm/board/samv71_xplained_ultra/board.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct SystemClock
3333
static constexpr uint32_t Spi0 = Mck;
3434
static constexpr uint32_t Twihs0 = Mck;
3535
static constexpr uint32_t Dacc = Mck;
36+
37+
static constexpr uint32_t Pck5 = 80_MHz;
38+
static constexpr uint32_t Mcan = Pck5;
39+
3640
// static constexpr uint32_t Usb = 48_MHz;
3741

3842
static bool inline
@@ -47,6 +51,16 @@ struct SystemClock
4751
ClockGen::selectMasterClk<MasterClkSource::PLLA_CLK, MasterClkPrescaler::CLK_1, MasterClkDivider::Div2>();
4852
ClockGen::updateCoreFrequency<Frequency>();
4953

54+
// Enable PMC bus-independent clock output PCK5 for MCAN
55+
// Manual (48.4.2): "It is recommended to use the CAN clock at frequencies of 20, 40 or 80 MHz.
56+
// To achieve these frequencies, PMC PCK5 must select the UPLLCK (480 MHz) as source clock and
57+
// divide by 24, 12, or 6. PCK5 allows the system bus and processor clock to be modified
58+
// without affecting the bit rate communication."
59+
ClockGen::enableUPll<UtmiRefClk::Xtal12>();
60+
ClockGen::disablePck(Pck::Pck5);
61+
ClockGen::configurePck(Pck::Pck5, PckSource::UPll, 6);
62+
ClockGen::enablePck(Pck::Pck5);
63+
5064
return true;
5165
}
5266
};
@@ -70,6 +84,16 @@ using Scl = GpioA4;
7084

7185
using LoggerDevice = modm::IODeviceWrapper<Debug::Uart, modm::IOBuffer::BlockIfFull>;
7286

87+
namespace Can
88+
{
89+
/// @ingroup modm_board_samv71_xplained_ultra
90+
/// @{
91+
using Rx = GpioC12;
92+
using Tx = GpioC14;
93+
using Can = Mcan1;
94+
/// @}
95+
}
96+
7397
inline void
7498
initialize()
7599
{
@@ -87,6 +111,8 @@ initialize()
87111

88112
Leds::setOutput();
89113
ButtonSW0::setInput(InputType::PullUp);
114+
115+
Can::Can::connect<Can::Rx::Rx, Can::Tx::Tx>(InputType::PullUp);
90116
}
91117

92118
/*

src/modm/board/samv71_xplained_ultra/module.lb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ def prepare(module, options):
1919
if not options[":target"].partname == "samv71q21b-aab":
2020
return False
2121

22-
module.depends(":debug", ":platform:clockgen", ":platform:gpio", ":platform:core", ":platform:usart:1", ":platform:i2c:0") #, ":platform:usb")
22+
module.depends(":debug",
23+
":platform:can:1",
24+
":platform:clockgen",
25+
":platform:core",
26+
":platform:gpio",
27+
":platform:i2c:0",
28+
":platform:usart:1") # , ":platform:usb")
2329
return True
2430

2531
def build(env):

0 commit comments

Comments
 (0)