@@ -208,7 +208,7 void bsp_spi_init() | |||
|
208 | 208 | |
|
209 | 209 | void bsp_iic_init() |
|
210 | 210 | { |
|
211 |
i2copenandconfig(i2c2,0, |
|
|
211 | i2copenandconfig(i2c2,0,10000,PF0,PF1); | |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | void bsp_SD_init() |
@@ -306,3 +306,7 void bsp_GTerm_init() | |||
|
306 | 306 | |
|
307 | 307 | |
|
308 | 308 | |
|
309 | ||
|
310 | ||
|
311 | ||
|
312 |
@@ -1,6 +1,9 | |||
|
1 | 1 | CPU=stm32f4xxxG |
|
2 | 2 | DEFINES+=BSP=\\\"BEAGLESYNTH\\\" |
|
3 | 3 | beagleCp.target = beagleCp |
|
4 |
beagleCp.commands = scp |
|
|
5 | QMAKE_EXTRA_TARGETS += beagleCp | |
|
4 | beagleCp.commands = cd bin && scp $(QMAKE_TARGET).bin root@192.168.7.2://opt/stm32flashAje/hello.bin | |
|
5 | beagleCp131.target = beagleCp131 | |
|
6 | beagleCp131.commands = cd bin && scp $(QMAKE_TARGET).bin root@129.104.27.131://opt/stm32flashAje/hello.bin | |
|
7 | QMAKE_EXTRA_TARGETS += beagleCp beagleCp131 | |
|
8 | ||
|
6 | 9 | UCMODEL=stm32f4 |
@@ -247,7 +247,7 void bsp_spi_init() | |||
|
247 | 247 | |
|
248 | 248 | void bsp_iic_init() |
|
249 | 249 | { |
|
250 |
|
|
|
250 | i2copenandconfig(i2c1,0,100000,PB9,PB6); | |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | void bsp_SD_init() |
@@ -3,12 +3,21 CONFIG += cpu | |||
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | UCMODEL=stm32f4 |
|
6 |
DEFINES += CPUFREQ= |
|
|
6 | DEFINES += CPUFREQ=40000000 | |
|
7 | 7 | |
|
8 |
|
|
|
8 | BSP = BEAGLESYNTH | |
|
9 | 9 | #BSP = SOLAR_LFR_PSU |
|
10 | BSP = STM32F4Eval | |
|
10 | #BSP = STM32F4Eval | |
|
11 | 11 | |
|
12 | 12 | SOURCES += \ |
|
13 | 13 | main.c |
|
14 | 14 | |
|
15 | ||
|
16 | ||
|
17 | ||
|
18 | ||
|
19 | #beagleCp.target = beagleCp | |
|
20 | #beagleCp.commands = cd bin && scp $(QMAKE_TARGET).bin root@192.168.7.2://opt/stm32flashAje/hello.bin | |
|
21 | #beagleCp131.target = beagleCp131 | |
|
22 | #beagleCp131.commands = cd bin && scp $(QMAKE_TARGET).bin root@129.104.27.131://opt/stm32flashAje/hello.bin | |
|
23 | #QMAKE_EXTRA_TARGETS += beagleCp beagleCp131 |
@@ -11,6 +11,7 | |||
|
11 | 11 | #include <fonts.h> |
|
12 | 12 | #include <stdlib.h> |
|
13 | 13 | #include <core.h> |
|
14 | #include <malloc.h> | |
|
14 | 15 | |
|
15 | 16 | |
|
16 | 17 | extern streamdevice* __opnfiles__[]; |
@@ -30,13 +31,21 extern streamdevice* __opnfiles__[]; | |||
|
30 | 31 | #define PSU_DISABLE LED1 |
|
31 | 32 | #endif |
|
32 | 33 | |
|
34 | void setUartAsStdout() | |
|
35 | { | |
|
36 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
|
37 | uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); | |
|
38 | uartmkstreamdev(uart,fd1); | |
|
39 | __opnfiles__[1] = fd1; | |
|
40 | } | |
|
33 | 41 | |
|
34 | 42 | int main() |
|
35 | 43 | { |
|
36 | 44 | delay_100us(20000); |
|
37 | 45 | INA226_t ina5VSens,ina33VSens,ina15VSens; |
|
38 | 46 | gpioset(PSU_DISABLE);//enable psu! |
|
39 | ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_BLACK); | |
|
47 | setUartAsStdout(); | |
|
48 | //ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_BLACK); | |
|
40 | 49 | if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000)) |
|
41 | 50 | { |
|
42 | 51 | printf("Can't open 3.3V monitor\n\r"); |
@@ -55,9 +64,10 int main() | |||
|
55 | 64 | current5V = ina226getCurrent(&ina5VSens); |
|
56 | 65 | current33V = ina226getCurrent(&ina33VSens); |
|
57 | 66 | current15V = ina226getCurrent(&ina15VSens); |
|
58 | printf("%dmA\n",current15V/1000); | |
|
59 | printf("%dmA\n",current33V/1000); | |
|
60 | printf("%dmA\n",current5V/1000); | |
|
67 | printf("%dmA\n\r",current15V/1000); | |
|
68 | printf("%dmA\n\r",current33V/1000); | |
|
69 | printf("%dmA\n\r",current5V/1000); | |
|
70 | delay_100us(10000); | |
|
61 | 71 | } |
|
62 | 72 | printf("Exit\n\r"); |
|
63 | 73 | return 0; |
@@ -6,7 +6,7 UCMODEL=stm32f4 | |||
|
6 | 6 | |
|
7 | 7 | BSP = STM32F4Eval |
|
8 | 8 | |
|
9 |
DEFINES += CPUFREQ= |
|
|
9 | DEFINES += CPUFREQ=40000000 | |
|
10 | 10 | |
|
11 | 11 | SOURCES += \ |
|
12 | 12 | main.c |
@@ -26,9 +26,17 extern streamdevice* __opnfiles__[__MAX_ | |||
|
26 | 26 | #define LCD_COLOR_CYAN 0x7FFF |
|
27 | 27 | #define LCD_COLOR_YELLOW 0xFFE0 |
|
28 | 28 | |
|
29 | void testAudioDAC() | |
|
30 | { | |
|
31 | CS43L22_t dac; | |
|
32 | cs43l22open(&dac,i2c1,0); | |
|
33 | uint8_t ID= cs43l22getID(&dac); | |
|
34 | printf("dac ID = %d\n\r",ID); | |
|
35 | } | |
|
29 | 36 | |
|
30 | 37 | int main() |
|
31 | 38 | { |
|
39 | delay_100us(10000); | |
|
32 | 40 | uint16_t innerbuffer[16]; |
|
33 | 41 | uint16_t outterbuffer[16]; |
|
34 | 42 | for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE; |
@@ -48,6 +56,8 int main() | |||
|
48 | 56 | printf("Line cnt :\n \t%d\n",terminal0.lineCount); |
|
49 | 57 | printf("Column cnt :\n \t%d\n",terminal0.columnCount); |
|
50 | 58 | printf("CPU Freq :\n \t%dMHz\n",getCpuFreq()/1000000); |
|
59 | //testAudioDAC(); | |
|
60 | i2cwrite(i2c1,0x4a," ",1); | |
|
51 | 61 | while(1) |
|
52 | 62 | { |
|
53 | 63 | i%=1000; |
@@ -29,7 +29,7 int ina226open(INA226_t *dev, i2c_t i2cd | |||
|
29 | 29 | if(dev != NULL) |
|
30 | 30 | { |
|
31 | 31 | dev->i2cdev=i2cdev; |
|
32 |
dev->devAddress = INA226_I2C_ADDRESS | (A0 & 1) | ((A1<< |
|
|
32 | dev->devAddress = INA226_I2C_ADDRESS | (A0 & 1) | ((A1<<2) & 5); | |
|
33 | 33 | printf("dev->devAddress = %x\n\r",dev->devAddress); |
|
34 | 34 | dev->shuntmOhm = shuntmOhm; |
|
35 | 35 | dev->CurrentRangeuAmp = CurrentRangeuAmp; |
@@ -39,8 +39,7 i2c_t i2copen(int count) | |||
|
39 | 39 | #define _INIT_DEV(_RCC_) \ |
|
40 | 40 | RCC_APB1PeriphClockCmd(_RCC_, ENABLE); \ |
|
41 | 41 | RCC_APB1PeriphResetCmd(_RCC_, ENABLE); \ |
|
42 |
RCC_APB1PeriphResetCmd(_RCC_, DISABLE); |
|
|
43 | RCC_APB1PeriphClockCmd(_RCC_, ENABLE); | |
|
42 | RCC_APB1PeriphResetCmd(_RCC_, DISABLE); | |
|
44 | 43 | |
|
45 | 44 | switch(count) |
|
46 | 45 | { |
@@ -70,7 +69,7 i2c_t i2copenandconfig(int count,uint32_ | |||
|
70 | 69 | i2cclose(dev); |
|
71 | 70 | i2csetpins(dev,SDA,SCL); |
|
72 | 71 | i2copen(count); |
|
73 | i2cenable(count); | |
|
72 | //i2cenable(count); | |
|
74 | 73 | //I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
75 | 74 | i2csetspeed(dev,speed); |
|
76 | 75 | i2cenable(count); |
@@ -99,7 +98,7 int i2cclose(i2c_t dev) | |||
|
99 | 98 | |
|
100 | 99 | int i2csetpins(i2c_t dev, uint32_t SDA, uint32_t SCL) |
|
101 | 100 | { |
|
102 |
if((dev< |
|
|
101 | if((dev<i2c4)&&(dev>=i2c1)) | |
|
103 | 102 | { |
|
104 | 103 | gpio_t SDApin,SCLpin; |
|
105 | 104 | SDApin = gpioopen(SDA); |
@@ -144,7 +143,7 int i2csetpins(i2c_t dev, uint32_t SDA, | |||
|
144 | 143 | |
|
145 | 144 | int i2cenable(i2c_t dev) |
|
146 | 145 | { |
|
147 |
if((dev< |
|
|
146 | if((dev<i2c4)&&(dev>=i2c1)) | |
|
148 | 147 | { |
|
149 | 148 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
150 | 149 | _dev_->CR1 |=1 ; |
@@ -155,7 +154,7 int i2cenable(i2c_t dev) | |||
|
155 | 154 | |
|
156 | 155 | int i2cdisable(i2c_t dev) |
|
157 | 156 | { |
|
158 |
if((dev< |
|
|
157 | if((dev<i2c4)&&(dev>=i2c1)) | |
|
159 | 158 | { |
|
160 | 159 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
161 | 160 | _dev_->CR1 &= ~1; |
@@ -167,7 +166,7 int i2cdisable(i2c_t dev) | |||
|
167 | 166 | |
|
168 | 167 | int i2csetspeed(i2c_t dev,uint32_t speed) |
|
169 | 168 | { |
|
170 |
if((dev< |
|
|
169 | if((dev<i2c4)&&(dev>=i2c1)) | |
|
171 | 170 | { |
|
172 | 171 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
173 | 172 | int32_t APB1Freq=getAPB1Freq()/1000000; |
@@ -193,9 +192,9 int i2csetspeed(i2c_t dev,uint32_t speed | |||
|
193 | 192 | } |
|
194 | 193 | else |
|
195 | 194 | { |
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
195 | tmpreg &= ~(1<<15); | |
|
196 | tmpreg &= ~(0xfff); | |
|
197 | tmpreg |= 0xfff & (APB1Freq/(2*speed)); | |
|
199 | 198 | } |
|
200 | 199 | _dev_->CCR=tmpreg; |
|
201 | 200 | tmpreg=_dev_->TRISE; |
@@ -211,7 +210,7 int i2csetspeed(i2c_t dev,uint32_t speed | |||
|
211 | 210 | |
|
212 | 211 | int i2cbusy(i2c_t dev) |
|
213 | 212 | { |
|
214 |
if((dev< |
|
|
213 | if((dev<i2c4)&&(dev>=i2c1)) | |
|
215 | 214 | { |
|
216 | 215 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
217 | 216 | if((_dev_->SR2 & 2) ==2) return 1; /* Dev is busy */ |
@@ -222,25 +221,37 int i2cbusy(i2c_t dev) | |||
|
222 | 221 | |
|
223 | 222 | int i2cwrite(i2c_t dev,char address,char* data,int count) |
|
224 | 223 | { |
|
225 |
if((dev< |
|
|
224 | if((dev<i2c4)&&(dev>=i2c1)) | |
|
226 | 225 | { |
|
227 | 226 | int timeout=i2ctimeout; |
|
228 | 227 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
229 | 228 | while(i2cbusy(dev)) |
|
230 | 229 | { |
|
231 |
if(0==(timeout--)) |
|
|
230 | if(0==(timeout--)) | |
|
231 | { | |
|
232 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
233 | return -1; | |
|
234 | } | |
|
232 | 235 | } |
|
233 | 236 | _dev_->CR1 |= 1<<8; |
|
234 | 237 | timeout=i2ctimeout; |
|
235 | 238 | while(!i2cStatusCheck(dev,((uint32_t)0x00030001))) |
|
236 | 239 | { |
|
237 |
if(0==(timeout--)) |
|
|
240 | if(0==(timeout--)) | |
|
241 | { | |
|
242 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
243 | return -1; | |
|
244 | } | |
|
238 | 245 | } |
|
239 | 246 | _dev_->DR= address<<1; |
|
240 | 247 | timeout=i2ctimeout; |
|
241 | 248 | while(!i2cStatusCheck(dev, ((uint32_t)0x00070082))) |
|
242 | 249 | { |
|
243 |
if(0==(timeout--)) |
|
|
250 | if(0==(timeout--)) | |
|
251 | { | |
|
252 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
253 | return -1; | |
|
254 | } | |
|
244 | 255 | } |
|
245 | 256 | address=_dev_->SR2; |
|
246 | 257 | for(int i=0;i<count;i++) |
@@ -248,19 +259,31 int i2cwrite(i2c_t dev,char address,char | |||
|
248 | 259 | timeout=i2ctimeout; |
|
249 | 260 | while(!i2cStatusCheck(dev,((uint32_t)0x00070080))) |
|
250 | 261 | { |
|
251 |
if(0==(timeout--)) |
|
|
262 | if(0==(timeout--)) | |
|
263 | { | |
|
264 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
265 | return -1; | |
|
266 | } | |
|
252 | 267 | } |
|
253 | 268 | _dev_->DR= data[i]; |
|
254 | 269 | } |
|
255 | 270 | timeout=i2ctimeout; |
|
256 | 271 | while(!i2cStatusCheck(dev,1<<7)) |
|
257 | 272 | { |
|
258 |
if(0==(timeout--)) |
|
|
273 | if(0==(timeout--)) | |
|
274 | { | |
|
275 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
276 | return -1; | |
|
277 | } | |
|
259 | 278 | } |
|
260 | 279 | timeout=i2ctimeout; |
|
261 | 280 | while(!i2cStatusCheck(dev,1<<2)) |
|
262 | 281 | { |
|
263 |
if(0==(timeout--)) |
|
|
282 | if(0==(timeout--)) | |
|
283 | { | |
|
284 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
285 | return -1; | |
|
286 | } | |
|
264 | 287 | } |
|
265 | 288 | _dev_->CR1 |= 1<<9; |
|
266 | 289 | return count; |
@@ -270,25 +293,37 int i2cwrite(i2c_t dev,char address,char | |||
|
270 | 293 | |
|
271 | 294 | int i2cread(i2c_t dev,char address,char* data,int count) |
|
272 | 295 | { |
|
273 |
if((dev< |
|
|
296 | if((dev<i2c4)&&(dev>=i2c1)) | |
|
274 | 297 | { |
|
275 | 298 | int i=0; |
|
276 | 299 | int timeout=i2ctimeout; |
|
277 | 300 | while(i2cbusy(dev)) |
|
278 | 301 | { |
|
279 |
if(0==(timeout--)) |
|
|
302 | if(0==(timeout--)) | |
|
303 | { | |
|
304 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
305 | return -1; | |
|
306 | } | |
|
280 | 307 | } |
|
281 | 308 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
282 | 309 | _dev_->CR1 |= (1<<8) + (1<<10); |
|
283 | 310 | timeout=i2ctimeout; |
|
284 | 311 | while(!i2cStatusCheck(dev,0x00030001)) |
|
285 | 312 | { |
|
286 |
if(0==(timeout--)) |
|
|
313 | if(0==(timeout--)) | |
|
314 | { | |
|
315 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
316 | return -1; | |
|
317 | } | |
|
287 | 318 | } |
|
288 | 319 | _dev_->DR= (address<<1) + 1; |
|
289 | 320 | while(!i2cStatusCheck(dev,0x000002)) |
|
290 | 321 | { |
|
291 |
if(0==(timeout--)) |
|
|
322 | if(0==(timeout--)) | |
|
323 | { | |
|
324 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
325 | return -1; | |
|
326 | } | |
|
292 | 327 | } |
|
293 | 328 | if(count==1) |
|
294 | 329 | { |
@@ -300,7 +335,11 int i2cread(i2c_t dev,char address,char* | |||
|
300 | 335 | timeout=i2ctimeout; |
|
301 | 336 | while(!i2cStatusCheck(dev,0x0000040)) |
|
302 | 337 | { |
|
303 |
if(0==(timeout--)) |
|
|
338 | if(0==(timeout--)) | |
|
339 | { | |
|
340 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
341 | return -1; | |
|
342 | } | |
|
304 | 343 | } |
|
305 | 344 | data[i]=_dev_->DR; |
|
306 | 345 | } |
@@ -309,13 +348,21 int i2cread(i2c_t dev,char address,char* | |||
|
309 | 348 | timeout=i2ctimeout; |
|
310 | 349 | while(!i2cStatusCheck(dev,0x0000040)) |
|
311 | 350 | { |
|
312 |
if(0==(timeout--)) |
|
|
351 | if(0==(timeout--)) | |
|
352 | { | |
|
353 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
354 | return -1; | |
|
355 | } | |
|
313 | 356 | } |
|
314 | 357 | data[i]=_dev_->DR; |
|
315 | 358 | timeout=i2ctimeout; |
|
316 | 359 | while(_dev_->CR1 & ((uint16_t)0x0200)) |
|
317 | 360 | { |
|
318 |
if(0==(timeout--)) |
|
|
361 | if(0==(timeout--)) | |
|
362 | { | |
|
363 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
|
364 | return -1; | |
|
365 | } | |
|
319 | 366 | } |
|
320 | 367 | _dev_->CR1 |= 1<<10; |
|
321 | 368 | return count; |
@@ -327,7 +374,7 int i2cread(i2c_t dev,char address,char* | |||
|
327 | 374 | int i2cStatusCheck(i2c_t dev,int32_t flagMask) |
|
328 | 375 | { |
|
329 | 376 | int32_t flag; |
|
330 |
if((dev< |
|
|
377 | if((dev<i2c4)&&(dev>=i2c1)) | |
|
331 | 378 | { |
|
332 | 379 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
333 | 380 | flag= _dev_->SR1 + (_dev_->SR2<<16); |
General Comments 0
You need to be logged in to leave comments.
Login now