diff --git a/servo_controller/.gitignore b/servo_controller/.gitignore index 1a6d87a..af55f5e 100644 --- a/servo_controller/.gitignore +++ b/servo_controller/.gitignore @@ -1,4 +1,3 @@ build tmp -boards .vscode \ No newline at end of file diff --git a/servo_controller/boards/arm/servo2350/Kconfig.defconfig b/servo_controller/boards/arm/servo2350/Kconfig.defconfig new file mode 100644 index 0000000..15ed436 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/Kconfig.defconfig @@ -0,0 +1,51 @@ + +if BOARD_SERVO2350 + +menu "USB sample options" + depends on USB_DEVICE_STACK_NEXT + +config USBD_MANUFACTURER + string "USB device sample manufacturer string" + default "Zephyr Project" + help + USB device sample manufacturer string. + +config USBD_PRODUCT + string "USB device sample product string" + default "USBD sample" + help + USB device sample product stringa. + +config USBD_PID + hex "USB device sample Product ID" + default 0x0001 + help + USB device sample Product ID. + +config USBD_SELF_POWERED + bool "USB device sample Self-powered attribute" + default y + help + Set the Self-powered attribute in the sample configuration. + +config USBD_REMOTE_WAKEUP + bool "USB device sample Remote Wakeup attribute" + help + Set the Remote Wakeup attribute in the sample configuration. + +config USBD_MAX_POWER + int "USB device sample bMaxPower value" + default 125 + range 0 250 + help + bMaxPower value in the sample configuration in 2 mA units. + +config USBD_20_EXTENSION_DESC + bool "Use default USB 2.0 Extension Descriptor" + depends on USBD_BOS_SUPPORT + help + Set bcdUSB value to 0201 and use default USB 2.0 Extension Descriptor. + +endmenu + +endif # BOARD_SERVO2350 diff --git a/servo_controller/boards/arm/servo2350/Kconfig.servo2350 b/servo_controller/boards/arm/servo2350/Kconfig.servo2350 new file mode 100644 index 0000000..9ff6836 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/Kconfig.servo2350 @@ -0,0 +1,4 @@ + +config BOARD_SERVO2350 + select SOC_RP2350B_HAZARD3 if BOARD_SERVO2350_RP2350B_HAZARD3 + select SOC_RP2350B_M33 if BOARD_SERVO2350_RP2350B_M33 diff --git a/servo_controller/boards/arm/servo2350/board.cmake b/servo_controller/boards/arm/servo2350/board.cmake new file mode 100644 index 0000000..b7a6d26 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/board.cmake @@ -0,0 +1,20 @@ + +board_runner_args(openocd --cmd-pre-init "source [find interface/cmsis-dap.cfg]") +if(CONFIG_ARM) + board_runner_args(openocd --cmd-pre-init "source [find target/rp2350.cfg]") +else() + board_runner_args(openocd --cmd-pre-init "source [find target/rp2350-riscv.cfg]") +endif() + +board_runner_args(probe-rs "--chip=RP235x") + +# The adapter speed is expected to be set by interface configuration. +# The Raspberry Pi's OpenOCD fork doesn't, so match their documentation at +# https://www.raspberrypi.com/documentation/microcontrollers/debug-probe.html#debugging-with-swd +board_runner_args(openocd --cmd-pre-init "set_adapter_speed_if_not_set 5000") + +board_runner_args(uf2 "--board-id=RP2350") + +include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/probe-rs.board.cmake) +include(${ZEPHYR_BASE}/boards/common/uf2.board.cmake) diff --git a/servo_controller/boards/arm/servo2350/board.yml b/servo_controller/boards/arm/servo2350/board.yml new file mode 100644 index 0000000..c6d42c5 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/board.yml @@ -0,0 +1,6 @@ +board: + name: servo2350 + full_name: Servo2350 + vendor: arm + socs: + - name: rp2350b diff --git a/servo_controller/boards/arm/servo2350/docs/Servo2350.pdf b/servo_controller/boards/arm/servo2350/docs/Servo2350.pdf new file mode 100644 index 0000000..20e19d8 Binary files /dev/null and b/servo_controller/boards/arm/servo2350/docs/Servo2350.pdf differ diff --git a/servo_controller/boards/arm/servo2350/servo2350-pinctrl.dtsi b/servo_controller/boards/arm/servo2350/servo2350-pinctrl.dtsi new file mode 100644 index 0000000..1d38dcf --- /dev/null +++ b/servo_controller/boards/arm/servo2350/servo2350-pinctrl.dtsi @@ -0,0 +1,57 @@ +#include + +&pinctrl { + i2c0_default: i2c0_default { + group1 { + pinmux = , // SDA + ; // SCL + input-enable; + input-schmitt-enable; + }; + }; + + spi1_default: spi1_default { + group1 { + pinmux = , // D29 + , // SPI_CLK + ; // SPI_MOSI + }; + + group2 { + pinmux = ; // SPI_MISO + input-enable; + }; + }; + + pwm_default: pwm_default { + group1 { + pinmux = , // SERVO 1 + , // SERVO 2 + , // SERVO 3 + , // SERVO 4 + , // SERVO 5 + , // SERVO 6 + , // SERVO 7 + , // SERVO 8 + , // SERVO 9 + , // SERVO 10 + , // SERVO 11 + , // SERVO 12 + , // SERVO 13 + , // SERVO 14 + , // SERVO 15 + , // SERVO 16 + , // SERVO 17 + ; // SERVO 18 + }; + }; + + adc_default: adc_default { + group1 { + pinmux = , // MUX_COMMON + , // SERVO 17 + ; // SERVO 18 + input-enable; + }; + }; +}; diff --git a/servo_controller/boards/arm/servo2350/servo2350.dtsi b/servo_controller/boards/arm/servo2350/servo2350.dtsi new file mode 100644 index 0000000..949d8c1 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/servo2350.dtsi @@ -0,0 +1,356 @@ +#include + +#include +#include +#include + +#include "servo2350-pinctrl.dtsi" + +/ { + chosen { + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,console = &cdc_acm_uart0; + zephyr,shell-uart = &cdc_acm_uart0; + zephyr,code-partition = &code_partition; + }; + + zephyr,user { + io-channels = <&adc 0>, + <&adc 1>, + <&adc 2>; + }; + + leds { + compatible = "gpio-leds"; + + led0: led_0 { + gpios = <&gpio0 24 GPIO_ACTIVE_LOW>; + label = "LED0"; + }; + led1: led_1 { + gpios = <&gpio0 25 GPIO_ACTIVE_LOW>; + label = "LED1"; + }; + }; + + imu_int1_pin { + compatible = "gpio-keys"; + + imu_int1: imu_int1 { + gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>; + label = "IMU_INT1"; + }; + + imu_int2: imu_int2 { + gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>; + label = "IMU_INT2"; + }; + }; + + digital_inputs: digital_inputs { + compatible = "gpio-keys"; + + digital1: digital_1 { + gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>; + label = "DIGITAL_1"; + }; + digital2: digital_2 { + gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>; + label = "DIGITAL_2"; + }; + digital3: digital_3 { + gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>; + label = "DIGITAL_3"; + }; + digital4: digital_4 { + gpios = <&gpio0 19 GPIO_ACTIVE_HIGH>; + label = "DIGITAL_4"; + }; + digital5: digital_5 { + gpios = <&gpio0 20 GPIO_ACTIVE_HIGH>; + label = "DIGITAL_5"; + }; + digital6: digital_6 { + gpios = <&gpio0 21 GPIO_ACTIVE_HIGH>; + label = "DIGITAL_6"; + }; + }; + + digital_outputs: digital_outputs { + compatible = "gpio-leds"; + + leg0_enable: leg0_enable { + gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>; + label = "LEG0_ENABLE"; + }; + leg1_enable: leg1_enable { + gpios = <&gpio0_hi 11 GPIO_ACTIVE_HIGH>; + label = "LEG1_ENABLE"; + }; + leg2_enable: leg2_enable { + gpios = <&gpio0_hi 12 GPIO_ACTIVE_HIGH>; + label = "LEG2_ENABLE"; + }; + leg3_enable: leg3_enable { + gpios = <&gpio0_hi 13 GPIO_ACTIVE_HIGH>; + label = "LEG3_ENABLE"; + }; + leg4_enable: leg4_enable { + gpios = <&gpio0_hi 14 GPIO_ACTIVE_HIGH>; + label = "LEG4_ENABLE"; + }; + leg5_enable: leg5_enable { + gpios = <&gpio0_hi 15 GPIO_ACTIVE_HIGH>; + label = "LEG5_ENABLE"; + }; + }; + + pwm_servos { + compatible = "pwm-leds"; + + servo1: servo_1 { + pwms = <&pwm 0 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_1"; + }; + servo2: servo_2 { + pwms = <&pwm 1 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_2"; + }; + servo3: servo_3 { + pwms = <&pwm 2 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_3"; + }; + servo4: servo_4 { + pwms = <&pwm 3 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_4"; + }; + servo5: servo_5 { + pwms = <&pwm 4 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_5"; + }; + servo6: servo_6 { + pwms = <&pwm 5 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_6"; + }; + servo7: servo_7 { + pwms = <&pwm 6 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_7"; + }; + servo8: servo_8 { + pwms = <&pwm 7 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_8"; + }; + servo9: servo_9 { + pwms = <&pwm 8 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_9"; + }; + servo10: servo_10 { + pwms = <&pwm 9 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_10"; + }; + servo11: servo_11 { + pwms = <&pwm 10 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_11"; + }; + servo12: servo_12 { + pwms = <&pwm 11 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_12"; + }; + servo13: servo_13 { + pwms = <&pwm 12 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_13"; + }; + servo14: servo_14 { + pwms = <&pwm 13 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_14"; + }; + servo15: servo_15 { + pwms = <&pwm 14 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_15"; + }; + servo16: servo_16 { + pwms = <&pwm 15 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_16"; + }; + servo17: servo_17 { + pwms = <&pwm 16 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_17"; + }; + servo18: servo_18 { + pwms = <&pwm 17 PWM_USEC(20000) PWM_POLARITY_NORMAL>; + label = "SERVO_18"; + }; + }; + + mux: mux { + compatible = "cd74hc4067"; + status = "okay"; + select-gpios = <&gpio0_hi 2 GPIO_ACTIVE_HIGH>, + <&gpio0_hi 3 GPIO_ACTIVE_HIGH>, + <&gpio0_hi 6 GPIO_ACTIVE_HIGH>, + <&gpio0_hi 7 GPIO_ACTIVE_HIGH>; + }; + + aliases { + watchdog0 = &wdt0; + led0 = &led0; + led1 = &led1; + imu = &imu; + imu-int1 = &imu_int1; + imu-int2 = &imu_int2; + digital1 = &digital1; + digital2 = &digital2; + digital3 = &digital3; + digital4 = &digital4; + digital5 = &digital5; + digital6 = &digital6; + leg0-enable = &leg0_enable; + leg1-enable = &leg1_enable; + leg2-enable = &leg2_enable; + leg3-enable = &leg3_enable; + leg4-enable = &leg4_enable; + leg5-enable = &leg5_enable; + servo1 = &servo1; + servo2 = &servo2; + servo3 = &servo3; + servo4 = &servo4; + servo5 = &servo5; + servo6 = &servo6; + servo7 = &servo7; + servo8 = &servo8; + servo9 = &servo9; + servo10 = &servo10; + servo11 = &servo11; + servo12 = &servo12; + servo13 = &servo13; + servo14 = &servo14; + servo15 = &servo15; + servo16 = &servo16; + servo17 = &servo17; + servo18 = &servo18; + mux = &mux; + }; +}; + +&flash0 { + /* W25Q16JVUXIQ_TR: 16M-bit (2MB) NOR Flash */ + reg = <0x10000000 DT_SIZE_M(2)>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* Code partition: 256KB for application code (starts at beginning of flash) */ + code_partition: partition@0 { + label = "code"; + reg = <0x00000000 DT_SIZE_K(256)>; + read-only; + }; + + /* Settings partition: 64KB for settings data */ + settings_partition: partition@40000 { + label = "settings"; + reg = <0x00040000 DT_SIZE_K(64)>; + }; + + /* Data partition: 1728KB for data storage (largest partition) */ + data_partition: partition@50000 { + label = "data"; + reg = <0x00050000 DT_SIZE_K(1728)>; + }; + }; +}; + +zephyr_udc0: &usbd { + status = "okay"; + cdc_acm_uart0: cdc_acm_uart0 { + compatible = "zephyr,cdc-acm-uart"; + label = "USB_CDC"; + }; +}; + +gpio0_lo: &gpio0 { + status = "okay"; +}; + +&gpio0_hi { + status = "okay"; + +}; + +&i2c0 { + pinctrl-0 = <&i2c0_default>; + pinctrl-names = "default"; + status = "okay"; + clock-frequency = ; + + imu: icm45686@68 { + compatible = "invensense,icm42688"; + reg = <0x68>; + status = "disabled"; + + int1-gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>; + int2-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>; + + accel-pwr-mode = <3>; + accel-ord = <9>; + accel-fs = <16>; + accel-lpf = <0>; + + gyro-pwr-mode = <0>; /* turn off */ + gyro-ord = <9>; + gyro-fs = <2000>; + }; +}; + +&spi1 { + clock-frequency = ; + pinctrl-0 = <&spi1_default>; + pinctrl-names = "default"; + status = "disabled"; +}; + +&adc { + pinctrl-0 = <&adc_default>; + pinctrl-names = "default"; + status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + adc0: channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; + + adc1: channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; + + adc2: channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; +}; + +&pwm { + status = "okay"; + pinctrl-0 = <&pwm_default>; + pinctrl-names = "default"; + divider-int-0 = <64>; +}; + +&timer0 { + status = "okay"; +}; diff --git a/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3.dts b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3.dts new file mode 100644 index 0000000..10e828f --- /dev/null +++ b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3.dts @@ -0,0 +1,12 @@ +/dts-v1/; + +/* The build system assumes that there's a cpucluster-specific file. + * + * This file provides composition of the device tree: + * 1. The common features of the SoC + * 2. Core-specific configuration. + * 3. Board-specific configuration. + */ +#include +#include +#include "servo2350.dtsi" diff --git a/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3.yaml b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3.yaml new file mode 100644 index 0000000..e8db7b1 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3.yaml @@ -0,0 +1,20 @@ +identifier: servo2350/rp2350b/hazard3 +name: Servo2350 (Hazard3) +type: mcu +arch: riscv +flash: 16384 +ram: 8192 +toolchain: + - zephyr +supported: + - adc + - clock + - counter + - dma + - gpio + - hwinfo + - i2c + - pwm + - spi + - usbd + - uart diff --git a/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3_defconfig b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3_defconfig new file mode 100644 index 0000000..89fba55 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_hazard3_defconfig @@ -0,0 +1,10 @@ +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_BUILD_OUTPUT_UF2=y +CONFIG_CLOCK_CONTROL=y +CONFIG_CONSOLE=y +CONFIG_GPIO=y +CONFIG_RESET=y +CONFIG_SERIAL=y +CONFIG_UART_CONSOLE=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_USE_DT_CODE_PARTITION=y diff --git a/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33.dts b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33.dts new file mode 100644 index 0000000..f8b0b67 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33.dts @@ -0,0 +1,12 @@ +/dts-v1/; + +/* The build system assumes that there's a cpucluster-specific file. + * + * This file provides composition of the device tree: + * 1. The common features of the SoC + * 2. Core-specific configuration. + * 3. Board-specific configuration. + */ +#include +#include +#include "servo2350.dtsi" diff --git a/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33.yaml b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33.yaml new file mode 100644 index 0000000..89f4dec --- /dev/null +++ b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33.yaml @@ -0,0 +1,21 @@ +identifier: servo2350/rp2350b/m33 +name: Servo2350 (Cortex-M33) +type: mcu +arch: arm +flash: 16384 +ram: 8192 +toolchain: + - zephyr + - gnuarmemb +supported: + - adc + - clock + - counter + - dma + - gpio + - hwinfo + - i2c + - pwm + - spi + - usbd + - uart diff --git a/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33_defconfig b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33_defconfig new file mode 100644 index 0000000..89fba55 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/servo2350_rp2350b_m33_defconfig @@ -0,0 +1,10 @@ +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_BUILD_OUTPUT_UF2=y +CONFIG_CLOCK_CONTROL=y +CONFIG_CONSOLE=y +CONFIG_GPIO=y +CONFIG_RESET=y +CONFIG_SERIAL=y +CONFIG_UART_CONSOLE=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_USE_DT_CODE_PARTITION=y diff --git a/servo_controller/boards/arm/servo2350/support/openocd.cfg b/servo_controller/boards/arm/servo2350/support/openocd.cfg new file mode 100644 index 0000000..652ca53 --- /dev/null +++ b/servo_controller/boards/arm/servo2350/support/openocd.cfg @@ -0,0 +1,8 @@ +# Checking and set 'adapter speed'. +# Set the adaptor speed, if unset, and given as an argument. +proc set_adapter_speed_if_not_set { speed } { + puts "checking adapter speed..." + if { [catch {adapter speed} ret] } { + adapter speed $speed + } +}