[En-Nut-Discussion] Ethernut on TI's Cortex-M3 (Stellaris LM3S...)

Ole Reinhardt ole.reinhardt at embedded-it.de
Tue Oct 9 12:00:18 CEST 2012

Hi Philipp,

> I've now started to update the directory structure and the headers. 
> Please find attached the Git bundle containing the changesets which I've 
> made so far. 

Sorry, but the attachment is cut off by mailman... could you please send
me a private mail?

> I'd greatly appreciate if someone could have a look at it and tell me if 
> it is basically correct what I'm doing. And if it adheres to the 
> Ethernut standards (if there are any).

Yes for sure, I'll do. 

> And them something specifically @Ole:
> Most parts of the headers are fairly self-explaining, but two locations 
> confused me so far. Both are related to the clocking. The first one is 
> the _clk.h (e.g. stm32_clk.h in nut/include/arch/cm3/stm):
> /* STM32F Clock source selectors */
> #define SYSCLK_HSI  0
> #define SYSCLK_PLL  1
> #define SYSCLK_HSE  2
> #define PLLCLK_HSI  3
> #define PLLCLK_HSE  4

> What are these numbers for? Are they something STM32-related, or
> should these be present on all Cortex-M3? 

These are special to STM and are used to select the clock source used as
system clock. The way, system clocks are initialised, depends on your
hardware. For example the LPC17xx can be clocked directly from the
crystal, from a PLL etc.

You should start implementing the standard way, wich is used on the
devkit as well (most propably PLL generated clock from a crystal input)
and later add the configuration options for different clock settings.

> The other looks similar and is in nut/include/arch/cm3/timer.h:

> #define NUT_HWCLK_EMC   2
> /*!
>   * Clock for USB
>   */
> #define NUT_HWCLK_USB   3
> /*!
>   * Clock for WDT
>   */
> #define NUT_HWCLK_WDT   4
> ... and so on
> Again, what do these numbers stand for? This time it can't be specific 
> to one single Cortex-M3 architecture, as it is in a generic file and the 
> same defines are present for different families.

Indeed these settings define the CPU internal clocking domains (output
of the PLLs). But not all CM3 architectures implement all of these
clocking domains.

You should keep the existing and (if needed) add further clocking domain
defines here. These defines are used to query a clock using 

NutClockGet()            // nut/os/timer.c

which calls

NutArchClockGet()        // nur/arch/cm3/cmsis/ostimer_cortex.c

 * \brief Return the specified clock frequency.
 * If only 1 hardware clock is defined, then this function is mapped
 * to NutGetCpuClock().
 * The number of available hardware clocks depends on the target harware
 * and is specified by NUT_HWCLK_MAX + 1.
 * \param idx Index of the hardware clock. Can be any of the following:
 *            - NUT_HWCLK_CPU
 *            - NUT_HWCLK_PERIPHERAL
 * \return CPU clock frequency in Hertz.

> Generally: How is the clocking handled in Ethernut? Is there a document 
> explaining this? I'd expect something like SetClock() to which I'd pass 
> some params to define how the device is clocked, but this seems to be 
> handled differently.

Unfortunately not that I know.

Clock set up is very different on each architecture. It is done during
startup either in in the crtxxx.S file (avr and arm) or in <CPU>_clk.c
called from SetSysclock() in nut/arch/cm3/os/nutinit.c for the Cortex

So in general we are missing a common clocking concept right now.
Normally clock settings are defined using the Nut/OS configurator. 

Again: For the moment start with creating some fixed clock settings and
later make them configurable.

Do you have any sample sources (CMSIS examples) which came with your
devkit? You could easily take over the settings (and code) provided in
your system.c file (most probably it will be called system.c)




Thermotemp GmbH, Embedded-IT

Embedded Hard-/ Software and Open Source Development, 
Integration and Consulting


Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen - 
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97

Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280 

More information about the En-Nut-Discussion mailing list