TM4C123 library function learning (1) --- Lighting LED+TM4C123 ROM function introduction+keil development environment construction

foreword

(1) First, we need to know that TM4C123 is the core of M4. For the vast majority of people, getting started is to learn STM32F103, which uses the M3 core. So you must have a certain understanding of the M3 core. The M4 core is an upgraded version of the M3 core. It inherits all the functions of the M3, and also adds and enhances the following functions:
<1> Adds high-precision MAC, which makes the performance of algorithm calculations higher;
<2> The floating point unit FPU is added;
<3> DSP instructions with SIMD function are added;
(2) These newly added functions make the M4 core chip have a very powerful floating point operation function, so that the M4 chip is mostly used for needs Scenes with complex number-crunching functions.

Build the development environment

Keil engineering environment construction

(1) First search for keil on the search engine, enter the official website of keil, search for pack, and then press Ctrl+F to search for TEXAS (because the English name prefix of TI is this).

insert image description here

(2) Import the pack file into keil. Open keil (note that any project is fine, even if no project is blank). Click on PACK Installer in the upper left corner

insert image description here

(3) After entering PACK Installer, close the pop-up window --> click File in the upper left corner --> click Import

insert image description here

(4) Find the path where PACK is stored, and then open it. After that, you need to wait for a while, and there will be a progress bar in the lower right corner, because the installation package is on a foreign website, so you need to wait for a long time.
Note: The pack name of TM4C123 is not as shown in the picture, because I am too lazy to re-demonstrate, so I copied the screenshot of my RA2E1 development board tutorial.

insert image description here

(5) After that, a bullet box will pop up in the keil project, just click OK.
(6) Then confirm whether the pack has been installed according to the figure below

insert image description here

program download

(1) Connect the downloader and set the downloader

insert image description here

(2) Set the initial position and size of the arithmetic unit of the ROM. and set the programming algorithm

insert image description here

(3) Compile and download

insert image description here

TM4C123 prefix functions with ROM

For details, please refer to: Differences between ROM functions and non-ROM functions of TM4C123

Function introduction

ROM_FPUEnable();

Because in the core of M4, there can be a dedicated floating-point unit. So when we need to use floating-point operations in the program, we need to call the ROM_FPUEnable() function.

/****** 函数声明 ******/
//这个存放在ROM
void ROM_FPUEnable(void);
//这个是存放在flash
void FPUEnable(void);

ROM_FPULazyStackingEnable();

This function allows lazy stacking of floating point registers s0-s15 when servicing interrupts. When lazy stacking is enabled, space is reserved on the stack for the floating-point context, but the floating-point state is not saved. If a floating-point instruction is executed in the interrupt context, the floating-point context is first saved to the space reserved by the stack. Only the floating-point context that was saved (as a result of executing a floating-point instruction) is restored when the interrupt handler completes.
(1) This provides fast interrupt response (because floating point state is not saved on interrupt entry) and (2) the ability to use floating point in interrupt handlers (because floating point state is saved if floating point instructions are used) compromise between

/****** 函数声明 ******/
//这个存放在ROM
void ROM_FPULazyStackingEnable(void);
//这个是存放在flash
void FPULazyStackingEnable(void);

ROM_SysCtlClockSet();

(1) This function is used to set the device clock. Generally use ROM_SysCtlClockSet (SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); set the system clock to 80MHZ.
(2) The following is the clock tree of TM4C123. Many people have a headache about the clock tree, there is no need to be afraid at first, we only need to look at the system clock now. Because it is the most important, other clock signals, look at it when you need it.
<1> Let's look at the parameters passed in ROM_SysCtlClockSet() one by one. SYSCTL_USE_PLL | SYSCTL_OSC_MAIN This paragraph indicates that the PLL is used as the clock source of the system clock.
<2>SYSCTL_XTAL_16MHZ means the main oscillator is 16MHZ, this needs to be set according to your external crystal oscillator frequency. Because the external crystal oscillator of my development board is 16MHZ, I choose SYSCTL_XTAL_16MHZ.
<3> SYSCTL_SYSDIV_2_5 performs frequency division again. Because the PLL outputs 400MHZ frequency, it returns to 200MHZ after a frequency division by 2. Because the maximum frequency of TM4C123 is 80MHZ, the frequency division number must be greater than 2.5. Here we choose frequency division 2.5 to let TM4C123 run at the maximum frequency.

insert image description here

/****** 系统时钟设置为80MHZ ******/
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);//配置系统时钟,系统时钟频率400M/2/2.5=80M

/****** 函数声明 ******/
//这个存放在ROM
void ROM_SysCtlClockSet(uint32_t ui32Config);
//这个存放在flash
void SysCtlClockSet(uint32_t ui32Config);

ROM_SysCtlPeripheralEnable()

(1) After the initial steps above, we can now enter the LED program normally. When the system is powered on, the IO port clock is turned off by default to reduce power consumption. So first we need to turn on the IO port clock, because the LED on my development board is on PF4. So I need to turn on the clock of the PF group of IO.

/****** 函数声明 ******/
//这个存放在ROM
void ROM_SysCtlPeripheralEnable(uint32_t ui32Peripheral);
//这个存放在flash
void SysCtlPeripheralEnable(uint32_t ui32Peripheral);

/****** 函数介绍 ******/
/* 作用 : 使能IO
 * 传入参数 : 
     * ui32Peripheral : 参数必须仅为下列值之一:
       SYSCTL_PERIPH_ADC0, SYSCTL_PERIPH_ADC1,
SYSCTL_PERIPH_CAN0, SYSCTL_PERIPH_CAN1, SYSCTL_PERIPH_CCM0,
SYSCTL_PERIPH_COMP0, SYSCTL_PERIPH_EEPROM0, SYSCTL_PERIPH_EMAC,
SYSCTL_PERIPH_EPHY, SYSCTL_PERIPH_EPI0, SYSCTL_PERIPH_GPIOA,
SYSCTL_PERIPH_GPIOB, SYSCTL_PERIPH_GPIOC, SYSCTL_PERIPH_GPIOD,
SYSCTL_PERIPH_GPIOE, SYSCTL_PERIPH_GPIOF, SYSCTL_PERIPH_GPIOG,
SYSCTL_PERIPH_GPIOH, SYSCTL_PERIPH_GPIOJ, SYSCTL_PERIPH_GPIOK,
SYSCTL_PERIPH_GPIOL, SYSCTL_PERIPH_GPIOM, SYSCTL_PERIPH_GPION,
SYSCTL_PERIPH_GPIOP, SYSCTL_PERIPH_GPIOQ, SYSCTL_PERIPH_GPIOR,
SYSCTL_PERIPH_GPIOS, SYSCTL_PERIPH_GPIOT, SYSCTL_PERIPH_HIBERNATE,
SYSCTL_PERIPH_I2C0, SYSCTL_PERIPH_I2C1, SYSCTL_PERIPH_I2C2,
SYSCTL_PERIPH_I2C3, SYSCTL_PERIPH_I2C4, SYSCTL_PERIPH_I2C5,
SYSCTL_PERIPH_I2C6, SYSCTL_PERIPH_I2C7, SYSCTL_PERIPH_I2C8,
SYSCTL_PERIPH_I2C9, SYSCTL_PERIPH_LCD0, SYSCTL_PERIPH_ONEWIRE0,
SYSCTL_PERIPH_PWM0, SYSCTL_PERIPH_PWM1, SYSCTL_PERIPH_QEI0,
SYSCTL_PERIPH_QEI1, SYSCTL_PERIPH_SSI0, SYSCTL_PERIPH_SSI1,
SYSCTL_PERIPH_SSI2, SYSCTL_PERIPH_SSI3, SYSCTL_PERIPH_TIMER0,
SYSCTL_PERIPH_TIMER1, SYSCTL_PERIPH_TIMER2, SYSCTL_PERIPH_TIMER3,
SYSCTL_PERIPH_TIMER4, SYSCTL_PERIPH_TIMER5, SYSCTL_PERIPH_TIMER6,
SYSCTL_PERIPH_TIMER7, SYSCTL_PERIPH_UART0, SYSCTL_PERIPH_UART1,
SYSCTL_PERIPH_UART2, SYSCTL_PERIPH_UART3, SYSCTL_PERIPH_UART4,
SYSCTL_PERIPH_UART5, SYSCTL_PERIPH_UART6, SYSCTL_PERIPH_UART7,
SYSCTL_PERIPH_UDMA, SYSCTL_PERIPH_USB0, SYSCTL_PERIPH_WDOG0,
SYSCTL_PERIPH_WDOG1, SYSCTL_PERIPH_WTIMER0, SYSCTL_PERIPH_WTIMER1,
SYSCTL_PERIPH_WTIMER2, SYSCTL_PERIPH_WTIMER3,
SYSCTL_PERIPH_WTIMER4, or SYSCTL_PERIPH_WTIMER5
 * 返回参数 : 无
*/

ROM_GPIOPinTypeGPIOOutput()

Because we want to light up the LED, we need to set the IO port as an output pin. Use this function to set the IO port as an output.

/****** 函数声明 ******/
//这个存放在ROM
void ROM_GPIOPinTypeGPIOOutput(uint32_t ui32Port,
uint8_t ui8Pins);
//这个存放在flash
void GPIOPinTypeGPIOOutput(uint32_t ui32Port,
uint8_t ui8Pins);

/****** 函数介绍 ******/
/* 作用 : 将IO口设置为输出
 * 传入参数 :
     * ui32Port : GPIO_PORTx_BASE,x可为A,B,C,D,E,F,G,H,J,K
     * ui8Pins : GPIO_PIN_x,x可为1,2,3,4,5,6,7
 *返回值 : 无
*/

ROM_GPIOPinWrite()

After we configure the IO, we need to set its output pin level. Because my LED is a common anode, the output is low to light up the LED.

/****** 函数声明 ******/
//这个存放在ROM
void ROM_GPIOPinWrite(uint32_t ui32Port,
uint8_t ui8Pins,
uint8_t ui8Val);
//这个存放在flash
void GPIOPinWrite(uint32_t ui32Port,
uint8_t ui8Pins,
uint8_t ui8Val);

/****** 函数介绍 ******/
/* 作用 : 设置IO口电平
 * 传入参数 :
     * ui32Port : GPIO_PORTx_BASE,x可为A,B,C,D,E,F,G,H,J,K
     * ui8Pins : GPIO_PIN_x,x可为1,2,3,4,5,6,7
     * ui8Val : GPIO_PIN_x表示设置为高电平,!GPIO_PIN_x表示设置为低电平
 *返回值 : 无
*/

code practice

#include "stdio.h"
#include <stdint.h>
#include <stdbool.h>
#include "hw_memmap.h"
#include "hw_types.h"
#include "hw_gpio.h"
#include "debug.h"
#include "fpu.h"
#include "gpio.h"
#include "pin_map.h"
#include "rom.h"
#include "sysctl.h"
#include "uart.h"
#include "uartstdio.h"


#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
    
    
}
#endif

int main(void)
{
    
    
	ROM_FPUEnable();//使能浮点单元。这个函数必须在执行任何硬件浮点运算之前被调用;如果不这样做,将导致NOCP使用错误。
	ROM_FPULazyStackingEnable();//浮点延迟堆栈,减少中断响应延迟 
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);//配置系统时钟,系统时钟频率400M/2/2.5=80M
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);  //使能GPIOF外设	
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4);// LED
	ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_PIN_4);//置高位熄灭
    while(1)
    {
    
    
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_5, !GPIO_PIN_5);//置低位点亮
			SysCtlDelay(SysCtlClockGet() / 10); //延时0.1s,为什么先不用管,后面会讲解
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_5, GPIO_PIN_5);//置高位熄灭
			SysCtlDelay(SysCtlClockGet() / 10);//延时0.1s,为什么先不用管,后面会讲解
}

Guess you like

Origin blog.csdn.net/qq_63922192/article/details/132145622