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

MKS CANable V2.0 #81366

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
10 changes: 10 additions & 0 deletions boards/makerbase/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _boards-makerbase:

Makerbase
KozhinovAlexander marked this conversation as resolved.
Show resolved Hide resolved
##################
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
##################
#########


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

**/*
5 changes: 5 additions & 0 deletions boards/makerbase/mks_canable_v20/Kconfig.mks_canable_v20
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2024 Alexander Kozhinov <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config BOARD_MKS_CANABLE_V20
select SOC_STM32G431XX
6 changes: 6 additions & 0 deletions boards/makerbase/mks_canable_v20/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2024 Alexander Kozhinov <[email protected]>
# SPDX-License-Identifier: Apache-2.0

board_runner_args(openocd "--config=${BOARD_DIR}/support/openocd.cfg")

include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
6 changes: 6 additions & 0 deletions boards/makerbase/mks_canable_v20/board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
board:
name: mks_canable_v20
full_name: MKS Canable V2.0
KozhinovAlexander marked this conversation as resolved.
Show resolved Hide resolved
vendor: makerbase
socs:
- name: stm32g431xx
Binary file not shown.
173 changes: 173 additions & 0 deletions boards/makerbase/mks_canable_v20/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
.. zephyr:board:: mks_canable_v20

Overview
********

The Makerbase MKS CANable V2.0 board features an ARM Cortex-M4 based STM32G431C8 MCU
KozhinovAlexander marked this conversation as resolved.
Show resolved Hide resolved
with a wide range of connectivity support and configurations.
Copy link
Member

@henrikbrixandersen henrikbrixandersen Nov 18, 2024

Choose a reason for hiding this comment

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

A range of? Not on this board, so I think that can be removed from the board description.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MCU supports a range of.... But in terms of board I agree and will update

Here are some highlights of the MKS CANable V2.0 board:

- STM32 microcontroller in LQFP48 package
- USB Type-C connector (J1)
- CAN-Bus connector (J2)
- ST-LINK/V3E debugger/programmer header (J4)
- USB VBUS power supply (5 V)
- Three LEDs: red/power_led (D1), blue/stat_led (D2), green/word_led (D3)
- One push-button for RESET
- Development support: serial wire debug (SWD), JTAG, Embedded Trace Macrocell.

The LED red/power_led (D1) is connected directly to on-board 3.3 V and not controllable by the MCU.

More information about the board can be found at the `MKS CANable V2.0 website`_.
It is very advisable to take a look in on user manual `MKS CANable V2.0 User Manual`_ and
schematic `MKS CANable V2.0 schematic`_ before start.

More information about STM32G431KB can be found here:

- `STM32G431C8 on www.st.com`_
- `STM32G4 reference manual`_

Supported Features
==================

The Zephyr ``mks_canable_v20`` board target supports the following hardware features:

+-----------+------------+-------------------------------------+
| Interface | Controller | Driver/Component |
+===========+============+=====================================+
| NVIC | on-chip | nested vector interrupt controller |
+-----------+------------+-------------------------------------+
| USB | on-chip | universal-serial-bus |
+-----------+------------+-------------------------------------+
| PINMUX | on-chip | pinmux |
+-----------+------------+-------------------------------------+
| GPIO | on-chip | gpio |
+-----------+------------+-------------------------------------+
| PWM | on-chip | pwm |
Copy link
Member

Choose a reason for hiding this comment

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

Where is PWM used on this board?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Planned to use it for PWM LED since i see LEDs on th board as way to bright. But for the current PR it may be removed - agree.

+-----------+------------+-------------------------------------+
| FDCAN | on-chip | can |
+-----------+------------+-------------------------------------+

Other hardware features are not yet supported on this Zephyr port.

The default configuration can be found in the defconfig file:
:zephyr_file:`boards/makerbase/mks_canable_v20/mks_canable_v20_defconfig`


Connections and IOs
===================

The stm32g431c8 mcu is the core of MKS CANable V2.0 board and it has 6 GPIO controllers.
These controllers are responsible for pin muxing, input/output, pull-up, etc.
Comment on lines +60 to +61
Copy link
Member

Choose a reason for hiding this comment

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

This is not that important for the board configuration and could be removed.


For more details please refer to `MKS CANable V2.0 schematic`_.

Default Zephyr Peripheral Mapping is fixed by `MKS CANable V2.0 schematic`_:
Copy link
Member

Choose a reason for hiding this comment

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

What does this mean?

----------------------------------------------------------------------------

.. rst-class:: rst-columns

- CAN_RX/BOOT0 : PB8
- CAN_TX : PB9
- D2 : PA15
- D3 : PA0
- USB_DN : PA11
- USB_DP : PA12
- SWDIO : PA13
- SWCLK : PA14
- NRST : PG10

System Clock
------------

The MKS CANable V2.0 system clock is driven by internal high speed oscillator.
By default system clock is driven by PLL clock at 170 MHz,
the PLL is driven by the 16 MHz high speed internal oscillator.
Comment on lines +83 to +85
Copy link
Member

Choose a reason for hiding this comment

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

At which frequency are you clocking the CAN controllers?


Programming and Debugging
*************************

MKS CANable V2.0 board includes an SWDIO debug connector header J4.

.. note::

The debugger is not the part of the board!

Applications for the ``mks_canable_v20`` board target can be built and
flashed in the usual way (see :ref:`build_an_application` and
:ref:`application_run` for more details).

Flashing
========

The board is configured to be flashed using west OpenOCD runner.
Copy link
Member

Choose a reason for hiding this comment

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

We usually don't mention this in the board documentation, as other runners can be added and used as well.


Flashing an application to MKS CANable V2.0
-------------------------------------------

The debugger shall be wired to MKS CANable V2.0 board's J4 connector
according `MKS CANable V2.0 schematic`_.

Build and flash an application. Here is an example for
:zephyr:code-sample:`hello_world`.

.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: mks_canable_v20
:goals: build flash
:west-args: -S rtt-console
:compact:

The argument ``-S rtt-console`` is needed for debug purposes with SEGGER RTT protocol.
This option is optional and may be omitted. Omitting it frees up RAM space but prevents RTT usage.

If option ``-S rtt-console`` is selected, the connection to the target can be established as follows:

.. code-block:: console

$ telnet localhost 9090

You should see the following message on the console:

.. code-block:: console

$ Hello World! mks_canable_v20/stm32g431xx

.. note::

Current OpenOCD config will skip Segger RTT for OpenOCD under 0.12.0.
Comment on lines +121 to +138
Copy link
Member

Choose a reason for hiding this comment

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

I would remove all of this and just refer to the common documentation on how to use Segger RTT.


Debugging
=========

You can debug an application in the usual way. Here is an example for the
:zephyr:code-sample:`hello_world` application.

.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: mks_canable_v20
:maybe-skip-config:
:goals: debug

References
**********

.. target-notes::

.. _MKS CANable V2.0 website:
https://github.com/makerbase-mks/CANable-MKS

.. _MKS CANable V2.0 User Manual:
https://github.com/makerbase-mks/CANable-MKS/blob/main/User%20Manual/CANable%20V2.0/Makerbase%20CANable%20V2.0%20Use%20Manual.pdf

.. _MKS CANable V2.0 schematic:
https://github.com/makerbase-mks/CANable-MKS/blob/main/Hardware/MKS%20CANable%20V2.0/MKS%20CANable%20V2.0_001%20schematic.pdf

.. _STM32G431C8 on www.st.com:
https://www.st.com/en/microcontrollers-microprocessors/stm32g431c8.html

.. _STM32G4 reference manual:
https://www.st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf

.. _STM32CubeProgrammer:
https://www.st.com/en/development-tools/stm32cubeprog.html
137 changes: 137 additions & 0 deletions boards/makerbase/mks_canable_v20/mks_canable_v20.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright (c) 2024 Alexander Kozhinov <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

/dts-v1/;
#include <st/g4/stm32g431X8.dtsi>
#include <st/g4/stm32g431c(6-8-b)tx-pinctrl.dtsi>

/ {
model = "Makerbase MKS CANable V2.0";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
model = "Makerbase MKS CANable V2.0";
model = "MakerBase MKS CANable V2.0";

compatible = "makerbase,mks-canable-v20";

chosen {
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,canbus = &fdcan1;
};

aliases {
led0 = &blue_led;
led1 = &green_led;
mcuboot-led0 = &blue_led;
};

leds: leds {
compatible = "gpio-leds";
blue_led: led_2 {
gpios = <&gpioa 15 GPIO_ACTIVE_LOW>;
label = "blue-status D2";
};
green_led: led_3 {
gpios = <&gpioa 0 GPIO_ACTIVE_LOW>;
label = "green-word D3";
};
};

aliases {
led0 = &green_led;
};
};

&clk_lsi {
status = "okay";
};

&clk_hsi {
status = "okay";
};

&clk_hsi48 {
status = "okay";
};

/* Adjust the pll for a SYSTEM Clock of 170MHz */
&pll {
div-m = <4>;
mul-n = <85>;
div-p = <7>;
div-q = <2>;
div-r = <2>;
clocks = <&clk_hsi>;
status = "okay";
};

&rcc {
clocks = <&pll>;
clock-frequency = <DT_FREQ_M(170)>;
ahb-prescaler = <1>;
apb1-prescaler = <1>;
apb2-prescaler = <1>;
};

&rng {
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x04000000>,
<&rcc STM32_SRC_HSI48 CLK48_SEL(0)>;
status = "okay";
};

stm32_lp_tick_source: &lptim1 {
clocks = <&rcc STM32_CLOCK_BUS_APB1 0x80000000>,
<&rcc STM32_SRC_LSE LPTIM1_SEL(3)>;
status = "okay";
};

&rtc {
status = "okay";
clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00000400>,
<&rcc STM32_SRC_LSI RTC_SEL(2)>;
};

&iwdg {
status = "okay";
};

&die_temp {
status = "okay";
};
Comment on lines +75 to +99
Copy link
Member

Choose a reason for hiding this comment

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

Have you tested RNG, RTC, IWDG, and die temperature sensor? If not, please remove them.


&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(16)>;
Copy link
Member

Choose a reason for hiding this comment

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

I doubt you will be able to fit MCUboot into 16k flash for this board? Have you tested it?

read-only;
};
slot0_partition: partition@c000 {
label = "image-0";
reg = <0x0000c000 DT_SIZE_K(48)>;
};
};
};

zephyr_udc0: &usb {
pinctrl-0 = <&usb_dm_pa11 &usb_dp_pa12>;
pinctrl-names = "default";
clocks = <&rcc STM32_CLOCK(APB1, 23U)>,
<&rcc STM32_SRC_HSI48 CLK48_SEL(0)>;
status = "okay";

cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
Comment on lines +126 to +128
Copy link
Member

Choose a reason for hiding this comment

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

This should be removed.

};

&fdcan1 {
pinctrl-0 = <&fdcan1_rx_pb8 &fdcan1_tx_pb9>;
pinctrl-names = "default";
clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00001000>,
<&rcc STM32_SRC_PLL_Q FDCAN_SEL(1)>;
status = "okay";
};
20 changes: 20 additions & 0 deletions boards/makerbase/mks_canable_v20/mks_canable_v20.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
identifier: mks_canable_v20
name: MKS CANable V2.0
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
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
- xtools

#80466

ram: 32
flash: 64
supported:
- can
- gpio
- rng
- counter
Comment on lines +14 to +15
Copy link
Member

Choose a reason for hiding this comment

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

Have you ran the tests for these?

- pinctrl
- usb_device
- usbd
- watchdog
Copy link
Member

Choose a reason for hiding this comment

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

Same here?

vendor: makerbase
7 changes: 7 additions & 0 deletions boards/makerbase/mks_canable_v20/mks_canable_v20_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2024 Alexander Kozhinov <[email protected]>
# SPDX-License-Identifier: Apache-2.0

CONFIG_GPIO=y
CONFIG_ARM_MPU=y
CONFIG_HW_STACK_PROTECTION=y
CONFIG_ENTROPY_GENERATOR=y
Copy link
Member

@henrikbrixandersen henrikbrixandersen Nov 18, 2024

Choose a reason for hiding this comment

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

Why is CONFIG_ENTROPY_GENERATOR enabled?

Loading
Loading