AnsweredAssumed Answered

SCB_VTOR description incorrect in PM0056 and bug in misc.c:NVIC_SetVectorTable

Question asked by Luke on Sep 8, 2011
Latest reply on Sep 9, 2011 by Luke
In section 4.4.4, page 134, of  the STM32 Cortex-M3 programming manual (PM0056, Rev 4), the vector table offset register is shown as being partitioned in three sections:
[31:30]  -- reserved
[29:9] -- TBLOFF
[8:0] -- reserved

In the description, however, TBLOFF is described as occupying bits [29:11], and bits [10:0] are said to be reserved.   According to the description, the table must have a minimum alignment of 128 words (4 bytes / word *  128 words = 512 bytes), so having bits [8:0] as reserved makes sense (2 ^ 9 = 512).

It seems contradictory that in the bit field picture, bits 9 and 10 are marked as "rw", but in the bit description below this picture, it is stated that bits 10:0 are reserved and must be kept clear.

It seems that the bit field picture is likely correct, but that the bit descriptions should read:
Bits 31:30 ...
Bits 29:9  ...
Bits 8:0  ...

instead of:
Bits 31:30 ...
Bits 29:11  ...
Bits 10:0  ..

In looking at the part of the firmware library that manipulates this register (misc.h/misc.c, function NVIC_SetVectorTable), we have the following:
misc.h:
#define NVIC_VectTab_RAM             ((uint32_t)0x20000000)
#define NVIC_VectTab_FLASH           ((uint32_t)0x08000000)

misc.c:
void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
{
  ...
  SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
}

In particular, this part seems incorrect:
(Offset & (uint32_t)0x1FFFFF80)

This clears bits [31:29] and bits [6:0] of Offset, which is presumably being done to clear all the bits in the reserved parts of the SCB_VTOR register.  The clearing of bits [31:29] seems reasonable given that the result will be bitwise or'd with either NVIC_VectTab_RAM or NVIC_VecTab_Flash.  However, clearing bits[6:0] doesn't seem correct.  Instead it seems (assuming my preceding arguments about PM0056 above are correct) that bits [8:0] should be cleared, so the correct code would read:

SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFE00);

If I am correct, this means there is a typo in PM0056, as well as a bug in NVIC_SetVectorTable of misc.c in the STM32 standard peripheral library.

Can anybody confirm this?

Outcomes