Olimex Support Forum

ARM => ATMEL => Topic started by: gccster on September 18, 2012, 03:34:46 pm

Title: SAM7-P256 WITH ARM-USB-TINY PROBLEM
Post by: gccster on September 18, 2012, 03:34:46 pm
Guys i recently bought Sam7-p256 board and Arm-Usb-Tiny i installed Olimex-ODS-20111221 and the included usb drivers i'm running a win7 64bit install.
1)I start olimexODS and open SAM7-EX256_FLASH project i open the main.c and do RUN->external Tools -> ARM-USB-TINY
and then
2) i open windows command prompt and do telnet localhost 4444
3) i do halt it seems to be working fine
4) i download https://www.olimex.com/Products/ARM/Atmel/SAM7-P256/resources/SAM7-P256-blinking-LED.zip which includes SAM7_Pxxx_led.bin
5) i do load_image /users/user/SAM7_Pxxx_led.bin and then i try to
verify_image /users/user SAM7_Pxxx_led.bin and i get Verification ERROR
6) I try to run the bin file like: resume 0x0 and i see no blinking led
7) the same happens when i use other addresses like 0x0020000 to load verify and resume the .bin
I also report that the SAM7-EX256_FLASH is not succesfully compiling but i would like first to fix the Blinking LED problem that is simpler...Can anybody please help me?
I also attach some screenshots to see the procedure
(http://www.lakoniapress.gr/image/olimexODS.png)
(http://www.lakoniapress.gr/image/telnet_sam7-p256.png)
Title: Re: SAM7-P256 WITH ARM-USB-TINY PROBLEM
Post by: maria_olimex on September 19, 2012, 01:47:38 pm
Hello,

There are several things that need to be changed/configured for the CDC project to work with the P256 board.
Rightclick on the EX256 project, copy. Paste it in the workspace and choose a name you like.

Load the project and open the Makefile; fix the prefix definition so that it is:
TOOLCHAIN_PREFIX=arm-none-eabi

If your compilation fails now, It would be best if you paste your compiler output here. There may be several things you can try, however:
It might be that the IDE doesn't know where to find the compiler. The installer adds the correct paths to the system paths, but they could conflict with another compiler on your PC. If you want to be sure that the project uses the yagarto compiler, do the following:
- Right click on the project name in the project explorer window and choose "Properties".
- Choose C/C++ make project, then the tab "Discovery options".
- In the "Compiler Invocation command" field, paste
${eclipse-home}/../yagarto/bin/arm-none-eabi-gcc.exe

If you still have problems building your project, paste your compiler output in a post here.

Configuring the Eclipse IDE and openOCD 0.6.0:
1. The current version of the Olimex IDE for OpenOCD uses OpenOCD 0.4.0, but the latest is 0.6.0 and it brings a number of improvements. First, visit
http://www.freddiechopin.info/en/download/category/4-openocd
and download the .zip file containing version 0.6.0. Put the folder openocd-0.6.0 in the Olimex IDE root directory. Don't delete the OpenOCD folder already there (it contains 0.4.0) as the two versions don't interfere with each other.

2. Several files are needed for openOCD to correctly work with the board. In the drop-down menu where you would choose your programmer, choose "External tools configurations..."
Choose ARM-USB-TINY and in the "Location:" field, replace the old path with

${eclipse_home}\..\openocd-0.6.0\bin\openocd-0.6.0.exe

or if you have a x64 Windows OS and want the x64 version, with
${eclipse_home}\..\openocd-0.6.0\bin-x64\openocd-0.6.0.exe

The other two fields should be:
Working directory: ${project_loc}
Argiments: -f ../scripts/interface/olimex-arm-usb-ocd-h.cfg -f project.cfg

Open the project.cfg file in you project and replace everything with:
#
# Flash AT91SAM7S memory using openocd
# and a FTDI FT2232-based JTAG-interface
#
# created by Martin Thomas
# based on information from Dominic Rath
#

#daemon configuration
telnet_port 4444
gdb_port 3333

gdb_memory_map disable
gdb_flash_program enable

#ARM-USB-TINY doesn't support adaptive clocking
adapter_khz 3000

source [find board/olimex_sam7_p256.cfg]

You need to create the board cfg file. Open notepad, and save the following
text as olimex_sam7_p256.cfg and place it in /.../openocd-0.6.0/scripts/board/:

# Olimex SAM7-P256 has a single Atmel at91sam7S256 on it.

source [find target/at91sam7s256.cfg]

You need to create the target cfg file. Open notepad, and save the following
text as at91sam7s256.cfg and place it in /.../openocd-0.6.0/scripts/target/:

#use combined on interfaces or targets that can't set TRST/SRST separately
reset_config srst_only srst_pulls_trst

if { [info exists CHIPNAME] } {
   set _CHIPNAME $CHIPNAME
} else {
   set _CHIPNAME at91sam7s
}

if { [info exists ENDIAN] } {
   set _ENDIAN $ENDIAN
} else {
   set _ENDIAN little
}

if { [info exists CPUTAPID] } {
   set _CPUTAPID $CPUTAPID
} else {
   set _CPUTAPID 0x3f0f0f0f
}

adapter_nsrst_delay 100
jtag_ntrst_delay 100

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

set _TARGETNAME $_CHIPNAME.cpu

target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm7tdmi

$_TARGETNAME configure -event reset-init {
        soft_reset_halt
        # RSTC_CR : Reset peripherals
        mww 0xfffffd00 0xa5000004
        # disable watchdog
   mww 0xfffffd44 0x00008000
   # enable user reset
   mww 0xfffffd08 0xa5000001
   # CKGR_MOR : enable the main oscillator
   mww 0xfffffc20 0x00000601
   sleep 10
   # CKGR_PLLR: 96.1097 MHz
   mww 0xfffffc2c 0x00481c0e
   sleep 10
   # PMC_MCKR : MCK = PLL / 2 ~= 48 MHz
   mww 0xfffffc30 0x00000007
   sleep 10
   # MC_FMR: flash mode (FWS=1,FMCN=73)
   mww 0xffffff60 0x00490100
   sleep 100
}

$_TARGETNAME configure -work-area-phys 0x00200000 -work-area-size 0x4000 -work-area-backup 0

#flash bank <driver> <base_addr> <size> <chip_width> <bus_width> <target_number> [<target_name> <banks> <sectors_per_bank> <pages_per_sector> <page_size> <num_nvmbits> <ext_freq_khz>]
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME at91sam7 0 0 0 0 0 0 0 0 0 0 0 0 18432

Configuring the debugger:

Open the drop-down menu next to the debug icon and choose "Debug configurations". Under "Zylin embedded debugger (Native)", create a new configuration and name it something you like. You need to edit the default settings.
Debugger tab: GDB Debugger: arm-none-eabi-gdb.exe (or, if launch fails, browse and point to that same file in the .../yagarto/bin/ directory)
GDB command line: .gdbinit

Commands tab:
Under "Initialize"
target remote 127.0.0.1:3333
monitor reset init
monitor arm7_9 force_hw_breakpoints enable
symbol-file main.out
monitor flash write_image erase unlock main 0 bin
monitor sleep 100
monitor arm7_9 fast_memory_access enable

Under "Run"
monitor soft_reset_halt
monitor thbreak main
monitor continue


To upload and debug after building:
1)start ARM-USB-TINY from the external tools menu.
2)from the drop-down menu next to the debug icon choose the debug configuration you just created for the project. If everything is successful, the gdb debugger will connect to openocd, command it to upload main.bin
and start the Eclipse debugging perspective. If there are errors, paste the console output here.

When you start debugging, the board will appear as a new device, point the driver installation to the file in the drv_inf folder in the project folder. The new device will have its own COM port and apper as "WinARM CDC Demo" in the device manager.

Best regards,
Maria
Title: Re: SAM7-P256 WITH ARM-USB-TINY PROBLEM
Post by: pacman on January 27, 2013, 06:17:26 pm
Excellent article. It helped me a lot!

I'd like to make a minor update: The source line for project.cfg should  be changed to...

source [find target/at91sam7x256.cfg]

...My project.cfg now looks like this:
#
# Flash AT91SAM7S memory using openocd
# and a FTDI FT2232-based JTAG-interface
#
# created by Martin Thomas
# based on information from Dominic Rath
#

#daemon configuration
telnet_port 4444
gdb_port 3333

gdb_memory_map disable
gdb_flash_program enable

#ARM-USB-TINY doesn't support adaptive clocking
adapter_khz 3000

# the following does not exist at all:
#source [find board/olimex_sam7_p256.cfg]

# the following does not find "target/sam7x256.cfg":
#source [find board/olimex_sam7_ex256.cfg]

source [find target/at91sam7x256.cfg]


For those dropping by, I'd like to suggest reading this document (https://www.olimex.com/Products/ARM/JTAG/_resources/Manual_PROGRAMMER.pdf) too.


Love
Jens
Title: Re: SAM7-P256 WITH ARM-USB-TINY PROBLEM
Post by: maria_olimex on January 29, 2013, 01:16:31 pm
Hello pacman,

I'm glad my reply was useful to you. However, the project.cfg file that I've posted is now pat of a fully functioning project in Olimex ODS, without any changes. I don't know what made you change the file, but this is the wrong chip for the board.
SAM7-P256  -> AT91SAM7S256
SAM7-EX256 -> AT91SAM7X256

notice that the X in the MCU name is part of the name, not a letter that could be anything (like the stmf4xx files for example). So the at91sam7s256.cfg file is correct for the board. Note, that the board file needs to be in the .../scripts/board/ directory in order to be found properly. Now in this case the board file is just calling the target file so it really can be omitted; but in a lot of OpenOCD projects the board files contain borad-specific instructions(not project-, not cpu-specific, but board) and it is important to keep everything separate.

Best Regards,
Maria/OLIMEX
Title: Re: SAM7-P256 WITH ARM-USB-TINY PROBLEM
Post by: pacman on January 29, 2013, 01:37:39 pm
Hi Maria.

Thank you for your reply; this is indeed helpful. :)

Quote from: maria_olimex on January 29, 2013, 01:16:31 pm
I'm glad my reply was useful to you. However, the project.cfg file that I've posted is now pat of a fully functioning project in Olimex ODS, without any changes. I don't know what made you change the file, but this is the wrong chip for the board.
SAM7-P256  -> AT91SAM7S256
SAM7-EX256 -> AT91SAM7X256


This is why I changed the file:
$ cd /usr/local/share/openocd/scripts/target
$ ls -l *sam7*
-rw-r--r--  1 root  wheel  1198 Nov 30 00:04 at91sam7se512.cfg
-rw-r--r--  1 root  wheel  1527 Nov 30 00:04 at91sam7sx.cfg
-rw-r--r--  1 root  wheel  1434 Nov 30 00:04 at91sam7x256.cfg
-rw-r--r--  1 root  wheel  1515 Nov 30 00:04 at91sam7x512.cfg
$ cd ../board
$ ls -l *sam7*
-rw-r--r--  1 root  wheel  151 Nov 30 00:04 atmel_at91sam7s-ek.cfg
-rw-r--r--  1 root  wheel   96 Nov 30 00:04 olimex_sam7_ex256.cfg
$ cat olimex_sam7_ex256.cfg
# Olimex SAM7-EX256 has a single Atmel at91sam7ex256 on it.

source [find target/sam7x256.cfg]


-There is no at91sam7s256.cfg installed with the openocd 0.6.1 package.
Also, the file "olimex_sam7_ex256" is looking for "sam7x256.cfg", which does not exist either.

Some files seem to be missing, maybe you want to contact the OpenOCD people and make sure they're OK for the next release.


Love
Jens
Title: Re: SAM7-P256 WITH ARM-USB-TINY PROBLEM
Post by: maria_olimex on January 29, 2013, 01:49:17 pm
Hello,

Yes, I just checked, they have changed the scripts' name from at91sam7s256.cfg to a universal at91sam7sx.cfg name and removed 2 rows of code(everything else is the same). I also had the old file in the target directory, because it stayed when I moved projects around for olimexODS. So you have the file, just change the 256 to x.

Here is the old file, it has two extra rows of code:

adapter_nsrst_delay 100
jtag_ntrst_delay 100


#use combined on interfaces or targets that can't set TRST/SRST separately
reset_config srst_only srst_pulls_trst

if { [info exists CHIPNAME] } {
   set _CHIPNAME $CHIPNAME
} else {
   set _CHIPNAME at91sam7s
}

if { [info exists ENDIAN] } {
   set _ENDIAN $ENDIAN
} else {
   set _ENDIAN little
}

if { [info exists CPUTAPID] } {
   set _CPUTAPID $CPUTAPID
} else {
   set _CPUTAPID 0x3f0f0f0f
}

adapter_nsrst_delay 100
jtag_ntrst_delay 100

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

set _TARGETNAME $_CHIPNAME.cpu

target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm7tdmi

$_TARGETNAME configure -event reset-init {
        soft_reset_halt
        # RSTC_CR : Reset peripherals
        mww 0xfffffd00 0xa5000004
        # disable watchdog
mww 0xfffffd44 0x00008000
# enable user reset
mww 0xfffffd08 0xa5000001
# CKGR_MOR : enable the main oscillator
mww 0xfffffc20 0x00000601
sleep 10
# CKGR_PLLR: 96.1097 MHz
mww 0xfffffc2c 0x00481c0e
sleep 10
# PMC_MCKR : MCK = PLL / 2 ~= 48 MHz
mww 0xfffffc30 0x00000007
sleep 10
# MC_FMR: flash mode (FWS=1,FMCN=73)
mww 0xffffff60 0x00490100
sleep 100
}

$_TARGETNAME configure -work-area-phys 0x00200000 -work-area-size 0x4000 -work-area-backup 0

#flash bank <driver> <base_addr> <size> <chip_width> <bus_width> <target_number> [<target_name> <banks> <sectors_per_bank> <pages_per_sector> <page_size> <num_nvmbits> <ext_freq_khz>]
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME at91sam7 0 0 0 0 0 0 0 0 0 0 0 0 18432


Best regards,
Maria/OLIMEX
Title: Re: SAM7-P256 WITH ARM-USB-TINY PROBLEM
Post by: pacman on January 29, 2013, 01:57:01 pm
Hi Maria.

Quote from: maria_olimex on January 29, 2013, 01:49:17 pm
Yes, I just checked, they have changed the scripts' name from at91sam7s256.cfg to a universal at91sam7sx.cfg name and removed 2 rows of code(everything else is the same).


Excellent, this explains it all!! Thank you very much, you're a lifesaver! :)


Love
Jens