Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
19618: cpu/stm32: fix riotboot settings for L4 and WB r=aabadie a=gschorcht

### Contribution description

This PR fixes the `riotboot` configuration for L4 and WB.

The family is not called `stm32l4` or `stm32wb` but `l4` and `wb`. That is, the `riotboot` configuration didn't work at all. Furthermore, a minimum `RIOTBOOT_LEN` of `0x2000` is required for L4.

Found when investigating the compilation errors for `bootloaders/riotboot_serial` in PR #19576.

### Testing procedure

1. Green CI.
2. Use the following commands:
    ```
    BOARD=nucleo-l496zg make -C tests/riotboot info-debug-variable-RIOTBOOT_HDR_LEN
    BOARD=p-nucleo-wb55 make -C tests/riotboot info-debug-variable-RIOTBOOT_HDR_LEN
    ```
    In master these commands give
    ```
    0x400
    ```
    With this PR these commands give
    ```
    0x200
    ```
    as expected.
3. Use the following commands:
    ```
    BOARD=nucleo-l496zg make -C tests/riotboot info-debug-variable-RIOTBOOT_LEN
    BOARD=p-nucleo-wb55 make -C tests/riotboot info-debug-variable-RIOTBOOT_LEN
    ```
    In master these commands give
    ```
    0x1000
    ```
    With this PR these commands give
    ```
    0x2000
    ```
    as expected.

### Issues/PRs references


19636: sys: model ecc, evtimer, pipe and shell_lock in kconfig r=aabadie a=aabadie



19639: tests/net/gnrc_mac_timeout: add automated test r=aabadie a=aabadie



Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Co-authored-by: Alexandre Abadie <alexandre.abadie@inria.fr>
  • Loading branch information
3 people authored May 23, 2023
4 parents 4c27aff + 2b96630 + 0ef40af + da67b11 commit 3df44cb
Show file tree
Hide file tree
Showing 26 changed files with 202 additions and 93 deletions.
13 changes: 9 additions & 4 deletions cpu/stm32/stm32_riotboot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ ifneq (,$(filter $(CPU_FAM),f2 f4 f7))
# flash, to get evenly sized and distributed slots.
SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-2*$(RIOTBOOT_LEN)) / $(NUM_SLOTS))))
SLOT1_LEN ?= $(SLOT0_LEN)
else ifeq (stm32l4,$(CPU_FAM))
else ifeq (l4,$(CPU_FAM))
# "The Vector table must be naturally aligned to a power of two whose alignment
# value is greater than or equal to number of Exceptions supported x 4"
# CPU_IRQ_NUMOFF for stm32l4 boards is < 91+16 so (107*4 bytes = 428 bytes ~= 0x200)
# CPU_IRQ_NUMOFF for stm32l4 boards is < 95+16 so (111*4 bytes = 444 bytes ~= 0x200)
# RIOTBOOT_HDR_LEN can be set to 0x200
RIOTBOOT_HDR_LEN ?= 0x200
else ifeq (stm32wb,$(CPU_FAM))

# Slot size is determined by "((total_flash_size - RIOTBOOT_LEN) / 2)".
# If RIOTBOOT_LEN uses an odd number of flashpages, the remainder of the
# flash cannot be divided by two slots while staying FLASHPAGE_SIZE aligned.
RIOTBOOT_LEN ?= 0x2000
else ifeq (wb,$(CPU_FAM))
# "The Vector table must be naturally aligned to a power of two whose alignment
# value is greater than or equal to number of Exceptions supported x 4"
# CPU_IRQ_NUMOFF for stm32l4 boards is < 91+16 so (107*4 bytes = 428 bytes ~= 0x200)
# CPU_IRQ_NUMOFF for stm32wb boards is < 63+16 so (79*4 bytes = 316 bytes ~= 0x200)
# RIOTBOOT_HDR_LEN can be set to 0x200
RIOTBOOT_HDR_LEN ?= 0x200

Expand Down
1 change: 0 additions & 1 deletion makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ PSEUDOMODULES += event_%
PSEUDOMODULES += event_timeout
PSEUDOMODULES += event_timeout_ztimer
PSEUDOMODULES += evtimer_mbox
PSEUDOMODULES += evtimer_on_ztimer
PSEUDOMODULES += fatfs_vfs_format
PSEUDOMODULES += fmt_%
PSEUDOMODULES += gcoap_forward_proxy
Expand Down
4 changes: 4 additions & 0 deletions sys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ choice LOG
endchoice

rsource "coding/Kconfig"
rsource "ecc/Kconfig"
rsource "evtimer/Kconfig"
rsource "log_color/Kconfig"
rsource "log_printfnoformat/Kconfig"
rsource "luid/Kconfig"
Expand All @@ -85,6 +87,7 @@ rsource "net/Kconfig"
rsource "od/Kconfig"
rsource "oneway-malloc/Kconfig"
rsource "phydat/Kconfig"
rsource "pipe/Kconfig"
rsource "pm_layered/Kconfig"
rsource "posix/Kconfig"
rsource "preprocessor/Kconfig"
Expand All @@ -100,6 +103,7 @@ rsource "sema_inv/Kconfig"
rsource "senml/Kconfig"
rsource "seq/Kconfig"
rsource "shell/Kconfig"
rsource "shell_lock/Kconfig"
rsource "ssp/Kconfig"
rsource "test_utils/Kconfig"
rsource "timex/Kconfig"
Expand Down
9 changes: 1 addition & 8 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -998,14 +998,7 @@ ifneq (,$(filter ztimer64%,$(USEMODULE)))
endif

ifneq (,$(filter evtimer,$(USEMODULE)))
ifneq (,$(filter evtimer_on_ztimer,$(USEMODULE)))
USEMODULE += ztimer_msec
else
USEMODULE += xtimer
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
USEMODULE += evtimer_on_ztimer
endif
endif
USEMODULE += ztimer_msec
endif

# handle xtimer's deps. Needs to be done *after* ztimer
Expand Down
35 changes: 35 additions & 0 deletions sys/ecc/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2023 Inria
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

menuconfig MODULE_ECC
bool "Error Correction Code (ECC) algorithms"
depends on TEST_KCONFIG
help
Provides Golay1412, Hamming256 and Repetition algorithms.

if MODULE_ECC

menu "ECC algorithms"

config MODULE_ECC_GOLAY1412
bool "Golay1412 Error Correction Code (ECC) algorithm"
help
Provides Golay1412 ECC algorithm.

config MODULE_ECC_HAMMING256
bool "Hamming256 Error Correction Code (ECC) algorithm"
help
Provides Hamming256 ECC algorithm.

config MODULE_ECC_REPETITION
bool "Repetition Error Correction Code (ECC) algorithm"
help
Provides Repetition ECC algorithm.

endmenu # ECC algorithms

endif
19 changes: 19 additions & 0 deletions sys/evtimer/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2023 Inria
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

config MODULE_EVTIMER
bool "Event timer module"
depends on TEST_KCONFIG
select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC

config MODULE_EVTIMER_MBOX
bool "Use message box"
select MODULE_CORE_MBOX
select MODULE_EVTIMER
help
Use message box to implement event timer.
32 changes: 0 additions & 32 deletions sys/evtimer/evtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,9 @@ static void _del_event_from_list(evtimer_t *evtimer, evtimer_event_t *event)
static void _set_timer(evtimer_t *evtimer)
{
evtimer_event_t *next_event = evtimer->events;

#if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
evtimer->base = ztimer_set(ZTIMER_MSEC, &evtimer->timer, next_event->offset);
DEBUG("evtimer: now=%" PRIu32 " ms setting ztimer to %" PRIu32 " ms\n",
evtimer->base, next_event->offset);
#else
uint64_t offset_us = (uint64_t)next_event->offset * US_PER_MS;

DEBUG("evtimer: now=%" PRIu32 " us setting xtimer to %" PRIu32 ":%" PRIu32 " us\n",
xtimer_now_usec(), (uint32_t)(offset_us >> 32), (uint32_t)(offset_us));

xtimer_set64(&evtimer->timer, offset_us);
#endif
}

static void _update_timer(evtimer_t *evtimer)
Expand All @@ -114,15 +104,10 @@ static void _update_timer(evtimer_t *evtimer)
_set_timer(evtimer);
}
else {
#if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
ztimer_remove(ZTIMER_MSEC, &evtimer->timer);
#else
xtimer_remove(&evtimer->timer);
#endif
}
}

#if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
static void _update_head_offset(evtimer_t *evtimer)
{
if (evtimer->events) {
Expand All @@ -137,23 +122,6 @@ static void _update_head_offset(evtimer_t *evtimer)
evtimer->base = now;
}
}
#else /* IS_USED(MODULE_EVTIMER_ON_ZTIMER) */
static uint32_t _get_offset(xtimer_t *timer)
{
uint64_t left = xtimer_left_usec(timer);
/* add half of 125 so integer division rounds to nearest */
return div_u64_by_125((left >> 3) + 62);
}

static void _update_head_offset(evtimer_t *evtimer)
{
if (evtimer->events) {
evtimer_event_t *event = evtimer->events;
event->offset = _get_offset(&evtimer->timer);
DEBUG("evtimer: _update_head_offset(): new head offset %" PRIu32 "\n", event->offset);
}
}
#endif /* !IS_USED(MODULE_EVTIMER_ON_ZTIMER) */

void evtimer_add(evtimer_t *evtimer, evtimer_event_t *event)
{
Expand Down
30 changes: 6 additions & 24 deletions sys/include/evtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,20 @@
*
* @note Experimental and likely to replaced with unified timer API
*
* RIOT's main timer subsystem is @ref sys_xtimer "xtimer", but for many
* applications @ref sys_xtimer "xtimer's" 64-bit absolute time values are
* wasteful or clumsy to use.
*
* Compared to @ref sys_xtimer "xtimer", evtimer offers:
* RIOT's main timer subsystem is @ref sys_ztimer "ztimer" but compared to
* @ref sys_ztimer "ztimer", evtimer offers:
*
* - only relative 32-bit millisecond timer values
* Events can be scheduled with a relative offset of up to ~49.7 days in the
* future.
* **For time-critical stuff, use @ref sys_xtimer "xtimer"!**
* **For time-critical stuff, use @ref sys_ztimer "ztimer"!**
* - more flexible, "intrusive" timer type @ref evtimer_event_t only contains
* the necessary fields, which can be extended as needed, and handlers define
* actions taken on timer triggers. Check out @ref evtimer_msg_event_t as
* example.
* - uses @ref sys_xtimer "xtimer" as backend by default. Alternatively, with
* the pseudomodule "evtimer_on_ztimer" compiled in, evtimer is backend by
* @ref sys_ztimer "ZTIMER_MSEC".
*
* - when a number of timeouts with the same callback function need to be
* scheduled, evtimer is using less RAM (due to storing the callback function
* only once), while each ztimer has a function pointer for the callback.
* @{
*
* @file
Expand All @@ -48,13 +44,7 @@
#include <stdint.h>
#include "modules.h"

#if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
#include "ztimer.h"
#else
#include "xtimer.h"
#endif

#include "timex.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -77,12 +67,8 @@ typedef void(*evtimer_callback_t)(evtimer_event_t* event);
* @brief Event timer
*/
typedef struct {
#if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
ztimer_t timer; /**< Timer */
uint32_t base; /**< Absolute time the first event is built on */
#else
xtimer_t timer; /**< Timer */
#endif
evtimer_callback_t callback; /**< Handler function for this evtimer's
event type */
evtimer_event_t *events; /**< Event queue */
Expand Down Expand Up @@ -128,11 +114,7 @@ void evtimer_print(const evtimer_t *evtimer);
*/
static inline uint32_t evtimer_now_msec(void)
{
#if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
return ztimer_now(ZTIMER_MSEC);
#else
return xtimer_now_usec64() / US_PER_MS;
#endif
}

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions sys/include/net/gnrc/ipv6/nib/abr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/* prevent cascading include error to xtimer if it is not compiled in or not
* supported by board */
#if IS_USED(MODULE_EVTIMER)
#include "timex.h"
#include "evtimer.h"
#endif
#include "net/ipv6/addr.h"
Expand Down
2 changes: 1 addition & 1 deletion sys/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern "C" {
* Instead terminate RIOT, which is also the behavior a user would
* expect from a CLI application.
*/
# if defined(CPU_NATIVE) && !IS_ACTIVE(KCONFIG_USEMODULE_SHELL)
# if defined(CPU_NATIVE)
# define CONFIG_SHELL_SHUTDOWN_ON_EXIT 1
# else
# define CONFIG_SHELL_SHUTDOWN_ON_EXIT 0
Expand Down
12 changes: 12 additions & 0 deletions sys/pipe/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2023 Inria
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

config MODULE_PIPE
bool "Statically allocated pipes"
depends on TEST_KCONFIG
help
Implementation for statically allocated pipes.
29 changes: 29 additions & 0 deletions sys/shell_lock/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2023 Inria
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

menuconfig MODULE_SHELL_LOCK
bool "Shell Locking module"
depends on TEST_KCONFIG
select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC

if MODULE_SHELL_LOCK

config SHELL_LOCK_PASSWORD
string "Lock password"
default "password"

config SHELL_LOCK_AUTO_LOCK_TIMEOUT_MS
int "Timeout in ms before automatic locking"
default 7000

endif # MODULE_SHELL_LOCK

config MODULE_SHELL_LOCK_AUTO_LOCKING
bool "Automatic locking of the shell"
depends on TEST_KCONFIG
select MODULE_SHELL_LOCK
12 changes: 0 additions & 12 deletions sys/ztimer/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ ifneq (,$(filter ztimer,$(USEMODULE)))
DEFAULT_MODULE += ztimer_init
endif

# unless ztimer_xtimer_compat is used, make xtimer use ztimer_usec as backend.
ifneq (,$(filter ztimer,$(USEMODULE)))
ifneq (,$(filter evtimer,$(USEMODULE)))
USEMODULE += evtimer_on_ztimer
endif
endif

ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
USEMODULE += ztimer_usec
endif
Expand All @@ -27,11 +20,6 @@ ifneq (,$(filter ztimer64_xtimer_compat,$(USEMODULE)))
USEMODULE += ztimer_xtimer_compat
endif

# make evtimer use ztimer_msec as low level timer
ifneq (,$(filter evtimer_on_ztimer,$(USEMODULE)))
USEMODULE += ztimer_msec
endif

ifneq (,$(filter ztimer_%,$(USEMODULE)))
USEMODULE += ztimer_core
USEMODULE += ztimer_extend
Expand Down
1 change: 1 addition & 0 deletions tests/net/gnrc_mac_timeout/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include ../Makefile.net_common

USEMODULE += ztimer_msec
USEMODULE += gnrc_mac

include $(RIOTBASE)/Makefile.include
10 changes: 5 additions & 5 deletions tests/net/gnrc_mac_timeout/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "net/gnrc/mac/timeout.h"
#include "thread.h"
#include "msg.h"
#include "xtimer.h"
#include "ztimer.h"

#define TIMEOUT_COUNT 3
#define TIMEOUT_1_DURATION 1000
Expand All @@ -34,7 +34,7 @@ static gnrc_mac_timeout_event_t test_timeouts[TIMEOUT_COUNT];
static gnrc_mac_timeout_type_t timeout_1;
static gnrc_mac_timeout_type_t timeout_2;
static gnrc_mac_timeout_type_t timeout_3;
static uint32_t start_time;
static ztimer_now_t start_time;

static char worker_stack[THREAD_STACKSIZE_MAIN];

Expand All @@ -47,10 +47,10 @@ void *worker_thread(void *arg)

while (1) {
msg_t m;
uint32_t now;
ztimer_now_t now;

msg_receive(&m);
now = xtimer_now_usec() / US_PER_MS;
now = ztimer_now(ZTIMER_MSEC);

if (gnrc_mac_timeout_is_expired(&mac_timeout, timeout_1)) {
printf("At %6" PRIu32 " ms received msg %i: timeout_1 (set at %" PRIu32 " ms) expired, "
Expand Down Expand Up @@ -102,7 +102,7 @@ int main(void)
timeout_2 = -2;
timeout_3 = -3;

start_time = xtimer_now_usec() / US_PER_MS;
start_time = ztimer_now(ZTIMER_MSEC);
gnrc_mac_init_timeouts(&mac_timeout, test_timeouts, TIMEOUT_COUNT);
gnrc_mac_set_timeout(&mac_timeout, timeout_1, TIMEOUT_1_DURATION, pid);
gnrc_mac_set_timeout(&mac_timeout, timeout_2, TIMEOUT_2_DURATION, pid);
Expand Down
Loading

0 comments on commit 3df44cb

Please sign in to comment.