From abdba7cb36c5b9ab3a648cc3e0e52ee80e9621d4 Mon Sep 17 00:00:00 2001 From: 423A35C7 <609514299@qq.com> Date: Wed, 30 Oct 2024 17:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B5=8C=E5=85=A5=E5=BC=8F=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=8E=9F=E7=90=86=E4=B8=8E=E5=AE=9E=E8=B7=B5=E2=80=94=E2=80=94?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E4=BA=8C=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 嵌入式系统原理与实践/实验报告/mypreamble.tex | 40 +++ 嵌入式系统原理与实践/实验报告/全部作业.tex | 8 + .../实验报告/第一次作业——时钟滴答.tex | 312 ++++++++++++++++++ .../实验报告/第二次作业——流水灯.tex | 235 +++++++++++++ 4 files changed, 595 insertions(+) create mode 100644 嵌入式系统原理与实践/实验报告/mypreamble.tex create mode 100644 嵌入式系统原理与实践/实验报告/全部作业.tex create mode 100644 嵌入式系统原理与实践/实验报告/第一次作业——时钟滴答.tex create mode 100644 嵌入式系统原理与实践/实验报告/第二次作业——流水灯.tex diff --git a/嵌入式系统原理与实践/实验报告/mypreamble.tex b/嵌入式系统原理与实践/实验报告/mypreamble.tex new file mode 100644 index 0000000..299d5a1 --- /dev/null +++ b/嵌入式系统原理与实践/实验报告/mypreamble.tex @@ -0,0 +1,40 @@ +\usepackage{underscore} +\usepackage[outputdir=./latex-output]{minted} +\usepackage{multicol} +\usepackage{subfiles} + +\setminted{breaklines=true, fontsize=\zihao{-6}, linenos} + +\title{《嵌入式系统原理与实践》作业} +\author[岳锦鹏 \quad 朱宇笑]{10213903403 岳锦鹏 \newline 10225001410 朱宇笑 +} +\date{2024年10月26日——} + + +\usetheme{Malmoe} %主题包之一,直接换名字即可 +\setbeamertemplate{page number in head/foot}[totalframenumber] + +\usecolortheme{default} %主题色之一,直接换名字即可。 +\usefonttheme{professionalfonts} + +% 设置用acrobat打开就会全屏显示 +\hypersetup{pdfpagemode=FullScreen} + + +%每个章节都有小目录 +\AtBeginSubsection[] +{ + \begin{frame} + \tableofcontents[currentsection,currentsubsection] + \end{frame} +} + +\definecolor{palette1}{RGB}{123,199,233} +\definecolor{palette2}{RGB}{58,169,222} +\definecolor{palette3}{RGB}{3,35,74} +\definecolor{palette4}{RGB}{145,152,158} + +\setbeamercolor{palette primary}{bg=palette1} +\setbeamercolor{palette secondary}{bg=palette2} +\setbeamercolor{palette tertiary}{bg=palette3} +\setbeamercolor{palette quaternary}{bg=palette4} \ No newline at end of file diff --git a/嵌入式系统原理与实践/实验报告/全部作业.tex b/嵌入式系统原理与实践/实验报告/全部作业.tex new file mode 100644 index 0000000..d44c64d --- /dev/null +++ b/嵌入式系统原理与实践/实验报告/全部作业.tex @@ -0,0 +1,8 @@ +\documentclass[aspectratio=169, 10pt, utf8, mathserif]{ctexbeamer} +\input{mypreamble} +\begin{document} + \maketitle + \tableofcontents + \subfile{第一次作业——时钟滴答} + \subfile{第二次作业——流水灯} +\end{document} \ No newline at end of file diff --git a/嵌入式系统原理与实践/实验报告/第一次作业——时钟滴答.tex b/嵌入式系统原理与实践/实验报告/第一次作业——时钟滴答.tex new file mode 100644 index 0000000..b9e334a --- /dev/null +++ b/嵌入式系统原理与实践/实验报告/第一次作业——时钟滴答.tex @@ -0,0 +1,312 @@ +\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 +#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} \ No newline at end of file diff --git a/嵌入式系统原理与实践/实验报告/第二次作业——流水灯.tex b/嵌入式系统原理与实践/实验报告/第二次作业——流水灯.tex new file mode 100644 index 0000000..91085fc --- /dev/null +++ b/嵌入式系统原理与实践/实验报告/第二次作业——流水灯.tex @@ -0,0 +1,235 @@ +\documentclass[全部作业]{subfiles} + +\begin{document} + +\date{2024年10月29日} +\begin{frame} + %\maketitle + \titlepage +\end{frame} + +\begin{frame} + \frametitle{目录} + \tableofcontents[hideallsubsections] +\end{frame} + +\section{第二次作业} + +\subsection{准备} +\begin{frame}[fragile] + 将实验一的代码复制一份,并将exp1改名为exp2: + \vspace{1em} + + \begin{minipage}[H]{0.3\linewidth} + \begin{minted}[linenos=false]{text} +exp1 +│ .mxproject +│ exp1.ioc +│ +├─Core +│ +├─Drivers +│ +└─MDK-ARM + exp1.uvprojx + startup_stm32g473xx.s + \end{minted} + \end{minipage} + {\Huge$\longrightarrow$} + \begin{minipage}[H]{0.3\linewidth} + \begin{minted}[linenos=false]{text} + exp2 + │ .mxproject + │ exp2.ioc + │ + ├─Core + │ + ├─Drivers + │ + └─MDK-ARM + exp2.uvprojx + startup_stm32g473xx.s + \end{minted} + \end{minipage} + \vspace{1em} + + 需要改文件夹名、.ioc、.uvprojx这三个地方。 +\end{frame} + +\begin{frame} + 打开.uvprojx文件,修改调试器: + \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{端口修改} +\begin{frame} + 这样设置端口,点击生成代码。 + \includegraphics[width=1\linewidth]{imgs/2024-10-29-16-44-16.png} +\end{frame} + +\begin{frame} + 将STM32核心板JP1的PA0~PA7与系统底板跑马灯控制端JP21相连。 + + \includegraphics[width=0.3\linewidth]{imgs/IMG_20241029_204905_1.jpg} + \includegraphics[width=0.3\linewidth]{imgs/IMG_20241029_205023.jpg} +\end{frame} + +\subsection{代码修改} +\begin{frame}[fragile] + main.c: + \begin{multicols}{2} + \begin{minted}[firstnumber=62]{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 */ + uint8_t FlashFlag = 0; + uint16_t nShift = 0x0001; + uint8_t i = 0; + /* 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 */ + FlashLeds_GPIO_Port->ODR &= 0xffff; + /* USER CODE END 2 */ + + \end{minted} + \end{multicols} +\end{frame} + +\begin{frame}[fragile] + main.c: + \begin{multicols}{2} + \begin{minted}[firstnumber=last]{C} + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while (1) + { + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + if (sSysTickTimer.bTimeOk) { + sSysTickTimer.bTimeOk = 0; + HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); + + HAL_GPIO_WritePin(FlashLeds_GPIO_Port, nShift, GPIO_PIN_SET); + + + // FlashLeds_GPIO_Port->ODR &= 0xFF00; + // FlashLeds_GPIO_Port->ODR |= (~nShift) & 0x00FF; + + if (i < 7) + nShift <<= 1; + else + nShift >>= 1; + + i++; + + if (i >= 14) { + i = 0; + nShift = 0x0001; + } + + HAL_GPIO_WritePin(FlashLeds_GPIO_Port, nShift, GPIO_PIN_RESET); + + // if (FlashFlag != 0) { + + // } + } + } + /* USER CODE END 3 */ +} + \end{minted} + \end{multicols} +\end{frame} + +\subsection{改进} +\begin{frame}[fragile] + 目前的闪烁频率较慢,可以修改部分代码使灯闪烁得更快。 + 在variable.h中增加10毫秒计数和100毫秒标志位: + \begin{minted}[firstnumber=9]{C} +typedef struct { + uint8_t mMilSecCount; // 毫秒计数 + uint8_t bTenMilSecOk; // 10毫秒标志位 + uint8_t mTenMilSecCount; // 10毫秒计数 + uint8_t bHundredMilSecOk; // 100毫秒标志位 + uint8_t mTimeCount; // 秒计数 + uint8_t bTimeOk; // 秒标志位 +} stSysTickTimer; + \end{minted} +\end{frame} + +\begin{frame}[fragile] + 相应地,在 \mintinline{C}{SysTick_Handler()} 中也需要在100毫秒标志位时设置相应标志。 + \begin{minted}[firstnumber=192]{C} + if (++sSysTickTimer.mMilSecCount >= 10) { + sSysTickTimer.mMilSecCount = 0; + sSysTickTimer.bTenMilSecOk = 1; + if (++sSysTickTimer.mTenMilSecCount >= 10) { + sSysTickTimer.mTenMilSecCount = 0; + sSysTickTimer.bHundredMilSecOk = 1; + if (++sSysTickTimer.mTimeCount >= 10) { + sSysTickTimer.mTimeCount = 0; + sSysTickTimer.bTimeOk = 1; + } + } + } + \end{minted} +\end{frame} + +\begin{frame}[fragile] + 在 \mintinline{C}{main.c} 中在100毫秒标志为1时进行流水灯的操作(时钟滴答仍然在1秒标志位为1时操作)。 + \begin{minted}[firstnumber=103]{C} + /* USER CODE BEGIN 3 */ + if (sSysTickTimer.bTimeOk) { + sSysTickTimer.bTimeOk = 0; + HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); + } + if (sSysTickTimer.bHundredMilSecOk) { + sSysTickTimer.bHundredMilSecOk = 0; + HAL_GPIO_WritePin(FlashLeds_GPIO_Port, nShift, GPIO_PIN_SET); + ... + } + \end{minted} +\end{frame} + +\subsection{实验结果} + +\begin{frame} + 每次只有一个灯亮,从最左边的灯亮向右移动,直到最右边的灯亮,再向左移动,直到最左边的灯亮。 + + \includegraphics[width=0.5\linewidth]{imgs/IMG_20241029_205440.jpg} + + 完整视频可以查看:\url{https://gitea.librastalker.top/423A35C7/STM32CubeMX-Keil_uVision5} +\end{frame} + +\end{document} \ No newline at end of file