1 | /**
|
2 | ******************************************************************************
|
3 | * @file : main.c
|
4 | * @brief : Main program body
|
5 | ******************************************************************************
|
6 | ** This notice applies to any and all portions of this file
|
7 | * that are not between comment pairs USER CODE BEGIN and
|
8 | * USER CODE END. Other portions of this file, whether
|
9 | * inserted by the user or by software development tools
|
10 | * are owned by their respective copyright owners.
|
11 | *
|
12 | * COPYRIGHT(c) 2018 STMicroelectronics
|
13 | *
|
14 | * Redistribution and use in source and binary forms, with or without modification,
|
15 | * are permitted provided that the following conditions are met:
|
16 | * 1. Redistributions of source code must retain the above copyright notice,
|
17 | * this list of conditions and the following disclaimer.
|
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
19 | * this list of conditions and the following disclaimer in the documentation
|
20 | * and/or other materials provided with the distribution.
|
21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
22 | * may be used to endorse or promote products derived from this software
|
23 | * without specific prior written permission.
|
24 | *
|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35 | *
|
36 | ******************************************************************************
|
37 | */
|
38 | /* Includes ------------------------------------------------------------------*/
|
39 | #include "main.h"
|
40 | #include "stm32f0xx_hal.h"
|
41 |
|
42 | /* USER CODE BEGIN Includes */
|
43 |
|
44 | /* USER CODE END Includes */
|
45 |
|
46 | /* Private variables ---------------------------------------------------------*/
|
47 |
|
48 | /* USER CODE BEGIN PV */
|
49 | /* Private variables ---------------------------------------------------------*/
|
50 |
|
51 | /* USER CODE END PV */
|
52 |
|
53 | /* Private function prototypes -----------------------------------------------*/
|
54 | void SystemClock_Config(void);
|
55 | static void MX_GPIO_Init(void);
|
56 |
|
57 | /* USER CODE BEGIN PFP */
|
58 | /* Private function prototypes -----------------------------------------------*/
|
59 |
|
60 | /* USER CODE END PFP */
|
61 |
|
62 | /* USER CODE BEGIN 0 */
|
63 |
|
64 | /* USER CODE END 0 */
|
65 |
|
66 | /**
|
67 | * @brief The application entry point.
|
68 | *
|
69 | * @retval None
|
70 | */
|
71 | int main(void)
|
72 | {
|
73 | /* USER CODE BEGIN 1 */
|
74 | // set_frequency();
|
75 | /* USER CODE END 1 */
|
76 |
|
77 | /* MCU Configuration----------------------------------------------------------*/
|
78 |
|
79 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
80 | HAL_Init();
|
81 |
|
82 | /* USER CODE BEGIN Init */
|
83 |
|
84 |
|
85 |
|
86 | /* USER CODE END Init */
|
87 |
|
88 | /* Configure the system clock */
|
89 | SystemClock_Config();
|
90 |
|
91 | /* USER CODE BEGIN SysInit */
|
92 |
|
93 | /* USER CODE END SysInit */
|
94 |
|
95 | /* Initialize all configured peripherals */
|
96 | MX_GPIO_Init();
|
97 | /* USER CODE BEGIN 2 */
|
98 | /*
|
99 | uint8_t check = SSD1306_Init(); // initialize the diaply
|
100 |
|
101 | SSD1306_Fill(0); // fill the display with black color
|
102 | SSD1306_UpdateScreen(); // update screen
|
103 |
|
104 | SSD1306_GotoXY(10,10); // goto 10, 10
|
105 | SSD1306_Puts("HELLO", &Font_11x18, 1); // print Hello
|
106 |
|
107 | SSD1306_GotoXY(10, 30);
|
108 | SSD1306_Puts("WORLD !!", &Font_11x18, 1);
|
109 |
|
110 | SSD1306_UpdateScreen(); // update screen
|
111 | */
|
112 | // char *msg = "Hello Nucleo Fun!\n\r";
|
113 |
|
114 | /* USER CODE END 2 */
|
115 |
|
116 | /* Infinite loop */
|
117 | /* USER CODE BEGIN WHILE */
|
118 | while (1)
|
119 | {
|
120 |
|
121 | /* USER CODE END WHILE */
|
122 |
|
123 | /* USER CODE BEGIN 3 */
|
124 |
|
125 | if (HAL_GPIO_ReadPin(GPIOB, 7) == 0)
|
126 | {
|
127 |
|
128 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_7, 1);
|
129 |
|
130 | }
|
131 | else
|
132 | {
|
133 |
|
134 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_7, 0);
|
135 |
|
136 | }
|
137 |
|
138 | }
|
139 |
|
140 | /* USER CODE END 3 */
|
141 |
|
142 | }
|
143 |
|
144 | /**
|
145 | * @brief System Clock Configuration
|
146 | * @retval None
|
147 | */
|
148 | void SystemClock_Config(void)
|
149 | {
|
150 |
|
151 | RCC_OscInitTypeDef RCC_OscInitStruct;
|
152 | RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
153 |
|
154 | /**Initializes the CPU, AHB and APB busses clocks
|
155 | */
|
156 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
157 | RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
158 | RCC_OscInitStruct.HSICalibrationValue = 16;
|
159 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
160 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
161 | {
|
162 | _Error_Handler(__FILE__, __LINE__);
|
163 | }
|
164 |
|
165 | /**Initializes the CPU, AHB and APB busses clocks
|
166 | */
|
167 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
168 | |RCC_CLOCKTYPE_PCLK1;
|
169 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
170 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
171 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
172 |
|
173 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
174 | {
|
175 | _Error_Handler(__FILE__, __LINE__);
|
176 | }
|
177 |
|
178 | /**Configure the Systick interrupt time
|
179 | */
|
180 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
|
181 |
|
182 | /**Configure the Systick
|
183 | */
|
184 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
185 |
|
186 | /* SysTick_IRQn interrupt configuration */
|
187 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
188 | }
|
189 |
|
190 | /** Configure pins as
|
191 | * Analog
|
192 | * Input
|
193 | * Output
|
194 | * EVENT_OUT
|
195 | * EXTI
|
196 | */
|
197 | static void MX_GPIO_Init(void)
|
198 | {
|
199 |
|
200 | GPIO_InitTypeDef GPIO_InitStruct;
|
201 |
|
202 | /* GPIO Ports Clock Enable */
|
203 | __HAL_RCC_GPIOF_CLK_ENABLE();
|
204 | __HAL_RCC_GPIOB_CLK_ENABLE();
|
205 |
|
206 | /*Configure GPIO pin Output Level */
|
207 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
|
208 |
|
209 | /*Configure GPIO pins : PF6 PF7 */
|
210 | GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
211 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
212 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
213 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
214 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
215 |
|
216 | /*Configure GPIO pin : PB7 */
|
217 | GPIO_InitStruct.Pin = GPIO_PIN_7;
|
218 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
219 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
220 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
221 |
|
222 | }
|
223 |
|
224 | /* USER CODE BEGIN 4 */
|
225 |
|
226 |
|
227 | /* USER CODE END 4 */
|
228 |
|
229 | /**
|
230 | * @brief This function is executed in case of error occurrence.
|
231 | * @param file: The file name as string.
|
232 | * @param line: The line in file as a number.
|
233 | * @retval None
|
234 | */
|
235 | void _Error_Handler(char *file, int line)
|
236 | {
|
237 | /* USER CODE BEGIN Error_Handler_Debug */
|
238 | /* User can add his own implementation to report the HAL error return state */
|
239 | while(1)
|
240 | {
|
241 | }
|
242 | /* USER CODE END Error_Handler_Debug */
|
243 | }
|
244 |
|
245 | #ifdef USE_FULL_ASSERT
|
246 | /**
|
247 | * @brief Reports the name of the source file and the source line number
|
248 | * where the assert_param error has occurred.
|
249 | * @param file: pointer to the source file name
|
250 | * @param line: assert_param error line source number
|
251 | * @retval None
|
252 | */
|
253 | void assert_failed(uint8_t* file, uint32_t line)
|
254 | {
|
255 | /* USER CODE BEGIN 6 */
|
256 | /* User can add his own implementation to report the file name and line number,
|
257 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
258 | /* USER CODE END 6 */
|
259 | }
|
260 | #endif /* USE_FULL_ASSERT */
|
261 |
|
262 | /**
|
263 | * @}
|
264 | */
|
265 |
|
266 | /**
|
267 | * @}
|
268 | */
|
269 |
|
270 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|