Go Down

Topic: Arduino Due Initialization (Read 2125 times) previous topic - next topic

krzysiek

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

stimmer

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.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

Graynomad

#2
Nov 17, 2012, 02:44 am Last Edit: Nov 17, 2012, 02:52 am by Graynomad Reason: 1
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
Rob Gray aka the GRAYnomad www.robgray.com

stimmer

I'd add that from my experiments with timers and VGA, the clock is definitely running at 84MHz by the time setup is called.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

krzysiek

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

cmaglie

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

C.

Go Up