Skip to content

Commit c6a74a5

Browse files
nzmichaelhcfriedt
authored andcommitted
drivers/flash: sam0: only use a semaphore if multitasking is enabled
This lets the driver be used in single threaded applications such as a bootloader. Signed-off-by: Michael Hope <[email protected]>
1 parent b21a91e commit c6a74a5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/flash/flash_sam0.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ struct flash_sam0_data {
5151
off_t offset;
5252
#endif
5353

54+
#if defined(CONFIG_MULTITHREADING)
5455
struct k_sem sem;
56+
#endif
5557
};
5658

5759
#if CONFIG_FLASH_PAGE_LAYOUT
@@ -74,16 +76,20 @@ static int flash_sam0_write_protection(const struct device *dev, bool enable);
7476

7577
static inline void flash_sam0_sem_take(const struct device *dev)
7678
{
79+
#if defined(CONFIG_MULTITHREADING)
7780
struct flash_sam0_data *ctx = dev->data;
7881

7982
k_sem_take(&ctx->sem, K_FOREVER);
83+
#endif
8084
}
8185

8286
static inline void flash_sam0_sem_give(const struct device *dev)
8387
{
88+
#if defined(CONFIG_MULTITHREADING)
8489
struct flash_sam0_data *ctx = dev->data;
8590

8691
k_sem_give(&ctx->sem);
92+
#endif
8793
}
8894

8995
static int flash_sam0_valid_range(off_t offset, size_t len)
@@ -435,9 +441,11 @@ flash_sam0_get_parameters(const struct device *dev)
435441

436442
static int flash_sam0_init(const struct device *dev)
437443
{
444+
#if defined(CONFIG_MULTITHREADING)
438445
struct flash_sam0_data *ctx = dev->data;
439446

440447
k_sem_init(&ctx->sem, 1, 1);
448+
#endif
441449

442450
#ifdef PM_APBBMASK_NVMCTRL
443451
/* Ensure the clock is on. */

0 commit comments

Comments
 (0)