Pages: [1]   Go Down
Author Topic: Arduino Due Initialization  (Read 1812 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm new to Arduino and I'm little bit confused about start up initialization. Is there any information on how DUE is initializated? Especially I'm wondering if it starts at 84MHz or I have to set up PLL myself?

I think arduino_due_x/variant.cpp is file where some initialization is done, but then it use SystemInit(), but I'm not able to find this function quickly.

Thanks for any suggestion.

BR,
Krzysiek
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know if it is the exact file used, but look at hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/source/system_sam3xa.c - there looks like there is some clock setting code in there.
Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There's a call to init() in main()

C:\arduino-1.5\hardware\arduino\sam\cores\arduino\main.cpp

It's bound to be in there even if you have to follow the train of calls for a while. But for the life of me I can't find where init() is.

It probably winds up at SystemInit() in the file Stimmer mentioned, but it would be nice to know.

EDIT:
There's a main() in this file that calls SystemInIt() directly

C:\arduino-1.5\hardware\arduino\sam\system\CMSIS\Examples\cmsis_example\main.c

But the first main() I pointed to seem to be the Arduino entry point.

______
Rob
« Last Edit: November 16, 2012, 08:52:02 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd add that from my experiments with timers and VGA, the clock is definitely running at 84MHz by the time setup is called.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many thanks for replay.

It looks like 'hardware/arduino/sam/cores/arduino' is an Arduino part with the entry point main.cpp. Then, I think initialization of MCU is done in init() function from 'hardware/arduino/sam/variants/arduino_due_x/variant.cpp'.

The init() uses SystemInit() function, it's probably from 'hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/source/system_sam3xa.c'.

It seems that this CMSIS folder contains some standard libraries provided by ARM: http://www.arm.com/products/processors/cortex-m/cortex-microcontroller-software-interface-standard.php.

'hardware/arduino/sam/system/libsam/' is also interesting, it contains functions to use some pheripherals, like RTC, SPI or Watchdog.

Regards,
Krzysiek
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

as you already discovered, the Reset_Handler function is the entry point.

https://github.com/arduino/Arduino/blob/ide-1.5.x/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/source/gcc/startup_sam3xa.c#L244

I also patched the file above:

https://github.com/arduino/Arduino/commit/d994e48c5565a0c7aea54384a1b15a19623fe209

the reason is that __libc_init_array() initializes all static c++ objects (by calling their constructor), and some libraries
(for instance LiquidCrystal) uses delay() inside constructors, and delay() didnt work (hangs the CPU) if the hardware is not
initalized before.

C

Logged

C.

Pages: [1]   Go Up
Jump to: