LibrePilot Forum

Development => Firmware General => Topic started by: vv on April 17, 2016, 10:51:20 am

Title: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 17, 2016, 10:51:20 am
Hi, I am new to this project and would like to start developing and hopefully contributing some useful code to the project. I am trying to setup the environment in Ubuntu linux for programming and debugging using the outdated guide attached. Here are a few problems and questions I can't solve myself.

There is a link in the pdf guide for a patched st-utils that links to a non-existing page. Do I still need the patched version or has it been fixed in the upcoming releases?

Do I really need to compile OpenOCD with 'configure --enable-usb --enable-stlink', is this still (Version 0.9.0) not by default? I was working on another project using STM32F103 and I just downloaded OpenOCD using apt-get and all worked fine out of the box.

Can I find any updated instructions anywhere?

How do I program the board using the programmer without using gui tools such as GCS?

How do you guys do it? Whats your secret/advice on successful programming and debugging?

Thanks in advance!
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: lee on April 17, 2016, 11:29:37 am
I think Eclipse+OpenOCD+gdb+stlink is a good choice, but I have no time to do it. Good Luck!
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 17, 2016, 03:22:09 pm
I prefer Qt Creator as IDE but if I manage to get things running in Eclipse I will try to port the settings to Qt. Sadly, your post doesn't answer much. If anyone has experience debugging with Qt, you are very welcome.
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: hwh on April 17, 2016, 05:35:30 pm
...Can I find any updated instructions anywhere?...
Unlikely, once the gui and bootloaders were working there was no reason to flash from the command line.

...How do I program the board using the programmer without using gui tools such as GCS?...
A better question is why would you want to?  I tried a stlink v2 under both openocd and texane stlink but that was just to see if it worked, I'd never do that normally in a project that had a gui and bootloader.

...How do you guys do it? Whats your secret/advice on successful programming and debugging?...
There's no secret, as you were told in the other thread use the gui.  It's always running to monitor what the board is doing and configure it anyway.
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 17, 2016, 06:47:22 pm
Quote
A better question is why would you want to?  I tried a stlink v2 under both openocd and texane stlink but that was just to see if it worked, I'd never do that normally in a project that had a gui and bootloader.

First of, using the programmer I can have absolute control over hardware. The problem with using a GUI is mainly speed. I can't setup my environment to press F5 and the program is compiled and uploaded. It is just annoying and a waste of time for me using a mouse, clicking and waiting around. I hope I am not too terrible..

This leads me to another question or too:
How does the debug console work? I have it set up to baudrate 57600 an main port or flexi, doesn't matter, but I get no output. I get output from telemetry, but not the debug console? How do I print to debug, Just a regular printf()?

What kind of protocol does telemetry use, I assume OPlink? Do you guys know about any good parser/debugger for the telemetry protocol, preferably with a GUI this time :) Thanks.

 
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 17, 2016, 07:44:19 pm
How does the debug console work? I have it set up to baudrate 57600 an main port or flexi, doesn't matter, but I get no output. I get output from telemetry, but not the debug console? How do I print to debug, Just a regular printf()?

https://forum.librepilot.org/index.php?topic=1353.msg9858#msg9858

Did you enable debug console ?
./flight/targets/boards/coptercontrol/firmware/inc/pios_config.h

Code: [Select]
#define PIOS_INCLUDE_DEBUG_CONSOLE
#define DEBUG_LEVEL 2

And add printf somewhere ?

Code: [Select]
DEBUG_PRINTF(2, "Hello vv, current axis is: %d\n\r", t);
Next VCP, main or FlexiPort can be used.

(https://forum.librepilot.org/index.php?action=dlattach;topic=1380.0;attach=2536)

Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 17, 2016, 09:52:28 pm
Thanks for the instructions, but I still can't get it to transmit any debug data over serial port. Here is exactly what I did:

 - in file ibrepilot/flight/targets/boards/gpsplatinum/pios_board.h I uncommented the following lines like this
Code: [Select]
#define PIOS_INCLUDE_DEBUG_CONSOLE
 #define DEBUG_LEVEL 2
// #define PIOS_ENABLE_DEBUG_PINS

 - I added the following code to the flight/modules/Stabilization/innerloop.c in the GyroStateUpdatedCb() function:
Code: [Select]
static void GyroStateUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
{
    GyroStateData gyroState;
    GyroStateGet(&gyroState);

    printf("TEST printf");
    DEBUG_PRINTF(2, "Testing!!!\n");

 - Deleted the whole build folder (just in case)
 - Compiled using
Code: [Select]
make fw_coptercontrol - Uploaded with your fancy GUI :)
 - Tried to set 'DebugConsole' on all ports, disabling everything else except 'USBTelemetry' on USB HID port'
 - Tested the serial by setting the telemetry on the flexi/main port and I had data flying around like crazy, matrix style :)
 - Tried every combination I could think of, just like installing a printer on Windows 95 :)

Can someone please confirm the following steps on the CC3D are correct or not, please? I am runnign out of ideas here..



Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 17, 2016, 10:00:38 pm
/flight/targets/boards/gpsplatinum/pios_board.h

and

CC3D looks a wrong match  :'(

Do you want to debug the CC3D or GPSv9 ?
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 17, 2016, 10:17:49 pm
You got it ?

(https://forum.librepilot.org/index.php?action=dlattach;topic=1380.0;attach=2538)
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 17, 2016, 10:36:31 pm
Sorry about the gpsplatinum, wrong copy/paste, I use CC3D. There even aren't the #defines I would be looking for. Here is the screenshot, just to make sure.. So still no luck. Thanks for the effort guys, I guess I'll just have to keep trying.
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 17, 2016, 10:44:42 pm
You did something wrong for sure, in screenshot above you can see it works perfectly running a CC3D.

Code: [Select]
------------------- flight/modules/Stabilization/innerloop.c -------------------
index 629e87c..eb8cf6a 100644
@@ -382,6 +382,8 @@ static void GyroStateUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
 
     GyroStateGet(&gyroState);
 
+    DEBUG_PRINTF(2, "Testing!!!\n");
+
     gyro_filtered[0] = gyro_filtered[0] * stabSettings.gyro_alpha + gyroState.x * (1 - stabSettings.gyro_alpha);
     gyro_filtered[1] = gyro_filtered[1] * stabSettings.gyro_alpha + gyroState.y * (1 - stabSettings.gyro_alpha);
     gyro_filtered[2] = gyro_filtered[2] * stabSettings.gyro_alpha + gyroState.z * (1 - stabSettings.gyro_alpha);

-------- flight/targets/boards/coptercontrol/firmware/inc/pios_config.h --------
index b207bd0..69e3943 100644
@@ -37,8 +37,8 @@
  * details.
  */
 
-/* #define PIOS_INCLUDE_DEBUG_CONSOLE */
-/* #define DEBUG_LEVEL 0 */
+#define PIOS_INCLUDE_DEBUG_CONSOLE
+#define DEBUG_LEVEL 2
 /* #define PIOS_ENABLE_DEBUG_PINS */
 
 /* PIOS FreeRTOS support */
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 17, 2016, 11:42:20 pm
Solved!!! I had a version mismatch. After compiling running the current GCS it works like a charm!
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 20, 2016, 06:04:47 pm
The title says it all.

Can someone please confirm and/or try to find the source of this. I am pretty new the code and the structure and I already tried to debug the problem for 2 days with no success. Can confirm that DEBUG_PRINTF() works fine from within the manualcontrol.c for example.
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 20, 2016, 06:50:44 pm
Should work exactly the same as the example i posted with innerloop.c above.

Edit: What do you want to debug inside manualcontrol.c ?
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 20, 2016, 07:07:57 pm
Since my other post was merged here, even thought it has little to do with the tilte (not debugging with SWD), I am writing the new problem's title here:

CC3D freezes when function DEBUG_PRINTF() is called in receiver.h in the main while() loop. Everywhere else works fine till now. See two posts up for more.

@f5soh I know it should, but it doesn't. I wouldn't be wasting your time if I hadn't tried to solve the problem myself for 2 days.

I am trying to find the source of the lag between PWM/PPM input and manual channel out.  "Stabilization out" is fine, no lag there, but channels have lag (0.1-0.4 secs, eye measurment) for some reason. So when I move a stick it takes time for the servo to move. I know the processor is more then powerful enough to crunch all the data so there must be a problem with priorities/update rates or something along the way.

So I am currently trying to debug the time in takes for data to come from capture of receiver.c to manualcontrol.c etc... Thats why I need DEBUG_PRINTF() to work in receiver.c.

If you have any suggestions an how to debug the timings you are very welcome.
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 20, 2016, 07:21:29 pm
Sorry, but where you see the 0.4s lag "eye measurement" ?

Edit: Post the diff from debug changes you did in receiver.c
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 20, 2016, 07:25:39 pm
I explained everything in the last post. Are you gonna help or not?
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 20, 2016, 07:35:03 pm
Shit, i edit your post.

Calm down, please. That YOU with your issue, and I try to understand.

So,
How do you setup the servo output and the "link" between the input stick and output (servo)
Please post a config file. File > Export UAV settings.
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 20, 2016, 07:44:11 pm
Here is my settings. I often sound mad when texting,  sorry about that, I get that a lot :)
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 20, 2016, 09:03:34 pm
Ok, loaded your settings and just calibrated.
Taranis + old D4FR PPM receiver.

What do you think ?
https://www.youtube.com/watch?v=TLkGW3ihhts
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: f5soh on April 20, 2016, 09:10:27 pm
And this one using PWMSync 500Hz
https://www.youtube.com/watch?v=qo2w_ZWkoNk
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: Brian on April 20, 2016, 10:06:30 pm
If you're seeing a crash when adding debug print statements it's almost always (in my experience) a shortage of stack space.  Try increasing the stack space for the task that you're trying to debug.
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 20, 2016, 10:13:12 pm
I just did a comparison with two servos, one from receiver and the other via CC3D at the same time. It looks good all of a sudden, little to no difference.. Idk, ether I am going crazy or I was using an old firmware before or something. I just got the thing so I am not sure what I was doing before my first flights, but I know that it was really annoying to fly, especially in the wind. I wouldn't have gone through all that trouble if I wasn't sure something was wrong. I will try the thing on the plane again tomorrow and see how it feels.

Thanks for your trouble and effort and everything! I'll report back tomorrow. Also, let me know if you need some help with development, I wouldn't mind.

I need a vacation...
Title: Re: Debugging CC3D board using SWD and an STlink-v2 programmer
Post by: vv on April 20, 2016, 10:16:55 pm
@Brian That makes a lot of sense, thanks, I'll try it when I run into new "problems", it seems for second now that all is looking and I don't even have to debug that anymore, but we'll see tomorrow. Need to rest now...