Skip to content

Commit 35b016a

Browse files
authored
v1.32.43 Bug fixes (#5)
* v1.32.43: Disabling actions that are rarely performed * v1.32.43: Added annotations. * v1.32.43: SW0 interrupt division and LOCK device related
1 parent 24a36aa commit 35b016a

File tree

12 files changed

+14912
-14639
lines changed

12 files changed

+14912
-14639
lines changed

hex/updi4avr-usb/AVR64DU32_CNANO.hex

Lines changed: 666 additions & 664 deletions
Large diffs are not rendered by default.

hex/updi4avr-usb/AVR64DU32_CNANO.lst

Lines changed: 5620 additions & 5601 deletions
Large diffs are not rendered by default.

hex/updi4avr-usb/AVR64DU32_CNANO_DEBUG1.hex

Lines changed: 988 additions & 980 deletions
Large diffs are not rendered by default.

hex/updi4avr-usb/AVR64DU32_CNANO_DEBUG1.lst

Lines changed: 7414 additions & 7322 deletions
Large diffs are not rendered by default.

src/configuration.h

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@
5252
* | VUSB - |6 9| - PC3 - LED0
5353
* for Application USB | DM - |7 8| - DP - for Application USB
5454
* +------+
55+
*
56+
* - If CONFIG_SYS_SW0_ALT_14P is enabled, the pin definitions go to:
57+
*
58+
* PF6 - nRST
59+
* PD7 - VBD
60+
* PD6 - SW0
61+
* (DEBUG is Disable)
5562
*/
5663

5764
/*
5865
* HAL_BAREMETAL_20P: The AVR32-16DU20 has the following limitations:
5966
*
60-
* - The following I/O signal cannot be used: DSR, CTS, RI, DCD, nRST.
61-
* - When using DEBUG-COM port, the following control signals are not available: DTR, VBD.
67+
* - The following I/O signal cannot be used: DSR, RI, DCD.
68+
* - When using DEBUG-COM port, the following control signals are not available: RTS, VBD.
6269
*
6370
* AVR32-16DU20
6471
* +------+
@@ -73,6 +80,14 @@
7380
* HVSL - PA5 - |9 12| - VUSB |
7481
* LED0 - PA6 - |10 11| - PA7 - HVSW
7582
* +------+
83+
*
84+
* - If CONFIG_VCP_RS232C_ENABLE is disabled, the pin definitions go to:
85+
*
86+
* PF6 - nRST
87+
* PD7 - DBG-RxD or N.C.
88+
* PD6 - DBG-TxD or N.C.
89+
* PD5 - SW0
90+
* PD4 - VBD
7691
*/
7792

7893
/*
@@ -212,7 +227,7 @@
212227
* Columns: HW_VER, FW_MAJOR, FW_MINOR, FW_RELL, FW_RELH (all 1-byte decimal)
213228
*/
214229

215-
#define CONFIG_SYS_FWVER { 0, 1, 32, 42, 0 }
230+
#define CONFIG_SYS_FWVER { 0, 1, 32, 43, 0 }
216231

217232
/*
218233
* For CNANO, you can change the detection of SW0 to PIN_PF5.
@@ -225,6 +240,14 @@
225240

226241
// #define CONFIG_SYS_SW0_ALT_CNANO
227242

243+
/*
244+
* For HAL_BAREMETAL_14P you can change SW0 to PD6.
245+
*
246+
* This will disable DEBUG and replace PF6 with nRST.
247+
*/
248+
249+
// #define CONFIG_SYS_SW0_ALT_14P
250+
228251
/*** CONFIG_USB ***/
229252

230253
/*
@@ -411,6 +434,42 @@
411434
#endif
412435
#endif
413436

437+
/*** To override the default value at the CLI level: ***/
438+
439+
#ifdef CONFIG_USB_VDETECT_DISABLE
440+
#undef CONFIG_USB_VDETECT
441+
#endif
442+
#ifdef CONFIG_VCP_DTR_RESET_DISABLE
443+
#undef CONFIG_VCP_DTR_RESET
444+
#endif
445+
#ifdef CONFIG_VCP_RS232C_DISABLE
446+
#undef CONFIG_VCP_RS232C_ENABLE
447+
#endif
448+
#ifdef CONFIG_VCP_CTS_DISABLE
449+
#undef CONFIG_VCP_CTS_ENABLE
450+
#endif
451+
#ifdef CONFIG_VCP_INTERRUPT_SUPPRT_DISABLE
452+
#undef CONFIG_VCP_INTERRUPT_SUPPRT
453+
#endif
454+
#ifdef CONFIG_VCP_TXD_ODM_DISABLE
455+
#undef CONFIG_VCP_TXD_ODM
456+
#endif
457+
#ifdef CONFIG_VCP_9BIT_SUPPORT_DISABLE
458+
#undef CONFIG_VCP_9BIT_SUPPORT
459+
#endif
460+
#ifdef CONFIG_HVCTRL_ENABLE_DISABLE
461+
#undef CONFIG_HVCTRL_ENABLE
462+
#endif
463+
#ifdef CONFIG_HVCTRL_POWER_DISABLE
464+
#undef CONFIG_HVCTRL_POWER_ENABLE
465+
#endif
466+
#ifdef CONFIG_PGM_TPI_DISABLE
467+
#undef CONFIG_PGM_TPI_ENABLE
468+
#endif
469+
#ifdef CONFIG_PGM_PDI_DISABLE
470+
#undef CONFIG_PGM_PDI_ENABLE
471+
#endif
472+
414473
/*** Note: The pin numbers of VCP-DCD,DSR,RI are fixed as PIN_PD0,1,3. ***/
415474

416475
#if (CONFIG_HAL_TYPE == HAL_BAREMETAL_14P)
@@ -422,14 +481,20 @@
422481
#define PIN_PG_TDAT PIN_USART0_TXD_ALT3
423482
#define PIN_PG_TRST PIN_USART0_RXD_ALT3
424483
#define PIN_SYS_LED PIN_PC3 /* PIN_LUT1_OUT */
425-
#define PIN_SYS_SW0 PIN_PF6
426484
#undef CONFIG_VCP_CTS_ENABLE
427485
#undef CONFIG_PGM_TPI_ENABLE
428486
#undef CONFIG_HVCTRL_ENABLE
429487
#undef CONFIG_HVCTRL_POWER_ENABLE
430-
#if !defined(DEBUG)
488+
#ifdef CONFIG_SYS_SW0_ALT_14P
489+
#undef DEBUG
431490
#define PIN_USB_VDETECT PIN_PD7
432-
#define PIN_VCP_DTR PIN_PD6
491+
#define PIN_SYS_SW0 PIN_PD6
492+
#else
493+
#define PIN_SYS_SW0 PIN_PF6
494+
#if !defined(DEBUG)
495+
#define PIN_USB_VDETECT PIN_PD7
496+
#define PIN_VCP_DTR PIN_PD6
497+
#endif
433498
#endif
434499
#else
435500
#define PORTMUX_USART_VCP (PORTMUX_USART0_ALT2_gc | PORTMUX_USART1_ALT2_gc)
@@ -444,13 +509,18 @@
444509
#define PIN_HV_SELECT PIN_PA5
445510
#define PIN_HV_CHGPUMP PIN_PA4 /* PIN_TCA0_WO4 */
446511
#if (CONFIG_HAL_TYPE == HAL_BAREMETAL_20P)
447-
#define PIN_SYS_SW0 PIN_PF6
448-
#if !defined(DEBUG)
449-
#define PIN_USB_VDETECT PIN_PD7
450-
#define PIN_VCP_RTS PIN_PD6
512+
#ifdef CONFIG_VCP_RS232C_ENABLE
513+
#if !defined(DEBUG)
514+
#define PIN_USB_VDETECT PIN_PD7
515+
#define PIN_VCP_RTS PIN_PD6
516+
#endif
517+
#define PIN_SYS_SW0 PIN_PF6
518+
#define PIN_VCP_DTR PIN_PD5
519+
#define PIN_VCP_CTS PIN_PD4
520+
#else
521+
#define PIN_SYS_SW0 PIN_PD5
522+
#define PIN_USB_VDETECT PIN_PD4
451523
#endif
452-
#define PIN_VCP_DTR PIN_PD5
453-
#define PIN_VCP_CTS PIN_PD4
454524
#define PIN_HV_FEEDBACK PIN_PC3 /* PIN_AC0_AINP4 */
455525
#define PIN_SYS_LED0 PIN_PA6 /* PIN_LUT0_OUT_ALT1 */
456526
#elif (CONFIG_HAL_TYPE == HAL_BAREMETAL_28P)
@@ -477,7 +547,7 @@
477547
#define PIN_HV_FEEDBACK PIN_PC3 /* PIN_AC0_AINP4 */
478548
#define PIN_SYS_LED0 PIN_PA6 /* PIN_LUT0_OUT_ALT1 */
479549
#else /* CNANO */
480-
#if defined(CONFIG_SYS_SW0_ALT_CNANO)
550+
#ifdef CONFIG_SYS_SW0_ALT_CNANO
481551
#define PIN_SYS_SW0 PIN_PF5
482552
#else
483553
#define PIN_SYS_SW0 PIN_PF6

src/jtag.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,13 @@ namespace JTAG {
186186
}
187187
else if (_section == 1) { /* SET_GET_CTXT_PHYSICAL */
188188
if (_index == 0 || _index == 0x20) { /* PARM3_VTARGET */
189+
/* Called with `-xvtarget` HAS_VTARG_READ */
189190
_vtarget = SYS::get_vdd();
190191
D1PRINTF(" VTARGET=%d\r\n", _vtarget);
191192
packet.in.wValue = _vtarget;
192193
}
193194
else { /* PARM3_ANALOG_XXXX */
195+
/* Called with PowerDebugger HAS_VTARG_ADJ */
194196
D1PRINTF(" PHYSICAL=%02X:%02X\r\n", _index, _length);
195197
memcpy_P(&packet.in.data[0], &jtag_physical[_index & 7], _length);
196198
}
@@ -229,7 +231,7 @@ namespace JTAG {
229231
D1PRINTF(" AVR_SET_PARAM=%02X:%02X:%02X:%02X\r\n", _section, _index, _length, _data);
230232
if (_section == 0) { /* SET_GET_CTXT_CONFIG */
231233
if (_index == 0x10) { /* EDBG_CONTROL_TARGET_POWER */
232-
/* Called with `-xvtarget_switch=0,1` */
234+
/* Called with `-xvtarget_switch=0,1` HAS_VTARG_SWITCH */
233235
D1PRINTF(" TARGET_POWER=%02X\r\n", _data);
234236
_jtag_vpow = _data; /* 0,1 */
235237
#if defined(PIN_HV_POWER)
@@ -246,6 +248,7 @@ namespace JTAG {
246248
D1PRINTF(" AVR_GET_PARAM=%02X:%02X:%02X\r\n", _section, _index, _length);
247249
if (_section == 0) { /* SET_GET_CTXT_CONFIG */
248250
if (_index == 0x10) { /* EDBG_CONTROL_TARGET_POWER */
251+
/* Called with `-xvtarget_switch` HAS_VTARG_SWITCH */
249252
D1PRINTF(" TARGET_POWER=%02X\r\n", _jtag_vpow);
250253
packet.in.data[0] = _jtag_vpow;
251254
}
@@ -314,6 +317,8 @@ namespace JTAG {
314317
D2PRINTF(" lockbits_base=%04X\r\n", Device_Descriptor.UPDI.lockbits_base);
315318
D2PRINTF(" address_mode=%02X\r\n", Device_Descriptor.UPDI.address_mode);
316319
D2PRINTF(" hvupdi_variant=%02X\r\n", Device_Descriptor.UPDI.hvupdi_variant);
320+
/* Even with all this, the BOOTROW information is still undefined! */
321+
/* Re-analysis of newer ICE FW is needed! */
317322
}
318323
/* STUB: And other descriptors. */
319324
#elif defined(DEBUG)
@@ -325,11 +330,12 @@ namespace JTAG {
325330
}
326331
else if (_section == 3) { /* SET_GET_CTXT_OPTIONS */
327332
if (_index == 6) { /* PARM3_OPT_12V_UPDI_ENABLE */
328-
/* Called with `-xhvupdi` */
333+
/* Called with `-xhvupdi` hvupdi_support */
329334
D1PRINTF(" HVCTRLEN=%02X\r\n", _data);
330335
_jtag_hvctrl = _data; /* 1:ENABLE */
331336
}
332337
else if (_index == 7) { /* PARM3_OPT_CHIP_ERASE_TO_ENTER */
338+
/* This is a stub that shows no signs of being used. */
333339
/* force unlock chip-erase */
334340
/* This might be called having no `-e` or `-D`, but having `-F`. */
335341
D1PRINTF(" UNLOCKEN=%02X\r\n", _data);
@@ -348,10 +354,12 @@ namespace JTAG {
348354
}
349355
else if (_section == 1) { /* SET_GET_CTXT_PHYSICAL */
350356
if (_index == 0) { /* PARM3_CONNECTION */
357+
/* This is a stub that is called but not used. */
351358
D1PRINTF(" CONNECTION=%02X\r\n", _jtag_conn);
352359
packet.in.data[0] = _jtag_conn;
353360
}
354361
else if (_index == 0x31) { /* PARM3_CLK_XMEGA_PDI */
362+
/* `-B <num>khz` : "khz" units are required. */
355363
D1PRINTF(" XCLK=%d\r\n", _xclk);
356364
packet.in.wValue = _xclk;
357365
}
@@ -360,7 +368,7 @@ namespace JTAG {
360368
_rspsize = _length + 1;
361369
}
362370
#ifdef _Not_yet_implemented_stub_
363-
else if (_jtag_arch == 0x01) _rspsize = DWIRE:jtag_scope_tiny(); /* dWire? */
371+
else if (_jtag_arch == 0x01) _rspsize = DWIRE::jtag_scope_tiny(); /* dWire? */
364372
else if (_jtag_arch == 0x02) _rspsize = MEGA::jtag_scope_mega(); /* MEGA */
365373
else if (_jtag_arch == 0x03) _rspsize = XMEGA::jtag_scope_xmega(); /* XMEGA */
366374
#endif
@@ -381,7 +389,7 @@ namespace JTAG {
381389
packet.out.index);
382390
if (_scope == 0x01) _rspsize = jtag_scope_general(); /* SCOPE_GENERAL */
383391
#ifdef _Not_yet_implemented_stub_
384-
else if (_scope == 0x00) _rspsize = jtag_scope_info(); /* SCOPE_INFO */ /* Not used with HID */
392+
else if (_scope == 0x00) _rspsize = jtag_scope_info(); /* SCOPE_INFO */ /* Not used with EDBG/CMSIS-DAP type */
385393
else if (_scope == 0x11) _rspsize = ISP::jtag_scope_isp(); /* SCOPE_AVR_ISP */
386394
else if (_scope == 0x13) _rspsize = AVR32::jtag_scope_avr32(); /* SCOPE_AVR32 */
387395
#endif

src/main.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ int main (void) {
9696
loop_until_bit_is_clear(WDT_STATUS, WDT_SYNCBUSY_bp);
9797
_PROTECTED_WRITE(WDT_CTRLA, WDT_PERIOD_1KCLK_gc);
9898

99-
VPORTA_INTFLAGS = ~0;
100-
VPORTC_INTFLAGS = ~0;
101-
VPORTD_INTFLAGS = ~0;
102-
VPORTF_INTFLAGS = ~0;
99+
#if defined(PIN_SYS_SW0)
100+
/* Clear the dirty flag before enabling interrupts. */
101+
vportRegister(PIN_SYS_SW0).INTFLAGS = ~0;
102+
CCL_INTFLAGS = ~0;
103+
#endif
103104
interrupts();
104105

105106
#if !defined(PIN_USB_VDETECT)
107+
/* If you do not use VBD, insert the shortest possible delay instead. */
106108
delay_millis(250);
107109
USB::setup_device(true);
108110
#else
@@ -118,12 +120,20 @@ int main (void) {
118120
USB::handling_bus_events();
119121
if (USB::is_ep_setup()) USB::handling_control_transactions();
120122

121-
if (bit_is_set(GPCONF, GPCONF_FAL_bp)) SYS::reset_enter();
122-
else if (bit_is_set(GPCONF, GPCONF_RIS_bp)) SYS::reset_leave();
123+
/* If SW0 was used, work here. */
124+
if (bit_is_clear(PGCONF, PGCONF_UPDI_bp)) {
125+
if (bit_is_set(GPCONF, GPCONF_FAL_bp)) SYS::reset_enter();
126+
else if (bit_is_set(GPCONF, GPCONF_RIS_bp)) SYS::reset_leave();
127+
}
123128

129+
/* If the USB port is not open, go back to the loop beginning. */
124130
if (bit_is_clear(GPCONF, GPCONF_USB_bp)) continue;
125131

126132
/*** CMSIS-DAP VCP transceiver ***/
133+
/* The AVR series requires at least 100 clocks to service */
134+
/* an interrupt. At the maximum speed of the VCP-RxD, one */
135+
/* character arrives every 400 clocks on a 20MHz reference. */
136+
/* So we avoid using interrupts here and use polling to gain speed. */
127137
#if defined(CONFIG_VCP_9BIT_SUPPORT)
128138
if (bit_is_set(GPCONF, GPCONF_VCP_bp)) usart_transmitter();
129139
#else

src/sys.cpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,23 @@ namespace SYS {
105105

106106
#if defined(PIN_SYS_SW0)
107107
/* SW0 detection: Input negative logic. */
108-
pinControlRegister(PIN_SYS_SW0) = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc;
108+
/* Use CCL in conjunction to separate the falling edge and rising edge interrupts. */
109+
/* For the falling edge, use the CCL filter function to remove chattering noise. */
110+
pinControlRegister(PIN_SYS_SW0) = PORT_PULLUPEN_bm | PORT_ISC_RISING_gc;
111+
portRegister(PIN_SYS_SW0).EVGENCTRLA = pinPosition(PIN_SYS_SW0);
112+
#if (PIN_SYS_SW0 & 0xF0) == 176
113+
EVSYS_CHANNEL3 = EVSYS_CHANNEL_PORTF_EVGEN0_gc;
114+
#elif (PIN_SYS_SW0 & 0xF0) == 112
115+
EVSYS_CHANNEL3 = EVSYS_CHANNEL_PORTD_EVGEN0_gc;
116+
#elif (PIN_SYS_SW0 & 0xF0) == 16
117+
EVSYS_CHANNEL3 = EVSYS_CHANNEL_PORTA_EVGEN0_gc;
118+
#endif
109119
#endif
110120

111121
/*
112122
* GPIO - LED
113123
*/
114124

115-
#undef LED_CCL
116125
#if (CONFIG_HAL_TYPE == HAL_BAREMETAL_14P)
117126
/* PORTMUX LUT0OUT -> PIN_PC3 */
118127
/* TRUTH0: 001 010 is ON */
@@ -137,6 +146,15 @@ namespace SYS {
137146
CCL_LUT1CTRLA = CCL_ENABLE_bm | CCL_OUTEN_bm; /* PIN_PA6 */
138147
#endif
139148

149+
#if defined(PIN_SYS_SW0)
150+
/* SW0 -> CH3 -> LUT3OUT -> INTFLAGS:INT3 */
151+
EVSYS_USERCCLLUT3A = EVSYS_USER_CHANNEL3_gc;
152+
CCL_TRUTH3 = CCL_TRUTH_1_bm;
153+
CCL_LUT3CTRLB = CCL_INSEL0_EVENTA_gc;
154+
CCL_LUT3CTRLA = CCL_ENABLE_bm | CCL_FILTSEL_FILTER_gc;
155+
CCL_INTCTRL0 = CCL_INTMODE3_FALLING_gc;
156+
#endif
157+
140158
/*** CCL enable ***/
141159
/* One of the CCL's is the LED output control. */
142160
CCL_CTRLA = CCL_RUNSTDBY_bm | CCL_ENABLE_bm;
@@ -234,7 +252,6 @@ namespace SYS {
234252
* May be called multiple times due to chattering.
235253
*/
236254
void reset_enter (void) {
237-
if (bit_is_set(PGCONF, PGCONF_UPDI_bp)) return;
238255
LED_Blink();
239256
if (_jtag_arch == 5) {
240257
/*
@@ -256,7 +273,6 @@ namespace SYS {
256273
* but if the USB is stopped, it will reboot at the end.
257274
*/
258275
void reset_leave (void) {
259-
if (bit_is_set(PGCONF, PGCONF_UPDI_bp)) return;
260276
if (_jtag_arch == 5) {
261277
_updi_bitmap[10] = 0x00; /* SYSRUN */
262278
send_bitmap(_updi_bitmap, sizeof(_updi_bitmap) * 8);
@@ -268,11 +284,11 @@ namespace SYS {
268284
#endif
269285
D1PRINTF("<RST:OUT>\r\n");
270286
if (bit_is_set(GPCONF, GPCONF_USB_bp))
271-
LED_HeartBeat();
287+
LED_HeartBeat(); /* The USB is ready. */
272288
else if (!USB0_ADDR)
273-
reboot();
289+
reboot(); /* USB disconnected, System reboot. */
274290
else
275-
LED_Flash();
291+
LED_Flash(); /* USB is not yet enabled. */
276292
bit_clear(GPCONF, GPCONF_FAL_bp);
277293
bit_clear(GPCONF, GPCONF_RIS_bp);
278294
}
@@ -332,15 +348,17 @@ namespace SYS {
332348
};
333349

334350
#if defined(PIN_SYS_SW0)
351+
/* If the level is not maintained for a sufficient period of time it will not function properly. */
335352
ISR(portIntrruptVector(PIN_SYS_SW0)) {
353+
/* SW0 Raising Interrupt */
336354
vportRegister(PIN_SYS_SW0).INTFLAGS = ~0;
337-
/* If the level is not maintained for a sufficient period of time it will not function properly. */
338-
if (bit_is_clear(PGCONF, PGCONF_UPDI_bp)) {
339-
if (digitalReadMacro(PIN_SYS_SW0))
340-
bit_set(GPCONF, GPCONF_RIS_bp);
341-
else
342-
bit_set(GPCONF, GPCONF_FAL_bp);
343-
}
355+
bit_set(GPCONF, GPCONF_RIS_bp);
356+
}
357+
358+
ISR(CCL_CCL_vect) {
359+
/* SW0 Falling Intrrupt */
360+
CCL_INTFLAGS = ~0;
361+
bit_set(GPCONF, GPCONF_FAL_bp);
344362
}
345363
#endif
346364

0 commit comments

Comments
 (0)