Skip to content

Commit

Permalink
[example] added blue_pill_f103/undefined_irq
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Jan 12, 2022
1 parent b735568 commit b9406a9
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
100 changes: 100 additions & 0 deletions examples/blue_pill_f103/undefined_irq/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2019, Niklas Hauser
* Copyright (c) 2022, Thomas Sommer
*
* 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/assert.hpp>
#include <modm/debug/logger.hpp>
#include <string>

using namespace Board;
using namespace std::string_literals;

using PushButton = GpioInverted<GpioInputA1>;

// ----------------------------------------------------------------------------
// Set the log level
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::DEBUG

// Create an IODeviceWrapper around the Uart Peripheral we want to use
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
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);

MODM_ISR(EXTI0)
{ MODM_LOG_DEBUG << "EXTI0 called!" << modm::endl; }
MODM_ISR(EXTI1)
{ MODM_LOG_DEBUG << "EXTI1 called!" << modm::endl; }
MODM_ISR(EXTI2)
{ MODM_LOG_DEBUG << "EXTI2 called!" << modm::endl; }
MODM_ISR(EXTI3)
{ MODM_LOG_DEBUG << "EXTI3 called!" << modm::endl; }

// But we forgot about EXTI4
// MODM_ISR(EXTI4)
// { MODM_LOG_DEBUG << "EXTI4 called!" << modm::endl; }

[[maybe_unused]]
static modm::Abandonment
core_assertion_handler(const modm::AssertionInfo &info)
{
if (info.name == "nvic.undef"s) {
MODM_LOG_ERROR.printf("Ignoring undefined IRQ handler %d!\n", int8_t(info.context));
return modm::Abandonment::Ignore;
}
return modm::Abandonment::DontCare;
}
// Comment this line to abandon execution
MODM_ASSERTION_HANDLER(core_assertion_handler);

int main()
{
Board::initialize();
PushButton::setInput(Gpio::InputType::PullUp);

// initialize Uart2 for MODM_LOG_*
Usart2::connect<GpioOutputA2::Tx>();
Usart2::initialize<Board::SystemClock, 115200_Bd>();

// Enable the Interrupt handlers
NVIC_EnableIRQ(EXTI0_IRQn);
NVIC_EnableIRQ(EXTI1_IRQn);
NVIC_EnableIRQ(EXTI2_IRQn);
NVIC_EnableIRQ(EXTI3_IRQn);
NVIC_EnableIRQ(EXTI4_IRQn);
// Give them the highest priority
NVIC_SetPriority(EXTI0_IRQn, 0);
NVIC_SetPriority(EXTI1_IRQn, 0);
NVIC_SetPriority(EXTI2_IRQn, 0);
NVIC_SetPriority(EXTI3_IRQn, 0);
NVIC_SetPriority(EXTI4_IRQn, 0);

MODM_LOG_INFO << "Push the Button to trigger EXTI interrupts!" << modm::endl;
int ii{0};

while (true)
{
if(PushButton::read())
{
NVIC_SetPendingIRQ(IRQn_Type(int(EXTI0_IRQn) + ii));
ii = (ii + 1) % 5;
// wait for user reaction
modm::delay(500ms);
}
}

return 0;
}
2 changes: 2 additions & 0 deletions examples/blue_pill_f103/undefined_irq/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Replace this with your custom programmer
source [find interface/stlink-v2.cfg]
12 changes: 12 additions & 0 deletions examples/blue_pill_f103/undefined_irq/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:blue-pill-f103</extends>
<options>
<option name="modm:build:build.path">../../../build/blue_pill_f103/undefined_irq</option>
<option name="modm:build:openocd.cfg">openocd.cfg</option>
</options>
<modules>
<module>modm:debug</module>
<module>modm:build:scons</module>
<module>modm:platform:uart:2</module>
</modules>
</library>

0 comments on commit b9406a9

Please sign in to comment.