##// END OF EJS Templates
Fusion
jeandet -
r95:b5861d577019 merge dev_alexis
parent child
Show More
@@ -0,0 +1,21
1 TEMPLATE = lib
2
3 TARGET=bsp
4 CONFIG += bsp
5
6 BSP=Nano-particle
7
8 UCMODEL=stm32f4
9
10 SOURCES += bsp.c
11
12 HEADERS += bsp.h
13
14 LIBS+= -lgpio -luart -li2c -lspi -lpwm
15
16 BSPFILE = bsp.pri
17
18 OTHER_FILES += bsp.pri
19
20
21
@@ -0,0 +1,91
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2014, Kaveh Mohamadabadi
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Kaveh Mohamadabadi
20 -- Mail : kaveh.mohamadabadi@gmail.com
21 -------------------------------------------------------------------------------*/
22 #include "bsp.h"
23 #include <streamdevices.h>
24 #include <malloc.h>
25 #include <gpio.h>
26 #include <uart.h>
27 #include <stdio.h>
28 uint32_t OSC0 =12000000;
29 uint32_t INTOSC =16000000;
30 uint32_t RTCOSC =32768;
31 uint32_t currentCpuFreq=0;
32 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
33 gpio_t TickLed = LED1;
34
35 float VREF0 =(float)3.3;
36
37 int bsp_init()
38 {
39 int i=0;
40 for(i=0;i<32;i++)
41 {
42 __opnfiles__[i] = NULL;
43 }
44 bsp_GPIO_init();
45 bsp_uart_init();
46 printf("\r================================================================\n\r");
47 printf("================================================================\n\r");
48 printf(BSP);
49 printf(" initialised\n\r");
50 printf("================================================================\n\r");
51 return 1;
52 }
53
54 void bsp_GPIO_init()
55 {
56
57 }
58
59 void bsp_uart_init()
60 {
61 if(__opnfiles__[1]==NULL)
62 {
63 // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
64 // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,19200,PB10,PB11,-1,-1);
65 // uartmkstreamdev(uart,fd1);
66 // __opnfiles__[1] = fd1; //stdo
67 // __opnfiles__[0] = fd1; //stdi
68 }
69 else
70 {
71 // uartopenandconfig(2,uartparitynone | uart8bits | uartonestop,115200,PB10,PB11,-1,-1);
72 }
73 }
74
75 void bsp_spi_init()
76 {
77
78 }
79
80
81 void bsp_iic_init()
82 {
83
84 }
85
86
87
88
89
90
91
@@ -0,0 +1,68
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2014, Kaveh Mohamadabadi
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Kaveh Mohamadabadi
20 -- Mail : kaveh.mohamadabadi@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef BSP_H
23 #define BSP_H
24 #include <stm32f4xx.h>
25 #include <gpio.h>
26
27 #define __MAX_OPENED_FILES__ 32
28 #define __FS_ROOT_SIZE__ 32
29
30 #define LED1 PD12
31 #define LED2 PD13
32
33 extern float VREF0;
34
35 extern uint32_t OSC0;
36 extern uint32_t currentCpuFreq;
37
38
39
40 extern int bsp_init();
41
42 extern void bsp_GPIO_init();
43 extern void bsp_uart_init();
44 extern void bsp_iic_init();
45 extern void bsp_spi_init();
46
47
48
49 #endif
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@@ -0,0 +1,3
1 CPU=stm32f4xxxG
2 DEFINES+=BSP=\\\"Nano-particle\\\"
3 UCMODEL=stm32f4
@@ -0,0 +1,349
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2014, Kaveh Mohamadabadi
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Kaveh Mohamadabadi
20 -- Mail : kaveh.mohamadabadi@gmail.com
21 -------------------------------------------------------------------------------*/
22 /// \defgroup PWM
23 /*! \file pwm.h
24 \brief PWM api.
25
26 The pwm api gives you a standard way to drive any pwm pin on any processor.
27 With this api you will be able to open and configure your PWM module, define the
28 associated pins when applicable and set the duty cycle and frequency. Note that depending
29 on the target architecture you can have soft or hard PWM.
30
31 A simple example to configure and use PWM4_CH4 on STM32 discovery for example.
32 \code
33 // lets open PWM4_CH4
34 //config :
35 // -TIMER = TIMER4 (PWM4=TIMER4)
36 // -PWM channel = 4
37 // -PWM output = PD15
38 // -PWM frequency = 1kHz
39 // -PWM duty cycle = 40.5%
40 pwmopen(PWM4_CH4,PD15);
41 int error = pwmsetconfig(PWM4_CH4,1000,40.5);
42 //check that everything is ok
43 if(error!=-1) //=> no error
44 {
45 //to change duty cycle to 15% for example:
46 pwmsetdutycycle(PWM4_CH4,15.0);
47 //you can also change the frequency:
48 pwmsetfrequency(PWM4_CH4,455000);
49 }
50
51 \endcode
52 \ingroup PWM
53
54 */
55 #ifndef PWM_H
56 #define PWM_H
57
58 #include <stdint.h>
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 /**
63 * @brief PWM open function
64 *
65 * This function opens the given PWM, it should turn it ON iff needed and enable it.
66 * @param PWM The PWM module and channel PWM1_CH6 for example
67 * @return The 0 on success or -1 if it fails.
68 * @ingroup PWM
69 */
70 extern int pwmopen(int PWM,uint32_t pin);
71 extern int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle);
72 extern int pwmsetdutycycle(int PWM,float dutyCycle);
73 extern int pwmsetfrequency(int PWM,uint32_t freq);
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 #ifndef DOXYGEN_SHOULD_SKIP_THIS
80 #define UARTPARITYMASK 0x3
81 #define UARTBITSMASK 0xC
82 #define UARTSTOPBITSMASK 0x70
83
84 typedef enum
85 {
86 channel1 = 0,
87 channel2 = 1,
88 channel3 = 2,
89 channel4 = 3,
90 }channelx;
91
92 #define PWM1_CH1 ((0 << 8) + 0 )
93 #define PWM1_CH2 ((0 << 8) + 1 )
94 #define PWM1_CH3 ((0 << 8) + 2 )
95 #define PWM1_CH4 ((0 << 8) + 3 )
96 #define PWM1_CH5 ((0 << 8) + 4 )
97 #define PWM1_CH6 ((0 << 8) + 5 )
98 #define PWM1_CH7 ((0 << 8) + 6 )
99 #define PWM1_CH8 ((0 << 8) + 7 )
100 #define PWM1_CH9 ((0 << 8) + 8 )
101 #define PWM1_CH10 ((0 << 8) + 9 )
102 #define PWM1_CH11 ((0 << 8) + 10 )
103 #define PWM1_CH12 ((0 << 8) + 11 )
104 #define PWM1_CH13 ((0 << 8) + 12 )
105 #define PWM1_CH14 ((0 << 8) + 13 )
106 #define PWM1_CH15 ((0 << 8) + 14 )
107 #define PWM1_CH16 ((0 << 8) + 15 )
108 #define PWM2_CH1 ((1 << 8) + 0 )
109 #define PWM2_CH2 ((1 << 8) + 1 )
110 #define PWM2_CH3 ((1 << 8) + 2 )
111 #define PWM2_CH4 ((1 << 8) + 3 )
112 #define PWM2_CH5 ((1 << 8) + 4 )
113 #define PWM2_CH6 ((1 << 8) + 5 )
114 #define PWM2_CH7 ((1 << 8) + 6 )
115 #define PWM2_CH8 ((1 << 8) + 7 )
116 #define PWM2_CH9 ((1 << 8) + 8 )
117 #define PWM2_CH10 ((1 << 8) + 9 )
118 #define PWM2_CH11 ((1 << 8) + 10 )
119 #define PWM2_CH12 ((1 << 8) + 11 )
120 #define PWM2_CH13 ((1 << 8) + 12 )
121 #define PWM2_CH14 ((1 << 8) + 13 )
122 #define PWM2_CH15 ((1 << 8) + 14 )
123 #define PWM2_CH16 ((1 << 8) + 15 )
124 #define PWM3_CH1 ((2 << 8) + 0 )
125 #define PWM3_CH2 ((2 << 8) + 1 )
126 #define PWM3_CH3 ((2 << 8) + 2 )
127 #define PWM3_CH4 ((2 << 8) + 3 )
128 #define PWM3_CH5 ((2 << 8) + 4 )
129 #define PWM3_CH6 ((2 << 8) + 5 )
130 #define PWM3_CH7 ((2 << 8) + 6 )
131 #define PWM3_CH8 ((2 << 8) + 7 )
132 #define PWM3_CH9 ((2 << 8) + 8 )
133 #define PWM3_CH10 ((2 << 8) + 9 )
134 #define PWM3_CH11 ((2 << 8) + 10 )
135 #define PWM3_CH12 ((2 << 8) + 11 )
136 #define PWM3_CH13 ((2 << 8) + 12 )
137 #define PWM3_CH14 ((2 << 8) + 13 )
138 #define PWM3_CH15 ((2 << 8) + 14 )
139 #define PWM3_CH16 ((2 << 8) + 15 )
140 #define PWM4_CH1 ((3 << 8) + 0 )
141 #define PWM4_CH2 ((3 << 8) + 1 )
142 #define PWM4_CH3 ((3 << 8) + 2 )
143 #define PWM4_CH4 ((3 << 8) + 3 )
144 #define PWM4_CH5 ((3 << 8) + 4 )
145 #define PWM4_CH6 ((3 << 8) + 5 )
146 #define PWM4_CH7 ((3 << 8) + 6 )
147 #define PWM4_CH8 ((3 << 8) + 7 )
148 #define PWM4_CH9 ((3 << 8) + 8 )
149 #define PWM4_CH10 ((3 << 8) + 9 )
150 #define PWM4_CH11 ((3 << 8) + 10 )
151 #define PWM4_CH12 ((3 << 8) + 11 )
152 #define PWM4_CH13 ((3 << 8) + 12 )
153 #define PWM4_CH14 ((3 << 8) + 13 )
154 #define PWM4_CH15 ((3 << 8) + 14 )
155 #define PWM4_CH16 ((3 << 8) + 15 )
156 #define PWM5_CH1 ((4 << 8) + 0 )
157 #define PWM5_CH2 ((4 << 8) + 1 )
158 #define PWM5_CH3 ((4 << 8) + 2 )
159 #define PWM5_CH4 ((4 << 8) + 3 )
160 #define PWM5_CH5 ((4 << 8) + 4 )
161 #define PWM5_CH6 ((4 << 8) + 5 )
162 #define PWM5_CH7 ((4 << 8) + 6 )
163 #define PWM5_CH8 ((4 << 8) + 7 )
164 #define PWM5_CH9 ((4 << 8) + 8 )
165 #define PWM5_CH10 ((4 << 8) + 9 )
166 #define PWM5_CH11 ((4 << 8) + 10 )
167 #define PWM5_CH12 ((4 << 8) + 11 )
168 #define PWM5_CH13 ((4 << 8) + 12 )
169 #define PWM5_CH14 ((4 << 8) + 13 )
170 #define PWM5_CH15 ((4 << 8) + 14 )
171 #define PWM5_CH16 ((4 << 8) + 15 )
172 #define PWM6_CH1 ((5 << 8) + 0 )
173 #define PWM6_CH2 ((5 << 8) + 1 )
174 #define PWM6_CH3 ((5 << 8) + 2 )
175 #define PWM6_CH4 ((5 << 8) + 3 )
176 #define PWM6_CH5 ((5 << 8) + 4 )
177 #define PWM6_CH6 ((5 << 8) + 5 )
178 #define PWM6_CH7 ((5 << 8) + 6 )
179 #define PWM6_CH8 ((5 << 8) + 7 )
180 #define PWM6_CH9 ((5 << 8) + 8 )
181 #define PWM6_CH10 ((5 << 8) + 9 )
182 #define PWM6_CH11 ((5 << 8) + 10 )
183 #define PWM6_CH12 ((5 << 8) + 11 )
184 #define PWM6_CH13 ((5 << 8) + 12 )
185 #define PWM6_CH14 ((5 << 8) + 13 )
186 #define PWM6_CH15 ((5 << 8) + 14 )
187 #define PWM6_CH16 ((5 << 8) + 15 )
188 #define PWM7_CH1 ((6 << 8) + 0 )
189 #define PWM7_CH2 ((6 << 8) + 1 )
190 #define PWM7_CH3 ((6 << 8) + 2 )
191 #define PWM7_CH4 ((6 << 8) + 3 )
192 #define PWM7_CH5 ((6 << 8) + 4 )
193 #define PWM7_CH6 ((6 << 8) + 5 )
194 #define PWM7_CH7 ((6 << 8) + 6 )
195 #define PWM7_CH8 ((6 << 8) + 7 )
196 #define PWM7_CH9 ((6 << 8) + 8 )
197 #define PWM7_CH10 ((6 << 8) + 9 )
198 #define PWM7_CH11 ((6 << 8) + 10 )
199 #define PWM7_CH12 ((6 << 8) + 11 )
200 #define PWM7_CH13 ((6 << 8) + 12 )
201 #define PWM7_CH14 ((6 << 8) + 13 )
202 #define PWM7_CH15 ((6 << 8) + 14 )
203 #define PWM7_CH16 ((6 << 8) + 15 )
204 #define PWM8_CH1 ((7 << 8) + 0 )
205 #define PWM8_CH2 ((7 << 8) + 1 )
206 #define PWM8_CH3 ((7 << 8) + 2 )
207 #define PWM8_CH4 ((7 << 8) + 3 )
208 #define PWM8_CH5 ((7 << 8) + 4 )
209 #define PWM8_CH6 ((7 << 8) + 5 )
210 #define PWM8_CH7 ((7 << 8) + 6 )
211 #define PWM8_CH8 ((7 << 8) + 7 )
212 #define PWM8_CH9 ((7 << 8) + 8 )
213 #define PWM8_CH10 ((7 << 8) + 9 )
214 #define PWM8_CH11 ((7 << 8) + 10 )
215 #define PWM8_CH12 ((7 << 8) + 11 )
216 #define PWM8_CH13 ((7 << 8) + 12 )
217 #define PWM8_CH14 ((7 << 8) + 13 )
218 #define PWM8_CH15 ((7 << 8) + 14 )
219 #define PWM8_CH16 ((7 << 8) + 15 )
220 #define PWM9_CH1 ((8 << 8) + 0 )
221 #define PWM9_CH2 ((8 << 8) + 1 )
222 #define PWM9_CH3 ((8 << 8) + 2 )
223 #define PWM9_CH4 ((8 << 8) + 3 )
224 #define PWM9_CH5 ((8 << 8) + 4 )
225 #define PWM9_CH6 ((8 << 8) + 5 )
226 #define PWM9_CH7 ((8 << 8) + 6 )
227 #define PWM9_CH8 ((8 << 8) + 7 )
228 #define PWM9_CH9 ((8 << 8) + 8 )
229 #define PWM9_CH10 ((8 << 8) + 9 )
230 #define PWM9_CH11 ((8 << 8) + 10 )
231 #define PWM9_CH12 ((8 << 8) + 11 )
232 #define PWM9_CH13 ((8 << 8) + 12 )
233 #define PWM9_CH14 ((8 << 8) + 13 )
234 #define PWM9_CH15 ((8 << 8) + 14 )
235 #define PWM9_CH16 ((8 << 8) + 15 )
236 #define PWM10_CH1 ((9 << 8) + 0 )
237 #define PWM10_CH2 ((9 << 8) + 1 )
238 #define PWM10_CH3 ((9 << 8) + 2 )
239 #define PWM10_CH4 ((9 << 8) + 3 )
240 #define PWM10_CH5 ((9 << 8) + 4 )
241 #define PWM10_CH6 ((9 << 8) + 5 )
242 #define PWM10_CH7 ((9 << 8) + 6 )
243 #define PWM10_CH8 ((9 << 8) + 7 )
244 #define PWM10_CH9 ((9 << 8) + 8 )
245 #define PWM10_CH10 ((9 << 8) + 9 )
246 #define PWM10_CH11 ((9 << 8) + 10 )
247 #define PWM10_CH12 ((9 << 8) + 11 )
248 #define PWM10_CH13 ((9 << 8) + 12 )
249 #define PWM10_CH14 ((9 << 8) + 13 )
250 #define PWM10_CH15 ((9 << 8) + 14 )
251 #define PWM10_CH16 ((9 << 8) + 15 )
252 #define PWM11_CH1 ((10 << 8) + 0 )
253 #define PWM11_CH2 ((10 << 8) + 1 )
254 #define PWM11_CH3 ((10 << 8) + 2 )
255 #define PWM11_CH4 ((10 << 8) + 3 )
256 #define PWM11_CH5 ((10 << 8) + 4 )
257 #define PWM11_CH6 ((10 << 8) + 5 )
258 #define PWM11_CH7 ((10 << 8) + 6 )
259 #define PWM11_CH8 ((10 << 8) + 7 )
260 #define PWM11_CH9 ((10 << 8) + 8 )
261 #define PWM11_CH10 ((10 << 8) + 9 )
262 #define PWM11_CH11 ((10 << 8) + 10 )
263 #define PWM11_CH12 ((10 << 8) + 11 )
264 #define PWM11_CH13 ((10 << 8) + 12 )
265 #define PWM11_CH14 ((10 << 8) + 13 )
266 #define PWM11_CH15 ((10 << 8) + 14 )
267 #define PWM11_CH16 ((10 << 8) + 15 )
268 #define PWM12_CH1 ((11 << 8) + 0 )
269 #define PWM12_CH2 ((11 << 8) + 1 )
270 #define PWM12_CH3 ((11 << 8) + 2 )
271 #define PWM12_CH4 ((11 << 8) + 3 )
272 #define PWM12_CH5 ((11 << 8) + 4 )
273 #define PWM12_CH6 ((11 << 8) + 5 )
274 #define PWM12_CH7 ((11 << 8) + 6 )
275 #define PWM12_CH8 ((11 << 8) + 7 )
276 #define PWM12_CH9 ((11 << 8) + 8 )
277 #define PWM12_CH10 ((11 << 8) + 9 )
278 #define PWM12_CH11 ((11 << 8) + 10 )
279 #define PWM12_CH12 ((11 << 8) + 11 )
280 #define PWM12_CH13 ((11 << 8) + 12 )
281 #define PWM12_CH14 ((11 << 8) + 13 )
282 #define PWM12_CH15 ((11 << 8) + 14 )
283 #define PWM12_CH16 ((11 << 8) + 15 )
284 #define PWM13_CH1 ((12 << 8) + 0 )
285 #define PWM13_CH2 ((12 << 8) + 1 )
286 #define PWM13_CH3 ((12 << 8) + 2 )
287 #define PWM13_CH4 ((12 << 8) + 3 )
288 #define PWM13_CH5 ((12 << 8) + 4 )
289 #define PWM13_CH6 ((12 << 8) + 5 )
290 #define PWM13_CH7 ((12 << 8) + 6 )
291 #define PWM13_CH8 ((12 << 8) + 7 )
292 #define PWM13_CH9 ((12 << 8) + 8 )
293 #define PWM13_CH10 ((12 << 8) + 9 )
294 #define PWM13_CH11 ((12 << 8) + 10 )
295 #define PWM13_CH12 ((12 << 8) + 11 )
296 #define PWM13_CH13 ((12 << 8) + 12 )
297 #define PWM13_CH14 ((12 << 8) + 13 )
298 #define PWM13_CH15 ((12 << 8) + 14 )
299 #define PWM13_CH16 ((12 << 8) + 15 )
300 #define PWM14_CH1 ((13 << 8) + 0 )
301 #define PWM14_CH2 ((13 << 8) + 1 )
302 #define PWM14_CH3 ((13 << 8) + 2 )
303 #define PWM14_CH4 ((13 << 8) + 3 )
304 #define PWM14_CH5 ((13 << 8) + 4 )
305 #define PWM14_CH6 ((13 << 8) + 5 )
306 #define PWM14_CH7 ((13 << 8) + 6 )
307 #define PWM14_CH8 ((13 << 8) + 7 )
308 #define PWM14_CH9 ((13 << 8) + 8 )
309 #define PWM14_CH10 ((13 << 8) + 9 )
310 #define PWM14_CH11 ((13 << 8) + 10 )
311 #define PWM14_CH12 ((13 << 8) + 11 )
312 #define PWM14_CH13 ((13 << 8) + 12 )
313 #define PWM14_CH14 ((13 << 8) + 13 )
314 #define PWM14_CH15 ((13 << 8) + 14 )
315 #define PWM14_CH16 ((13 << 8) + 15 )
316 #define PWM15_CH1 ((14 << 8) + 0 )
317 #define PWM15_CH2 ((14 << 8) + 1 )
318 #define PWM15_CH3 ((14 << 8) + 2 )
319 #define PWM15_CH4 ((14 << 8) + 3 )
320 #define PWM15_CH5 ((14 << 8) + 4 )
321 #define PWM15_CH6 ((14 << 8) + 5 )
322 #define PWM15_CH7 ((14 << 8) + 6 )
323 #define PWM15_CH8 ((14 << 8) + 7 )
324 #define PWM15_CH9 ((14 << 8) + 8 )
325 #define PWM15_CH10 ((14 << 8) + 9 )
326 #define PWM15_CH11 ((14 << 8) + 10 )
327 #define PWM15_CH12 ((14 << 8) + 11 )
328 #define PWM15_CH13 ((14 << 8) + 12 )
329 #define PWM15_CH14 ((14 << 8) + 13 )
330 #define PWM15_CH15 ((14 << 8) + 14 )
331 #define PWM15_CH16 ((14 << 8) + 15 )
332 #define PWM16_CH1 ((15 << 8) + 0 )
333 #define PWM16_CH2 ((15 << 8) + 1 )
334 #define PWM16_CH3 ((15 << 8) + 2 )
335 #define PWM16_CH4 ((15 << 8) + 3 )
336 #define PWM16_CH5 ((15 << 8) + 4 )
337 #define PWM16_CH6 ((15 << 8) + 5 )
338 #define PWM16_CH7 ((15 << 8) + 6 )
339 #define PWM16_CH8 ((15 << 8) + 7 )
340 #define PWM16_CH9 ((15 << 8) + 8 )
341 #define PWM16_CH10 ((15 << 8) + 9 )
342 #define PWM16_CH11 ((15 << 8) + 10 )
343 #define PWM16_CH12 ((15 << 8) + 11 )
344 #define PWM16_CH13 ((15 << 8) + 12 )
345 #define PWM16_CH14 ((15 << 8) + 13 )
346 #define PWM16_CH15 ((15 << 8) + 14 )
347 #define PWM16_CH16 ((15 << 8) + 15 )
348 #endif
349 #endif // PWM_H
@@ -0,0 +1,222
1 #include <pwm.h>
2 #include <stm32f4xx_tim.h>
3 #include <stm32f4xx_gpio.h>
4 #include <stm32f4xx_rcc.h>
5 #include <stm32f4xx_tim.h>
6 #include <core.h>
7 #include <gpio.h>
8 const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7,
9 TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14};
10
11 #define timer1 0
12 #define timer2 1
13 #define timer3 2
14 #define timer4 3
15 #define timer5 4
16 #define timer6 5
17 #define timer7 6
18 #define timer8 7
19 #define timer9 8
20 #define timer10 9
21 #define timer11 10
22 #define timer12 11
23 #define timer13 12
24 #define timer14 13
25 #define timer15 14
26 #define timer16 15
27
28 #define PWMGETTIMNUMBER(PWM) (((uint32_t)(PWM) & (uint32_t)0x0000FF00)>>(uint32_t)8)
29
30 int pwmopen(int PWM,uint32_t pin)
31 {
32 #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
33 #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
34 int timer = PWMGETTIMNUMBER(PWM);
35 gpio_t PWMOUT;
36 PWMOUT = gpioopen(pin);
37 PWMOUT |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
38 gpiosetconfig(&PWMOUT);
39 uint8_t GPIO_AF = -1;
40 if(timer==timer1 || timer==timer2)GPIO_AF=1;
41 if(timer==timer3 || timer==timer4 || timer==timer5)GPIO_AF=2;
42 if(timer==timer8 || timer==timer9 || timer==timer10 || timer==timer11)GPIO_AF=3;
43 if(timer==timer12 || timer==timer13 || timer==timer14)GPIO_AF=9;
44
45 if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE);
46 if(timer>=timer12 && timer <= timer14)RCC_APB1PeriphClockCmd((1<<(timer-5)), ENABLE);
47 if(timer==timer1)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
48 if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
49 if(timer==timer9)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);
50 if(timer==timer10)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);
51 if(timer==timer11)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE);
52
53 if(GPIO_AF!=-1)GPIO_PinAFConfig(GPIOGETPORT(PWMOUT), (uint8_t)(PWMOUT & 0xF), GPIO_AF);
54
55 return 0;
56 }
57
58 int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle)
59 {
60 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
61 TIM_OCInitTypeDef TIM_OCInitStructure;
62 if(PWM==-1) return -1;
63 int timer = PWMGETTIMNUMBER(PWM);
64 TIM_TypeDef* tim = _timer_dev_table[timer];
65 uint32_t timfreq = getCpuFreq()/2;
66 uint32_t period = timfreq/freq - 1;
67 uint16_t PrescalerValue=0;
68
69 while (period>=0x0FFFF)
70 {
71 PrescalerValue++;
72 timfreq = getCpuFreq()/(2*(PrescalerValue+1));
73 period = (timfreq/freq) - 1;
74 }
75
76 TIM_TimeBaseStructure.TIM_Period = period;
77 TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
78 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
79 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
80 TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure);
81
82 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
83 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
84 TIM_OCInitStructure.TIM_Pulse = (uint32_t)((period * dutyCycle)/100);
85 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
86
87 switch (PWM&0x0FF) {
88 case 0:
89 TIM_OC1Init(tim, &TIM_OCInitStructure);
90 TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable);
91 TIM_ARRPreloadConfig(tim, ENABLE);
92 TIM_Cmd(tim, ENABLE);
93 break;
94 case 1:
95 TIM_OC2Init(tim, &TIM_OCInitStructure);
96 TIM_OC2PreloadConfig(tim, TIM_OCPreload_Enable);
97 TIM_ARRPreloadConfig(tim, ENABLE);
98 TIM_Cmd(tim, ENABLE);
99 break;
100 case 2:
101 TIM_OC3Init(tim, &TIM_OCInitStructure);
102 TIM_OC3PreloadConfig(tim, TIM_OCPreload_Enable);
103 TIM_ARRPreloadConfig(tim, ENABLE);
104 TIM_Cmd(tim, ENABLE);
105 break;
106 case 3:
107 TIM_OC4Init(tim, &TIM_OCInitStructure);
108 TIM_OC4PreloadConfig(tim, TIM_OCPreload_Enable);
109 TIM_ARRPreloadConfig(tim, ENABLE);
110 TIM_Cmd(tim, ENABLE);
111 break;
112 default:
113 return -1;
114 break;
115 }
116 return 0;
117 }
118
119
120
121
122
123 int pwmsetdutycycle(int PWM,float dutyCycle)
124 {
125 if(PWM==-1) return -1;
126 int timer = PWMGETTIMNUMBER(PWM);
127 TIM_TypeDef* tim = _timer_dev_table[timer];
128 switch (PWM&0x0FF) {
129 case 0:
130 tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100);
131 break;
132 case 1:
133 tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100);
134 break;
135 case 2:
136 tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100);
137 break;
138 case 3:
139 tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100);
140 break;
141 default:
142 return -1;
143 break;
144 }
145 return 0;
146 }
147
148 float pwmgetdutycycle(int PWM)
149 {
150 if(PWM==-1) return -1;
151 int timer = PWMGETTIMNUMBER(PWM);
152 TIM_TypeDef* tim = _timer_dev_table[timer];
153 switch (PWM&0x0FF) {
154 case 0:
155 return (float)((tim->CCR1*100)/tim->ARR);
156 break;
157 case 1:
158 return (float)((tim->CCR2*100)/tim->ARR);
159 break;
160 case 2:
161 return (float)((tim->CCR3*100)/tim->ARR);
162 break;
163 case 3:
164 return (float)((tim->CCR4*100)/tim->ARR);
165 break;
166 default:
167 return -1;
168 break;
169 }
170 return 0;
171 }
172
173
174 int pwmsetfrequency(int PWM,uint32_t freq)
175 {
176 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
177 if(PWM==-1) return -1;
178 int timer = PWMGETTIMNUMBER(PWM);
179 TIM_TypeDef* tim = _timer_dev_table[timer];
180 uint32_t timfreq = getCpuFreq()/2;
181 uint32_t period = timfreq/freq - 1;
182 uint16_t PrescalerValue=0;
183 float dutyCycle = pwmgetdutycycle(PWM);
184 while (period>=0x0FFFF)
185 {
186 PrescalerValue++;
187 timfreq = getCpuFreq()/(2*(PrescalerValue+1));
188 period = (timfreq/freq) - 1;
189 }
190
191 TIM_TimeBaseStructure.TIM_Period = period;
192 TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
193 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
194 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
195 TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure);
196
197 switch (PWM&0x0FF) {
198 case 0:
199 tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100);
200 TIM_ARRPreloadConfig(tim, ENABLE);
201 break;
202 case 1:
203 tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100);
204 TIM_ARRPreloadConfig(tim, ENABLE);
205 break;
206 case 2:
207 tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100);
208 TIM_ARRPreloadConfig(tim, ENABLE);
209 break;
210 case 3:
211 tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100);
212 TIM_ARRPreloadConfig(tim, ENABLE);
213 break;
214 default:
215 return -1;
216 break;
217 }
218 return 0;
219 }
220
221
222
@@ -0,0 +1,13
1 TEMPLATE = lib
2 CONFIG += libuc2lib
3
4 SOURCES += pwm.c
5
6
7 UCMODEL=stm32f4
8
9 HEADERS += \
10 ../../../include/PERIPHERALS/pwm.h
11
12
13
@@ -71,6 +71,8 FAT32fs sdcard2FAT32part3;
71 dikpartition sdcard2Part4;
71 dikpartition sdcard2Part4;
72 FAT32fs sdcard2FAT32part4;
72 FAT32fs sdcard2FAT32part4;
73
73
74
75
74 int bsp_init()
76 int bsp_init()
75 {
77 {
76 int i=0;
78 int i=0;
@@ -329,4 +331,3 Uint32 getpixel(SDL_Surface *surface, in
329
331
330
332
331
333
332
@@ -11,7 +11,7 SOURCES += bsp.c
11
11
12 HEADERS += bsp.h
12 HEADERS += bsp.h
13
13
14 LIBS+= -lgpio -luart -li2c -lspi
14 LIBS+= -lgpio -luart -li2c -lspi -lpwm
15
15
16 BSPFILE = bsp.pri
16 BSPFILE = bsp.pri
17
17
@@ -11,7 +11,8 SUBDIRS += STM32F4Discovery \
11 OPLAYER \
11 OPLAYER \
12 STM32-E407 \
12 STM32-E407 \
13 STM32F429Discovery \
13 STM32F429Discovery \
14 STM32F4Discovery_35LCD
14 STM32F4Discovery_35LCD \
15 Nano-particle
15
16
16
17
17
18
@@ -2,6 +2,10
2 #include <stdio.h>
2 #include <stdio.h>
3 #include <fat32.h>
3 #include <fat32.h>
4 #include <ucdirent.h>
4 #include <ucdirent.h>
5 #include <stdarg.h>
6 #include <streamdevices.h>
7
8
5
9
6 void printRootClustersChain(FAT32fs* sdcard2FAT32part)
10 void printRootClustersChain(FAT32fs* sdcard2FAT32part)
7 {
11 {
@@ -24,8 +24,6
24 * the project file. The value BSP contains the board name, and UCMODEL contain
24 * the project file. The value BSP contains the board name, and UCMODEL contain
25 * the target architecture.
25 * the target architecture.
26 */
26 */
27 #include <stdio.h>
28
29
27
30 int libuc_main()
28 int libuc_main()
31 {
29 {
@@ -27,7 +27,7 QMAKE_LINK = gcc
27 QMAKE_LINK_SHLIB = gcc
27 QMAKE_LINK_SHLIB = gcc
28 QMAKE_LINK_C = gcc
28 QMAKE_LINK_C = gcc
29 QMAKE_LINK_C_SHLIB = gcc
29 QMAKE_LINK_C_SHLIB = gcc
30 QMAKE_LFLAGS += -g -O0
30 QMAKE_LFLAGS += -g -O0 -Wl,-wrap,printf -Wl,-wrap,puts
31 QMAKE_LFLAGS_RELEASE +=
31 QMAKE_LFLAGS_RELEASE +=
32 QMAKE_LFLAGS_DEBUG +=
32 QMAKE_LFLAGS_DEBUG +=
33 QMAKE_LFLAGS_APP +=
33 QMAKE_LFLAGS_APP +=
@@ -1,4 +1,32
1 #include <stdio.h>
2 #include <stdarg.h>
3 #include <streamdevices.h>
1
4
5 extern streamdevice* __opnfiles__[];
6
7 extern int __real_printf(const char *format,...);
8
9 int __wrap_printf(const char *format,...)
10 {
11 char* str_buffer;
12 // for(int i =0;i<512;i++)str_buffer[i]='\0';
13 int i;
14 va_list ap;
15 va_start(ap,format);
16 vasprintf(&str_buffer,format,ap);
17 va_end(ap);
18 i=strlen(str_buffer);
19 __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)str_buffer,1,i);
20 }
21
22 extern int __real_puts(const char *s);
23
24 int __wrap_puts(const char *s)
25 {
26 int i;
27 i=strlen(s);
28 __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)s,1,i);
29 }
2
30
3 int main(void)
31 int main(void)
4 {
32 {
@@ -57,7 +57,11 contains( TEMPLATE, app ) {
57
57
58 stflash.target = stflash
58 stflash.target = stflash
59 stflash.commands = cd $$DESTDIR && st-flash write $(QMAKE_TARGET).bin 0x08000000
59 stflash.commands = cd $$DESTDIR && st-flash write $(QMAKE_TARGET).bin 0x08000000
60 dfu_file.target = $$DESTDIR/$(QMAKE_TARGET).dfu
61 dfu_file.commands = python $$[QT_INSTALL_BINS]/dfu.py -b 0x08000000:$$DESTDIR/$(QMAKE_TARGET).bin $$DESTDIR/$(QMAKE_TARGET).dfu
62 dfu_file.depends = $$DESTDIR/$(QMAKE_TARGET)
60 dfu.target = dfu
63 dfu.target = dfu
64 dfu.depends = $$DESTDIR/$(QMAKE_TARGET).dfu
61 dfu.commands = cd $$DESTDIR && dfu-util d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D $(QMAKE_TARGET).bin 0x08000000
65 dfu.commands = cd $$DESTDIR && dfu-util d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D $(QMAKE_TARGET).bin 0x08000000
62 gdb-server.target = gdb-server
66 gdb-server.target = gdb-server
63 gdb-server.commands = st-util -p 3333 &
67 gdb-server.commands = st-util -p 3333 &
@@ -65,7 +69,7 contains( TEMPLATE, app ) {
65 nemiver.target = nemiver
69 nemiver.target = nemiver
66 nemiver.commands = cd $$DESTDIR && nemiver --remote=localhost:3333 --gdb-binary=`which arm-none-eabi-gdb` $(QMAKE_TARGET)
70 nemiver.commands = cd $$DESTDIR && nemiver --remote=localhost:3333 --gdb-binary=`which arm-none-eabi-gdb` $(QMAKE_TARGET)
67 nemiver.depends = gdb-server
71 nemiver.depends = gdb-server
68 QMAKE_EXTRA_TARGETS += stflash dfu nemiver gdb-server
72 QMAKE_EXTRA_TARGETS += dfu_file stflash dfu nemiver gdb-server
69 }
73 }
70
74
71
75
@@ -1,4 +1,32
1 #include <stdio.h>
2 #include <stdarg.h>
3 #include <streamdevices.h>
1
4
5 extern streamdevice* __opnfiles__[];
6
7 extern int __real_printf(const char *format,...);
8
9 int __wrap_printf(const char *format,...)
10 {
11 char* str_buffer;
12 // for(int i =0;i<512;i++)str_buffer[i]='\0';
13 int i;
14 va_list ap;
15 va_start(ap,format);
16 vasprintf(&str_buffer,format,ap);
17 va_end(ap);
18 i=strlen(str_buffer);
19 __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)str_buffer,1,i);
20 }
21
22 extern int __real_puts(const char *s);
23
24 int __wrap_puts(const char *s)
25 {
26 int i;
27 i=strlen(s);
28 __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)s,1,i);
29 }
2
30
3 int main(void)
31 int main(void)
4 {
32 {
@@ -7,8 +7,9 SUBDIRS = CORE/core.pro \
7 UART/uart.pro \
7 UART/uart.pro \
8 SPI/spi.pro \
8 SPI/spi.pro \
9 I2C/i2c.pro \
9 I2C/i2c.pro \
10 SDCARD-SDIO/sdcard-sdio.pro \
10 PWM/pwm.pro \
11 USB
11 SDCARD-SDIO/sdcard-sdio.pro
12
12
13
13
14
14
15
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now