Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate main.c @ 3:74e9b3baac1e
Jumbo commit to make things work.
Note I have t
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sun, 01 Jan 2012 11:01:13 +1030 |
parents | 274e01fa5a4c |
children | 2c87e30c982d |
rev | line source |
---|---|
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 #include <ctype.h> |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
2 #include <malloc.h> |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 #include <stdio.h> |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 #include <stdint.h> |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
5 #include <time.h> |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
6 #include <string.h> |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
7 #include <sys/time.h> |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
8 #include <stdlib.h> |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
9 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 #include "stm32f10x.h" |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
11 #include "lcd.h" |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 #include "main.h" |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 #include "comm.h" |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
15 typedef struct { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
16 char buf[40]; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
17 volatile uint8_t state; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
18 uint8_t len; |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
19 } consbuf_t; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 void Setup_HW(void); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 void NVIC_Configuration(void); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
24 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
25 /* Called every 1 / TICK_FREQ */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
26 #define TICK_FREQ 10000 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 RAMFUNC void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 SysTick_Handler(void) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
29 static uint32_t tick = 0; |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
30 static int led = 0; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
31 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 tick++; |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
33 if (tick % 10000 == 0) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
34 led = !led; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
35 if (led) |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
36 GPIO_SetBits(GPIOB, GPIO_Pin_5); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
37 else |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
38 GPIO_ResetBits(GPIOB, GPIO_Pin_5); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
39 } |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
40 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
43 consbuf_t cmd; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
44 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 RAMFUNC void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 USART1_IRQHandler(void) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
47 char c; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
48 int i; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
50 /* Recieved data */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
51 while (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
52 c = USART_ReceiveData(USART1); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
53 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
54 /* End of line? */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
55 if (c == '\n' || c == '\r') { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
56 cmd.buf[cmd.state] = '\0'; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
57 fputs("\r\n", stdout); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
58 cmd.len = cmd.state; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
59 cmd.state = 255; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
60 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
61 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
62 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
63 /* Ctrl-w / Ctrl-u */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
64 if (c == 0x17 || c == 0x15) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
65 for (i = 0; i < cmd.state; i++) |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
66 fputs("\010\040\010", stdout); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
67 cmd.state = 0; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
68 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
69 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
70 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
71 /* Backspace/delete */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
72 if (c == 0x08 || c == 0x7f) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
73 if (cmd.state > 0) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
74 cmd.state--; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
75 fputs("\010\040\010", stdout); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
76 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
77 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
78 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
79 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
80 /* Anything unprintable just ignore it */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
81 if (!isprint(c)) |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
82 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
83 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
84 cmd.buf[cmd.state] = tolower(c); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
85 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
86 /* Echo back to the user */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
87 comm_put(cmd.buf[cmd.state]); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
88 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
89 cmd.state++; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
90 /* Over flow? */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
91 if (cmd.state == ((sizeof(cmd.buf) / sizeof(cmd.buf[0])) - 1)) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
92 fputs("\r\nLine too long", stdout); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
93 cmd.state = 0; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
94 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
95 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
96 } |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
97 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
98 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
99 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
100 int |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
101 main(void) { |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
102 char buf[40]; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
103 struct tm nowtm; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
104 time_t now; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
105 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
106 cmd.state = cmd.len = 0; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
107 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
108 /* Setup USART etc */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
109 Setup_HW(); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
110 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
111 /* NVIC configuration */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
112 NVIC_Configuration(); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
113 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
114 /* Setup SysTick Timer rate, also enables Systick and Systick-Interrupt */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
115 if (SysTick_Config(SystemCoreClock / TICK_FREQ)) { |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
116 /* Capture error */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
117 comm_puts("Can't setup SysTick\r\n"); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
118 while (1) |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
119 ; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
120 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
121 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
122 /* Init LCD interface */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
123 LCD_init(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
124 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
125 /* Set stdout to unbuffered */ |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
126 setvbuf(stdout, NULL, _IONBF, 0); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
127 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
128 /* Say hello */ |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
129 fputs("\r\nHello world\r\n", stdout); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
130 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
131 #define Bank1_LCD_D ((uint32_t)0x60020000) //disp Data ADDR |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
132 #define Bank1_LCD_C ((uint32_t)0x60000000) //disp Reg ADDR |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
133 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
134 while (1) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
135 fputs("> ", stdout); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
136 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
137 while (cmd.state != 255) |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
138 ; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
139 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
140 if (cmd.len > 0) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
141 if (!strncmp("gc", cmd.buf, 2)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
142 now = time(NULL); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
143 gmtime_r(&now, &nowtm); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
144 strftime(buf, sizeof(buf) - 1, "Time is %Y/%m/%d %H:%M:%S UTC", &nowtm); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
145 printf("Time is %s (%d)\r\n", buf, (int)now); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
146 } else if (!strncmp("sc ", cmd.buf, 3)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
147 struct timeval tv; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
148 tv.tv_sec = atoi(cmd.buf + 3); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
149 tv.tv_usec = 0; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
150 settimeofday(&tv, NULL); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
151 } else if (!strncmp("lcd", cmd.buf, 3)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
152 *(__IO uint16_t *) (Bank1_LCD_C) = 0x00; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
153 printf("LCD ID = %hx\r\n", *(__IO uint16_t *) (Bank1_LCD_D)); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
154 } else if (!strncmp("read", cmd.buf, 4)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
155 printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
156 } else if (!strncmp("zz", cmd.buf, 2)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
157 NVIC_SystemReset(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
158 } else { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
159 printf("Unknown command\r\n"); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
160 } |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
161 } |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
162 cmd.state = 0; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
163 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
164 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
165 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
166 /* Setup hardware (USART etc) */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
167 void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
168 Setup_HW(void) { |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
169 GPIO_InitTypeDef GPIO_InitStructure; |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
170 USART_InitTypeDef USART_InitStructure; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
171 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
172 /* RTC stuff */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
173 /* Enable PWR and BKP clocks */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
174 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
175 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
176 /* Allow access to BKP Domain */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
177 PWR_BackupAccessCmd(ENABLE); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
178 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
179 /* Reset Backup Domain |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
180 * |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
181 * This resets the RTC etc back to 0 so probably only useful under user command |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
182 BKP_DeInit(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
183 */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
184 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
185 /* Enable LSE */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
186 RCC_LSEConfig(RCC_LSE_ON); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
187 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
188 /* Wait till LSE is ready */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
189 while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
190 ; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
191 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
192 /* Select LSE as RTC Clock Source */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
193 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
194 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
195 /* Enable RTC Clock */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
196 RCC_RTCCLKCmd(ENABLE); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
197 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
198 /* Wait for RTC registers synchronization */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
199 RTC_WaitForSynchro(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
200 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
201 /* Wait until last write operation on RTC registers has finished */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
202 RTC_WaitForLastTask(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
203 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
204 /* Wait until last write operation on RTC registers has finished */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
205 RTC_WaitForLastTask(); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
206 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
207 /* Set RTC prescaler: set RTC period to 1sec */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
208 RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
209 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
210 /* Wait until last write operation on RTC registers has finished */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
211 RTC_WaitForLastTask(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
212 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
213 /* Clock setup */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
214 /* Enable clocks we need */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
215 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
216 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
217 RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
218 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
219 /* Port configuration */ |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
220 /* Configure USART1 TX (PA.09) as alternate function push-pull */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
221 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
222 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
223 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
224 GPIO_Init(GPIOA, &GPIO_InitStructure); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
225 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
226 /* Configure USART1 RX (PA.10) as input floating */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
227 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
228 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
229 GPIO_Init(GPIOA, &GPIO_InitStructure); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
230 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
231 /* Configure PB5 as output push-pull */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
232 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
233 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
234 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
235 GPIO_Init(GPIOB, &GPIO_InitStructure); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
236 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
237 /* Configure PB15 as input pull-up push-pull */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
238 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
239 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
240 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
241 GPIO_Init(GPIOB, &GPIO_InitStructure); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
242 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
243 /* USART configuration */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
244 /* USART1 - 115200 8n1, no flow control TX & RX enabled */ |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
245 USART_InitStructure.USART_BaudRate = 115200; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
246 USART_InitStructure.USART_WordLength = USART_WordLength_8b; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
247 USART_InitStructure.USART_StopBits = USART_StopBits_1; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
248 USART_InitStructure.USART_Parity = USART_Parity_No; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
249 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
250 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
251 USART_Init(USART1, &USART_InitStructure); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
252 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
253 /* Enable interrupts on receive data */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
254 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
255 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
256 /* Enable USART */ |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
257 USART_Cmd(USART1, ENABLE); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
258 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
259 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
260 /* Configure interrupt controller */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
261 #ifdef VECT_TAB_RAM |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
262 /* vector-offset (TBLOFF) from bottom of SRAM. defined in linker script */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
263 extern uint32_t _isr_vectorsram_offs; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
264 #else |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
265 extern uint32_t _isr_vectorsflash_offs; |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
266 #endif |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
267 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
268 void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
269 NVIC_Configuration(void) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
270 NVIC_InitTypeDef NVIC_InitStructure; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
271 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
272 #ifdef VECT_TAB_RAM |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
273 /* Set the Vector Table base location at 0x20000000+_isr_vectorsram_offs */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
274 NVIC_SetVectorTable(NVIC_VectTab_RAM, (uint32_t)&_isr_vectorsram_offs); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
275 #else |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
276 /* Set the Vector Table base location at 0x08000000+_isr_vectorsflash_offs */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
277 NVIC_SetVectorTable(NVIC_VectTab_FLASH, (uint32_t)&_isr_vectorsflash_offs); |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
278 #endif |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
279 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
280 /* Enable the USART1 Interrupt */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
281 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
282 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
283 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
284 NVIC_Init(&NVIC_InitStructure); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
285 } |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
286 |