Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate hw.c @ 88:5fc6a25f40ef
Disable LCD init code since this board doesn't have it.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 13 Mar 2015 11:36:41 +1030 |
parents | 345a42f6151b |
children |
rev | line source |
---|---|
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 #include <stdint.h> |
10
0b75cff7c570
Add _usleep16 - sleeps for cnt microseconds.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
2 #include <stdio.h> |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 #include "stm32f10x.h" |
13 | 4 |
5 #include "1wire.h" | |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 #include "lcd.h" |
30
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
27
diff
changeset
|
7 #include "rtc.h" |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 |
18 | 9 #define I2C_TIMEOUT 10000 |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 static void hw_port_cfg(void); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 |
13 | 12 void |
13 hw_init(void) { | |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 hw_port_cfg(); |
88
5fc6a25f40ef
Disable LCD init code since this board doesn't have it.
Daniel O'Connor <darius@dons.net.au>
parents:
86
diff
changeset
|
15 #if 0 |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 lcd_init(); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 lcd_setpwm(1000); |
88
5fc6a25f40ef
Disable LCD init code since this board doesn't have it.
Daniel O'Connor <darius@dons.net.au>
parents:
86
diff
changeset
|
18 #endif |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 } |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 static void |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 hw_port_cfg(void) { |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 FSMC_NORSRAMTimingInitTypeDef p; |
18 | 25 GPIO_InitTypeDef GPIO_InitStructure; |
26 I2C_InitTypeDef I2C_InitStructure; | |
27 SPI_InitTypeDef SPI_InitStructure; | |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
18 | 29 USART_InitTypeDef USART_InitStructure; |
30 | |
31 /* Enable clocks */ | |
62
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
32 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP | |
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
33 RCC_APB1Periph_TIM4 | RCC_APB1Periph_I2C1, |
18 | 34 ENABLE); |
35 | |
62
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
36 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | |
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
37 RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOB | |
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
38 RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | |
18 | 39 RCC_APB2Periph_GPIOE | RCC_APB2Periph_SPI1, ENABLE); |
40 | |
62
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
41 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC | RCC_AHBPeriph_CRC | |
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
42 RCC_AHBPeriph_SDIO | RCC_AHBPeriph_DMA2, ENABLE); |
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
43 |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 /* Allow access to BKP Domain */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 PWR_BackupAccessCmd(ENABLE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 /* Reset Backup Domain |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 * |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 * This resets the RTC etc back to 0 so probably only useful under user command |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 BKP_DeInit(); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 /* Enable Low Speed External clock */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 RCC_LSEConfig(RCC_LSE_ON); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 /* Wait till LSE is ready */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 ; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 /* Select LSE as RTC Clock Source */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 /* Enable RTC Clock */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
65 RCC_RTCCLKCmd(ENABLE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
66 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
67 /* Wait for RTC registers synchronization */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
68 RTC_WaitForSynchro(); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
69 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
70 /* Wait until last write operation on RTC registers has finished */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
71 RTC_WaitForLastTask(); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
72 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
73 /* Wait until last write operation on RTC registers has finished */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
74 RTC_WaitForLastTask(); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
75 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
76 /* Set RTC prescaler: set RTC period to 1sec */ |
30
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
27
diff
changeset
|
77 RTC_SetPrescaler(RTC_PRESCALE); |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
78 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
79 /* Wait until last write operation on RTC registers has finished */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
80 RTC_WaitForLastTask(); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
81 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
82 /* Port configuration */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
83 /* Configure USART1 TX (PA.09) as alternate function push-pull */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
84 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
85 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
86 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
87 GPIO_Init(GPIOA, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
88 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
89 /* Configure USART1 RX (PA.10) as input floating */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
90 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
91 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
92 GPIO_Init(GPIOA, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
93 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
94 /* Configure PB5 as output push-pull for LED */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
95 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
96 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
97 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
98 GPIO_Init(GPIOB, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
99 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
100 /* Configure PB15 as input pull-up push-pull for push button */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
101 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
102 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
103 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
104 GPIO_Init(GPIOB, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
105 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
106 /* USART configuration */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
107 /* USART1 - 115200 8n1, no flow control TX & RX enabled */ |
86
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
108 USART_InitStructure.USART_BaudRate = 38400; |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
109 USART_InitStructure.USART_WordLength = USART_WordLength_8b; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
110 USART_InitStructure.USART_StopBits = USART_StopBits_1; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
111 USART_InitStructure.USART_Parity = USART_Parity_No; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
112 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
113 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
114 USART_Init(USART1, &USART_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
115 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
116 /* Enable interrupts on receive data */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
117 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
118 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
119 /* Enable USART */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
120 USART_Cmd(USART1, ENABLE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
121 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
122 /* Enable FSMC clock */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
123 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
124 /* Configures LCD Control lines (FSMC Pins) in alternate function Push-Pull mode. |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
125 * |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
126 * PD0(D2), PD1(D3), PD4(NOE), PD5(NWE), PD7(NE1/CS), PD8(D13), PD9(D14), |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
127 * PD10(D15), PD11(A16/RS) PD14(D0), PD15(D1) |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
128 */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
129 GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
130 GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
131 GPIO_Pin_14 | GPIO_Pin_15); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
132 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
133 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
134 GPIO_Init(GPIOD, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
135 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
136 /* PE7(D4), PE8(D5), PE9(D6), PE10(D7), PE11(D8), PE12(D9), PE13(D10), |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
137 * PE14(D11), PE15(D12) |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
138 */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
139 GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
140 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
141 GPIO_Pin_15); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
142 GPIO_Init(GPIOE, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
143 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
144 /* Configure backlight control (PD13/FSMC_A18 remapped to TIM4_CH2) */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
145 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
146 /* Enable timer function |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
147 * Note source clock is SYSCLK / 2 = 36MHz |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
148 */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
149 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
150 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
62
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
151 // XXX: PWM not working |
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
152 //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
153 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
154 GPIO_Init(GPIOD, &GPIO_InitStructure); |
62
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
155 GPIO_SetBits(GPIOD, GPIO_Pin_13); |
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
156 |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
157 /* Remap TIM4_CH2 to PD13 */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
158 GPIO_PinRemapConfig(GPIO_Remap_TIM4, ENABLE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
159 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
160 /* Reset TIM4 */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
161 TIM_DeInit(TIM4); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
162 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
163 /* Time Base configuration */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
164 TIM_TimeBaseStructure.TIM_Period = 999; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
165 TIM_TimeBaseStructure.TIM_Prescaler = 0; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
166 TIM_TimeBaseStructure.TIM_ClockDivision = 0; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
167 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
168 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
169 TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
170 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
171 /* Enable timer */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
172 TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
173 TIM_ARRPreloadConfig(TIM4, ENABLE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
174 TIM_Cmd(TIM4, ENABLE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
175 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
176 /* Configure reset pin (PE1) as GPIO out PP */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
177 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
178 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
179 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
180 GPIO_Init(GPIOE, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
181 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
182 /* Configures the Parallel interface (FSMC) for LCD (Parallel mode) */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
183 /* Timing configuration */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
184 p.FSMC_AddressSetupTime = 5; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
185 p.FSMC_AddressHoldTime = 5; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
186 p.FSMC_DataSetupTime = 5; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
187 p.FSMC_BusTurnAroundDuration = 0; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
188 p.FSMC_CLKDivision = 0; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
189 p.FSMC_DataLatency = 0; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
190 p.FSMC_AccessMode = FSMC_AccessMode_A; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
191 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
192 /* FSMC_Bank1_NORSRAM1 configured as follows: |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
193 - Data/Address MUX = Disable |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
194 - Memory Type = SRAM |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
195 - Data Width = 16bit |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
196 - Write Operation = Enable |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
197 - Extended Mode = Disable |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
198 - Asynchronous Wait = Disable */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
199 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
200 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
201 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
202 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
203 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
204 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
205 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
206 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
207 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
208 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
209 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
210 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
211 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
212 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
213 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
214 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
215 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
216 /* Enable FSMC_Bank1_NORSRAM1 */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
217 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
218 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
219 /* Configure touch screen controller |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
220 * |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
221 * Connected to SPI1 which is shared with the AT45DB161D. |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
222 * |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
223 * The touch screen is selected with PB7. |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
224 * The flash chip is selected with PA4. |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
225 */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
226 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
227 /* Configure MOSI, MISO and SCLK as alternate function PP */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
228 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
229 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
230 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
231 GPIO_Init(GPIOA, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
232 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
233 /* Configure flash chip select pin (PA4) as GPIO out PP */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
234 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
235 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
236 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
237 GPIO_Init(GPIOA, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
238 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
239 /* Configure touch chip select pin (PB7) as GPIO out PP */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
240 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
241 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
242 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
243 GPIO_Init(GPIOB, &GPIO_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
244 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
245 /* De-select touch & flash */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
246 GPIO_SetBits(GPIOA, GPIO_Pin_4); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
247 GPIO_SetBits(GPIOB, GPIO_Pin_7); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
248 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
249 /* SPI1 Config */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
250 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
251 SPI_InitStructure.SPI_Mode = SPI_Mode_Master; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
252 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
253 SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
254 SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
255 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; |
24
1e2fa7396f98
Reduce prescaler to 2, the flash is capable of 25MHz reads (although
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
256 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
257 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
258 SPI_InitStructure.SPI_CRCPolynomial = 7; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
259 SPI_Init(SPI1, &SPI_InitStructure); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
260 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
261 /* SPI1 enable */ |
10
0b75cff7c570
Add _usleep16 - sleeps for cnt microseconds.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
262 SPI_Cmd(SPI1, ENABLE); |
0b75cff7c570
Add _usleep16 - sleeps for cnt microseconds.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
263 |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
30
diff
changeset
|
264 /* Setup GPIO for delay test (2) 1-wire (3) & temp ctrl (4/5) |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
30
diff
changeset
|
265 * PE2 -> 3 (on header) |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
30
diff
changeset
|
266 * PE3 -> 4 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
30
diff
changeset
|
267 * PE4 -> 5 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
30
diff
changeset
|
268 * PE5 -> 6 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
30
diff
changeset
|
269 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
30
diff
changeset
|
270 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5; |
32
188d5a8a7470
Readd code accidentally removed from last version, now the hot & cold
Daniel O'Connor <darius@dons.net.au>
parents:
31
diff
changeset
|
271 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
188d5a8a7470
Readd code accidentally removed from last version, now the hot & cold
Daniel O'Connor <darius@dons.net.au>
parents:
31
diff
changeset
|
272 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
188d5a8a7470
Readd code accidentally removed from last version, now the hot & cold
Daniel O'Connor <darius@dons.net.au>
parents:
31
diff
changeset
|
273 GPIO_Init(GPIOE, &GPIO_InitStructure); |
10
0b75cff7c570
Add _usleep16 - sleeps for cnt microseconds.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
274 |
86
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
275 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
276 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
277 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
278 GPIO_Init(GPIOC, &GPIO_InitStructure); |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
279 |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
280 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12; |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
281 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
282 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
283 GPIO_Init(GPIOA, &GPIO_InitStructure); |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
62
diff
changeset
|
284 |
41
2db4bb90cfca
Remove unused timer and (broken) I2C code.
Daniel O'Connor <darius@dons.net.au>
parents:
40
diff
changeset
|
285 /* Setup 1-wire bus */ |
13 | 286 OWInit(); |
10
0b75cff7c570
Add _usleep16 - sleeps for cnt microseconds.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
287 |
18 | 288 /* Setup I2C bus */ |
289 | |
290 /* Configure SCL/SDA pins */ | |
291 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; | |
292 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
293 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; | |
294 GPIO_Init(GPIOB, &GPIO_InitStructure); | |
295 | |
296 /* Reset I2C1 */ | |
297 I2C_DeInit(I2C1); | |
298 | |
299 /* Setup I2C1 */ | |
300 I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; | |
301 I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; | |
302 I2C_InitStructure.I2C_OwnAddress1 = 0x00; | |
303 I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; | |
304 I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; | |
305 I2C_InitStructure.I2C_ClockSpeed = 100000; | |
306 I2C_Init(I2C1, &I2C_InitStructure); | |
307 | |
308 /* Start I2C controller */ | |
309 I2C_Cmd(I2C1, ENABLE); | |
310 | |
41
2db4bb90cfca
Remove unused timer and (broken) I2C code.
Daniel O'Connor <darius@dons.net.au>
parents:
40
diff
changeset
|
311 /* Enable debug block for cycle counter |
2db4bb90cfca
Remove unused timer and (broken) I2C code.
Daniel O'Connor <darius@dons.net.au>
parents:
40
diff
changeset
|
312 * From http://forums.arm.com/index.php?/topic/13949-cycle-count-in-cortex-m3/ |
2db4bb90cfca
Remove unused timer and (broken) I2C code.
Daniel O'Connor <darius@dons.net.au>
parents:
40
diff
changeset
|
313 * via http://stackoverflow.com/questions/11530593/cycle-counter-on-arm-cortex-m4-or-m3/11530829#11530829 |
2db4bb90cfca
Remove unused timer and (broken) I2C code.
Daniel O'Connor <darius@dons.net.au>
parents:
40
diff
changeset
|
314 */ |
40
a38003b97de6
Use debug cycle counter to handle delays.
Daniel O'Connor <darius@dons.net.au>
parents:
32
diff
changeset
|
315 volatile uint32_t *DWT_CONTROL = (uint32_t *)0xe0001000; |
a38003b97de6
Use debug cycle counter to handle delays.
Daniel O'Connor <darius@dons.net.au>
parents:
32
diff
changeset
|
316 volatile uint32_t *SCB_DEMCR = (uint32_t *)0xe000edfc; |
a38003b97de6
Use debug cycle counter to handle delays.
Daniel O'Connor <darius@dons.net.au>
parents:
32
diff
changeset
|
317 |
a38003b97de6
Use debug cycle counter to handle delays.
Daniel O'Connor <darius@dons.net.au>
parents:
32
diff
changeset
|
318 *SCB_DEMCR = *SCB_DEMCR | 0x01000000; |
a38003b97de6
Use debug cycle counter to handle delays.
Daniel O'Connor <darius@dons.net.au>
parents:
32
diff
changeset
|
319 *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter |
49
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
320 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
321 /* Setup SDIO |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
322 * See SD_LowLevelInit from libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.c |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
323 */ |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
324 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
325 /* Configure SDIO pins for AF |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
326 PC8 -> SD0 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
327 PC9 -> SD1 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
328 PC10 -> SD2 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
329 PC11 -> SD3 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
330 PC12 -> SCK |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
331 */ |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
332 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
333 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
334 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
335 GPIO_Init(GPIOC, &GPIO_InitStructure); |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
336 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
337 /* Configure PD2 -> CMD SDIO pin for AF */ |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
41
diff
changeset
|
338 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
62
bb52e6dad784
The LCD works better when the GPIO clocks are enabled before frobbing them.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
339 GPIO_Init(GPIOD, &GPIO_InitStructure); |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
340 } |