@@ -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,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 |
@@ -1,332 +1,333 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
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 |
|
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 |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include "bsp.h" |
|
22 | #include "bsp.h" | |
23 | #include <streamdevices.h> |
|
23 | #include <streamdevices.h> | |
24 | #include <malloc.h> |
|
24 | #include <malloc.h> | |
25 | #include <stdio.h> |
|
25 | #include <stdio.h> | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | uint32_t OSC0 =8000000; |
|
28 | uint32_t OSC0 =8000000; | |
29 | uint32_t INTOSC =16000000; |
|
29 | uint32_t INTOSC =16000000; | |
30 | uint32_t RTCOSC =32768; |
|
30 | uint32_t RTCOSC =32768; | |
31 | uint32_t currentCpuFreq=0; |
|
31 | uint32_t currentCpuFreq=0; | |
32 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
32 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | LCD_IF_t lcdIF0={ |
|
35 | LCD_IF_t lcdIF0={ | |
36 | .init = &SDLCD_init, |
|
36 | .init = &SDLCD_init, | |
37 | .writereg = &SDLCD_writereg, |
|
37 | .writereg = &SDLCD_writereg, | |
38 | .readreg = &SDLCD_readreg, |
|
38 | .readreg = &SDLCD_readreg, | |
39 | .writeGRAM = &SDLCD_writeGRAM_16bpp, |
|
39 | .writeGRAM = &SDLCD_writeGRAM_16bpp, | |
40 | .readGRAM = &SDLCD_readGRAM_16bpp |
|
40 | .readGRAM = &SDLCD_readGRAM_16bpp | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | LCD_t lcd0={ |
|
43 | LCD_t lcd0={ | |
44 | .interface = &lcdIF0, |
|
44 | .interface = &lcdIF0, | |
45 | .init = &ili9328init, |
|
45 | .init = &ili9328init, | |
46 | .paint = &ili9328paint, |
|
46 | .paint = &ili9328paint, | |
47 | .paintText = &ili9328paintText, |
|
47 | .paintText = &ili9328paintText, | |
48 | .paintFilRect = &ili9328paintFilRect, |
|
48 | .paintFilRect = &ili9328paintFilRect, | |
49 | .getPix = &ili9328getPix, |
|
49 | .getPix = &ili9328getPix, | |
50 | .refreshenable = &ili9328refreshenable, |
|
50 | .refreshenable = &ili9328refreshenable, | |
51 | .width= 600, |
|
51 | .width= 600, | |
52 | .height = 800 |
|
52 | .height = 800 | |
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | terminal_t terminal0; |
|
55 | terminal_t terminal0; | |
56 |
|
56 | |||
57 | volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; |
|
57 | volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; | |
58 | volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); |
|
58 | volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); | |
59 |
|
59 | |||
60 | float VREF0 =(float)3.3; |
|
60 | float VREF0 =(float)3.3; | |
61 | volatile vs10XXDev audioCodec0; |
|
61 | volatile vs10XXDev audioCodec0; | |
62 |
|
62 | |||
63 | sdcardDev sdcard2; |
|
63 | sdcardDev sdcard2; | |
64 | blkdevice sdcard2blkdev; |
|
64 | blkdevice sdcard2blkdev; | |
65 | dikpartition sdcard2Part1; |
|
65 | dikpartition sdcard2Part1; | |
66 | FAT32fs sdcard2FAT32part1; |
|
66 | FAT32fs sdcard2FAT32part1; | |
67 | dikpartition sdcard2Part2; |
|
67 | dikpartition sdcard2Part2; | |
68 | FAT32fs sdcard2FAT32part2; |
|
68 | FAT32fs sdcard2FAT32part2; | |
69 | dikpartition sdcard2Part3; |
|
69 | dikpartition sdcard2Part3; | |
70 | FAT32fs sdcard2FAT32part3; |
|
70 | 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; | |
77 | for(i=0;i<__MAX_OPENED_FILES__;i++) |
|
79 | for(i=0;i<__MAX_OPENED_FILES__;i++) | |
78 | { |
|
80 | { | |
79 | __opnfiles__[i] = NULL; |
|
81 | __opnfiles__[i] = NULL; | |
80 | } |
|
82 | } | |
81 | bsp_GPIO_init(); |
|
83 | bsp_GPIO_init(); | |
82 | bsp_uart_init(); |
|
84 | bsp_uart_init(); | |
83 | bsp_iic_init(); |
|
85 | bsp_iic_init(); | |
84 | bsp_FSMC_init(); |
|
86 | bsp_FSMC_init(); | |
85 | bsp_GTerm_init(); |
|
87 | bsp_GTerm_init(); | |
86 | bsp_spi_init(); |
|
88 | bsp_spi_init(); | |
87 | bsp_SD_init(); |
|
89 | bsp_SD_init(); | |
88 | bsp_Audio_init(); |
|
90 | bsp_Audio_init(); | |
89 | printf("\r=====================\n\r"); |
|
91 | printf("\r=====================\n\r"); | |
90 | printf( "=====================\n\r"); |
|
92 | printf( "=====================\n\r"); | |
91 | printf(BSP); |
|
93 | printf(BSP); | |
92 | printf(" initialised\n\r"); |
|
94 | printf(" initialised\n\r"); | |
93 | printf( "=====================\n\r"); |
|
95 | printf( "=====================\n\r"); | |
94 | return 1; |
|
96 | return 1; | |
95 | } |
|
97 | } | |
96 |
|
98 | |||
97 | void bsp_GPIO_init() |
|
99 | void bsp_GPIO_init() | |
98 | { |
|
100 | { | |
99 |
|
101 | |||
100 | } |
|
102 | } | |
101 |
|
103 | |||
102 | void bsp_uart_init() |
|
104 | void bsp_uart_init() | |
103 | { |
|
105 | { | |
104 |
|
106 | |||
105 | } |
|
107 | } | |
106 |
|
108 | |||
107 | /* |
|
109 | /* | |
108 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
110 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 | |
109 | D5 PE8 D6 PE9 D7 PE10 |
|
111 | D5 PE8 D6 PE9 D7 PE10 | |
110 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S |
|
112 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S | |
111 | FSMC_NOE PD4 RD |
|
113 | FSMC_NOE PD4 RD | |
112 | */ |
|
114 | */ | |
113 |
|
115 | |||
114 | int bsp_FSMC_init() |
|
116 | int bsp_FSMC_init() | |
115 | { |
|
117 | { | |
116 |
|
118 | |||
117 | return 1; |
|
119 | return 1; | |
118 | } |
|
120 | } | |
119 |
|
121 | |||
120 | void bsp_spi_init() |
|
122 | void bsp_spi_init() | |
121 | { |
|
123 | { | |
122 |
|
124 | |||
123 | } |
|
125 | } | |
124 |
|
126 | |||
125 |
|
127 | |||
126 | void bsp_iic_init() |
|
128 | void bsp_iic_init() | |
127 | { |
|
129 | { | |
128 |
|
130 | |||
129 | } |
|
131 | } | |
130 |
|
132 | |||
131 |
|
133 | |||
132 | void bsp_Audio_init() |
|
134 | void bsp_Audio_init() | |
133 | { |
|
135 | { | |
134 |
|
136 | |||
135 | } |
|
137 | } | |
136 |
|
138 | |||
137 | void bsp_SD_init() |
|
139 | void bsp_SD_init() | |
138 | { |
|
140 | { | |
139 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2, bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); |
|
141 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2, bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); | |
140 | if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) |
|
142 | if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) | |
141 | { |
|
143 | { | |
142 | if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) |
|
144 | if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) | |
143 | { |
|
145 | { | |
144 | if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) |
|
146 | if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) | |
145 | printf("Can't open fat32 partition 1\n"); |
|
147 | printf("Can't open fat32 partition 1\n"); | |
146 | } |
|
148 | } | |
147 | else |
|
149 | else | |
148 | { |
|
150 | { | |
149 | printf("Can't open or read MBR\n"); |
|
151 | printf("Can't open or read MBR\n"); | |
150 | } |
|
152 | } | |
151 | delay_100us(1000); |
|
153 | delay_100us(1000); | |
152 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) |
|
154 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) | |
153 | { |
|
155 | { | |
154 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) |
|
156 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) | |
155 | printf("Can't open fat32 partition 2\n"); |
|
157 | printf("Can't open fat32 partition 2\n"); | |
156 | } |
|
158 | } | |
157 | else |
|
159 | else | |
158 | { |
|
160 | { | |
159 | printf("Can't open or read MBR\n"); |
|
161 | printf("Can't open or read MBR\n"); | |
160 | } |
|
162 | } | |
161 | delay_100us(1000); |
|
163 | delay_100us(1000); | |
162 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) |
|
164 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) | |
163 | { |
|
165 | { | |
164 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) |
|
166 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) | |
165 | printf("Can't open fat32 partition 3\n"); |
|
167 | printf("Can't open fat32 partition 3\n"); | |
166 | } |
|
168 | } | |
167 | else |
|
169 | else | |
168 | { |
|
170 | { | |
169 | printf("Can't open or read MBR\n"); |
|
171 | printf("Can't open or read MBR\n"); | |
170 | } |
|
172 | } | |
171 | delay_100us(1000); |
|
173 | delay_100us(1000); | |
172 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) |
|
174 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) | |
173 | { |
|
175 | { | |
174 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) |
|
176 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) | |
175 | printf("Can't open fat32 partition 4\n"); |
|
177 | printf("Can't open fat32 partition 4\n"); | |
176 | } |
|
178 | } | |
177 | else |
|
179 | else | |
178 | { |
|
180 | { | |
179 | printf("Can't open or read MBR\n"); |
|
181 | printf("Can't open or read MBR\n"); | |
180 | } |
|
182 | } | |
181 | } |
|
183 | } | |
182 | else |
|
184 | else | |
183 | { |
|
185 | { | |
184 | printf("Can't initialize SDCARD\n"); |
|
186 | printf("Can't initialize SDCARD\n"); | |
185 | } |
|
187 | } | |
186 |
|
188 | |||
187 | delay_100us(2000); |
|
189 | delay_100us(2000); | |
188 | } |
|
190 | } | |
189 |
|
191 | |||
190 | void vs1052setXCS(char val) |
|
192 | void vs1052setXCS(char val) | |
191 | { |
|
193 | { | |
192 | } |
|
194 | } | |
193 |
|
195 | |||
194 | void vs1052setXDCS(char val) |
|
196 | void vs1052setXDCS(char val) | |
195 | { |
|
197 | { | |
196 | } |
|
198 | } | |
197 |
|
199 | |||
198 | void vs1052setRST(char val) |
|
200 | void vs1052setRST(char val) | |
199 | { |
|
201 | { | |
200 | } |
|
202 | } | |
201 |
|
203 | |||
202 | int vs10XXDREQ() |
|
204 | int vs10XXDREQ() | |
203 | { |
|
205 | { | |
204 | return 1; |
|
206 | return 1; | |
205 | } |
|
207 | } | |
206 |
|
208 | |||
207 |
|
209 | |||
208 | void bsppowersdcard(char onoff) //always ON |
|
210 | void bsppowersdcard(char onoff) //always ON | |
209 | { |
|
211 | { | |
210 |
|
212 | |||
211 | } |
|
213 | } | |
212 |
|
214 | |||
213 | char bspsdcardpresent() |
|
215 | char bspsdcardpresent() | |
214 | { |
|
216 | { | |
215 | return 1; |
|
217 | return 1; | |
216 | } |
|
218 | } | |
217 |
|
219 | |||
218 | char bspsdcardwriteprotected() |
|
220 | char bspsdcardwriteprotected() | |
219 | { |
|
221 | { | |
220 | return 0; |
|
222 | return 0; | |
221 | } |
|
223 | } | |
222 |
|
224 | |||
223 | void bspsdcardselect(char YESNO) |
|
225 | void bspsdcardselect(char YESNO) | |
224 | { |
|
226 | { | |
225 |
|
227 | |||
226 | } |
|
228 | } | |
227 |
|
229 | |||
228 |
|
230 | |||
229 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
231 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) | |
230 | { |
|
232 | { | |
231 |
|
233 | |||
232 | } |
|
234 | } | |
233 |
|
235 | |||
234 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
236 | uint32_t bsp_lcd0_read_reg(uint32_t reg) | |
235 | { |
|
237 | { | |
236 | return 0; |
|
238 | return 0; | |
237 | } |
|
239 | } | |
238 |
|
240 | |||
239 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
241 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) | |
240 | { |
|
242 | { | |
241 |
|
243 | |||
242 | } |
|
244 | } | |
243 |
|
245 | |||
244 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
246 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) | |
245 | { |
|
247 | { | |
246 |
|
248 | |||
247 | } |
|
249 | } | |
248 |
|
250 | |||
249 | void bsp_GTerm_init() |
|
251 | void bsp_GTerm_init() | |
250 | { |
|
252 | { | |
251 | SDLCD_mkscreen(lcd0.width,lcd0.height,16,LCDILI9328); |
|
253 | SDLCD_mkscreen(lcd0.width,lcd0.height,16,LCDILI9328); | |
252 |
|
254 | |||
253 | if(__opnfiles__[1]==NULL) |
|
255 | if(__opnfiles__[1]==NULL) | |
254 | { |
|
256 | { | |
255 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
257 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
256 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); |
|
258 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); | |
257 | lcd0.paintFilRect(&lcd0,0,0,lcd0.width,lcd0.height,0,0,0x0f0f); |
|
259 | lcd0.paintFilRect(&lcd0,0,0,lcd0.width,lcd0.height,0,0,0x0f0f); | |
258 | __opnfiles__[1] = fd1; |
|
260 | __opnfiles__[1] = fd1; | |
259 | } |
|
261 | } | |
260 | else |
|
262 | else | |
261 | { |
|
263 | { | |
262 |
|
264 | |||
263 | } |
|
265 | } | |
264 | } |
|
266 | } | |
265 |
|
267 | |||
266 |
|
268 | |||
267 |
|
269 | |||
268 |
|
270 | |||
269 |
|
271 | |||
270 |
|
272 | |||
271 |
|
273 | |||
272 | void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
274 | void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) | |
273 | { |
|
275 | { | |
274 | int bpp = surface->format->BytesPerPixel; |
|
276 | int bpp = surface->format->BytesPerPixel; | |
275 | /* Here p is the address to the pixel we want to set */ |
|
277 | /* Here p is the address to the pixel we want to set */ | |
276 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
278 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; | |
277 | switch(bpp) { |
|
279 | switch(bpp) { | |
278 | case 1: |
|
280 | case 1: | |
279 | *p = pixel; |
|
281 | *p = pixel; | |
280 | break; |
|
282 | break; | |
281 | case 2: |
|
283 | case 2: | |
282 | *(Uint16 *)p = pixel; |
|
284 | *(Uint16 *)p = pixel; | |
283 | break; |
|
285 | break; | |
284 | case 3: |
|
286 | case 3: | |
285 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { |
|
287 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { | |
286 | p[0] = (pixel >> 16) & 0xff; |
|
288 | p[0] = (pixel >> 16) & 0xff; | |
287 | p[1] = (pixel >> 8) & 0xff; |
|
289 | p[1] = (pixel >> 8) & 0xff; | |
288 | p[2] = pixel & 0xff; |
|
290 | p[2] = pixel & 0xff; | |
289 | } else { |
|
291 | } else { | |
290 | p[0] = pixel & 0xff; |
|
292 | p[0] = pixel & 0xff; | |
291 | p[1] = (pixel >> 8) & 0xff; |
|
293 | p[1] = (pixel >> 8) & 0xff; | |
292 | p[2] = (pixel >> 16) & 0xff; |
|
294 | p[2] = (pixel >> 16) & 0xff; | |
293 | } |
|
295 | } | |
294 | break; |
|
296 | break; | |
295 | case 4: |
|
297 | case 4: | |
296 | *(Uint32 *)p = pixel; |
|
298 | *(Uint32 *)p = pixel; | |
297 | break; |
|
299 | break; | |
298 | } |
|
300 | } | |
299 | } |
|
301 | } | |
300 |
|
302 | |||
301 | Uint32 getpixel(SDL_Surface *surface, int x, int y) |
|
303 | Uint32 getpixel(SDL_Surface *surface, int x, int y) | |
302 | { |
|
304 | { | |
303 | int bpp = surface->format->BytesPerPixel; |
|
305 | int bpp = surface->format->BytesPerPixel; | |
304 | /* Here p is the address to the pixel we want to retrieve */ |
|
306 | /* Here p is the address to the pixel we want to retrieve */ | |
305 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
307 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; | |
306 | switch(bpp) { |
|
308 | switch(bpp) { | |
307 | case 1: |
|
309 | case 1: | |
308 | return *p; |
|
310 | return *p; | |
309 | case 2: |
|
311 | case 2: | |
310 | return *(Uint16 *)p; |
|
312 | return *(Uint16 *)p; | |
311 | case 3: |
|
313 | case 3: | |
312 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) |
|
314 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
313 | return p[0] << 16 | p[1] << 8 | p[2]; |
|
315 | return p[0] << 16 | p[1] << 8 | p[2]; | |
314 | else |
|
316 | else | |
315 | return p[0] | p[1] << 8 | p[2] << 16; |
|
317 | return p[0] | p[1] << 8 | p[2] << 16; | |
316 | case 4: |
|
318 | case 4: | |
317 | return *(Uint32 *)p; |
|
319 | return *(Uint32 *)p; | |
318 | default: |
|
320 | default: | |
319 | return 0; |
|
321 | return 0; | |
320 | } |
|
322 | } | |
321 | /* shouldn’t happen, but avoids warnings */ |
|
323 | /* shouldn’t happen, but avoids warnings */ | |
322 | } |
|
324 | } | |
323 |
|
325 | |||
324 |
|
326 | |||
325 |
|
327 | |||
326 |
|
328 | |||
327 |
|
329 | |||
328 |
|
330 | |||
329 |
|
331 | |||
330 |
|
332 | |||
331 |
|
333 | |||
332 |
|
@@ -1,19 +1,19 | |||||
1 | TEMPLATE = lib |
|
1 | TEMPLATE = lib | |
2 |
|
2 | |||
3 | TARGET=bsp |
|
3 | TARGET=bsp | |
4 | CONFIG += bsp |
|
4 | CONFIG += bsp | |
5 |
|
5 | |||
6 | BSP=STM32F4Discovery |
|
6 | BSP=STM32F4Discovery | |
7 |
|
7 | |||
8 | UCMODEL=stm32f4 |
|
8 | UCMODEL=stm32f4 | |
9 |
|
9 | |||
10 | SOURCES += bsp.c |
|
10 | 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 | |||
18 |
|
18 | |||
19 |
|
19 |
@@ -1,21 +1,22 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | CONFIG += ordered |
|
2 | CONFIG += ordered | |
3 | SUBDIRS += STM32F4Discovery \ |
|
3 | SUBDIRS += STM32F4Discovery \ | |
4 | M4Stick \ |
|
4 | M4Stick \ | |
5 | M4StickV2 \ |
|
5 | M4StickV2 \ | |
6 | SOLAR_LFR_PSU \ |
|
6 | SOLAR_LFR_PSU \ | |
7 | BEAGLESYNTH \ |
|
7 | BEAGLESYNTH \ | |
8 | STM32F4Eval \ |
|
8 | STM32F4Eval \ | |
9 | STM32F4Discovery-EXT \ |
|
9 | STM32F4Discovery-EXT \ | |
10 | STM32F4Discovery-ILI9328-8bits \ |
|
10 | STM32F4Discovery-ILI9328-8bits \ | |
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 | |||
18 |
|
19 | |||
19 |
|
20 | |||
20 |
|
21 | |||
21 |
|
22 |
@@ -1,19 +1,23 | |||||
1 |
|
1 | |||
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 | { | |
8 | ucdirent root; |
|
12 | ucdirent root; | |
9 | uint32_t sector_lba,res,tmp=sdcard2FAT32part->cluster_begin_lba; |
|
13 | uint32_t sector_lba,res,tmp=sdcard2FAT32part->cluster_begin_lba; | |
10 | sector_lba=tmp; |
|
14 | sector_lba=tmp; | |
11 | do |
|
15 | do | |
12 | { |
|
16 | { | |
13 | printf("Sector @0x%x\n",tmp); |
|
17 | printf("Sector @0x%x\n",tmp); | |
14 | //sector_lba=tmp+sdcard2FAT32part->BPB_SecPerClus-1; |
|
18 | //sector_lba=tmp+sdcard2FAT32part->BPB_SecPerClus-1; | |
15 | sector_lba=tmp; |
|
19 | sector_lba=tmp; | |
16 | res=fat32nextsectorlba(sdcard2FAT32part,sector_lba,&tmp); |
|
20 | res=fat32nextsectorlba(sdcard2FAT32part,sector_lba,&tmp); | |
17 | }while((res==DIRENT_noErr)&&(res!=DIRENT_LastSect)); |
|
21 | }while((res==DIRENT_noErr)&&(res!=DIRENT_LastSect)); | |
18 |
|
22 | |||
19 | } |
|
23 | } |
@@ -1,47 +1,45 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2013, Alexis Jeandet |
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
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 |
|
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 |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
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 |
|
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 |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org |
|
19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org | |
20 | -------------------------------------------------------------------------------*/ |
|
20 | -------------------------------------------------------------------------------*/ | |
21 | /** |
|
21 | /** | |
22 | * This file is a simple hello world example it should run on any supported |
|
22 | * This file is a simple hello world example it should run on any supported | |
23 | * board/architecture couple. To change target board and architecture modify |
|
23 | * board/architecture couple. To change target board and architecture modify | |
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 | { | |
32 | /** |
|
30 | /** | |
33 | Depending on the board the printf can be directed on one uart or LCD screen or |
|
31 | Depending on the board the printf can be directed on one uart or LCD screen or | |
34 | any other stream device. |
|
32 | any other stream device. | |
35 | */ |
|
33 | */ | |
36 | printf("hello world\n\r"); |
|
34 | printf("hello world\n\r"); | |
37 | return 0; |
|
35 | return 0; | |
38 | } |
|
36 | } | |
39 |
|
37 | |||
40 |
|
38 | |||
41 |
|
39 | |||
42 |
|
40 | |||
43 |
|
41 | |||
44 |
|
42 | |||
45 |
|
43 | |||
46 |
|
44 | |||
47 |
|
45 |
@@ -1,41 +1,41 | |||||
1 | # |
|
1 | # | |
2 | # qmake configuration for simulator |
|
2 | # qmake configuration for simulator | |
3 | # |
|
3 | # | |
4 |
|
4 | |||
5 | CONFIG += |
|
5 | CONFIG += | |
6 | QMAKE_CC = gcc |
|
6 | QMAKE_CC = gcc | |
7 | QMAKE_CFLAGS += -g -O0 |
|
7 | QMAKE_CFLAGS += -g -O0 | |
8 | QMAKE_CFLAGS_DEPS += -M |
|
8 | QMAKE_CFLAGS_DEPS += -M | |
9 | QMAKE_CFLAGS_WARN_ON += -Wall |
|
9 | QMAKE_CFLAGS_WARN_ON += -Wall | |
10 | QMAKE_CFLAGS_WARN_OFF += -w |
|
10 | QMAKE_CFLAGS_WARN_OFF += -w | |
11 | QMAKE_CFLAGS_RELEASE += -O2 |
|
11 | QMAKE_CFLAGS_RELEASE += -O2 | |
12 | QMAKE_CFLAGS_DEBUG += |
|
12 | QMAKE_CFLAGS_DEBUG += | |
13 |
|
13 | |||
14 | QMAKE_CXX = g++ |
|
14 | QMAKE_CXX = g++ | |
15 | QMAKE_CXXFLAGS += $$QMAKE_CFLAGS s |
|
15 | QMAKE_CXXFLAGS += $$QMAKE_CFLAGS s | |
16 | QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS |
|
16 | QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS | |
17 | QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON |
|
17 | QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON | |
18 | QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF |
|
18 | QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF | |
19 | QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE |
|
19 | QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE | |
20 | QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG |
|
20 | QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG | |
21 | QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB |
|
21 | QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB | |
22 | QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB |
|
22 | QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB | |
23 | QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC |
|
23 | QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC | |
24 | QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS |
|
24 | QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS | |
25 |
|
25 | |||
26 | QMAKE_LINK = gcc |
|
26 | 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 += | |
34 | QMAKE_LFLAGS_SHLIB += |
|
34 | QMAKE_LFLAGS_SHLIB += | |
35 | QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB |
|
35 | QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB | |
36 | QMAKE_LFLAGS_THREAD += |
|
36 | QMAKE_LFLAGS_THREAD += | |
37 |
|
37 | |||
38 | QMAKE_AR = ar -ru |
|
38 | QMAKE_AR = ar -ru | |
39 | QMAKE_LIB = ar -ru |
|
39 | QMAKE_LIB = ar -ru | |
40 | QMAKE_RANLIB = |
|
40 | QMAKE_RANLIB = | |
41 |
|
41 |
@@ -1,7 +1,35 | |||||
|
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 | { | |
5 | bsp_init(); |
|
33 | bsp_init(); | |
6 | libuc_main(); |
|
34 | libuc_main(); | |
7 | } |
|
35 | } |
@@ -1,88 +1,92 | |||||
1 | # |
|
1 | # | |
2 | # qmake configuration for stm32f4 |
|
2 | # qmake configuration for stm32f4 | |
3 | # |
|
3 | # | |
4 | # |
|
4 | # | |
5 |
|
5 | |||
6 |
|
6 | |||
7 | isEmpty(_stm32f4_conf){ |
|
7 | isEmpty(_stm32f4_conf){ | |
8 | _stm32f4_conf="oneshot" |
|
8 | _stm32f4_conf="oneshot" | |
9 |
|
9 | |||
10 | QMAKE_CFLAGS+= -g -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 |
|
10 | QMAKE_CFLAGS+= -g -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 | |
11 |
|
11 | |||
12 | include(../../common/arm-none-eabi.conf) |
|
12 | include(../../common/arm-none-eabi.conf) | |
13 |
|
13 | |||
14 | DEFINES += __OPTIMIZED_MATH |
|
14 | DEFINES += __OPTIMIZED_MATH | |
15 | DEFINES += \"assert_param(expr)=((void)0)\" |
|
15 | DEFINES += \"assert_param(expr)=((void)0)\" | |
16 | INCLUDEPATH += $$PWD |
|
16 | INCLUDEPATH += $$PWD | |
17 |
|
17 | |||
18 | DEFINES += __FPU_PRESENT=1 |
|
18 | DEFINES += __FPU_PRESENT=1 | |
19 | DEFINES += ARM_MATH_CM4 |
|
19 | DEFINES += ARM_MATH_CM4 | |
20 |
|
20 | |||
21 | DEFINES += BSP="\"\\\"$$BSP"\\\"\" |
|
21 | DEFINES += BSP="\"\\\"$$BSP"\\\"\" | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | contains(CPU, stm32f42x){ |
|
24 | contains(CPU, stm32f42x){ | |
25 | LDSCRIPT=stm32f42.ld |
|
25 | LDSCRIPT=stm32f42.ld | |
26 | } |
|
26 | } | |
27 | contains(CPU, stm32f4xxxG){ |
|
27 | contains(CPU, stm32f4xxxG){ | |
28 | LDSCRIPT=stm32f4.ld |
|
28 | LDSCRIPT=stm32f4.ld | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | contains( TEMPLATE, app ) { |
|
32 | contains( TEMPLATE, app ) { | |
33 |
|
33 | |||
34 | unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" $$escape_expand(\\n\\t) |
|
34 | unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" $$escape_expand(\\n\\t) | |
35 | unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O binary "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin" $$escape_expand(\\n\\t) |
|
35 | unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O binary "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin" $$escape_expand(\\n\\t) | |
36 | win32:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" $$escape_expand(\\n\\t) |
|
36 | win32:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" $$escape_expand(\\n\\t) | |
37 | win32:QMAKE_POST_LINK += arm-none-eabi-objcopy -O binary "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin" $$escape_expand(\\n\\t) |
|
37 | win32:QMAKE_POST_LINK += arm-none-eabi-objcopy -O binary "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin" $$escape_expand(\\n\\t) | |
38 |
|
38 | |||
39 | contains( CONFIG, dfu ){ |
|
39 | contains( CONFIG, dfu ){ | |
40 | unix:QMAKE_POST_LINK += python $$[QT_INSTALL_BINS]/dfu.py -b 0x08000000:$$DESTDIR/"$(QMAKE_TARGET).bin" $$DESTDIR/"$(QMAKE_TARGET).dfu" $$escape_expand(\\n\\t) |
|
40 | unix:QMAKE_POST_LINK += python $$[QT_INSTALL_BINS]/dfu.py -b 0x08000000:$$DESTDIR/"$(QMAKE_TARGET).bin" $$DESTDIR/"$(QMAKE_TARGET).dfu" $$escape_expand(\\n\\t) | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP -lbsp |
|
43 | LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP -lbsp | |
44 | LIBS += -L$$[QT_INSTALL_LIBS]/$$UCMODEL |
|
44 | LIBS += -L$$[QT_INSTALL_LIBS]/$$UCMODEL | |
45 | LIBS += -lcpu |
|
45 | LIBS += -lcpu | |
46 | LIBS += -lcore -lm -lc |
|
46 | LIBS += -lcore -lm -lc | |
47 |
|
47 | |||
48 | QMAKE_LFLAGS += -g -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 -T $$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/$$LDSCRIPT |
|
48 | QMAKE_LFLAGS += -g -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 -T $$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/$$LDSCRIPT | |
49 |
|
49 | |||
50 |
|
50 | |||
51 |
|
51 | |||
52 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/syscalls.c |
|
52 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/syscalls.c | |
53 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/fs.c |
|
53 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/fs.c | |
54 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/crt0.s |
|
54 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/crt0.s | |
55 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/cpuinit.c |
|
55 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/cpuinit.c | |
56 |
|
56 | |||
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 & | |
64 | gdb-server.depends = stflash |
|
68 | gdb-server.depends = stflash | |
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 | |||
72 |
|
76 | |||
73 | } |
|
77 | } | |
74 |
|
78 | |||
75 |
|
79 | |||
76 |
|
80 | |||
77 |
|
81 | |||
78 |
|
82 | |||
79 |
|
83 | |||
80 |
|
84 | |||
81 |
|
85 | |||
82 |
|
86 | |||
83 |
|
87 | |||
84 |
|
88 | |||
85 |
|
89 | |||
86 |
|
90 | |||
87 |
|
91 | |||
88 |
|
92 |
@@ -1,7 +1,35 | |||||
|
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 | { | |
5 | bsp_init(); |
|
33 | bsp_init(); | |
6 | libuc_main(); |
|
34 | libuc_main(); | |
7 | } |
|
35 | } |
@@ -1,14 +1,15 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | CONFIG += ordered |
|
2 | CONFIG += ordered | |
3 |
|
3 | |||
4 | SUBDIRS = CORE/core.pro \ |
|
4 | SUBDIRS = CORE/core.pro \ | |
5 | CPU/cpu.pro \ |
|
5 | CPU/cpu.pro \ | |
6 | GPIO/gpio.pro \ |
|
6 | GPIO/gpio.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