Skip to content

Conversation

@MCHP-MPU-Solutions-SHA
Copy link
Contributor

Add counter driver for sama7g5 pit64b IP, use it as a standard zephyr counter device.
pit64 has only one compare register, by default pit64 counter device only have top_value channel, and have no alarm channel.

Didn't add support in samples/drivers/counter/alarm because pit64b counter device have no alarm channel by default.
Didn't add support in tests/drivers/counter/counter_basic_api because pit64b has no get_value() api, and get_value_64() should be used.

Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

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

Hi Xing,

You need to follow always the dependency order. In this case, you need to reorder the commits:

dts: arm: microchip: sam: add pit64b device to sama7g5
drivers: counter: add support for sama7g54 PIT64B

Then you need to proper extract and name those commits:

west: Add mchp sam pit64b dependency (when applicable)
dts: bindings: counter: Add mchp sam pit64b
soc: ? You need to add the early init because it is a pre-req to the driver.
drivers: counter: Introduce pit64b driver
boards: ? You need to consume the driver on a board
tests: ? You should enable the tests using that board (when applicable)

In the first commit, you create the binding and already can add the relevant nodes inside MPU dtsi.
In the drivers commit, you will put all the driver/kconfig/cmake work at once.
Finally you can consume the driver on a board.

This sequence allow each maintainer look in the topics that are relevant and do not break git bisect. If we see that something is missing in the hal, the west changes should be the first commit in the series using the reference pull/<pr number>/head.

BTW, we do not accept a driver that it is not build on a test or on a board.

@albertofloyd albertofloyd removed their request for review August 4, 2025 20:46
@zephyrbot zephyrbot added the area: Samples Samples label Aug 5, 2025
@zephyrbot zephyrbot requested review from kartben and nashif August 5, 2025 10:10
@MCHP-MPU-Solutions-SHA
Copy link
Contributor Author

MCHP-MPU-Solutions-SHA commented Aug 5, 2025

Hi Xing,

You need to follow always the dependency order. In this case, you need to reorder the commits:

dts: arm: microchip: sam: add pit64b device to sama7g5 drivers: counter: add support for sama7g54 PIT64B

Then you need to proper extract and name those commits:

west: Add mchp sam pit64b dependency (when applicable) dts: bindings: counter: Add mchp sam pit64b soc: ? You need to add the early init because it is a pre-req to the driver. drivers: counter: Introduce pit64b driver boards: ? You need to consume the driver on a board tests: ? You should enable the tests using that board (when applicable)

In the first commit, you create the binding and already can add the relevant nodes inside MPU dtsi. In the drivers commit, you will put all the driver/kconfig/cmake work at once. Finally you can consume the driver on a board.

This sequence allow each maintainer look in the topics that are relevant and do not break git bisect. If we see that something is missing in the hal, the west changes should be the first commit in the series using the reference pull/<pr number>/head.

BTW, we do not accept a driver that it is not build on a test or on a board.

Hi Gerson,

Thank you so much for this detailed guide!

I have reorder these commits, please help to check.
Here is the updated commit list:

  1. dts: arm: microchip: sam: add pit64b device to sama7g5
    dts/arm/microchip/sam/sama7g5.dtsi

  2. drivers: counter: add support for sama7g54 PIT64B
    drivers/counter/Kconfig
    drivers/counter/Kconfig.mchp_sam_pit64b
    drivers/counter/counter_mchp_sam_pit64b.c

  3. dts: bindings: counter: add mchp sam pit64b
    dts/bindings/counter/microchip,sam-pit64b-counter.yaml

  4. soc: microchip: sam: update mmu for sama7g5 pit64b
    soc/microchip/sam/sama7g5/soc.c

  5. drivers: counter: introduce mchp sam pit64b driver
    drivers/counter/CMakeLists.txt

  6. boards: microchip: sam: add and enable pit64b1
    boards/microchip/sam/sama7g54_ek/sama7g54_ek.dts

For this issue:
BTW, we do not accept a driver that it is not build on a test or on a board.
Please check commit ff8d0ef and daff86a.
Will you accept this solution? because PIT64B can only accept "COUNTER_ALARM_CFG_ABSOLUTE" alarm flag.
With these two commits pit64b counter device works well with zephyr/samples/drivers/counter/alarm.

Many thanks.
Xing.

@nandojve nandojve changed the title Sama7g5 pit64 drivers: counter: sam: Introduce sama7g5 pit64b Aug 5, 2025
@nandojve nandojve added this to the v4.3.0 milestone Aug 16, 2025
@MCHP-MPU-Solutions-SHA
Copy link
Contributor Author

Hi Xing,

I still don't see the driver in the list. Unfortunately, you need to force an entry here:

People are trying to reduce the number of board that compile the driver. This is something that we need to reevaluate in the project because, sometimes, we have different paths inside the driver.

So, only the boards in the list will build (no variations).

CC: @NhMch

Hi Gerson,
File zephyr/samples/drivers/counter/alarm/sample.yaml has been updated.
And verified with command:
west twister -p sama7g54_ek -s sample.drivers.counter.alarm

@nandojve
Copy link
Member

needs rebase

@MCHP-MPU-Solutions-SHA
Copy link
Contributor Author

needs rebase

PR has been rebased.

nandojve
nandojve previously approved these changes Sep 18, 2025
Copy link
Contributor

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

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

Comment on lines +126 to +132
k_spinlock_key_t key;

key = k_spin_lock(&data->lock);

*ticks = (uint32_t)pit_counter_value(config->regs);

k_spin_unlock(&data->lock, key);
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternative is to use K_SPINLOCK, which is a bit cleaner IMO (doesn't work with return statements in the block).

	K_SPINLOCK(&data->lock) {
		*ticks = (uint32_t)pit_counter_value(config->regs);
	}

@nandojve
Copy link
Member

Xing,

I think you need to rebase due to CI issues.

@MCHP-MPU-Solutions-SHA
Copy link
Contributor Author

Xing,

I think you need to rebase due to CI issues.

Gerson,

So, maybe this issue "Some checks were not successful" can be fixed by a rebase?
Actually I'm trying to fix it but can not find the root cause.

@pdgendt
Copy link
Contributor

pdgendt commented Sep 24, 2025

So, maybe this issue "Some checks were not successful" can be fixed by a rebase? Actually I'm trying to fix it but can not find the root cause.

Probably, a Python dependency was added on main

@nandojve
Copy link
Member

So, maybe this issue "Some checks were not successful" can be fixed by a rebase? Actually I'm trying to fix it but can not find the root cause.

Probably, a Python dependency was added on main

ahh, so if CI is broken then we need to wait the fix.
But we can make PR ready in the meantime : )

@pdgendt
Copy link
Contributor

pdgendt commented Sep 24, 2025

ahh, so if CI is broken then we need to wait the fix. But we can make PR ready in the meantime : )

A fix has already been merged to main, a rebase should get you going again.

@MCHP-MPU-Solutions-SHA
Copy link
Contributor Author

Many thanks for comments.
I will rebase this PR firstly.

Add pit64b1 ~ pit64b5 counter devices to sama7g5

Signed-off-by: CHEN Xing <[email protected]>
Add driver for sama7g54 PIT64B
Use PIT64B as a zephyr counter device

Signed-off-by: CHEN Xing <[email protected]>
Update mmu region for mchp sam pit64b
Add gclk configuration for mchp sam pit64b

Signed-off-by: CHEN Xing <[email protected]>
Add and enable pit64b1 counter device.

Signed-off-by: CHEN Xing <[email protected]>
Counter devices can use this definition to specify alarm flags.

Signed-off-by: CHEN Xing <[email protected]>
Add support for pit64b1 counter device.

Signed-off-by: CHEN Xing <[email protected]>
@sonarqubecloud
Copy link

@MCHP-MPU-Solutions-SHA
Copy link
Contributor Author

ahh, so if CI is broken then we need to wait the fix. But we can make PR ready in the meantime : )

A fix has already been merged to main, a rebase should get you going again.

I have rebase this PR, and the CI issue has gone.
Many thanks for support.

@nandojve nandojve requested a review from NhMchp October 23, 2025 16:27
@nandojve
Copy link
Member

needs rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Counter area: Samples Samples 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.

5 participants