vv

  • *
  • 20
Debugging CC3D board using SWD and an STlink-v2 programmer
« 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!

lee

  • *
  • 42
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #1 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!

vv

  • *
  • 20
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #2 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.

hwh

  • *
  • 1018
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #3 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.

vv

  • *
  • 20
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #4 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.

 

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #5 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.




vv

  • *
  • 20
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #6 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..




f5soh

  • *****
  • 4572
    • LibrePilot
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #7 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 ?

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #8 on: April 17, 2016, 10:17:49 pm »
You got it ?


vv

  • *
  • 20
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #9 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.

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #10 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 */

vv

  • *
  • 20
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #11 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!

vv

  • *
  • 20
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #12 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.

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #13 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 ?
« Last Edit: April 20, 2016, 06:53:57 pm by f5soh »

vv

  • *
  • 20
Re: Debugging CC3D board using SWD and an STlink-v2 programmer
« Reply #14 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.