Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 1.68 KB

File metadata and controls

72 lines (48 loc) · 1.68 KB

Tutorial 1 - GPIO, TFT and HAL

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:

  1. HAL_Init() initiates the HAL library.
  2. SystemClock_Config configurates the clock.
  3. Under Initialize all configured peripherals all used peripherals (GPIO, SPI, I2C etc etc) are initialized.
  4. Infinite while loop, where the user code runs indefinitely (instead of immediately halting after 1 cycle).
  5. Error handling at the bottom of the file.

Next Page