It seems that your C compiler does not support C99 out-of-the box.
So try to turn on C99. As for GCC, you have to add -std=c99
to the command line arguments. As for Keil try --c99
. As an alternative, in Keil uVision, you can turn this on by clicking the "C99 Mode" checkbox in the "C/C++" tab in the project options (this has been pointed out by zapeitor in a comment).
Otherwise rewrite the code: In your case the declaration of the variable within the for
statement is not valid. You have to move it up; it must appear right after the function's declaration:
void f() {
int i;
[...]
for (i = 0; i < 5; i++) {
}
}
instead of
void f() {
[...]
for (int i = 0; i < 5; i++) {
}
}
The latter is only possible with C99.
Definitely the CMSIS. It is not exactly a library, it mostly contains definitions for the various registers.
It is exactly what one needs to access the microcontroller's registers easy, so as to implement his/her own HAL. It has no overhead, since you just access the registers.
Keep in mind that CMSIS, unlike the other two, is defined by ARM and not ST. This means that the various CMSIS libraries out there for the various microcontrollers are quite similar, which greatly aids in portability.
Furthermore, CMSIS is the simpler one so it is (IMO) the most versatile, and most reliable, with possibly fewer (or no) bugs. Some hal libraries for the various mcu's that I've used are quite infamous for their bugs.
On the other hand, CMSIS needs quite more work from you. It is however my personal choice, since I prefer to invest my time creating quality libraries, that suit my needs, and understanding how the chip works, than just spending time to learn another, new library.
Best Answer
Yes, it's quite possible and it has saved my life for a project I was working on where I had everything built around HAL.
Believe it or not, I kept resisting the transition to that HAL thing for so long, until I found myself forced to use it for my project due to many advantages it provides on certain aspect.
However, part of my project is to control a slave device over SPI and I had the library for the SPL from ST. After spending a tremendous time trying to solve an issue I had with the receive part of the SPI over HAL, and after giving up trying hundreds of examples and code snippets for the SPI, I have finally managed to figure it out by mixing the SPI driver from the SPL with the rest of my project, which was built with HAL.
Here's what I did in Keil uVision to get it to work for me without any problem. I have created pre-compiled objects for the SPI and any dependencies used by SPI and had those imported/linked into my HAL project. Of course, I have removed everything about HAL_SPI in the project and now the project compiles and runs quickly and smoothly. I can now drive my device with the SPL based SPI functions, and still enjoy what HAL has to offer for the remaining modules of the project.