Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,71 @@ unoq.bootloader.tool.default=remoteocd
unoq.bootloader.file=zephyr-{build.variant}.elf
unoq.bootloader.target=stm32u585zitxq

##########################################################################################
##############################################################################################################

nano_connect.name=Arduino Nano RP2040 Connect
nano_connect.build.core=arduino
nano_connect.build.crossprefix=arm-zephyr-eabi-
nano_connect.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/

nano_connect.menu.debug.false=Standard
nano_connect.menu.debug.true=Debug
nano_connect.menu.debug.true.build.zsk_args.debug=-debug

nano_connect.menu.link_mode.dynamic=Dynamic
nano_connect.menu.link_mode.static=Static
nano_connect.menu.link_mode.static.build.link_mode=static
nano_connect.menu.link_mode.static.upload.extension=bin-zsk.bin

nano_connect.build.zephyr_target=arduino_nano_connect
nano_connect.build.zephyr_args=
nano_connect.build.zephyr_hals=hal_rpi_pico
nano_connect.build.artifact=zephyr_main
nano_connect.build.variant=arduino_nano_connect_rp2040
nano_connect.build.mcu=cortex-m0plus
nano_connect.build.fpu=
nano_connect.build.architecture=cortex-m0plus
nano_connect.compiler.zephyr.arch.define=

nano_connect.build.float-abi=-mfloat-abi=soft
nano_connect.build.extra_flags=
nano_connect.build.postbuild.cmd="{tools.imgtool.path}/{tools.imgtool.cmd}" exit
nano_connect.recipe.hooks.objcopy.postobjcopy.3.pattern="{runtime.tools.bin2uf2.path}/bin2uf2" {upload.address} {upload.familyid} "{build.path}/{build.project_name}.{upload.extension}" "{build.path}/{build.project_name}.uf2"
nano_connect.build.board=NANO_RP2040_CONNECT
nano_connect.compiler.zephyr=
nano_connect.vid.0=0x2341
nano_connect.pid.0=0x005E
nano_connect.upload_port.0.vid=0x2341
nano_connect.upload_port.0.pid=0x005E

nano_connect.upload.tool=picotool
nano_connect.upload.tool.default=picotool
nano_connect.upload.protocol=
nano_connect.upload.transport=
nano_connect.upload.vid=0x2341
nano_connect.upload.pid=0x005E
nano_connect.upload.interface=0
nano_connect.upload.use_1200bps_touch=true
nano_connect.upload.wait_for_upload_port=false
nano_connect.upload.native_usb=true
nano_connect.upload.maximum_size=16777216
nano_connect.upload.maximum_data_size=270336

nano_connect.upload.address=0x100E0000
nano_connect.upload.familyid=0xe48bff56

nano_connect.bootloader.tool=picotool
nano_connect.bootloader.tool.default=picotool
nano_connect.bootloader.vid=0x2341
nano_connect.bootloader.pid=0x005E
nano_connect.bootloader.interface=0
nano_connect.bootloader.file=zephyr-{build.variant}

nano_connect.debug.tool=gdb
nano_connect.debug.server.openocd.scripts.0=interface/{programmer.protocol}.cfg
nano_connect.debug.server.openocd.scripts.1={programmer.transport_script}
nano_connect.debug.server.openocd.scripts.2=target/rp2040-core0.cfg
nano_connect.debug.cortex-debug.custom.request=attach
nano_connect.debug.svd_file={runtime.platform.path}/svd/rp2040.svd

##############################################################################################################
25 changes: 25 additions & 0 deletions cores/arduino/llext_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,28 @@
* The naked trampoline uses r12 (ip, AAPCS inter-procedure scratch register)
* which is never an argument register, so r0–r3 and d0–d7 are untouched.
*/
#if defined(__ARM_ARCH_6M__) || (defined(__ARM_ARCH) && __ARM_ARCH < 7)
/* Thumb-1 (Cortex-M0/M0+): movw/movt are Thumb-2 only, use a PC-relative
* literal pool load via r4 (callee-saved, push/pop balanced). r0-r3 carry
* the RTABI double arguments and must not be touched.
*/
#define VN(name) \
__attribute__((naked)) void name(void) { \
__asm__("push {r4}\n\t" \
"ldr r4, =__real_" #name "\n\t" \
"mov r12, r4\n\t" \
"pop {r4}\n\t" \
"bx r12"); \
}
#else
#define VN(name) \
__attribute__((naked)) void name(void) { \
__asm__("movw r12, #:lower16:__real_" #name "\n\t" \
"movt r12, #:upper16:__real_" #name "\n\t" \
"bx r12"); \
}
#endif
#endif

/* string.h */
W3(void *, memcpy, void *, const void *, size_t)
Expand Down Expand Up @@ -203,6 +218,16 @@ VN(__aeabi_idivmod)
VN(__aeabi_uidivmod)
VN(__aeabi_ldivmod)
VN(__aeabi_uldivmod)
#if defined(__ARM_ARCH_6M__) || (defined(__ARM_ARCH) && __ARM_ARCH < 7)
/*
* Thumb1 switch-dispatch helpers.
*/
VN(__gnu_thumb1_case_uqi)
VN(__gnu_thumb1_case_sqi)
VN(__gnu_thumb1_case_uhi)
VN(__gnu_thumb1_case_shi)
VN(__gnu_thumb1_case_si)
#endif
#endif

/* stdio.h */
Expand Down
2 changes: 1 addition & 1 deletion extra/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ line_continuation='\\$' # match lines ending with '\'
c_comment='\s*\/\*.*?\*\/' # match C-style comments and any preceding space
perl -i -pe "s/${c_comment}//gs unless /${line_preproc_ok}/ || (/${line_comment_only}/ && !/${line_continuation}/)" $(find ${VARIANT_DIR}/llext-edk/include/ -type f)

for ext in elf bin hex; do
for ext in elf bin hex uf2; do
rm -f firmwares/zephyr-$variant.$ext
if [ -f ${BUILD_DIR}/zephyr/zephyr.$ext ]; then
cp ${BUILD_DIR}/zephyr/zephyr.$ext firmwares/zephyr-$variant.$ext
Expand Down
9 changes: 8 additions & 1 deletion libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,18 @@ void arduino::ZephyrSPI::detachInterrupt() {
}

void arduino::ZephyrSPI::begin() {

#if defined(CONFIG_BOARD_ARDUINO_NANO_CONNECT)
/* On nano_connect the SPI driver is already initialized by the loader;
* calling init() again on an already-ready device hangs. */
if (!device_is_ready(spi_dev)) {
(void)zephyr::arduino::init_dev_apply_pinctrl(spi_dev);
}
#else
/* Re-apply DEFAULT pinctrl state so shared pins
* are remuxed back to SPI after other peripherals have used them.
*/
(void)zephyr::arduino::init_dev_apply_pinctrl(spi_dev);
#endif
}

void arduino::ZephyrSPI::end() {
Expand Down
48 changes: 48 additions & 0 deletions loader/fixups.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,54 @@ SYS_INIT(disable_bootloader_mpu, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAU
SYS_INIT(disable_mpu_rasr_xn, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
#endif

#if defined(CONFIG_BOARD_ARDUINO_NANO_CONNECT)
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <pico/bootrom.h>

/*
* Double-tap reset detection: if the board is reset twice within 500ms,
* enter USB bootloader (BOOTSEL) mode. This mirrors the original
* ArduinoCore-mbed NANO_RP2040_CONNECT behavior.
*
* A magic token is stored in uninitialized RAM (.noinit), which survives
* a warm reset but is lost on power cycle. On boot:
* - If the token is present: a second reset happened quickly, so we
* clear the token and enter USB boot mode (never returns).
* - If not: write the token, wait 500ms, then clear it and boot normally.
*/
static const uint32_t magic_token[] = {
0xf01681de,
0xbd729b29,
0xd359be7a,
};

/* Non-static so the variant's _on_1200_bps() can arm the same magic. */
uint32_t magic_location[3] __attribute__((section(".noinit.double_tap")));

#define NANO_RP2040_LED_PIN 6

int double_tap_check(void) {
if (magic_location[0] == magic_token[0] && magic_location[1] == magic_token[1] &&
magic_location[2] == magic_token[2]) {
magic_location[0] = 0;
reset_usb_boot(1 << NANO_RP2040_LED_PIN, 0);
/* never returns */
}

for (int i = 0; i < 3; i++) {
magic_location[i] = magic_token[i];
}

k_busy_wait(500000);

magic_location[0] = 0;
return 0;
}

SYS_INIT(double_tap_check, POST_KERNEL, 0);
#endif

#if defined(CONFIG_INPUT)
#include <zephyr/kernel.h>
#include <zephyr/device.h>
Expand Down
18 changes: 17 additions & 1 deletion loader/llext_exports.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,17 @@ EXPORT_AEABI_SYM(__aeabi_idivmod);
EXPORT_AEABI_SYM(__aeabi_uidivmod);
EXPORT_AEABI_SYM(__aeabi_ldivmod);
EXPORT_AEABI_SYM(__aeabi_uldivmod);

#if defined(__ARM_ARCH_6M__) || (defined(__ARM_ARCH) && __ARM_ARCH < 7)
/*
* Thumb1 switch-dispatch helpers.
*/
EXPORT_AEABI_SYM(__gnu_thumb1_case_uqi);
EXPORT_AEABI_SYM(__gnu_thumb1_case_sqi);
EXPORT_AEABI_SYM(__gnu_thumb1_case_uhi);
EXPORT_AEABI_SYM(__gnu_thumb1_case_shi);
EXPORT_AEABI_SYM(__gnu_thumb1_case_si);
#endif
#endif

#if defined(CONFIG_CPP)
Expand Down Expand Up @@ -443,7 +454,7 @@ EXPORT_SYMBOL(arm_irq_is_enabled);
EXPORT_SYMBOL(arm_irq_priority_set);
#endif

#if defined(__arm__)
#if defined(__arm__) && !defined(CONFIG_SOC_FAMILY_RPI_PICO)
EXPORT_SYMBOL(SystemCoreClock);
#endif

Expand All @@ -455,3 +466,8 @@ STRUCT_SECTION_END_EXTERN(device);
EXPORT_SYMBOL(TYPE_SECTION_START(device));
EXPORT_SYMBOL(TYPE_SECTION_END(device));
#endif

#if defined(CONFIG_BOARD_ARDUINO_NANO_CONNECT)
extern uint32_t magic_location[3];
EXPORT_SYMBOL(magic_location);
#endif
10 changes: 9 additions & 1 deletion platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,15 @@ tools.picotool.path={runtime.tools.rp2040tools.path}
tools.picotool.cmd=rp2040load
tools.picotool.upload.params.verbose=-v
tools.picotool.upload.params.quiet=
tools.picotool.upload.pattern="{path}/{cmd}" {upload.verbose} -D "{build.path}/{build.project_name}.elf"
tools.picotool.upload.pattern="{path}/{cmd}" {upload.verbose} -D "{build.path}/{build.project_name}"

tools.picotool.erase.params.verbose=
tools.picotool.erase.params.quiet=
tools.picotool.erase.pattern=

tools.picotool.bootloader.params.verbose=-v
tools.picotool.bootloader.params.quiet=
tools.picotool.bootloader.pattern="{path}/{cmd}" {upload.verbose} -D "{runtime.platform.path}/firmwares/{bootloader.file}"

#
# IMGTOOL
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) Arduino s.r.l. and/or its affiliated companies
# SPDX-License-Identifier: Apache-2.0

CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Arduino Nano RP2040 Connect"
CONFIG_USB_DEVICE_MANUFACTURER="Arduino"
CONFIG_USB_DEVICE_VID=0x2341
CONFIG_USB_DEVICE_PID=0x005E

CONFIG_USB_CDC_ACM=y
CONFIG_USB_CDC_ACM_RINGBUF_SIZE=1024
CONFIG_UART_LINE_CTRL=y
CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y

CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_MAIN_STACK_SIZE=32768
CONFIG_LLEXT_HEAP_SIZE=64

CONFIG_LLEXT_STORAGE_WRITABLE=n
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

CONFIG_ADC=y
CONFIG_DAC=n
CONFIG_PWM=y

Loading
Loading