Skip to content

Commit ad278dd

Browse files
committed
Adapt BL to UNO WiFi rev2 internal UART
1 parent f8657e6 commit ad278dd

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed

bootloaders/atmega4809_uart_bl.hex

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
:100000001124109948C080EC80932608A0912311F8
2-
:100010000A2E000CBB0BBC5F2CE530E00E945200A6
3-
:10002000DC01CB019E5FAF4FBF4F2AE0B595A7958E
4-
:10003000979587952A95D1F780932808909329085A
5-
:100040008091E20584608093E205449A669A6E9AF4
6-
:10005000E0E0F1E49DE923E030E48091240887FFAB
7-
:10006000FCCF80912008809322088193AF014F77C5
8-
:100070005527452B51F494BF209300108091021016
9-
:1000800080FDFCCF8DB183278DB9309731F7E0E843
10-
:10009000F0E0099507C082E080930110E0E8F0E00D
11-
:1000A0000995B1CF0E945900B7FF0895821B930BA9
12-
:1000B0000895A29FB001B39FC001A39F700D811D41
13-
:1000C0001124911DB29F700D811D1124911D089561
1+
:10000000112480911F138B3E09F059C08FEF80930C
2+
:100010001F1393E08DE984BF90930010809102102C
3+
:1000200081FDFCCF80EC80930608A09123110A2E5D
4+
:10003000000CBB0BBC5F2CE530E00E946600DC01CD
5+
:10004000CB019E5FAF4FBF4F2AE0B595A79597951F
6+
:1000500087952A95D1F78093080890930908809195
7+
:10006000E20581608093E205049A669A9DB180E47E
8+
:1000700089278DB9E0E0F1E49DE923E030E4809147
9+
:10008000040887FFFCCF80910008809302088193C9
10+
:10009000AF014F775527452B51F494BF20930010A3
11+
:1000A0008091021080FDFCCF8DB183278DB93097F0
12+
:1000B00031F791E088ED84BF9093410007C082E062
13+
:1000C00080930110E0E8F0E00995ACCF0E946D004C
14+
:1000D000B7FF0895821B930B0895A29FB001B39FB1
15+
:1000E000C001A39F700D811D1124911DB29F700D41
16+
:0800F000811D1124911D0895EA
1417
:02000004008278
1518
:00000001FF

bootloaders/boot.c

+25-18
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
* to disable standard startup files in Toolchain->AVR/GNU Linker->General.
3030
*
3131
* The example is written for ATtiny817 with the following pinout:
32-
* USART0 TxD PB2
33-
* USART0 RxD PB3
34-
* LED0 PB4
35-
* SW1 PC5 (external pull-up)
32+
* USART0 TxD PA4
33+
* USART0 RxD PA5
34+
* LED0 PD6
35+
* SW1 PC1 (external pull-up)
3636
*/
3737
#define F_CPU_RESET (16E6/6)
3838

@@ -100,6 +100,8 @@ __attribute__((naked)) __attribute__((section(".ctors"))) void boot(void)
100100
init_uart();
101101
init_status_led();
102102

103+
toggle_status_led();
104+
103105
/*
104106
* Start programming at start for application section
105107
* Subtract MAPPED_PROGMEM_START in condition to handle overflow on large flash sizes
@@ -131,11 +133,16 @@ __attribute__((naked)) __attribute__((section(".ctors"))) void boot(void)
131133
*/
132134
static bool is_bootloader_requested(void)
133135
{
134-
/* Check if SW1 (PA0) is low */
135-
if(VPORTA.IN & PIN0_bm) {
136-
return false;
136+
/* Check for boot request from firmware */
137+
if (USERROW.USERROW31 == 0xEB) {
138+
/* Clear boot request*/
139+
USERROW.USERROW31 = 0xff;
140+
_PROTECTED_WRITE_SPM(NVMCTRL.CTRLA, NVMCTRL_CMD_PAGEERASEWRITE_gc);
141+
while(NVMCTRL.STATUS & NVMCTRL_EEBUSY_bm);
142+
143+
return true;
137144
}
138-
return true;
145+
return false;
139146
}
140147

141148
/*
@@ -144,7 +151,7 @@ static bool is_bootloader_requested(void)
144151
static void init_uart(void)
145152
{
146153
/* Configure UART */
147-
USART1.CTRLB = USART_RXEN_bm | USART_TXEN_bm;
154+
USART0.CTRLB = USART_RXEN_bm | USART_TXEN_bm;
148155

149156
/* From datasheet:
150157
* Baud rate compensated with factory stored frequency error
@@ -157,35 +164,35 @@ static void init_uart(void)
157164
baud_reg_val *= (1024 + sigrow_val); // sum resolution + error
158165
baud_reg_val += 512; // compensate for rounding error
159166
baud_reg_val /= 1024; // divide by resolution
160-
USART1.BAUD = (int16_t) baud_reg_val; // set adjusted baud rate
167+
USART0.BAUD = (int16_t) baud_reg_val; // set adjusted baud rate
161168

162-
PORTMUX.USARTROUTEA |= PORTMUX_USART1_ALT1_gc;
169+
PORTMUX.USARTROUTEA |= PORTMUX_USART0_ALT1_gc;
163170

164-
/* Set TxD (PB2) as output */
165-
VPORTC.DIR |= PIN4_bm;
171+
/* Set TxD (PA4) as output */
172+
VPORTA.DIR |= PIN4_bm;
166173
}
167174

168175
static uint8_t uart_receive(void)
169176
{
170177
/* Poll for data received */
171-
while(!(USART1.STATUS & USART_RXCIF_bm));
172-
return USART1.RXDATAL;
178+
while(!(USART0.STATUS & USART_RXCIF_bm));
179+
return USART0.RXDATAL;
173180
}
174181

175182
static void uart_send(uint8_t byte)
176183
{
177184
/* Data will be sent when TXDATA is written */
178-
USART1.TXDATAL = byte;
185+
USART0.TXDATAL = byte;
179186
}
180187

181188
static void init_status_led(void)
182189
{
183-
/* Set LED0 (PB4) as output */
190+
/* Set LED0 (PD6) as output */
184191
VPORTD.DIR |= PIN6_bm;
185192
}
186193

187194
static void toggle_status_led(void)
188195
{
189-
/* Toggle LED0 (PB4) */
196+
/* Toggle LED0 (PD6) */
190197
VPORTD.OUT ^= PIN6_bm;
191198
}

0 commit comments

Comments
 (0)