The file Cortex/Hardware/LPC17xx/startLPC17xx.fth contains the start up code for LPC17xx devices. Start up code for other Cortex-M3 implementations, e.g. STM32, can be found in parallel directories. The absolute minimum code to start a Cortex-M3 is in Cortex/StartCortex.fth.
l: ExcVecs \ -- addr ; start of vector table
The exception vector table is /ExcVecs
bytes long. The
equate is defined in the control file. Note that this table
table must be correctly aligned as described in the Cortex-M3
Technical Reference Manual (ARM DDI0337, rev E page 8-21). If
placed at 0 or the start of Flash, you'll usually be fine.
: SetExcVec \ addr exc# --
Set the given exception vector number to the given address.
Note that for vectors other than 0, the Thumb bit is forced
to 1. Do not use this to set the ISP checksum!
0 equ sp-guard \ -- +n
The number of cells reserved as guard space on the Forth
data stack. Usually set to two in the control file. This
value allows the data stack to underflow by the given amount
before other data is corrupted.
init-s0 tos-cached? sp-guard + cells - equ real-init-s0 \ -- addr
The data stack pointer value set at start up.
Find the clock divider that generates the CCO clock at 288 Mhz. The value in the CCLKCFG register is one less than this.
#288000000 system-speed / 1- equ CCLKCFGval \ -- x
The CCLKCFG register initial value.
CCLKCFGval 1+ system-speed * equ cco-speed \ -- hz
The actual CCO frequency that will be generated by the
calculated configuration values.
: genPLL0 \ -- mval nval
INTERPRETER: Generate the data for the PLL0CFG register.
For the moment, we set N=1 (nval=0), and calculate the Mval
only.
: gen-FlTim \ -- flcfg
Generate the Flash configuration register value.
L: ^PCLKSEL0val
This location contains the initial value of the PCLKSEL0
register if the equate PCLKSELbug?
is set non-zero.
L: ^PCLKSEL1val
This location contains the initial value of the PCLKSEL0
register if the equate PCLKSELbug?
is set non-zero.
: setClocks \ --
Enable the clocks, set the bus dividers, and enable the PLLs
as required.
: setNVIC \ --
Initialise the NVIC. By default it points into Flash.
: StartCortex \ -- ; never exits
Set up the Forth registers and start Forth. Other primary
hardware initialisation is also performed here.