Docsity

ARM Development Environments - Notes | EEMB 189, Study notes of Biology

Partial preview of the text

Download ARM Development Environments - Notes | EEMB 189 and more Study notes Biology in PDF only on Docsity!

  • ARM IDEs and I2C ECE 189B --- April 7,

ARM Development Environments ^ Several IDEs exist on the market for ARM-basedsystems^ 

Green Hills Software (based in Santa Barbara)  Keil μVisionTools (a division of ARM, Ltd)  ....

^ We use the Keil Tools for ECE189A/B^ 

Eval version is installed on digilab computers  Many ARM-based processors are supported^ ^ Limitations exist, however … primarily based on code

size

^ For larger projects, use the GNU tools (free & unrestricted)^ ^

Significantly harder to setup, but correct & complete

Keil’s startup.s^ ^ Once you have specified the processor^ 

Keil tools insert an assembly file in your project^ ^ Startup.s …. written in ARM assembly, with GUI hooks^ ^ There are structured comments … if you edit, leave them in!^ ^ “Configuration” pane lets you make changes via GUI

^ doesn’t seem to be there on the newest Keil version, however?

^ Keil startup gets CPU initialized, sets up ‘C’runtime system, then calls main() ^ Your first program can probably just startwiggling a GPIO line^ 

Later, you can carefully add other peripheral inits, etc.  We suggest getting a public-domain example to start

The boot process … LPC2xxx^ ^ Philips LPC2xxx family contains an integrated boot loader^ 

If P0.14 (pin 41) is low when CPU comes out of reset, the boot loader isactivated  UART0 is used and it autobauds  so you can use a relatively fast setting … say 38400  Set TeraTerm for 9600-8-N-1 with no flow control  Send “?” (and wait to receive)  Receive “Synchronized”  Send

“Synchronized” ... (case is significant)

^ Receive “OKlf>” ^ Send crystal frequency in KHz, e.g. “20000” ^ Receive “OK” ^ Send various boot loader commands ….  Read app note AN10302, available from Philips (NXP) website ^ Best to get the Philips ISP Utility, a nice GUI that handles everything …

The boot process … STR71X^ ^ STR71X has configurable boot pins … booten + boot[1:0]^ 

Flash (internal …. only possible after initial programming)
^01 
Boot (special hookup required)
^10 
Ram (requires JTAG or prior boot loader installation)
^11 
External (@ 0x6000 0000 on CSn.0 in 16-bit mode)

^ After reset

^ 1, boot settings can be changed by software

^ Recommend using External (11) mode (with BootEn high)^ ^

Keil generates flash image for 16-bit-wide memory at 0x60000000  Use GNU objcopy (or write your own) to strip image into two files^ ^ corresponding to separate even and odd flash memories  Write the two images into even and odd flash chips  Install in on-board sockets  Reset processor ….

(^2) IC for all processor types ^ Master mode only (i.e. processor is master)^ ^

Master drives all clocking, makes all START and STOP conditions

^ Addresses are 7-bits plus 1 bit direction (0=write, 1=read) ^ Initialization sets bit rate (100KHz or 400KHz typical max)

void^ WriteBlkI2C(char
addrx2,
char^
*buffer,
unsigned
char^
len)
{ StartI2C();
//^ generate
a^ START
condition
WaitI2C();SSPBUF
=^ addrx2;
//^ send
address
(7^ bits
+^ direction=0)
WaitI2C();while(len--
>^ 0)^
SSPBUF
=^ *buffer++;
send^
next^ data
WaitI2C();} StopI2C();
//^ generate
a^ STOP
condition
WaitI2C();}  Earlier, before using the above … you must open and initialize I2C #include
<i2c.h>:
OpenI2C(
MASTER,
SLEW_OFF
SSPADD
=^ 24;
//^ set
bit^ rate
(per^
your^ crystal)

(^2) IC --- WRITE

on a PIC

#define WaitI2C() {
\
while(!PIR1bits.SSPIF) continue;
\
PIR1bits.SSPIF = 0;
\

} This can also be packaged as a function

…^ void WaitI2C(void)

(^2) IC --- WaitI2C() on a PIC

void^ ReadBlkI2C(char addrx2,

char^ reg,

char *buffer, unsigned

char^ len)

{ StartI2C();

//^ generate a

START^ condition

WaitI2C();SSPBUF^ =^ addrx2;

//^ write

address

of^ slave

(dir=WRITE)

WaitI2C();SSPBUF^ =^ reg;^

//^ write

register within

slave^ to^ read

WaitI2C();RestartI2C();

//^ generate a

(RE)START

condition

WaitI2C();SSPBUF^ =^ addrx2|1;

//^ send (addrx2|1);

----^ address

for^ READ

WaitI2C();while(len--

^ 1)^ {

//^ for^ all but^

the^ LAST byte

to^ be^ read

SSPCON2bits.RCEN

=^ 1;^ //^ enable

receiver

WaitI2C();*buffer++

=^ SSPBUF;

//^ Read

next^ data byte

AckI2C();

//^ acknowledge

the^ read

WaitI2C();} SSPCON2bits.RCEN =

1;^

//^ enable

receiver

for last

byte

WaitI2C();*buffer++

=^ SSPBUF;

//^ read^

last^ data

byte

NotAckI2C();

//^ negative

acknowledge to show

END^ of reading

WaitI2C();StopI2C();

//^ generate

a^ STOP condition

(^2) IC --- READ on a PIC WaitI2C();}

void^ writeToReg

( unsigned

char^ reg, unsigned

char^ data

)

{ I2C_STARTGenerate (I2C0,

ENABLE);

//^ Generate

a^ START

while^ (I2C_FlagStatus

(I2C0, DIRECT, I2C_SB)

==^ RESET);

I2C_AddressSend

(I2C0, 0x86,^ I2C_Mode7,

I2C_TX);

//^ Send device address

while^ (I2C_TransmissionStatus(I2C0)

!=^ I2C_TX_ADD_OK);

I2C_FlagClear

(I2C0, I2C_ENDAD); while^ (I2C_FlagStatus

(I2C0, DIRECT, I2C_BTF)

==^ RESET);

I2C_FlagClear

(I2C0, I2C_BTF); I2C_ByteSend

(I2C0, reg);^

//^ Send target address

while^ (I2C_FlagStatus

(I2C0, DIRECT, I2C_BTF)

==^ RESET);

I2C_FlagClear

(I2C0, I2C_BTF); I2C_ByteSend

(I2C0, data);

//^ Send 1-byte payload

while^ (I2C_FlagStatus

(I2C0, DIRECT, I2C_BTF)

==^ RESET);

I2C_FlagClear

(I2C0, I2C_BTF); I2C_STOPGenerate

(I2C0, ENABLE);

//^ Generate

STOP^ condition

} Note: this is just a single-byte payload routine^ ^

(^2) IC --- WRITE It would be easy to make it write an arbitrary-length block … how?^ ^ As with the PIC, the I2C subsystem must first be opened

(from ARM STM library)

unsigned^

char^ grabReg

(^ unsigned

char^ reg

)

{ unsigned

char^ I2Cdata

=^ 0; I2C_STARTGenerate

(I2C0,^ ENABLE);

//^ Generate

a^ START

while^ (I2C_FlagStatus

(I2C0,^ DIRECT,

I2C_SB)^

==^ RESET);

I2C_AddressSend

(I2C0,^ 0x86,

I2C_Mode7,

I2C_TX);

//^ Send^ device

address

while^ (I2C_TransmissionStatus(I2C0)

!=^ I2C_TX_ADD_OK);

I2C_FlagClear

(I2C0,^ I2C_ENDAD); while^ (I2C_FlagStatus

(I2C0,^ DIRECT,

I2C_BTF)

==^ RESET)

;

I2C_FlagClear

(I2C0,^ I2C_BTF); I2C_ByteSend

(I2C0,^ reg);

//^ Send^ target

address

//^ while

(I2C_FlagStatus

(I2C0,^ DIRECT,

I2C_BTF)

==^ RESET);

I2C_FlagClear

(I2C0,^ I2C_BTF); I2C_STARTGenerate

(I2C0,^ ENABLE);

//^ Generate

a^ (re-)start

//^ while

(I2C_FlagStatus

(I2C0,^ DIRECT,

I2C_SB)^

==^ RESET);

I2C_AddressSend

(I2C0,^ 0x87,

I2C_Mode7,

I2C_RX);

//^ Send^ device

address

//^ while

(I2C_TransmissionStatus(I2C0)

!=^ I2C_TX_ADD_OK);

I2C_FlagClear

(I2C0,^ I2C_ENDAD); //^ while

(I2C_FlagStatus

(I2C0,^ DIRECT,

I2C_BTF)

==^ RESET);

I2C_STOPGenerate

(I2C0,^ ENABLE);

//^ Generate

stop^ condition

//^ while

(I2C_ReceptionStatus(I2C0)

!=^ I2C_RX_DATA_OK);

I2Cdata^ =

I2C_ByteReceive(I2C0);

//^ Receive

byte

I2C_FlagClear

(I2C0,^ I2C_BTF); (^2) IC --- Read return^ I2Cdata;} Note: This code from former year’s 189 project

(from ARM STM library)

Class Meeting Schedule (reminder)

ARM Development Environment Tour^ ^ Demo Keil μVisionTools via remote desktop^ 

Project creation (including processor selection)  Editing of the startup file via GUI  Creation of simple main()  Project build, including quick walkthrough of options  Simulation, showing breakpoints & device access