Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 3:db424769ecca
- Parent:
- 2:7c45a714b991
- Child:
- 4:c52637c8d084
--- a/main.cpp Thu Aug 01 07:53:05 2019 +0000
+++ b/main.cpp Fri Aug 02 04:16:14 2019 +0000
@@ -1,5 +1,5 @@
-#include <mbed.h>
-
+//#include <mbed.h>
+#include "stm32f303xe.h"
#include <iostream>
#include <iomanip>
@@ -10,7 +10,7 @@
void inline enable_timer ()
{
- TIM2->CR1 = TIM_CR1_URS | TIM_CR1_CEN;
+ TIM2->CR1 |= TIM_CR1_ARPE | TIM_CR1_OPM | TIM_CR1_URS | TIM_CR1_CEN;
}
void inline enable_timer_interrupt ()
@@ -100,10 +100,21 @@
toggle_LED();
}
+void fun ()
+{
+ cout << "Interrupt hit!" << endl;
+ clear_timer_status();
+ toggle_LED();
+}
+
inline void enable_interrupt ()
{
- NVIC_SetPriority(TIM2_IRQn, 255);
+ NVIC_SetPriority(TIM2_IRQn, 250);
+ cout << "TIM2_IRQn priority : " << NVIC_GetPriority(TIM2_IRQn) << endl;
NVIC_EnableIRQ(TIM2_IRQn);
+ cout << "TIM2_IRQn status : " << NVIC_GetEnableIRQ(TIM2_IRQn) << endl;
+ cout << "TIM2_IRQn pending : " << NVIC_GetPendingIRQ(TIM2_IRQn) << endl;
+ NVIC_SetVector(TIM2_IRQn, (uint32_t) &fun);
}
//
@@ -119,20 +130,27 @@
TIM2->CR1 = TIM2->CR2 = TIM2->SMCR = TIM2->DIER = TIM2->SR = TIM2->CCMR1 = TIM2->CCMR2
= TIM2->CCER = TIM2->CNT = TIM2->PSC = TIM2->CCR1 = TIM2->CCR2 = TIM2->CCR3
= TIM2->CCR4 = TIM2->DCR = TIM2->DMAR = 0;
+ TIM2->CR1 |= TIM_CR1_UDIS;
downscale_timer_max();
limit_timer_counter_to(0x1000);
// ^ LED stays open for 0.5 and closed for 0.5 with a total of 1 sec.
// -
clear_timer_status();
-// enable_timer_interrupt();
+ enable_timer_interrupt();
enable_timer();
enable_interrupt();
cout << "Exiting main().." << endl;
cout << endl;
+ cout << hex
+ << "Status : 0x" << TIM2->SR << endl
+ << "Count : 0x" << TIM2->CNT << endl;
+ TIM2->CR1 &= ~TIM_CR1_UDIS;
while (true)
{
cout << hex
<< "Status : 0x" << TIM2->SR << endl
<< "Count : 0x" << TIM2->CNT << endl;
+ if (TIM2->CNT > 2)
+ TIM2->SR = 0;
}
}
\ No newline at end of file