Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards: canaan: Add initial support for canmv_k230 #74169

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,17 @@ Broadcom Platforms:
- soc/brcm/
- boards/brcm/

Canaan Platforms:
status: maintained
maintainers:
- judehahh
files:
- boards/canaan/canmv_k230/
- dts/riscv/canaan/
- soc/canaan/
labels:
- "platform: CANAAN"

GD32 Platforms:
status: maintained
maintainers:
Expand Down
5 changes: 5 additions & 0 deletions boards/canaan/canmv_k230/Kconfig.canmv_k230
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config BOARD_CANMV_K230
select SOC_CANAAN_K230
8 changes: 8 additions & 0 deletions boards/canaan/canmv_k230/board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

board:
name: canmv_k230
vendor: canaan
socs:
- name: k230
30 changes: 30 additions & 0 deletions boards/canaan/canmv_k230/canmv_k230.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Junhui Liu <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

/dts-v1/;

#include "canaan/k230.dtsi"

/ {
model = "Canaan CanMV-K230";
compatible = "cannan,canmv-k230";

ddr: memory@0 {
device_type = "memory";
reg = <0x0 0x0 0x0 0x20000000>;
};

chosen {
zephyr,console = &uart3;
zephyr,shell-uart = &uart3;
zephyr,sram = &ddr;
};
};

&uart3 {
status = "okay";
current-speed = <115200>;
};
9 changes: 9 additions & 0 deletions boards/canaan/canmv_k230/canmv_k230.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
identifier: canmv_k230
name: Canaan CanMV-K230
type: mcu
arch: riscv
toolchain:
- zephyr
- cross-compile
supported:
- uart
13 changes: 13 additions & 0 deletions boards/canaan/canmv_k230/canmv_k230_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: Apache-2.0

# Zephyr Kernel Configuration
CONFIG_XIP=n

# Serial Drivers
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_NS16550_ACCESS_WORD_ONLY=y

# Enable Console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
27 changes: 27 additions & 0 deletions boards/canaan/canmv_k230/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. _canmv_k230:

Canaan CanMV-K230
#################

Overview
********

The Canaan CanMV-K230 is a development board with a Canaan Kendryte K230
64bit RISC-V SoC.

Programming and debugging
*************************

Zephyr binary can be loaded by U-Boot command in machine mode.

.. code-block:: console

fatload mmc 1:1 0x0 zephyr.bin
go 0x0

Applications for the ``canmv_k230`` board configuration can be built as
usual (see :ref:`build_an_application`) using the corresponding board name:

.. zephyr-app-commands::
:board: canmv_k230
:goals: build
10 changes: 10 additions & 0 deletions boards/canaan/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _boards-canaan:

Canaan
######

.. toctree::
:maxdepth: 1
:glob:

**/*
8 changes: 8 additions & 0 deletions dts/bindings/cpu/thead,c908.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

description: T-Head C908 RISC-V CPU

compatible: "thead,c908"

include: riscv,cpus.yaml
103 changes: 103 additions & 0 deletions dts/riscv/canaan/k230.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2024 Junhui Liu <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
#address-cells = <2>;
#size-cells = <2>;
compatible = "canaan,kendryte-k230";
model = "canaan,k230";

cpus {
#address-cells = <1>;
#size-cells = <0>;

cpu0: cpu@0 {
compatible = "thead,c908", "riscv";
device_type = "cpu";
mmu-type = "riscv,sv39";
reg = <0>;
riscv,isa = "rv64imafdc_zicsr_zifencei";
status = "okay";

cpu0_intc: interrupt-controller {
compatible = "riscv,cpu-intc";
#address-cells = <0>;
#interrupt-cells = <1>;
interrupt-controller;
};
};
};

soc {
#address-cells = <2>;
#size-cells = <2>;
compatible = "canaan,k230-soc", "simple-bus";
interrupt-parent = <&plic>;
ranges;

plic: interrupt-controller@f00000000 {
compatible = "sifive,plic-1.0.0";
reg = <0xf 0x00000000 0x0 0x04000000>;
interrupt-controller;
interrupts-extended = <&cpu0_intc 11>, <&cpu0_intc 9>;
#address-cells = <0>;
#interrupt-cells = <2>;
riscv,max-priority = <7>;
riscv,ndev = <208>;
};

clint: clint@f04000000 {
compatible = "thead,machine-timer";
reg = <0xf 0x04000000 0x0 0x00010000>;
interrupts-extended = <&cpu0_intc 7>;
};

uart0: serial@91400000 {
compatible = "ns16550";
reg = <0x0 0x91400000 0x0 0x1000>;
interrupts = <16 1>;
reg-shift = <2>;
clock-frequency = <50000000>;
status = "disabled";
};

uart1: serial@91401000 {
compatible = "ns16550";
reg = <0x0 0x91401000 0x0 0x1000>;
interrupts = <17 1>;
reg-shift = <2>;
clock-frequency = <50000000>;
status = "disabled";
};

uart2: serial@91402000 {
compatible = "ns16550";
reg = <0x0 0x91402000 0x0 0x1000>;
interrupts = <18 1>;
reg-shift = <2>;
clock-frequency = <50000000>;
status = "disabled";
};

uart3: serial@91403000 {
compatible = "ns16550";
reg = <0x0 0x91403000 0x0 0x1000>;
interrupts = <19 1>;
reg-shift = <2>;
clock-frequency = <50000000>;
status = "disabled";
};

uart4: serial@91404000 {
compatible = "ns16550";
reg = <0x0 0x91404000 0x0 0x1000>;
interrupts = <20 1>;
reg-shift = <2>;
clock-frequency = <50000000>;
status = "disabled";
};
};
};
4 changes: 4 additions & 0 deletions soc/canaan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(${SOC_SERIES})
8 changes: 8 additions & 0 deletions soc/canaan/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

if SOC_FAMILY_CANAAN

rsource "*/Kconfig"

endif # SOC_FAMILY_CANAAN
8 changes: 8 additions & 0 deletions soc/canaan/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

if SOC_FAMILY_CANAAN

rsource "*/Kconfig.defconfig"

endif # SOC_FAMILY_CANAAN
10 changes: 10 additions & 0 deletions soc/canaan/Kconfig.soc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config SOC_FAMILY_CANAAN
bool

config SOC_FAMILY
default "canaan" if SOC_FAMILY_CANAAN

rsource "*/Kconfig.soc"
5 changes: 5 additions & 0 deletions soc/canaan/k230/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_include_directories(.)

set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "")
14 changes: 14 additions & 0 deletions soc/canaan/k230/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config SOC_SERIES_CANAAN_K230
select RISCV
select RISCV_PRIVILEGED
select RISCV_HAS_PLIC
select RISCV_ISA_RV64I
select RISCV_ISA_EXT_G
select RISCV_ISA_EXT_C

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update it when rebase

select INCLUDE_RESET_VECTOR
select ATOMIC_OPERATIONS_C
select 64BIT
24 changes: 24 additions & 0 deletions soc/canaan/k230/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

if SOC_SERIES_CANAAN_K230

config SYS_CLOCK_HW_CYCLES_PER_SEC
default 27000000

config RISCV_SOC_INTERRUPT_INIT
default y

config RISCV_GP
default y

config 2ND_LVL_ISR_TBL_OFFSET
default 12

config 2ND_LVL_INTR_00_OFFSET
default 11

config NUM_IRQS
default 208

endif
16 changes: 16 additions & 0 deletions soc/canaan/k230/Kconfig.soc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2024 Junhui Liu <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config SOC_SERIES_CANAAN_K230
bool
select SOC_FAMILY_CANAAN

config SOC_CANAAN_K230
bool
select SOC_SERIES_CANAAN_K230

config SOC_SERIES
default "k230" if SOC_SERIES_CANAAN_K230

config SOC
default "k230" if SOC_CANAAN_K230
Comment on lines +13 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the text here, it needs to match the symbol, if you have k230 then you need SOC_SERIES_K230/SOC_K230, if you have canaan_k280 then you need SOC_SERIES_CANAAN_K230/SOC_CANAAN_K230

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I'll update it when rebase

4 changes: 4 additions & 0 deletions soc/canaan/k230/soc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
series:
- name: k230
socs:
- name: k230
6 changes: 6 additions & 0 deletions soc/canaan/soc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
family:
- name: canaan
series:
- name: k230
socs:
- name: k230
Loading