Authors
Ryan Ku (rcwku@connect.ust.hk) Modified from: Ivan Lok, Dicaprio Cheung, Joseph Lam, Binay Gurung, Anshuman Medhi
DO NOT put the mainboard on any metal surface, or on your computer, if you do not want your computer to burn (as well as the pcb)
Welcome to the first tutorial!
In STM32, the main.c file is the core of the program, containing the program's entry point and primary control flow.
Below is the code generated by CubeMX inside the main.c file.
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init(); // Initialization of HAL
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
// Insert user code here
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}Inside the code:
HAL_Init()initiates the HAL library.SystemClock_Configconfigurates the clock.- Under
Initialize all configured peripheralsall used peripherals (GPIO, SPI, I2C etc etc) are initialized. - Infinite
whileloop, where the user code runs indefinitely (instead of immediately halting after 1 cycle). - Error handling at the bottom of the file.