1  | //--------------------------------------------------------------
  | 
2  | // File     : main.c
  | 
3  | // Datum    : 29.10.2013
  | 
4  | // Version  : 1.1
  | 
5  | // Autor    : UB
  | 
6  | // EMail    : mc-4u(@)t-online.de
  | 
7  | // Web      : www.mikrocontroller-4u.de
  | 
8  | // CPU      : STM32F429
  | 
9  | // IDE      : CooCox CoIDE 1.7.4
  | 
10  | // GCC      : 4.7 2012q4
  | 
11  | // Module   : CMSIS_BOOT, M4_CMSIS_CORE
  | 
12  | // Funktion : Demo der LCD-Library (ILI9341)
  | 
13  | // Hinweis  : Diese zwei Files muessen auf 8MHz stehen
  | 
14  | //              "cmsis_boot/stm32f4xx.h"
  | 
15  | //              "cmsis_boot/system_stm32f4xx.c"
  | 
16  | // In Configuration diese Define hinzufügen :
  | 
17  | // "STM32F429_439xx" , "__ASSEMBLY__" , "USE_STDPERIPH_DRIVER"
  | 
18  | //--------------------------------------------------------------
  | 
19  | 
  | 
20  | #include "main.h"
  | 
21  | #include "stm32f4xx_conf.h"
  | 
22  | #include "stm32_ub_lcd_ili9341.h"
  | 
23  | #include "stm32_ub_graphic2d.h"
  | 
24  | #include "stm32_ub_font.h"
  | 
25  | #include "stm32f4xx_tim.h"
  | 
26  | #include "stm32f4xx_rcc.h"
  | 
27  | #include "stm32f4xx.h"
  | 
28  | #include "misc.h"
  | 
29  | #include "stm32f4xx_gpio.h"
  | 
30  | #include "stm32f4xx_can.h"
  | 
31  | 
  | 
32  | 
  | 
33  | 
  | 
34  | volatile unsigned char X_pos[15];
  | 
35  | 
  | 
36  | 
  | 
37  | int main(void)
  | 
38  | {
 | 
39  |   uint32_t n;
  | 
40  | 
  | 
41  | 
  | 
42  | 
  | 
43  | 
  | 
44  |   SystemInit(); // Quarz Einstellungen aktivieren
  | 
45  | 
  | 
46  | 
  | 
47  | 
  | 
48  | 
  | 
49  | 
  | 
50  |   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG,ENABLE);
  | 
51  | 
  | 
52  |     // Strukturen festlegen
  | 
53  |     GPIO_InitTypeDef GPIO_InitGPIO;
  | 
54  | 
  | 
55  |     // Pin Parameter einstellen
  | 
56  |     GPIO_InitGPIO.GPIO_Pin = (GPIO_Pin_14);
  | 
57  |     GPIO_InitGPIO.GPIO_Mode = GPIO_Mode_OUT;
  | 
58  |     GPIO_InitGPIO.GPIO_OType = GPIO_OType_PP;
  | 
59  |     GPIO_InitGPIO.GPIO_PuPd = GPIO_PuPd_NOPULL;
  | 
60  |     GPIO_InitGPIO.GPIO_Speed = GPIO_Speed_50MHz;
  | 
61  | 
  | 
62  |     // Port initialisieren
  | 
63  |     GPIO_Init(GPIOG, &GPIO_InitGPIO);
  | 
64  | 
  | 
65  | 
  | 
66  | 
  | 
67  |   TIM_TimeBaseInitTypeDef TIM_TimeBaseInitTIM;
  | 
68  |   NVIC_InitTypeDef NVIC_InitStructure;
  | 
69  | 
  | 
70  |   // Takt für Timer2 einschalten
  | 
71  |   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  | 
72  | 
  | 
73  |   // Timer 2 konfigurieren
  | 
74  |   TIM_TimeBaseInitTIM.TIM_ClockDivision = TIM_CKD_DIV1;
  | 
75  |   TIM_TimeBaseInitTIM.TIM_CounterMode = TIM_CounterMode_Up;
  | 
76  |   TIM_TimeBaseInitTIM.TIM_Period = 700;
  | 
77  |   TIM_TimeBaseInitTIM.TIM_Prescaler = 17999;
  | 
78  |   TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitTIM);
  | 
79  | 
  | 
80  |   TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
  | 
81  | 
  | 
82  |   // Timer Interrupt konfigurieren
  | 
83  |   NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  | 
84  |   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  | 
85  |   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  | 
86  |   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  | 
87  |   NVIC_Init(&NVIC_InitStructure);
  | 
88  | 
  | 
89  |   // Timer starten
  | 
90  |   TIM_Cmd(TIM2, ENABLE);
  | 
91  | 
  | 
92  | 
  | 
93  | 
  | 
94  | 
  | 
95  |   // Init vom LCD
  | 
96  |   UB_LCD_Init();
  | 
97  |   // Init der Layer
  | 
98  |   UB_LCD_LayerInit_Fullscreen();
  | 
99  |   // auf Hintergrund schalten
  | 
100  |   UB_LCD_SetLayer_1();
  | 
101  |   // Hintergrund komplett mit einer Farbe füllen
  | 
102  |   UB_LCD_FillLayer(RGB_COL_WHITE);
  | 
103  |   // auf Vordergrund schalten
  | 
104  |   UB_LCD_SetLayer_2();
  | 
105  |   // Vordergrund komplett mit einer Farbe füllen
  | 
106  |   UB_LCD_FillLayer(RGB_COL_BLACK);
  | 
107  | 
  | 
108  | //Testrechteck zeichnen
  | 
109  |   UB_Graphic2D_DrawFullRectDMA(150, 30, 50, 50, 990);
  | 
110  | 
  | 
111  | 
  | 
112  | 
  | 
113  | 
  | 
114  | 
  | 
115  | //__________CAN INIT__________
  | 
116  |   CAN_InitTypeDef CAN_InitStructure;
  | 
117  |   GPIO_InitTypeDef GPIO_InitStructure;
  | 
118  |   CAN_FilterInitTypeDef CAN_FilterInitStructure;
  | 
119  | 
  | 
120  |   RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
  | 
121  |   RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);
  | 
122  | 
  | 
123  |   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  | 
124  |   GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_CAN2);
  | 
125  |   GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_CAN2);
  | 
126  | 
  | 
127  |   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  | 
128  |   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  | 
129  |   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13;
  | 
130  |   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  | 
131  |   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  | 
132  |   GPIO_Init(GPIOB, &GPIO_InitStructure);
  | 
133  | 
  | 
134  |   CAN_DeInit(CAN2);
  | 
135  |   CAN_InitStructure.CAN_ABOM = DISABLE;
  | 
136  |   CAN_InitStructure.CAN_AWUM = DISABLE;
  | 
137  |   CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
  | 
138  |   CAN_InitStructure.CAN_NART = DISABLE;
  | 
139  |   CAN_InitStructure.CAN_RFLM = DISABLE;
  | 
140  |   CAN_InitStructure.CAN_SJW  = CAN_SJW_1tq;
  | 
141  |   CAN_InitStructure.CAN_TTCM = DISABLE;
  | 
142  |   CAN_InitStructure.CAN_TXFP = DISABLE;
  | 
143  | 
  | 
144  |   CAN_InitStructure.CAN_BS1 = CAN_BS1_12tq;
  | 
145  |   CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
  | 
146  |   CAN_InitStructure.CAN_Prescaler = 5;
  | 
147  |   CAN_Init(CAN2, &CAN_InitStructure);
  | 
148  | 
  | 
149  |     // Init the CAN filter
  | 
150  |     CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
  | 
151  |     CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
  | 
152  |     CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
  | 
153  |     CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
  | 
154  |     CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
  | 
155  |     CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
  | 
156  |     CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
  | 
157  |     CAN_FilterInitStructure.CAN_FilterNumber = 0;
  | 
158  |     CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
  | 
159  |     CAN_FilterInit(&CAN_FilterInitStructure);
  | 
160  | 
  | 
161  | //    NVIC_InitTypeDef NVIC_InitStructure;
  | 
162  |     NVIC_InitStructure.NVIC_IRQChannel = CAN2_RX0_IRQn;
  | 
163  |     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  | 
164  |     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
  | 
165  |     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
  | 
166  |     NVIC_Init(&NVIC_InitStructure);
  | 
167  | 
  | 
168  |     // Enable "FIFO 0 message pending" interrupt
  | 
169  |     CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);
  | 
170  | 
  | 
171  | //__________ENDE CAN INIT
  | 
172  | 
  | 
173  | 
  | 
174  | 
  | 
175  |   while(1)
  | 
176  |   {
 | 
177  | 
  | 
178  |     }
  | 
179  | }
  | 
180  | 
  | 
181  | 
  | 
182  | 
  | 
183  | 
  | 
184  | void TIM2_IRQHandler(void){
 | 
185  |  TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  | 
186  | 
  | 
187  |   if(GPIO_ReadOutputDataBit(GPIOG, GPIO_Pin_14)){
 | 
188  |       GPIO_WriteBit(GPIOG, GPIO_Pin_14, RESET);
  | 
189  |     }else{
 | 
190  |       GPIO_WriteBit(GPIOG, GPIO_Pin_14, SET);
  | 
191  |     }
  | 
192  | 
  | 
193  | }
  | 
194  | 
  | 
195  | void CAN2_RX0_IRQHandler()
  | 
196  | {
 | 
197  |   // Check CAN2_Rx status
  | 
198  | //  if( CAN_GetITStatus(CAN2, CAN_IT_FMP0))
  | 
199  | //  {
 | 
200  |     if(GPIO_ReadOutputDataBit(GPIOG, GPIO_Pin_13)){
 | 
201  |           GPIO_WriteBit(GPIOG, GPIO_Pin_13, RESET);
  | 
202  |         }else{
 | 
203  |           GPIO_WriteBit(GPIOG, GPIO_Pin_13, SET);
  | 
204  |         }
  | 
205  | 
  | 
206  |     // Clear CAN buffer
  | 
207  | //  clear_CanRxMessage();
  | 
208  | //  }
  | 
209  | }
  |