Skip to main content
This topic has been closed for replies.

12 replies

Tesla DeLorean
Guru
Jul 21, 2021 4:09 PM UTC

You can always ask...

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
waclawek.jan
Super User
Jul 21, 2021 5:15 PM UTC

:D

TDK
Jul 21, 2021 9:55 PM UTC

The first one is clearly solvable.

How would you solve the second? Split the EXTICR array into 4 different fields and ditch the array? There's a few similar issues like this. Arrays are 0-indexed, no way of changing that. Registers are always 1-based per all the RM docs. Or split into low/high like the AF registers.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
Jul 22, 2021 9:04 AM UTC

> Registers are always 1-based

0693W00000D0JgOQAV.png(The latter is ridiculous in itself, as FMC/FSMC_BCRx registers are indeed later numbered from 1. FMC/FSMC is a ridiculuous issue in itself, as is UART/USART and many similar. And the CMSIS-mandated headers' state is sad in general, too).

I know, milk has been spilt long ago so we just have to learn to live with this; frustration remains nevertheless. And we see this happening again and again all over the place.

I know I am opinionated but it was not me who taught that indexing in programming should ALWAYS start with zero - and for good reasons.

Note, that pins *are* zero-indexed - even in the very SYSCFG_EXTICR1 register you'll see EXTI0 field - how could that not ring any bells to whomever "designed" this?

This is all about culture, doing things systematically, meticulously, properly.

As Clive said, I can always ask; so here I am, asking.

JW

waclawek.jan
Super User
Jul 22, 2021 9:10 AM UTC

Btw. I told to myself, but Jan, you must've come across the SYSCFG/EXTI thing in the past, how did you cope with the frustration back then?

So I looked it up:

 SYSCFG->EXTICR[SOMEINPUT_PIN / 4] =
 (SYSCFG->EXTICR[SOMEINPUT_PIN / 4] AND (~(0xF SHL (4 * (SOMEINPUT_PIN % 4))))) OR (GLUE(SYSCFG_EXTICR1_EXTI0_P, SOMEINPUT_PORT_LETTER) SHL (4 * (SOMEINPUT_PIN % 4)));

:)

JW

Harish1
Associate III
Jul 22, 2021 1:12 PM UTC

I also agree, not only of consistency, I found few bugs in the ref. manuals. They need to be updated asap.

TDK
Jul 22, 2021 1:30 PM UTC

I guess if pins are 0-index based, and those are clearly exposed to the user in a very prominent way, it's not very consistent for other stuff to be 1-based.

I'm always a fan of making things 0-based but make an effort to make things exposed to a (non-programming) user 1-based.

I would argue those DMA registers are named based off the channel numbering, and the USB is based off the stream.

Fat chance of any of this changing now, of course.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
Jul 22, 2021 2:21 PM UTC

> I would argue those DMA registers are named based off the channel numbering,

No. That's *streams* in the dual-port DMA ('F2/'F4/'F7) 0-based numbere; channels (which here mean "multiplexer input") are indeed 0-based numbered, too.

These Streams correspond to Channels in the single-port DMA (as in 'F1/'F0/'F4/'Lx) and those are 1-based numbered.

This causes real trouble in 'G0/'H7 (for BDMA) where DMAMUX feeds their 0-based Channels into the 1-based DMA Channels.

> USB is based off the stream.

You mean, endpoint? That would be a fair point for the Device registers (and as such is indeed reflected also in the Device-only USB such as in 'F103/'F0/'F3/'L0/low 'L4), but not for Host in the OTG module (where the numbering corresponds to... eee... that's a long story). The main reason for 0-based numbering here is, that the OTG does not come from ST but from Synopsys.

JW

waclawek.jan
Super User
Jul 22, 2021 2:03 PM UTC

More.

0693W00000D0ME7QAN.pngEven more.

0693W00000D0MGIQA3.png(with the added bonus of the field describing number of channels in sequence being mixed in).

JW

TDK
Jul 22, 2021 2:45 PM UTC

I'm not arguing that inconsistencies don't exist in the RM.

Should peripherals also be 0-based? ADC0/1/2 instead of ADC1/2/3? I much prefer the latter, but maybe I'm just used to it.

Just a thought exercise.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
Jul 24, 2021 9:52 PM UTC

Maybe I am exceptionally stupid, but I simply cannot comprehend some things.

In the CMSIS mandated device headers, why is the RCC_APBxENR.RTCAPBEN bit in CubeF4 called RCC_APB1ENR_RTCAPBEN (as expected and consistently to the respective RM), while in CubeF7 the same thing is called - inconsistently to manual and everything - RCC_APB1ENR_RTCEN - with the added bonus of confusion with RTCEN bit in RCC_BDCR.

Would that be a question, I would end it with a question mark.

JW