Skip to content

Commit 3f32b5c

Browse files
committed
Added chip45boot2 code, docs, etc.
1 parent c230bbf commit 3f32b5c

File tree

378 files changed

+70706
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

378 files changed

+70706
-1
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 ER!K
3+
Copyright (c) 2023 Erik Lins
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# chip45boot2
22
Bootloader for Atmel AVR ATmega and Xmega micro controllers with Intel hex file support and automatic baudrate adjustment.
3+
4+
chip45boot2 was previously offered commercially by chip45.com and is now available as open-source under MIT License.
5+
6+
## Description
7+
8+
Flexible bootloader for AVR microcontrollers with auto-baud, hexfile support and extra functions. See [infosheet](docs/chip45boot2_infosheet.pdf) for details.
9+
10+
## Features
11+
chip45boot2 provides the following features:
12+
13+
- direct input of Intel Hex files
14+
- automatic baud rate adjustment
15+
- XON/XOFF protocol
16+
- Flash and EEPROM programming
17+
- byte-wise writing and reading of SRAM memory
18+
- byte-wise writing and reading of EEPROM memory
19+
- 2k bootblock size
20+
- graphical Windows user interface chip45boot2 GUI for programming from PC
21+
- The bootloader automatically adjusts at start to the hosts baudrate, so that it is not necessary to recompile the bootloader to a particular MCU clock.
22+
23+
## Further Information
24+
25+
- [chip45boot2 Infosheet](docs/chip45boot2_infosheet.pdf)
26+
- [Notes for using Atmel Studio](docs/chip45boot2_Studio6_notes.pdf)
27+
28+
## PC Software
29+
The chip45boot2 GUI is a PC/Windows application with a graphical user interface for the bootloader, which simplifies flash and eeprom programming over a COM port.
30+
31+
![chip45boot2 PC GUI](img/chip45boot2_GUI.png)
32+
33+
You can download Windows binaries under [releases](https://github.com/eriklins/chip45boot2/releases).
34+
35+
The PC software was programmed with LabWindows/CVI and hence requires an active license for that.
36+
37+
## Command Line Tool
38+
[c45b](https://github.com/bullestock/c45b) is a command line frontend for the bootloader.
39+
40+
## Pre-Compiled Hex Files
41+
Pre-built bootloader hexfiles for a bunch of AVR MCUs are included under [bootloader/build](bootloader/build).
42+
43+
## Contributing/Feedback
44+
Feedback / improvements / pull-requests / etc. are welcome.
45+
46+
However, I decided to open-source the bootloader due to lack of time/resources available for supporting the bootloader anymore, hence I cannot guarantee working on issues/pull-requests in the short-term.
47+
48+
## License
49+
Copyright (C) 2023 Erik Lins
50+
51+
This project is released under the MIT License.

bootloader/avr_compiler.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* This file has been prepared for Doxygen automatic documentation generation.*/
2+
/*! \file *********************************************************************
3+
*
4+
* \brief This file implements some macros that makes the IAR C-compiler and
5+
* avr-gcc work with the same code base for the AVR architecture.
6+
*
7+
* \par Documentation
8+
* For comprehensive code documentation, supported compilers, compiler
9+
* settings and supported devices see readme.html
10+
*
11+
* \author
12+
* Atmel Corporation: http://www.atmel.com \n
13+
* Support email: avr@atmel.com
14+
*
15+
* $Revision: 613 $
16+
* $Date: 2006-04-07 14:40:07 +0200 (fr, 07 apr 2006) $ \n
17+
*
18+
* Copyright (c) 2008, Atmel Corporation All rights reserved.
19+
*
20+
* Redistribution and use in source and binary forms, with or without
21+
* modification, are permitted provided that the following conditions are met:
22+
*
23+
* 1. Redistributions of source code must retain the above copyright notice,
24+
* this list of conditions and the following disclaimer.
25+
*
26+
* 2. Redistributions in binary form must reproduce the above copyright notice,
27+
* this list of conditions and the following disclaimer in the documentation
28+
* and/or other materials provided with the distribution.
29+
*
30+
* 3. The name of ATMEL may not be used to endorse or promote products derived
31+
* from this software without specific prior written permission.
32+
*
33+
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
34+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
36+
* SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
37+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43+
******************************************************************************/
44+
45+
#ifndef COMPILER_AVR_H
46+
#define COMPILER_AVR_H
47+
48+
#ifndef F_CPU
49+
/*! \brief Define default CPU frequency, if this is not already defined. */
50+
#define F_CPU 7372800UL
51+
#endif
52+
53+
#include <stdint.h>
54+
#include <stdbool.h>
55+
#include <stdlib.h>
56+
57+
/*! \brief This macro will protect the following code from interrupts. */
58+
#define AVR_ENTER_CRITICAL_REGION( ) uint8_t volatile saved_sreg = SREG; \
59+
cli();
60+
61+
/*! \brief This macro must always be used in conjunction with AVR_ENTER_CRITICAL_REGION
62+
* so the interrupts are enabled again.
63+
*/
64+
#define AVR_LEAVE_CRITICAL_REGION( ) SREG = saved_sreg;
65+
66+
#include <avr/io.h>
67+
#include <avr/interrupt.h>
68+
#include <avr/pgmspace.h>
69+
#include <util/delay.h>
70+
71+
/*! \brief Define the delay_us macro for GCC. */
72+
#define delay_us( us ) (_delay_us( us ))
73+
74+
#define INLINE static inline
75+
76+
/*! \brief Define the no operation macro. */
77+
#define nop() do { __asm__ __volatile__ ("nop"); } while (0)
78+
79+
#define MAIN_TASK_PROLOGUE int
80+
81+
82+
#define MAIN_TASK_EPILOGUE() return -1;
83+
84+
#define SHORTENUM __attribute__ ((packed))
85+
86+
#endif
87+

bootloader/boot.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// boot.c
2+
//
3+
// own boot.c functions for xmega
4+
// these functions are implemented as wrapper functions
5+
6+
#include <avr/interrupt.h>
7+
8+
#include "sp_driver.h"
9+
#include "mcudefs.h"
10+
11+
// on A3 devices with die revision B a workaround is required
12+
#ifdef WORKAROUND
13+
14+
//Temporary storage used for NVM-workaround
15+
uint8_t sleepCtr;
16+
uint8_t statusStore;
17+
uint8_t pmicStore;
18+
uint8_t globalInt;
19+
uint8_t spmintStore;
20+
21+
// SPM wakeup interrupt
22+
ISR(NVM_SPM_vect) {
23+
NVM.INTCTRL = (NVM.INTCTRL & ~NVM_SPMLVL_gm); // Disable the SPM interrupt
24+
SLEEP.CTRL = sleepCtr; // Restore sleep settings
25+
// Restore PMIC status and control registers
26+
PMIC.STATUS = statusStore;
27+
PMIC.CTRL = pmicStore;
28+
NVM.INTCTRL = spmintStore; // Restore SPM interruptsettings
29+
SREG = globalInt; // Restore global interrupt settings
30+
}
31+
32+
// Set interrupt vector location to boot section of flash
33+
void PMIC_SetVectorLocationToBoot( void ) {
34+
uint8_t temp = PMIC.CTRL | PMIC_IVSEL_bm;
35+
CCP = CCP_IOREG_gc;
36+
PMIC.CTRL = temp;
37+
}
38+
39+
// Set interrupt vector location to application section of flash
40+
void PMIC_SetVectorLocationToApplication( void ) {
41+
uint8_t temp = PMIC.CTRL & ~PMIC_IVSEL_bm;
42+
CCP = CCP_IOREG_gc;
43+
PMIC.CTRL = temp;
44+
}
45+
46+
// Save register settings before entering sleep mode
47+
void Prepare_to_Sleep( void ) {
48+
sleepCtr = SLEEP.CTRL;
49+
SLEEP.CTRL = 0x00; // Set sleep mode to IDLE
50+
// Save the PMIC Status and control registers
51+
statusStore = PMIC.STATUS;
52+
pmicStore = PMIC.CTRL;
53+
PMIC.CTRL = (PMIC.CTRL & ~(PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm)) | PMIC_HILVLEN_bm; // Enable only the highest level of interrupts
54+
globalInt = SREG; // Save SREG for later use
55+
sei(); // Enable global interrupts
56+
spmintStore = NVM.INTCTRL; // Save SPM interrupt settings for later
57+
}
58+
#endif // WORKAROUND
59+
60+
61+
void boot_page_fill(uint32_t ulAddress, uint16_t usData) {
62+
63+
#ifdef WORKAROUND
64+
Prepare_to_Sleep();
65+
#endif
66+
SP_LoadFlashWord(ulAddress, usData);
67+
}
68+
69+
70+
void boot_page_erase(uint32_t ulAddress) { // do a page erase
71+
72+
#ifdef WORKAROUND
73+
Prepare_to_Sleep();
74+
#endif
75+
SP_EraseApplicationPage(ulAddress);
76+
}
77+
78+
79+
void boot_spm_busy_wait() { // wait for page erase done
80+
81+
#ifdef WORKAROUND
82+
Prepare_to_Sleep();
83+
#endif
84+
SP_WaitForSPM();
85+
}
86+
87+
88+
void boot_page_write(uint32_t ulAddress) { // do a page write
89+
90+
#ifdef WORKAROUND
91+
Prepare_to_Sleep();
92+
#endif
93+
SP_WriteApplicationPage(ulAddress);
94+
}
95+
96+
97+
void boot_rww_enable() { // reenable rww section again
98+
}
99+
100+
101+
// end of file: boot.c

bootloader/boot.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// usart.h
2+
//
3+
// own boot.c functions for xmega
4+
5+
// make sure to include just once!
6+
#ifndef _BOOT_H_
7+
#define _BOOT_H_
8+
9+
// include the spm function of AVR1605 application note
10+
#include "sp_driver.h"
11+
#include "mcudefs.h"
12+
13+
14+
// prototypes
15+
16+
#ifdef WORKAROUND // on A3 devices with die revision B a workaround is required
17+
void PMIC_SetVectorLocationToBoot( void );
18+
void PMIC_SetVectorLocationToApplication( void );
19+
#endif
20+
void boot_page_fill(uint32_t ulAddress, uint16_t usData);
21+
void boot_page_erase(uint32_t ulAddress); // do a page erase
22+
void boot_spm_busy_wait(); // wait for page erase done
23+
void boot_page_write(uint32_t ulAddress); // do a page write
24+
void boot_rww_enable(); // reenable rww section again
25+
#endif
26+
27+
28+
// end of file: boot.h

0 commit comments

Comments
 (0)