MBed Printf Hardfault in Keil uV5

13 Jan 2017

Hi,

online my code works well, dragging it offline into Keil uV5, it compiles :)

but immediately it goes into hard-fault. I stepped through, it is the printf call causing the fault.

Can someone please help me get past this issue ?

15 Jan 2017

I have made a new class called nStream

declared an instance

nStream Usart1;

now writing functions fputc, fputs etc. which write to the DMA buffers on Usart1

just not sure how to redirect stdout and stdin.. working on it

the aim is to redirect printf away from the Keil-USB-tracey-no-printy-thingy to my Usart1 pins.

16 Jan 2017

Nick, did you try

#include "mbed.h"
Serial pc(PC_10, PC_11, 115200); // second serial port on Nucleo Boards (top 2 pins on CN7)
int main () {   while(1) pc.printf("Hello World");  }  // serial out on PC_10
22 Jan 2017

Well, Yes, I can print like that... within mbed online. to all 4 serial ports... but when you drag it offline into keil uV5 printf is redirected to the STDIN & STDOUT

this is what I am trying to redirect back to the serial port.

otherwise any printf goes directly to hardfault.

I have all but drifted away from mbed now due to this exact problem. Actually I cannot find any offline IDE that works with mbed. I guess you can get eclipse running, but I cant do it with the support being limited. This is probably due to the Volunteer aspect, We appreciate the support we get but I guess no one is being paid to do any support.

It hard for the beginners because we ask stupid questions. and then ignored. As you can see here, this question posted over a week ago and no support.

22 Jan 2017

Nick,

I'm not a Keil user but did you see this? Seems like you can route the printf to wherever you want.

[http://armcortexm.blogs.upv.es/stm32f4-discovery-and-printf-redirection-to-debug-viewer-in-keil/]

22 Jan 2017

:) I thought that nobody replied my post for the last few days is alr the worst but here u are.

But anyway, the routing from serial to stdin, out should be defined inside mbed-os/platform/retarget.cpp, according to my experience. Inside the file, it has __write and __read method. But i don't think after u route ur routine into stdin, out, it will work. There are some initialization routines need to be done before mbed-os can work correctly. I also have no idea about them. Like now, the mbed documentation is suck, doesn't have enough info. Thus, there s no choice that u ve to roam through the code, and understand what happens in the background.

Maybe u should do step by step.

  • like try ur serial function (no mbed-os), see if they can work correctly.
  • try to work on the most popular board to test mbed. make sure u have a working project. in my case, i use Stm, so the most supported chip should be stm32f4xx. Then use it, stepping through the code in debug mode, see how it works,
  • if u want to export to keil, plz try with mbedcli. the exported project will contain all the mbed-os source code. it is different from the online ide export feature. the online ide can only export the mbed-os.lib which is a hassel because u cannot use the "step into" debug.
22 Jan 2017

I have switched to uV5 and HAL drivers, running on an '091 now working on CAN

mbed-cli still no IDE. yes my answer, but no IDE

22 Jan 2017

it s a good choice. i also don't use mbed for my work, totally ban it. however, i try it as a side project to learn more about embedded coding.

23 Jan 2017

I may try that... to export online to mbed-cli offline, which exporter do you use ? The new HAL code I am working on runs twice as fast as mbed. but my system limits me to STM32F products.

30 Jan 2017

i use coide exporter.