58
58
extern uint32_t __Vectors [];
59
59
60
60
#define VECTORS_FLASH_START __Vectors
61
- #define UICR_BOOTLOADER_ADDRESS 0x10001014
62
- #define MBR_ADDRESS 0x0
61
+ #define MBR_VTOR_ADDRESS 0x20000000
62
+ #define SOFTDEVICE_VTOR_ADDRESS 0x20000004
63
63
64
64
/**
65
65
* @brief Function for relocation of the vector to RAM on nRF5x devices.
@@ -68,36 +68,42 @@ extern uint32_t __Vectors[];
68
68
void nrf_reloc_vector_table (void )
69
69
{
70
70
// Copy and switch to dynamic vectors
71
- uint32_t * old_vectors = ( uint32_t * ) VECTORS_FLASH_START ;
71
+ uint32_t * old_vectors = VECTORS_FLASH_START ;
72
72
uint32_t i ;
73
73
for (i = 0 ; i < NVIC_NUM_VECTORS ; i ++ ) {
74
74
nrf_dispatch_vector [i ] = old_vectors [i ];
75
75
}
76
76
77
77
#if defined(SOFTDEVICE_PRESENT )
78
- /* Bootloader address is stored in UICR */
79
- uint32_t * bootloader = (uint32_t * ) UICR_BOOTLOADER_ADDRESS ;
80
78
81
79
/**
82
- * Before setting the new vector table address in the SoftDevice the MBR must be initialized.
83
- * If no bootloader is present the MBR will be initialized automatically.
80
+ * Before setting the new vector table address in the SoftDevice the MBR must be initialized.
81
+ * If no bootloader is present the MBR will be initialized automatically.
84
82
* If a bootloader is present nrf_dfu_mbr_init_sd must be called once and only once.
85
83
*
86
- * This application is a bootloader being booted for the first time if:
87
- * 1. The application's vector table (VECTORS_FLASH_START) is set in the UICR.
88
- * 2. SCB->VTOR is still pointing to the MBR's vector table (MBR_ADDRESS).
84
+ * By resetting the MBR and SoftDevice VTOR address first, it becomes safe to initialize
85
+ * the MBR again regardless of how the application was started.
89
86
*/
90
- if ((VECTORS_FLASH_START == (uint32_t * ) * bootloader ) && (SCB -> VTOR == MBR_ADDRESS )) {
91
87
92
- /* Initialize MBR so SoftDevice service calls are being trapped correctly. */
93
- nrf_dfu_mbr_init_sd ();
94
- }
88
+ /* Reset MBR VTOR to original state before calling MBR init. */
89
+ uint32_t * mbr_vtor_address = (uint32_t * ) MBR_VTOR_ADDRESS ;
90
+ * mbr_vtor_address = (uint32_t ) VECTORS_FLASH_START ;
91
+
92
+ /* Reset SoftDevive VTOR. */
93
+ uint32_t * softdevice_vtor_address = (uint32_t * ) SOFTDEVICE_VTOR_ADDRESS ;
94
+ * softdevice_vtor_address = 0xFFFFFFFF ;
95
95
96
96
/* Set SCB->VTOR to go through MBR to trap SoftDevice service calls. */
97
97
SCB -> VTOR = 0x0 ;
98
98
99
+ /* Initialize MBR so SoftDevice service calls are being trapped correctly.
100
+ * This call sets MBR_VTOR_ADDRESS to point to the SoftDevice's VTOR at address 0x1000.
101
+ */
102
+ nrf_dfu_mbr_init_sd ();
103
+
99
104
/* Instruct the SoftDevice to forward interrupts to the application's vector table in RAM. */
100
105
sd_softdevice_vector_table_base_set ((uint32_t ) nrf_dispatch_vector );
106
+
101
107
#else
102
108
103
109
/* No SoftDevice is present. Set all interrupts to vector table in RAM. */
0 commit comments