Skip to content

Add minimal support for Microchip SAMA7G54-EK #89145

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

Merged
merged 12 commits into from
May 28, 2025

Conversation

TonyHan11
Copy link
Contributor

  • Add minimal support for sama7g54-ek as following
Interface Controller Driver/Component
GICv2 on-chip arch/arm
GPIO on-chip pinctrl
PMC on-chip clock_control
SCKC on-chip clock_control
Flexcom on-chip mfd
USART on-chip serial
PIT64B on-chip timer

Need: zephyrproject-rtos/hal_microchip#27

Copy link

Hello @TonyHan11, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds minimal support for the Microchip SAMA7G54-EK board by implementing necessary updates and drivers for USART, pinctrl, MFD (Flexcom), clock control, and the board definition.

  • In usart_sam.c, initialization levels and baudrate calculations are updated to support board‐specific clock configurations.
  • New drivers are added for pinctrl, flexcom, and clock control modules, along with a new board YAML file for sama7g54_ek.

Reviewed Changes

Copilot reviewed 44 out of 58 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
drivers/serial/usart_sam.c Updated initialization level macros and baudrate calculation logic.
drivers/pinctrl/pinctrl_sam_pio4.c New pin configuration driver for SAM PIO, with potential bit-clear issues.
drivers/mfd/mfd_mchp_sam_flexcom.c Added minimal flexcom support using DT properties and logging.
drivers/clock_control/clock_control_sama7g5_sckc.c New clock control driver for SCKC manage oscillator selection.
drivers/clock_control/clock_control_sama7g5_pmc.c Implements PMC clock control with DT-based configuration.
boards/microchip/sam/sama7g54_ek/board.yml Board definition added for SAMA7G54-EK.
Files not reviewed (14)
  • boards/microchip/sam/sama7g54_ek/Kconfig.defconfig: Language not supported
  • boards/microchip/sam/sama7g54_ek/Kconfig.sama7g54_ek: Language not supported
  • boards/microchip/sam/sama7g54_ek/doc/index.rst: Language not supported
  • boards/microchip/sam/sama7g54_ek/sama7g54_ek.dts: Language not supported
  • boards/microchip/sam/sama7g54_ek/sama7g54_ek_defconfig: Language not supported
  • drivers/clock_control/CMakeLists.txt: Language not supported
  • drivers/clock_control/Kconfig.sam: Language not supported
  • drivers/mfd/CMakeLists.txt: Language not supported
  • drivers/mfd/Kconfig: Language not supported
  • drivers/mfd/Kconfig.mchp_sam: Language not supported
  • drivers/pinctrl/CMakeLists.txt: Language not supported
  • drivers/pinctrl/Kconfig.sam: Language not supported
  • drivers/serial/Kconfig.usart_sam: Language not supported
  • drivers/timer/CMakeLists.txt: Language not supported

@TonyHan11 TonyHan11 force-pushed the sama7g5_minimal_support branch 2 times, most recently from 0b28dd6 to 9b8a328 Compare April 28, 2025 04:23
Comment on lines 14 to 15
default y
depends on DT_HAS_MICROCHIP_SAMA5D2_FLEXCOM_ENABLED
Copy link
Collaborator

Choose a reason for hiding this comment

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

the underlying driver should select MFD since it requires it, not do this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, the config here will be removed and add select MFD in config USART_SAM. Thanks.

if BOARD_SAMA7G54_EK

config SYS_CLOCK_HW_CYCLES_PER_SEC
default 10000000
Copy link
Collaborator

Choose a reason for hiding this comment

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

needs to come from dts property

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The config here will be removed and add CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=10000000 to boards/microchip/sam/sama7g54_ek/sama7g54_ek_defconfig. Thank you very much.

Copy link
Collaborator

Choose a reason for hiding this comment

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

no, you need to get it from a dts property, if you just move this to a defconfig you're going to get the same nack and comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll try to get it from the DT. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

needs to come from dts property

Hi @nordicjm ,
I haven't found a way to get this config from dts. As it is described in Kernel/Kconfig, this option is set by the SOC's or board's Kconfig file.
Might it is confused with another option.
In the support for other boards SYS_CLOCK_HW_CYCLES_PER_SEC come from the defconfig too (see grep -Hnr SYS_CLOCK_HW_CYCLES_PER_SEC boards/).
Thank you for your advice.

Copy link
Member

Choose a reason for hiding this comment

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

config SYS_CLOCK_HW_CYCLES_PER_SEC
default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nandojve Got it, thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

convert to webp, then put through https://tinypng.com/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, thanks.


CONFIG_CONSOLE=y
CONFIG_SERIAL=y
# CONFIG_BOOT_BANNER is not set
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
# CONFIG_BOOT_BANNER is not set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reasons of do not output the banner are list bellow:

  • As k_calloc() is used in the clock drivers, the initialize level of clock-controller needs be POST_KERNEL
  • The serial for console used clock-controller for initialize, so the initialize level of it needs to be POST_KERNEL too
  • The banner is designed to be output before POST_KERNEL, in this case skip it to avoid the boot stuck due to the serial is not ready then

Copy link
Collaborator

Choose a reason for hiding this comment

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

If this does not work then your board/soc/driver setup fails the minimum requirement for zephyr and needs to be reworked to work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll remove all the k_calloc() to make it work.

CONFIG_UART_CONSOLE=y
CONFIG_USART_SAM=y
CONFIG_CLOCK_CONTROL_FIXED_RATE_CLOCK=y
CONFIG_HEAP_MEM_POOL_SIZE=32768
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
CONFIG_HEAP_MEM_POOL_SIZE=32768

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In code of clock drivers (soc/microchip/sam/common), k_calloc() are used for acquiring memories for struct of clocks. The default value of CONFIG_HEAP_MEM_POOL_SIZE is 0 and it would cause k_calloc() fail.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the part that feels wrong, SoC code shouldn't depend on heap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

a clock driver should frankly not need malloc at all, I would say something is very wrong with your driver design

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ping @nordic-krch for comment

Comment on lines 8 to 12
#define DT_DRV_COMPAT atmel_sam_usart
#ifdef CONFIG_DT_HAS_MICROCHIP_AT91SAM9260_USART_ENABLED
#undef DT_DRV_COMPAT
#define DT_DRV_COMPAT microchip_at91sam9260_usart
#endif
Copy link
Collaborator

@nordicjm nordicjm Apr 28, 2025

Choose a reason for hiding this comment

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

rename the driver instead? Ping @decsny

Copy link
Member

Choose a reason for hiding this comment

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

@nordicjm What do you mean with rename the driver ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

atmel_sam_usart just seems to be microchip_at91sam9260_usart?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add a new driver for usart to avoid #undef and #define. Thank you for your comments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was more meaning why not just use the existing name? Why does need a new binding and driver name when the driver (and, I assume silicon) is the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The driver is the same (for USART standalone vs Flexcom (USART/TWI/SPI included) peripheral), actually I used it to handle the initialize level issue. We can use the driver after solving the k_calloc() issue, thanks.

Copy link
Member

Choose a reason for hiding this comment

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

atmel_sam_usart just seems to be microchip_at91sam9260_usart?

Ahh ok.

What I understood is that maybe we need to support multiple dts bindings here. The MCHP will start to send a lot of new bindings that can be shared between Microchip/Atmel because the driver is the same. I assume this will be something common over the time.

For instance, in the past I fixed the the Ethernet and shared between to complete different series like this:

#if defined(CONFIG_SOC_FAMILY_ATMEL_SAM)
#define DT_DRV_COMPAT atmel_sam_gmac
#else
#define DT_DRV_COMPAT atmel_sam0_gmac
#endif

So, the outcome for me is define the acceptable pattern to allow multiple bindings inside the driver.

Copy link

github-actions bot commented May 19, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_microchip zephyrproject-rtos/hal_microchip@15ca197 zephyrproject-rtos/hal_microchip@4b74f40 zephyrproject-rtos/hal_microchip@15ca1970..4b74f408

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

Update west.yml for SAMA7G54 HAL

Signed-off-by: Tony Han <tony.han@microchip.com>
@TonyHan11 TonyHan11 force-pushed the sama7g5_minimal_support branch from 0c75ff0 to b15ce8e Compare May 19, 2025 07:07
TonyHan11 added 11 commits May 20, 2025 11:07
Product URL: https://www.microchip.com/en-us/product/SAMA7G54

Signed-off-by: Tony Han <tony.han@microchip.com>
Add code for sama7g5 Generic Clock, Main Clock, Main System Bus Clock,
Peripheral Clock, Programmable Clock and PLL Clock.

Signed-off-by: Tony Han <tony.han@microchip.com>
Initialize the configurations for PMC driver.
Add implement of the API for PMC clocks.

Signed-off-by: Tony Han <tony.han@microchip.com>
Add driver for sama7g5 Slow Clock Controller (SCKC).

Signed-off-by: Tony Han <tony.han@microchip.com>
The FLEXCOM offers several serial communication protocols that are
managed by the three sub-modules USART, SPI, and TWI (I2C).

Signed-off-by: Tony Han <tony.han@microchip.com>
The USART is compatiable with the USART feature in sama7g5's Flexcom.
Update serial/usart_sam to support sama7g5.

Signed-off-by: Tony Han <tony.han@microchip.com>
Support pull up/down, open drain for sam7g5's PIO.

Signed-off-by: Tony Han <tony.han@microchip.com>
Use pit64b0 as systick, make "kernel sleep/uptime" commands work.

Signed-off-by: Tony Han <tony.han@microchip.com>
Add the base DTSI file for Microchip sama7g5.

Signed-off-by: Tony Han <tony.han@microchip.com>
Introduce sama7g54_ek.dts for sama7g54_ek board.

Signed-off-by: Tony Han <tony.han@microchip.com>
@TonyHan11 TonyHan11 force-pushed the sama7g5_minimal_support branch from b15ce8e to 0bf699e Compare May 20, 2025 03:17
Copy link

@TonyHan11
Copy link
Contributor Author

@nandojve
updated with the revision for hal_microchip and fix the error in CI checks.
Result: 1 neutral, 2 skipped, 26 successful checks.

@TonyHan11
Copy link
Contributor Author

@kartben , @nordicjm ,
Would you like to review the pull request again as all the known issues have been fixed? Thanks a lot in advance.

@kartben kartben assigned nandojve and unassigned nordic-krch May 27, 2025
@nandojve nandojve requested a review from nordicjm May 27, 2025 19:19
@kartben
Copy link
Collaborator

kartben commented May 27, 2025

Let's wait a bit for @nordicjm to confirm he's +1 on the additional changes but let's proceed to merge otherwise as he had previously approved

@kartben kartben merged commit f862716 into zephyrproject-rtos:main May 28, 2025
29 checks passed
Copy link

Hi @TonyHan11!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.

Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁

@TonyHan11 TonyHan11 deleted the sama7g5_minimal_support branch May 28, 2025 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Clock Control area: MFD area: Pinctrl area: Timer Timer area: UART Universal Asynchronous Receiver-Transmitter manifest manifest-hal_microchip platform: Microchip MEC Microchip MEC Platform platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants