Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[board] add same70 xplained board #969

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ jobs:
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py same54_xplained_pro)
- name: Examples SAME70 Devices
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py same70_xplained)
- name: Examples SAMV Devices
if: always()
run: |
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,12 @@ We have out-of-box support for many development boards including documentation.
<td align="center"><a href="https://modm.io/reference/config/modm-samd21-xplained-pro">SAMD21-XPLAINED-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-same54-xplained-pro">SAME54-XPLAINED-PRO</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-same70-xplained">SAME70-XPLAINED</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-samg55-xplained-pro">SAMG55-XPLAINED-PRO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-samv71-xplained-ultra">SAMV71-XPLAINED-ULTRA</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-srxe">Smart Response XE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32_f4ve">STM32-F4VE</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32_f4ve">STM32-F4VE</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-stm32f030_demo">STM32F030-DEMO</a></td>
<td align="center"><a href="https://modm.io/reference/config/modm-thingplus-rp2040">THINGPLUS-RP2040</a></td>
</tr>
Expand Down
38 changes: 38 additions & 0 deletions examples/same70_xplained/adc/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2021, Jeff McBride
* Copyright (c) 2022, Christopher Durand
* Copyright (c) 2023, Luiz Carlos Gili
*
* 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/io/iostream.hpp>

using namespace modm::platform;
using namespace modm::literals;

using Ad2 = GpioD30::Ad; // channel 0, pin AD2 on board
using Ad3 = GpioA19::Ad; // channel 8, pin AD8 on board

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

Afec0::initialize<Board::SystemClock>();
Afec0::connect<Ad2::Ad, Ad3::Ad>();

while (true)
{
MODM_LOG_INFO << "ADC Readings: ";
MODM_LOG_INFO.printf("%5d ", Afec0::readChannel(Afec0::getPinChannel<Ad2>()));
MODM_LOG_INFO.printf("%5d ", Afec0::readChannel(Afec0::getPinChannel<Ad3>()));
MODM_LOG_INFO << modm::endl;

modm::delay(500ms);
}
}
10 changes: 10 additions & 0 deletions examples/same70_xplained/adc/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:same70-xplained</extends>
<options>
<option name="modm:build:build.path">../../../build/same70_xplained/adc</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:adc:0</module>
</modules>
</library>
44 changes: 44 additions & 0 deletions examples/same70_xplained/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2016-2017, Niklas Hauser
* Copyright (c) 2023, Luiz Carlos Gili
*
* 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/architecture/interface/delay.hpp>
using namespace Board;

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

// Use the logging streams to print some messages.
// Change MODM_LOG_LEVEL above to enable or disable these messages
MODM_LOG_DEBUG << "debug" << modm::endl;
MODM_LOG_INFO << "info" << modm::endl;
MODM_LOG_WARNING << "warning" << modm::endl;
MODM_LOG_ERROR << "error" << modm::endl;

uint32_t counter(0);

while (true)
{
Led0::toggle();
modm::delay_ms(1000);

if(ButtonSW0::read()){
counter = 0;
}

MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
}

return 0;
}
9 changes: 9 additions & 0 deletions examples/same70_xplained/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<library>
<extends>modm:same70-xplained</extends>
<options>
<option name="modm:build:build.path">../../../build/same70_xplained/blink</option>
</options>
<modules>
<module>modm:build:scons</module>
</modules>
</library>
66 changes: 66 additions & 0 deletions examples/same70_xplained/pwm/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2023, Christopher Durand
* Copyright (c) 2023, Luiz Carlos Gili
*
* 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>

using namespace Board;

// Complementary output on PWM0 Channel2 High / Low outputs
using OutH2 = GpioC19;
using OutL2 = GpioD26;

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

MODM_LOG_INFO << "PWM Test" << modm::endl;

Pwm0::connect<OutH2::PwmH2, OutL2::PwmL2>();

Pwm0::initialize();
// Period 1500 => MCLK / 1500 = 100 kHz
Pwm0::setPeriod(Pwm0::Channel::Ch2, 1500);
// 500/1500 = 33.3% duty-cycle
Pwm0::setDutyCycle(Pwm0::Channel::Ch2, 500);

constexpr auto mode = Pwm0::ChannelMode()
.setClock(Pwm0::ChannelClock::Mck)
.setDeadTimeGeneration(Pwm0::DeadTimeGeneration::Enabled);

Pwm0::setChannelMode(Pwm0::Channel::Ch2, mode);

// Set 50 ticks dead-time for both high and low output
const auto deadTimeL = 50; // ticks
const auto deadTimeH = 50; // ticks
Pwm0::setDeadTime(Pwm0::Channel::Ch2, deadTimeL, deadTimeH);

// Set all outputs to low in override mode
Pwm0::configureOutputOverrideValues(Pwm0::Outputs_t{});

Pwm0::enableChannelOutput(Pwm0::Channels::Ch2);

while (true)
{
Led0::toggle();
modm::delay(500ms);

// Activate override mode to force outputs to low when button is pressed
const auto outputs = Pwm0::Outputs::Ch2PwmH | Pwm0::Outputs::Ch2PwmL;
if (ButtonSW0::read())
Pwm0::setOutputOverride(outputs, false);
else
Pwm0::clearOutputOverride(outputs, false);

}

return 0;
}
10 changes: 10 additions & 0 deletions examples/same70_xplained/pwm/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:same70-xplained</extends>
<options>
<option name="modm:build:build.path">../../../build/same70_xplained/pwm</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:pwm:*</module>
</modules>
</library>
72 changes: 72 additions & 0 deletions examples/same70_xplained/timer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2023, Christopher Durand
* Copyright (c) 2023, Luiz Carlos Gili
*
* 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/platform/timer/timer_channel_0.hpp>
#include <modm/platform/timer/timer_channel_10.hpp>

using namespace Board;

// use timer channel 10 to toggle led
MODM_ISR(TC10)
{
// clear interrupt flags by reading
(void) TimerChannel10::getInterruptFlags();
Led0::toggle();
}

using Tioa0 = GpioA0;


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

MODM_LOG_INFO << "Timer / Counter Test" << modm::endl;

// generate 25% duty-cycle 100 kHz PWM waveform on TIOA0 output (GpioA0)
TimerChannel0::initialize();
TimerChannel0::connect<Tioa0::Tioa>();

TimerChannel0::setClockSource(TimerChannel0::ClockSource::Mck);
TimerChannel0::setWaveformMode(true);
// Up-counter, reset on register C compare match
TimerChannel0::setWaveformSelection(TimerChannel0::WavSel::Up_Rc);

// Clear output on register A match, set on register C match
TimerChannel0::setTioaEffects(TimerChannel0::TioEffect::Clear, TimerChannel0::TioEffect::Set);
// period MCLK = 150 MHz / 1500 = 100 kHz
// duty-cycle 375 / 1500 = 25%
TimerChannel0::setRegA(375);
TimerChannel0::setRegC(1500);
TimerChannel0::enable();
TimerChannel0::start();

// setup timer channel 10 to run interrupt at ~1 Hz from ~32 kHz internal slow clock
TimerChannel10::initialize();
TimerChannel10::setClockSource(TimerChannel10::ClockSource::Slck);
// Toggle every 8192 / 32768 kHz = 0.25s => 1 Hz period
TimerChannel10::setRegC(8192);
TimerChannel10::setWaveformMode(true);
TimerChannel10::setWaveformSelection(TimerChannel10::WavSel::Up_Rc);
TimerChannel10::enableInterruptVector(true);
TimerChannel10::enableInterrupt(TimerChannel10::Interrupt::RcCompare);
TimerChannel10::enable();
TimerChannel10::start();

while (true)
{
modm::delay(500ms);
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/same70_xplained/timer/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:same70-xplained</extends>
<options>
<option name="modm:build:build.path">../../../build/same70_xplained/timer</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:timer:*</module>
</modules>
</library>
97 changes: 97 additions & 0 deletions src/modm/board/same70_xplained/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2022, Christopher Durand
* Copyright (c) 2023, Luiz Carlos Gili
*
* 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/.
*/
// ----------------------------------------------------------------------------
#pragma once

#include <modm/architecture/interface/clock.hpp>
#include <modm/platform.hpp>
#include <modm/debug/logger.hpp>

#define MODM_BOARD_HAS_LOGGER

namespace Board
{
/// @ingroup modm_board_same70_xplained_pro
/// @{
using namespace modm::literals;
using namespace modm::platform;

struct SystemClock
{
// 300 MHz system clock generated by PLLA from external 12 MHz crystal
static constexpr uint32_t PllAMult = 25;
static constexpr uint32_t Frequency = 300_MHz;
static constexpr uint32_t Mck = Frequency / 2; // 150 MHz max.
static constexpr uint32_t Usart1 = Mck;
static constexpr uint32_t Spi0 = Mck;
// static constexpr uint32_t Usb = 48_MHz;

static bool inline
enable()
{
ClockGen::setFlashLatency<Mck>();

ClockGen::enableMainExternalCrystal<12_MHz>(std::chrono::microseconds{1000});
ClockGen::selectMainClockSource(MainClockSource::External);

ClockGen::enablePllA<PllAMult>();
ClockGen::selectMasterClk<MasterClkSource::PLLA_CLK, MasterClkPrescaler::CLK_1, MasterClkDivider::Div2>();
ClockGen::updateCoreFrequency<Frequency>();

return true;
}
};

using Led0 = GpioC8;
using ButtonSW0 = GpioInverted<GpioA11>;

using Leds = SoftwareGpioPort<Led0>;

struct Debug
{
using Uart = Usart1;
using UartTx = GpioB4;
using UartRx = GpioA21;
};

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

inline void
initialize()
{
// Turn off the watchdog
WDT->WDT_MR = WDT_MR_WDDIS_Msk;

SystemClock::enable();
SysTickTimer::initialize<SystemClock>();

// Disable JTAG TDI function on debug UART TX pin
MATRIX->CCFG_SYSIO |= CCFG_SYSIO_SYSIO4;

Debug::Uart::initialize<SystemClock, 115200>();
Debug::Uart::connect<Debug::UartTx::Tx, Debug::UartRx::Rx>();

Leds::setOutput();
ButtonSW0::setInput(InputType::PullUp);
}

/*
// TODO: usb
inline void initializeUsbFs()
{
//SystemClock::enableUsb();
//modm::platform::Usb::initialize<Board::SystemClock>();
}
*/
/// @}

} // namespace Board

Loading