annotate main.c @ 21:bd8e2cf04034

- Add flash erase, write & read commands (needs more work). - Split the buffer into argv/argc to make sub commands simpler.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 15 Nov 2012 23:40:51 +1030
parents d078651f5353
children 198ac9d95770
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
8
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
11
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
12 #include "1wire.h"
8
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
13 #include "comm.h"
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
14 #include "delay.h"
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
15 #include "flash.h"
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
16 #include "hw.h"
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
17 #include "lcd.h"
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 #include "main.h"
8
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
19 #include "touch.h"
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
21 #define MAXARGS 10
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
22 #define LINEBUF 40
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
23 typedef struct {
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
24 char *buf;
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
25 volatile uint8_t state;
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
26 uint8_t len;
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
27 } consbuf_t;
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 void NVIC_Configuration(void);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
31
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
32 /* Called every 1 / TICK_FREQ */
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
33 #define TICK_FREQ 10000
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 RAMFUNC void
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 SysTick_Handler(void) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
36 static uint32_t tick = 0;
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
37 static int led = 0;
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
38
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 tick++;
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
40 if (tick % 10000 == 0) {
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
41 led = !led;
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
42 if (led)
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
43 GPIO_SetBits(GPIOB, GPIO_Pin_5);
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
44 else
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
45 GPIO_ResetBits(GPIOB, GPIO_Pin_5);
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
46 }
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
47
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 }
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 consbuf_t cmd;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
51
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 RAMFUNC void
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 USART1_IRQHandler(void) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
54 char c;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
55 int i;
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
57 /* Recieved data */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
58 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
59 c = USART_ReceiveData(USART1);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
60
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
61 /* End of line? */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
62 if (c == '\n' || c == '\r') {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
63 cmd.buf[cmd.state] = '\0';
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
64 fputs("\r\n", stdout);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
65 cmd.len = cmd.state;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
66 cmd.state = 255;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
67 continue;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
68 }
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 /* Ctrl-w / Ctrl-u */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
71 if (c == 0x17 || c == 0x15) {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
72 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
73 fputs("\010\040\010", stdout);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
74 cmd.state = 0;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
75 continue;
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
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
78 /* Backspace/delete */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
79 if (c == 0x08 || c == 0x7f) {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
80 if (cmd.state > 0) {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
81 cmd.state--;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
82 fputs("\010\040\010", stdout);
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 continue;
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
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
87 /* Anything unprintable just ignore it */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
88 if (!isprint(c))
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
89 continue;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
90
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
91 cmd.buf[cmd.state] = tolower(c);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
92
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
93 /* Echo back to the user */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
94 comm_put(cmd.buf[cmd.state]);
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 cmd.state++;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
97 /* Over flow? */
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
98 if (cmd.state == LINEBUF - 1) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
99 fputs("\r\nLine too long", stdout);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
100 cmd.state = 0;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
101 continue;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
102 }
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
103 }
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 }
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 int
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 main(void) {
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
108 char buf[40], *argv[MAXARGS], **ap, *tmp;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
109 int argc;
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
110 struct tm nowtm;
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
111 time_t now;
12
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
112 uint16_t x, y, x1, y1, z1, z2, r, c, rx, ry;
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
113 float t, t2;
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
114
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 cmd.state = cmd.len = 0;
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
116 cmd.buf = malloc(LINEBUF);
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117
8
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
118 /* Init hardware - configure IO ports and external peripherals */
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
119 hw_init();
0
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 /* NVIC configuration */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 NVIC_Configuration();
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
124 /* 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
125 if (SysTick_Config(SystemCoreClock / TICK_FREQ)) {
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 /* Capture error */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 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
128 while (1)
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 ;
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
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
132 /* Set stdout to unbuffered */
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
133 setvbuf(stdout, NULL, _IONBF, 0);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
134
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 /* Say hello */
7
9404b9869c27 Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents: 5
diff changeset
136 fputs("\r\n\r\n\r\nHello world\r\n", stdout);
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137
12
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
138 lcd_stripes();
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
139
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
140 lcd_circle(20, 20, 20, 1, LCD_RED); /* Bottom left */
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
141 lcd_circle(300, 220, 20, 1, LCD_WHITE); /* Top right */
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
142 lcd_circle(20, 220, 20, 1, LCD_BLUE); /* Top left */
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
143 lcd_circle(300, 20, 20, 1, LCD_GREEN); /* Bottom right */
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
144
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
145 lcd_line(20, 20, 20, 220, LCD_BLACK);
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
146 lcd_line(20, 220, 300, 220, LCD_BLACK);
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
147 lcd_line(300, 220, 300, 20, LCD_BLACK);
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
148 lcd_line(300, 20, 20, 20, LCD_BLACK);
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
149
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
150 lcd_ellipse(160, 120, 50, 30, 1, LCD_WHITE);
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
151 lcd_ellipse(160, 120, 30, 50, 1, LCD_WHITE);
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
152
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 while (1) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
154 fputs("> ", stdout);
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
156 while (cmd.state != 255)
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
157 ;
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
159 if (cmd.len < 1)
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
160 goto out;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
161
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
162 /* Split command string on space/tab boundaries into argv/argc */
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
163 argc = 0;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
164 tmp = cmd.buf;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
165 for (ap = argv; (*ap = strsep(&cmd.buf, " \t")) != NULL;) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
166 if (**ap != '\0') {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
167 argc++;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
168 if (++ap >= &argv[MAXARGS])
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
169 break;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
170 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
171 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
172 /* Reset the buffer pointer after strsep() has mangled it */
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
173 cmd.buf = tmp;
12
093bc0c3b1cc Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
174
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
175 if (!strcmp("gc", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
176 now = time(NULL);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
177 gmtime_r(&now, &nowtm);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
178 strftime(buf, sizeof(buf) - 1, "%Y/%m/%d %H:%M:%S UTC", &nowtm);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
179 printf("Time is %s (%d)\r\n", buf, (int)now);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
180 } else if (!strcmp("sc", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
181 struct timeval tv;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
182 if (argc != 2) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
183 fputs("Incorrect number of arguments\r\n", stdout);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
184 goto out;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
185 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
186
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
187 tv.tv_sec = atoi(argv[1]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
188 tv.tv_usec = 0;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
189 settimeofday(&tv, NULL);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
190 } else if (!strcmp("read", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
191 printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15));
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
192 } else if (!strcmp("touch", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
193 for (int i = 0; i < 10; i++) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
194 tp_getcoords(&x, &y, &z1, &z2, &t, &t2);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
195 printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
196 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
197 } else if (!strcmp("fl", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
198 flashcmd(argv + 1, argc - 1);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
199 } else if (!strcmp("pwm", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
200 lcd_setpwm(atoi(argv[1]));
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
201 } else if (!strcmp("timing", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
202 fputs("Timing..\r\n", stdout);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
203 delay(10000);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
204 fputs("Done\r\n", stdout);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
205 } else if (!strcmp("circ", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
206 if (argc != 5) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
207 fputs("Unable to parse circ args\r\n", stdout);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
208 goto out;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
209 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
210 x = atoi(argv[1]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
211 y = atoi(argv[2]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
212 r = atoi(argv[3]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
213 c = lcd_parsecol(argv[4][0]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
214 lcd_circle(x, y, r, 0, c);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
215 } else if (!strncmp("ellip", cmd.buf, 6)) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
216 if (argc != 5) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
217 fputs("Unable to parse ellip args\r\n", stdout);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
218 goto out;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
219 }
16
db6011aa94d6 Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
220
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
221 x = atoi(argv[1]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
222 y = atoi(argv[2]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
223 rx = atoi(argv[3]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
224 ry = atoi(argv[4]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
225 c = lcd_parsecol(argv[5][0]);
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
226
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
227 lcd_ellipse(x, y, rx, ry, 0, c);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
228 } else if (!strncmp("line", cmd.buf, 5)) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
229 if (argc != 5) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
230 fputs("Unable to parse line args\r\n", stdout);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
231 goto out;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
232 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
233
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
234 x = atoi(argv[1]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
235 y = atoi(argv[2]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
236 x1 = atoi(argv[3]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
237 y1 = atoi(argv[4]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
238 c = lcd_parsecol(argv[5][0]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
239
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
240 lcd_line(x, y, x1, y1, c);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
241 } else if (!strcmp("delay", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
242 GPIO_InitTypeDef GPIO_InitStructure;
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
243
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
244 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
245 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
246 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
247 GPIO_Init(GPIOE, &GPIO_InitStructure);
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
248
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
249 for (x = 0; x < 100; x++) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
250 GPIO_SetBits(GPIOE, GPIO_Pin_2);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
251 delay(30);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
252 GPIO_ResetBits(GPIOE, GPIO_Pin_2);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
253 delay(60);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
254 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
255 } else if (!strcmp("rs", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
256 printf("Reset got %d\r\n", OWTouchReset());
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
257 } else if (!strcmp("sr", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
258 uint8_t ROM[8];
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
259 int8_t i;
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
260
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
261 memset(ROM, 0, 8);
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
262
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
263 i = OWFirst(ROM, 1, 0);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
264 do {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
265 switch (i) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
266 case OW_NOMODULES:
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
267 case OW_FOUND:
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
268 break;
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
269
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
270 case OW_BADWIRE:
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
271 case OW_NOPRESENCE:
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
272 case OW_BADCRC:
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
273 default:
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
274 printf("Err %d\r\n", i);
13
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
275 break;
96c345d304af Add 1wire code.
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
276 }
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
277
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
278 if (i != OW_FOUND)
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
279 break;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
280
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
281 for (i = 0; i < 8; i++)
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
282 printf("%02x%s", ROM[i], i == 7 ? "\r\n" : ":");
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
283
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
284 i = OWNext(ROM, 1, 0);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
285 } while (1);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
286 } else if (!strcmp("rb", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
287 printf("Read bit returned %d\r\n", OWReadBit());
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
288 } else if (!strcmp("wb", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
289 if (argc != 2) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
290 fputs("Incorrect number of arguments\r\n", stdout);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
291 goto out;
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
292 }
21
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
293
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
294 x = atoi(argv[1]);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
295 OWWriteBit(x);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
296 printf("Wrote %d\r\n", x);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
297 } else if (!strcmp("te", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
298 uint8_t ROM[8];
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
299 int16_t res;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
300
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
301 if (sscanf(argv[1], "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
302 &ROM[0], &ROM[1], &ROM[2], &ROM[3],
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
303 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
304 fputs("Unable to parse ROM ID\r\n", stdout);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
305 goto out;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
306 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
307
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
308 res = OWGetTemp(ROM);
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
309 switch (res) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
310 case OW_TEMP_WRONG_FAM:
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
311 printf("ROM specified isn't a temperature sensor\r\n");
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
312 break;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
313
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
314 case OW_TEMP_CRC_ERR:
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
315 printf("CRC mismatch\r\n");
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
316 break;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
317
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
318 case OW_TEMP_NO_ROM:
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
319 printf("No ROM found\r\n");
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
320 break;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
321
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
322 default:
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
323 printf("%hd.%02hd\r\n", GETWHOLE(res), GETFRAC(res));
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
324 break;
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
325 }
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
326 } else if (!strcmp("zz", argv[0])) {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
327 NVIC_SystemReset();
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
328 } else {
bd8e2cf04034 - Add flash erase, write & read commands (needs more work).
Daniel O'Connor <darius@dons.net.au>
parents: 19
diff changeset
329 printf("Unknown command\r\n");
3
74e9b3baac1e Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
330 }
8
58d76cf522ff Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
331 out:
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
332 cmd.state = 0;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
333 }
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
334 }
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
335
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
336 /* Configure interrupt controller */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
337 #ifdef VECT_TAB_RAM
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
338 /* 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
339 extern uint32_t _isr_vectorsram_offs;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
340 #else
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
341 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
342 #endif
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
343
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
344 void
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
345 NVIC_Configuration(void) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
346 NVIC_InitTypeDef NVIC_InitStructure;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
347
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
348 #ifdef VECT_TAB_RAM
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
349 /* 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
350 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
351 #else
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
352 /* 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
353 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
354 #endif
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
355
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
356 /* Enable the USART1 Interrupt */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
357 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
358 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
359 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
360 NVIC_Init(&NVIC_InitStructure);
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
361 }
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
362