AnsweredAssumed Answered

How to relocate the Cortex-M0 Vector Table

Question asked by a._rico.alejandra on Jun 19, 2015
Latest reply on Jun 20, 2015 by Pac-Man
Hello I have a problem with the vector table relocating, I moved the vector table with the following code, but when I am activating the usart interrupts the programs hangs
#define APPLICATION_ADDRESS     (uint32_t)0x08003000
 __IO uint32_t VectorTable[48] __attribute__((at(0x20000000)));
 
int main (void)
{
     uint32_t i = 0;


/* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/  


  /* Copy the vector table from the Flash (mapped at the base of the application
     load address 0x08003000) to the base address of the SRAM at 0x20000000. */
  for(i = 0; i < 48; i++)
  {
    VectorTable[i] = *(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));
  }


 /* Enable the SYSCFG peripheral clock*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
 
/* Remap SRAM at 0x00000000 */
SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);


     init_SystickClock();
     rtc_ini();
     init_SPI1();
     init_led();     
     init_LCD ();     
     Delayms(500);
     init_USART1(9600);
}

void init_USART1(uint32_t baudrate) // this funcion initializes the USART1 peripheral
{
     
//     RCC_ClocksTypeDef                RCC_Clocks;
     GPIO_InitTypeDef        GPIO_InitStructure;               // this is for the GPIO pins 
     USART_InitTypeDef                USART1_InitStructure;      // this is for the USART1 initilization
//     
     //************ Enable USART CLOCK ************//
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);


     /* GPIOA Periph clock enable */
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);     
     
     //************ Configure the TX and RX PIN ************//
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;     
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;                                                        
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                                             
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;                                                  
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;                                                       
     GPIO_Init(GPIOA, &GPIO_InitStructure);     
          
     //************ Configure the RTS PIN ************//
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; 
     GPIO_Init(GPIOA, &GPIO_InitStructure);
     
     //************ Configure the CTS PIN ************//
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 
     GPIO_Init(GPIOA, &GPIO_InitStructure);
          
     //************ Asigned the AF (connect USART1 pins to USART1 alternate function) ************//
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);     // TX
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);     // RX
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_1);     // CTS
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_1);     // RTS


     USART1_InitStructure.USART_BaudRate = baudrate;                                                                                          // the baudrate is set to the value we passed into this init function
     USART1_InitStructure.USART_WordLength = USART_WordLength_8b;                                                       // we want the data frame size to be 8 bits (standard)
     USART1_InitStructure.USART_StopBits = USART_StopBits_1;                                                                      // we want 1 stop bit (standard)
     USART1_InitStructure.USART_Parity = USART_Parity_Even;                                                                           // we don't want a parity bit (standard)
     USART1_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;     // we don't want flow control (standard)
     USART1_InitStructure.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;                                                  // we want to enable the transmitter and the receiver
     USART_Init(USART1, &USART1_InitStructure);                                                                                                    // again all the properties are passed to the USART_Init function which takes care of all the bit setting
     
      // finally this enables the complete USART1 peripheral






  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);


  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; // Pins 9 (TX) and 10 (RX) are used
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // the pins are configured as alternate function so the USART peripheral has access to them
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // this defines the IO speed and has nothing to do with the baudrate!
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // this defines the output type as push pull mode (as opposed to open drain)
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // this activates the pullup resistors on the IO pins
  GPIO_Init(GPIOA, &GPIO_InitStructure);


  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); //
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);




  USART1_InitStructure.USART_BaudRate = 9600; // the baudrate is set to the value we passed into this init function
  USART1_InitStructure.USART_WordLength = USART_WordLength_9b; // we want the data frame size to be 8 bits (standard)
  USART1_InitStructure.USART_StopBits = USART_StopBits_1; // we want 1 stop bit (standard)
  USART1_InitStructure.USART_Parity = USART_Parity_Even; // we don't want a parity bit (standard)
  USART1_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // we don't want flow control (standard)
  USART1_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; // we want to enable the transmitter and the receiver
  USART_Init(USART1, &USART1_InitStructure);


  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // enable the USART1 receive interrupt
  USART_ITConfig(USART1, USART_IT_TXE, ENABLE); // enable the USART1  interrupt
     //USART_ITConfig(USART1, USART_IT_RTO, ENABLE); // enable the USART1 timeout interrupt
//     USART_SetReceiverTimeOut(USART1, 200);
     
     GPIO_ResetBits(GPIOA,GPIO_Pin_12);// RTS Usart1
  USART_Cmd(USART1, ENABLE);
}

Outcomes