Compare commits

..

145 Commits

Author SHA1 Message Date
Christopher Friedt
38de9b0156 release: Zephyr 2.7.2
Set version to 2.7.2

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2022-04-22 12:24:33 -04:00
Flavio Ceolin
3a21dff459 doc: release: Update release notes with CVE
Update 2.7.1 release notes with information about CVE fixed.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-04-22 11:02:44 -04:00
Stephanos Ioannidis
b98ec9e0db x86: Initialise FPU regs during thread creation for eager FPU sharing
When "eager FPU sharing" mode is enabled, FPU registers must be
initialised at the time of thread creation because the floating-point
context is always active and no further FPU initialisation is performed
later.

Note that, in case of the "lazy FPU sharing" mode, floating-point
context is inactive by default and the FPU is initialised when the
first floating-point instruction is executed.

Refer to the issue #44902 for more details.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
(cherry picked from commit f9a3f02b86)
2022-04-19 18:08:22 +02:00
Christopher Friedt
8f2d164674 release: Bump release to 2.7.2-rc1
Bump version to 2.7.2-rc1

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2022-04-19 06:18:23 -04:00
Jamie McCrae
6b61b219ea doc: Add link to J-Link virtual MSD disable for SMP
Virtual MSD J-Link support on some development boards has caused an
issue with SMP due to limiting the maximum size of UART data via the CDC
endpoint, add a link to the SMP documentation and smp_svr sample
application on how to disable MSD functionality and resolve the issue.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-04-14 20:21:06 -04:00
Jaxson Han
8822f85ef9 board: arm64: fvp_baser_aemv8r_smp: Increase CONFIG_MAX_THREAD_BYTES
Increase CONFIG_MAX_THREAD_BYTES to 3 to fix the build issue on
tests/drivers/build_all/modem/ test case.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
Change-Id: I6a26955bdd7e8b176894fa8246aec63a3a3db05f
(cherry picked from commit a483828d46)
2022-04-14 20:19:22 -04:00
Jaxson Han
0bc81c82ab board: arm64: fvp_baser_aemv8r: Update the version requirement
The current minimum required version of "Armv8-R AEM FVP" is 11.16.16.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
Change-Id: Iaaf1ec7fd432753371b58d13fdd29b1278f6c997
(cherry picked from commit 3875a1e787)
2022-04-14 20:19:22 -04:00
Jaxson Han
32c49d04b0 cmake: armfvp: Add FVP min version check
After the fix of FVP_BaseR_AEMv8R booting issue, the minimum required
version of FVP will be 11.16.16. Add an FVP minimal required version
check in building time.

When the ARMFVP_MIN_VERSION is set in board cmake file, the version
check will be enabled and print a warning.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
Change-Id: Ibbade0c328b5e91b8830fb35cba6917f08aabbda
(cherry picked from commit 3c1f3197e2)
2022-04-14 20:19:22 -04:00
Jaxson Han
02c32316fc arm64: Fix booting issue with FVP V8R >= 11.16.16
In the Armv8R AArch64 profile[1], the Armv8R AArch64 is always in secure
mode. But the FVP_BaseR_AEMv8R before version 11.16.16 doesn't strictly
follow this rule. It still has some non-secure registers
(e.g. CNTHP_CTL_EL2).

Since version 11.16.16, the FVP_BaseR_AEMv8R has fixed this issue. The
CNTHP_XXX_EL2 registers have been changed to CNTHPS_XXX_EL2. So the
FVP_BaseR_AEMv8R (version >= 11.16.16) cannot boot Zephyr. This patch
will fix it.

[1] https://developer.arm.com/documentation/ddi0600/latest/

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
Change-Id: If986f34dc080ae7a8b226bba589b6fe616a4260b
(cherry picked from commit fd231e32e9)
2022-04-14 20:19:22 -04:00
Tomasz Bursztyka
9bf571808d net/tcp: Use highest priority for TCP internal work queue
Reason why the prority was at its lowest is unknown, but now that it may
be used to send local packets (which used to be sent right away),
it seems to affect TCP scheduling in loopback mode. Raising the prority
so it matches how it was previously (i.e. sent right away) should fix
things. (Note however that this issue was not broadly present, only
sockets.tls test seemed to be affected.)

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-04-13 14:38:15 -04:00
Tomasz Bursztyka
4eec9d95ef test/net: Make sure the tls server socket is accepting before connect
Client thread might run before the server gets to put itself on accept.
Leading to the server waiting forever.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-04-13 14:38:15 -04:00
Tomasz Bursztyka
32a593396d tests/net: Put the context down and not only the tcp part in tcp2 test
This will clean up the context properly and call net_tcp_put()
relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-04-13 14:38:15 -04:00
Tomasz Bursztyka
066dcd6119 tests/net: Switch k_msleep to k_yield for tcp packet scheduling
TCP work queue is of higher priority so k_yield should do the trick, and
the test will not be affected by any timing.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-04-13 14:38:15 -04:00
Tomasz Bursztyka
ffcc1d3c92 tests/net: TLS test requires more RX PKT and buffers
Due to the previous change on when to send TCP packet on local IP, pkt
may be held in a queue which is to run on a k_work. This changes the
scheduling, and due to that one of the test is failing to allocate a
RX net_pkt at the time it wants to. (previous TCP connection is not yet
fully closed and still own PKT that new connection cannot get then).

Of course all those waiting paquets require buffers so raising them.

It was verified that there is no leak, adding net_pkt_print() at
tcp_conn_unref() shows that when all tcp connection are finally unrefed:
all net_pkt get freed as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-04-13 14:38:15 -04:00
Tomasz Bursztyka
2d49a4c8b9 net/context: Close TCP connection properly
Closing a connection, thus calling net_context_put() will not close a
TCP connection properly, and will leak tcp connection memory.

This is because: net_context_put calls net_context_unref which calls
net_tcp_unref which leads to unref tcp connection and thus sets
ctx->tcp to NULL. Back to net_context_put, that one finally calls
net_tcp_put: but that bails out directly since ctx->tcp is NULL.

Fixing it by inverting net_tcp_put() and net_context_unref() calls
within net_context_put().

Fixes #38598

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-04-13 14:38:15 -04:00
Tomasz Bursztyka
9d229e0bb5 net/tcp: Stop TCP state machine breaking when sending locally
On any target, running a TCP server and a net shell can show the issue:
net tcp connect local_ip port

will fail. Usally it ends up by consumming all tcp connection memory.

This is because in tcp_in(), state changes will most of the time lead to
sending SYN/ACK/etc... packets under the same thread, which will run all
through net_send_data(), back to tcp_in(). Thus a forever loop on SYN ->
SYN|ACK -> SYN -> SYN|ACK until tcp connection cannot be allocated
anymore.

Fixing it by scheduling any local packet to be sent on the queue.

Fixes #38576

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-04-13 14:38:15 -04:00
Jamie McCrae
74c00d0b4e boards: bl654_usb: Fix non-mcuboot builds not limiting size
This limits non-mcuboot builds to have a maximum size of 892KB to
prevent code being placed over the top of the bootloader's flash area.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-04-12 16:40:58 -04:00
Michael Schmidt
2a09d5e53f drivers: virt_ivshmem: Allow multiple instances of ivShMem devices.
- Supporting multiple instances of ivShMem virtual devices.
- Introduces DT based configuration for ivShMem devices.
- Add DTS overlay file to test new multiple ivshmem instance capability.
- Enable BDF unspecified device initialization.
  (limited to one instance. An improved version of pcie_bdf_lookup()
  will come soon that fixes this limitation)
- Make PCIE DTS file macros available for a proper ivshmem device
  properties parsing.

Sample for dts file:
pcie0 {
	label = "PCIE_0";
	#address-cells = <1>;
	#size-cells = <1>;
	compatible = "intel,pcie";
	ranges;
    ivshmem0: ivshmem@800 {
	    compatible = "qemu,ivshmem";
	    reg = <PCIE_BDF_NONE PCIE_ID(0x1af4,0x1110)>;
	    label = "IVSHMEM";
	    status = "okay";
    };
};

Signed-off-by: Michael Schmidt <michael1.schmidt@intel.com>
2022-04-12 16:40:25 -04:00
Jamie McCrae
ad4e9934de samples: subsys: mgmt: smp_svr: Fix dupicate fs mgmt registration
This fixes an issue with the filesystem mcumgr being registered twice
in the sample application which resolves an issue with an endless loop
if a mcumgr handler is used which is not registered.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-04-12 16:39:15 -04:00
Alexandre Bourdiol
f133449cf5 boards: arm: stm32l562e_dk and nucleo_l552ze_q add openocd support
OpenOCD was partially implemented in board.cmake,
it is now functional.

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2022-04-12 12:04:07 -04:00
Gerard Marull-Paretas
33318bfb45 doc: css: update code documentation directives style
New Sphinx version (or docutils) has slightly changed the output format
for code documentation directives. These changes try to mimic previous
behavior, even though it does not achieve 100% equal result. In some
cases the new default style does not require further tweaks, and in some
others styling as before is not possible.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-04-07 05:30:04 -04:00
Gerard Marull-Paretas
3497031e3e doc: update requirements
breathe: for simplicity, require versions > 4.30 (lower versions have
known issues, so do not take risks).
Sphinx: start requiring versions >=4.x. Keep with compatible versions,
since Sphinx major updrages can easily break extensions, themes, etc.
sphinx_rtd_theme: upgrade to >=1.x. Again, keep with compatible versions
since we have style customizations that can likely break on major
upgrades.
pygments: Allow any version >=2.9 (version that introduced DT support).
We do not have strong compatibility requirements here.
sphinx-notfound-page: Remove any requirements, we do not have strong
requirements for this one.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-04-07 05:30:04 -04:00
Erwan Gouriou
57a1be33ff boards: nucleo_wb55rg: Add stm32cubeprogrammer runner
Use of stm32cubeprogrammer runner makes life easier
on test bench for this device.
Though, keep openocd as default.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-05 12:10:33 -04:00
Erwan Gouriou
652eb37b4d scripts/pylib/twister: Add sn option to stm32cubeprogrgammer runner
In order to enable use of stm32cubeprogrammer runner with twister,
add "sn" tool specific option which allows to provide target serial
number and hence select the target to flash when multiple ones are
connected to the host.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-05 12:08:40 -04:00
Szymon Janc
9e4edaec21 tests/bluetooth/tester: Add support for auto connection establishment
autopts was updated to properly require support for Accept Filter List
in Auto Connection Establishment Procedure related tests. This patch
enabled support for it and adds required BTP support.

This was affecting following qualification test cases:
GAP/CONN/ACEP/BV-03-C
GAP/CONN/ACEP/BV-04-C

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-29 18:07:48 +02:00
Kweh Hock Leong
9b18f4a730 net: gptp: Fix type mismatch calculation error in gptp_mi
NSEC_PER_SEC is an unsigned integer macro. Thus, -NSEC_PER_SEC will be
treated as unsigned integer as well which lead to calculation error on
64bits integer variables. Added the correct type casting into the formula
to fix the calculation error.

Signed-off-by: Kweh Hock Leong <hock.leong.kweh@intel.com>
2022-03-29 12:07:20 -04:00
Flavio Ceolin
3f958347c2 test: pm: device: Fix build options
The test is using device and device runtime power management. Just
including them to the test build.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-03-29 18:04:54 +02:00
Flavio Ceolin
041653662b pm: Remove unused fields in pm_device
Several fields on struct pm_device are just necessary when
built with PM_DEVICE_RUNTIME.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-03-29 18:04:54 +02:00
Evgeniy Paltsev
6da71d7c2f ARC: nSIM: fix missing core numbers for mdb-hw runner args
We don't set core numbers for mdb-hw runner for nSIM
board, so it defaults to 1, so mdb-hw runner doesn't work with
SMP boards.

Fix that.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2022-03-23 05:58:54 -04:00
Robert Lubos
52a68bec73 net: tcp: Verify accept callback before use
Closing a listening socket will set the accept callback to NULL.
This could lead to a crash, in case an already received packet,
finalizing the connection handshake, was processed after the socket was
closed. Thereby, it's needed to verify if the callback is actually set
before processing it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-22 20:17:36 -04:00
Robert Lubos
6324e997e1 net: sockets: Fix userspace accept() verification
The verification function for accept() did not take into account that
addr and addrlen pointers provided could be NULL.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-22 20:17:36 -04:00
Yong Cong Sin
e9eed0015f subsys/mgmt/hawkbit: update http response handling
Following the merge of #42646, the http body handling can be simplified.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-22 20:13:09 -04:00
Jordan Yates
a3e7047ad5 wifi: esp_at: claim net_context in rx
Claim the net_context mutext associated with a socket before claiming
the socket mutex. The receive callback claims the net_context mutex
internally, which will now always succeed immediately.

The TX path claims the net_context mutex before the socket mutex, and if
we don't use the same order, we can end up in a deadlock.

Fixes #43470.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-03-22 20:12:42 -04:00
Robert Lubos
50a24d6782 net: sockets: Retry net_context_sendmsg if EAGAIN is reported
TCP module can report EAGAIN in case TX window is full. This should not
be forwarded to the application, as blocking socket is not supposed to
return EAGAIN.

Fix this for sendmsg by implementing the same mechanism for handling TX
errors as for regular send/sendto operations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-22 20:08:35 -04:00
Szymon Janc
9c3be1212f tests/bluetooth/tester: Enable security validation for GATT subsciption
This was affecting following qualification test cases:
GAP/SEC/SEM/BV-56-C
GAP/SEC/SEM/BV-57-C
GAP/SEC/SEM/BV-58-C
GAP/SEC/SEM/BV-59-C
GAP/SEC/SEM/BV-60-C
GAP/SEC/SEM/BV-61-C

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-22 20:08:06 -04:00
Szymon Janc
e2c96814ce Bluetooth: Host: Validate security on GATT subscription
Core Specification 5.3 clarified security requirements for GATT client
when handling incoming notifications and indications.

Vol 3: Part C: 10.3.2.2:
"...Since the configuration is persistent across a disconnection and
reconnection, the client shall check the security requirements against
the configuration upon a reconnection before processing any indications
or notifications from the server. Any notifications received before
the security requirements are met shall be ignored. Any indications
received before the security requirements are met shall be confirmed
and then discarded. ..."

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-22 20:08:06 -04:00
Andrzej Głąbek
3c64ed4e77 drivers: spi_nrfx_spi: Fix compilation error
Fix a copy/paste mistake introduced by commit
fdc25cd44c.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2022-03-22 17:06:09 +01:00
Jordan Yates
e78a6ab2cd spi: nrfx_spi*: only run uninit if configured
Only run the `uninit` function if the SPI instance has previously been
configured. This stops an assertion in the HAL drivers from triggering
due to running `uninit` without a previous `init`.

Fixes #42299.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-03-22 17:06:09 +01:00
Piotr Pryga
6bbf1e7e7a Bluetooth: controller: Add missing NULL assign to df_cfg in ll_adv_set
ll_adv_set stores poitner to direction finding TX configuration.
When ll_reset is executed the pointer was not NULL assigned.
That lead to erroneous behavior e.g. df_cfg->is_enabled was set
to TRUE even the functionality was not enabled.
DF configuration is stored in memory pool. The memory pool uses
free elements to store its internal data. On reset whole pool is
expected to be free, so ll_adv_set->df_cfg may not point to any
element allocated from memory pool.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-03-17 13:19:53 +01:00
Tomasz Bursztyka
063dbecb23 arch/x86: Fix MSI MAP destination
When Zephyr runs directly on actual hardware, it will be always
directing MSI messages to BSP (BootStrap Processor). This was fine until
Zephyr could be ran on virtualizor that may NOT run it on BSP.

So directing MSI messages on current processor. If Zephyr runs on actual
hardware, it will be BSP since such setup is always made at boot time by
the BSP. On other use case it will be whatever is relevant at that time.

Fixes #43853

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-03-16 11:45:25 -04:00
Tomasz Bursztyka
a807fff085 arch/x86: Add a CPUID function to get initial APIC ID
Depending on whether X2APIC is enabled or not, it will be safer to grab
such ID from the right place.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-03-16 11:45:25 -04:00
Tomasz Bursztyka
b4b474cb4b arch/x86: Have a dedicated place for CPUID related functions
This will centralize CPUID related accessors. There was no need for it
so far, but this is going to change.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-03-16 11:45:25 -04:00
Szymon Janc
175ae83c78 tests/bluetooth/tester: Allocate L2CAP channel only when needed
This fix leaking channels when autorization or key size are tested.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-16 11:07:30 -04:00
Szymon Janc
22ab715ad8 test/bluetooth/tester: Don't clear auth requirements on L2CAP server
We have single server but it can accept multiple connections so
keep same requirements for all connection attempts.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-16 11:07:30 -04:00
Szymon Janc
dff6cf2694 tests/bluetooth/tester: Add support for multiple GATT subscriptions
This is required by GATT/CL/GAI/BI-01-C qualification test.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-16 11:07:09 -04:00
Szymon Janc
d4a1231cd4 tests/bluetooth/tester: Fix possible buffer overflow
Make sure we have enough space for notification data.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-16 11:07:09 -04:00
Szymon Janc
88249c470e tests/bluetooth/tester: Add support for rejecting connection parameters
This is required for GAP/CONN/CPUP/BV-05-C qualification test.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-16 11:06:43 -04:00
Carlo Caione
265cd286f2 gen_relocate_app: Create files from scratch, do not append
The problem with append is that when doing incremental (non-clean)
build, the content of these files are appended each time to the previous
leftover content.

Example:

 # west build -p -b qemu_cortex_m3 \
 	samples/application_development/code_relocation/

 #   // disable for example CONFIG_XIP

 # west build -b qemu_cortex_m3 \
        samples/application_development/code_relocation/

at this point the content of the generated files (i.e.
linker_relocate.ld) is wrong.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-03-16 10:38:09 +01:00
Krzysztof Chruscinski
4bc2808291 lib: os: mpsc_pbuf: Add const to mpsc_pbuf_free argument
Added const qualifier to argument in a function.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-15 20:28:31 -04:00
Francois Ramu
feb1630492 dts: arm: stm32l0 LSI clock freq is 37kHz
Corrects the LSI clock freq for stm32l0x mcus
especially stm32l0x1 stm32l0x2 stm32l0x3 series

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-03-15 20:27:14 -04:00
Chen Peng1
59a491efd6 cmake: save eh_frame section in output with CONFIG_EXCEPTIONS.
.eh_frame section should not be removed directly in the
hex format and bin format output, it should be based on
whether we need exception handler feature.

Signed-off-by: Chen Peng1 <peng1.chen@intel.com>
2022-03-15 20:27:00 -04:00
Rene Bredlau
51e7ee4711 modem: hl7800: use correct timeouts on KTCPSND to avoid internal deadlock
The response of a KTCPSND has two phases. According to documentation by
wireless the timeout is 60 seconds. The fix respects the timeout on the
second phase, too (waiting for OK or errors from modem). Previously only
the first phase used 60 seconds and the second phase used 5 seconds.

Without this fix the hl7800 will lock the tcp stack for the current
socket indefinitely if another socket operation is performed before the
response from the modem is received.

Additionally all timeouts are adjusted to be at least one second longer
as the documented timeout from wireless. This avoids races between the
hl7800 and the driver.

Signed-off-by: Rene Bredlau <git@unrelated.de>
2022-03-15 20:22:56 -04:00
Johann Fischer
5883e897ba usb: bluetooth: check buffer tailroom before copying
If HCI packet length is greater than endpoint MPS or currently
received data block (over USB), next block could be larger
than allocated net_buf buffer.

Check buffer tailroom before copying data using net_buf_add_mem().

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-03-08 12:30:24 -05:00
Johann Fischer
20899f9f7e bluetooth: hci_raw: avoid possible memory overflow in bt_buf_get_tx()
Function bt_buf_get_tx(), which is used to allocate buffer from
fixed-size pool, does not check size argument before copying
the data with the length size into fixed-size buffer, wich may
not be large enough.

Check immediately before copying if the tailroom of the buffer
is large enough.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-03-08 12:30:24 -05:00
Christopher Friedt
3e41a7810d tests: pthread: cond: check return from pthread_cond_wait()
The expectation is that this call succeeeds in order for
the test to pass.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2022-03-08 11:46:56 -05:00
Christopher Friedt
de5fc723eb pthread: cond: fix pthread_cond_wait always returning ETIMEDOUT
It was noted that `pthread_cond_wait()` would always return
ETIMEDOUT, even when successful (and no timeout should ever
occur with `K_FOREVER`).

The z_sched_wake() / z_sched_wake_all() / z_sched_wait() API
are used here with a swap return value of 0 to indicate
success.

Fixes #41284

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2022-03-08 11:46:56 -05:00
Gerard Marull-Paretas
6fa562e805 ci: split Bluetooth workflow
Split Bluetooth tests workflow into 2 steps:

- One that runs the actual tests and stored results
- A second one that fecthes and uploads tests results

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-08 11:16:09 -05:00
Gerard Marull-Paretas
df7a1f3cf6 ci: make git credentials non-persistent
With this setting enabled, Git credentials are not kept after checkout.
Credentials are not necessary after the checkout step since we do not
do any further manual push/pull operations.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-08 11:15:38 -05:00
Georgij Cernysiov
798cca3d61 include: drivers: clock_control: stm32: fix xtpre
Correct DT property to set correct STM32_PLL_XTPRE value.
The driver bindings defined `xtpre` instead of used `xtre`
in the `DT_PROP` macro.
That allows to use F1 PLL clock with division by 2.

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2022-03-02 09:52:56 -05:00
Andrea Campanella
58b8290163 drivers: serial: stm32: Add Line Break Detection
The current driver doesn't handle the LBD flag, this leads
uart_stm32_err_check to return always true if a Line Break
is detected.

This PR adds Line Break Detection and the related flag clearing,
F0 series it's excluded from the changes.

Fixes zephyrproject-rtos#41339

Signed-off-by: Andrea Campanella <andrea.campanella@helvar.com>
2022-03-02 09:26:14 -05:00
Thomas Stranger
9c6ed8ff95 tests: drivers: flash: change integration_platforms
drivers.flash.nrf_qspi_nor and drivers.flash.soc_flash_nrf:
keep nrf52840dk_nrf52840 as integration_platform

drivers.flash.default:
Use mimxrt1060_evk instead as integration_platform,
this is the only platform allowed.

drivers.flash.stm32:
Add a bunch of boards as integration_platforms for
this test configuration.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-03-02 09:23:36 -05:00
Thomas Stranger
fcf027ef93 drivers: flash: stm32g0: dual bank handling
This commit fixes dual bank flash handling on stm32g0 targets.
In contrast to other Series (G4, L5) the flash page size does not change
in single bank configuration (2KiB in both configurations).

nSWAP_BANK:
While the reference manual(RM) only documents:
"This bit selects the bank that is the subject of empty check upon boot"
as expected, this behaves similar to BFB2 on G4 and SWAP_BANK on L5.
It has been observed that this bit swaps the address mapping of bank1
and bank2, regardless of DUAL_BANK bit being set or not.
As documented in the RM the nSWAP_BANK bit is ignored when the BOOT_LOOK
bit is set. This applies to the empty check as well as the address
mapping.

On this Series FLASH_CR_BKER must be set in single-bank as well as
dual-bank configuration for erase operations on bank2 regardless of
the swap status.

On a G0B1RE (dev-id: 0x467) I could not observe a difference between
DUAL_BANK flash option bit set and not.
It this may be different on 256KiB Flash targets.
The HAL indicates that "FLASH_SALES_TYPE_0" only uses a single bank if
OB_DUAL_BANK_VALUE is not set, but as I don't know which SoC this is
and I can't test the behaviour and the driver does not take this into
account.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-03-02 09:23:36 -05:00
Thomas Stranger
d8ad569d33 drivers: flash: stm32g0: preparation for dual bank handling
This commit makes no functional changes, it only refactors the
driver such that dual bank flash handling can be easily added.

Instead of using HAL macros directly in the code, new macros
with STM32G0 prefix are defined.
The erase_page function gets passed the offset instead of the page,
and the FLASH CR reg is written once with all erase parameters.
flash_stm32_wait_flash_idle is already called before each
write to CR, consequently it is also made sure CFGBSY flag
is not set.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-03-02 09:23:36 -05:00
Thomas Stranger
a04de78971 drivers: flash: stm32: wait for CFGBSY & BSY2 in wait_flash_idle
Some series (namely g0, u5, wb, wl, ?) use CFGBSY to indicate
that FLASH_CR is not ready to be modfied.

This commit adds this flag additionally to other the flash busy flags,
in flash_stm32_wait_flash_idle such that the driver waits before
trying to modify PG, PNB[6:0], PER, and MER bits in FLASH_CR.

Additionally, dual bank variants of STM32G0 have a seperarate BSY2 flag
for flash bank two.
Until now this was not yet checked in flash_stm32_wait_flash_idle.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-03-02 09:23:36 -05:00
Thomas Stranger
9b1dfd6568 flash: stm32: fix g0 error flags and move ifdef-ery to header
In STM32G0 HAL FLASH_FLAG_xxx defines don't follow the pattern of
other Series to simply redefine the FLASH_SR_xxx Msk.
Instead an ID for the SR reg and the position of the Error flag
are defined.

As a result error checking in flash_stm32_check_status was not working
until this fix on stm32g0 series.

In order to avoid complexity in the driver, the ifdef-ery of the flags
was moved to the header file.
Other series except g0 use FLASH_FLAG_xxx defines, because those
are valid for both cores in dual core(wl) and in secure/non-secure
targets(l5,u5).
FLASH_STM32_SR_ERRORS mask is introduced to check for any active error
in the SR.

The flags for SIZERR, MISERR, FASTERR are newly introduced.
the latter two are only required once fast programming is used,
which is not yet the case for any series.

The FLASH_SR_OPTVERR flag (option validity flag) is also present
in the SR, but is not added.
Also ecc errors are generally not checked, but these are in a different
register.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-03-02 09:23:36 -05:00
Thomas Stranger
c2898af367 drivers: flash: stm32: mv security-mode dependent defines to header
An attempt to simplify the ifdef-ery around FLASH_SR is made.
Define Registers and flags in the header file instead of including
several individual operations in the driver.

FLASH_FLAG_BSY is not only defined for STM32L5, but also other series.
Therefore use this flag instead of FLASH_SR_BSY.
Only the g0 series definition is not valid in our context,
therefore use FLASH_SR_BSY1 instead.

No functional changes, only refactoring.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-03-02 09:23:36 -05:00
Yong Cong Sin
5933705d0c driver: serial: uart_stm32: Calculate suitable PRESCALER value
Current driver set a fixed prescaler value for the lpuart
that caused certain baudrate configurations to fail due to
LPUARTDIV overflow the LPUART_BRR register.

This PR attempt to calculate a suitable PRESCALER for the
selected baudrate, throws error and return if it couldn't get
an optimal one.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-02 09:23:25 -05:00
Julien D'ascenzio
f77cb92075 drivers/uart: stm32: don't call k_yield on poll_out
Some tests like:
    tests/kernel/sched/metairq/kernel.scheduler.metairq
    tests/kernel/profiling/profiling_api/kernel.common.profiling
    tests/kernel/sched/schedule_api/kernel.scheduler
    tests/kernel/sched/schedule_api/kernel.scheduler.multiq
    tests/kernel/profiling/profiling_api/kernel.common.profiling
    tests/kernel/workq/work_queue/kernel.workqueue

don't support that the current thread change when writing a message with
printk (which uses poll_out). So, we remove the call to k_yield which is
useful only for optimizing cpu usage by forcing a thread change if the
usart send stack is full.

Signed-off-by: Julien D'ascenzio <julien.dascenzio@paratronic.fr>
2022-03-02 09:22:57 -05:00
Julien D'ascenzio
d340ff111f drivers/uart: stm32: fix dead lock on poll_out
A dead lock could happen if 2 threads with differents priorities use
poll_out. In fact, the lock data->tx_lock could be lock by a thread with
lower priority and then a thread with higher priority can't take the
lock. There was a race condition here:

/* Wait for TXE flag to be raised */
while (1) {
	if (atomic_cas(&data->tx_lock, 0, 1)) {
		/* !!!!!!!! RACE CONDITION !!!!!!!!!!!!!!
		if (LL_USART_IsActiveFlag_TXE(UartInstance)) {
			break;
		}
		atomic_set(&data->tx_lock, 0);
	}
}

To fix race condition, the interrupts are locked in poll_out.

Signed-off-by: Julien D'ascenzio <julien.dascenzio@paratronic.fr>
2022-03-02 09:22:57 -05:00
Julien D'ascenzio
c9b24cf07d uart_stm32: Fix conflit between poll_out and irq API
A lock was added to manage situation where the API poll_out and irq API
are used in same time.

Signed-off-by: Julien D'ascenzio <julien.dascenzio@paratronic.fr>
2022-03-02 09:22:57 -05:00
Kweh Hock Leong
1c71036236 net: shell: Fix parser error on net ping command
The strtol() function use errno to return error code.
However, it is not being initialized in the parser_arg()
function before calling the strtol(). Thus, hitting error
when performing net ping command with -c / -i parameters.

Signed-off-by: Kweh Hock Leong <hock.leong.kweh@intel.com>
2022-03-02 07:34:24 -05:00
Chris Reed
fe53adec8e arm: cortex-m: initialise ptr_esf in get_esf() in fault.c.
This was producing a -Wsometimes-uninitialized warning.

Signed-off-by: Chris Reed <chris.reed@arm.com>
2022-03-02 07:33:24 -05:00
Robert Lubos
9b3a68b7d5 net: mqtt: Fix SOCKS5 setsockopt error handling
Transports should close the socket in case of `setsockopt()` failure,
otherwise we end up with a leaked socket, as it won't be closed
elsewhere.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-02 07:32:29 -05:00
Robert Lubos
8546159275 net: arp: Fix ARP retransmission source address selection
There was a problem with source address selection for ARP
retransmissions, when an ARP entry was already pending. In such case,
the `entry` value passed to `arp_prepare()` is NULL, which in result
caused the `current_ip` variable being used as the source value. The
problem with this approach is, that the `current_ip` is only set in
IPv4 autoconf, the Ethernet L2 does not set this variable. In result,
every retransmission of an ARP packet was sent with unspecified source
address, preventing the response from being handled.

Fix this by partially restoring the behaviour of the ARP source address
assignment from before IPv4 autoconf was introduced. If the ARP is sent
by the IPv4 autoconf, use the `current_ip` value provided. If entry is
not set, use the source IPv4 address set in the actual data packet.
Otherwise, search for a source address on the interface corresponding to
the `entry`.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-02 07:12:37 -05:00
Daniel Nejezchleb
49f35f3a00 net: sockets: Fixes net_pkt leak in accept
Fix net_pkt leak by increasing net_context the reference count earlier
in the zsock_accepted_cb() with instalment of the
zsock_received_cb() callback.

And consequently flushing recv_q and decrement net_context
reference count if zsock_accept_ctx() fails.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2022-03-02 07:12:28 -05:00
Daniel Nejezchleb
13571c4155 lib/os: fdtable: add locking to posix api
Added locking to posix read(), write(), close()
for additional protection.

In read() missing lock would create uneven calls to locking
mechanism in sockets.c after k_condvar_wait().
That results in socket lock not ever being unlocked

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2022-03-02 07:12:17 -05:00
Daniel Nejezchleb
14d87fcb63 net: tcp: Fix possible deadlock in tcp_conn_unref()
This reverts commit e7489d8de7.

And fixes the deadlock by allowing only 1 thread to actualy clean up
the connection when the ref_count is 0.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2022-03-02 07:12:17 -05:00
Daniel Nejezchleb
f7f21cbc5f net: tcp: Fixed forever loop in tcp_resend_data
Increments send retry every time
after the tcp_send_data when resending.
That way unhandled return values can time
out after set amount of tcp_retries.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2022-03-02 07:12:09 -05:00
Krzysztof Chruscinski
98e79516bd net: ip: route: Fix log_strdup misuse
Log_strdup was used in NET_ASSERT macro which is not logging.
As a result linking fails when logging is disabled but asserts
are enabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-02 07:11:51 -05:00
Tomasz Bursztyka
ad2d8fea73 net/icmpv4: Do not send error on a packet that was broadcasted
For instance, DHCP (UDP protocol) can send broadcasted packet and if we
no not serve the requested destination port, let's not send an error
back.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-03-02 07:11:34 -05:00
Tomasz Bursztyka
24b30abc65 net/icmpv4: Fix logging messagse
Invert src/dst strings, the icmpv4 error is sent from the dst (us) to
src (sender of the ipv4 packet that generated the error).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2022-03-02 07:11:34 -05:00
Ryan McClelland
c9f11ff697 cmake: fix multiple shield parsing
When multiple shields are defined, only the shield last in the -DSHIELD
list gets defined in `.config`. This is due to too many backslashes
used defining it for an env setting.

Signed-off-by: Ryan McClelland <ryanmcclelland@fb.com>
2022-03-02 07:11:23 -05:00
Binu Jacob
d52b43826e libc: newlibc: Fix recursive gettimeofday() calls on non-Posix systems
Calling gettimeofday() from _gettimeofday() in a non-Posix build
environment can result in a recursive call loop, causing a stack
overflow. Modify _gettimeofday() to return -1 for non-posix systems
(the previous behaviour that was added in #22508).

Fixes #41095

Signed-off-by: Binu Jacob <bjj@planetinnovation.com.au>
2022-03-02 07:11:08 -05:00
Szymon Janc
7cdc791b51 Bluetooth: L2CAP: Fix checking if LTK is present
This fix a typo where incorrect member of bt_keys was used for
checking if LTK is present. This was resulting in bogus results
depending on connection role and current identity used.

This was affecting L2CAP/LE/CFC/BV-25-C qualification test case.

Fixes: #42862

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-03-02 07:09:41 -05:00
Keith Packard
6a8023a18c arm: Use correct macro for z_interrupt_stacks declaration in stack.h
There are two macros for declaring stack arrays:

K_KERNEL_STACK_ARRAY_DEFINE:

	Defines the array, allocating storage and setting the section name

K_KERNEL_STACK_ARRAY_EXTERN

	Declares the name of a stack array allowing code to reference
	the array which must be defined elsewhere

arch/arm/include/aarch32/cortex_m/stack.h was mis-using
K_KERNEL_STACK_ARRAY_DEFINE to declare z_interrupt_stacks by sticking
'extern' in front of the macro use. However, when this macro also set
the object file section for the symbol, having two of those caused a
conflict in the compiler due to the automatic unique name mechanism used
for sections to allow unused symbols to be discarded during linking.

This patch makes the header use the correct macro.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-03-02 07:09:26 -05:00
Michel Haber
229f0e259f timing: use runtime cycles for cortex-m systick
Use sys_clock_hw_cycles_per_sec() instead of
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC to determine clock cycles.

Signed-off-by: Michel Haber <michel-haber@hotmail.com>
2022-03-02 07:06:40 -05:00
Alexander Mihajlovic
6f6a77a492 drivers: adc: stm32: Clear ADRDY before waiting
Clear ADRDY before enabling ADC to ensure the subsequent
wait for ADRDY does not stop prematurely in case ADRDY
was already set.

The "ADC on-off control" sections of the following reference manuals
were consulted. That gives at least one instance per series affected
by this change, even if not every affected MCU is covered.

- RM0438 (STM32L552xx and STM32L562xx)
- RM0351 (STM32L47xxx, STM32L48xxx, STM32L49xxx and STM32L4Axxx)
- RM0434 (STM32WB55xx and STM32WB35xx)
- RM0454 (STM32G0x0)
- RM0440 (STM32G4 Series)
- RM0399 (STM32H745/755 and STM32H747/757)
- RM0433 (STM32H742, STM32H743/753 and STM32H750)
- RM0453 (STM32WL5x)

Signed-off-by: Alexander Mihajlovic <a@abxy.se>
2022-03-02 03:53:20 -05:00
Alexander Mihajlovic
bdbab499b5 drivers: adc: stm32: Add function to enable ADC consistently
Use a wrapper for LL_ADC_Enable that also waits for ADRDY if required
by the SoC to make sure it's properly enabled everywhere this is done.

Signed-off-by: Alexander Mihajlovic <a@abxy.se>
2022-03-02 03:53:20 -05:00
Francois Ramu
532806e063 drivers: adc: driver setting the oversampling for stm32wl
RM 0453: the sw is allowed to write the Oversampling
ratio or shift of the ADC Config.Reg.2 only when ADSTART = 0
(no conversion is on-going). So disabling it will be stopped.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-03-02 03:53:20 -05:00
Francois Ramu
aecbdb7285 drivers: adc: driver setting the resolution for stm32wl
RM 0453: the sw is allowed to write the Data Resolution bits
of the ADC Config.Reg.1 only when ADEN = 0 (ADC disable).

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-03-02 03:53:20 -05:00
Pete Dietl
8369a0a3eb drivers: adc: stm32: Disable ADC before calibration
The STM32 docs state that the ADC may not be calibrated unless
the ADC is disabled (ADEN=0). This commit implements this constraint

Fixes #40936

Signed-off-by: Pete Dietl <petedietl@gmail.com>
2022-03-02 03:53:20 -05:00
Robert Lubos
73d79674d7 net: sockets: tls: Fix ZSOCK_POLLHUP detection
The previous approach to detect if the underlying transport was closed
(by checking the return value of `mbedtls_ssl_read()` was not right,
since the function call does not request any data - therefore 0 as a
return value is perfectly fine.

Instead, rely on the underlying transport ZSOCK_POLLHUP event - if it
reports that the connection ended, forward the event to the application.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-24 11:22:18 -05:00
Robert Lubos
7654997990 net: sockets: Report ZSOCK_POLLHUP when socket is in EOF state
Report ZSOCK_POLLHUP event if peer closed the connection, and thus the
socket is in EOF state.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-24 11:22:18 -05:00
Krzysztof Chruscinski
cf58352c22 logging: Fix counting of buffered messages
When message is dropped then log_process is called with
bypass flag set and additionally z_log_dropped() is called.
In both functions counter of buffered messages was decremented.
That resulted in counter being decremented twice. It resulted
in logging misbehavior after messages being dropped (delayed
processing). Fixing it by decrementing the counter in log_process
only when bypass flag is not set.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-24 11:21:16 -05:00
Krzysztof Chruscinski
a618d6ff81 logging: Improve algorithm for waking up the thread
Use value returned by atomic_inc to decide on action.
Previously direct value was used and that could lead to
delays in logging processing because thread waking up
could be mishandled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-24 11:21:16 -05:00
Guillaume Lager
02275d8013 drivers: console: gsm_mux: fix length indicator
The MSB and LSB were inverted for length > 127
Fixes #41077

Signed-off-by: Guillaume Lager <g.lager@innoseis.com>
2022-02-24 11:20:30 -05:00
Yong Cong Sin
3d61857d2f kernel: workq: Fix type errors in delayable work handlers
A common pattern here was to take the work item as the subfield of a
containing object. But the contained field is not a k_work, it's a
k_work_delayable.

Things were working only because the work field was first, so the
pointers had the same value. Do things right and fix things to
produce correct code if/when that field ever moves within delayable.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-24 11:19:15 -05:00
Robert Lubos
0d70ee6017 net: sockets: Use struct timeval provided by libc
Instead of redefining own `struct zsock_timeval` type at the socket
layer, use a standard type provided by libc. This prevents the
compliation errors when application includes both, `net/socket.h` and
standard C header defining `struct timeval` (sys/time.h).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-24 11:18:52 -05:00
Robert Lubos
43e116e496 net: route: Verify if neighbor entry is in use when iterating
Verify the `ref` value of the neighbor entry in `net_route_foreach()`,
so that it only executes the callback on routes in use. Otherwise, the
function could call the callback for the route that has already been
deleted.

This could be encountered when executing `net route` shell command,
which printed the already deleted routes along the existing ones.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-24 11:18:22 -05:00
Robert Lubos
d4d569b334 net: route: Fix struct net_route_nexthop leak
When new route is allocated, a corresponding NBR entry (containing
`struct net_route_nexthop` data) is allocated from
`net_route_nexthop_pool`. When the route was deleted however, the entry
was not freed - only the "core" neighbor entry from the neighbor
management module (nbr.c) was dereferenced. This lead to a resource
leak, effecitevly leaking one `net_route_nexthop_pool` entry for each
deleted route.

Fix this, by defreferencing the NBR entry corresponding to the `struct
net_route_nexthop` data of the deleted route when route is removed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-24 11:18:22 -05:00
Robert Lubos
c4bb210f4a net: sockets: Simplify common getsockname() implementation
Simplify common `getsockname()` implementation by using VTABLE_CALL()
macro, in the same way as other socket calls do. This additionally
allows to cover the case, when `getsockname()` is not implemnented by
particular socket implementation, preventing the crash.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-24 11:17:48 -05:00
Andrei Emeltchenko
8f24184e1b net: tcp: Remove unneeded declaration
Remove unneeded declaration and change include logic.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-02-24 11:17:29 -05:00
Andrei Emeltchenko
728ed5e4a6 net: tcp: Remove redundant TCP option definitions
Use the same TCP option definitions.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-02-24 11:17:29 -05:00
Jukka Rissanen
203ec2a124 net: tcp2: Send our MSS to peer
Send our MSS to peer when sending SYN or SYN-ACK.

Fixes #30367

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2022-02-24 11:17:29 -05:00
Marius Scholtz
e34b8d5b58 modbus: serial: Fix incomplete transmission issue
This patch is to fix an issue where the transceiver chip is
disabled before it has transmitted all data. This causes the
message to be corrupted because the last few bytes are missing.

The fix adds a check to make sure the transmission is completed
before disabling the transceiver.

Signed-off-by: Marius Scholtz <mariuss@ricelectronics.com>
2022-02-24 11:16:51 -05:00
Guillaume Lager
f7358ea85a driver: modem: Fix mux device name comparison
CONFIG_UART_MUX_DEVICE_NAME is used as a prefix for the uart muxes
name. Pointer comparison will always return false

Fix #39774

Signed-off-by: Guillaume Lager <g.lager@innoseis.com>
2022-02-24 11:15:43 -05:00
Robert Lubos
1d61b94eb2 net: sockets: getaddrinfo: Fix possible crash when callback is delayed
In case system workqueue processing is delayed for any reason, and
resolver callback is executed after getaddrinfo() call already timed
out, the system would crash as the callback makes use of the user data
allocated on the stack within getaddrinfo() function.

Prevent that, by cancelling the DNS request explicitly from the
getaddrinfo() context, therefore preventing the resolver callback
from being executed after the getaddrinfo() call ends.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-24 11:15:20 -05:00
Robert Lubos
8bc6f2cf34 net: http_client: Set body_start pointer unconditionally
Set `body_start` pointer regardless of the body position in the recv
buffer. In result, the pointer shall indicate correctly position of the
body for each fragment, it's also explicit now that if the pointer is
not set for a fragment, there's no body in that particular fragment.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-24 11:14:40 -05:00
Yong Cong Sin
1a7fc79c75 net: mgmt: Use mutex for net_mgmt_lock
Conceptually the net_mgmt_lock should be a mutex instead of a
semaphore. It is easier to identify the owner of a mutex and
debug when deadlock happens, so convert it.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-23 10:59:43 -05:00
Sylvio Alves
b805164907 soc: esp32: use PYTHON_EXECUTABLE from build system
ESP32 build is failing after f-string is added into python
files. This sets esp32 build to use Zephyr's build system python
version.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2022-02-22 10:28:20 +01:00
Vinayak Kariappa Chettimada
54dc715b8d Bluetooth: Controller: Fix Periodic Adv EVENT_OVERHEAD_START_US jitter
As EVENT_OVERHEAD_START_US offset is used in ticks unit in
LLL, ULL scheduling using ticker should also use ticks unit
for EVENT_OVERHEAD_START_US when reducing the first Periodic
Advertising event preparation.

Relates to commit 858dc7fab4 ("Bluetooth: controller: Fix
EVENT_OVERHEAD_START_US jitter").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-02-09 13:26:36 +01:00
Christopher Friedt
96cfb7ac9f doc: spinlock: ensure spinlock api is added to doxygen
Previously, `k_spin_lock()` and friends had broken links
in html docs.

Fixes #42373

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2022-02-09 06:28:50 -05:00
Krzysztof Chruscinski
8a1d3a0a40 tests: logging: log_api: Add test for LOG_PRINTK
Added test that validates CONFIG_LOG_PRINTK option where
printk is redirected to logging.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-09 06:26:13 -05:00
Krzysztof Chruscinski
533d284bd3 tests: logging: log_core_additional: Add panic handler for test backend
Backend implemented in the test did not implemented panic
function and test crashed when log_panic was used.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-09 06:26:13 -05:00
Krzysztof Chruscinski
5b690c698e logging: log_output: Fix immediate output for big endian
Pointer to int was passed to a function which expected pointer to
uint8_t. There was an unexpected content for big endian as the
highest byte was read instead of the lowest which contained valid char.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-09 06:26:13 -05:00
Krzysztof Chruscinski
139f200992 logging: printk: Fix LOG_PRINTK for v2
Fixed a dependency from printk.h to logging headers which in
certain configurations could lead to circular dependencies.
Cleaned up printk.c to call z_log_vprintk from vprintk.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-09 06:26:13 -05:00
Krzysztof Chruscinski
753b1d7f23 lib: os: printk: Minor refactoring
Refactoring to remove code redundancy caused by splitted
handling based on USERSPACE enabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-09 06:26:13 -05:00
Jordan Yates
f51223b449 doc: guides: index: document Doxygen linking
Document the existance of `zephyr.tag` by providing a link on the main
documentation guide page. Also include an example of how to use this
file in an external project.

Implements #41529.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-02-09 06:24:23 -05:00
Jordan Yates
2cf6ae69fc doc: generate Doxygen tag file
Generate the Doxygen tag file to static html sources directory so that
external documentation can use it as a source for linking. See:
    https://www.doxygen.nl/manual/external.html

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-02-09 06:24:23 -05:00
Gerard Marull-Paretas
13dfae7410 doc: conf: specify which variable is used for output directory
This is needed so that it can be re-used by other Doxygen configuration
entries.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-02-09 06:24:23 -05:00
Gerard Marull-Paretas
262497f3a8 doc: extensions: doxyrunner: do not modify extension config
After the introduction of #41688, doxyrunner extension modifies the
fmt_vars content (from a variable defined in `conf.py`) when the output
directory variable is defined. This means that Sphinx will always get an
outdated environment and so will always perform a full build instead of
an incremental build. This patch makes a copy first to prevent this
situation.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-02-09 06:24:23 -05:00
Gerard Marull-Paretas
4bde9471c9 doc: extensions: doxyrunner: add doxyrunner_outdir_var option
The doxyrunner_outdir_var option allows to specify which variable (if
any) is used to represent the output directory (as used by
OUTPUT_DIRECTORY). This makes sure that other options referencing it are
processed correctly, since the output directory is not passed as a
variable.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-02-09 06:24:23 -05:00
Jordan Yates
17c54a0072 lora: sx126x: don't re-enable interrupt in sleep
Don't re-enable the DIO1 interrupt when the modem is in sleep mode. This
fixes the power regression introduced in Zephyr v2.7.0 #41026.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-02-09 06:23:10 -05:00
Jeremy Wood
3ebd567041 drivers: can: m_can: fix reconfiguring bitrate
Set enable configuration change bit in can_mcan_set_timing() because
the NBTP register can only be changed if we're in init mode AND
configuration change bit is set, per MCU docs.

Signed-off-by: Jeremy Wood <jeremy@bcdevices.com>
2022-02-08 12:11:41 -05:00
Krzysztof Chruscinski
822b82faf0 logging: Fix tracking of buffered messages
Algorithm was failing in case when overflow mode was enabled
but allocation of new message failed. It could happen if message
size exceeded buffer size. Losing track of buffered messages
can lead to logging processing freeze.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-08 12:10:45 -05:00
Krzysztof Chruscinski
750b212ac8 logging: Fix tracking of active messages
A variable is tracking number of buffered messages. This is used
to trigger processing thread in certain cases. Counter was not
handled correctly when message was dropped. In certain cases that
can lead to hanging of log processing.

Added counter decrementation in the callback called whenever
message is dropped.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-08 12:10:45 -05:00
Erwan Gouriou
1903793c89 boards: h747/h745: Update dual core flash and debug instructions
Review flashing and debugging instructions on these dual core boards.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-02-02 16:02:18 -05:00
Emil Lindqvist
8f539523b6 logging: fix timestamp func overwrite on log2
When LOG2 is enabled, timestamp func which was just set
according to various conditions, is overwritten using sysclock.
Since sysclock is very fast, it will cause uint32_t to wrap very
fast and cause the time to start over from 0 often.

This commit combines the two statements doing the same thing,
to one statement.

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2022-01-26 07:22:42 -05:00
NingX Zhao
22fc985376 poll: modify the function z_vrfy_k_poll
Removing the 'U' to avoid the type of num_events changed.
And make sure it is meaningful Z_SYSCALL_VERIFY micro.

Fixed #40614

Signed-off-by: NingX Zhao <ningx.zhao@intel.com>
2022-01-25 14:05:49 -05:00
Carlo Caione
3cb83d1bbe kernel: Reset the switch_handler only in the arch code
Avoid setting the switch_handler in the z_get_next_switch_handle() code
when the context is not fully saved yet to avoid a race against other
cores waiting on wait_for_switch().

See issue #40795 and discussion in #41840

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-01-25 10:52:54 -05:00
Johann Fischer
e23cd666c3 drivers: ssd16xx: fix driver initialization
ssd16xx driver is not well designed and does not pass configuration
via device->config but via struct ssd16xx_data, this was not taken
into account in the commit 4d6d50e2bc
("display: ssd16xx: convert to spi_dt_spec").

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-01-15 12:28:25 -05:00
Johann Fischer
1630dac971 include: usb: add alignment attribute to macro USBD_CFG_DATA_DEFINE
It could be observed on native_posix_64 platform that
without alignment attribute the usb_cfg_data structures
are placed with a gap or padding in specified RAM section.
This breaks the possibility to iterate over the structures.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-01-15 12:28:15 -05:00
Patric Karlström
f21e74cb07 posix: Make clock_settime/gettime REALTIME thread-safe
Fixes #23419

Signed-off-by: Patric Karlström <pakar@imperialnet.org>
2022-01-15 12:27:47 -05:00
Gerson Fernando Budke
dfb5ef29ef riscv: linker.ld: Fix undefined reference linker error
The commit a28830b aligned the data and rename some symbols.  However
there are two symbols at riscv linker script that were missing, which
causes below linker error:

kernel/xip.c:28: undefined reference to `__itcm_load_start'
kernel/xip.c:43: undefined reference to `__dtcm_data_load_start'

Rename below symbols to fix the issues.

__itcm_rom_start -> __itcm_load_start
__dtcm_data_rom_start -> __dtcm_data_load_start

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2022-01-15 12:23:44 -05:00
Yong Cong Sin
419583697e drivers: watchdog: STM32G0X: clock DBGMCU before configuring
Enable the clock for the DBGMCU peripherals so that it can be
configured.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-01-15 12:22:02 -05:00
Fabio Baltieri
dddb9f14d5 boards: nucleo_h745zi_q: enable POWER_SUPPLY_DIRECT_SMPS
The board is fitted with the SMPS components and have no path from
VDD_MCU to VDD_LDO.

The stm32h7_init code used to default to SMPS on supported SoC but has
been changed in 22186c7c51 to only use SMPS if explicitly configured to
do so. This is causing the board to become unresponsive after a power
cycle when flashed with the current defconfig, and needs to be started
pulling BOOT0 high to be recovered.

Setting CONFIG_POWER_SUPPLY_DIRECT_SMPS restores the intended behavior.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2022-01-15 12:15:32 -05:00
Dominik Ermel
d10cb9b25b mgmt/mcumgr: Fix serial packet length not including CRC16
The length field of packet has not been including the length of
CRC16 field.

Fixes #39546

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-01-15 12:07:35 -05:00
Dominik Ermel
f9dee5613a mgmt/mcumgr: Correct packet length information
The packet length should include length of CRC16.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-01-15 12:07:35 -05:00
Henrik Brix Andersen
8af83eac4f drivers: can: change can_tx_callback_t function signature
Change the can_tx_callback_t function signature to use an "int" (not an
uint32_t) for representing transmission errors.

The "error" callback function parameter is functionally equivalent to
the return value from can_send() and thus needs to use the same data
type and needs to be able to hold negative errno values.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-01-15 12:01:35 -05:00
Alexandre Bourdiol
956bb90b08 boards: arm: stm32h7: select direct SMPS for both disco boards
Direct SMPS is the default configuration out of the box of:
* stm32h474i_disco
* stm32h735g_disco

Fixes #34732

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2022-01-06 17:39:00 -05:00
Gennady Kovalev
2f24663c38 drivers: clock_control: More power supply modes for STM32H7
STM32H7 has different power supply modes but now Zephyr supports just
LDO and direct SMPS. This commit introduses POWER_SUPPLY_CHOICE
configuration parameter and add support for missed power supply modes.

Signed-off-by: Gennady Kovalev <gik@bigur.com>

Fixes #40730.
2022-01-05 13:11:32 -05:00
Erwan Gouriou
af35240cdd include/drivers/clock_control: stm32h7: Add missing symbol PLL SRC CSI
Symbol STM32_PLL_SRC_CSI was missing and was preventing the config
to be used.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-01-05 07:32:45 -05:00
Manojkumar Subramaniam
e00e2b8754 soc: arm: st_stm32: use SMPS power supply only if enabled
Use SMPS power supply only if enabled.

The default power supply configuration for the
NUCLEO board with -Q subfix is SMPS,
so it's essential to match with hardware configuration
to avoid deadlocks due to mismatch.

if a custom board with LDO configuration is in use,
then no need to enable `CONFIG_POWER_SUPPLY_SMPS`

Signed-off-by: Manojkumar Subramaniam <manoj@electrolance.com>
2022-01-05 07:29:00 -05:00
Manojkumar Subramaniam
9e2bb08928 drivers: clock_control: stm32h7: Add logic to handle SMPS config
Some STM32 SoC supports an internal SMPS

Signed-off-by: Manojkumar Subramaniam <manoj@electrolance.com>
2022-01-05 07:29:00 -05:00
Manojkumar Subramaniam
357d9d3220 soc: arm: st_stm32: add kconfig entry for STM32 SMPS
Add support for SMPS

Signed-off-by: Manojkumar Subramaniam <manoj@electrolance.com>
2022-01-05 07:29:00 -05:00
172 changed files with 1961 additions and 811 deletions

View File

@@ -0,0 +1,29 @@
name: Publish Bluetooth Tests Results
on:
workflow_run:
workflows: ["Bluetooth Tests"]
types:
- completed
jobs:
bluetooth-test-results:
name: "Publish Bluetooth Test Results"
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'
steps:
- name: Download artifacts
uses: dawidd6/action-download-artifact@v2
with:
workflow: bluetooth-tests.yaml
run_id: ${{ github.event.workflow_run.id }}
- name: Publish Bluetooth Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
check_name: Bluetooth Test Results
comment_mode: off
commit: ${{ github.event.workflow_run.head_sha }}
event_file: event/event.json
event_name: ${{ github.event.workflow_run.event }}
files: "bluetooth-test-results/**/bsim_results.xml"

View File

@@ -1,7 +1,7 @@
name: Bluetooth Tests
on:
pull_request_target:
pull_request:
paths:
- "west.yml"
- "subsys/bluetooth/**"
@@ -39,9 +39,6 @@ jobs:
- name: checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: west setup
run: |
@@ -60,26 +57,15 @@ jobs:
if: always()
uses: actions/upload-artifact@v2
with:
name: Bluetooth Test Results
path: ./bsim_bt_out/bsim_results.xml
name: bluetooth-test-results
path: |
./bsim_bt_out/bsim_results.xml
${{ github.event_path }}
bluetooth-test-results:
name: "Publish Bluetooth Test Results"
needs: bluetooth-test-build
runs-on: ubuntu-20.04
# the build-and-test job might be skipped, we don't need to run this job then
if: success() || failure()
steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
- name: Upload Event Details
if: always()
uses: actions/upload-artifact@v2
with:
path: artifacts
- name: Publish Bluetooth Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
check_name: Bluetooth Test Results
github_token: ${{ secrets.GITHUB_TOKEN }}
files: "**/bsim_results.xml"
comment_mode: off
name: event
path: |
${{ github.event_path }}

View File

@@ -39,6 +39,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false
- name: Environment Setup
run: |

View File

@@ -15,6 +15,7 @@ jobs:
path: zephyrproject/zephyr
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false
- name: Manifest
uses: zephyrproject-rtos/action-manifest@2f1ad2908599d4fe747f886f9d733dd7eebae4ef

View File

@@ -49,6 +49,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false
- name: Environment Setup
if: github.event_name == 'pull_request_target'
@@ -137,6 +138,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false
- name: Environment Setup
run: |

View File

@@ -1385,6 +1385,17 @@ if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE)
endif()
endif()
if(NOT CONFIG_EXCEPTIONS)
set(eh_frame_section ".eh_frame")
else()
set(eh_frame_section "")
endif()
set(remove_sections_argument_list "")
foreach(section .comment COMMON ${eh_frame_section})
list(APPEND remove_sections_argument_list
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>${section})
endforeach()
if(CONFIG_BUILD_OUTPUT_HEX OR BOARD_FLASH_RUNNER STREQUAL openocd)
get_property(elfconvert_formats TARGET bintools PROPERTY elfconvert_formats)
if(ihex IN_LIST elfconvert_formats)
@@ -1394,9 +1405,7 @@ if(CONFIG_BUILD_OUTPUT_HEX OR BOARD_FLASH_RUNNER STREQUAL openocd)
$<TARGET_PROPERTY:bintools,elfconvert_flag>
${GAP_FILL}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>ihex
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>.comment
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>COMMON
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>.eh_frame
${remove_sections_argument_list}
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_HEX_NAME}
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
@@ -1418,9 +1427,7 @@ if(CONFIG_BUILD_OUTPUT_BIN)
$<TARGET_PROPERTY:bintools,elfconvert_flag>
${GAP_FILL}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>binary
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>.comment
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>COMMON
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>.eh_frame
${remove_sections_argument_list}
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_BIN_NAME}
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>

View File

@@ -1,5 +1,5 @@
VERSION_MAJOR = 2
VERSION_MINOR = 7
PATCHLEVEL = 1
PATCHLEVEL = 2
VERSION_TWEAK = 0
EXTRAVERSION =

View File

@@ -849,7 +849,7 @@ static inline z_arch_esf_t *get_esf(uint32_t msp, uint32_t psp, uint32_t exc_ret
bool *nested_exc)
{
bool alternative_state_exc = false;
z_arch_esf_t *ptr_esf;
z_arch_esf_t *ptr_esf = NULL;
*nested_exc = false;

View File

@@ -40,7 +40,7 @@ static inline uint64_t z_arm_dwt_freq_get(void)
/* SysTick and DWT both run at CPU frequency,
* reflected in the system timer HW cycles/sec.
*/
return CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
return sys_clock_hw_cycles_per_sec();
#else
static uint64_t dwt_frequency;
uint32_t cyc_start, cyc_end;

View File

@@ -26,7 +26,7 @@
extern "C" {
#endif
extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
K_KERNEL_STACK_ARRAY_EXTERN(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
CONFIG_ISR_STACK_SIZE);
/**

View File

@@ -101,9 +101,28 @@ spurious_continue:
* x0: 1st thread in the ready queue
* x1: _current thread
*/
#ifdef CONFIG_SMP
/*
* 2 possibilities here:
* - x0 != NULL (implies x0 != x1): we need to context switch and set
* the switch_handle in the context switch code
* - x0 == NULL: no context switch
*/
cmp x0, #0x0
bne switch
/*
* No context switch. Restore x0 from x1 (they are the same thread).
* See also comments to z_arch_get_next_switch_handle()
*/
mov x0, x1
b exit
switch:
#else
cmp x0, x1
beq exit
#endif
/* Switch thread */
bl z_arm64_context_switch

View File

@@ -129,7 +129,11 @@ void z_arm64_el2_init(void)
zero_cntvoff_el2(); /* Set 64-bit virtual timer offset to 0 */
zero_cnthctl_el2();
#ifdef CONFIG_CPU_AARCH64_CORTEX_R
zero_cnthps_ctl_el2();
#else
zero_cnthp_ctl_el2();
#endif
/*
* Enable this if/when we use the hypervisor timer.
* write_cnthp_cval_el2(~(uint64_t)0);

View File

@@ -124,9 +124,28 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
void *z_arch_get_next_switch_handle(struct k_thread **old_thread)
{
/*
* When returning from this function we will have the current thread
* onto the stack to be popped in x1 and the next thread in x0 returned
* from z_get_next_switch_handle() (see isr_wrapper.S)
*/
*old_thread = _current;
#ifdef CONFIG_SMP
/*
* XXX: see thread in #41840 and #40795
*
* The scheduler API requires a complete switch handle here, but arm64
* optimizes things such that the callee-save registers are still
* unsaved here (they get written out in z_arm64_context_switch()
* below). So pass a NULL instead, which the scheduler will store into
* the thread switch_handle field. The resulting thread won't be
* switched into until we write that ourselves.
*/
return z_get_next_switch_handle(NULL);
#else
return z_get_next_switch_handle(*old_thread);
#endif
}
#ifdef CONFIG_USERSPACE

View File

@@ -6,6 +6,7 @@ zephyr_library()
zephyr_library_sources(cpuhalt.c)
zephyr_library_sources(prep_c.c)
zephyr_library_sources(fatal.c)
zephyr_library_sources(cpuid.c)
zephyr_library_sources(spec_ctrl.c)
zephyr_library_sources_ifdef(CONFIG_X86_MEMMAP memmap.c)

51
arch/x86/core/cpuid.c Normal file
View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2022 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <cpuid.h> /* Header provided by the toolchain. */
#include <kernel_structs.h>
#include <arch/x86/cpuid.h>
#include <kernel.h>
uint32_t z_x86_cpuid_extended_features(void)
{
uint32_t eax, ebx, ecx = 0U, edx;
if (__get_cpuid(CPUID_EXTENDED_FEATURES_LVL,
&eax, &ebx, &ecx, &edx) == 0) {
return 0;
}
return edx;
}
#define INITIAL_APIC_ID_SHIFT (24)
#define INITIAL_APIC_ID_MASK (0xFF)
uint8_t z_x86_cpuid_get_current_physical_apic_id(void)
{
uint32_t eax, ebx, ecx, edx;
if (IS_ENABLED(CONFIG_X2APIC)) {
/* leaf 0x1F should be used first prior to using 0x0B */
if (__get_cpuid(CPUID_EXTENDED_TOPOLOGY_ENUMERATION_V2,
&eax, &ebx, &ecx, &edx) == 0) {
if (__get_cpuid(CPUID_EXTENDED_TOPOLOGY_ENUMERATION,
&eax, &ebx, &ecx, &edx) == 0) {
return 0;
}
}
} else {
if (__get_cpuid(CPUID_BASIC_INFO_1,
&eax, &ebx, &ecx, &edx) == 0) {
return 0;
}
edx = (ebx >> INITIAL_APIC_ID_SHIFT);
}
return (uint8_t)(edx & INITIAL_APIC_ID_MASK);
}

View File

@@ -114,4 +114,18 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
thread->arch.excNestCount = 0;
#endif /* CONFIG_LAZY_FPU_SHARING */
thread->arch.flags = 0;
/*
* When "eager FPU sharing" mode is enabled, FPU registers must be
* initialised at the time of thread creation because the floating-point
* context is always active and no further FPU initialisation is performed
* later.
*/
#if defined(CONFIG_EAGER_FPU_SHARING)
thread->arch.preempFloatReg.floatRegsUnion.fpRegs.fcw = 0x037f;
thread->arch.preempFloatReg.floatRegsUnion.fpRegs.ftw = 0xffff;
#if defined(CONFIG_X86_SSE)
thread->arch.preempFloatReg.floatRegsUnion.fpRegsEx.mxcsr = 0x1f80;
#endif /* CONFIG_X86_SSE */
#endif /* CONFIG_EAGER_FPU_SHARING */
}

View File

@@ -16,6 +16,8 @@
#include <kernel_arch_func.h>
#include <device.h>
#include <drivers/pcie/msi.h>
#include <drivers/interrupt_controller/sysapic.h>
#include <arch/x86/cpuid.h>
#endif
/* PCI Express Extended Configuration Mechanism (MMIO) */
@@ -179,12 +181,15 @@ static bool get_vtd(void)
/* these functions are explained in include/drivers/pcie/msi.h */
#define MSI_MAP_DESTINATION_ID_SHIFT 12
#define MSI_RH BIT(3)
uint32_t pcie_msi_map(unsigned int irq,
msi_vector_t *vector)
{
uint32_t map;
ARG_UNUSED(irq);
#if defined(CONFIG_INTEL_VTD_ICTL)
#if !defined(CONFIG_PCIE_MSI_X)
if (vector != NULL) {
@@ -197,7 +202,15 @@ uint32_t pcie_msi_map(unsigned int irq,
#endif
#endif
{
map = 0xFEE00000U; /* standard delivery to BSP local APIC */
uint32_t dest_id;
dest_id = z_x86_cpuid_get_current_physical_apic_id() <<
MSI_MAP_DESTINATION_ID_SHIFT;
/* Directing to current physical CPU (may not be BSP)
* Destination ID - RH 1 - DM 0
*/
map = 0xFEE00000U | dest_id | MSI_RH;
}
return map;

View File

@@ -4,13 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <cpuid.h> /* Header provided by the toolchain. */
#include <init.h>
#include <kernel_structs.h>
#include <kernel_arch_data.h>
#include <kernel_arch_func.h>
#include <arch/x86/msr.h>
#include <arch/x86/cpuid.h>
#include <kernel.h>
/*
@@ -18,31 +17,13 @@
* https://software.intel.com/security-software-guidance/api-app/sites/default/files/336996-Speculative-Execution-Side-Channel-Mitigations.pdf
*/
#define CPUID_EXTENDED_FEATURES_LVL 7
/* Bits to check in CPUID extended features */
#define CPUID_SPEC_CTRL_SSBD BIT(31)
#define CPUID_SPEC_CTRL_IBRS BIT(26)
#if defined(CONFIG_DISABLE_SSBD) || defined(CONFIG_ENABLE_EXTENDED_IBRS)
static uint32_t cpuid_extended_features(void)
{
uint32_t eax, ebx, ecx = 0U, edx;
if (__get_cpuid(CPUID_EXTENDED_FEATURES_LVL,
&eax, &ebx, &ecx, &edx) == 0) {
return 0;
}
return edx;
}
static int spec_ctrl_init(const struct device *dev)
{
ARG_UNUSED(dev);
uint32_t enable_bits = 0U;
uint32_t cpuid7 = cpuid_extended_features();
uint32_t cpuid7 = z_x86_cpuid_extended_features();
#ifdef CONFIG_DISABLE_SSBD
if ((cpuid7 & CPUID_SPEC_CTRL_SSBD) != 0U) {

View File

@@ -12,6 +12,7 @@ endif()
string(REPLACE "nsim" "mdb" MDB_ARGS "${BOARD}.args")
if((CONFIG_SOC_NSIM_HS_SMP OR CONFIG_SOC_NSIM_HS6X_SMP))
board_runner_args(mdb-nsim "--cores=${CONFIG_MP_NUM_CPUS}" "--nsim_args=${MDB_ARGS}")
board_runner_args(mdb-hw "--cores=${CONFIG_MP_NUM_CPUS}")
else()
board_runner_args(mdb-nsim "--nsim_args=${MDB_ARGS}")
endif()

View File

@@ -1,6 +1,6 @@
# BL654 USB adapter board configuration
# Copyright (c) 2021 Laird Connectivity
# Copyright (c) 2021-2022 Laird Connectivity
# SPDX-License-Identifier: Apache-2.0
if BOARD_BL654_USB
@@ -13,16 +13,21 @@ config BOARD
# Nordic nRF5 bootloader exists outside of the partitions specified in the
# DTS file, so we manually override FLASH_LOAD_OFFSET to link the application
# correctly, after Nordic MBR.
# correctly, after Nordic MBR, and limit the maximum size to not protude into
# the bootloader at the end of flash.
# When building MCUBoot, MCUBoot itself will select USE_DT_CODE_PARTITION
# which will make it link into the correct partition specified in DTS file,
# so no override is necessary.
# so no override or limit is necessary.
config FLASH_LOAD_OFFSET
default 0x1000
depends on !USE_DT_CODE_PARTITION
config FLASH_LOAD_SIZE
default 0xdf000
depends on !USE_DT_CODE_PARTITION
if USB_DEVICE_STACK
config USB_UART_CONSOLE

View File

@@ -216,7 +216,7 @@ Run a serial host program to connect with your NUCLEO-H745ZI-Q board.
$ minicom -b 115200 -D /dev/ttyACM0
or use scrreen:
or use screen:
.. code-block:: console
@@ -235,15 +235,20 @@ You should see the following message on the console:
$ Hello World! nucleo_h745zi_q_m7
Blinky example can also be used:
.. note::
Sometimes, flashing is not working. It is necessary to erase the flash
(with STM32CubeProgrammer for example) to make it work again.
Similarly, you can build and flash samples on the M4 target. For this, please
take care of the resource sharing (UART port used for console for instance).
Here is an example for the :ref:`blinky-sample` application on M4 core.
.. zephyr-app-commands::
:zephyr-app: samples/basic/blinky
:board: nucleo_h745zi_q_m7
:board: nucleo_h745zi_q_m4
:goals: build flash
Same way M4 core can be flashed.
.. note::
Flashing both M4 and M7 and pushing RESTART button on the board leads
@@ -261,6 +266,10 @@ You can debug an application in the usual way. Here is an example for the
:maybe-skip-config:
:goals: debug
Debugging with west is currently not available on Cortex M4 side.
In order to debug a Zephyr application on Cortex M4 side, you can use
`STM32CubeIDE`_.
.. _Nucleo H745ZI-Q website:
https://www.st.com/en/evaluation-tools/nucleo-h745zi-q.html

View File

@@ -6,6 +6,9 @@ CONFIG_SOC_STM32H745XX=y
# Board config should be specified since there are 2 possible targets
CONFIG_BOARD_NUCLEO_H745ZI_Q_M7=y
# Enable the internal SMPS regulator
CONFIG_POWER_SUPPLY_DIRECT_SMPS=y
# Enable MPU
CONFIG_ARM_MPU=y

View File

@@ -255,19 +255,17 @@ flashed in the usual way (see :ref:`build_an_application` and
Flashing
========
Nucleo L552ZE Q board includes an ST-LINK/V3E embedded debug tool
interface. This interface is not yet supported by the openocd version.
Instead, support can be enabled on pyocd by adding "pack" support with
the following pyocd command:
Nucleo L552ZE Q board includes an ST-LINK/V2-1 embedded debug tool
interface. Support can be enabled on pyocd by adding "pack" support with the
following pyocd command:
.. code-block:: console
$ pyocd pack --update
$ pyocd pack --install stm32l552ze
Nucleo L552ZE Q board includes an ST-LINK/V2-1 embedded debug tool
interface. This interface is supported by the openocd version
included in the Zephyr SDK since v0.9.2.
Alternatively, this interface is supported by the openocd version
included in the Zephyr SDK since v0.13.1.
Flashing an application to Nucleo L552ZE Q
------------------------------------------

View File

@@ -0,0 +1,19 @@
source [find interface/stlink.cfg]
transport select hla_swd
source [find target/stm32l5x.cfg]
# use hardware reset
reset_config srst_only srst_nogate
$_TARGETNAME configure -event gdb-attach {
echo "Debugger attaching: halting execution"
reset halt
gdb_breakpoint_override hard
}
$_TARGETNAME configure -event gdb-detach {
echo "Debugger detaching: resuming execution"
resume
}

View File

@@ -1,5 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(pyocd "--target=stm32wb55rgvx")
board_runner_args(stm32cubeprogrammer "--port=swd" "--reset=hw")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/stm32cubeprogrammer.board.cmake)

View File

@@ -3,6 +3,9 @@
CONFIG_SOC_SERIES_STM32H7X=y
CONFIG_SOC_STM32H735XX=y
# Enable the internal SMPS regulator
CONFIG_POWER_SUPPLY_DIRECT_SMPS=y
# Enable MPU
CONFIG_ARM_MPU=y

View File

@@ -220,24 +220,6 @@ the USB port to prepare it for flashing. Then build and flash your application.
Here is an example for the :ref:`hello_world` application.
.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: stm32h747i_disco_m7
:goals: build
Use the following commands to flash either m7 or m4 target:
.. code-block:: console
$ ./STM32_Programmer_CLI -c port=SWD mode=UR -w <path_to_m7_binary> 0x8000000
$ ./STM32_Programmer_CLI -c port=SWD mode=UR -w <path_to_m4_binary> 0x8100000
Alternatively it is possible to flash with OpenOcd but with some restrictions:
Sometimes, flashing is not working. It is necessary to erase the flash
(with STM32CubeProgrammer for example) to make it work again.
Debugging with OpenOCD is currently working for this board only with Cortex M7,
not Cortex M4.
.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: stm32h747i_disco_m7
@@ -255,6 +237,20 @@ You should see the following message on the console:
Hello World! stm32h747i_disco_m7
.. note::
Sometimes, flashing is not working. It is necessary to erase the flash
(with STM32CubeProgrammer for example) to make it work again.
Similarly, you can build and flash samples on the M4 target. For this, please
take care of the resource sharing (UART port used for console for instance).
Here is an example for the :ref:`blinky-sample` application on M4 core.
.. zephyr-app-commands::
:zephyr-app: samples/basic/blinky
:board: stm32h747i_disco_m4
:goals: build flash
Debugging
=========
@@ -266,6 +262,9 @@ You can debug an application in the usual way. Here is an example for the
:board: stm32h747i_disco_m7
:goals: debug
Debugging with west is currently not available on Cortex M4 side.
In order to debug a Zephyr application on Cortex M4 side, you can use
`STM32CubeIDE`_.
.. _STM32H747I-DISCO website:
http://www.st.com/en/evaluation-tools/stm32h747i-disco.html
@@ -284,3 +283,6 @@ You can debug an application in the usual way. Here is an example for the
.. _DISCO_H747I modifications for Ethernet:
https://os.mbed.com/teams/ST/wiki/DISCO_H747I-modifications-for-Ethernet
.. _STM32CubeIDE:
https://www.st.com/en/development-tools/stm32cubeide.html

View File

@@ -9,6 +9,9 @@ CONFIG_BOARD_STM32H747I_DISCO_M7=y
# enable pinmux
CONFIG_PINMUX=y
# Enable the internal SMPS regulator
CONFIG_POWER_SUPPLY_DIRECT_SMPS=y
# enable GPIO
CONFIG_GPIO=y

View File

@@ -252,18 +252,16 @@ Flashing
========
STM32L562E-DK Discovery board includes an ST-LINK/V3E embedded debug tool
interface. This interface is not yet supported by the openocd version.
Instead, support can be enabled on pyocd by adding "pack" support with
the following pyocd command:
interface. Support can be enabled on pyocd by adding "pack" support with the
following pyocd command:
.. code-block:: console
$ pyocd pack --update
$ pyocd pack --install stm32l562qe
STM32L562E-DK Discovery board includes an ST-LINK/V2-1 embedded debug tool
interface. This interface is supported by the openocd version
included in the Zephyr SDK since v0.9.2.
Alternatively, this interface is supported by the openocd version
included in the Zephyr SDK since v0.13.1.
Flashing an application to STM32L562E-DK Discovery
--------------------------------------------------

View File

@@ -0,0 +1,19 @@
source [find interface/stlink.cfg]
transport select hla_swd
source [find target/stm32l5x.cfg]
# use hardware reset
reset_config srst_only srst_nogate
$_TARGETNAME configure -event gdb-attach {
echo "Debugger attaching: halting execution"
reset halt
gdb_breakpoint_override hard
}
$_TARGETNAME configure -event gdb-detach {
echo "Debugger detaching: resuming execution"
resume
}

View File

@@ -3,6 +3,7 @@
set(EMU_PLATFORM armfvp)
set(ARMFVP_BIN_NAME FVP_BaseR_AEMv8R)
set(ARMFVP_MIN_VERSION 11.16.16)
set(ARMFVP_FLAGS
-C cluster0.has_aarch64=1

View File

@@ -27,6 +27,8 @@ To Run the Fixed Virtual Platform simulation tool you must download "Armv8-R AEM
FVP" from Arm developer [1]_ (This might require the user to register) and
install it on your host PC.
The current minimum required version of "Armv8-R AEM FVP" is 11.16.16.
Hardware
********

View File

@@ -33,3 +33,5 @@ CONFIG_PM_CPU_OPS_PSCI=n
CONFIG_SOC_FVP_AEMV8R_EL2_INIT=y
CONFIG_MP_NUM_CPUS=4
CONFIG_MAX_THREAD_BYTES=3

View File

@@ -24,6 +24,7 @@ if(CONFIG_BOOTLOADER_ESP_IDF)
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER}
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DPYTHON=${PYTHON_EXECUTABLE}
BUILD_COMMAND
${CMAKE_COMMAND} --build .
INSTALL_COMMAND "" # This particular build system has no install command
@@ -35,14 +36,14 @@ if(CONFIG_BOOTLOADER_ESP_IDF)
BINARY_DIR ${espidf_build_dir}
CONFIGURE_COMMAND ""
BUILD_COMMAND
python ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
--offset 0x1000 --flash-size 4MB ${ESP_IDF_PATH}/components/partition_table/partitions_singleapp.csv ${espidf_build_dir}/partitions_singleapp.bin
INSTALL_COMMAND ""
)
if(CONFIG_BUILD_OUTPUT_BIN)
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND python ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
ARGS --chip esp32c3 elf2image --flash_mode dio --flash_freq 40m
-o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)

View File

@@ -23,6 +23,7 @@ if(CONFIG_BOOTLOADER_ESP_IDF)
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER}
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DPYTHON=${PYTHON_EXECUTABLE}
BUILD_COMMAND
${CMAKE_COMMAND} --build .
INSTALL_COMMAND "" # This particular build system has no install command
@@ -34,14 +35,14 @@ if(CONFIG_BOOTLOADER_ESP_IDF)
BINARY_DIR ${espidf_build_dir}
CONFIGURE_COMMAND ""
BUILD_COMMAND
python ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
--offset 0x1000 --flash-size 4MB ${ESP_IDF_PATH}/components/partition_table/partitions_singleapp.csv ${espidf_build_dir}/partitions_singleapp.bin
INSTALL_COMMAND ""
)
if(CONFIG_BUILD_OUTPUT_BIN)
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND python ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
ARGS --chip esp32 elf2image --flash_mode dio --flash_freq 40m
-o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)

View File

@@ -23,6 +23,7 @@ if(CONFIG_BOOTLOADER_ESP_IDF)
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER}
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DPYTHON=${PYTHON_EXECUTABLE}
BUILD_COMMAND
${CMAKE_COMMAND} --build .
INSTALL_COMMAND "" # This particular build system has no install command
@@ -34,14 +35,14 @@ if(CONFIG_BOOTLOADER_ESP_IDF)
BINARY_DIR ${espidf_build_dir}
CONFIGURE_COMMAND ""
BUILD_COMMAND
python ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
--offset 0x1000 --flash-size 4MB ${ESP_IDF_PATH}/components/partition_table/partitions_singleapp.csv ${espidf_build_dir}/partitions_singleapp.bin
INSTALL_COMMAND ""
)
if(CONFIG_BUILD_OUTPUT_BIN)
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND python ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
ARGS --chip esp32s2 elf2image --flash_mode dio --flash_freq 40m
-o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)

View File

@@ -10,6 +10,20 @@ find_program(
NAMES ${ARMFVP_BIN_NAME}
)
if ((NOT "${ARMFVP}" STREQUAL "ARMFVP-NOTFOUND") AND (DEFINED ARMFVP_MIN_VERSION))
execute_process(
COMMAND ${ARMFVP} --version
OUTPUT_VARIABLE out
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE "\n" "" out ${out})
string(REGEX MATCH "[0-9]+\.[0-9]+\.[0-9]+" armfvp_version ${out})
if(${armfvp_version} VERSION_LESS ${ARMFVP_MIN_VERSION})
message(WARNING "Found FVP version is \"${armfvp_version}\", "
"the minimum required by the current board is \"${ARMFVP_MIN_VERSION}\".")
endif()
endif()
if(CONFIG_ARMV8_A_NS)
foreach(filetype BL1 FIP)
if ((NOT DEFINED ARMFVP_${filetype}_FILE) AND (EXISTS "$ENV{ARMFVP_${filetype}_FILE}"))

View File

@@ -90,6 +90,8 @@ endforeach()
# A list of common environment settings used when invoking Kconfig during CMake
# configure time or menuconfig and related build target.
string(REPLACE ";" "\\\;" SHIELD_AS_LIST_ESCAPED "${SHIELD_AS_LIST}")
# cmake commands are escaped differently
string(REPLACE ";" "\\;" SHIELD_AS_LIST_ESCAPED_COMMAND "${SHIELD_AS_LIST}")
set(COMMON_KCONFIG_ENV_SETTINGS
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
@@ -250,7 +252,7 @@ endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E env
${COMMON_KCONFIG_ENV_SETTINGS}
SHIELD_AS_LIST=${SHIELD_AS_LIST_ESCAPED}
SHIELD_AS_LIST=${SHIELD_AS_LIST_ESCAPED_COMMAND}
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/kconfig/kconfig.py
--zephyr-base=${ZEPHYR_BASE}

View File

@@ -31,6 +31,9 @@ Configuration options
- ``doxyrunner_doxyfile``: Path to Doxyfile.
- ``doxyrunner_outdir``: Doxygen build output directory (inserted to
``OUTPUT_DIRECTORY``)
- ``doxyrunner_outdir_var``: Variable representing the Doxygen build output
directory, as used by ``OUTPUT_DIRECTORY``. This can be useful if other
Doxygen variables reference to the output directory.
- ``doxyrunner_fmt``: Flag to indicate if Doxyfile should be formatted.
- ``doxyrunner_fmt_vars``: Format variables dictionary (name: value).
- ``doxyrunner_fmt_pattern``: Format pattern.
@@ -132,6 +135,7 @@ def process_doxyfile(
fmt: bool = False,
fmt_pattern: Optional[str] = None,
fmt_vars: Optional[Dict[str, str]] = None,
outdir_var: Optional[str] = None,
) -> str:
"""Process Doxyfile.
@@ -146,6 +150,7 @@ def process_doxyfile(
fmt: If Doxyfile should be formatted.
fmt_pattern: Format pattern.
fmt_vars: Format variables.
outdir_var: Variable representing output directory.
Returns:
Processed Doxyfile content.
@@ -179,6 +184,10 @@ def process_doxyfile(
if not fmt_pattern or not fmt_vars:
raise ValueError("Invalid formatting pattern or variables")
if outdir_var:
fmt_vars = fmt_vars.copy()
fmt_vars[outdir_var] = outdir.as_posix()
for var, value in fmt_vars.items():
content = content.replace(fmt_pattern.format(var), value)
@@ -349,6 +358,7 @@ def doxygen_build(app: Sphinx) -> None:
app.config.doxyrunner_fmt,
app.config.doxyrunner_fmt_pattern,
app.config.doxyrunner_fmt_vars,
app.config.doxyrunner_outdir_var,
)
logger.info("Checking if Doxygen needs to be run...")
@@ -374,6 +384,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value("doxyrunner_doxygen", "doxygen", "env")
app.add_config_value("doxyrunner_doxyfile", None, "env")
app.add_config_value("doxyrunner_outdir", None, "env")
app.add_config_value("doxyrunner_outdir_var", None, "env")
app.add_config_value("doxyrunner_fmt", False, "env")
app.add_config_value("doxyrunner_fmt_vars", {}, "env")
app.add_config_value("doxyrunner_fmt_pattern", "@{}@", "env")

View File

@@ -124,64 +124,27 @@ hr,
border-color: var(--admonition-attention-title-background-color) !important;
color: var(--admonition-attention-color) !important;
}
.rst-content dl:not(.docutils).class dt,
.rst-content dl:not(.docutils).function dt,
.rst-content dl:not(.docutils).method dt,
.rst-content dl:not(.docutils).attribute dt {
width: 100% !important;
}
.rst-content dl:not(.docutils).class > dt,
.rst-content dl:not(.docutils).function > dt,
.rst-content dl:not(.docutils).method > dt,
.rst-content dl:not(.docutils).attribute > dt {
font-size: 100% !important;
font-weight: normal !important;
margin-bottom: 16px !important;
padding: 6px 8px !important;
}
.rst-content dl:not(.docutils) tt.descclassname,
.rst-content dl:not(.docutils) code.descclassname {
color: var(--highlight-type2-color) !important;
font-weight: normal !important;
}
.rst-content dl:not(.docutils) tt.descname,
.rst-content dl:not(.docutils) code.descname {
color: var(--highlight-function-color) !important;
font-weight: normal !important;
}
.rst-content dl:not(.docutils) .sig-paren,
.rst-content dl:not(.docutils) .optional {
color: var(--highlight-operator-color) !important;
font-weight: normal !important;
padding: 0 2px !important;
}
.rst-content dl:not(.docutils) .optional {
font-style: italic !important;
}
.rst-content dl:not(.docutils) .sig-param,
.rst-content dl:not(.docutils).class dt > em,
.rst-content dl:not(.docutils).function dt > em,
.rst-content dl:not(.docutils).method dt > em {
color: var(--code-literal-color) !important;
.rst-content dt.sig .k {
color: var(--highlight-keyword2-color) !important;
font-style: normal !important;
padding: 0 4px !important;
}
.rst-content dl:not(.docutils) .sig-param,
.rst-content dl:not(.docutils).class dt > code,
.rst-content dl:not(.docutils).function dt > code,
.rst-content dl:not(.docutils).method dt > code {
padding: 0 4px !important;
}
.rst-content dl:not(.docutils) .sig-param,
.rst-content dl:not(.docutils).class dt > .optional ~ em,
.rst-content dl:not(.docutils).function dt > .optional ~ em,
.rst-content dl:not(.docutils).method dt > .optional ~ em {
color: var(--highlight-number-color) !important;
font-style: italic !important;
}
.rst-content dl:not(.docutils).class dt > em.property {
.rst-content dt.sig .kt {
color: var(--highlight-keyword-color) !important;
font-style: normal !important;
}
.rst-content dt.sig .sig-name .n {
color: var(--highlight-function-color) !important;
}
.rst-content dt.sig .k,
.rst-content dt.sig .kt,
.rst-content dt.sig .n {
font-weight: normal !important;
}
.rst-content dl:not(.docutils) dt a.headerlink {
color: var(--link-color) !important;
}
@@ -878,16 +841,8 @@ kbd, .kbd {
/* Breathe tweaks */
.rst-content dl.group>dt, .rst-content dl.group>dd>p {
display:none !important;
}
.rst-content dl.group {
margin: 0 0 1rem 0;
}
.rst-content dl.group>dd {
margin-left: 0 !important;
.rst-content .section > dl > dd {
margin-left: 0;
}
.rst-content p.breathe-sectiondef-title {
@@ -895,24 +850,12 @@ kbd, .kbd {
color: var(--link-color);
}
.rst-content div.breathe-sectiondef {
padding-left: 0 !important;
}
.rst-content dl:not(.docutils) dl:not(.rst-other-versions) dt {
background: var(--admonition-note-background-color) !important;
border-top: none !important;
border-left: none !important;
}
.rst-content dl:not(.docutils).c.var .pre {
padding-right: 4px;
}
.rst-content dl:not(.docutils).c.struct .property {
padding-right: 4px !important;
}
/* Misc tweaks */
.rst-columns {

View File

@@ -180,6 +180,7 @@ doxyrunner_doxyfile = ZEPHYR_BASE / "doc" / "zephyr.doxyfile.in"
doxyrunner_outdir = ZEPHYR_BUILD / "doxygen"
doxyrunner_fmt = True
doxyrunner_fmt_vars = {"ZEPHYR_BASE": str(ZEPHYR_BASE)}
doxyrunner_outdir_var = "DOXY_OUT"
# -- Options for Breathe plugin -------------------------------------------
@@ -203,6 +204,7 @@ cpp_id_attributes = [
"__DEPRECATED_MACRO",
"FUNC_NORETURN",
"__subsystem",
"ALWAYS_INLINE",
]
c_id_attributes = cpp_id_attributes

View File

@@ -209,6 +209,20 @@ on Zephyr. The ones that are supported are described in the following table:
:kconfig:`CONFIG_THREAD_STACK_INFO` and :kconfig:`CONFIG_INIT_STACKS` options
must be set.
.. _mcumgr_jlink_ob_virtual_msd:
J-Link Virtual MSD Interaction Note
***********************************
On boards where a J-Link OB is present which has both CDC and MSC (virtual Mass
Storage Device, also known as drag-and-drop) support, the MSD functionality can
prevent mcumgr commands over the CDC UART port from working due to how USB
endpoints are configured in the J-Link firmware (for example on the Nordic
``nrf52840dk``) because of limiting the maximum packet size (most likely to occur
when using image management commands for updating firmware). This issue can be
resolved by disabling MSD functionality on the J-Link device, follow the
instructions on :ref:`nordic_segger_msd` to disable MSD support.
.. _image_mgmt:
Image Management

View File

@@ -261,7 +261,21 @@ or invoke make with the following target::
# To generate HTML output without detailed Kconfig
make html-fast
Linking external Doxygen projects against Zephyr
************************************************
External projects that build upon Zephyr functionality and wish to refer to
Zephyr documentation in Doxygen (through the use of @ref), can utilize the
tag file exported at `zephyr.tag </doxygen/html/zephyr.tag>`_
Once downloaded, the tag file can be used in a custom ``doxyfile.in`` as follows::
TAGFILES = "/path/to/zephyr.tag=https://docs.zephyrproject.org/latest/doxygen/html/"
For additional information refer to `Doxygen External Documentation`_.
.. _reStructuredText: http://sphinx-doc.org/rest.html
.. _Sphinx: http://sphinx-doc.org/
.. _Windows Python Path: https://docs.python.org/3/using/windows.html#finding-the-python-executable
.. _Doxygen External Documentation: https://www.doxygen.nl/manual/external.html

View File

@@ -297,3 +297,8 @@ Note that while SMP requires :kconfig:`CONFIG_USE_SWITCH`, the reverse is not
true. A uniprocessor architecture built with :kconfig:`CONFIG_SMP` set to No might
still decide to implement its context switching using
:c:func:`arch_switch`.
API Reference
**************
.. doxygengroup:: spinlock_apis

View File

@@ -177,12 +177,12 @@ occurred. It does not block until the message is sent like the example above.
.. code-block:: C
void tx_irq_callback(uint32_t error_flags, void *arg)
void tx_irq_callback(int error, void *arg)
{
char *sender = (char *)arg;
if (error_flags) {
LOG_ERR("Sendig failed [%d]\nSender: %s\n", error_flags, sender);
if (error != 0) {
LOG_ERR("Sendig failed [%d]\nSender: %s\n", error, sender);
}
}

View File

@@ -55,6 +55,19 @@ release:
* :github:`40844` - gen_app_partitions scans object files unrelated to current image
* :github:`41237` - drivers: ieee802154_dw1000: use dedicated workqueue
Security Vulnerability Related
******************************
The following security vulnerabilities (CVEs) were addressed in this
release:
* CVE-2021-3966: `Zephyr project bug tracker GHSA-hfxq-3w6x-fv2m
<https://github.com/zephyrproject-rtos/zephyr/security/advisories/GHSA-hfxq-3w6x-fv2m>`_
More detailed information can be found in:
https://docs.zephyrproject.org/latest/security/vulnerabilities.html
.. _zephyr_2.7.0:
Zephyr 2.7.0

View File

@@ -2064,7 +2064,7 @@ TAGFILES =
# tag file that is based on the input files it reads. See section "Linking to
# external documentation" for more information about the usage of tag files.
GENERATE_TAGFILE =
GENERATE_TAGFILE = @DOXY_OUT@/html/zephyr.tag
# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
# the class index. If set to NO, only the inherited external classes will be

View File

@@ -319,6 +319,49 @@ static void adc_stm32_calib(const struct device *dev)
}
#endif
/*
* Enable ADC peripheral, and wait until ready if required by SOC.
*/
static int adc_stm32_enable(ADC_TypeDef *adc)
{
#if defined(CONFIG_SOC_SERIES_STM32L4X) || \
defined(CONFIG_SOC_SERIES_STM32L5X) || \
defined(CONFIG_SOC_SERIES_STM32WBX) || \
defined(CONFIG_SOC_SERIES_STM32G0X) || \
defined(CONFIG_SOC_SERIES_STM32G4X) || \
defined(CONFIG_SOC_SERIES_STM32WLX)
if (LL_ADC_IsEnabled(adc) == 1UL) {
return 0;
}
LL_ADC_ClearFlag_ADRDY(adc);
LL_ADC_Enable(adc);
/*
* Enabling ADC modules in L4, WB, G0 and G4 series may fail if they are
* still not stabilized, this will wait for a short time to ensure ADC
* modules are properly enabled.
*/
uint32_t count_timeout = 0;
while (LL_ADC_IsActiveFlag_ADRDY(adc) == 0) {
if (LL_ADC_IsEnabled(adc) == 0UL) {
LL_ADC_Enable(adc);
count_timeout++;
if (count_timeout == 10) {
return -ETIMEDOUT;
}
}
}
#else
LL_ADC_Enable(adc);
#endif
return 0;
}
static int start_read(const struct device *dev,
const struct adc_sequence *sequence)
{
@@ -409,9 +452,10 @@ static int start_read(const struct device *dev,
return err;
}
#if defined(CONFIG_SOC_SERIES_STM32G0X)
#if defined(CONFIG_SOC_SERIES_STM32G0X) || \
defined(CONFIG_SOC_SERIES_STM32WLX)
/*
* Errata: Writing ADC_CFGR1 register while ADEN bit is set
* Writing ADC_CFGR1 register while ADEN bit is set
* resets RES[1:0] bitfield. We need to disable and enable adc.
*/
if (LL_ADC_IsEnabled(adc) == 1UL) {
@@ -420,15 +464,14 @@ static int start_read(const struct device *dev,
while (LL_ADC_IsEnabled(adc) == 1UL) {
}
LL_ADC_SetResolution(adc, resolution);
LL_ADC_Enable(adc);
while (LL_ADC_IsActiveFlag_ADRDY(adc) != 1UL) {
}
adc_stm32_enable(adc);
#elif !defined(CONFIG_SOC_SERIES_STM32F1X) && \
!defined(STM32F3X_ADC_V2_5)
LL_ADC_SetResolution(adc, resolution);
#endif
#ifdef CONFIG_SOC_SERIES_STM32L0X
#if defined(CONFIG_SOC_SERIES_STM32L0X) || \
defined(CONFIG_SOC_SERIES_STM32WLX)
/*
* setting OVS bits is conditioned to ADC state: ADC must be disabled
* or enabled without conversion on going : disable it, it will stop
@@ -524,11 +567,11 @@ static int start_read(const struct device *dev,
break;
default:
LOG_ERR("Invalid oversampling");
LL_ADC_Enable(adc);
adc_stm32_enable(adc);
return -EINVAL;
}
/* re-enable ADC after changing the OVS */
LL_ADC_Enable(adc);
adc_stm32_enable(adc);
#else
if (sequence->oversampling) {
LOG_ERR("Oversampling not supported");
@@ -543,7 +586,14 @@ static int start_read(const struct device *dev,
!defined(CONFIG_SOC_SERIES_STM32F1X) && \
!defined(STM32F3X_ADC_V2_5) && \
!defined(CONFIG_SOC_SERIES_STM32L1X)
/* we cannot calibrate the ADC while the ADC is enabled */
LL_ADC_Disable(adc);
while (LL_ADC_IsEnabled(adc) == 1UL) {
}
adc_stm32_calib(dev);
/* re-enable ADC after calibration */
adc_stm32_enable(adc);
#else
LOG_ERR("Calibration not supported");
return -ENOTSUP;
@@ -564,7 +614,7 @@ static int start_read(const struct device *dev,
#elif defined(CONFIG_SOC_SERIES_STM32F1X)
LL_ADC_EnableIT_EOS(adc);
#elif defined(STM32F3X_ADC_V2_5)
LL_ADC_Enable(adc);
adc_stm32_enable(adc);
LL_ADC_EnableIT_EOS(adc);
#else
LL_ADC_EnableIT_EOCS(adc);
@@ -904,32 +954,10 @@ static int adc_stm32_init(const struct device *dev)
}
#endif
LL_ADC_Enable(adc);
#if defined(CONFIG_SOC_SERIES_STM32L4X) || \
defined(CONFIG_SOC_SERIES_STM32L5X) || \
defined(CONFIG_SOC_SERIES_STM32WBX) || \
defined(CONFIG_SOC_SERIES_STM32G0X) || \
defined(CONFIG_SOC_SERIES_STM32G4X) || \
defined(CONFIG_SOC_SERIES_STM32H7X) || \
defined(CONFIG_SOC_SERIES_STM32WLX)
/*
* Enabling ADC modules in L4, WB, G0 and G4 series may fail if they are
* still not stabilized, this will wait for a short time to ensure ADC
* modules are properly enabled.
*/
uint32_t countTimeout = 0;
while (LL_ADC_IsActiveFlag_ADRDY(adc) == 0) {
if (LL_ADC_IsEnabled(adc) == 0UL) {
LL_ADC_Enable(adc);
countTimeout++;
if (countTimeout == 10) {
return -ETIMEDOUT;
}
}
err = adc_stm32_enable(adc);
if (err < 0) {
return err;
}
#endif
config->irq_cfg_func();

View File

@@ -149,6 +149,9 @@ int can_mcan_set_timing(const struct can_mcan_config *cfg,
return -EIO;
}
/* Configuration Change Enable */
can->cccr |= CAN_MCAN_CCCR_CCE;
can_mcan_configure_timing(can, timing, timing_data);
ret = can_leave_init_mode(can, K_MSEC(CAN_INIT_TIMEOUT));

View File

@@ -56,7 +56,7 @@ static const uint8_t reg_demand[] = {2, 1, 4, 2};
static void can_stm32_signal_tx_complete(struct can_mailbox *mb)
{
if (mb->tx_callback) {
mb->tx_callback(mb->error_flags, mb->callback_arg);
mb->tx_callback(mb->error, mb->callback_arg);
} else {
k_sem_give(&mb->tx_int_sem);
}
@@ -151,7 +151,7 @@ void can_stm32_tx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
bus_off = can->ESR & CAN_ESR_BOFF;
if ((can->TSR & CAN_TSR_RQCP0) | bus_off) {
data->mb0.error_flags =
data->mb0.error =
can->TSR & CAN_TSR_TXOK0 ? CAN_TX_OK :
can->TSR & CAN_TSR_TERR0 ? CAN_TX_ERR :
can->TSR & CAN_TSR_ALST0 ? CAN_TX_ARB_LOST :
@@ -163,7 +163,7 @@ void can_stm32_tx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
}
if ((can->TSR & CAN_TSR_RQCP1) | bus_off) {
data->mb1.error_flags =
data->mb1.error =
can->TSR & CAN_TSR_TXOK1 ? CAN_TX_OK :
can->TSR & CAN_TSR_TERR1 ? CAN_TX_ERR :
can->TSR & CAN_TSR_ALST1 ? CAN_TX_ARB_LOST :
@@ -175,7 +175,7 @@ void can_stm32_tx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
}
if ((can->TSR & CAN_TSR_RQCP2) | bus_off) {
data->mb2.error_flags =
data->mb2.error =
can->TSR & CAN_TSR_TXOK2 ? CAN_TX_OK :
can->TSR & CAN_TSR_TERR2 ? CAN_TX_ERR :
can->TSR & CAN_TSR_ALST2 ? CAN_TX_ARB_LOST :
@@ -688,7 +688,7 @@ int can_stm32_send(const struct device *dev, const struct zcan_frame *msg,
if (callback == NULL) {
k_sem_take(&mb->tx_int_sem, K_FOREVER);
return mb->error_flags;
return mb->error;
}
return 0;

View File

@@ -43,7 +43,7 @@ struct can_mailbox {
can_tx_callback_t tx_callback;
void *callback_arg;
struct k_sem tx_int_sem;
uint32_t error_flags;
int error;
};

View File

@@ -45,12 +45,12 @@ static inline void socket_can_iface_init(struct net_if *iface)
LOG_DBG("Init CAN interface %p dev %p", iface, dev);
}
static inline void tx_irq_callback(uint32_t error_flags, void *arg)
static inline void tx_irq_callback(int error, void *arg)
{
char *caller_str = (char *)arg;
if (error_flags) {
if (error != 0) {
LOG_DBG("TX error from %s! error-code: %d",
caller_str, error_flags);
caller_str, error);
}
}

View File

@@ -259,8 +259,28 @@ static uint32_t get_hclk_frequency(void)
static int32_t prepare_regulator_voltage_scale(void)
{
/* Make sure to put the CPU in highest Voltage scale during clock configuration */
/* Apply system power supply configuration */
#if defined(SMPS) && defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS)
LL_PWR_ConfigSupply(LL_PWR_DIRECT_SMPS_SUPPLY);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO)
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_LDO);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO)
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_LDO);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO)
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO)
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT)
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT)
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT);
#elif defined(CONFIG_POWER_SUPPLY_EXTERNAL_SOURCE)
LL_PWR_ConfigSupply(LL_PWR_EXTERNAL_SOURCE_SUPPLY);
#else
LL_PWR_ConfigSupply(LL_PWR_LDO_SUPPLY);
#endif
/* Make sure to put the CPU in highest Voltage scale during clock configuration */
/* Highest voltage is SCALE0 */
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE0);
return 0;
@@ -276,7 +296,25 @@ static int32_t optimize_regulator_voltage_scale(uint32_t sysclk_freq)
/* LL_PWR_REGULATOR_SCALE3 is lowest power consumption */
/* Must be done in accordance to the Maximum allowed frequency vs VOS*/
/* See RM0433 page 352 for more details */
#if defined(SMPS) && defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS)
LL_PWR_ConfigSupply(LL_PWR_DIRECT_SMPS_SUPPLY);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO)
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_LDO);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO)
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_LDO);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO)
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO)
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT)
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT);
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT)
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT);
#elif defined(CONFIG_POWER_SUPPLY_EXTERNAL_SOURCE)
LL_PWR_ConfigSupply(LL_PWR_EXTERNAL_SOURCE_SUPPLY);
#else
LL_PWR_ConfigSupply(LL_PWR_LDO_SUPPLY);
#endif
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE0);
return 0;
}

View File

@@ -387,8 +387,8 @@ static int gsm_mux_send_data_msg(struct gsm_mux *mux, bool cmd,
hdr[3] = (size << 1) | EA;
pos = 4;
} else {
hdr[3] = (size >> 7);
hdr[4] = (size & 127) << 1;
hdr[3] = (size & 127) << 1;
hdr[4] = (size >> 7);
pos = 5;
}
@@ -610,7 +610,8 @@ static void ctrl_msg_cleanup(struct gsm_control_msg *entry, bool pending)
/* T2 timeout is for control message retransmits */
static void gsm_mux_t2_timeout(struct k_work *work)
{
struct gsm_mux *mux = CONTAINER_OF(work, struct gsm_mux, t2_timer);
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
struct gsm_mux *mux = CONTAINER_OF(dwork, struct gsm_mux, t2_timer);
uint32_t current_time = k_uptime_get_32();
struct gsm_control_msg *entry, *next;

View File

@@ -636,8 +636,8 @@ static int ssd16xx_controller_init(const struct device *dev)
static int ssd16xx_init(const struct device *dev)
{
const struct ssd16xx_config *config = dev->config;
struct ssd16xx_data *driver = dev->data;
const struct ssd16xx_config *config = driver->config;
LOG_DBG("");

View File

@@ -217,8 +217,9 @@ static void invoke_link_cb(const struct device *dev)
static void monitor_work_handler(struct k_work *work)
{
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
struct phy_mii_dev_data *const data =
CONTAINER_OF(work, struct phy_mii_dev_data, monitor_work);
CONTAINER_OF(dwork, struct phy_mii_dev_data, monitor_work);
const struct device *dev = data->dev;
int rc;

View File

@@ -30,17 +30,6 @@ LOG_MODULE_REGISTER(flash_stm32, CONFIG_FLASH_LOG_LEVEL);
#define STM32_FLASH_TIMEOUT \
(2 * DT_PROP(DT_INST(0, st_stm32_nv_flash), max_erase_time))
#if defined(FLASH_NSSR_NSBSY) /* For STM32L5x in non-secure mode */
#define FLASH_SECURITY_NS
#elif defined(FLASH_SECSR_SECBSY) /* For STM32L5x in secured mode */
#error Flash is not supported in secure mode
#define FLASH_SECURITY_SEC
#else
#define FLASH_SECURITY_NA /* For series which does not have
* secured or non-secured mode
*/
#endif
static const struct flash_parameters flash_stm32_parameters = {
.write_block_size = FLASH_STM32_WRITE_BLOCK_SIZE,
/* Some SoCs (L0/L1) use an EEPROM under the hood. Distinguish
@@ -89,37 +78,11 @@ static inline void _flash_stm32_sem_give(const struct device *dev)
#if !defined(CONFIG_SOC_SERIES_STM32WBX)
static int flash_stm32_check_status(const struct device *dev)
{
uint32_t const error =
#if defined(FLASH_FLAG_PGAERR)
FLASH_FLAG_PGAERR |
#endif
#if defined(FLASH_FLAG_RDERR)
FLASH_FLAG_RDERR |
#endif
#if defined(FLASH_FLAG_PGPERR)
FLASH_FLAG_PGPERR |
#endif
#if defined(FLASH_FLAG_PGSERR)
FLASH_FLAG_PGSERR |
#endif
#if defined(FLASH_FLAG_OPERR)
FLASH_FLAG_OPERR |
#endif
#if defined(FLASH_FLAG_PROGERR)
FLASH_FLAG_PROGERR |
#endif
#if defined(FLASH_FLAG_PGERR)
FLASH_FLAG_PGERR |
#endif
FLASH_FLAG_WRPERR;
#if defined(FLASH_SECURITY_NS)
if (FLASH_STM32_REGS(dev)->NSSR & error) {
LOG_DBG("Status: 0x%08x", FLASH_STM32_REGS(dev)->NSSR & error);
#else /* FLASH_SECURITY_SEC | FLASH_SECURITY_NA */
if (FLASH_STM32_REGS(dev)->SR & error) {
LOG_DBG("Status: 0x%08x", FLASH_STM32_REGS(dev)->SR & error);
#endif /* FLASH_SECURITY_NS */
if (FLASH_STM32_REGS(dev)->FLASH_STM32_SR & FLASH_STM32_SR_ERRORS) {
LOG_DBG("Status: 0x%08lx",
FLASH_STM32_REGS(dev)->FLASH_STM32_SR &
FLASH_STM32_SR_ERRORS);
return -EIO;
}
@@ -131,21 +94,21 @@ int flash_stm32_wait_flash_idle(const struct device *dev)
{
int64_t timeout_time = k_uptime_get() + STM32_FLASH_TIMEOUT;
int rc;
uint32_t busy_flags;
rc = flash_stm32_check_status(dev);
if (rc < 0) {
return -EIO;
}
#if defined(FLASH_SECURITY_NS)
while ((FLASH_STM32_REGS(dev)->NSSR & FLASH_FLAG_BSY)) {
#else /* FLASH_SECURITY_SEC | FLASH_SECURITY_NA */
#if defined(FLASH_SR_BSY1)
/* Applicable for STM32G0 series */
while ((FLASH_STM32_REGS(dev)->SR & FLASH_SR_BSY1)) {
#else
while ((FLASH_STM32_REGS(dev)->SR & FLASH_SR_BSY)) {
busy_flags = FLASH_STM32_SR_BUSY;
/* Some Series can't modify FLASH_CR reg while CFGBSY is set. Wait as well */
#if defined(FLASH_STM32_SR_CFGBSY)
busy_flags |= FLASH_STM32_SR_CFGBSY;
#endif
#endif /* FLASH_SECURITY_NS */
while ((FLASH_STM32_REGS(dev)->FLASH_STM32_SR & busy_flags)) {
if (k_uptime_get() > timeout_time) {
LOG_ERR("Timeout! val: %d", STM32_FLASH_TIMEOUT);
return -EIO;

View File

@@ -33,9 +33,142 @@ struct flash_stm32_priv {
/* as flash node property 'write-block-size' */
#endif
/* Differentiate between arm trust-zone non-secure/secure, and others. */
#if defined(FLASH_NSSR_NSBSY) /* For mcu w. TZ in non-secure mode */
#define FLASH_SECURITY_NS
#define FLASH_STM32_SR NSSR
#elif defined(FLASH_SECSR_SECBSY) /* For mcu w. TZ in secured mode */
#error Flash is not supported in secure mode
#define FLASH_SECURITY_SEC
#else
#define FLASH_SECURITY_NA /* For series which does not have
* secured or non-secured mode
*/
#define FLASH_STM32_SR SR
#endif
#define FLASH_STM32_PRIV(dev) ((struct flash_stm32_priv *)((dev)->data))
#define FLASH_STM32_REGS(dev) (FLASH_STM32_PRIV(dev)->regs)
/* Redefintions of flags and masks to harmonize stm32 series: */
#if defined(CONFIG_SOC_SERIES_STM32G0X)
#if defined(FLASH_FLAG_BSY2)
#define FLASH_STM32_SR_BUSY (FLASH_FLAG_BSY1 | FLASH_FLAG_BSY2);
#else
#define FLASH_STM32_SR_BUSY (FLASH_SR_BSY1)
#endif /* defined(FLASH_FLAG_BSY2) */
#else
#define FLASH_STM32_SR_BUSY (FLASH_FLAG_BSY)
#endif
#if defined(CONFIG_SOC_SERIES_STM32G0X)
#define FLASH_STM32_SR_CFGBSY (FLASH_SR_CFGBSY)
#elif defined(FLASH_FLAG_CFGBSY)
#define FLASH_STM32_SR_CFGBSY (FLASH_FLAG_CFGBSY)
#endif
#if defined(CONFIG_SOC_SERIES_STM32G0X)
/* STM32G0 HAL FLASH_FLAG_x don't represent bit-masks, need FLASH_SR_x instead */
#define FLASH_STM32_SR_OPERR FLASH_SR_OPERR
#define FLASH_STM32_SR_PGERR 0
#define FLASH_STM32_SR_PROGERR FLASH_SR_PROGERR
#define FLASH_STM32_SR_WRPERR FLASH_SR_WRPERR
#define FLASH_STM32_SR_PGAERR FLASH_SR_PGAERR
#define FLASH_STM32_SR_SIZERR FLASH_SR_SIZERR
#define FLASH_STM32_SR_PGSERR FLASH_SR_PGSERR
#define FLASH_STM32_SR_MISERR FLASH_SR_MISERR
#define FLASH_STM32_SR_FASTERR FLASH_SR_FASTERR
#if defined(FLASH_SR_RDERR)
#define FLASH_STM32_SR_RDERR FLASH_SR_RDERR
#else
#define FLASH_STM32_SR_RDERR 0
#endif
#define FLASH_STM32_SR_PGPERR 0
#else /* !defined(CONFIG_SOC_SERIES_STM32G0X) */
#if defined(FLASH_FLAG_OPERR)
#define FLASH_STM32_SR_OPERR FLASH_FLAG_OPERR
#else
#define FLASH_STM32_SR_OPERR 0
#endif
#if defined(FLASH_FLAG_PGERR)
#define FLASH_STM32_SR_PGERR FLASH_FLAG_PGERR
#else
#define FLASH_STM32_SR_PGERR 0
#endif
#if defined(FLASH_FLAG_PROGERR)
#define FLASH_STM32_SR_PROGERR FLASH_FLAG_PROGERR
#else
#define FLASH_STM32_SR_PROGERR 0
#endif
#if defined(FLASH_FLAG_WRPERR)
#define FLASH_STM32_SR_WRPERR FLASH_FLAG_WRPERR
#else
#define FLASH_STM32_SR_WRPERR 0
#endif
#if defined(FLASH_FLAG_PGAERR)
#define FLASH_STM32_SR_PGAERR FLASH_FLAG_PGAERR
#else
#define FLASH_STM32_SR_PGAERR 0
#endif
#if defined(FLASH_FLAG_SIZERR)
#define FLASH_STM32_SR_SIZERR FLASH_FLAG_SIZERR
#else
#define FLASH_STM32_SR_SIZERR 0
#endif
#if defined(FLASH_FLAG_PGSERR)
#define FLASH_STM32_SR_PGSERR FLASH_FLAG_PGSERR
#else
#define FLASH_STM32_SR_PGSERR 0
#endif
#if defined(FLASH_FLAG_MISERR)
#define FLASH_STM32_SR_MISERR FLASH_FLAG_MISERR
#else
#define FLASH_STM32_SR_MISERR 0
#endif
#if defined(FLASH_FLAG_FASTERR)
#define FLASH_STM32_SR_FASTERR FLASH_FLAG_FASTERR
#else
#define FLASH_STM32_SR_FASTERR 0
#endif
#if defined(FLASH_FLAG_RDERR)
#define FLASH_STM32_SR_RDERR FLASH_FLAG_RDERR
#else
#define FLASH_STM32_SR_RDERR 0
#endif
#if defined(FLASH_FLAG_PGPERR)
#define FLASH_STM32_SR_PGPERR FLASH_FLAG_PGPERR
#else
#define FLASH_STM32_SR_PGPERR 0
#endif
#endif /* !defined(CONFIG_SOC_SERIES_STM32G0X) */
#define FLASH_STM32_SR_ERRORS (FLASH_STM32_SR_OPERR | \
FLASH_STM32_SR_PGERR | \
FLASH_STM32_SR_PROGERR | \
FLASH_STM32_SR_WRPERR | \
FLASH_STM32_SR_PGAERR | \
FLASH_STM32_SR_SIZERR | \
FLASH_STM32_SR_PGSERR | \
FLASH_STM32_SR_MISERR | \
FLASH_STM32_SR_FASTERR | \
FLASH_STM32_SR_RDERR | \
FLASH_STM32_SR_PGPERR)
#ifdef CONFIG_FLASH_PAGE_LAYOUT
static inline bool flash_stm32_range_exists(const struct device *dev,
off_t offset,

View File

@@ -21,12 +21,30 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
#include "flash_stm32.h"
#define STM32G0X_PAGE_SHIFT 11
/* FLASH_DBANK_SUPPORT is defined in the HAL for all G0Bx and G0C1 SoCs,
* while only those with 256KiB and 512KiB Flash have two banks.
*/
#if defined(FLASH_DBANK_SUPPORT) && (CONFIG_FLASH_SIZE > (128))
#define STM32G0_DBANK_SUPPORT
#endif
#if defined(STM32G0_DBANK_SUPPORT)
#define STM32G0_BANK_COUNT 2
#define STM32G0_BANK2_START_PAGE_NR 256
#else
#define STM32G0_BANK_COUNT 1
#endif
#define STM32G0_FLASH_SIZE (FLASH_SIZE)
#define STM32G0_FLASH_PAGE_SIZE (FLASH_PAGE_SIZE)
#define STM32G0_PAGES_PER_BANK \
((STM32G0_FLASH_SIZE / STM32G0_FLASH_PAGE_SIZE) / STM32G0_BANK_COUNT)
/*
* offset and len must be aligned on 8 for write,
* positive and not beyond end of flash
* On dual-bank SoCs memory accesses starting on the first bank and continuing
* beyond the first bank into the second bank are allowed.
*/
bool flash_stm32_valid_range(const struct device *dev, off_t offset,
uint32_t len,
@@ -36,14 +54,6 @@ bool flash_stm32_valid_range(const struct device *dev, off_t offset,
flash_stm32_range_exists(dev, offset, len);
}
/*
* STM32G0xx devices can have up to 64 2K pages
*/
static unsigned int get_page(off_t offset)
{
return offset >> STM32G0X_PAGE_SHIFT;
}
static inline void flush_cache(FLASH_TypeDef *regs)
{
if (regs->ACR & FLASH_ACR_ICEN) {
@@ -101,11 +111,12 @@ static int write_dword(const struct device *dev, off_t offset, uint64_t val)
return rc;
}
static int erase_page(const struct device *dev, unsigned int page)
static int erase_page(const struct device *dev, unsigned int offset)
{
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
uint32_t tmp;
int rc;
int page;
/* if the control register is locked, do not fail silently */
if (regs->CR & FLASH_CR_LOCK) {
@@ -125,16 +136,32 @@ static int erase_page(const struct device *dev, unsigned int page)
*/
flush_cache(regs);
/* Set the PER bit and select the page you wish to erase */
regs->CR |= FLASH_CR_PER;
regs->CR &= ~FLASH_CR_PNB_Msk;
regs->CR |= ((page % 256) << 3);
/* Set the STRT bit */
regs->CR |= FLASH_CR_STRT;
/* flush the register write */
tmp = regs->CR;
page = offset / STM32G0_FLASH_PAGE_SIZE;
#if defined(STM32G0_DBANK_SUPPORT)
bool swap_enabled = (regs->OPTR & FLASH_OPTR_nSWAP_BANK) == 0;
/* big page-nr w/o swap or small page-nr w/ swap indicate bank2 */
if ((page >= STM32G0_PAGES_PER_BANK) != swap_enabled) {
page = (page % STM32G0_PAGES_PER_BANK) + STM32G0_BANK2_START_PAGE_NR;
tmp |= FLASH_CR_BKER;
LOG_DBG("Erase page %d on bank 2", page);
} else {
page = page % STM32G0_PAGES_PER_BANK;
tmp &= ~FLASH_CR_BKER;
LOG_DBG("Erase page %d on bank 1", page);
}
#endif
/* Set the PER bit and select the page you wish to erase */
tmp |= FLASH_CR_PER;
tmp &= ~FLASH_CR_PNB_Msk;
tmp |= ((page << FLASH_CR_PNB_Pos) & FLASH_CR_PNB_Msk);
/* Set the STRT bit and write the reg */
tmp |= FLASH_CR_STRT;
regs->CR = tmp;
/* Wait for the BSY bit */
rc = flash_stm32_wait_flash_idle(dev);
@@ -148,11 +175,11 @@ int flash_stm32_block_erase_loop(const struct device *dev,
unsigned int offset,
unsigned int len)
{
int i, rc = 0;
unsigned int addr = offset;
int rc = 0;
i = get_page(offset);
for (; i <= get_page(offset + len - 1) ; ++i) {
rc = erase_page(dev, i);
for (; addr <= offset + len - 1 ; addr += STM32G0_FLASH_PAGE_SIZE) {
rc = erase_page(dev, addr);
if (rc < 0) {
break;
}
@@ -176,6 +203,16 @@ int flash_stm32_write_range(const struct device *dev, unsigned int offset,
return rc;
}
/*
* The address space is always continuous, even though a subset of G0 SoCs has
* two flash banks.
* Only the "physical" flash page-NRs are not continuous on those SoCs.
* As a result the page numbers used in the zephyr flash api differs
* from the "physical" flash page number.
* The first is equal to the address offset divided by the page size, while
* "physical" pages are numbered starting with 0 on bank1 and 256 on bank2.
* As a result only a single homogeneous flash page layout needs to be defined.
*/
void flash_stm32_page_layout(const struct device *dev,
const struct flash_pages_layout **layout,
size_t *layout_size)
@@ -188,10 +225,24 @@ void flash_stm32_page_layout(const struct device *dev,
ARG_UNUSED(dev);
if (stm32g0_flash_layout.pages_count == 0) {
stm32g0_flash_layout.pages_count = FLASH_SIZE / FLASH_PAGE_SIZE;
stm32g0_flash_layout.pages_size = FLASH_PAGE_SIZE;
stm32g0_flash_layout.pages_count =
STM32G0_FLASH_SIZE / STM32G0_FLASH_PAGE_SIZE;
stm32g0_flash_layout.pages_size = STM32G0_FLASH_PAGE_SIZE;
}
*layout = &stm32g0_flash_layout;
*layout_size = 1;
}
/* Override weak function */
int flash_stm32_check_configuration(void)
{
#if defined(STM32G0_DBANK_SUPPORT) && (CONFIG_FLASH_SIZE == 256)
/* Single bank mode not supported on dual bank SoCs with 256kiB flash */
if ((regs->OPTR & FLASH_OPTR_DUAL_BANK) == 0) {
LOG_ERR("Single bank configuration not supported by the driver");
return -ENOTSUP;
}
#endif
return 0;
}

View File

@@ -410,7 +410,10 @@ static void sx126x_dio1_irq_work_handler(struct k_work *work)
Radio.IrqProcess();
}
sx126x_dio1_irq_enable(&dev_data);
/* Re-enable the interrupt if we are not in sleep mode */
if (dev_data.mode != MODE_SLEEP) {
sx126x_dio1_irq_enable(&dev_data);
}
}
static int sx126x_lora_init(const struct device *dev)

View File

@@ -241,8 +241,8 @@ static const struct mdm_control_pinconfig pinconfig[] = {
#define MDM_SEND_OK_ENABLED 0
#define MDM_SEND_OK_DISABLED 1
#define MDM_CMD_SEND_TIMEOUT K_SECONDS(5)
#define MDM_IP_SEND_RX_TIMEOUT K_SECONDS(60)
#define MDM_CMD_SEND_TIMEOUT K_SECONDS(6)
#define MDM_IP_SEND_RX_TIMEOUT K_SECONDS(62)
#define MDM_SOCK_NOTIF_DELAY K_MSEC(150)
#define MDM_CMD_CONN_TIMEOUT K_SECONDS(31)
@@ -1317,7 +1317,7 @@ static int send_data(struct hl7800_socket *sock, struct net_pkt *pkt)
/* Send EOF pattern to terminate data */
k_sem_reset(&sock->sock_send_sem);
mdm_receiver_send(&ictx.mdm_ctx, EOF_PATTERN, strlen(EOF_PATTERN));
ret = k_sem_take(&sock->sock_send_sem, MDM_CMD_SEND_TIMEOUT);
ret = k_sem_take(&sock->sock_send_sem, MDM_IP_SEND_RX_TIMEOUT);
if (ret == 0) {
ret = ictx.last_error;
} else if (ret == -EAGAIN) {

View File

@@ -130,8 +130,8 @@ static bool mux_is_active(struct modem_iface *iface)
bool active = false;
#if defined(CONFIG_UART_MUX_DEVICE_NAME)
const char *mux_name = CONFIG_UART_MUX_DEVICE_NAME;
active = (mux_name == iface->dev->name);
active = strncmp(CONFIG_UART_MUX_DEVICE_NAME, iface->dev->name,
sizeof(CONFIG_UART_MUX_DEVICE_NAME) - 1) == 0;
#endif /* CONFIG_UART_MUX_DEVICE_NAME */
return active;

View File

@@ -186,7 +186,8 @@ static int uart_sam0_tx_halt(struct uart_sam0_dev_data *dev_data)
static void uart_sam0_tx_timeout(struct k_work *work)
{
struct uart_sam0_dev_data *dev_data = CONTAINER_OF(work,
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
struct uart_sam0_dev_data *dev_data = CONTAINER_OF(dwork,
struct uart_sam0_dev_data, tx_timeout_work);
uart_sam0_tx_halt(dev_data);

View File

@@ -51,6 +51,34 @@ LOG_MODULE_REGISTER(uart_stm32);
#define UART_STRUCT(dev) \
((USART_TypeDef *)(DEV_CFG(dev))->uconf.base)
#if HAS_LPUART_1
#ifdef USART_PRESC_PRESCALER
uint32_t lpuartdiv_calc(const uint64_t clock_rate, const uint16_t presc_idx,
const uint32_t baud_rate)
{
uint64_t lpuartdiv;
lpuartdiv = clock_rate / LPUART_PRESCALER_TAB[presc_idx];
lpuartdiv *= LPUART_LPUARTDIV_FREQ_MUL;
lpuartdiv += baud_rate / 2;
lpuartdiv /= baud_rate;
return (uint32_t)lpuartdiv;
}
#else
uint32_t lpuartdiv_calc(const uint64_t clock_rate, const uint32_t baud_rate)
{
uint64_t lpuartdiv;
lpuartdiv = clock_rate * LPUART_LPUARTDIV_FREQ_MUL;
lpuartdiv += baud_rate / 2;
lpuartdiv /= baud_rate;
return (uint32_t)lpuartdiv;
}
#endif /* USART_PRESC_PRESCALER */
#endif /* HAS_LPUART_1 */
#define TIMEOUT 1000
#ifdef CONFIG_PM
@@ -92,13 +120,39 @@ static inline void uart_stm32_set_baudrate(const struct device *dev,
return;
}
#if HAS_LPUART_1
if (IS_LPUART_INSTANCE(UartInstance)) {
uint32_t lpuartdiv;
#ifdef USART_PRESC_PRESCALER
uint8_t presc_idx;
uint32_t presc_val;
for (presc_idx = 0; presc_idx < ARRAY_SIZE(LPUART_PRESCALER_TAB); presc_idx++) {
lpuartdiv = lpuartdiv_calc(clock_rate, presc_idx, baud_rate);
if (lpuartdiv >= LPUART_BRR_MIN_VALUE && lpuartdiv <= LPUART_BRR_MASK) {
break;
}
}
if (presc_idx == ARRAY_SIZE(LPUART_PRESCALER_TAB)) {
LOG_ERR("Unable to set %s to %d", dev->name, baud_rate);
return;
}
presc_val = presc_idx << USART_PRESC_PRESCALER_Pos;
LL_LPUART_SetPrescaler(UartInstance, presc_val);
#else
lpuartdiv = lpuartdiv_calc(clock_rate, baud_rate);
if (lpuartdiv < LPUART_BRR_MIN_VALUE || lpuartdiv > LPUART_BRR_MASK) {
LOG_ERR("Unable to set %s to %d", dev->name, baud_rate);
return;
}
#endif /* USART_PRESC_PRESCALER */
LL_LPUART_SetBaudRate(UartInstance,
clock_rate,
#ifdef USART_PRESC_PRESCALER
LL_USART_PRESCALER_DIV1,
presc_val,
#endif
baud_rate);
} else {
@@ -473,15 +527,32 @@ static void uart_stm32_poll_out(const struct device *dev,
unsigned char c)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
#ifdef CONFIG_PM
struct uart_stm32_data *data = DEV_DATA(dev);
#endif
int key;
/* Wait for TXE flag to be raised */
while (!LL_USART_IsActiveFlag_TXE(UartInstance)) {
/* Wait for TXE flag to be raised
* When TXE flag is raised, we lock interrupts to prevent interrupts (notably that of usart)
* or thread switch. Then, we can safely send our character. The character sent will be
* interlaced with the characters potentially send with interrupt transmission API
*/
while (1) {
if (LL_USART_IsActiveFlag_TXE(UartInstance)) {
key = irq_lock();
if (LL_USART_IsActiveFlag_TXE(UartInstance)) {
break;
}
irq_unlock(key);
}
}
#ifdef CONFIG_PM
struct uart_stm32_data *data = DEV_DATA(dev);
if (!data->tx_poll_stream_on) {
/* If an interrupt transmission is in progress, the pm constraint is already managed by the
* call of uart_stm32_irq_tx_[en|dis]able
*/
if (!data->tx_poll_stream_on && !data->tx_int_stream_on) {
data->tx_poll_stream_on = true;
/* Don't allow system to suspend until stream
@@ -497,6 +568,7 @@ static void uart_stm32_poll_out(const struct device *dev,
#endif /* CONFIG_PM */
LL_USART_TransmitData8(UartInstance, (uint8_t)c);
irq_unlock(key);
}
static int uart_stm32_err_check(const struct device *dev)
@@ -520,6 +592,16 @@ static int uart_stm32_err_check(const struct device *dev)
err |= UART_ERROR_FRAMING;
}
#if !defined(CONFIG_SOC_SERIES_STM32F0X) || defined(USART_LIN_SUPPORT)
if (LL_USART_IsActiveFlag_LBD(UartInstance)) {
err |= UART_BREAK;
}
if (err & UART_BREAK) {
LL_USART_ClearFlag_LBD(UartInstance);
}
#endif
if (err & UART_ERROR_OVERRUN) {
LL_USART_ClearFlag_ORE(UartInstance);
}
@@ -531,7 +613,6 @@ static int uart_stm32_err_check(const struct device *dev)
if (err & UART_ERROR_FRAMING) {
LL_USART_ClearFlag_FE(UartInstance);
}
/* Clear noise error as well,
* it is not represented by the errors enum
*/
@@ -556,6 +637,14 @@ static int uart_stm32_fifo_fill(const struct device *dev,
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
uint8_t num_tx = 0U;
int key;
if (!LL_USART_IsActiveFlag_TXE(UartInstance)) {
return num_tx;
}
/* Lock interrupts to prevent nested interrupts or thread switch */
key = irq_lock();
while ((size - num_tx > 0) &&
LL_USART_IsActiveFlag_TXE(UartInstance)) {
@@ -565,6 +654,8 @@ static int uart_stm32_fifo_fill(const struct device *dev,
LL_USART_TransmitData8(UartInstance, tx_data[num_tx++]);
}
irq_unlock(key);
return num_tx;
}
@@ -593,25 +684,44 @@ static int uart_stm32_fifo_read(const struct device *dev, uint8_t *rx_data,
static void uart_stm32_irq_tx_enable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
#ifdef CONFIG_PM
struct uart_stm32_data *data = DEV_DATA(dev);
int key;
#endif
#ifdef CONFIG_PM
key = irq_lock();
data->tx_poll_stream_on = false;
data->tx_int_stream_on = true;
uart_stm32_pm_constraint_set(dev);
#endif
LL_USART_EnableIT_TC(UartInstance);
#ifdef CONFIG_PM
irq_unlock(key);
#endif
}
static void uart_stm32_irq_tx_disable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
#ifdef CONFIG_PM
struct uart_stm32_data *data = DEV_DATA(dev);
int key;
key = irq_lock();
#endif
LL_USART_DisableIT_TC(UartInstance);
#ifdef CONFIG_PM
data->tx_int_stream_on = false;
uart_stm32_pm_constraint_release(dev);
#endif
#ifdef CONFIG_PM
irq_unlock(key);
#endif
}
static int uart_stm32_irq_tx_ready(const struct device *dev)
@@ -1234,7 +1344,8 @@ static int uart_stm32_async_tx_abort(const struct device *dev)
static void uart_stm32_async_rx_timeout(struct k_work *work)
{
struct uart_dma_stream *rx_stream = CONTAINER_OF(work,
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
struct uart_dma_stream *rx_stream = CONTAINER_OF(dwork,
struct uart_dma_stream, timeout_work);
struct uart_stm32_data *data = CONTAINER_OF(rx_stream,
struct uart_stm32_data, dma_rx);
@@ -1251,7 +1362,8 @@ static void uart_stm32_async_rx_timeout(struct k_work *work)
static void uart_stm32_async_tx_timeout(struct k_work *work)
{
struct uart_dma_stream *tx_stream = CONTAINER_OF(work,
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
struct uart_dma_stream *tx_stream = CONTAINER_OF(dwork,
struct uart_dma_stream, timeout_work);
struct uart_stm32_data *data = CONTAINER_OF(tx_stream,
struct uart_stm32_data, dma_tx);

View File

@@ -74,6 +74,7 @@ struct uart_stm32_data {
#endif
#ifdef CONFIG_PM
bool tx_poll_stream_on;
bool tx_int_stream_on;
bool pm_constraint_on;
#endif
};

View File

@@ -288,8 +288,10 @@ static int spi_nrfx_pm_control(const struct device *dev,
break;
case PM_DEVICE_ACTION_SUSPEND:
nrfx_spi_uninit(&config->spi);
data->initialized = false;
if (data->initialized) {
nrfx_spi_uninit(&config->spi);
data->initialized = false;
}
break;
default:

View File

@@ -345,8 +345,10 @@ static int spim_nrfx_pm_control(const struct device *dev,
break;
case PM_DEVICE_ACTION_SUSPEND:
nrfx_spim_uninit(&config->spim);
data->initialized = false;
if (data->initialized) {
nrfx_spim_uninit(&config->spim);
data->initialized = false;
}
break;
default:

View File

@@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT qemu_ivshmem
#define LOG_LEVEL CONFIG_IVSHMEM_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(ivshmem);
@@ -223,25 +225,42 @@ static const struct ivshmem_driver_api ivshmem_api = {
static int ivshmem_init(const struct device *dev)
{
struct ivshmem *data = dev->data;
static bool bdf_lookup_done;
data->bdf = pcie_bdf_lookup(PCIE_ID(IVSHMEM_VENDOR_ID,
IVSHMEM_DEVICE_ID));
if (data->bdf == PCIE_BDF_NONE) {
LOG_WRN("ivshmem device not found");
if ((data->bdf == PCIE_BDF_NONE) && bdf_lookup_done) {
LOG_ERR("One instance of ivshmem with pcie_bdf_lookup() already initialized.\n"
"Using more than one with PCIE_BDF_NONE parameter might conflict\n"
"with already initialized instances.");
return -ENOTSUP;
}
if ((data->bdf == PCIE_BDF_NONE) && !bdf_lookup_done) {
if (data->dev_ven_id) {
data->bdf = pcie_bdf_lookup(data->dev_ven_id);
} else {
data->bdf = pcie_bdf_lookup(PCIE_ID(IVSHMEM_VENDOR_ID, IVSHMEM_DEVICE_ID));
}
if (data->bdf == PCIE_BDF_NONE) {
LOG_WRN("ivshmem device not found");
return -ENOTSUP;
}
}
LOG_DBG("ivshmem found at bdf 0x%x", data->bdf);
bdf_lookup_done = true;
if (!ivshmem_configure(dev)) {
return -EIO;
}
return 0;
}
static struct ivshmem ivshmem_data;
#define IVSHMEM_DEVICE_INIT(n) \
static struct ivshmem ivshmem_data_##n = { \
.bdf = DT_INST_REG_ADDR_BY_IDX(n, 0), \
.dev_ven_id = DT_INST_REG_SIZE_BY_IDX(n, 0) \
}; \
DEVICE_DT_INST_DEFINE(n, &ivshmem_init, NULL, \
&ivshmem_data_##n, NULL, \
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&ivshmem_api);
DEVICE_DEFINE(ivshmem, CONFIG_IVSHMEM_DEV_NAME,
ivshmem_init, NULL, &ivshmem_data, NULL,
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &ivshmem_api);
DT_INST_FOREACH_STATUS_OKAY(IVSHMEM_DEVICE_INIT)

View File

@@ -25,6 +25,7 @@ struct ivshmem_param {
struct ivshmem {
DEVICE_MMIO_RAM;
pcie_bdf_t bdf;
uint32_t dev_ven_id;
uintptr_t shmem;
size_t size;
#ifdef CONFIG_IVSHMEM_DOORBELL

View File

@@ -83,6 +83,8 @@ static int iwdg_stm32_setup(const struct device *dev, uint8_t options)
if (options & WDT_OPT_PAUSE_HALTED_BY_DBG) {
#if defined(CONFIG_SOC_SERIES_STM32F0X)
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_DBGMCU);
#elif defined(CONFIG_SOC_SERIES_STM32G0X)
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DBGMCU);
#elif defined(CONFIG_SOC_SERIES_STM32L0X)
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_DBGMCU);
#endif

View File

@@ -418,7 +418,8 @@ MODEM_CMD_DEFINE(on_cmd_cipsta)
static void esp_ip_addr_work(struct k_work *work)
{
struct esp_data *dev = CONTAINER_OF(work, struct esp_data,
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
struct esp_data *dev = CONTAINER_OF(dwork, struct esp_data,
ip_addr_work);
int ret;

View File

@@ -169,6 +169,15 @@ void esp_socket_rx(struct esp_socket *sock, struct net_buf *buf,
return;
}
#ifdef CONFIG_NET_SOCKETS
/* We need to claim the net_context mutex here so that the ordering of
* net_context and socket mutex claims matches the TX code path. Failure
* to do so can lead to deadlocks.
*/
if (sock->context->cond.lock) {
k_mutex_lock(sock->context->cond.lock, K_FOREVER);
}
#endif /* CONFIG_NET_SOCKETS */
k_mutex_lock(&sock->lock, K_FOREVER);
if (sock->recv_cb) {
sock->recv_cb(sock->context, pkt, NULL, NULL,
@@ -179,6 +188,11 @@ void esp_socket_rx(struct esp_socket *sock, struct net_buf *buf,
net_pkt_unref(pkt);
}
k_mutex_unlock(&sock->lock);
#ifdef CONFIG_NET_SOCKETS
if (sock->context->cond.lock) {
k_mutex_unlock(sock->context->cond.lock);
}
#endif /* CONFIG_NET_SOCKETS */
}
void esp_socket_close(struct esp_socket *sock)

View File

@@ -91,10 +91,11 @@ static void eswifi_off_read_work(struct k_work *work)
int next_timeout_ms = 100;
int err, len;
char *data;
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
LOG_DBG("");
socket = CONTAINER_OF(work, struct eswifi_off_socket, read_work);
socket = CONTAINER_OF(dwork, struct eswifi_off_socket, read_work);
eswifi = eswifi_socket_to_dev(socket);
eswifi_lock(eswifi);

View File

@@ -63,7 +63,7 @@
clk_lsi: clk-lsi {
#clock-cells = <0>;
compatible = "fixed-clock";
clock-frequency = <DT_FREQ_K(32)>;
clock-frequency = <DT_FREQ_K(37)>;
status = "disabled";
};

View File

@@ -0,0 +1,8 @@
# Copyright (c) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
description: ivShMem device properties
compatible: "qemu,ivshmem"
include: base.yaml

View File

@@ -56,6 +56,7 @@
MAKE_REG_HELPER(cntfrq_el0);
MAKE_REG_HELPER(cnthctl_el2);
MAKE_REG_HELPER(cnthp_ctl_el2);
MAKE_REG_HELPER(cnthps_ctl_el2);
MAKE_REG_HELPER(cntv_ctl_el0)
MAKE_REG_HELPER(cntv_cval_el0)
MAKE_REG_HELPER(cntvct_el0);

View File

@@ -304,7 +304,7 @@ GROUP_START(ITCM)
} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)
__itcm_size = __itcm_end - __itcm_start;
__itcm_rom_start = LOADADDR(_ITCM_SECTION_NAME);
__itcm_load_start = LOADADDR(_ITCM_SECTION_NAME);
GROUP_END(ITCM)
#endif
@@ -339,7 +339,7 @@ GROUP_START(DTCM)
__dtcm_end = .;
__dtcm_data_rom_start = LOADADDR(_DTCM_DATA_SECTION_NAME);
__dtcm_data_load_start = LOADADDR(_DTCM_DATA_SECTION_NAME);
GROUP_END(DTCM)
#endif

32
include/arch/x86/cpuid.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 Intel Corp.
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_ARCH_X86_CPUID_H_
#define ZEPHYR_INCLUDE_ARCH_X86_CPUID_H_
#ifndef _ASMLANGUAGE
#ifdef __cplusplus
extern "C" {
#endif
#define CPUID_BASIC_INFO_1 0x01
#define CPUID_EXTENDED_FEATURES_LVL 0x07
#define CPUID_EXTENDED_TOPOLOGY_ENUMERATION 0x0B
#define CPUID_EXTENDED_TOPOLOGY_ENUMERATION_V2 0x1F
/* Bits to check in CPUID extended features */
#define CPUID_SPEC_CTRL_SSBD BIT(31)
#define CPUID_SPEC_CTRL_IBRS BIT(26)
uint32_t z_x86_cpuid_extended_features(void);
uint8_t z_x86_cpuid_get_current_physical_apic_id(void);
#ifdef __cplusplus
}
#endif
#endif /* _ASMLANGUAGE */
#endif /* ZEPHYR_INCLUDE_ARCH_X86_CPUID_H_ */

View File

@@ -1599,6 +1599,13 @@ struct bt_gatt_subscribe_params {
#endif /* CONFIG_BT_GATT_AUTO_DISCOVER_CCC */
/** Subscribe value */
uint16_t value;
#if defined(CONFIG_BT_SMP)
/** Minimum required security for received notification. Notifications
* and indications received over a connection with a lower security
* level are silently discarded.
*/
bt_security_t min_security;
#endif
/** Subscription flags */
ATOMIC_DEFINE(flags, BT_GATT_SUBSCRIBE_NUM_FLAGS);

View File

@@ -302,10 +302,10 @@ struct can_timing {
* @typedef can_tx_callback_t
* @brief Define the application callback handler function signature
*
* @param error_flags status of the performed send operation
* @param error status of the performed send operation
* @param arg argument that was passed when the message was sent
*/
typedef void (*can_tx_callback_t)(uint32_t error_flags, void *arg);
typedef void (*can_tx_callback_t)(int error, void *arg);
/**
* @typedef can_rx_callback_t

View File

@@ -207,7 +207,7 @@
#endif
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32f1_pll_clock, okay)
#define STM32_PLL_XTPRE DT_PROP(DT_NODELABEL(pll), xtre)
#define STM32_PLL_XTPRE DT_PROP(DT_NODELABEL(pll), xtpre)
#define STM32_PLL_MULTIPLIER DT_PROP(DT_NODELABEL(pll), mul)
#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32f0_pll_clock, okay) || \
DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32f100_pll_clock, okay) || \
@@ -269,6 +269,7 @@
#define STM32_PLL_SRC_MSI DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_msi))
#define STM32_PLL_SRC_MSIS DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_msis))
#define STM32_PLL_SRC_HSI DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
#define STM32_PLL_SRC_CSI DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_csi))
#define STM32_PLL_SRC_HSE DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
#define STM32_PLL_SRC_PLL2 DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(pll2))
#else

View File

@@ -256,18 +256,16 @@ extern "C" {
* @brief Writes an formatted string to the log.
*
* @details Conditionally compiled (see CONFIG_LOG_PRINTK). Function provides
* printk functionality. It is inefficient compared to standard logging
* because string formatting is performed in the call context and not deferred
* to the log processing context (@ref log_process).
* printk functionality.
*
* It is less efficient compared to standard logging because static packaging
* cannot be used in v2. When v1 is used string formatting is performed in the
* call context and not deferred to the log processing context (@ref log_process).
*
* @param fmt Formatted string to output.
* @param ap Variable parameters.
*/
void z_log_printk(const char *fmt, va_list ap);
static inline void log_printk(const char *fmt, va_list ap)
{
z_log_printk(fmt, ap);
}
void z_log_vprintk(const char *fmt, va_list ap);
/** @brief Copy transient string to a buffer from internal, logger pool.
*

View File

@@ -737,8 +737,12 @@ uint32_t log_get_strdup_pool_utilization(void);
uint32_t log_get_strdup_longest_string(void);
/** @brief Indicate to the log core that one log message has been dropped.
*
* @param buffered True if dropped message was already buffered and it is being
* dropped to free space for another message. False if message is being dropped
* because allocation failed.
*/
void z_log_dropped(void);
void z_log_dropped(bool buffered);
/** @brief Read and clear current drop indications counter.
*

View File

@@ -35,7 +35,8 @@
* | -------------- | ------------------------------------------------------- |
* | 0x06 0x09 | Byte pair indicating the start of a packet. |
* | 0x04 0x14 | Byte pair indicating the start of a continuation frame. |
* | Packet length | The combined total length of the *unencoded* body. |
* | Packet length | The combined total length of the *unencoded* body plus |
* | | the final CRC (2 bytes). Length is in Big-Endian format.|
* | Body | The actual SMP data (i.e., 8-byte header and CBOR |
* | | key-value map). |
* | CRC16 | A CRC16 of the *unencoded* body of the entire packet. |

View File

@@ -109,7 +109,6 @@ void ZSOCK_FD_SET(int fd, zsock_fd_set *set);
#ifdef CONFIG_NET_SOCKETS_POSIX_NAMES
#define fd_set zsock_fd_set
#define timeval zsock_timeval
#define FD_SETSIZE ZSOCK_FD_SETSIZE
static inline int select(int nfds, zsock_fd_set *readfds,

View File

@@ -16,36 +16,37 @@
#include <zephyr/types.h>
#ifdef CONFIG_POSIX_API
#ifdef CONFIG_NEWLIB_LIBC
#include <newlib.h>
#ifdef __NEWLIB__
#include <sys/_timeval.h>
#else
#else /* __NEWLIB__ */
#include <sys/types.h>
/* workaround for older Newlib 2.x, as it lacks sys/_timeval.h */
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
#endif /* __NEWLIB__ */
#endif /* CONFIG_POSIX_API */
#else /* CONFIG_NEWLIB_LIBC */
#ifdef CONFIG_ARCH_POSIX
#include <bits/types/struct_timeval.h>
#else
#include <sys/_timeval.h>
#endif
#endif /* CONFIG_NEWLIB_LIBC */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CONFIG_POSIX_API
/* Rely on the underlying libc definition */
#ifdef __NEWLIB__
#define zsock_timeval timeval
#else
/* workaround for older Newlib 2.x, as it lacks sys/_timeval.h */
struct zsock_timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
#endif /* __NEWLIB__ */
#else
struct zsock_timeval {
/* Using longs, as many (?) implementations seem to use it. */
long tv_sec;
long tv_usec;
};
#endif /* CONFIG_POSIX_API */
#ifdef __cplusplus
}

View File

@@ -86,6 +86,7 @@ enum pm_device_action {
* @brief Device PM info
*/
struct pm_device {
#ifdef CONFIG_PM_DEVICE_RUNTIME
/** Pointer to the device */
const struct device *dev;
/** Lock to synchronize the get/put operations */
@@ -93,18 +94,28 @@ struct pm_device {
/* Following are packed fields protected by #lock. */
/** Device pm enable flag */
bool enable : 1;
/* Device PM status flags. */
atomic_t flags;
/** Device usage count */
uint32_t usage;
/** Device power state */
enum pm_device_state state;
/** Work object for asynchronous calls */
struct k_work_delayable work;
/** Event conditional var to listen to the sync request events */
struct k_condvar condvar;
#endif /* CONFIG_PM_DEVICE_RUNTIME */
/* Device PM status flags. */
atomic_t flags;
/** Device power state */
enum pm_device_state state;
};
#ifdef CONFIG_PM_DEVICE_RUNTIME
#define INIT_PM_DEVICE_RUNTIME(obj) \
.usage = 0U, \
.lock = Z_MUTEX_INITIALIZER(obj.lock), \
.condvar = Z_CONDVAR_INITIALIZER(obj.condvar),
#else
#define INIT_PM_DEVICE_RUNTIME(obj)
#endif /* CONFIG_PM_DEVICE_RUNTIME */
/**
* @brief Utility macro to initialize #pm_device.
*
@@ -116,9 +127,7 @@ struct pm_device {
*/
#define Z_PM_DEVICE_INIT(obj, node_id) \
{ \
.usage = 0U, \
.lock = Z_MUTEX_INITIALIZER(obj.lock), \
.condvar = Z_CONDVAR_INITIALIZER(obj.condvar), \
INIT_PM_DEVICE_RUNTIME(obj) \
.state = PM_DEVICE_STATE_ACTIVE, \
.flags = ATOMIC_INIT(COND_CODE_1( \
DT_NODE_EXISTS(node_id), \

View File

@@ -3,6 +3,12 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Public interface for spinlocks
*/
#ifndef ZEPHYR_INCLUDE_SPINLOCK_H_
#define ZEPHYR_INCLUDE_SPINLOCK_H_
@@ -15,6 +21,13 @@
extern "C" {
#endif
/**
* @brief Spinlock APIs
* @defgroup spinlock_apis Spinlock APIs
* @ingroup kernel_apis
* @{
*/
struct z_spinlock_key {
int key;
};
@@ -199,6 +212,8 @@ static ALWAYS_INLINE void k_spin_release(struct k_spinlock *l)
#endif
}
/** @} */
#ifdef __cplusplus
}
#endif

View File

@@ -226,7 +226,7 @@ const union mpsc_pbuf_generic *mpsc_pbuf_claim(struct mpsc_pbuf_buffer *buffer);
* @param packet Packet.
*/
void mpsc_pbuf_free(struct mpsc_pbuf_buffer *buffer,
union mpsc_pbuf_generic *packet);
const union mpsc_pbuf_generic *packet);
/** @brief Check if there are any message pending.
*

View File

@@ -12,9 +12,6 @@
#include <stddef.h>
#include <stdarg.h>
#include <inttypes.h>
#if defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2)
#include <logging/log.h>
#endif
#ifdef __cplusplus
extern "C" {
@@ -49,18 +46,8 @@ extern "C" {
*/
#ifdef CONFIG_PRINTK
#if defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2)
#define printk(...) Z_LOG_PRINTK(__VA_ARGS__)
static inline __printf_like(1, 0) void vprintk(const char *fmt, va_list ap)
{
z_log_msg2_runtime_vcreate(CONFIG_LOG_DOMAIN_ID, NULL,
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0,
fmt, ap);
}
#else
extern __printf_like(1, 2) void printk(const char *fmt, ...);
extern __printf_like(1, 0) void vprintk(const char *fmt, va_list ap);
#endif /* defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG) */
#else
static inline __printf_like(1, 2) void printk(const char *fmt, ...)

View File

@@ -68,7 +68,7 @@ extern "C" {
* inside usb data section in the RAM.
*/
#define USBD_CFG_DATA_DEFINE(p, name) \
static __in_section(usb, data_##p, name) __used
static __in_section(usb, data_##p, name) __used __aligned(4)
/*************************************************************************
* USB configuration

View File

@@ -348,7 +348,7 @@ static inline int z_vrfy_k_poll(struct k_poll_event *events,
/* Validate the events buffer and make a copy of it in an
* allocated kernel-side buffer.
*/
if (Z_SYSCALL_VERIFY(num_events >= 0U)) {
if (Z_SYSCALL_VERIFY(num_events >= 0)) {
ret = -EINVAL;
goto out;
}

View File

@@ -552,5 +552,12 @@ void *_sbrk_r(struct _reent *r, int count)
int _gettimeofday(struct timeval *__tp, void *__tzp)
{
#ifdef CONFIG_POSIX_API
return gettimeofday(__tp, __tzp);
#else
/* Non-posix systems should not call gettimeofday() here as it will
* result in a recursive call loop and result in a stack overflow.
*/
return -1;
#endif
}

View File

@@ -224,21 +224,37 @@ int z_alloc_fd(void *obj, const struct fd_op_vtable *vtable)
ssize_t read(int fd, void *buf, size_t sz)
{
ssize_t res;
if (_check_fd(fd) < 0) {
return -1;
}
return fdtable[fd].vtable->read(fdtable[fd].obj, buf, sz);
(void)k_mutex_lock(&fdtable[fd].lock, K_FOREVER);
res = fdtable[fd].vtable->read(fdtable[fd].obj, buf, sz);
k_mutex_unlock(&fdtable[fd].lock);
return res;
}
FUNC_ALIAS(read, _read, ssize_t);
ssize_t write(int fd, const void *buf, size_t sz)
{
ssize_t res;
if (_check_fd(fd) < 0) {
return -1;
}
return fdtable[fd].vtable->write(fdtable[fd].obj, buf, sz);
(void)k_mutex_lock(&fdtable[fd].lock, K_FOREVER);
res = fdtable[fd].vtable->write(fdtable[fd].obj, buf, sz);
k_mutex_unlock(&fdtable[fd].lock);
return res;
}
FUNC_ALIAS(write, _write, ssize_t);
@@ -250,8 +266,12 @@ int close(int fd)
return -1;
}
(void)k_mutex_lock(&fdtable[fd].lock, K_FOREVER);
res = fdtable[fd].vtable->close(fdtable[fd].obj);
k_mutex_unlock(&fdtable[fd].lock);
z_free_fd(fd);
return res;

View File

@@ -444,18 +444,19 @@ const union mpsc_pbuf_generic *mpsc_pbuf_claim(struct mpsc_pbuf_buffer *buffer)
}
void mpsc_pbuf_free(struct mpsc_pbuf_buffer *buffer,
union mpsc_pbuf_generic *item)
const union mpsc_pbuf_generic *item)
{
uint32_t wlen = buffer->get_wlen(item);
k_spinlock_key_t key = k_spin_lock(&buffer->lock);
union mpsc_pbuf_generic *witem = (union mpsc_pbuf_generic *)item;
item->hdr.valid = 0;
witem->hdr.valid = 0;
if (!(buffer->flags & MPSC_PBUF_MODE_OVERWRITE) ||
((uint32_t *)item == &buffer->buf[buffer->rd_idx])) {
item->hdr.busy = 0;
witem->hdr.busy = 0;
buffer->rd_idx = idx_inc(buffer, buffer->rd_idx, wlen);
} else {
item->skip.len = wlen;
witem->skip.len = wlen;
}
MPSC_PBUF_DBG(buffer, "freed: %p ", item);

View File

@@ -22,8 +22,12 @@
#include <sys/cbprintf.h>
#include <sys/types.h>
#if defined(CONFIG_PRINTK_SYNC) && \
!(defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2))
/* Option present only when CONFIG_USERSPACE enabled. */
#ifndef CONFIG_PRINTK_BUFFER_SIZE
#define CONFIG_PRINTK_BUFFER_SIZE 0
#endif
#if defined(CONFIG_PRINTK_SYNC)
static struct k_spinlock lock;
#endif
@@ -75,11 +79,7 @@ void *__printk_get_hook(void)
{
return _char_out;
}
#endif /* CONFIG_PRINTK */
#if defined(CONFIG_PRINTK) && \
!(defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2))
#ifdef CONFIG_USERSPACE
struct buf_out_context {
int count;
unsigned int buf_count;
@@ -104,7 +104,6 @@ static int buf_char_out(int c, void *ctx_p)
return c;
}
#endif /* CONFIG_USERSPACE */
struct out_context {
int count;
@@ -118,9 +117,13 @@ static int char_out(int c, void *ctx_p)
return _char_out(c);
}
#ifdef CONFIG_USERSPACE
void vprintk(const char *fmt, va_list ap)
{
if (IS_ENABLED(CONFIG_LOG_PRINTK)) {
z_log_vprintk(fmt, ap);
return;
}
if (k_is_user_context()) {
struct buf_out_context ctx = { 0 };
@@ -142,21 +145,6 @@ void vprintk(const char *fmt, va_list ap)
#endif
}
}
#else
void vprintk(const char *fmt, va_list ap)
{
struct out_context ctx = { 0 };
#ifdef CONFIG_PRINTK_SYNC
k_spinlock_key_t key = k_spin_lock(&lock);
#endif
cbvprintf(char_out, &ctx, fmt, ap);
#ifdef CONFIG_PRINTK_SYNC
k_spin_unlock(&lock, key);
#endif
}
#endif /* CONFIG_USERSPACE */
void z_impl_k_str_out(char *c, size_t n)
{
@@ -212,16 +200,11 @@ void printk(const char *fmt, ...)
va_start(ap, fmt);
if (IS_ENABLED(CONFIG_LOG_PRINTK)) {
log_printk(fmt, ap);
} else {
vprintk(fmt, ap);
}
vprintk(fmt, ap);
va_end(ap);
}
#endif /* defined(CONFIG_PRINTK) && \
* !(defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2))
*/
#endif /* defined(CONFIG_PRINTK) */
struct str_context {
char *str;

View File

@@ -8,6 +8,7 @@
#include <posix/time.h>
#include <posix/sys/time.h>
#include <syscall_handler.h>
#include <spinlock.h>
/*
* `k_uptime_get` returns a timestamp based on an always increasing
@@ -17,6 +18,7 @@
* set from a real time clock, if such hardware is present.
*/
static struct timespec rt_clock_base;
static struct k_spinlock rt_clock_base_lock;
/**
* @brief Get clock time specified by clock_id.
@@ -27,6 +29,7 @@ int z_impl_clock_gettime(clockid_t clock_id, struct timespec *ts)
{
uint64_t elapsed_nsecs;
struct timespec base;
k_spinlock_key_t key;
switch (clock_id) {
case CLOCK_MONOTONIC:
@@ -35,7 +38,9 @@ int z_impl_clock_gettime(clockid_t clock_id, struct timespec *ts)
break;
case CLOCK_REALTIME:
key = k_spin_lock(&rt_clock_base_lock);
base = rt_clock_base;
k_spin_unlock(&rt_clock_base_lock, key);
break;
default:
@@ -77,6 +82,7 @@ int z_vrfy_clock_gettime(clockid_t clock_id, struct timespec *ts)
int clock_settime(clockid_t clock_id, const struct timespec *tp)
{
struct timespec base;
k_spinlock_key_t key;
if (clock_id != CLOCK_REALTIME) {
errno = EINVAL;
@@ -90,7 +96,9 @@ int clock_settime(clockid_t clock_id, const struct timespec *tp)
base.tv_sec = delta / NSEC_PER_SEC;
base.tv_nsec = delta % NSEC_PER_SEC;
key = k_spin_lock(&rt_clock_base_lock);
rt_clock_base = base;
k_spin_unlock(&rt_clock_base_lock, key);
return 0;
}

View File

@@ -24,7 +24,7 @@ static int cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut,
mut->lock_count = 0U;
mut->owner = NULL;
_ready_one_thread(&mut->wait_q);
ret = z_pend_curr(&z_pthread_spinlock, key, &cv->wait_q, timeout);
ret = z_sched_wait(&z_pthread_spinlock, key, &cv->wait_q, timeout, NULL);
/* FIXME: this extra lock (and the potential context switch it
* can cause) could be optimized out. At the point of the
@@ -39,37 +39,15 @@ static int cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut,
return ret == -EAGAIN ? ETIMEDOUT : ret;
}
/* This implements a "fair" scheduling policy: at the end of a POSIX
* thread call that might result in a change of the current maximum
* priority thread, we always check and context switch if needed.
* Note that there is significant dispute in the community over the
* "right" way to do this and different systems do it differently by
* default. Zephyr is an RTOS, so we choose latency over
* throughput. See here for a good discussion of the broad issue:
*
* https://blog.mozilla.org/nfroyd/2017/03/29/on-mutex-performance-part-1/
*/
int pthread_cond_signal(pthread_cond_t *cv)
{
k_spinlock_key_t key = k_spin_lock(&z_pthread_spinlock);
_ready_one_thread(&cv->wait_q);
z_reschedule(&z_pthread_spinlock, key);
z_sched_wake(&cv->wait_q, 0, NULL);
return 0;
}
int pthread_cond_broadcast(pthread_cond_t *cv)
{
k_spinlock_key_t key = k_spin_lock(&z_pthread_spinlock);
while (z_waitq_head(&cv->wait_q)) {
_ready_one_thread(&cv->wait_q);
}
z_reschedule(&z_pthread_spinlock, key);
z_sched_wake_all(&cv->wait_q, 0, NULL);
return 0;
}

View File

@@ -94,7 +94,7 @@ static void canopen_rx_isr_callback(struct zcan_frame *msg, void *arg)
buffer->pFunct(buffer->object, &rxMsg);
}
static void canopen_tx_isr_callback(uint32_t error_flags, void *arg)
static void canopen_tx_isr_callback(int error, void *arg)
{
CO_CANmodule_t *CANmodule = arg;
@@ -103,7 +103,7 @@ static void canopen_tx_isr_callback(uint32_t error_flags, void *arg)
return;
}
if (error_flags == CAN_TX_OK) {
if (error == CAN_TX_OK) {
CANmodule->first_tx_msg = false;
}

View File

@@ -37,13 +37,13 @@ struct can_bus_err_cnt current_err_cnt;
CAN_DEFINE_MSGQ(counter_msgq, 2);
void tx_irq_callback(uint32_t error_flags, void *arg)
void tx_irq_callback(int error, void *arg)
{
char *sender = (char *)arg;
if (error_flags) {
if (error != 0) {
printk("Callback! error-code: %d\nSender: %s\n",
error_flags, sender);
error, sender);
}
}

Some files were not shown because too many files have changed in this diff Show More