Month: November 2023

Using the dfu-programmer with MCUZone UC3B-CPU board

Finally I got dfu-programmer working:

$ sudo dfu-programmer at32uc3b0256 get
Bootloader Version: 0x02 (2)

$ sudo dfu-programmer at32uc3b0256 erase

$ sudo dfu-programmer at32uc3b0256 getfuse
Locked regions: 0xffff (65535)

I flashed my nuttx.hex this way:

sudo dfu-programmer at32uc3b0256 flash nuttx.hex

I can start the program running dfu-programmer start:

$ sudo dfu-programmer at32uc3b0256 start

Thanks Raman Gopalan for help!
Also this post helped me a lot: https://hofmeyr.de/avr32%20hello%20world/

Key words: atmel avr32 DFU

How to format SDCard on NuttX terminal

Today during my weekly NuttX Channel Live about porting NuttX to STM32F401RC-RS485 board we explained how to add support to SDCard and I commented that we could use the mkfatfs command to format the SDCard. However during our tests it failed:

nsh> mkfatfs /dev/mmcsd0
nsh: mkfatfs: mkfatfs failed: 23
nsh>

Looking the file nuttx/include/errno.h I saw that error -23 means ENFILE (“File table overflow”).

Then we look at mkfatfs help:

nsh> help mkfatfs
mkfatfs usage:  mkfatfs [-F <fatsize>] [-r <rootdirentries>] <block-driver>

Initially I thought that fatsize was the size of FAT sector (i.e. 512 byter per sector) and my colleague Rodrigo thought it was the size of SDCard itself. So we tried 512 and bigger values, but it didn’t work.

Then Rodrigo looked at NuttX documentation and found the answer: it was the type of FAT: FAT16, FAT32, etc.

So we tried using “-F 32” and it worked:

nsh> mkfatfs -F 32 /dev/mmcsd0

Trying to use versaloon and vsprog to flash my MCUZone UC3B-CPU

I’m trying to use versaloon programmer and its vsprog tool to flash a firmware in the AT32UC3B0256 microcontroller.

The first I had to remove some conditional compilation from vsprog source code to compile with support to AVR32 (it is a bad signal, probably because it is not well supported).

Let see if our device is supported:

$ vsprog -Savr32
VSProg 1.0 svn:
CopyRight(c) 2008-2010 by SimonQian <SimonQian@SimonQian.com>

URL: http://www.SimonQian.com/en/Versaloon
mail: SimonQian@SimonQian.com

Support list of avr32(AX):
avr32: id = 0x0, mode = j:JTAG(F), area = f1
avr32uc3b0512: id = 0x205003F, mode = j, area = f1
avr32uc3b1512: id = 0x205203F, mode = j, area = f1
avr32uc3b0256: id = 0x1EE403F, mode = j, area = f1
avr32uc3b1256: id = 0x1EE503F, mode = j, area = f1
avr32uc3b0128: id = 0x1EE603F, mode = j, area = f1
avr32uc3b1128: id = 0x1EE903F, mode = j, area = f1
avr32uc3b064: id = 0x1EEA03F, mode = j, area = f1
avr32uc3b164: id = 0x1EEB03F, mode = j, area = f1
avr32uc3a0512: id = 0x1EDC03F, mode = j, area = f1
avr32uc3a1512: id = 0x1EDD03F, mode = j, area = f1
avr32uc3a0256: id = 0x1EDF03F, mode = j, area = f1
avr32uc3a1256: id = 0x1EE003F, mode = j, area = f1
avr32uc3a0128: id = 0x1EE203F, mode = j, area = f1
avr32uc3a1128: id = 0x1EE303F, mode = j, area = f1

Good, it is supported! Then I tried to flash using the ELF file:

$ sudo vsprog -d2 -savr32 -cavr32uc3b0256 -I nuttx -o w
VSProg 1.0 svn:
CopyRight(c) 2008-2010 by SimonQian <SimonQian@SimonQian.com>

URL: http://www.SimonQian.com/en/Versaloon
mail: SimonQian@SimonQian.com

Debug:  avr32 initialized.
Debug:  avr32 initialized.
Error:  flash is not defined, please define first.
Error:  Fail to check target defined content.
Error:  Fail to run command: prepare.

Then I decided to use the nuttx.bin:

$ sudo vsprog -d2 -savr32 -cavr32uc3b0256 -I nuttx.bin -o w
VSProg 1.0 svn:
CopyRight(c) 2008-2010 by SimonQian <SimonQian@SimonQian.com>

URL: http://www.SimonQian.com/en/Versaloon
mail: SimonQian@SimonQian.com

Debug:  avr32 initialized.
Debug:  avr32 initialized.
Error:  Fail to parse input file nuttx.bin.
Error:  Fail to initialize target data.
Error:  Fail to run command: prepare.

Probably this raw binary is not supported.

Passing only the chip name the message change, but the error still the same:

$ sudo vsprog -d2 -cavr32uc3b0256 -I /home/alan/nuttxspace/nuttx/nuttx -o w
VSProg 1.0 svn:
CopyRight(c) 2008-2010 by SimonQian <SimonQian@SimonQian.com>

URL: http://www.SimonQian.com/en/Versaloon
mail: SimonQian@SimonQian.com

Debug:  avr32 initialized for avr32uc3b0256.
Error:  flash is not defined, please define first.
Error:  Fail to check target defined content.
Error:  Fail to run command: prepare.

I also tried adding the flash information to avr32.xml:

  <chip name="avr32uc3b0256">
    <chip_id>0x01EE403F</chip_id>
    <program_mode>j</program_mode>
    <app_page_num>512</app_page_num>
    <app_default>0xFF</app_default>
    <app_addr>0x80000000</app_addr>
    <app_seg>0</app_seg>
  </chip>

But it didn’t help, same flash not defined error.

Compiling NuttX to Atmel AVR32 Mcuzone UC3B-CPU board

I’m trying to get NuttX working on AVR32 (Mcuzone UC3b-CPU: http://www.mcuzone.com/product/UC3B/AT32UC3B-CPU_UG_V1_B080815.pdf ) and decided to report my (lack of) progress until now!

First we need to download and setup the toolchain:

$ git clone https://github.com/ramangopalan/avr32-gnu-toolchain-linux_x86
$ sudo mkdir /opt/avr32
$ cd avr32-gnu-toolchain-linux_x86
$ sudo cp -a * /opt/avr32/
$ export PATH=/opt/avr32/bin:$PATH

Compile NuttX to avr32dev1 (similar uc3b-cpu board)

$ ./tools/configure.sh avr32dev1:nsh
$ export LC_ALL=C
$ make

I tried to flash using the AVR32 DFU:

$ sudo dmesg
...
[26451.339347] usb 3-5.1: new full-speed USB device number 15 using xhci_hcd
[26451.490782] usb 3-5.1: New USB device found, idVendor=03eb, idProduct=2ff6, bcdDevice=10.00
[26451.490793] usb 3-5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[26451.490796] usb 3-5.1: Product: AT32UC3B DFU
[26451.490799] usb 3-5.1: Manufacturer: ATMEL
[26451.490802] usb 3-5.1: SerialNumber: 1.0.2

Let to list the DFU configurations:

$ sudo dfu-util -l
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [03eb:2ff6] ver=1000, devnum=15, cfg=1, intf=0, path="3-5.1", alt=0, name="UNKNOWN", serial="1.0.2"

Unfortunately the DFU flashing didn’t work:

$ sudo dfu-util -d 03eb:2ff6 -D nuttx.bin 
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 03eb:2ff6
Run-time device DFU version 0101
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 15
dfuIDLE, continuing
WARNING: DFU Status: 'Device stalled an unexpected request'
DFU mode device DFU version 0101
Device returned transfer size 65535
Limited transfer size to 4096
Copying data from PC to DFU device
Download	[                         ]   0%            0 bytesdfu-util: Error during download

Update: I had to use dfu-programmer to get it working: https://acassis.wordpress.com/2023/11/25/using-the-dfu-programmer-with-mcuzone-uc3b-cpu-board/