12

I have designed a PCB for a client recently, everything is fine with the hardware and software (application is working as it is supposed to). Now we are facing the need to update the program inside the microcontroller, but since these PCBs are installed at different places over the world, it would be perfect to install a bootloader and use the same UART as used by the application.

Board description

  • AT32UC3L032
  • One UART already used to communicate between board and PC
  • Couple of I/Os for the application
  • Couple of state LEDs

Relevant PINS and config

PA01 # Used for entering ISP with high level

PA20 # Used for application and ISP UART
PA21 # Used for application and ISP UART

#define COM_USART               (&AVR32_USART2)
#define COM_USART_RX_PIN        AVR32_USART2_RXD_0_0_PIN
#define COM_USART_RX_FUNCTION   AVR32_USART2_RXD_0_0_FUNCTION
#define COM_USART_TX_PIN        AVR32_USART2_TXD_0_0_PIN
#define COM_USART_TX_FUNCTION   AVR32_USART2_TXD_0_0_FUNCTION
#define COM_USART_IRQ           AVR32_USART2_IRQ
#define COM_USART_BAUDRATE      115200

Tools used

  • Windows XP
  • Atmel Studio 6.1
  • AVRONE programmer

After many hours searching, I've found the Atmel Software Framework DFU, provided in ASF 3.14.0.834. That was looking promising, I was able to install it on my board using provided tools :

  • AVR32Studio 2.6.0
  • program_at32uc3l-uart-isp-1.0.1.cmd (provided script with ASF)
  • Flip 3.4.7 (batchisp)

At first, I used .bin and .dat provided with ASF, installed using the script. Now trying to upload application using batchisp command :

batchisp.exe -device at32uc3l032 -hardware RS232 -port COM1 -baudrate 115200 -operation erase f memory flash blankcheck loadbuffer myapp.hex program verify

But always getting :

Device selection.................... PASS
Hardware selection.................. PASS
Opening port........................ PASS
Synchronzing target................. FAIL    Timeout error.

I've tested with oscilloscope RX and TX from UART, data is going to board but PC is receiving a 27kHz square wave (can't be data from UART since there is no stop bit or anything, also frequency is probably not the same for 115200bps).

After more research, I've configured Word1 and Word2 in file at32uc3l-uart-isp_cfg-1.0.1.dat to get these values :

  • Word1 : 0xE11E0024
  • Word2 : 0x494F81AA

To use pin PA01 as option to enter in the ISP.

Also, loaded the source of the DFU in Atmel Studio 6.1 and noticed they were not using same serial port configuration, so changed for the same as my application. Also added some LEDs toggle inside the main of the DFU.

After updating the bootloader in the board, no LEDs changes, same timeout, same square wave.

Am I missing something?


Alexandre Lavoie
  • 243
  • 1
  • 11
  • 1
    Posted as a ticket to Atmel, will see who can really help me :D – Alexandre Lavoie Mar 20 '14 at 18:55
  • Which pins are you using (PAxx/PBxx). I don't remember exactly, but to enter the bootloader you are supposed to pull a pin high or low (depending on the two configurations words). Can you confirm you are pushing a button or similar? – Tom L. Mar 20 '14 at 19:11
  • @TomL., using PA01 (added in question). Tried with both high / low... same result. Even if this pin is used with JTAG, should not cause problem. – Alexandre Lavoie Mar 20 '14 at 19:15
  • And which pins are you using for the UART? – Tom L. Mar 20 '14 at 19:15
  • @TomL. PA20 & PA21 for UART (AVR32_USART2) which is working in normal application (without bootloader). – Alexandre Lavoie Mar 20 '14 at 19:20
  • 1
    Hm ok, so nothing unusual here. Can you check the trampoline code and if the application is correctly linked to the flash start address (you should see this in the linker .map file). Can you post your linker arguments? – Tom L. Mar 20 '14 at 19:26
  • @TomL. Added two files at the end, probably the map will not be relevant since in the batch script the bootloader is placed at specific address. I am converting ELF to BIN before that. – Alexandre Lavoie Mar 20 '14 at 19:34
  • The manual states: "Connections If the JTAG is enabled, the JTAG will take control over a number of pins, irrespectively of the I/O Controller configuration." Care to try with a different pin? – Tom L. Mar 20 '14 at 19:37
  • Give me about 5-10 minutes, I'll get a try... – Alexandre Lavoie Mar 20 '14 at 19:38
  • (Just a wild guess) :-( – Tom L. Mar 20 '14 at 19:39
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/13743/discussion-between-alexandre-lavoie-and-tom-l) – Alexandre Lavoie Mar 20 '14 at 19:49
  • Well same result, also noticed that 0x494F81AA was wrong, should be 0x494F0123 for PA01. Tested PA01 and PB00 without success. – Alexandre Lavoie Mar 20 '14 at 19:50
  • ... wouldn't you have to have implemented support for firmware updates *before* shipping the board? – SamB Nov 11 '14 at 22:21
  • Dumb question but, do you have the reset pin connected to the programmer? Assuming it is needed... –  Nov 26 '14 at 00:38
  • @tim, sur it is connected, I am able to load my own program without any issue (by using the programmer). – Alexandre Lavoie Dec 10 '14 at 14:39
  • @AlexandreLavoie I added some new info at the end of mine answer. – Spektre Jun 19 '19 at 11:19

2 Answers2

1

Maybe try using a AVR programmer and the Arduino IDE if that is possible. I know it works well with the AT series microcontrollers.

electricviolin
  • 539
  • 2
  • 10
  • 17
0

Using JTAG without proper trampoline code will overwrite the BOOTLOADER shipped by the ATMEL. So after first programming with JTAG you most likely erased the BOOTLOADER for good.

Also the fuses must be set to allow bootloader to work which default settings of JTAG programmer usually screw up.

In order to repair this you need to program the BOOTLOADER back (taken from unprogrammed yet chip) into chip by JTAG and set the fuses correctly.

I stopped using JTAG long ago as BOOTLOADER+FLIP is much more comfortable and faster. Make sure you are using hex instead of bin/elf and BOOTLOADER condition is still true after reset condition ends.

This is how I use FLIP on RS232:

avr32-objcopy -O ihex AT32UC3L064.elf AT32UC3L064.hex
Batchisp -device AT32UC3L064 -hardware RS232 -port COM1 -baudrate 115200 -operation onfail abort memory flash erase f blankcheck loadbuffer AT32UC3L064.hex program start reset 0

Where avr32-objcopy is from AVRStudio bin folder and Batchisp is from FLIP. You just need to change the filenames and AVR chip ID and COM to match your project.

In case you need it you can also use USB:

avr32-objcopy -O ihex cpp_trampoline.elf AT32UC3A3256.hex
Batchisp -device AT32UC3A3256 -hardware USB -operation onfail abort memory flash erase f blankcheck loadbuffer AT32UC3A3256.hex program start reset 0

The trampoline must be enabled in linker (project properties) this is how mine config looks like:

linker: -nostartfiles -Wl,--gc-sections -Wl,-e,_trampoline -mpart=uc3l032 -Wl,--gc-sections --direct-data --rodata-writable

I am still using AVR32 Studio 2.7.0 as the newer versions are horse shit so in them the config might be different.

[Edit1] additional info

for UC3L0the AVR32_PIN_PA20 is some RC generic clock (should be 32KHz but it varies from chip to chip quite a lot without calibration with prescalers) from the chip until its purpose is changed to GPIO or anything else so the ~27KHz clock has nothing to do with USART. Btw that clock is powered by 3.3V and generates even if the chip 1.98V core is fried for good....

The Bootloader condition is having AVR32_PIN_PA11 set to zero prior to Reset release (unless you implement your own DFU conditions/commands into your firmware) So one possibility is making an RC that you dissipate to LOW state , and reset before it charge up back ... or use some FLIP/FLOP gate or jumper ...

Spektre
  • 126
  • 5