Skip to content

Draft: STM32 periph clk: centralize conditional code #20532

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

Closed
wants to merge 2 commits into from

Conversation

Enoch247
Copy link
Contributor

@Enoch247 Enoch247 commented Apr 2, 2024

Contribution description

This is a work in progress. I wanted to put it out there to get some feedback. See review comments for areas where feedback is especially requested.

Testing procedure

TBD

Issues/PRs references

This work supports my work to port RIOT to the STM32H7 family.

@github-actions github-actions bot added Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports labels Apr 2, 2024
{
assert(periph);

const int irq_state = irq_disable();
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 existing periph_clk_en() implementation (I believe) is not thread safe. So I have added critical sections to this implementation. Is my thinking correct that this is needed?

@@ -113,6 +113,12 @@ typedef enum {
#endif
} bus_t;

typedef struct periph_t
Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops :)

Suggested change
typedef struct periph_t
typedef struct

{
volatile uint32_t *en_reg;
uint32_t en_mask;
} periph_t;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

thoughts on the name of this sturct?

Copy link
Contributor

Choose a reason for hiding this comment

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

the name seems a bit generic, at least the usage in this PR seems like rcc_register_t or more specific

Comment on lines 47 to 59
static const periph_t periph_timer2 = {
#if defined(RCC_APB1ENR_TIM2EN)
.en_reg = &RCC->APB1ENR,
.en_mask = RCC_APB1ENR_TIM2EN,
#elif defined(RCC_APB1ENR1_TIM2EN)
.en_reg = &RCC->APB1ENR1,
.en_mask = RCC_APB1ENR1_TIM2EN,
#elif defined(RCC_MC_APB1ENSETR_TIM2EN)
.en_reg = &RCC->MC_APB1ENSETR,
.en_mask = RCC_MC_APB1ENSETR_TIM2EN,
#endif
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the right file to define this in?

/**
* @brief Timer configuration
*/
typedef struct {
TIM_TypeDef *dev; /**< timer device */
const periph_t *rcc_dev;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better name for this pointer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const periph_t *rcc_dev;
const rcc_register_t *rcc_register;

Comment on lines 67 to 68
uint32_t rcc_mask; /**< corresponding bit in the RCC register */
uint8_t bus; /**< APBx bus the timer is clock from */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These will go away when this work is complete.

@Teufelchen1 Teufelchen1 marked this pull request as draft April 3, 2024 14:13
{
volatile uint32_t *en_reg; /**< RCC enable reg */
uint32_t en_mask; /**< RCC enable reg mask */
} periph_base_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

While every/most periph need to be clocked via the rcc this is certainly not the base of that peripheral, but more like a "RCC configuration" of said periph. (rcc_config_t or periph_clock_config_t)

If the base of an periph would be pointed at somewhere, I would expect is to point to that periphs base adress eg: for timer 1 to TIM1_CR1 (add an offset to that base and you find the other registers)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes since. I will fix it.

@Enoch247
Copy link
Contributor Author

I now believe that this approach was flawed. I have created a PR with an alternate approach (#20609), which is better in my opinion.

@Enoch247 Enoch247 closed this Apr 22, 2024
@Enoch247 Enoch247 deleted the improve-stm32-periph-enable branch October 21, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants