From b9406a9c7f2e5ccc8d02acca8b27beb8f4ce2e49 Mon Sep 17 00:00:00 2001 From: Thomas Sommer Date: Wed, 12 Jan 2022 09:33:28 +0100 Subject: [PATCH] [example] added blue_pill_f103/undefined_irq --- .../blue_pill_f103/undefined_irq/main.cpp | 100 ++++++++++++++++++ .../blue_pill_f103/undefined_irq/openocd.cfg | 2 + .../blue_pill_f103/undefined_irq/project.xml | 12 +++ 3 files changed, 114 insertions(+) create mode 100644 examples/blue_pill_f103/undefined_irq/main.cpp create mode 100644 examples/blue_pill_f103/undefined_irq/openocd.cfg create mode 100644 examples/blue_pill_f103/undefined_irq/project.xml diff --git a/examples/blue_pill_f103/undefined_irq/main.cpp b/examples/blue_pill_f103/undefined_irq/main.cpp new file mode 100644 index 0000000000..07bdfe040b --- /dev/null +++ b/examples/blue_pill_f103/undefined_irq/main.cpp @@ -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 +#include +#include +#include + +using namespace Board; +using namespace std::string_literals; + +using PushButton = GpioInverted; + +// ---------------------------------------------------------------------------- +// 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(); + Usart2::initialize(); + + // 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; +} diff --git a/examples/blue_pill_f103/undefined_irq/openocd.cfg b/examples/blue_pill_f103/undefined_irq/openocd.cfg new file mode 100644 index 0000000000..b157e7e432 --- /dev/null +++ b/examples/blue_pill_f103/undefined_irq/openocd.cfg @@ -0,0 +1,2 @@ +# Replace this with your custom programmer +source [find interface/stlink-v2.cfg] diff --git a/examples/blue_pill_f103/undefined_irq/project.xml b/examples/blue_pill_f103/undefined_irq/project.xml new file mode 100644 index 0000000000..4f66957976 --- /dev/null +++ b/examples/blue_pill_f103/undefined_irq/project.xml @@ -0,0 +1,12 @@ + + modm:blue-pill-f103 + + + + + + modm:debug + modm:build:scons + modm:platform:uart:2 + +