WCL 201101846 조윤정 Arduino Bootloader 코드 분석. BAUD_RATE 설정 /* set the UART baud rate defaults */ #ifndef BAUD_RATE #if F_CPU >= 8000000L #define BAUD_RATE.

Slides:



Advertisements
Similar presentations
Serial Communications (Chapter 10)
Advertisements

1 Homework Reading (linked from my web page) –S and S Extracts –National Semiconductor UART Data Sheet Machine Projects –mp2 due at start of class 12 Labs.
Review: Interrupts & Timers
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
C Examples 1.
ECT 357 Ch 18 UART. Today’s Quote: Be careful that your marriage doesn’t become a duel instead of a duet. Be careful that your marriage doesn’t become.
Lab 3 General MIDI Explorer with Record/Playback
Hierarchy of I/O Control Devices
COMP3221: Microprocessors and Embedded Systems Lecture 22: Serial Input/Output (II) Lecturer: Hui Wu Session 1, 2005.
USARTS CS423 Dick Steflik. USART ● Universal Synchronous Asynchronous Receiver Transmitter ● used to send and receive small packets over a serial line.
Infineon Technologies Corp. June 99 1 HOT167-1 Version 2.0 * C167CS not yet supported by DAvE V1.0 CD ROM. See “Hints regarding DAvE.” Exercise 7ASC_1.
Fuses and Lock Bits The ATMega128 has several special memory areas -Six lock bits which determine program memory features. -Three fuse bytes which determine.
Butterfly I/O Ports CS-212 Dick Steflik. I/O for our labs To get data into and out of our Butterfly its a little trickier than using printf and scanf.
USART and Asynchrono us Communica tion The USART is used for synchronous and asynchronous serial communication. USART = Universal Synchronous/Asynchronous.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Arduino Interrupts Paul MacDougal September 8, 2014.
External & internal Interrupts. Interrupt Sources There are 21 different interrupts and each one has its own vector located in a predefined location at.
Lecture 13: TI MSP430 Watchdog Timer and Real-Time Clock
NS Training Hardware. System Controller Module.
MSP432™ MCUs Training Part 5: Digital Peripherals
Serial Communication ETEC 6416.
328eForth for Arduino Uno C. H. Ting February 16, 2012 SVFIG.
System Clock, Crossbar and GPIO
SC200x Peripherals Broadband Entertainment Division DTV Source Applications July 2001.
Lecture 9. - Synchronous Devices require a timing signal. Clock generated Interval Timer Microprocessor Interval Timer Clk PCLK = MHz PCLK (for.
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
Chapter 6: Interrupts and Resets
ATmega128RFA1 Power Measurement. ATmega128RFA1 SoC (uC and Transceiver) Up to 16 MHz (i.e. almost 16 MIPS) Voltage range: 1.8v to 3.6v 16K bytes RAM 128.
AT91 Embedded Peripherals
Microprocessor based Design for Biomedical Applications MBE 3 – MDBA III : The ATmega8 Basic Features (2)
Page 1 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/Jansen June 2003 N e v e r s t o p t h i n k i n g. Infineon C868 Hands On Training CAPCOM6.
Industrial Reference Design Platform RS-232 Interface Developed by the TSC Americas Release 1.0.
Arch1 LCD Lab Eric Freudenthal. Topics Score Demo LCD Panel Geometry Utilities to draw to the display Drawing characters Buttons Nuisance: multiple versions.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
CE-2810 Dr. Mark L. Hornick 1 Using the USART Configuration and Programming.
C Preprocessor Lightning Talk 12/08/2014 Paul MacDougal.
Jump, Loop, and Call Instructions
Lecture 18 CIS 208 Wednesday, March 30, Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.
Presented by: © 2015 Jacob Beningo All Rights Reserved Writing Portable and Robust Firmware in C September 2, 2015 Jacob Beningo, CSDP Class 3: Uart Driver.
Timer & Watch Dog Test UNIT 16 로봇 SW 교육원 조용수. 학습 목표 Timer Init Timer Delay Test Timer Interrupt Test –One Shot Mode –Periodic Mode Watch Dog Test 시계 만들어.
Communicating. The ATmega16 communicates through one of the following ways: Serial Peripheral Interface (SPI) Universal Synchronous and Asynchronous serial.
Chap.6.3 UART.
Microcontroller basics Embedded systems for mortals.
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
As a part of ALA in the subject of MCI ( ) subject faculty:Hiren Patel Sir Presentation on rtc interfacing with atmega32 using ds1307 By:selva kumar.r.
 The LPC2xxx devices currently have two on- chip UARTS.  Except UART1 has additional modem support.
Timers and Scheduled Interrupts
Chip Config & Drivers – Required Drivers:
80C51 Block Diagram ECE Overview.
Source: Serial Port Source:
Homework Reading (linked from my web page) Machine Projects Labs
4-Integrating Peripherals in Embedded Systems
RX Watchdog Timer (WDT)
ATMEGA 32 CONNECTIONS TO RS232; UDR AND UCSR REGISTERS
The Arduino Microcontroller: Atmel AVR Atmega 328
ATmega103 Timer0 and Interrupts
Arduino Interrupts I am amazed by how much I learned in preparing for this talk. I would encourage each of you to consider making a presentation, however.
UART Protocol Chapter 11 Sepehr Naimi
COMP3221: Microprocessors and Embedded Systems
Lecturer: Reza Arjmandi Autumn 2015
Configuration and Programming
Serial Communication 19th Han Seung Uk.
AVR UART The UART, or Universal Asynchronous Receiver Transmitter, provides hardware support for a serial port on AVR processors Signaling is compatible.
Presentation transcript:

WCL 조윤정 Arduino Bootloader 코드 분석

BAUD_RATE 설정 /* set the UART baud rate defaults */ #ifndef BAUD_RATE #if F_CPU >= L #define BAUD_RATE L // Highest rate Avrdude win32 will support #elsif F_CPU >= L #define BAUD_RATE 9600L // also supported, but with significant error #elsif F_CPU >= L #define BAUD_RATE 4800L // Good for 128kHz internal RC #else #define BAUD_RATE 1200L // Good even at 32768Hz #endif

Watchdog Timer /* Watchdog settings */ #define WATCHDOG_OFF (0) #define WATCHDOG_16MS (_BV(WDE)) //WDE : Watchdog System Reset Enable(Time out : 16ms) #define WATCHDOG_32MS (_BV(WDP0) | _BV(WDE)) // #define WATCHDOG_64MS (_BV(WDP1) | _BV(WDE)) #define WATCHDOG_125MS (_BV(WDP1) | _BV(WDP0) | _BV(WDE)) #define WATCHDOG_250MS (_BV(WDP2) | _BV(WDE)) #define WATCHDOG_500MS (_BV(WDP2) | _BV(WDP0) | _BV(WDE)) #define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE)) #define WATCHDOG_2S (_BV(WDP2) | _BV(WDP1) | _BV(WDP0) | _BV(WDE))

부트로더 위치 설정 #if defined(__AVR_ATmega168__) #define RAMSTART (0x100) #define NRWWSTART (0x3800) #elif defined(__AVR_ATmega328P__) #define RAMSTART (0x100) #define NRWWSTART (0x7000) #elif defined (__AVR_ATmega644P__) #define RAMSTART (0x100) #define NRWWSTART (0xE000) #elif defined(__AVR_ATtiny84__) #define RAMSTART (0x100) #define NRWWSTART (0x0000) #elif defined(__AVR_ATmega1280__) #define RAMSTART (0x200) #define NRWWSTART (0xE000) #elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__) #define RAMSTART (0x100) #define NRWWSTART (0x1800) #endif

main register uint16_t address = 0; register uint8_t length; ch = MCUSR; MCUSR = 0; if (!(ch & _BV(EXTRF))) appStart(); #if LED_START_FLASHES > 0 // Set up Timer 1 for timeout counter TCCR1B = _BV(CS12) | _BV(CS10); // div 1024 #endif #ifndef SOFT_UART #ifdef __AVR_ATmega8__ UCSRA = _BV(U2X); //Double speed mode USART UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1 UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 ); #else UCSR0A = _BV(U2X0); //Double speed mode USART0 UCSR0B = _BV(RXEN0) | _BV(TXEN0); UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 ); #endif watchdogConfig(WATCHDOG_1S); LED_DDR |= _BV(LED); #ifdef SOFT_UART /* Set TX pin as output */ UART_DDR |= _BV(UART_TX_BIT); #endif

main ch = getch(); if(ch == STK_GET_PARAMETER) { unsigned char which = getch(); verifySpace(); if (which == 0x82) { /* * Send optiboot version as "minor SW version" */ putch(OPTIBOOT_MINVER); //4 } else if (which == 0x81) { putch(OPTIBOOT_MAJVER); //4 } else { /* * GET PARAMETER returns a generic 0x03 reply for * other parameters - enough to keep Avrdude happy */ putch(0x03); } else if(ch == STK_SET_DEVICE) { // SET DEVICE is ignored getNch(20); } else if(ch == STK_SET_DEVICE_EXT) { // SET DEVICE EXT is ignored getNch(5); } else if(ch == STK_LOAD_ADDRESS) { // LOAD ADDRESS uint16_t newAddress; newAddress = getch(); newAddress = (newAddress & 0xff) | (getch() << 8); #ifdef RAMPZ // Transfer top bit to RAMPZ RAMPZ = (newAddress & 0x8000) ? 1 : 0; #endif newAddress += newAddress; // Convert from word address to byte address address = newAddress; verifySpace(); } else if(ch == STK_UNIVERSAL) { // UNIVERSAL command is ignored getNch(4); putch(0x00); }

함수 void getNch(uint8_t count) { do getch(); while (--count); verifySpace(); } void verifySpace() { if (getch() != CRC_EOP) { watchdogConfig(WATCHDOG_16MS); // shorten WD timeout while (1) // and busy- loop so that WD causes ; // a reset and app start. } putch(STK_INSYNC); } void watchdogConfig(uint8_t x) { WDTCSR = _BV(WDCE) | _BV(WDE); WDTCSR = x; } void appStart() { watchdogConfig(WATCHDOG_OFF); __asm__ __volatile__ ( #ifdef VIRTUAL_BOOT_PARTITION // Jump to WDT vector "ldi r30,4\n" "clr r31\n" #else // Jump to RST vector "clr r30\n" "clr r31\n" #endif "ijmp\n" ); }

STK500 constants list /* STK500 constants list, from AVRDUDE */ #define STK_OK 0x10 #define STK_FAILED 0x11 // Not used #define STK_UNKNOWN 0x12 // Not used #define STK_NODEVICE 0x13 // Not used #define STK_INSYNC 0x14 // ' ' #define STK_NOSYNC 0x15 // Not used #define ADC_CHANNEL_ERROR 0x16 // Not used #define ADC_MEASURE_OK 0x17 // Not used #define PWM_CHANNEL_ERROR 0x18 // Not used #define PWM_ADJUST_OK 0x19 // Not used #define CRC_EOP 0x20 // 'SPACE' #define STK_GET_SYNC 0x30 // '0' #define STK_GET_SIGN_ON 0x31 // '1' #define STK_SET_PARAMETER 0x40 // #define STK_GET_PARAMETER 0x41 // 'A' #define STK_SET_DEVICE 0x42 // 'B' #define STK_SET_DEVICE_EXT 0x45 // 'E' #define STK_ENTER_PROGMODE 0x50 // 'P' #define STK_LEAVE_PROGMODE 0x51 // 'Q' #define STK_CHIP_ERASE 0x52 // 'R' #define STK_CHECK_AUTOINC 0x53 // 'S' #define STK_LOAD_ADDRESS 0x55 // 'U' #define STK_UNIVERSAL 0x56 // 'V' #define STK_PROG_FLASH 0x60 // '`' #define STK_PROG_DATA 0x61 // 'a' #define STK_PROG_FUSE 0x62 // 'b' #define STK_PROG_LOCK 0x63 // 'c' #define STK_PROG_PAGE 0x64 // 'd' #define STK_PROG_FUSE_EXT 0x65 // 'e' #define STK_READ_FLASH 0x70 // 'p' #define STK_READ_DATA 0x71 // 'q' #define STK_READ_FUSE 0x72 // 'r' #define STK_READ_LOCK 0x73 // 's' #define STK_READ_PAGE 0x74 // 't' #define STK_READ_SIGN 0x75 // 'u' #define STK_READ_OSCCAL 0x76 // 'v' #define STK_READ_FUSE_EXT 0x77 // 'w' #define STK_READ_OSCCAL_EXT 0x78 // 'x'