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.
Fork of mbed-dev by
targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c@0:9b334a45a8ff, 2015-10-01 (annotated)
- Committer:
- bogdanm
- Date:
- Thu Oct 01 15:25:22 2015 +0300
- Revision:
- 0:9b334a45a8ff
Initial commit on mbed-dev
Replaces mbed-src (now inactive)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /* mbed Microcontroller Library - cmsis_nvic for STM32F4 |
bogdanm | 0:9b334a45a8ff | 2 | * Copyright (c) 2009-2011 ARM Limited. All rights reserved. |
bogdanm | 0:9b334a45a8ff | 3 | * |
bogdanm | 0:9b334a45a8ff | 4 | * CMSIS-style functionality to support dynamic vectors |
bogdanm | 0:9b334a45a8ff | 5 | */ |
bogdanm | 0:9b334a45a8ff | 6 | #include "cmsis_nvic.h" |
bogdanm | 0:9b334a45a8ff | 7 | |
bogdanm | 0:9b334a45a8ff | 8 | #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Location of vectors in RAM |
bogdanm | 0:9b334a45a8ff | 9 | |
bogdanm | 0:9b334a45a8ff | 10 | static unsigned char vtor_relocated; |
bogdanm | 0:9b334a45a8ff | 11 | |
bogdanm | 0:9b334a45a8ff | 12 | void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { |
bogdanm | 0:9b334a45a8ff | 13 | uint32_t *vectors = (uint32_t*)SCB->VTOR; |
bogdanm | 0:9b334a45a8ff | 14 | uint32_t i; |
bogdanm | 0:9b334a45a8ff | 15 | |
bogdanm | 0:9b334a45a8ff | 16 | // Copy and switch to dynamic vectors if the first time called |
bogdanm | 0:9b334a45a8ff | 17 | if (!vtor_relocated) { |
bogdanm | 0:9b334a45a8ff | 18 | uint32_t *old_vectors = vectors; |
bogdanm | 0:9b334a45a8ff | 19 | vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; |
bogdanm | 0:9b334a45a8ff | 20 | for (i=0; i<NVIC_NUM_VECTORS; i++) { |
bogdanm | 0:9b334a45a8ff | 21 | vectors[i] = old_vectors[i]; |
bogdanm | 0:9b334a45a8ff | 22 | } |
bogdanm | 0:9b334a45a8ff | 23 | SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS; |
bogdanm | 0:9b334a45a8ff | 24 | vtor_relocated = 1; |
bogdanm | 0:9b334a45a8ff | 25 | } |
bogdanm | 0:9b334a45a8ff | 26 | vectors[IRQn + 16] = vector; |
bogdanm | 0:9b334a45a8ff | 27 | } |
bogdanm | 0:9b334a45a8ff | 28 | |
bogdanm | 0:9b334a45a8ff | 29 | uint32_t NVIC_GetVector(IRQn_Type IRQn) { |
bogdanm | 0:9b334a45a8ff | 30 | uint32_t *vectors = (uint32_t*)SCB->VTOR; |
bogdanm | 0:9b334a45a8ff | 31 | return vectors[IRQn + 16]; |
bogdanm | 0:9b334a45a8ff | 32 | } |
bogdanm | 0:9b334a45a8ff | 33 |