drivers: hwinfo: Added unique ID support for RPi Pico

Added support for hwinfo's hwinfo_get_device_id for the
RPi Pico series.

Signed-off-by: Yonatan Schachter <yonatan.schachter@gmail.com>
This commit is contained in:
Yonatan Schachter 2022-02-07 21:31:06 +02:00 committed by Carles Cufí
parent 36888b1fb7
commit 90b20fffa4
7 changed files with 73 additions and 0 deletions

View file

@ -16,6 +16,7 @@ zephyr_library_sources_ifdef(CONFIG_HWINFO_MCUX_SRC hwinfo_mcux_src.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_MCUX_SYSCON hwinfo_mcux_syscon.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_NRF hwinfo_nrf.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_PSOC6 hwinfo_psoc6.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_RPI_PICO hwinfo_rpi_pico.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_SAM_RSTC hwinfo_sam_rstc.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_SAM hwinfo_sam.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_SAM0 hwinfo_sam0.c)

View file

@ -70,6 +70,14 @@ config HWINFO_IMXRT
help
Enable NXP i.mx RT hwinfo driver.
config HWINFO_RPI_PICO
bool "Raspberry Pi Pico hwinfo driver"
default y
depends on SOC_SERIES_RP2XXX
select PICOSDK_USE_FLASH
help
Enable Raspberry Pi Pico hwinfo driver.
config HWINFO_SAM_RSTC
bool "Atmel SAM reset cause"
default y

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 Yonatan Schachter
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <drivers/hwinfo.h>
#include <hardware/flash.h>
#define FLASH_RUID_DATA_BYTES 8
ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
{
uint8_t id[FLASH_RUID_DATA_BYTES];
uint32_t key;
/*
* flash_get_unique_id temporarily disables XIP to query the
* flash for its ID. If the CPU is interrupted while XIP is
* disabled, it will halt. Therefore, interrupts must be disabled
* before fetching the ID.
*/
key = irq_lock();
flash_get_unique_id(id);
irq_unlock(key);
if (length > sizeof(id)) {
length = sizeof(id);
}
memcpy(buffer, id, length);
return length;
}

View file

@ -80,4 +80,21 @@ if(CONFIG_HAS_RPI_PICO)
${rp2_common_dir}/hardware_uart/uart.c)
zephyr_include_directories_ifdef(CONFIG_PICOSDK_USE_UART
${rp2_common_dir}/hardware_uart/include)
zephyr_library_sources_ifdef(CONFIG_PICOSDK_USE_FLASH
${rp2_common_dir}/hardware_flash/flash.c)
zephyr_include_directories_ifdef(CONFIG_PICOSDK_USE_FLASH
${rp2_common_dir}/hardware_flash/include)
# Some flash driver functions must be executed from the RAM.
# Originally pico-sdk places them in the RW data section, so this
# implementation does the same.
zephyr_linker_sources_ifdef(CONFIG_PICOSDK_USE_FLASH RWDATA timecritical.ld)
# A function in flash.c adds 1 to a function pointer, causing a warning
set_source_files_properties(
${rp2_common_dir}/hardware_flash/flash.c
PROPERTIES
COMPILE_FLAGS $<TARGET_PROPERTY:compiler,warning_no_pointer_arithmetic>
)
endif()

View file

@ -13,3 +13,8 @@ config PICOSDK_USE_GPIO
bool
help
Use the GPIO driver from pico-sdk
config PICOSDK_USE_FLASH
bool
help
Use the flash driver from pico-sdk

View file

@ -35,4 +35,11 @@
#define __always_inline ALWAYS_INLINE
#endif /* __always_inline */
/* Two definitions required for the flash driver */
#define __STRING(x) #x
#ifndef __noinline
#define __noinline __attribute__((noinline))
#endif
#endif

View file

@ -0,0 +1 @@
*(.time_critical*)