@@ -1,132 +1,126 | |||||
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@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
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 <gpio.h> |
|
25 | #include <gpio.h> | |
26 | #include <uart.h> |
|
26 | #include <uart.h> | |
27 | #include <stdio.h> |
|
27 | #include <stdio.h> | |
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 | float VREF0 =(float)3.3; |
|
34 | float VREF0 =(float)3.3; | |
35 |
|
35 | |||
36 | int bsp_init() |
|
36 | int bsp_init() | |
37 | { |
|
37 | { | |
38 | int i=0; |
|
38 | int i=0; | |
39 | for(i=0;i<32;i++) |
|
39 | for(i=0;i<32;i++) | |
40 | { |
|
40 | { | |
41 | __opnfiles__[i] = NULL; |
|
41 | __opnfiles__[i] = NULL; | |
42 | } |
|
42 | } | |
43 | bsp_GPIO_init(); |
|
43 | bsp_GPIO_init(); | |
44 | bsp_uart_init(); |
|
44 | bsp_uart_init(); | |
45 | printf("\r================================================================\n\r"); |
|
45 | printf("\r================================================================\n\r"); | |
46 | printf("================================================================\n\r"); |
|
46 | printf("================================================================\n\r"); | |
47 | printf(BSP); |
|
47 | printf(BSP); | |
48 | printf(" initialised\n\r"); |
|
48 | printf(" initialised\n\r"); | |
49 | printf("================================================================\n\r"); |
|
49 | printf("================================================================\n\r"); | |
50 | return 1; |
|
50 | return 1; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void bsp_GPIO_init() |
|
53 | void bsp_GPIO_init() | |
54 | { |
|
54 | { | |
55 |
gpio_t gpio1 = gpioopen(P |
|
55 | gpio_t gpio1 = gpioopen(PC6);//gpioopen(LED1); //PD9 D=> 0x0300 9 => 0x0009 | |
56 |
gpio_t gpio2 = gpioopen(P |
|
56 | gpio_t gpio2 = gpioopen(PC7);//gpioopen(LED2); | |
57 | gpio_t gpio3 = gpioopen(PD14);//gpioopen(LED2); |
|
|||
58 | gpio_t gpio4 = gpioopen(PD15);//gpioopen(LED2); |
|
|||
59 | gpiosetspeed(&gpio1,gpiohighspeed); |
|
57 | gpiosetspeed(&gpio1,gpiohighspeed); | |
60 | gpiosetspeed(&gpio2,gpiohighspeed); |
|
58 | gpiosetspeed(&gpio2,gpiohighspeed); | |
61 | gpiosetspeed(&gpio3,gpiohighspeed); |
|
|||
62 | gpiosetspeed(&gpio4,gpiohighspeed); |
|
|||
63 | gpiosetdir(&gpio1,gpiooutdir); |
|
59 | gpiosetdir(&gpio1,gpiooutdir); | |
64 | gpiosetdir(&gpio3,gpiooutdir); |
|
|||
65 | gpiosetdir(&gpio2,gpiooutdir); |
|
60 | gpiosetdir(&gpio2,gpiooutdir); | |
66 | gpiosetdir(&gpio4,gpiooutdir); |
|
|||
67 | } |
|
61 | } | |
68 |
|
62 | |||
69 | void bsp_uart_init() |
|
63 | void bsp_uart_init() | |
70 | { |
|
64 | { | |
71 | if(__opnfiles__[1]==NULL) |
|
65 | if(__opnfiles__[1]==NULL) | |
72 | { |
|
66 | { | |
73 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
67 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
74 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
68 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
75 |
uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200, |
|
69 | uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,LED2,LED1,-1,-1); | |
76 | uartmkstreamdev(uart,fd1); |
|
70 | uartmkstreamdev(uart,fd1); | |
77 | __opnfiles__[1] = fd1; |
|
71 | __opnfiles__[1] = fd1; | |
78 | } |
|
72 | } | |
79 | else |
|
73 | else | |
80 | { |
|
74 | { | |
81 |
uartopenandconfig( |
|
75 | uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,LED2,LED1,-1,-1); | |
82 | } |
|
76 | } | |
83 | } |
|
77 | } | |
84 |
|
78 | |||
85 | void bsp_spi_init() |
|
79 | void bsp_spi_init() | |
86 | { |
|
80 | { | |
87 |
|
81 | |||
88 | } |
|
82 | } | |
89 |
|
83 | |||
90 |
|
84 | |||
91 | void bsp_iic_init() |
|
85 | void bsp_iic_init() | |
92 | { |
|
86 | { | |
93 |
|
87 | |||
94 | } |
|
88 | } | |
95 |
|
89 | |||
96 | void bsp_SD_init() |
|
90 | void bsp_SD_init() | |
97 | { |
|
91 | { | |
98 |
|
92 | |||
99 | } |
|
93 | } | |
100 |
|
94 | |||
101 | void vs10XXclearXCS(){} |
|
95 | void vs10XXclearXCS(){} | |
102 | void vs10XXsetXCS(){} |
|
96 | void vs10XXsetXCS(){} | |
103 | int vs10XXDREQ() |
|
97 | int vs10XXDREQ() | |
104 | { |
|
98 | { | |
105 | return 1; |
|
99 | return 1; | |
106 | } |
|
100 | } | |
107 |
|
101 | |||
108 |
|
102 | |||
109 | void bsppowersdcard(char onoff) //always ON |
|
103 | void bsppowersdcard(char onoff) //always ON | |
110 | { |
|
104 | { | |
111 |
|
105 | |||
112 | } |
|
106 | } | |
113 |
|
107 | |||
114 | char bspsdcardpresent() |
|
108 | char bspsdcardpresent() | |
115 | { |
|
109 | { | |
116 | return 0; |
|
110 | return 0; | |
117 | } |
|
111 | } | |
118 |
|
112 | |||
119 | char bspsdcardwriteprotected() |
|
113 | char bspsdcardwriteprotected() | |
120 | { |
|
114 | { | |
121 | return 0; |
|
115 | return 0; | |
122 | } |
|
116 | } | |
123 |
|
117 | |||
124 | void bspsdcardselect(char YESNO) |
|
118 | void bspsdcardselect(char YESNO) | |
125 | { |
|
119 | { | |
126 |
|
120 | |||
127 | } |
|
121 | } | |
128 |
|
122 | |||
129 |
|
123 | |||
130 |
|
124 | |||
131 |
|
125 | |||
132 |
|
126 |
@@ -1,109 +1,109 | |||||
1 | #include <stdio.h> |
|
1 | #include <stdio.h> | |
2 | #include <fat32.h> |
|
2 | #include <fat32.h> | |
3 | #include <gpio.h> |
|
3 | #include <gpio.h> | |
4 | #include <uart.h> |
|
4 | #include <uart.h> | |
5 | #include <stm32f4xx.h> |
|
5 | #include <stm32f4xx.h> | |
6 | #include <math.h> |
|
6 | #include <math.h> | |
7 | #include <bsp.h> |
|
7 | #include <bsp.h> | |
8 | #include <i2c.h> |
|
8 | #include <i2c.h> | |
9 | #include <CS43L22.h> |
|
9 | #include <CS43L22.h> | |
10 | #include <ina226.h> |
|
10 | #include <ina226.h> | |
11 | #include <fonts.h> |
|
11 | #include <fonts.h> | |
12 | #include <stdlib.h> |
|
12 | #include <stdlib.h> | |
13 | #include <core.h> |
|
13 | #include <core.h> | |
14 |
|
14 | |||
15 |
|
15 | |||
16 | extern streamdevice* __opnfiles__[]; |
|
16 | extern streamdevice* __opnfiles__[]; | |
17 |
|
17 | |||
18 | #define LCD_COLOR_WHITE 0xFFFF |
|
18 | #define LCD_COLOR_WHITE 0xFFFF | |
19 | #define LCD_COLOR_BLACK 0x0000 |
|
19 | #define LCD_COLOR_BLACK 0x0000 | |
20 | #define LCD_COLOR_GREY 0xF7DE |
|
20 | #define LCD_COLOR_GREY 0xF7DE | |
21 | #define LCD_COLOR_BLUE 0x001F |
|
21 | #define LCD_COLOR_BLUE 0x001F | |
22 | #define LCD_COLOR_BLUE2 0x051F |
|
22 | #define LCD_COLOR_BLUE2 0x051F | |
23 | #define LCD_COLOR_RED 0xF800 |
|
23 | #define LCD_COLOR_RED 0xF800 | |
24 | #define LCD_COLOR_MAGENTA 0xF81F |
|
24 | #define LCD_COLOR_MAGENTA 0xF81F | |
25 | #define LCD_COLOR_GREEN 0x07E0 |
|
25 | #define LCD_COLOR_GREEN 0x07E0 | |
26 | #define LCD_COLOR_CYAN 0x7FFF |
|
26 | #define LCD_COLOR_CYAN 0x7FFF | |
27 | #define LCD_COLOR_YELLOW 0xFFE0 |
|
27 | #define LCD_COLOR_YELLOW 0xFFE0 | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | void monkDemo() |
|
30 | void monkDemo() | |
31 | { |
|
31 | { | |
32 | while(1) |
|
32 | while(1) | |
33 | { |
|
33 | { | |
34 | lcd0.paintText(&lcd0," ",10,Monk_24.Height+10,&Monk_24,LCD_COLOR_BLACK); |
|
34 | lcd0.paintText(&lcd0," ",10,Monk_24.Height+10,&Monk_24,LCD_COLOR_BLACK); | |
35 | lcd0.paintText(&lcd0," ",230-Monk_24.Width,310,&Monk_24,LCD_COLOR_BLUE); |
|
35 | lcd0.paintText(&lcd0," ",230-Monk_24.Width,310,&Monk_24,LCD_COLOR_BLUE); | |
36 | for(volatile int i=0;i<(1024*1024*16);i++); |
|
36 | for(volatile int i=0;i<(1024*1024*16);i++); | |
37 | lcd0.paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_WHITE,1,LCD_COLOR_WHITE); |
|
37 | lcd0.paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_WHITE,1,LCD_COLOR_WHITE); | |
38 | for(volatile int i=0;i<(1024*1024*4);i++); |
|
38 | for(volatile int i=0;i<(1024*1024*4);i++); | |
39 | } |
|
39 | } | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 |
|
42 | |||
43 | void randBoxesDemo() |
|
43 | void randBoxesDemo() | |
44 | { |
|
44 | { | |
45 | int16_t x,y,w,h,t,r; |
|
45 | int16_t x,y,w,h,t,r; | |
46 | x=rand()%240; |
|
46 | x=rand()%240; | |
47 | y=rand()%320; |
|
47 | y=rand()%320; | |
48 | w=rand()%(240-x); |
|
48 | w=rand()%(240-x); | |
49 | if(x>y) |
|
49 | if(x>y) | |
50 | r=(rand()%(y))%(320-y); |
|
50 | r=(rand()%(y))%(320-y); | |
51 | else |
|
51 | else | |
52 | r=(rand()%(x))%(240-x); |
|
52 | r=(rand()%(x))%(240-x); | |
53 | h=rand()%(320-y); |
|
53 | h=rand()%(320-y); | |
54 | t=rand()%(10); |
|
54 | t=rand()%(10); | |
55 | ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
55 | ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); | |
56 | ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
56 | ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); | |
57 | //delay_100us(10); |
|
57 | //delay_100us(10); | |
58 | //for(volatile int i=0;i<(1024*2);i++); |
|
58 | //for(volatile int i=0;i<(1024*2);i++); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | int main() |
|
61 | int main() | |
62 | { |
|
62 | { | |
63 | INA226_t ina5VSens,ina33VSens,ina15VSens; |
|
63 | INA226_t ina5VSens,ina33VSens,ina15VSens; | |
64 | gpioset(PSU_DISABLE); |
|
64 | gpioset(PSU_DISABLE); | |
65 | volatile int16_t* regtest=(volatile int16_t*)0x60000000; |
|
65 | volatile int16_t* regtest=(volatile int16_t*)0x60000000; | |
66 | volatile int16_t* regtest2=(volatile int16_t*)(0x61FFFFF0); |
|
66 | volatile int16_t* regtest2=(volatile int16_t*)(0x61FFFFF0); | |
67 | //ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000); |
|
67 | //ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000); | |
68 | //ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000); |
|
68 | //ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000); | |
69 | *regtest=(int16_t)0; |
|
69 | *regtest=(int16_t)0; | |
70 | printf("LCD ID=%x\n\r",0xFFFF&(*regtest2)); |
|
70 | printf("LCD ID=%x\n\r",0xFFFF&(*regtest2)); | |
71 | printf("Sys Tick=%d\n\r",SysTick->VAL); |
|
71 | printf("Sys Tick=%d\n\r",SysTick->VAL); | |
72 | printf("Sys Tick=%d\n\r",SysTick->VAL); |
|
72 | printf("Sys Tick=%d\n\r",SysTick->VAL); | |
73 | printf("Sys Tick=%d\n\r",SysTick->VAL); |
|
73 | printf("Sys Tick=%d\n\r",SysTick->VAL); | |
74 | printf("Sys Tick=%d\n\r",SysTick->VAL); |
|
74 | printf("Sys Tick=%d\n\r",SysTick->VAL); | |
75 | ili9328paintFilRect(&lcd0,1,1,3,3,LCD_COLOR_BLACK,1,LCD_COLOR_WHITE); |
|
75 | ili9328paintFilRect(&lcd0,1,1,3,3,LCD_COLOR_BLACK,1,LCD_COLOR_WHITE); | |
76 |
while(1) |
|
76 | while(1)monkDemo(); //randBoxesDemo(); | |
77 | if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,1,15,1000000)) |
|
77 | if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,1,15,1000000)) | |
78 | { |
|
78 | { | |
79 | printf("Can't open 3.3V monitor\n\r"); |
|
79 | printf("Can't open 3.3V monitor\n\r"); | |
80 | } |
|
80 | } | |
81 | int current5V,current33V,current15V; |
|
81 | int current5V,current33V,current15V; | |
82 | printf("\t5V\t3.3V\n\r"); |
|
82 | printf("\t5V\t3.3V\n\r"); | |
83 | while(1) |
|
83 | while(1) | |
84 | { |
|
84 | { | |
85 | for(volatile int i=0;i<1024*1024;i++); |
|
85 | for(volatile int i=0;i<1024*1024;i++); | |
86 | gpioset(LED1); |
|
86 | gpioset(LED1); | |
87 | gpioclr(LED2); |
|
87 | gpioclr(LED2); | |
88 | for(volatile int i=0;i<1024*1024;i++); |
|
88 | for(volatile int i=0;i<1024*1024;i++); | |
89 | gpioclr(LED1); |
|
89 | gpioclr(LED1); | |
90 | gpioset(LED2); |
|
90 | gpioset(LED2); | |
91 | //current5V = ina226getCurrent(&ina5VSens); |
|
91 | //current5V = ina226getCurrent(&ina5VSens); | |
92 | current33V = ina226getCurrent(&ina33VSens); |
|
92 | current33V = ina226getCurrent(&ina33VSens); | |
93 | //current15V = ina226getCurrent(&ina15VSens); |
|
93 | //current15V = ina226getCurrent(&ina15VSens); | |
94 | //current = ina226getReg(&Psens1,INA226_Current_Reg); |
|
94 | //current = ina226getReg(&Psens1,INA226_Current_Reg); | |
95 | //printf("%duA %dmA\t%duA %dmA\n\r",current5V,current5V/1000,current33V,current33V/1000); |
|
95 | //printf("%duA %dmA\t%duA %dmA\n\r",current5V,current5V/1000,current33V,current33V/1000); | |
96 | printf("%duA %dmA\n\r",current33V,current33V/1000); |
|
96 | printf("%duA %dmA\n\r",current33V,current33V/1000); | |
97 | } |
|
97 | } | |
98 | printf("hello world\n\r"); |
|
98 | printf("hello world\n\r"); | |
99 | return 0; |
|
99 | return 0; | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 |
|
102 | |||
103 |
|
103 | |||
104 |
|
104 | |||
105 |
|
105 | |||
106 |
|
106 | |||
107 |
|
107 | |||
108 |
|
108 | |||
109 |
|
109 |
@@ -1,12 +1,13 | |||||
1 | TEMPLATE = app |
|
1 | TEMPLATE = app | |
2 | CONFIG += console |
|
2 | CONFIG += console | |
3 | CONFIG -= qt |
|
3 | CONFIG -= qt | |
4 |
|
4 | |||
5 | #BSP = BEAGLESYNTH |
|
5 | #BSP = BEAGLESYNTH | |
6 | BSP = SOLAR_LFR_PSU |
|
6 | #BSP = SOLAR_LFR_PSU | |
|
7 | BSP=M4Stick | |||
7 | include($$(libuc2)/bsp/cfg/$$BSP/bsp.pri) |
|
8 | include($$(libuc2)/bsp/cfg/$$BSP/bsp.pri) | |
8 | #include($$(libuc2)/rules/stm32f4-arm-none-eabi-gcc/rules.pri) |
|
9 | #include($$(libuc2)/rules/stm32f4-arm-none-eabi-gcc/rules.pri) | |
9 |
|
10 | |||
10 | SOURCES += \ |
|
11 | SOURCES += \ | |
11 | main.c |
|
12 | main.c | |
12 |
|
13 |
@@ -1,45 +1,43 | |||||
1 | #include <stdio.h> |
|
1 | #include <stdio.h> | |
2 | #include <fat32.h> |
|
2 | #include <fat32.h> | |
3 | #include <gpio.h> |
|
3 | #include <gpio.h> | |
4 | #include <uart.h> |
|
4 | #include <uart.h> | |
5 | #include <stm32f4xx.h> |
|
5 | #include <stm32f4xx.h> | |
6 | #include <bsp.h> |
|
6 | #include <bsp.h> | |
7 |
|
7 | #include <core.h> | ||
8 |
|
8 | |||
9 | extern streamdevice* __opnfiles__[]; |
|
9 | extern streamdevice* __opnfiles__[]; | |
10 |
|
10 | |||
11 | int main() |
|
11 | int main() | |
12 | { |
|
12 | { | |
13 | //gpioset(PSU_DISABLE); |
|
|||
14 |
|
|
13 | while(1) | |
15 | { |
|
14 | { | |
16 | for(volatile int i=0;i<1024*2048;i++); |
|
|||
17 | gpioset(LED1); |
|
15 | gpioset(LED1); | |
18 | gpioclr(LED2); |
|
16 | gpioclr(LED2); | |
19 | for(volatile int i=0;i<1024*2048;i++); |
|
|||
20 | gpioclr(LED1); |
|
17 | gpioclr(LED1); | |
21 | gpioset(LED2); |
|
18 | gpioset(LED2); | |
|
19 | printf("Hello\n\r"); | |||
22 | } |
|
20 | } | |
23 | printf("hello world\n\r"); |
|
21 | printf("hello world\n\r"); | |
24 | return 0; |
|
22 | return 0; | |
25 | } |
|
23 | } | |
26 |
|
24 | |||
27 |
|
25 | |||
28 |
|
26 | |||
29 | void USART3_IRQHandler(void) |
|
27 | void USART3_IRQHandler(void) | |
30 | { |
|
28 | { | |
31 | while(1) |
|
29 | while(1) | |
32 | { |
|
30 | { | |
33 | for(volatile int i=0;i<1024*2048;i++); |
|
31 | for(volatile int i=0;i<1024*2048;i++); | |
34 | gpioset(PD12); |
|
32 | gpioset(PD12); | |
35 | gpioclr(PD14); |
|
33 | gpioclr(PD14); | |
36 | for(volatile int i=0;i<1024*2048;i++); |
|
34 | for(volatile int i=0;i<1024*2048;i++); | |
37 | gpioclr(PD12); |
|
35 | gpioclr(PD12); | |
38 | gpioset(PD14); |
|
36 | gpioset(PD14); | |
39 | } |
|
37 | } | |
40 | } |
|
38 | } | |
41 |
|
39 | |||
42 |
|
40 | |||
43 |
|
41 | |||
44 |
|
42 | |||
45 |
|
43 |
@@ -1,60 +1,60 | |||||
1 | #include "stm32f4xx.h" |
|
1 | #include "stm32f4xx.h" | |
2 | #include <stdint.h> |
|
2 | #include <stdint.h> | |
3 | #include <stdlib.h> |
|
3 | #include <stdlib.h> | |
4 | #include <stdio.h> |
|
4 | #include <stdio.h> | |
5 | #include <bsp.h> |
|
5 | #include <bsp.h> | |
6 | #include <stm32f4xx_rcc.h> |
|
6 | #include <stm32f4xx_rcc.h> | |
7 | #include <core.h> |
|
7 | #include <core.h> | |
8 | extern int main(); |
|
8 | extern int main(); | |
9 |
|
9 | |||
10 |
|
10 | |||
11 |
|
11 | |||
12 | void cpu_init() |
|
12 | void cpu_init() | |
13 | { |
|
13 | { | |
14 | extern uint32_t currentCpuFreq; |
|
14 | extern uint32_t currentCpuFreq; | |
15 |
currentCpuFreq = 1 |
|
15 | currentCpuFreq = 16*1000*1000; | |
16 | enable_FPU(); |
|
16 | enable_FPU(); | |
17 | RCC->CR |= (uint32_t)0x00000001; |
|
17 | RCC->CR |= (uint32_t)0x00000001; | |
18 | FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; |
|
18 | FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; | |
19 | reset_AHB1(); |
|
19 | reset_AHB1(); | |
20 | reset_AHB2(); |
|
20 | reset_AHB2(); | |
21 | reset_APB1(); |
|
21 | reset_APB1(); | |
22 | reset_APB2(); |
|
22 | reset_APB2(); | |
23 | RCC->CR |= (uint32_t)0x00000001; |
|
23 | RCC->CR |= (uint32_t)0x00000001; | |
24 | FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; |
|
24 | FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; | |
25 | RCC->CFGR = 0x00000000; |
|
25 | RCC->CFGR = 0x00000000; | |
26 | RCC->CIR = 0x00000000; |
|
26 | RCC->CIR = 0x00000000; | |
27 | SCB->VTOR = FLASH_BASE; |
|
27 | SCB->VTOR = FLASH_BASE; | |
28 | RCC->APB1ENR |= RCC_APB1ENR_PWREN; |
|
28 | RCC->APB1ENR |= RCC_APB1ENR_PWREN; | |
29 | PWR->CR |= PWR_CR_PMODE; |
|
29 | PWR->CR |= PWR_CR_PMODE; | |
30 | currentCpuFreq=setCpuFreq(currentCpuFreq); |
|
30 | currentCpuFreq=setCpuFreq(currentCpuFreq); | |
31 | currentCpuFreq=getCpuFreq(); |
|
31 | currentCpuFreq=getCpuFreq(); | |
32 | configureSysTick(); |
|
32 | configureSysTick(); | |
33 | bsp_init(); |
|
33 | bsp_init(); | |
34 | printf("SysTick Configured to reach 100us period\n\r"); |
|
34 | printf("SysTick Configured to reach 100us period\n\r"); | |
35 | RCC_ClocksTypeDef RCC_ClocksStatus; |
|
35 | RCC_ClocksTypeDef RCC_ClocksStatus; | |
36 | RCC_GetClocksFreq(&RCC_ClocksStatus); |
|
36 | RCC_GetClocksFreq(&RCC_ClocksStatus); | |
37 | printf("PLL Configured got:\n\r SYS=%uHz\n\r CPU=%uHz\n\r APB1=%uHz\n\r APB2=%uHz\n\r",(unsigned int)RCC_ClocksStatus.SYSCLK_Frequency,(unsigned int)RCC_ClocksStatus.HCLK_Frequency,(unsigned int)RCC_ClocksStatus.PCLK1_Frequency,(unsigned int)RCC_ClocksStatus.PCLK2_Frequency); |
|
37 | printf("PLL Configured got:\n\r SYS=%uHz\n\r CPU=%uHz\n\r APB1=%uHz\n\r APB2=%uHz\n\r",(unsigned int)RCC_ClocksStatus.SYSCLK_Frequency,(unsigned int)RCC_ClocksStatus.HCLK_Frequency,(unsigned int)RCC_ClocksStatus.PCLK1_Frequency,(unsigned int)RCC_ClocksStatus.PCLK2_Frequency); | |
38 | printf("Enter Main\n\r"); |
|
38 | printf("Enter Main\n\r"); | |
39 | int res=main(); |
|
39 | int res=main(); | |
40 | printf("\n\rprogram exited with code "); |
|
40 | printf("\n\rprogram exited with code "); | |
41 | printf("%u",res); |
|
41 | printf("%u",res); | |
42 | printf("\n\r"); |
|
42 | printf("\n\r"); | |
43 | while(1) |
|
43 | while(1) | |
44 | { |
|
44 | { | |
45 | for(volatile int i=0;i<1024*64;i++); |
|
45 | for(volatile int i=0;i<1024*64;i++); | |
46 | gpioset(PD14); |
|
46 | gpioset(PD14); | |
47 | for(volatile int i=0;i<1024*64;i++); |
|
47 | for(volatile int i=0;i<1024*64;i++); | |
48 | gpioclr(PD14); |
|
48 | gpioclr(PD14); | |
49 | } |
|
49 | } | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 |
|
52 | |||
53 |
|
53 | |||
54 |
|
54 | |||
55 |
|
55 | |||
56 |
|
56 | |||
57 |
|
57 | |||
58 |
|
58 | |||
59 |
|
59 | |||
60 |
|
60 |
General Comments 0
You need to be logged in to leave comments.
Login now