| Products > Programming |
| CMSIS-SVD and C ambiguities |
| (1/3) > >> |
| techman-001:
I initially had a lot of trouble referring to Internet C code examples for STM32xx, (when that MCU series was new to me) as I found them ambiguous and lacking in information, here is one example. A C code example recently posted on this forum by a very knowledgeable poster showed how to set the timer #3 "counter enable" bit as " TIM3->CR |= TIM_CR_EN" However according to CMSIS-SVD, there is no "CR" Register in Timer 3, there are only registers CR1 and CR2, There is also no "EN" bit, there is only the "CEN" bit. My CMSIS-SVD auto-generated Forth Word to set the timer #3 "counter enable" bit is "TIM3_CR1_CEN". For instance when consulting the STM databook and searching for "EN", there is only "CEN" ? or "CR", there is only "CR1" is this not confusing for a C programmer, or is the STM databook not widely used ? Or am I missing something obvious here (not unusual for me), such as "we are told all the ambiguous names when using Atollic Studio" ? Note: I like C as it was my first decent HLL embedded programming language as a electronics technician. |
| oPossum:
CMSIS is too low level to allow code portability. Code for one part won't necessarily work on another. This is true even for parts within the same family from the same manufacturer. |
| ataradov:
Yes, you need to make sure that the code was for exactly the same part. Or just make necessary changes to the code. |
| techman-001:
--- Quote from: oPossum on May 29, 2019, 07:34:54 pm ---CMSIS is too low level to allow code portability. Code for one part won't necessarily work on another. This is true even for parts within the same family from the same manufacturer. --- End quote --- Thanks for your reply. It's possible I wasn't specific enough, after all this is a complex area. I have 44 files of different STM32xxxx MCU SVD's and I've just run a grep -i -w "tim._cr" on them all and I get zero hits. However grep -i -w "tim._cr." gives 321 hits which shows that there is no TIMx_CR bit in these MCUS. All hits are CR1,CR2,CR3 ... etc. I also get zero hits on "TIM._EN", but many on "TIM._CEN" In other words if you search the STM32xxxx documents across all their parts, you won't find a TIMx_CR bit, so it appears the example code of " TIM3->CR |= TIM_CR_EN" was in error at least in terms of CMSIS-SVD compliance. The correct C language CMSIS-SVD syntax is most likely: "TIM3->CR1 |= TIM_CR1_CEN" This test tends to indicate that CMSIS-SVD syntax is consistent across all STM32xx MCU's providing the nomenclature of "peripheral_register_bitfield" is applied. That's unless anyone has an example to the contrary ? |
| ataradov:
SVD files have versions. It is possible that naming has changed over the years. It is really hard to tell. Atmel definitely changed naming of things over time, primarily due to strange conflicts in naming with some libraries/built in defines. Right now it seems like TIM_CRx_CEN is the correct naming. But that also does not mean that the code is wrong, unless it was just typed from memory as an example. |
| Navigation |
| Message Index |
| Next page |