Imports working McuBoot for reset.
Updates microsec ticker driver.
Default baudrate is set to 115200 to see TF-M boot messages.
Stack top is set to scatter file dependent and not hard-coded.
Volatile makes no real difference when we're using assembler, or locked
functions, but leaving it off could be more efficient for the basic
loads and stores. So add non-volatile overloads in C++ for them.
Reimplement atomic code in inline assembly. This can improve
optimisation, and avoids potential architectural problems with using
LDREX/STREX intrinsics.
API further extended:
* Bitwise operations (fetch_and/fetch_or/fetch_xor)
* fetch_add and fetch_sub (like incr/decr, but returning old value -
aligning with C++11)
* compare_exchange_weak
* Explicit memory order specification
* Basic freestanding template overloads for C++
This gives our existing C implementation essentially all the functionality
needed by C++11.
An actual Atomic<T> template based upon these C functions could follow.
Once a fatal error is in progress, it's not useful to trap RTX errors
or mutex problems, so short-circuit the checks.
This makes it more likely that we may be able to get the console
initialised if it is being written to for the first time by `mbed_error`
in a difficult context - such as an RTX error callback from inside an
SVCall.
For example, the one-line program
osMutexAcquire(NULL, 0);
will generate an RTX error trap, then `mbed_error` will try to call
`write(STDERR_FILENO)` to print the error, which will prompt mbed_retarget to
construct a singleton `UARTSerial`. This would trap in the mutex
for the singleton or the construction of the UARTSerial itself, if
we didn't allow this leniency. If we clear the mutex checks, then
`UARTSerial::write_unbuffered` will work.
User uses of `MBED_MAKE_ERROR` assemble a new error that gets its bottom
16 bits from an existing negative 32-bit error code. This lead to
undefined behaviour when `<<` was used on it - even though it was a
shift by zero!
Avoid the undefined behaviour warning from Clang by masking before
shifting.
In rtos-less code, heap is defined by assuming one-region. Through weak-reference to
ARM_LIB_HEAP, heap definition is fixed if ARM_LIB_HEAP is defined.
Please note the heap address of the both the banks must not be contigious else
GCC considers it to be single memory bank and does allocation across the banks,
which might result into hard-fault
Assert failure took a critical section before calling `mbed_error`.
There's no need to take a critical section on assert failure -
mbed_error does not do this, and is designed to operate from normal
contexts.
Avoiding the critical section will improve the chances of console
initialisation due to assert failure working nicely.
New `target.console-uart` option added to indicate whether a target has
a console UART on STDIO_UART_TX/RX/RTS/CTS pins. (The existing option
`target.console-uart-flow-control` indicates whether RTS and or CTS is
available in addition to TX and RX).
The option defaults to true, and is currently true on all platforms. It
only applies if DEVICE_SERIAL is true, so no need to go through and mark
it false for non-SERIAL platforms.
An application can turn off target.console-uart to save ROM/power/etc if
they don't want to use the serial console. If this is turned off, the
console won't be activated for stdin/stdout, but the application is
still free to open `UARTSerial(STDIO_UART_TX, STDIO_UART_RX)`
themselves.
This provides the ability to generate really small delays - it's often
the case that wait_us() takes multiple microseconds to set up, so
having an alternative suitable for <10us delays is useful.
There have been a few local implementations - it makes sense to
centralise them as they need retuning for each new ARM core.
Based on the local implementation inside the Atmel 802.15.4 driver.
Add a necessary helper to allow FileHandle objects to be obtained
from POSIX file descriptors.
Primary envisaged use case is to act on STDIN_FILENO etc, eg to
set it non-blocking or use sigio, or to use the enable API.
Add API to dynamically enable/disable input and output on FileHandles.
Aim is to allow power saving by indicating that we permanently or
temporarily do not require input, so that for example serial Rx
interrupts can be released, and deep sleep permitted.
Memory model for RTOS and No RTOS was initially single stack and heap,
only few targets implemented 2-region RAM model.
2-region RAM model is applied for all toolchains and targets.
GCC: __wrap__sbrk was implemented for 2-region ram model, with switch to 2-region
for all targets, we do not need target specific implementation of this API
Also _sbrk is WEAK function, hence can be over written in target folder for
special cases
The following commits: #8039, #9092 added Boot/ISR stack definition to all scatter files (ARM_LIB_STACK).
This has changed memory model for RTOS-less builds to 2-region memory model and caused failure in case of rtos less builds.
This PR defines valid heap/stack regions for rtos-less builds.
Fix the following build warning
Compile [ 83.4%]: mbed_error.c
[Warning] mbed_error.c@71,21: 'compute_crc32' defined but not used [-Wunused-function]
compute_crc32 usage is guraded with #define, but not the definition.
Use the same #define around the definition of compute_crc32()
SharedPtr::reset did not actually set the stored pointer value.
Correct this, with other minor tidies:
* Ensure counter is set to NULL if pointer is reset to NULL
* Be consistent about not clearing pointers in decrement_counter().
->move() operator was not touching unused data fields, therefore
leaving uninitialised data and failing the comparison.
Fixed by initialising all fields to zero before moving.
mbed_die was calling wait_ms in a critical section - this is deprecated
behaviour, and caused a fatal error in debug builds, potentially leading
to an infinite reboot loop if this was caused due to a reboot limit
halt.
Switch to using wait_us - this is safe in a critical section. This does
trigger a call to mbed_warning, due to the large parameter, but that is
harmless - it doesn't output anything to the console, and won't
overwrite the error context if it already contains something.
The pre-main check of error_reboot_count was applied repeatedly on
every boot, meaning that once the reboot limit was hit, every subsequent
reset would halt before main, until something managed to clear
or corrupt the error context.
Set the is_error_processed flag before halting, so that when an external
agent resets us while we're halted, we do not report the error and halt
again.
A couple of places in mbed_retarget.cpp were testing for either ARMC5 or
ARMC6 in a long-winded fashion. Testing for __ARMCC_VERSION being
defined is sufficient.
Similar to SingletonPtr, use atomic accesses when loading the guard word
outside the lock, and when storing, to ensure no races for threads that
don't take the lock.
Lack of atomics unlikely to be a problem in current builds, but code
could conceivably be subject to reordering if link-time optimisation was
enabled.
SingletonPtr's implementation wasn't totally safe - see "C++ and the
Perils of Double-Checked Locking"by Meyers and Alexandrescu. No problems
observed in practice, but it was potentially susceptible to compiler
optimisation (or maybe even SMP issues).
Now that we have atomic loads and stores, the function can be made safe,
avoiding any potential races for threads that don't take the lock:
ensure that the unlocked load is atomic, and that the pointer store is
atomic.
See https://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/
for more discussion.
As barriers were added in #9247, review comments pointed out that atomic
stores needed a second barrier, and they got one. But atomic_flag_clear
was missed.
Add atomic load and store functions, and add barriers to the existing atomic
functions.
File currently has no explicit barriers - we don't support SMP, so don't
need CPU barriers.
But we do need to worry about compiler barriers - particularly if link time
optimisation is activated so that the compiler can see inside these
functions. The assembler or intrinsics that access PRIMASK for
enter/exit critical act as barriers, but LDREX, STREX and simple
volatile pointer loads and stores do not.
Critical section count/state variables are synchronised by IRQ disabling and
critical section calls themselves, so do not need to be volatile.
This eliminates a couple of unnecessary reads of the counter variable.
The DEVICE_FOO macros are always defined (either 0 or 1).
This patch replaces any instances of a define check on a DEVICE_FOO
macro with value test instead.
Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
As part of work to improve the debugging of exceptions, have
Mbed OS make an effort to make exceptions more precise in debug builds
at the cost of performance.
Related pyOCD work:
https://github.com/mbedmicro/pyOCD/pull/430
Make the option positively named, and as it is a platform config
option make sure it only affects platform code.
HAL functions still remain available even if platform is told not
to use them.
MPU lock under- or overflow is not a likely random runtime failure - it
will be a mismatched lock/unlock programming error, so should be
detected during development. Make the checks asserts so they can be
left out from release builds. MBED_ASSERT is also a bit smaller than
MBED_ERROR in develop builds.
Make the following changes:
-Allow a vector specific ARM MPU driver by defining MBED_MPU_CUSTOM
-Allow ROM address to be configured for ARMv7-M devices by
setting the define MBED_MPU_ROM_END
-Add ROM write protection
-Add new functions and lock
-enable at boot
-disable during flash programming
Rename MpuXnLock to ScopedMpuXnLock so it has the same naming
convention as ScopedMutexLock. Also make this class inherit from
NonCopyable to prevent misuse.
Enable the MPU as part of the boot sequence and disable it before
starting a new application. Also add reference counted MPU lock and
unlock functions to allow code to execute from ram when necessary.
Adding new modules inside the namespace could be breaking change for existing code base
hence add `using namespace::class` for classes newly added to mbed namespace to maintian
backwards compatibility.
MBED_NO_GLOBAL_USING_DIRECTIVE is added to remove auto-addition of namespace
Macro guard `MBED_NO_GLOBAL_USING_DIRECTIVE` is added around namespace, to avoid
polluting users namespace.
SocketStats Class is added to collect and provide the statistics information.
In this phase only socket information is collected and max sockets that can
be recorded at any time are configurable through 'MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT'
Network statistics can be enabled through a macro MBED_NW_STATS_ENABLED
More information on design is captured in #8743
Implement the following:
KVStore base class
TDBStore class
FileSystemStore class
SecureStore class
Global APIs
Configuration framework
Design documentation
Moved "bootloader_not_supported" check to where it was and handle that exception at only one place.
Removed ram/rom size info for realtek from targets.json. THe info we have is not correct.
was Not handling config exceptions from regions and ram_regions property
adding rom-ram info for REALTEK_RTL8195AM
Modify the implementation of CThunk so it does not execute from ram.
Instead is uses an array of functions in flash which can be allocated
as a thunk. The number of CThunks that can be used by an application
can be configured with MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX.
The issue is that the process_oob check would only return immediately
if no data at all on entry, or when receiving a known OOB. Any other
line noise or unknown OOBs could lead to a timeout delay - read the
noise or unknown OOB then timeout waiting for another line of input.
This revised version modifies the parser to recheck readable after each
line end when only looking for OOBs, so it can immediate exit.
Save some ROM space by putting MBED_NORETURN attributes on error
functions and failed asserts.
mbed_error was documented as returning an error code. It never
actually could return, so documentation updated, but return type
kept.
Various fixes in preparation for making sure error calls do not return.
* Clear out handle_error's use of error_in_progress as a sort of spin
lock; this is most likely to deadlock if ever activated, and conflicts
with error's use of error_in_progress. Use a normal critical section lock.
* Make error use same mbed_halt_system helper as mbed_error.
* Make error's recursion check avoid print and proceed to halt, rather
than returning.
* Make mbed_error use error_in_progress to avoid recursion in same way
as error() does.
* Give mbed_halt_system its own recursion check in case of error in
mbed_die - give it a simple fallback.
* Make the in_progress things properly atomic, just in case.
An atomic flag primitive is sometimes wanted, and it is cumbersome to
create it from the compare-and-swap operation - cumbersome enough that
people often don't bother.
Put in a core_util_atomic_flag that follows the C11/C++11 atomic_flag
API, such that it could be mapped to it with #define later.