2011-03-14 07:59 AM
STM32 StdPeriph_Lib 3.4
#!winning-makework2011-05-17 05:27 AM
Maybe because some parts of an init structure can be set at runtime only (for instance, timer dividers depending on the system clock, etc...). In such cases the init structure to allocate in RAM like local variables.
2011-05-17 05:27 AM
Many of us are quite happy building these structures on the stack, and thus not consuming any RAM permanently. And as mentioned, some things might actually be configurable and setting them in stone is a sure fire way to prevent any flexibility.
Want to define you're structures as const, then go ahead and do that and cast the input parameters to the library. Don't like the library, then modify it, they provide the source. Actually want to save code/data space for configuring GPIO's, then build a compact table description and iterate through it.2011-05-17 05:27 AM
Yes but this is just a hack!
clive, please readhttp://www.parashift.com/c++-faq-lite/const-correctness.html
Conclusion2011-05-17 05:27 AM
Yet the article you cite is highly C++ centric. Where the compiler might realistically modify, or add runtime code, that is not immediately apparent.
I'm not convinced this exercise will materially improve the code/data utilization. Perhaps you can go through the code and demonstrate this. I know it will contractually guarantee that the compiler won't write to such structures, but I'm not convinced the library does so now. Using RAM utilization as an argument in favour of doing the conversion, is incredibly weak. If one-time initialization code is permanently consuming RAM resources on an embedded system, the library user has far more problems with coding than the ''const correctness'' of the underlying library. ST's example code defines a lot of unnecessary global RAM based structures, and it's been pointed out by Andrew, and others, that these examples could be made significantly better. They are in the end though throw away examples, but as Microsoft has discovered, people tend to be rather lazy and a lot of example code gets cut-n-pasted blindly without much thought to the context. Even if one doesn't cast structures to the library, this would not legally preclude you from building large compact static/const table structures in ROM/FLASH and enumerating/decoding those into local stack based structures passed down to the library. Such efforts would materially improve the code/data utilization. And I'll reiterate that you have the source, we can clean or bug fix it as required. If your process requires you to run Lint against it, and sanitize it for const correctness, do that and share the results.2011-05-17 05:27 AM
Can anyone explain why this topic is in ''wide screen''? All the other threads wrap neatly on my screen. This one is about twice as wide as the display!
Oh! ... and I just create the INIT structures on the stack, use them and lose them. Works fine for me!2011-05-17 05:27 AM
''Can anyone explain why this topic is in 'wide screen'?''
No - the whole ST Forum is a complete mystery! However, the opening post is in an unusual font - looks like the OP somehow managed to find a ''preformatted'' mode...''I just create the INIT structures on the stack, use them and lose them. Works fine for me!'' I think the OP muddled the issue between the input parameter in the API call being const, and the structure that you pass to it being const. Having the API input parameters declared as const makes sense; Having the structure in Flash does not make universal sense.2011-05-17 05:27 AM
Can anyone explain why this topic is in ''wide screen''?
The OP applied some formatting in this godawful Word(tm)esc text editing dialog, and that effects all subsequent posts. He could edit it, but then it would probably re-order the posts too. I was looking for a ''remove all formatting'' button, but couldn't find one. As Andrew observed, the OP believes all his init data is statically allocated in RAM, this is a level of ''doing things wrong'' that will not be fixed by a library change, or rules enforcement by the compiler. And my observation that if RAM footprint is a problem, there are better ways to solve that. I certainly wouldn't advocate filling vast tracts of FLASH with repetitive constant data either, since most of it is used once and discarded, and is ripe for folding in any event. I'm all for the compiler being able to do this, and libraries that enable it, but it is so often used as a crutch. Developing solid code has a lot more to do with understanding the problem and the system limits/interactions, than erecting fences for the unwary. Perhaps someone can sanitize the library, and provide a patch file, so the poor guys that have to maintain it can merge in the ''idealized'' solution.2011-05-17 05:27 AM
Ok, I think we ran into a deadlock. Everyone has a different opinion.
Lets forget the s**t of placing one-time used init data into static memory areas. But as andrew already stated, API input parameters make sense. They really make sense, because the user is able to pass a constant and a mutable instance to the library without casting! clive, do you agree, or not?