annotate main.c @ 2:274e01fa5a4c

- Do console IO with RX IRQs. - Init tick counter (unused anyway). - Handle C-u and C-w. - Rejig NVIC setup for less duplication.
author Daniel O'Connor <darius@dons.net.au>
date Sat, 08 Oct 2011 20:35:34 +1030
parents c59513fd84fb
children 74e9b3baac1e
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>
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 #include <stdio.h>
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 #include <stdint.h>
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 #include "stm32f10x.h"
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 #include "main.h"
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 #include "comm.h"
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
8 typedef volatile struct {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
9 char buf[40];
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
10 uint8_t state;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
11 uint8_t len;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
12 } consbuf_t;
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 void Setup_HW(void);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 void NVIC_Configuration(void);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 /* Called every millisecond */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 RAMFUNC void
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 SysTick_Handler(void) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
20 static uint32_t tick = 0;
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 tick++;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 }
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
25 consbuf_t cmd;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
26
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 USART1_IRQHandler(void) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
29 char c;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
30 int i;
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
32 /* Recieved data */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
33 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
34 c = USART_ReceiveData(USART1);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
35
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
36 /* End of line? */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
37 if (c == '\n' || c == '\r') {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
38 cmd.buf[cmd.state] = '\0';
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
39 fputs("\r\n", stdout);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
40 cmd.len = cmd.state;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
41 cmd.state = 255;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
42 continue;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
43 }
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
44
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
45 /* Ctrl-w / Ctrl-u */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
46 if (c == 0x17 || c == 0x15) {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
47 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
48 fputs("\010\040\010", stdout);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
49 cmd.state = 0;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
50 continue;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
51 }
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
52
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
53 /* Backspace/delete */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
54 if (c == 0x08 || c == 0x7f) {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
55 if (cmd.state > 0) {
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
56 cmd.state--;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
57 fputs("\010\040\010", stdout);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
58 }
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
59 continue;
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
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
62 /* Anything unprintable just ignore it */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
63 if (!isprint(c))
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
64 continue;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
65
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
66 cmd.buf[cmd.state] = tolower(c);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
67
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
68 /* Echo back to the user */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
69 comm_put(cmd.buf[cmd.state]);
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 cmd.state++;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
72 /* Over flow? */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
73 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
74 fputs("\r\nLine too long", stdout);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
75 cmd.state = 0;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
76 continue;
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 }
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 }
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 int
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 main(void) {
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 cmd.state = cmd.len = 0;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 /* Setup USART etc */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 Setup_HW();
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 /* NVIC configuration */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 NVIC_Configuration();
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 /* Setup SysTick Timer for 1 millisecond interrupts, also enables Systick and Systick-Interrupt */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 if (SysTick_Config(SystemCoreClock / 1000)) {
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 /* Capture error */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 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
96 while (1)
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
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
100 setvbuf(stdout, NULL, _IONBF, 0);
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
101
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 /* Say hello */
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
103 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
104
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 while (1) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
106 fputs("> ", stdout);
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
108 while (cmd.state != 255)
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
109 ;
0
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 if (cmd.len > 0)
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 printf("Got command '%s'\r\n", cmd.buf);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 cmd.state = 0;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 }
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 }
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 /* Setup hardware (USART etc) */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 void
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 Setup_HW(void) {
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 GPIO_InitTypeDef GPIO_InitStructure;
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
121 USART_InitTypeDef USART_InitStructure;
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 /* Enable USART1, GPIOA, GPIOD and AFIO clocks */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOD
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 | RCC_APB2Periph_AFIO, ENABLE);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 /* Enable USART2 clock */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 /* DMA1 clock enable */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 /* 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
133 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 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
136 GPIO_Init(GPIOA, &GPIO_InitStructure);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 /* 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
139 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 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
141 GPIO_Init(GPIOA, &GPIO_InitStructure);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143 /* Init UART1 - 115200 8n1, no flow control TX & RX enabled */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 USART_InitStructure.USART_BaudRate = 115200;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 USART_InitStructure.USART_WordLength = USART_WordLength_8b;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 USART_InitStructure.USART_StopBits = USART_StopBits_1;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147 USART_InitStructure.USART_Parity = USART_Parity_No;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 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
150
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
151 /* Configure USART1 */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 USART_Init(USART1, &USART_InitStructure);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
154 /* Enable interrupts on receive data */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
155 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
156
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 /* Enable the USART1 */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158 USART_Cmd(USART1, ENABLE);
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159 }
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 /* Configure interrupt controller */
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162 #ifdef VECT_TAB_RAM
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163 /* 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
164 extern uint32_t _isr_vectorsram_offs;
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165 #else
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166 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
167 #endif
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
168
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169 void
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
170 NVIC_Configuration(void) {
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
171 NVIC_InitTypeDef NVIC_InitStructure;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
172
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
173 #ifdef VECT_TAB_RAM
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
174 /* 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
175 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
176 #else
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
177 /* 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
178 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
179 #endif
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
180
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
181 /* Enable the USART1 Interrupt */
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
182 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
183 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
184 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
185 NVIC_Init(&NVIC_InitStructure);
0
c59513fd84fb Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186 }
2
274e01fa5a4c - Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
187