\documentclass[全部作业]{subfiles}

\begin{document}
\date{2024年10月26日}

\begin{frame}
    %\maketitle
    \titlepage
\end{frame}

\begin{frame}
	\frametitle{目录}
	\tableofcontents[hideallsubsections]
\end{frame}

\section{第一次作业}

\subsection{STM32CubeMX}
\begin{frame}
    选择的MCU型号为STM32G473RCT6：
    \includegraphics[width=1\linewidth]{imgs/2024-10-26-19-29-11.png}
\end{frame}

\begin{frame}
    先设置时钟为外部：
    \includegraphics[width=1\linewidth]{imgs/2024-10-26-13-48-03.png}
\end{frame}

\begin{frame}
    再设置时钟频率：
    \includegraphics[width=1\linewidth]{imgs/2024-10-26-15-58-41.png}
\end{frame}

\begin{frame}
    开启debug模式：
    \includegraphics[width=1\linewidth]{imgs/2024-10-26-16-01-25.png}
\end{frame}

\begin{frame}
    开始调整端口：
    \includegraphics[width=1\linewidth]{imgs/2024-10-26-16-03-56.png}
\end{frame}

\begin{frame}
    选择GPIO_Output：
    \includegraphics[height=0.9\textheight]{imgs/2024-10-26-16-05-01.png}
\end{frame}

\begin{frame}
    调整端口配置：
    \includegraphics[height=0.9\textheight]{imgs/2024-10-26-19-20-26.png}
\end{frame}

\begin{frame}
    项目设置名称exp1：
    \includegraphics[width=1\linewidth]{imgs/2024-10-26-19-24-44.png}
\end{frame}

\begin{frame}
    继续项目设置：
    \includegraphics[width=1\linewidth]{imgs/2024-10-26-19-25-59.png}
    生成代码：
    \includegraphics[width=0.3\linewidth]{imgs/2024-10-28-20-36-25.png}
\end{frame}

\begin{frame}
    打开项目：
    \includegraphics[width=0.6\linewidth]{imgs/2024-10-29-15-09-10.png}
\end{frame}

\begin{frame}
    修改调试器：
    \includegraphics{imgs/2024-10-29-11-36-58.png}
    \vspace{1em}

    \includegraphics[width=1\linewidth]{imgs/2024-10-29-11-35-44.png}
\end{frame}

\begin{frame}
    修改调试设置，把reset and run打勾，就不需要手动按重置按钮了。
    \includegraphics[width=1\linewidth]{imgs/2024-10-29-14-54-11.png}
\end{frame}

\subsection{MDK-ARM}
\begin{frame}
    添加项目文件：
    \includegraphics[width=1\linewidth]{imgs/2024-10-29-09-21-05.png}
\end{frame}

\begin{frame}
    选择头文件，文件名为variable.h：
    \includegraphics[width=0.8\linewidth]{imgs/2024-10-29-09-22-20.png}
\end{frame}

% 加了[fragile]才能用minted不报错
\begin{frame}[fragile]
    variable.h:
    \begin{minted}{C}
#include <stdint.h>
#ifndef __VARIABLE_H
#define __VARIABLE_H

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
    uint8_t mMilSecCount;           // 毫秒计数
    uint8_t bTenMilSecOk;           // 10毫秒标志位
    uint8_t mTimeCount;             // 秒计数
    uint8_t bTimeOk;                // 秒标志位
} stSysTickTimer;

#ifdef __cplusplus
}
#endif

#endif /* __VARIABLE_H */
    \end{minted}
\end{frame}

\begin{frame}[fragile]
    stm32g4xx_it.c:

    \begin{multicols}{2}
        \begin{minted}[firstnumber=24]{C}
/* USER CODE BEGIN Includes */
#include "variable.h"
/* USER CODE END Includes */
        \end{minted}

\vspace{1em}
        \begin{minted}[firstnumber=60]{C}
/* USER CODE BEGIN EV */
extern stSysTickTimer sSysTickTimer;
extern uint16_t mSecCount;
extern uint16_t bSecondIsOk;
/* USER CODE END EV */
        \end{minted}

\vspace{1em}
        \begin{minted}[firstnumber=183]{C}
/**
  * @brief This function handles System tick timer.
  */
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  /* USER CODE BEGIN SysTick_IRQn 1 */
  if (++mSecCount >= 100) {
    mSecCount = 0;
    bSecondIsOk = 1;
  }

  if (++sSysTickTimer.mMilSecCount >= 10) {
    sSysTickTimer.mMilSecCount = 0;
    sSysTickTimer.bTenMilSecOk = 1;
    if (++sSysTickTimer.mTimeCount >= 100) {
      sSysTickTimer.mTimeCount = 0;
      sSysTickTimer.bTimeOk = 1;
    }
  }
  /* USER CODE END SysTick_IRQn 1 */
}
        \end{minted}
    \end{multicols}
\end{frame}

\begin{frame}[fragile]
    main.h:

    \begin{multicols}{2}
        \begin{minted}[firstnumber=48]{C}
/* USER CODE BEGIN EM */
#define SYSTICKCLK 170  // Systick Frequency 170MHz
/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */
void delay_us(uint32_t nus);
/* USER CODE END EFP */
        \end{minted}
    \end{multicols}
\end{frame}

\begin{frame}[fragile]
    main.c:

    \begin{multicols}{2}
        \begin{minted}[firstnumber=24]{C}
/* USER CODE BEGIN Includes */
#include "variable.h"
/* USER CODE END Includes */
        \end{minted}

\vspace{1em}
        \begin{minted}[firstnumber=45]{C}
/* USER CODE BEGIN PV */
stSysTickTimer sSysTickTimer = {
  0, 0, 0, 0
};
uint16_t mSecCount = 0;
uint16_t bSecondIsOk = 0;
/* USER CODE END PV */
        \end{minted}

\vspace{1em}
        \begin{minted}[firstnumber=60]{C}
/* USER CODE BEGIN 0 */
void delay_us(uint32_t nus) {
  uint32_t ticks;
  uint32_t told, tnow, tcnt=0;
  uint32_t reload = SysTick->LOAD;      // LOAD的值
  ticks = nus * SYSTICKCLK;             // 需要的节拍数
  told = SysTick->VAL;                  // 刚进入时的计数器值
  while (1) {
    tnow = SysTick->VAL;
    if (tnow != told) {
      if (tnow < told)
        tcnt += told - tnow;            // SYSTICK是一个递减的计数器就可以了
      else
        tcnt += reload - tnow + told;
      told = tnow;
      if (tcnt >= ticks) break;         // 事件超过/等于要延迟的时间，则退出
    }
  }
}
/* USER CODE END 0 */
        \end{minted}
    \end{multicols}
\end{frame}

\begin{frame}[fragile]
    main.c:

    \begin{multicols}{2}
        \begin{minted}[firstnumber=81]{C}
/**
  * @brief  The application entry point.
  * @retval int
  */
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();

  /* 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 */

    if (sSysTickTimer.bTimeOk) {
      sSysTickTimer.bTimeOk = 0;
      HAL_GPIO_TogglePin(TickClock_LED_GPIO_Port, TickClock_LED_Pin);
    }
  }
  /* USER CODE END 3 */
}
        \end{minted}
    \end{multicols}
\end{frame}

\begin{frame}
    编译和运行：
    \includegraphics[width=1\linewidth]{imgs/2024-10-29-11-38-55.png}
    \vspace{1em}

    \includegraphics[width=1\linewidth]{imgs/2024-10-29-11-39-46.png}
\end{frame}

\subsection{实验结果}

\begin{frame}
    实验结果：
    亮一秒，暗一秒。

    \includegraphics[height=0.8\textheight]{imgs/IMG_20241029_115504.jpg}

    完整视频可以查看：\url{https://gitea.librastalker.top/423A35C7/STM32CubeMX-Keil_uVision5}
\end{frame}

\end{document}