cancel
Showing results for 
Search instead for 
Did you mean: 

sw4stm32 basic function and printf not working

g. lewis
Associate II
Posted on February 09, 2017 at 12:12

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-eclipse
25 REPLIES 25
Posted on February 09, 2017 at 17:24

Yes Sirma, I used Stm32CubeMx to generate the code and the code works (led is blinking) if I only place the  following statement in the  main{} > while loop:

While(1){

      for(int i=0;i<14200000;i++);

      HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);

}

Posted on February 09, 2017 at 17:30

Hello,

Instead of writting HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);

could you try HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); ?

Kind regards

Sirma

Posted on February 09, 2017 at 18:42

For the printf problem, you have to add some shim code.

Read this: 

http://embedded.fm/blog/2016/12/13/discovery-uarts-part-3-the-final-step

 

Andrei.

Posted on February 09, 2017 at 18:54

Ok, Upgraded to 1.13.1 then changed the Linker flags to-> -specs=nosys.specs -specs=nano.specs -specs=rdimon.specs -lc -lrdimon

Still no 'hello world' on the console after running the program.

Instead I got these log messages:

** Programming Finished **

** Verify Started **

stm32f4x.cpu: target state: halted

target halted due to breakpoint, current mode: Thread

xPSR: 0x61000000 pc: 0x2000002e msp: 0x20020000

verified 8220 bytes in 0.784075s (10.238 KiB/s)

** Verified OK **

** Resetting Target **

Info : Unable to match requested speed 2000 kHz, using 1800 kHz

Info : Unable to match requested speed 2000 kHz, using 1800 kHz

adapter speed: 1800 kHz

shutdown command invoked
Posted on February 09, 2017 at 19:34

Ok. I check that and I'll get back to you soon.

Thanks you all

Posted on February 09, 2017 at 19:35

Yes It's the same...

Posted on February 10, 2017 at 11:28

Hello

lievre.gilles

,

> changed the Linker flags to-> -specs=nosys.specs -specs=nano.specs -specs=rdimon.specs -lc -lrdimon

Is only the first step of the procedure.

Please confirm you have followed the full tutorial.

Olivier

Olivier GALLIEN
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
Posted on February 12, 2017 at 17:56

Ok It finally works even though there is no syscalls.c file in my project.

Posted on February 12, 2017 at 21:31

Nice blog! I read all of it.Great Info. Do you mean it'll works for the SW4STM32 IDE as well since it uses also GCC compiler? Have you ever tried this IDE?

Thanks

Posted on February 13, 2017 at 00:12

excellent background music to work to: 

https://www.youtube.com/watch?v=8qrhRtjFlpo

 

(moby seems a little slow)