Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Native Zephyr change only: update to 3.7.0 (RC1). (#1194)
Browse files Browse the repository at this point in the history
Native Zephyr (i.e. for non-Nordic platforms) is now tested with Zephyr 3.7.0 release candidate 1 (rather than 3.6.0); we will move to the official 3.7.0 release as soon as it is available, expected late July.
  • Loading branch information
RobMeades authored Jul 5, 2024
1 parent 28f76bd commit 66b6b71
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion port/platform/common/automation/u_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ unity:

zephyr_native:
type: zephyr
version: v3.6.0
version: v3.7.0-rc1

nrfconnectsdk:
type: nrfconnectsdk
Expand Down
2 changes: 1 addition & 1 deletion port/platform/zephyr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Follow the instructions to install the development tools:
# SDK Installation For Other MCUs (Native Zephyr)
Please follow the [Zephyr](https://docs.zephyrproject.org/latest/develop/getting_started/index.html) instructions to install Zephyr and the `west` tool that configures and builds Zephyr.

`ubxlib` is tested with native Zephyr version 3.6.0.
`ubxlib` is tested with native Zephyr version 3.7.0-rc1.

If you intend to use Zephyr on Linux/posix then you must also follow the instructions here: https://docs.zephyrproject.org/latest/boards/posix/native_posix/doc/index.html.

Expand Down
4 changes: 4 additions & 0 deletions port/platform/zephyr/app/u_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ int main(void)
}

#ifdef U_DEBUG_UTILS_DUMP_THREADS
# if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,7,0)
void k_sys_fatal_error_handler(unsigned int reason, const struct arch_esf *esf)
# else
void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf)
# endif
{
(void)reason;
# ifdef __arm__
Expand Down
3 changes: 2 additions & 1 deletion port/platform/zephyr/runner/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ CONFIG_LOG_BACKEND_UART=n
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=2048
# End of SEGGER RTT

# This is needed for our thread dumper
# These are needed for our thread dumper
CONFIG_EXTRA_EXCEPTION_INFO=y
CONFIG_THREAD_MONITOR=y

# Enable I2C
CONFIG_I2C=y
Expand Down
13 changes: 12 additions & 1 deletion port/platform/zephyr/runner_stm32/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,26 @@ CONFIG_ASSERT=y
# all of which means we stick with console logging
CONFIG_UART_CONSOLE=y

# This is needed for our thread dumper
# These are needed for our thread dumper
CONFIG_EXTRA_EXCEPTION_INFO=y
CONFIG_THREAD_MONITOR=y

# Enable I2C
CONFIG_I2C=y

# Enable SPI
CONFIG_SPI=y

# From Zephyr 3.7.0, the asynchronous UART API, which we use
# with STM32F7 as it is the only way to enable DMA and avoid
# character loss with the single-byte UART buffers on that
# platform, requires UART buffers to be in non-cached RAM.
# There are some frightening device tree gymnastics to make
# that happen, which end up mixing what is internal ubxlib
# code with application behaviour, so for now we disable
# DCACHE here. This should probably be looked at.
CONFIG_DCACHE=n

# Enable PPP-level integration with the bottom of the Zephyr IP stack
CONFIG_NETWORKING=y
CONFIG_NET_DRIVERS=y
Expand Down
39 changes: 19 additions & 20 deletions port/platform/zephyr/src/u_port_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ K_MEM_PARTITION_DEFINE(chunk0_reloc, exe_chunk_0, sizeof(exe_chunk_0),
typedef struct {
struct k_thread *pThread;
k_thread_stack_t *pStack;
void *pStackAllocation;
size_t stackSize;
bool isAllocated;
} uPortOsThreadInstance_t;
Expand All @@ -126,7 +125,7 @@ static volatile int32_t gResourceAllocCount = 0;
* STATIC FUNCTIONS
* -------------------------------------------------------------- */

static uPortOsThreadInstance_t *getNewThreadInstance(size_t stackSizeBytes)
static uPortOsThreadInstance_t *pGetNewThreadInstance(size_t stackSizeBytes)
{
uPortOsThreadInstance_t *threadPtr = NULL;
int32_t i = 0;
Expand All @@ -136,7 +135,7 @@ static uPortOsThreadInstance_t *getNewThreadInstance(size_t stackSizeBytes)
//Free if previously used instance
if (threadPtr->stackSize > 0) {
k_free(threadPtr->pThread);
k_free(threadPtr->pStackAllocation);
k_free(threadPtr->pStack);
}

threadPtr->pThread = (struct k_thread *)k_malloc(sizeof(struct k_thread));
Expand All @@ -156,23 +155,25 @@ static uPortOsThreadInstance_t *getNewThreadInstance(size_t stackSizeBytes)
// since then only a small MPU guard region is added at the top of the stack.
// This decreases the stack alignment requirement to 32 bytes.
//
// For the above reason the code below will use the Z_KERNEL_STACK_xx defines
// instead of Z_THREAD_STACK_xx.
// For the above reason the code below will use K_KERNEL_STACK_LEN()

size_t stackAllocSize;
// Other architectures may have other alignment requirements so just add
// a simple check that we don't waste a huge amount dynamic memory due to
// aligment.
U_ASSERT(Z_KERNEL_STACK_OBJ_ALIGN <= 512);
// Z_KERNEL_STACK_SIZE_ADJUST() will add extra space that Zephyr may require and
// to make sure correct allignment we allocate Z_KERNEL_STACK_OBJ_ALIGN extra.
stackAllocSize = Z_KERNEL_STACK_OBJ_ALIGN + Z_KERNEL_STACK_SIZE_ADJUST(stackSizeBytes);
threadPtr->pStackAllocation = k_malloc(stackAllocSize);
// Do the stack alignment
threadPtr->pStack = (k_thread_stack_t *)ROUND_UP(threadPtr->pStackAllocation,
Z_KERNEL_STACK_OBJ_ALIGN);

if (threadPtr->pThread && threadPtr->pStackAllocation) {

// K_KERNEL_STACK_LEN() will add extra space that Zephyr may require.
// TODO: in the future we could use k_thread_stack_alloc() here and drop
// the need for K_KERNEL_STACK_LEN()
#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(3,7,0)
stackAllocSize = K_KERNEL_STACK_LEN(stackSizeBytes);
#else
stackAllocSize = Z_KERNEL_STACK_LEN(stackSizeBytes);
#endif
threadPtr->pStack = k_aligned_alloc(Z_KERNEL_STACK_OBJ_ALIGN, stackAllocSize);

if (threadPtr->pThread && threadPtr->pStack) {
memset(threadPtr->pThread, 0, sizeof(struct k_thread));
threadPtr->stackSize = stackSizeBytes;
threadPtr->isAllocated = true;
Expand All @@ -185,9 +186,9 @@ static uPortOsThreadInstance_t *getNewThreadInstance(size_t stackSizeBytes)
} else if (threadPtr->pThread == NULL || threadPtr->pStack == NULL) {
uPortLogF("Unable to allocate memory for thread with stack size %d\n", stackSizeBytes);
k_free(threadPtr->pThread);
k_free(threadPtr->pStackAllocation);
k_free(threadPtr->pStack);
threadPtr->pThread = NULL;
threadPtr->pStackAllocation = NULL;
threadPtr->pStack = NULL;
threadPtr = NULL;
}
return threadPtr;
Expand Down Expand Up @@ -218,7 +219,6 @@ void uPortOsPrivateInit()
for (int32_t i = 0; i < U_CFG_OS_MAX_THREADS; i++) {
gThreadInstances[i].pThread = NULL;
gThreadInstances[i].pStack = NULL;
gThreadInstances[i].pStackAllocation = NULL;
gThreadInstances[i].stackSize = 0;
gThreadInstances[i].isAllocated = false;
}
Expand All @@ -230,8 +230,7 @@ void uPortOsPrivateDeinit()
if (gThreadInstances[i].stackSize > 0) {
k_free(gThreadInstances[i].pThread);
gThreadInstances[i].pThread = NULL;
k_free(gThreadInstances[i].pStackAllocation);
gThreadInstances[i].pStackAllocation = NULL;
k_free(gThreadInstances[i].pStack);
gThreadInstances[i].pStack = NULL;
gThreadInstances[i].stackSize = 0;
gThreadInstances[i].isAllocated = false;
Expand All @@ -257,7 +256,7 @@ int32_t uPortTaskCreate(void (*pFunction)(void *),
(priority >= U_CFG_OS_PRIORITY_MIN) &&
(priority <= U_CFG_OS_PRIORITY_MAX)) {

newThread = getNewThreadInstance(stackSizeBytes);
newThread = pGetNewThreadInstance(stackSizeBytes);
errorCode = U_ERROR_COMMON_NO_MEMORY;
if (newThread != NULL) {
*pTaskHandle = (uPortTaskHandle_t) k_thread_create(
Expand Down

0 comments on commit 66b6b71

Please sign in to comment.