Вы находитесь на странице: 1из 54

Embedded System Design

Using ARM controllers


Nuvoton NuMicro-Cortex-M0
ARM

Dr Ramani Kalpathi
Professor, St. Josephs College of
Engineering

Agenda
Introduction to ARM Cortex-M0 Nuvoton-

NuMicro family
Programming Tools for ARM processors
NuMicro Learning Board Hardware Peripherals
NuTiny NUC140 Project Board
Keil Integrated Design Environment Tool Chain
Assembling, compiling, linking and Load
process
Compilation using C language, Build process
ARM processor peripherals
Applications using peripherals-ADC, Timer, I/O

Nuvoton ARM Academic Program


Memorandum of Understanding signed between

various colleges and Nuvoton Corporation, Taiwan


Nuvoton NuMicro lab has been setup to advance the
knowledge of students and teaching/research faculty
Nuvoton has provided learning boards, training
material and sample programs to establish a training
academy for embedded systems
The faculty of various colleges have undergone
training in using the learning boards.
The students are being further trained to start
working on Cortex-M0 platforms for final year
projects at the B.E and M.E level

Nuvoton ARM Academic Program


Projects on Power Electronic converters (DC-DC

converters), Instrumentation, Motor controls


and wireless communication will be the focus .
Projects are being designed using Nu-Tiny-SDKNUC140 (low cost version with peripheral ports
being available for interfacing to various
sensors, gate drivers and relays)
RTOS using ARM kits are part of the curriculum
in Electronics and Communication and the
Nuvoton Cortex-M0 learning boards provide
examples with FreeRTOS that is being adopted
by other departments

NuMicro Cortex-MO
NuMicro NUC100 Series includes NUC100,

NUC120, NUC130 and NUC140 product lines.


The NuMicro NUC140 Connectivity Line with USB
2.0 full-speed and CAN functions embeds CortexM0 core running up to 50 MHz with 32K/64K/128Kbyte embedded flash, 4K/8K/16K-byte embedded
SRAM, and 4K-byte loader ROM for the ISP. It also
includes peripheral devices such as Timers,
Watchdog Timer, RTC, PDMA, UART, SPI, I2C, I2S,
PWM Timer, GPIO, LIN, CAN, PS/2, USB 2.0 FS
Device, 12-bit ADC, Analog Comparator, Low
Voltage Reset Controller and Brown-out Detector.

NuMicro Family

NUC140 Learning Board

NU-TINY-SDK 140

NUC140 Core Features


ARM Cortex-M0 core runs up to 50 MHz
One 24-bit system timer
Supports low power sleep mode
Single-cycle 32-bit hardware multiplier
NVIC for the 32 interrupt inputs, each

with 4-levels of priority


Serial Wire Debug supports with 2
watchpoints /4 breakpoints
Built-in LDO for wide operating voltage

ranges from 2.5 V to 5.5 V

Flash Memory Features

32K/64K/128K bytes Flash for program code

4KB flash for ISP loader

Support In-system program (ISP) application code

update

512 byte page erase for flash

Configurable data flash address and size for


128KB system, fixed 4KB data flash for the 32KB
and 64KB system

Support 2 wire ICP update through SWD/ICE


interface

Support fast parallel programming mode by


external programmer

SRAM and DMA


4K/8K/16K bytes embedded SRAM
Support PDMA mode
Support 9 channels PDMA for automatic data

transfer between SRAM and peripherals

Clock
Flexible selection for different applications
Built-in 22.1184 MHz high speed OSC for system operation
Trimmed to

1 % at +25 and VDD = 5 V


Trimmed to 3 % at -40 ~ +85 and VDD = 2.5 V ~
5.5 V
Built-in 10 KHz low speed OSC for Watchdog Timer and
Wake-up operation
Support one PLL, up to 50 MHz, for high performance
system operation
External 4~24 MHz high speed crystal input for USB and
precise timing operation
External 32.768 kHz low speed crystal input for RTC
function and low power system operation

General Purpose I/O


Four I/O modes:
Quasi bi-direction
Push-Pull output
Open-Drain output
Input only with high impendence
TTL/Schmitt trigger input selectable
I/O pin can be configured as interrupt
source with edge/level setting
High driver and high sink IO mode support

Timer
Support 4 sets of 32-bit timers with 24-bit up-timer and
one 8-bit pre-scale counter
Independent clock source for each timer
Provides one-shot, periodic, toggle and continuous
counting operation modes
Support event counting function
Support input capture function
Watchdog Timer
Multiple clock sources
8 selectable time out period from 1.6ms ~ 26.0sec
(depends on clock source)
WDT can wake-up from power down or idle mode
Interrupt or reset selectable on watchdog time-out

Real Time Clock (RTC)


Support software compensation by setting

frequency compensate register (FCR)


Support RTC counter (second, minute, hour) and
calendar counter (day, month, year)
Support Alarm registers (second, minute, hour,
day, month, year)
Selectable 12-hour or 24-hour mode
Automatic leap year recognition
Support periodic time tick interrupt with 8 period
options 1/128, 1/64, 1/32, 1/16, 1/8, 1/4, 1/2 and 1
second
Support wake-up function

Pulse Width Modulation /


Capture
Built-in up to four 16-bit PWM generators

provide eight PWM outputs or four


complementary paired PWM outputs
Each PWM generator equipped with one
clock source selector, one clock divider, one
8-bit prescaler and one Dead-Zone generator
for complementary paired PWM
Up to eight 16-bit digital Capture timers
(shared with PWM timers) provide eight
rising/falling capture inputs
Support Capture interrupt

UART
Up to three UART controllers
UART ports with flow control (TXD, RXD, CTS and

RTS)
UART0 with 64-byte FIFO is for high speed
UART1/2(optional) with 16-byte FIFO for standard
device
Support IrDA (SIR) and LIN function
Support RS-485 9-bit mode and direction control.
Programmable baud-rate generator up to 1/16
system clock
Support PDMA mode

SPI Interface
Up to four sets of SPI controller
Master up to 32 MHz, and Slave up to 10 MHz (chip working @

5V)
Support SPI master/slave mode
Full duplex synchronous serial data transfer
Variable length of transfer data from 1 to 32 bits
MSB or LSB first data transfer
Rx and Tx on both rising or falling edge of serial clock
independently
2 slave/device select lines when it is as the master, and 1
slave/when it is as the slave
Support byte suspend mode in 32-bit transmission
Support PDMA mode
Support three wire, no slave select signal, bi-direction interface

I2C Interface
Up to two sets of I2C device
Master/Slave mode
Bidirectional data transfer between masters and slaves
Multi-master bus (no central master)
Arbitration between simultaneously transmitting masters

without corruption of serial data on the bus


Serial clock synchronization allows devices with different
bit rates to communicate via one serial bus
Serial clock synchronization can be used as a handshake
mechanism to suspend and resume serial transfer
Programmable clocks allow versatile rate control
Support multiple address recognition (four slave address
with mask option)

I2S Interface
Interface with external audio CODEC
Operate as either master or slave mode
Capable of handling 8-, 16-, 24- and 32-bit word

sizes
Mono and stereo audio data supported
I2S and MSB justified data format supported
Two 8 word FIFO data buffers are provided, one for
transmit and one for receive
Generates interrupt requests when buffer levels
cross a programmable boundary
Support two DMA requests, one for transmit and
one for receive

Controller Area Network


(CAN2.0)
Supports CAN protocol version 2.0 part A and B
Bit rates up to 1M bit/s
32 Message Objects
Each Message Object has its own identifier

mask
Programmable FIFO mode (concatenation of
Message Object)
Maskable interrupt
Disabled Automatic Re-transmission mode for
Time Triggered CAN applications
Support power down wake-up function

USB 2.0 Full-Speed Device


One set of USB 2.0 FS Device 12Mbps
On-chip USB Transceiver
Provide 1 interrupt source with 4 interrupt events
Support Control, Bulk In/Out, Interrupt and

Isochronous transfers
Auto suspend function when no bus signaling for
3 ms
Provide 6 programmable endpoints
Include 512 Bytes internal SRAM as USB buffer
Provide remote wake-up capability

Analog to Digital
Converter
12-bit SAR ADC with 700K SPS
Up to 8-ch single-end input or 4-ch

differential input
Single scan/single cycle scan/continuous scan
Each channel with individual result register
Scan on enabled channels
Threshold voltage detection
Conversion start by software programming or
external input
Support PDMA Mode

Other Features
Analog Comparator
Up to two analog comparators
External input or internal bandgap voltage
selectable at negative node
Interrupt when compare result change
Power down wake-up
One built-in temperature sensor with 1
resolution
Brown-Out detector
With 4 levels: 4.5 V/3.8 V/2.7 V/2.2 V
Support Brown-Out Interrupt and Reset option

Other Features
Low Voltage Reset

Threshold voltage levels: 2.0 V


Operating Temperature: -40~85
Packages:
All Green package (RoHS)
LQFP 100-pin / 64-pin / 48-pin

NUC Product Selection

NUC140 Block Diagram

Keil-ARM Integrated
Development Platform
The programmer can use the Keil IDE to develop

programs using a PC, build the program with the


associated libraries and generate an executable
code.
The IDE also allows downloading the executable
version to the Flash memory of the Cortex-M0
controller so that the program can execute in a
standalone mode using the NUC-140 learning board
or NU-Tiny 140 board.
C or assembly language programs can be designed in
this environment. Nuvoton provides supporting driver
files that need to be included in the Keil programming
environment to assist the programmer.

Create Projects using Keil


Create a new project folder where you

would like to locate the programs. Here it is


shown as d:\Prgs

Invoking the IDE


Start the Keil uVision4 by clicking on the

icon

Starting a New Project


Click on Project-New uVision Project and enter

the name Prog1 as the name for the project as


shown.

Naming the Project

Associate the project with


Nuvoton Cortex M0 family
Select CPU Base File as Nuvoton Cortex M0

Database

Select CPU as Nuvoton


family

Selection of specific
controller
Click on the + symbol and Select Nuvoton

NUC140VE3CN as the target controller as


shown.

Startup file
Click on No if prompted for adding the startup

file.( We will need the startup file but we will


copy the same from an already existing project
later)

Adding the supporting files


Copy the files that have an extension of .c, .h

and .s from the provided CD to get started as


shown into the folder d:\Prgs.
Now add these files to the project by selecting
Project-Manage-Components

Adding C files to the


project
Select file type as C source, click on one C file

use Ctrl-A to select all the C-files and add them


to the present project using the Add Files
button. (Note that the C files are being
provided to you in a preexisting CD in this
case).

Adding Header files


Select file type as text, click on one h file use

Ctrl-A to select all the header files and add


them to the present project using the Add Files
button. (Note that the header files are being
provided to you in a preexisting CD in this
case).
Add the startup file NUC1xx.s also similarly.

Ensure Output Hex file


generation
Select Project-Select Device for Target1 and similarly

select NuMicro Cortex M0 Database. Click OK. Click on


+next to Nuvoton and select the target controller
NUC140VE3CN by scrolling through the window. Click
on OK after the selection.
Click on Project-Options for Target
Ensure that Device selected is NUC140VE3CN by
clicking on Device and making sure that device is
highlighted.
Click on Output and select the window for creating
Hex file
The other options may be left at default unless you
want to change any later.

Building the project


Click on Prog1.c file to display the C file in the

window. Select Project-Build to start the


compilation and linking process.

Clearing errors, Configure Flash


tools
If no errors are present the compilation will

complete with Prg1.axf showing 0 errors and 0


warnings.
To configure the flash download tool, click on
Flash-Configure Flash Tools and select Use
Target Driver for Flash. Select Nuvoton Nu-Link
M0 Debugger. Click on OK.

Flash Tools configuration

Downloading to Flash
memory
Connect the NUC140 learning board using the

USB cable to the computer. Click on FlashDownload to transfer the program from the PC
to the flash memory of the ARM controller.

Running the embedded


system
Press the reset button after a few seconds

and the program will start running on the


learning board.

C Programs Blink LEDs


//Toggle

the pins on Port C, GPC-13 and GPC-14


is connected to LED 6 on the learning board
//GPC-14 is connected to LED 7 on the learning board
#include "DrvGPIO.h
uint16_t i; //Declare unsigned 16 bit variables
uint32_t delaycount;
int main(void)
{

DrvGPIO_Open(E_GPC,13,E_IO_OUTPUT); //Configure GPC-13 to output mode


DrvGPIO_Open(E_GPC,14,E_IO_OUTPUT); //Configure GPC-14 to output mode
while(1)
{
GPC_13 =1;
//Set GPA_13 to high
GPC_14=1;
delaycount=0xCFFFF;
while(--delaycount);
GPC_13 =0;
//Set GPA_13 to low
GPC_14=0;
delaycount=0xCFFFF;
while(--delaycount);
}
}
//GPC-13

//

Refer-NuMicro NUC100 Series Driver Reference Guide

LED interface

Writing to LCD
//SPI routines are used to pass data to the LCD
// LCD Hardware connections: GPD11- Pin 18 of LCD - SPI data; GPD9 - Pin 21 of

LCD - SPI Clock


//GPD10- Pin25 of LCD RST; GPD8 - Pin26 of LCD - CS
#include <stdio.h>
#include "NUC1xx.h"
#include "DrvSYS.h"
#include "DrvGPIO.h"
#include "LCD_Driver.h"
#include "Seven_Segment.h"
int main(void)
{

Initial_pannel(); //call initial pannel function

clr_all_pannal();

print_lcd(0, "Welcome to

print_lcd(1, "St.Josephs

");

print_lcd(2, "College of

");

print_lcd(3, "Engineering

while(1);

");

");

LCD Interface (SPI)

Assembly Language Programs


;Prasm1.s
;Add the contents of 8-bit data present in two registers R0,R1
from and store the result ;in R2
MOVS R0,#30
MOVS R1,#56
ADD R1,R1,R0
MOVS R2,R1
STOP B STOP

END

Prasm2.s
;Add the contents of 32-bit data present in two memory locations Value1 and Value2
;and store the added value in a memory location called Result
;

STOP

LDR R0, = Value1 ; Load the address of Value1


LDR R1,[R0]
; Load the contents of the address &34567890
LDR R2, = Value2 ; Load the address of Value2
LDR R3,[R2]
; Load the contents of the address &4545566
ADDS R3,R3,R1
; Add the two numbers and store in R3
LDR R5,=Result ; Load the memory address of Result in R5
STR R3,[R5]
; Store the sum in the memory
B STOP

ALIGN
Value1 DCD &34567890
Value2 DCD &45455656
AREA
Result DCD 0
END

DATATABLE, DATA,READWRITE
; First location in memory zero offset

;Prasm3.s
;Compute the factorial of a number stored in a memory location Number
;Store the computed factorial in the memory area declared under Result
LDR R0, = Number ; Load the address of Number in R0
LDR R1,[R0]
; Load the number in R1
MOVS R2,R1
; Copy the number to R2
LOOP CMPS R2,#1
; Compare the number in R1 with 1
BEQ SAVE
SUBS R2,R2,#1 ; Subtract the value in R2 with 1 and save in R2
MULS R1,R2,R1 ; Multiply the value in R1 with decremented number in R2.
Store result in R1.
B LOOP
; Continue loop if the value in R1 is not equal to 0
SAVE LDR R5,=Result
STR R1,[R5]
; Store the factorial in the memory (0x20000000)
STOP B STOP
ALIGN
Number DCD 9
;Declare the number whose factorial needs to be computed
AREA DATATABLE, DATA,READWRITE
Result DCD 0
; Memory address is 0x20000000
END

// ANALOG TO DIGITAL CONVERSION : 12-bit ADC value is written into LCD from 0 to 4095
#include <stdio.h>
#include "NUC1xx.h"
#include "LCD_Driver.h
void InitADC(void)
{
/* Step 1. GPIO initial */
GPIOA->OFFD|=0x00800000; //Disable digital input path
SYS->GPAMFP.ADC7_SS21_AD6=1; //Set ADC function
/* Step 2. Enable and Select ADC clock source, and then enable ADC module */
SYSCLK->CLKSEL1.ADC_S = 2; //Select 22Mhz for ADC
SYSCLK->CLKDIV.ADC_N = 1; //ADC clock source = 22Mhz/2 =11Mhz;
SYSCLK->APBCLK.ADC_EN = 1; //Enable clock source
ADC->ADCR.ADEN = 1; //Enable ADC module
/* Step 3. Select Operation mode */
ADC->ADCR.DIFFEN = 0;
//single end input
ADC->ADCR.ADMD = 0;
//single mode
/* Step 4. Select ADC channel */
ADC->ADCHER.CHEN = 0x80;
/* Step 5. Enable ADC interrupt
ADC->ADSR.ADF =1;
//clear the A/D interrupt flags for safe
ADC->ADCR.ADIE = 1;
/* Step 6. Enable WDT module */
ADC->ADCR.ADST=1;
}

*---------------------------------------------------------------------------MAIN function
----------------------------------------------------------------------------*/
int32_t main (void)
{
//Enable 12Mhz and set HCLK->12Mhz
char adc_value[15]="ADC Value:";
UNLOCKREG();
SYSCLK->PWRCON.XTL12M_EN = 1;
SYSCLK->CLKSEL0.HCLK_S = 0;
LOCKREG();
InitADC();
Initial_pannel(); //call initial pannel function
clr_all_pannal();
/* Synch field transmission & Request Identifier Field transmission*/
while(1)
{
while(ADC->ADSR.ADF==0);
ADC->ADSR.ADF=1;
sprintf(adc_value+10,"%d",ADC->ADDR[7].RSLT);
print_lcd(0, adc_value);
Delay(20000);
ADC->ADCR.ADST=1;
}
}

Вам также может понравиться