2017-02-09 03:12 AM
Hi, I'm beginner and I started by a blink project using SW4STM32 along with STMCubeMx libraries set up for my board which is the STM411RE board.
It works well using the following lines in the main while loop:
HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);
for(int i=0;i<14200000;i++);but It doen't work when I tried to replace the for statment: for(int i=0;i<14200000;i++); by a function declared above the main{}
like:
void tempo(void){
for(int i=0;i<14200000;i++);}This is really simple but I'm stuck here.
I got another problem with the printf statemenent that doesn't do anything. Don't know if this is correlated to it but it seems that there is something wrong on the configuration of Eclipse or missing I guess.
ps: I have include stdio.h on top of the program.
Thanks for your help
#sw4stm32-eclipse2017-02-09 03:48 AM
Can you perhaps post your entire code that doesn't work?
Not sure about your printf problem as I am using a different dev environment. FWIW for printf to work there one has to make sure the correct library is linked, otherwise the underlying functions are just stubs and any calls to printf will result in a big fat nothing. Either that or the redirection of the printf output is wrong.
2017-02-09 04:04 AM
I guess the 'for loop' is being compiled out... since it doesn't do anything.
put the 'int i' declaration before the 'for loop'.
and use 'i' after the 'for loop'
maybe you can use
sprintf(string,' i %d\n\r',i);
puts(string);
thats how I got around the printf hardfault issue.
I point my 'puts' to the Usart port...
but I am not an expert, just trying to help...
2017-02-09 06:26 AM
For compiled out of your 'for loop' you can try to remove optimization.
For printf you need to either redirect it to an UART or, what I suggest as a first step, use the semihosting feature which will direct your printf to SW4STM32 Console window
For semihosting a tutorial is available in latest version in
Help >> Help Contents >> SystemWorkbench for STM32 User Guide >> Advanced >> Semihosting
Hope it help
Olivier
2017-02-09 07:23 AM
Hello Kim,
Your code is working on my F769 Discovery board....
The tempo is about 8s.
Are you sure about your GPIO config ?
To drive a led, it should be something like pushpull, with a pull up and high t level.
Kind regards
Sirma
2017-02-09 07:28 AM
Hello Kim,
Instead of writting HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);
could you try HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); ?
This blink LED2 on my NUCLEO-F411RE board.
Kind regards
Sirma
2017-02-09 07:51 AM
2017-02-09 08:17 AM
Hello
Instead of using a loop, you can use HAL_Delay(time in ms);
i.e.: HAL_Delay(100), wait for 100ms
Kind regards
Sirma
2017-02-09 09:18 AM
Thanks Olivier,
It seems that I don't have the same kind of help contents.
For me it runs like this:
Help >> Help Contents >>Workbench User Guide >> no Advanced ??
This could be the clue of my problem since in the help nothing refer to stm32 !
Eclipse version:
2017-02-09 09:22 AM
The version which is required here is the one for STM32 plugin ( blue butterfly )
This specific help have come along 1.12.1 version.
If you upgrade on latest 1.13.1 for sure you will get it
Olivier