Name

HAL Port — Implementation Details

Overview

This documentation explains how the eCos HAL specification has been mapped onto the STM32L4R9-DISCO board hardware, and should be read in conjunction with that specification. The STM32L4R9-DISCO platform HAL package complements the Cortex-M architectural HAL and the STM32 variant HAL. It provides functionality which is specific to the target board.

Startup

Following a hard or soft reset the HAL will initialize or reinitialize many of the on-chip peripherals. There is an exception for RAM startup applications which depend on a ROM monitor for certain services.

For ROM, ROMAPP and SRAM startup types the HAL will perform additional initialization, programming the various internal registers including the PLL, peripheral clocks and GPIO pins. The details of the early hardware startup may be found in the src/stm32l4r9_disco_misc.c in both hal_system_init and hal_platform_init.

Memory Map

The platform HAL package provides the memory layout information needed to generate the linker script. For all the STARTUP variations the top CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE bytes of the on-chip SRAM are reserved for the interrupt stack. The remainder of the internal SRAM is available for use by applications. The key memory locations are as follows:

Internal SRAM
This is located at address 0x20000000 of the memory space, and is 640KiB in size. The eCos VSR table occupies the bottom 444 bytes of memory, with the virtual vector table starting at 0x200001BC and extending to 0x200002D8.
Internal FLASH
This is located at address 0x08000000 of the memory space and will be mapped to 0x00000000 at reset. This region is 2048KiB in size. ROM and ROMAPP applications are by default configured to run from this memory.
OCTOSPI NOR Flash
The OCTOSPI NOR flash is accessible through the flash API. It is partitioned between the alternate application image and test space for the JFFS2 flash file system. The alternate application image occupies the first 1Mbyte of the OCTOSPI flash. The JFFS2 test space currently occupies the next 256Kbytes. The space allocated for the alternate application image may be adjusted by changing STM32L4_BOOTUP_ALTERNATIVE_OFFSET and STM32L4_BOOTUP_ALTERNATIVE_MAXLEN in plf_arch.h. The JFFS2 test space is defined in __STM32L4R9_DISCO_FLASHTEST_OCTOSPI in plf_io.h. Applications would not normally use this to define their JFFS2 filesystem location, but use the device/offset/length placement device format in the filesystem mount() call.
On-Chip Peripherals
These are accessible at locations 0x40000000 and 0xE0000000 upwards. Descriptions of the contents can be found in the STM32 User Manual.

Linker Scripts

The platform linker scripts define the following symbols:

hal_vsr_table
This defines the location of the VSR table. This is set to 0x20000000 for all startup types, and space for 111 entries is reserved.
hal_virtual_vector_table
This defines the location of the virtual vector table used to communicate between an ROM monitor and an eCos application. This is allocated right after the VSR table, at 0x200002BC.
hal_interrupt_stack
This defines the location of the interrupt stack. This is allocated to the top of internal SRAM, from 0x200A0000 down.
hal_startup_stack
This defines the location of the startup stack. For all startup types it is initially allocated at the half-way point of the interrupt stack.

Flash wait states

The STM32L4R9-DISCO platform HAL provides a configuration option to set the number of Flash read wait states to use: CYGNUM_HAL_CORTEXM_STM32_FLASH_WAIT_STATES. It is important to verify and if necessary update this value if changing the CPU clock (HCLK) frequency or CPU voltage. Consult the relevant STM32 datasheets and programming manuals for the STM32L476 parts for appropriate values for different clock speeds or voltages. The default of 5 reflects a supply voltage in Vcore range 1 and HCLK of 120MHz.

Real-time characterization

The tm_basic kernel test gives statistics gathered about the real-time characterization and performance of the kernel. The sample output is shown here for information. The test was built for SRAM startup with optimization flag -O2, since it provides the best performance as both code and data could remain on-chip.

Example 310.1. stm32l4r9_disco Real-time characterization

Configured 
Testing parameters:
   Clock samples:            32
   Threads:                  64
   Thread switches:         128
   Mutexes:                  32
   Mailboxes:                32
   Semaphores:               32
   Scheduler operations:    128
   Counters:                 32
   Flags:                    32
   Alarms:                   32
   Stack Size:             1088

             Startup, main thrd : stack used   356 size  1536
             Startup : Idlethread stack used    76 size  1280

eCos Kernel Timings
Notes: all times are in microseconds (.000001) unless otherwise stated

Reading the hardware clock takes 0 'ticks' overhead
... this value will be factored out of all other measurements
Clock interrupt took    7.09 microseconds (7 raw clock ticks)

Testing parameters:
   Clock samples:            32
   Threads:                  64
   Thread switches:         128
   Mutexes:                  32
   Mailboxes:                32
   Semaphores:               32
   Scheduler operations:    128
   Counters:                 32
   Flags:                    32
   Alarms:                   32
   Stack Size:             1088


                                 Confidence
     Ave     Min     Max     Var  Ave  Min  Function
  ======  ======  ======  ====== ========== ========
INFO:<Ctrl-C disabled until test completion>
    7.67    6.00   10.00    1.14   39%  45% Create thread
    1.50    1.00    2.00    0.50  100%  50% Yield thread [all suspended]
    1.44    1.00    2.00    0.49   56%  56% Suspend [suspended] thread
    1.34    1.00    2.00    0.45   65%  65% Resume thread
    2.00    2.00    2.00    0.00  100% 100% Set priority
    0.00    0.00    0.00    0.00  100% 100% Get priority
    3.67    3.00    4.00    0.44   67%  32% Kill [suspended] thread
    1.41    1.00    2.00    0.48   59%  59% Yield [no other] thread
    2.09    2.00    3.00    0.17   90%  90% Resume [suspended low prio] thread
    1.38    1.00    2.00    0.47   62%  62% Resume [runnable low prio] thread
    1.88    1.00    2.00    0.22   87%  12% Suspend [runnable] thread
    1.44    1.00    2.00    0.49   56%  56% Yield [only low prio] thread
    1.42    1.00    2.00    0.49   57%  57% Suspend [runnable->not runnable]
    3.72    3.00    4.00    0.40   71%  28% Kill [runnable] thread
    3.36    3.00    4.00    0.46   64%  64% Destroy [dead] thread
    6.25    6.00    7.00    0.38   75%  75% Destroy [runnable] thread
    6.64    6.00    8.00    0.48   60%  37% Resume [high priority] thread
    2.47    2.00    3.00    0.50   53%  53% Thread switch

    0.27    0.00    1.00    0.39   73%  73% Scheduler lock
    1.23    1.00    2.00    0.36   76%  76% Scheduler unlock [0 threads]
    1.23    1.00    2.00    0.36   76%  76% Scheduler unlock [1 suspended]
    1.26    1.00    2.00    0.38   74%  74% Scheduler unlock [many suspended]
    1.27    1.00    2.00    0.39   73%  73% Scheduler unlock [many low prio]

    0.31    0.00    1.00    0.43   68%  68% Init mutex
    1.63    1.00    2.00    0.47   62%  37% Lock [unlocked] mutex
    1.81    1.00    2.00    0.31   81%  18% Unlock [locked] mutex
    1.44    1.00    2.00    0.49   56%  56% Trylock [unlocked] mutex
    1.38    1.00    2.00    0.47   62%  62% Trylock [locked] mutex
    0.28    0.00    1.00    0.40   71%  71% Destroy mutex
    7.00    7.00    7.00    0.00  100% 100% Unlock/Lock mutex

    0.53    0.00    1.00    0.50   53%  46% Create mbox
    0.22    0.00    1.00    0.34   78%  78% Peek [empty] mbox
    1.84    1.00    2.00    0.26   84%  15% Put [first] mbox
    0.31    0.00    1.00    0.43   68%  68% Peek [1 msg] mbox
    2.00    2.00    2.00    0.00  100% 100% Put [second] mbox
    0.41    0.00    1.00    0.48   59%  59% Peek [2 msgs] mbox
    1.97    1.00    2.00    0.06   96%   3% Get [first] mbox
    1.84    1.00    2.00    0.26   84%  15% Get [second] mbox
    1.59    1.00    2.00    0.48   59%  40% Tryput [first] mbox
    1.50    1.00    2.00    0.50  100%  50% Peek item [non-empty] mbox
    1.56    1.00    2.00    0.49   56%  43% Tryget [non-empty] mbox
    1.50    1.00    2.00    0.50  100%  50% Peek item [empty] mbox
    1.38    1.00    2.00    0.47   62%  62% Tryget [empty] mbox
    0.38    0.00    1.00    0.47   62%  62% Waiting to get mbox
    0.06    0.00    1.00    0.12   93%  93% Waiting to put mbox
    0.41    0.00    1.00    0.48   59%  59% Delete mbox
    5.09    5.00    6.00    0.17   90%  90% Put/Get mbox

    0.19    0.00    1.00    0.30   81%  81% Init semaphore
    1.38    1.00    2.00    0.47   62%  62% Post [0] semaphore
    1.56    1.00    2.00    0.49   56%  43% Wait [1] semaphore
    1.41    1.00    2.00    0.48   59%  59% Trywait [0] semaphore
    1.34    1.00    2.00    0.45   65%  65% Trywait [1] semaphore
    0.31    0.00    1.00    0.43   68%  68% Peek semaphore
    0.28    0.00    1.00    0.40   71%  71% Destroy semaphore
    4.94    4.00    5.00    0.12   93%   6% Post/Wait semaphore

    0.56    0.00    1.00    0.49   56%  43% Create counter
    0.41    0.00    1.00    0.48   59%  59% Get counter value
    0.19    0.00    1.00    0.30   81%  81% Set counter value
    1.75    1.00    2.00    0.38   75%  25% Tick counter
    0.28    0.00    1.00    0.40   71%  71% Delete counter

    0.31    0.00    1.00    0.43   68%  68% Init flag
    1.53    1.00    2.00    0.50   53%  46% Destroy flag
    1.31    1.00    2.00    0.43   68%  68% Mask bits in flag
    1.50    1.00    2.00    0.50  100%  50% Set bits in flag [no waiters]
    2.06    2.00    3.00    0.12   93%  93% Wait for flag [AND]
    2.09    2.00    3.00    0.17   90%  90% Wait for flag [OR]
    2.06    2.00    3.00    0.12   93%  93% Wait for flag [AND/CLR]
    2.03    2.00    3.00    0.06   96%  96% Wait for flag [OR/CLR]
    0.22    0.00    1.00    0.34   78%  78% Peek on flag

    1.00    1.00    1.00    0.00  100% 100% Create alarm
    2.13    2.00    3.00    0.22   87%  87% Initialize alarm
    1.31    1.00    2.00    0.43   68%  68% Disable alarm
    2.25    2.00    3.00    0.38   75%  75% Enable alarm
    1.47    1.00    2.00    0.50   53%  53% Delete alarm
    1.91    1.00    2.00    0.17   90%   9% Tick counter [1 alarm]
    9.00    9.00    9.00    0.00  100% 100% Tick counter [many alarms]
    2.84    2.00    3.00    0.26   84%  15% Tick & fire counter [1 alarm]
   46.97   46.00   47.00    0.06   96%   3% Tick & fire counters [>1 together]
   10.25   10.00   11.00    0.38   75%  75% Tick & fire counters [>1 separately]
    6.00    6.00    6.00    0.00  100% 100% Alarm latency [0 threads]
    6.00    6.00    6.00    0.00  100% 100% Alarm latency [2 threads]
    5.77    5.00    6.00    0.36   76%  23% Alarm latency [many threads]
   10.01   10.00   11.00    0.01   99%  99% Alarm -> thread resume latency

    0.00    0.00    0.00    0.00            Clock/interrupt latency

    2.74    2.00    3.00    0.00            Clock DSR latency

     175     132     220                    Worker thread stack used (stack size 1088)
            All done, main thrd : stack used   704 size  1536
            All done : Idlethread stack used   172 size  1280

Timing complete - 29740 ms total

PASS:<Basic timing OK>
EXIT:<done>