Вт окт 23, 2018 09:44:48
Вт окт 23, 2018 10:31:37
#ifdef __GNUC__
extern void *__vtor;
SCB->VTOR = (uint32_t)&__vtor;
#endif
#ifdef __ICCARM__
#pragma section = ".intvec"
SCB->VTOR = (uint32_t) __section_begin(".intvec");
#endif
Вт окт 23, 2018 12:15:26
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000);
#define APPLICATION_ADDRESS ((uint32_t)0x08004000)
/* Адрес стека */
uint32_t stackAddr = (*(__IO uint32_t*)APPLICATION_ADDRESS);
/* Проверка сигнатуры */
if ((stackAddr & 0x2FFE0000) == 0x20000000)
{
/* Инициализация указателя стека */
__set_MSP(stackAddr);
/* Запуск программы */
((void(*)(void))(*(__IO uint32_t*)(APPLICATION_ADDRESS + sizeof(uint32_t))))();
}
Вт окт 23, 2018 12:32:03
#ifdef __GNUC__
extern void *__vtor;
SCB->VTOR = (uint32_t)&__vtor;
#endif
#ifdef __ICCARM__
#pragma section = ".intvec"
SCB->VTOR = (uint32_t) __section_begin(".intvec");
#endif
Вт окт 23, 2018 12:48:12
__enable_irq() эквивалент __set_PRIMASK(0)
__disable_irq() эквивалент __set_PRIMASK(1)
Вт окт 23, 2018 12:59:10
Вт окт 23, 2018 13:08:09
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_exti.h"
#include "misc.h"
#include "Uart_lib.h"
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
USART_InitTypeDef USART_InitStructure;
uint16_t a = 0, b = 0;
void Init_led(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
//----------
//
//----------
void USART1_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/*NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);*/
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure the USART1 */
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
}
//----------
//
//----------
/* void USART1_Handler(void)
{
if (USART_GetFlagStatus(USART1, USART_IT_TXE) == SET)
{
USART_ClearITPendingBit(USART1, USART_IT_TXE);
}
}*/
//----------
//
//----------
/*void Send_Uart(USART_TypeDef* USARTx, unsigned char c)
{
while(USART_GetFlagStatus(USARTx,USART_FLAG_TXE) == RESET){}
USART_SendData(USARTx, c);
while(USART_GetFlagStatus(USARTx,USART_FLAG_TC) == RESET){}
} */
//uint32_t flash_read(uint32_t address) {
// return (*(__IO uint32_t*) address);
// }
//----------
//
//----------
void EXTI_NVIC_Init ()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//----------
//
//----------
void EXTI0_IRQHandler()
{
EXTI_ClearITPendingBit(EXTI_Line0);
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
//a++;
//----------
//
//----------
}
void Led(void)
{
if(a==1) {
while((b<10000)&(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==1))
{
b++;
}
if(b==10000)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
}
}
if (a>1) {
a=0;
while((b<10000)&(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==1)) {
b++;
}
if(b==10000)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);
}
}
}
//----------
//
//----------
int main(void)
{
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000);
Init_led();
EXTI_NVIC_Init();
USART1_Init();
GPIO_SetBits(GPIOA, GPIO_Pin_1);
__enable_irq();
while(1)
{
//Led();
}
}
Вт окт 23, 2018 13:45:38
Вт окт 23, 2018 18:00:30
jump_app (0x80004000);
void jump_app( uint32_t address ) {
__asm ("LDR SP, [R0]\n"); // Load new stack pointer address
__asm ("LDR PC, [R0, #4]\n"); //Load new program counter address;
};
uint32_t i;
i = (uint32_t)(&main); // Получаем адрес main()
SCB->VTOR = (i & 0xFF030000);
Ср окт 24, 2018 09:11:51
Ср окт 24, 2018 12:43:09
Ср окт 24, 2018 14:41:32
Ср окт 24, 2018 18:58:46
void jump_app( uint32_t address ) {
__asm ("LDR msp, [R0]\n"); // Load new stack pointer address
__asm ("LDR R15, [R0, #4]\n"); //Load new program counter address;
// Либо "r15" (в нижнем регистре), если так же не будет дефайна
// Можно так же выполнить
__asm ("BX [R0, #4]\n"); // Аналогичный переход на адрес инструкцией перехода
// Не уверен, что так можно делать
};
Ср окт 24, 2018 20:53:44
Чт окт 25, 2018 10:26:09
В настройках проекта нужный адрес выставил в Target и Linker.
Достаточно ли этих строчек для переноса или нужно что то еще?
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
#endif
Пт окт 26, 2018 08:53:07
#ifdef __GNUC__
extern void *__vtor;
SCB->VTOR = (uint32_t)&__vtor;
#endif
#ifdef __ICCARM__
#pragma section = ".intvec"
SCB->VTOR = (uint32_t) __section_begin(".intvec");
#endif
Пт окт 26, 2018 09:45:02
Пн окт 29, 2018 09:20:09
#define FLASH_DISK_START_ADDRESS 0x08002800 /* Flash start address */
void GoToUserApp(void){
u32 appJumpAddress;
void (*GoToApp)(void);
appJumpAddress = *((volatile u32*)(FLASH_DISK_START_ADDRESS + 4));
GoToApp = (void (*)(void))appJumpAddress;
__disable_irq();
SCB->VTOR = FLASH_DISK_START_ADDRESS;
__enable_irq();
__set_MSP(*((volatile u32*) FLASH_DISK_START_ADDRESS)); //stack pointer (to RAM) for USER app in this address
GoToApp();
}
Пн окт 29, 2018 10:04:50
Пн окт 29, 2018 10:10:12
uint32_t i;
i = (uint32_t)(&main); // Получаем адрес main()
SCB->VTOR = (i & 0xFF030000);
extern uint32_t __Vectors;
SCB->VTOR = (uint32_t) &__Vectors;