Mercurial > ~darius > hgwebdir.cgi > stm32test
annotate main.c @ 5:efa2c22266e3
PWM control LED backlight.
Not sure why the AFIO clock needs to be on for this but not, say USART.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 06 Jan 2012 09:46:28 +1030 |
parents | 2c87e30c982d |
children | 9404b9869c27 |
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 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
131 while (1) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
132 fputs("> ", stdout); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
133 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
134 while (cmd.state != 255) |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
135 ; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
136 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
137 if (cmd.len > 0) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
138 if (!strncmp("gc", cmd.buf, 2)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
139 now = time(NULL); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
140 gmtime_r(&now, &nowtm); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
141 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
|
142 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
|
143 } 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
|
144 struct timeval tv; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
145 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
|
146 tv.tv_usec = 0; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
147 settimeofday(&tv, NULL); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
148 } else if (!strncmp("lcd", cmd.buf, 3)) { |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
149 printf("LCD ID = %hx\r\n", LCD_RD_Reg(0x00)); |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
150 } 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
|
151 printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
152 } else if (!strncmp("touch", cmd.buf, 5)) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
153 for (int i = 0; i < 10; i++) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
154 uint16_t x, y, z1, z2; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
155 float t, t2; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
156 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
157 x = TPRead(TP_READ_SEL(TP_CHAN_X, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
158 y = TPRead(TP_READ_SEL(TP_CHAN_Y, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
159 z1 = TPRead(TP_READ_SEL(TP_CHAN_Z1, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
160 z2 = TPRead(TP_READ_SEL(TP_CHAN_Z2, TP_MODE_12, TP_REF_DIFF, TP_PD_ON)); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
161 t = ((float)x / 4096.0) * (((float)z2 / (float)z1) - 1); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
162 t2 = (((float)x / 4096) * ((4096.0 / (float)z1) - 1)) - (1 - ((float)y / (float)4096.0)); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
163 printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
164 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
165 } else if (!strncmp("fl", cmd.buf, 2)) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
166 uint8_t status; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
167 char *flstattbl[] = { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
168 "BUSY", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
169 "WEL", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
170 "BP0", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
171 "BP1", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
172 "BP2", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
173 "BP3", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
174 "AAI", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
175 "BPL" |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
176 }; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
177 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
178 printf("Flash ID = 0x%04hx (expect 0xbf41)\r\n", FlashReadID()); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
179 status = FlashReadStatus(); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
180 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
181 fputs("Status = ", stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
182 for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
183 if (status & 1 << i) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
184 fputs(flstattbl[i], stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
185 fputs(" ", stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
186 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
187 printf("(0x%02x)\r\n", status); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
188 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
189 FlashWriteStatus(0x00); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
190 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
191 status = FlashReadStatus(); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
192 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
193 fputs("Status = ", stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
194 for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
195 if (status & 1 << i) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
196 fputs(flstattbl[i], stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
197 fputs(" ", stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
198 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
199 printf("(0x%02x)\r\n", status); |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
200 } else if (!strncmp("pwm ", cmd.buf, 4)) { |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
201 lcd_setpwm(atoi(cmd.buf + 4)); |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
202 } 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
|
203 NVIC_SystemReset(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
204 } else { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
205 printf("Unknown command\r\n"); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
206 } |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
207 } |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
208 cmd.state = 0; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
209 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
210 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
211 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
212 /* Setup hardware (USART etc) */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
213 void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
214 Setup_HW(void) { |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
215 GPIO_InitTypeDef GPIO_InitStructure; |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
216 USART_InitTypeDef USART_InitStructure; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
217 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
218 /* RTC stuff */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
219 /* Enable PWR and BKP clocks */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
220 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
|
221 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
222 /* Allow access to BKP Domain */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
223 PWR_BackupAccessCmd(ENABLE); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
224 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
225 /* Reset Backup Domain |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
226 * |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
227 * 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
|
228 BKP_DeInit(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
229 */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
230 |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
231 /* Enable Low Speed External clock */ |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
232 RCC_LSEConfig(RCC_LSE_ON); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
233 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
234 /* Wait till LSE is ready */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
235 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
|
236 ; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
237 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
238 /* Select LSE as RTC Clock Source */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
239 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
240 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
241 /* Enable RTC Clock */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
242 RCC_RTCCLKCmd(ENABLE); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
243 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
244 /* Wait for RTC registers synchronization */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
245 RTC_WaitForSynchro(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
246 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
247 /* 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
|
248 RTC_WaitForLastTask(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
249 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
250 /* 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
|
251 RTC_WaitForLastTask(); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
252 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
253 /* 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
|
254 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
|
255 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
256 /* 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
|
257 RTC_WaitForLastTask(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
258 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
259 /* Clock setup */ |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
260 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE); |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
261 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
262 /* Port configuration */ |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
263 /* 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
|
264 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
265 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
266 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
|
267 GPIO_Init(GPIOA, &GPIO_InitStructure); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
268 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
269 /* 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
|
270 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
271 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
|
272 GPIO_Init(GPIOA, &GPIO_InitStructure); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
273 |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
274 /* Enable GPIOB clock */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
275 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
276 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
277 /* Configure PB5 as output push-pull for LED */ |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 GPIO_Init(GPIOB, &GPIO_InitStructure); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
282 |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
283 /* Configure PB15 as input pull-up push-pull for push button */ |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 GPIO_Init(GPIOB, &GPIO_InitStructure); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
288 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
289 /* USART configuration */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
290 /* 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
|
291 USART_InitStructure.USART_BaudRate = 115200; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
292 USART_InitStructure.USART_WordLength = USART_WordLength_8b; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
293 USART_InitStructure.USART_StopBits = USART_StopBits_1; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
294 USART_InitStructure.USART_Parity = USART_Parity_No; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
295 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
296 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
|
297 USART_Init(USART1, &USART_InitStructure); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
298 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
299 /* Enable interrupts on receive data */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
300 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
|
301 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
302 /* Enable USART */ |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
303 USART_Cmd(USART1, ENABLE); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
304 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
305 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
306 /* Configure interrupt controller */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
307 #ifdef VECT_TAB_RAM |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
308 /* 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
|
309 extern uint32_t _isr_vectorsram_offs; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
310 #else |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
311 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
|
312 #endif |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
313 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
314 void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
315 NVIC_Configuration(void) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
316 NVIC_InitTypeDef NVIC_InitStructure; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
317 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
318 #ifdef VECT_TAB_RAM |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
319 /* 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
|
320 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
|
321 #else |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
322 /* 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
|
323 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
|
324 #endif |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
325 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
326 /* Enable the USART1 Interrupt */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
327 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
328 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
329 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
330 NVIC_Init(&NVIC_InitStructure); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
331 } |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
332 |