Skip to content

libutils: Add support for stm32mp2 SoC family#205

Draft
bruelc wants to merge 1 commit intoseL4:masterfrom
bruelc:master-stm32mp2
Draft

libutils: Add support for stm32mp2 SoC family#205
bruelc wants to merge 1 commit intoseL4:masterfrom
bruelc:master-stm32mp2

Conversation

@bruelc
Copy link

@bruelc bruelc commented Feb 12, 2026

Description

Add support for uart and timers for stm32mp2 soc

Link to kernel PR seL4

Testing

Testing was part of the seL4-test and seL4-bench test suites

Supports UART and the general purpose 32bit autoreload counters
TIM2 and TIM3 to implement timeout and timestamp timers utilities

Signed-off-by: Christian Bruel <christian.bruel@foss.st.com>
@bruelc bruelc marked this pull request as draft February 12, 2026 10:06
@Indanz Indanz marked this pull request as ready for review February 17, 2026 14:15
@Indanz Indanz marked this pull request as draft February 17, 2026 14:15
Copy link
Contributor

@Indanz Indanz left a comment

Choose a reason for hiding this comment

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

You don't handle 32-bit timer overflows, you probably want to register an IRQ handler for that. Alternatively, you can probably link two timers into one 64-bit timer and ignore overflows.

You also use two hard-coded timers, instead of one. Each timer has four channels which can be used for compare independently. I'd use one for the timeout function and another for overflow detection, if there is no other way. Except if it's one of those stupid timers which can't be reprogrammed on-the-fly without stopping it, in which case you do need to use two timers and document this somewhere. But the datasheet says "The TIMx_CCRx register can be updated at any time by software to control the output waveform, provided that the preload register is not enable", so it seems okay.

But if hard-coding timers like this, it doesn't make much sense to use the DTS walker either, as you know everything already. (Keep it if the code is simpler though.)

/* official device names */
enum chardev_id {
UART0,
UART1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is UART1 actually supported by this driver? If not, leave it out.

The SoC has about 10 UARTs, probably a good idea to follow the datasheet UART names in this enum and elsewhere.


#pragma once

#define UART0_PADDR 0x400E0000
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually USART2.

#pragma once

#define UART0_PADDR 0x400E0000
#define UART1_PADDR 0x400F0000
Copy link
Contributor

Choose a reason for hiding this comment

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

And this is USART3.

* Copyright 2026, STMicroelectronics
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good to give an overview here of which timers you're using and how and why (if it's more than one).

Comment on lines +27 to +29
#define RCC_APB1DIVR_OFF 0x4B4
#define RCC_APB1DIVR_PADDR (RCC_PADDR + RCC_APB1DIVR_OFF)
#define RCC_APB1DIVR_SIZE 4
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird indentation. And also unused?

#include "../../common.h"
#include <utils/util.h>

#include "../../chardev.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate, and see Julia's comment elsewhere.

uint32_t tisel;
uint32_t pad[0xEA];
uint32_t ipidr;
} stm32_regs_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

This structure you can move to timer.c instead, leaving a forward declaration behind. Same for most of the defines. But whatever you prefer.

Comment on lines +20 to +23
static const struct dev_defn dev_defn[] = {
UART_DEFN(0),
UART_DEFN(1),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

If you use this construction instead of hard-coding a specific UART, any reason not to add all compatible ones?

#include "../../ltimer.h"

/*
* We use two dm timers: one to keep track of an absolute time, the other for timeouts.
Copy link
Contributor

Choose a reason for hiding this comment

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

You're using the TIM2 and TIM3 general purpose timers. What do you mean with "dm"?

Also, each timer seems to have four channels, so why do you need to use two timers?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants