forked from avislab/STM32F103
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
58 lines (48 loc) · 1.25 KB
/
main.c
File metadata and controls
58 lines (48 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_rcc.h"
#include "misc.h"
#include "usb_lib.h"
#include "hw_config.h"
#include "usb_pwr.h"
#include "mass_mal.h"
#define BUTTON_PIN GPIO_Pin_1
void GoToUserApp(void)
{
u32 appJumpAddress;
void (*GoToApp)(void);
appJumpAddress = *((volatile u32*)(FLASH_DISK_START_ADDRESS + 4));
GoToApp = (void (*)(void))appJumpAddress;
SCB->VTOR = FLASH_DISK_START_ADDRESS;
__set_MSP(*((volatile u32*) FLASH_DISK_START_ADDRESS)); //stack pointer (to RAM) for USER app in this address
GoToApp();
}
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Initialize Button input PB */
// Enable PORTB Clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure the GPIO_BUTTON pin */
GPIO_InitStructure.GPIO_Pin = BUTTON_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
if (GPIO_ReadInputDataBit(GPIOB, BUTTON_PIN) == Bit_SET) {
// Go To Application
GPIO_DeInit(GPIOB);
GoToUserApp();
}
else {
// Initialize Mass Storage
Set_System();
Set_USBClock();
USB_Interrupts_Config();
USB_Init();
while (bDeviceState != CONFIGURED);
while (1)
{
}
}
}