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

cpu/stm32: stm32f4 BRR from BSRR #19670

Merged
merged 1 commit into from
May 30, 2023
Merged

cpu/stm32: stm32f4 BRR from BSRR #19670

merged 1 commit into from
May 30, 2023

Conversation

kfessel
Copy link
Contributor

@kfessel kfessel commented May 25, 2023

Contribution description

sometimes one wants to save one instruction :)
just write the bits we need to write.

Testing procedure

tests/periph/gpio_ll tests this

Issues/PRs references

@maribu might know some reference

maybe #19407

@kfessel kfessel requested a review from maribu May 25, 2023 21:13
@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms labels May 25, 2023
Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

That should indeed save an instruction. Previously the compiler would take the GPIO port base address

  1. add the offset of the BSRR register
  2. do a left shift
  3. do a 32 bit store

Now it would take the GPIO port base address

  1. add the offest of the BSRR register + 2
  2. do a 16 bit store

Please fix the style nitpicks and squash directly

@kfessel kfessel added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 26, 2023
@riot-ci
Copy link

riot-ci commented May 26, 2023

Murdock results

✔️ PASSED

f8a64df cpu/stm32: stm32f4 BRR from BSRR

Success Failures Total Runtime
6933 0 6933 20m:11s

Artifacts

@benpicco
Copy link
Contributor

bors merge

bors bot added a commit that referenced this pull request May 27, 2023
19268: shell_lock: don't set CONFIG_SHELL_SHUTDOWN_ON_EXIT r=benpicco a=benpicco



19629: cpu/stm32/periph/adc: fix setting ADC clock r=benpicco a=Enoch247

### Contribution description

The current implementation uses the core clock frequency to calculate the needed prescalar to achieve a given ADC clock frequency. This is incorrect. This patch fixes the calculation to use the correct source clock (PCKLK2 ie APB2). It also changes the defined max clock rate to use the frequency macro to improve readability.

I based on code similarity. I believe the gd32v CPU may need this same fix, but I am not familiar with that MCU.

### Testing procedure

I tested this on a nucleo-f767zi. The the MCU's reference manual is in agreement with what I have implemented here. I spot checked references manuals for a random [STM32F1](https://www.st.com/resource/en/reference_manual/cd00171190-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf) and [STM32F2](https://www.st.com/resource/en/reference_manual/rm0033-stm32f205xx-stm32f207xx-stm32f215xx-and-stm32f217xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf), and they are clocked similar to the F7 I have.

### Issues/PRs references

None known.


19670: cpu/stm32: stm32f4 BRR from BSRR r=benpicco a=kfessel

### Contribution description

sometimes one wants to save one instruction :) 
just write the bits we need to write.

### Testing procedure

tests/periph/gpio_ll tests this 

### Issues/PRs references

`@maribu` might know some reference

maybe #19407

Co-authored-by: Benjamin Valentin <[email protected]>
Co-authored-by: Benjamin Valentin <[email protected]>
Co-authored-by: Joshua DeWeese <[email protected]>
Co-authored-by: Karl Fessel <[email protected]>
@bors
Copy link
Contributor

bors bot commented May 27, 2023

Build failed (retrying...):

bors bot added a commit that referenced this pull request May 28, 2023
19629: cpu/stm32/periph/adc: fix setting ADC clock r=benpicco a=Enoch247

### Contribution description

The current implementation uses the core clock frequency to calculate the needed prescalar to achieve a given ADC clock frequency. This is incorrect. This patch fixes the calculation to use the correct source clock (PCKLK2 ie APB2). It also changes the defined max clock rate to use the frequency macro to improve readability.

I based on code similarity. I believe the gd32v CPU may need this same fix, but I am not familiar with that MCU.

### Testing procedure

I tested this on a nucleo-f767zi. The the MCU's reference manual is in agreement with what I have implemented here. I spot checked references manuals for a random [STM32F1](https://www.st.com/resource/en/reference_manual/cd00171190-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf) and [STM32F2](https://www.st.com/resource/en/reference_manual/rm0033-stm32f205xx-stm32f207xx-stm32f215xx-and-stm32f217xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf), and they are clocked similar to the F7 I have.

### Issues/PRs references

None known.


19670: cpu/stm32: stm32f4 BRR from BSRR r=benpicco a=kfessel

### Contribution description

sometimes one wants to save one instruction :) 
just write the bits we need to write.

### Testing procedure

tests/periph/gpio_ll tests this 

### Issues/PRs references

`@maribu` might know some reference

maybe #19407

Co-authored-by: Joshua DeWeese <[email protected]>
Co-authored-by: Karl Fessel <[email protected]>
@@ -77,7 +77,8 @@ static inline void gpio_ll_clear(gpio_port_t port, uword_t mask)
#if defined(GPIO_BRR_BR0) && !defined(CPU_FAM_STM32F4)
p->BRR = mask;
#else
p->BSRR = mask << 16;
uint16_t *brr = (void *)&(p->BSRR);
Copy link
Member

@maribu maribu May 28, 2023

Choose a reason for hiding this comment

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

Suggested change
uint16_t *brr = (void *)&(p->BSRR);
volatile uint16_t *brr = (volatile uint16_t *)&(p->BSRR);

The volatile is needed here and C++ is being annoying again here.

Copy link
Member

Choose a reason for hiding this comment

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

I was so free to add this. Should be good to go now.

@bors
Copy link
Contributor

bors bot commented May 28, 2023

Build failed (retrying...):

@maribu
Copy link
Member

maribu commented May 28, 2023

bors cancel

@bors
Copy link
Contributor

bors bot commented May 28, 2023

Canceled.

@maribu
Copy link
Member

maribu commented May 30, 2023

bors merge

bors bot added a commit that referenced this pull request May 30, 2023
19610: drivers/periph/rtc: improve doc on rtc_set_alarm r=maribu a=maribu

### Contribution description

- point out behavior on denormalized time stamps
- use errno codes to indicate errors (and adapt the few instances of actual error handling to use them)


19670: cpu/stm32: stm32f4 BRR from BSRR r=maribu a=kfessel

### Contribution description

sometimes one wants to save one instruction :) 
just write the bits we need to write.

### Testing procedure

tests/periph/gpio_ll tests this 

### Issues/PRs references

`@maribu` might know some reference

maybe #19407

19678: gnrc_sixlowpan_iphc: fix NULL pointer dereference r=maribu a=miri64



19679: gnrc_sixlowpan_frag_sfr: fix ARQ scheduler race-condition r=maribu a=miri64



19680: gnrc_sixlowpan_frag_rb: fix OOB write in _rbuf_add r=maribu a=miri64



19681: sys/xtimer: improve documentation r=maribu a=maribu

### Contribution description

- Add a warning that xtimer is deprecated, so that new code hopefully starts using ztimer
- Add a hint that `ztimer_xtimer_compat` can be used even after `xtimer` is gone


Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Karl Fessel <[email protected]>
Co-authored-by: Martine Lenders <[email protected]>
@bors
Copy link
Contributor

bors bot commented May 30, 2023

This PR was included in a batch that was canceled, it will be automatically retried

@bors bors bot merged commit 00b5bc1 into RIOT-OS:master May 30, 2023
@bors
Copy link
Contributor

bors bot commented May 30, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@benpicco benpicco added this to the Release 2023.07 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants