Professional Documents
Culture Documents
NHÚNG
Eval Kit 30-day full 32KB code size 32KB code size Full function.
License function. limited. limited. Onboard
Upgradeable Upgradeable Upgradeable emulation limited
99 USD
personal MDK-Basic (256
Full Upgrade edition / 2700 USD KB) = €2000 445 USD
2800 USD (2895 USD)
full support
JTAG J-Link, 299 U-Link, 199 USD XDS100, 79 USD
Debugger USD
PC7
PC6
GPIO Port C GPIO Port D PD7
PD6
6 General-Purpose I/O
PC5
PC4
USB 2.0 Twelve
Timers
PD5
PD4
(GPIO) ports:
PC3/TDO/SWO PD3 • Four 8-bit ports (A, B,
PC2/TDI JTAG Six PD2
PC1/TMS/SWDIO
PC0/TCK/SWCLK
64-bit wide PD1
PD0
C, D)
• One 6-bit port (E)
GPIO Port E GPIO Port F • One 5-bit port (F)
PE5
PE4 ADC Two Analog PF4
PE3 2 channels Comparators PF3
PE2 12 inputs PF2
PE1 12 bits Two PWM PF1
PE0 Modules PF0
- Plus -
The internal PLL (400 MHz)
The internal 16MHz oscillator divided by four (4MHz ± 3%)
Processor
n n
DQ Input/Output Port
GPIOPinTypeGPIOOutput(GPIO_PORT
F_BASE, GPIO_PIN_3)
GPIOPinWrite(GPIO_PORTF_BASE,
GPIO_PIN_3, 1 << 3)
PortA 0x40004000
PortB 0x40005000
PortC 0x40006000
PortD 0x40007000
PortE 0x40024000
PortF 0x40025000
XTAL
Bộ dao động nội giúp giảm giá thành, nhưng độ chính xác không cao
LM4F120 được tích hợp bộ dao động 16 Mhz, tốc độ hoạt động tối đa là 80
MHz
uint8_t ui8PinData=2;
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
while(1)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3, ui8PinData);
SysCtlDelay(2000000);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
SysCtlDelay(2000000);
if(ui8PinData==8) {ui8PinData=2;} else {ui8PinData=ui8PinData*2;}
}
}
Tail Chaining...
Interrupt Latency - Tail Chaining
Highest
Priority IRQ
1
IRQ
2
Tail-
chaining
Cortex-M4 PUSH ISR 1 ISR 2 POP
Interrupt handling in HW
12 6 12
Cycles Cycles Cycles
Highest
Priority IRQ1
IRQ2
Highest IRQ1
Priority
IRQ2
Entry
Automatically pushes registers R0–R3, R12, LR, PSR, and PC onto the
stack
In parallel, ISR is pre-fetched on the instruction bus. ISR ready to start
executing as soon as stack PUSH complete
Exit
Processor state is automatically restored from the stack
In parallel, interrupted instruction is pre-fetched ready for execution
upon completion of stack POP
Timer modes:
• One-shot
• Periodic
• Input edge count or time capture with 16-bit prescaler
• PWM generation (separated only)
• Real-Time Clock (concatenated only)
Count up or down
Simple PWM (no deadband generation)
Support for timer synchronization, daisy-chains, and stalling during debugging
May trigger ADC samples or DMA transfers
int main(void)
{
uint32_t ui32Period;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
while(1)
{
}
} 49
BM Kỹ Thuật Điện Tử - ĐH Bách Khoa TP.HCM
Timer interrupt example
void Timer0IntHandler(void)
{
// Clear the timer interrupt
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
Systick Period
Nếu bằng 1, nguồn clock cho Systick Timer là xung nhịp clock hệ thống
Bit INTEN:
Cấu hình mức ưu tiên của ngắt SysTick bằng cách ghi vào các bit TICK của
thanh ghi NVIC_SYS_PRI3_R.
Set ENABLE bit để cho phép timer chạy.
main(void)
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC
| SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
InitConsole();
g_ulCounter = 0;
SysTickPeriodSet(SysCtlClockGet());
IntMasterEnable();
SysTickIntEnable();
SysTickEnable();
if(ulPrevCount != g_ulCounter)
UARTprintf("Number of interrupts:
%d\r",g_ulCounter);
ulPrevCount = g_ulCounter;
InitConsole(void)
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 |
GPIO_PIN_1);
UARTStdioInit(0);
UART_FIFO_TX4_8
Trigger points for FIFO interrupts
can be set at 1/8, 1/4, 1/2,3/4, 7/8
full, e.g.
UARTFIFOLevelSet(UART0_BASE,
UART_FIFO_TX6_8
UART_FIFO_TX4_8,
UART_FIFO_TX7_8 UART_FIFO_RX4_8);
int main(void) {
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
while (1)
{
if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
}
void UARTIntHandler(void)
{
uint32_t ui32Status;
ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status
UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTCharPut(UART0_BASE, 'E');
UARTCharPut(UART0_BASE, 'n');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, 'e');
UARTCharPut(UART0_BASE, 'r');
UARTCharPut(UART0_BASE, ' ');
UARTCharPut(UART0_BASE, 'T');
UARTCharPut(UART0_BASE, 'e');
UARTCharPut(UART0_BASE, 'x');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, ':');
UARTCharPut(UART0_BASE, ' ');
Half (16-bit)
Single (32-bit)
Double (64-bit)
Quadruple (128-bit)
Symbol s e f
Example 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X
Default NaN (not a number) mode – In this mode, the result of any
arithmetic data processing operation that involves an input NaN, or
that generates a NaN result, returns the default NaN. ( 0 / 0 = NaN )
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
int32_t i32DataCount = 0;
ROM_FPULazyStackingEnable();
ROM_FPUEnable();
while(1)
{
}
}