Hello everyone, i'm working on NVIC, i need enable the TIMER2 IRQ, but without CMSIS HAL, just native C code, so i have got this:
#include "NVICDriver.h" #include <stdint.h> #include <string.h> #define BASE_ADDRESS_VECTOR_TABLE 0x00000000 static uint32_t* NVIC_ISER0 = 0x10000000; static uint32_t* NVIC_ICER0 = 0x18000000; typedef void(*vect_func)(void); static vect_func vector_table[1] = { TIMER2_IRQHandle }; void NVIC_Init(){ *NVIC_ISER0 |= 0x001C; //tmr2 enable interrupt IRQ 28 *NVIC_ICER0 &= 0x00000000; //Clear flags memcpy((BASE_ADDRESS_VECTOR_TABLE+0xB0), vector_table, sizeof(vector_table)); }
As you can see, first i enable the IRQ on NVIC_ISER0 (IRQ28 = TMR2 so my register is NIVC_ISER0, isn''t it? after that, i clear interrupts, and I copy to vector table just the function what i want! (0xb0 is the offset into the vector table where the TIMER2 is from)
What's wrong on this?
the function TIMER2_IRQHandle should be pointing to the TIMR2 Vector addres really? i trie to turn on LED (timer is is configured) but it doesn't work
Thanks
UPDATE:
I just try this:
#define EnablePrivilegedMode() __asm("SVC #0") #define BASE_ADDRESS_NVIC 0xE000E000 #define OFFSET_ISER0 0x100 #define BASE_ADDRESS_IABR (BASE_ADDRESS_NVIC+0x300) static uint32_t* NVIC = (uint32_t*)(BASE_ADDRESS_NVIC+OFFSET_ISER0); static uint32_t* IABR = (uint32_t*)BASE_ADDRESS_IABR; uint32_t reader = 0; void NVIC_Init(){ EnablePrivilegedMode(); *NVIC |= 0x10000000; reader = ((*IABR) & 0x10000000); //Read whether IRQ28's enabled or not if(reader == 0x10000000){ GPIOADriver_Set(PIN5); } }
i figured out how to enter in privileged mode, just doin SVC (supervisor call), after that i try to write NVIC_ISER0 the 28 bit, and READ the IABR so that to know whether the IRQ's active or no, if is, turn on the LED, but it doesn't work yet :(, the LED doesn't turn on. therefore it is not activeted! why?¿ any idea?
Ah, and enable all warnings in your compiler. There are some weird things in your code.