Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 8 Replies) Using Cosa (replaced arduino cores) - Debugger fails (Read 26071 times)
jaco
Newbies
*
Offline


Posts: 3
Joined: Jan 15th, 2015
Using Cosa (replaced arduino cores) - Debugger fails
Jan 15th, 2015 at 11:51am
Print Post  
Hi,

I would like to use the Arduino Cosa library together with Visual Micro on Atmel Studio but i cannot get them to play nice with the debugger. 

Compiling as a release is working but debug fails with errors like 
Code
Select All
VM_DBG.h:141:2: error: 'HardwareSerial' does not name a type
:HardwareSerial *transport;

VM_DBG.h:206:33: error: 'byte' has not been declared
:static void vmsetvar(char *rs, byte format, char *v );

VM_DBG.cpp:374:33: error: 'uint8_t' was not declared in this scope
VM_DBG.cpp:375:1: error: expected ',' or ';' before '{' token
:{
:^
Error compiling
 



Cosa integrates with the Arduino Ide as a new board target to support namespaces. I'm not sure if combining Visual Micro debugging & the Cosa library is even possible, i only have basic knowledge of C++, toolchains etc. etc.

Does anyone have any ideas if this is possible and how?

Thanks!

Cosa library: https://github.com/mikaelpatel/Cosa
Atmel Studio 6 (Version: 6.2.1502 - Service Pack 1)
I'm using the latest Visual Micro beta: 1412.10 Sp4


« Last Edit: Jan 16th, 2015 at 5:32pm by Tim@Visual Micro »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using the Cosa library with Visual Micro & Atmel Studio - Debugger fails
Reply #1 - Jan 15th, 2015 at 12:11pm
Print Post  
Hi,

Cosa is not a library but an entire core replacement for all boards.

The main issue is that your custom core does not contain a HardwareSerial or ano class which would normally be available for the selected processor.

The Visual Micro debugger needs to know the type of the serial object (HardwareSerial or USB etc).

If you try to use Serial in your code does it work without debug?

Thanks
« Last Edit: Jan 15th, 2015 at 12:54pm by Tim@Visual Micro »  
Back to top
IP Logged
 
jaco
Newbies
*
Offline


Posts: 3
Joined: Jan 15th, 2015
Re: Using the Cosa library with Visual Micro & Atmel Studio - Debugger fails
Reply #2 - Jan 16th, 2015 at 5:14pm
Print Post  
It seems that all functions in the Arduino library are not accessible when compiling for the Cosa BoardXX target. The Cosa author says that using Cosa with the original Arduino library should be possible but i cannot get it to work.

I've taken a look at the debugger code and if i understand it correctly the debugger tries to access the HardwareSerial class which does not exists in the Cosa library. Could you point me in the direction where i can configure the debugger type? i couldn't find it in the project properties in Atmel Studio.

I've also tried to include the Arduino library classes to Cosa but there are to many code conflicts between them. 

I don't know on which code/classes the debugger depends on but is it feasible to write a (Hardware)Serial wrapper class around the Cosa Uart class? I can give it a try but my knowledge of C++ is definitely not up to par for this stuff.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #3 - Jan 16th, 2015 at 5:30pm
Print Post  
Hi,

Thanks for the info. Actually visual micro does switch to use alternative classes for some processors such as UART. However this functionality is currently hard coded.

It wouldn't be difficult to change to make this more flexible.

Can you confirm if the UART class for your board provides both Serial.write() and Serial.print() functions. .print() should send ascii .write() should send the binary.

If the UART class supports the correct version of .print() I can tell you how to hack some Visual Micro files to test it and try to make it work.

Thanks

I know the author calls the board core a library but that is actually quite confusing because arduino libraries are something different. The author has actually re-written the arduino core so it is no longer arduino. He appears to have done a good and big job but it would help if we could call his variations "replacement cores".
« Last Edit: Jan 16th, 2015 at 5:33pm by Tim@Visual Micro »  
Back to top
IP Logged
 
jaco
Newbies
*
Offline


Posts: 3
Joined: Jan 15th, 2015
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #4 - Jan 18th, 2015 at 5:26pm
Print Post  
The Uart class has these methods:

Code (C++)
Select All
int UART::putchar(char c)
int IOStream::Device::puts(const char *s)
int IOStream::Device::write(const void *buf,size_t size)
 



These methods look largely the same as the Arduino counterparts. Next step will be to change the VisualMicroDebug class i think? I can try but i'm still learning to grasp pointers, so this could take a while..
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #5 - Jan 18th, 2015 at 5:53pm
Print Post  
Okay interesting. 

It will need to have the ascii print() and println() overloads for the various data types

print(int)
print(char)
print(long)

etc.
« Last Edit: Jan 18th, 2015 at 5:54pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Cosa
Newbies
*
Offline


Posts: 6
Joined: Jan 21st, 2015
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #6 - Jan 21st, 2015 at 8:52am
Print Post  
Hi I might be able to help you get this working. 

The Cosa IO classes is somewhat more abstracted than Arduino. The IOStream class knows about transforming data to text and the IOStream Device class implementations about transporting data. The UART is an IOStream Device. Typicall usage is:
Code (C++)
Select All
IOStream cout(&uart);
cout << PSTR("Hi") << endl;
cout.print(42);
 


A lot of drivers are actually IOStream Devices and can be used to stream text output to. This includes for instance the Ethernet W5100 driver. 

To make things even more reusable and efficient the Cosa UART uses to IOBuffers for input and output buffering. The IOBuffer is also an implementation of the IOStream Device interface. 

Some of the documentation of Cosa is out of date as this project has been ongoing for more than two years and is very very much larger than the Arduino core. 

The dependency to Arduino and the IDE is more or less totally removed. Cosa can be used standalone with the AVR-GCC toolchain.

Cosa is much more than an Arduino library or even Arduino core.  

Cheers! Mikael
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #7 - Jan 21st, 2015 at 10:56am
Print Post  
Hi Cosa,

Thanks for the info. Your core is certainly very impressive!

Correct me if I am wrong but you seem to provide the equivalent of the Arduino serial.write() methods?

Can you provide the same print() and println() functions as used in the Arduino core?

Thanks
  
Back to top
IP Logged
 
Cosa
Newbies
*
Offline


Posts: 6
Joined: Jan 21st, 2015
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #8 - Jan 21st, 2015 at 3:36pm
Print Post  
Hi Tim. It would be nice to get full debug support for Cosa. It does not seem to be very difficult.

The print and println functions are available in the IOStream class. https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/IOStream.hh
Whats is required is more or less the binding to the UART as I described previous in a code example. What does the debugger need in more detail? How does the interaction work?

Below is what is needed in Cosa to get Arduino style. 
Code (C++)
Select All
#include "Cosa/IOStream/Driver/UART.hh"

// Create an instance of the iostream and bind to the uart
IOStream Serial(&uart);

// Start the uart
uart.begin(9600);

// Some examples
Serial.print(42);
Serial.print_P(PSTR("Hi"));
Serial.println();
...
 


Some extra renaming is needed but this shows the basic principle to port Arduino code directly to Cosa. 

Cheers! Mikael
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #9 - Jan 21st, 2015 at 3:52pm
Print Post  
Oh okay thanks. I will give it a try I think it will work easily enough. 

I'll try to add this over the next 24/48 and make a service pack release.

One last question. Is there a single value against all boards.txt defs that can be used to determine that cosa is being used. I have not yet looked at boards.txt but assume there might be something? Otherwise I will use the first few chars of the board names which all seems to contain "Cosa" but that seems a bit limiting for you in the future.


As a reminder for me....

By the looks of it Visual Micro just needs to substitute HardwareSerial references with IOStream then in the debugBegin() use the following code to init the Serial port:-

Code
Select All
// Create an instance of the iostream and bind to the uart
IOStream Serial(&uart);
// Start the uart
uart.begin(debug_speed);
 



Thanks again
« Last Edit: Jan 21st, 2015 at 3:52pm by Tim@Visual Micro »  
Back to top
IP Logged
 
gelius59
Junior Member
**
Offline


Posts: 82
Location: Ukraine
Joined: Oct 6th, 2012
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #10 - Jan 21st, 2015 at 5:26pm
Print Post  
Interesting, powerful core Cosa.
Well if it works debugger.
  
Back to top
 
IP Logged
 
Cosa
Newbies
*
Offline


Posts: 6
Joined: Jan 21st, 2015
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #11 - Jan 21st, 2015 at 9:54pm
Print Post  
It is easy to detect the core in the boards.txt file. Each board has the following property.
Code
Select All
BOARD.build.core=cosa
 


There is also preprocessor symbol for the board. You might also want to integrate with the Cosa command line build. Please see the folder build and the shell script cosa and default makefile Cosa.mk. The script allows users to compile, link, upload and monitor without writing a makefile. 

Cheers!
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #12 - Jan 22nd, 2015 at 4:43am
Print Post  
@Cosa - What a huge project you have created. It's awesome!

There is a new beta on our downloads page that has basic debug support and break and/or trace.

minor: The beta also includes a number of other minor fixes one that relates to Cosa. The "Show sketch core and libraries" option did not include files with ".hh" extension so it wasn't so easy to explore the underlying cosa code.

There are a few area  that need to be addressed...

1) I could not find a millis() function so the breakpoint timers are temporarily spoofed with a meaningless integer counter. Hopefully @Cosa can help with this?

2) If you have an Uno and want to use the "Cosa Arduino Uno 328 optiboot" board you need to edit the boards.txt in the Cosa hardware folder folder and change the board name of the Uno from "uno." to something else such as "cosa_uno.". The board name is the string prefix of all the Uno properties. The problem currently is that Visual Micro shows a single list of all boards for the selected Ide. The name Uno is already in use by the Arduino Ide. I am sure this problem might apply to a few others boards, I will have to give some thought to a better solution.

3) Currently the digital pins viewer and analog graph fails because the debugger runs like an Arduino library and does not have automatic access to digitalRead and digitalWrite. I ran out of time to investigate but it is just a matter of knowing which .hh file contains the analogRead and digitalread functions?

I hope that covers it
« Last Edit: Jan 22nd, 2015 at 4:44am by Tim@Visual Micro »  
Back to top
IP Logged
 
Cosa
Newbies
*
Offline


Posts: 6
Joined: Jan 21st, 2015
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #13 - Jan 22nd, 2015 at 8:15am
Print Post  
Quick answer to some of the questions:

Cosa has two implementations of millis() depending on resolution and if the user wants to take full advantage of Cosa's support for extreme low power mode. The first implementation is Watchdog::millis(). This implementation gives a resolution of max 16 ms. The advantage is that the Watchdog timer will continue to run when the MCU is put into power down sleep (uA level). The second and more accurate version is RTC::millis() which is closest to the Arduino millis() function. Both timers requires a call to begin() in setup. 
Code (C++)
Select All
#include "Cosa/RTC.hh"
inline uint32_t millis()
{
  return (RTC::millis());
}

void setup() {
  ...
  RTC::begin();
  ...
}
 


Cosa is fully object-oriented and pins are different classes; Pin, InputPin, OutputPin, IOPin, AnalogPin, etc. There is a very rich set of member functions to write and read the pin values. Also Cosa uses strong data typing so that pins are actually symbols. The mapping to Arduino is:
Code (C++)
Select All
#include "Cosa/InputPin.hh"
#include "Cosa/OutputPin.hh"
#include "Cosa/AnalogPin.hh"

inline int digitalRead(Board::DigitalPin pin)
{
  return (InputPin::read(pin));
}

inline void digitalWrite(Board::DigitalPin pin, uint8_t value)
{
  OutputPin::write(pin, value);
}

inline int analogRead(Board::AnalogPin pin)
{
  return (AnalogPin::sample(pin));
}
 


The normal way to use Cosa Pins is:
Code (C++)
Select All
InputPin button(Board::D4);
OutputPin LED(Board::D5, 1);
 


The pin constructor does all the initialization of pin mode, pull-up, and start value if needed.

Both the object-orientation (classes) and the strong typing contribute to the X2-X10 higher performance than Arduino/Wiring. Please see the Benchmarks; https://github.com/mikaelpatel/Cosa/tree/master/examples/Benchmarks. The compiler can do a much better job and it is actually possible to write a pin-toggle function that is done in a single instruction (clock cycle, 62.5 ns) and still have a very high level of abstraction. 

BW: There is a high level IOStream class for trace which allow syslog style prorities and that adds a lot of information to trace points. Below is a snippet from a trace.
Code (C++)
Select All
45:void setup():trace:free_memory() = 387

53:void loop():measure:one character (new-line):28 us
1
54:void loop():measure:one character:36 us
1
55:void loop():measure:one character string:44 us
 


https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmar...
The source code that generated this looks like this:
Code (C++)
Select All
void setup()
{
  ...
  TRACE(free_memory());
  ...
}

void loop()
{
  // Measure time to print character, string and number
  MEASURE("one character (new-line):", 1) trace << endl;
  MEASURE("one character:", 1) trace << '1' << endl;
  MEASURE("one character string:", 1) trace << PSTR("1") << endl;
  ...
}
 


https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmar...
Cheers!
« Last Edit: Jan 22nd, 2015 at 8:25am by Cosa »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #14 - Jan 24th, 2015 at 12:15am
Print Post  
Thanks for the info. The more I see and use the more I realize that this is the first real core for Arduino! So incredibly well written and seems to provide so much efficiency. The simple Arduino syntax is great for novices but I think everyone else should take a good look as Cosa.

Timed debugger breakpoints are now working with Cosa and provide break/trace and watch. A new beta is available from the downloads page.

Update of variables or calling methods on the arduino from the debugger are not yet working but we will look at that shortly.

The other remaining items are:-

Quote:
Live memory usage graph
Digital pins visualization
Analog pin graphs
I2C device enumeration


The reading of the analog/digital ports is slightly more complex because the debugger only does that using it's own code when displaying a graphical representation of the pins. To do that it needs to know how many digital or analog pins there are and to be able to get  the value of any pin by pin number. Or to get the values of all pins into arrays in pin number order.

Thanks
  
Back to top
IP Logged
 
gelius59
Junior Member
**
Offline


Posts: 82
Location: Ukraine
Joined: Oct 6th, 2012
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #15 - Jan 24th, 2015 at 3:35am
Print Post  
I fully agree with Tim.
excellent core “Cosa”
Especially if used with Visual micro.
But requires programming experience.
I am new to programming a hobby for me, but I can appreciate it.
The digital output is faster, checked. Smiley
  
Back to top
 
IP Logged
 
gelius59
Junior Member
**
Offline


Posts: 82
Location: Ukraine
Joined: Oct 6th, 2012
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #16 - Jan 24th, 2015 at 6:18am
Print Post  
If it is of interest.
Here are the results of the study.
For digital output.
Simple sketch Blink without delay "delay (1000)"
For core "Cosa" and Arduino

https://cloud.mail.ru/public/df3dbba2d181/Arduino.jpg
https://cloud.mail.ru/public/f57cba1c9ed7/Cosa.jpg
« Last Edit: Jan 24th, 2015 at 8:13am by gelius59 »  
Back to top
 
IP Logged
 
Cosa
Newbies
*
Offline


Posts: 6
Joined: Jan 21st, 2015
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #17 - Jan 24th, 2015 at 11:38am
Print Post  
Nice screenshots. You can go even faster with:
Code (C++)
Select All
OutputPin::toggle(Board::D10);
OutputPin::toggle(Board::D10);
 


Please see the Cosa Pin Benchmark: 
https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmar...
This allows the compiler to reduce the code even further but is not so flexible as the pin value must be a constant. 

Cheers!
gelius59 wrote on Jan 24th, 2015 at 6:18am:
If it is of interest.
Here are the results of the study.
For digital output.
Simple sketch Blink without delay "delay (1000)"
For core "Cosa" and Arduino

https://cloud.mail.ru/public/df3dbba2d181/Arduino.jpg
https://cloud.mail.ru/public/f57cba1c9ed7/Cosa.jpg

« Last Edit: Jan 24th, 2015 at 11:39am by Cosa »  
Back to top
 
IP Logged
 
Cosa
Newbies
*
Offline


Posts: 6
Joined: Jan 21st, 2015
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #18 - Jan 24th, 2015 at 11:51am
Print Post  
Tim@Visual Micro wrote on Jan 24th, 2015 at 12:15am:
The reading of the analog/digital ports is slightly more complex because the debugger only does that using it's own code when displaying a graphical representation of the pins. To do that it needs to know how many digital or analog pins there are and to be able to get  the value of any pin by pin number. Or to get the values of all pins into arrays in pin number order.

I think I can help you with that. The Cosa Board definition contains a few symbols and program memory tables for this use case. Best is an example. In the Sandbox directory there is a command shell example (CosaShell) that allows basic Arduino functions as interactive commands. There is a command for printing the state of the digital pins. By name (D0..Dn), LED or all.
https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaShell/Comma...
The maps are called digital_pin_map, analog_pin_map and pwm_pin_map. https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Board.hh#L113 

The shell example sketch also contains a simple I2C (TWI) and 1-Wire (OWI) scanner. https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaShell/Comma... and https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaShell/Comma....

Cheers!
« Last Edit: Jan 25th, 2015 at 2:19pm by Cosa »  
Back to top
 
IP Logged
 
gelius59
Junior Member
**
Offline


Posts: 82
Location: Ukraine
Joined: Oct 6th, 2012
Re: Using Cosa (replaced arduino cores) - Debugger fails
Reply #19 - Jan 24th, 2015 at 12:08pm
Print Post  
Cosa wrote on Jan 24th, 2015 at 11:38am:
Nice screenshots. You can go even faster with:
Code (C++)
Select All
OutputPin::toggle(Board::D10);
OutputPin::toggle(Board::D10);
 


Please see the Cosa Pin Benchmark: 
https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmar...
This allows the compiler to reduce the code even further but is not so flexible as the pin value must be a constant. 

Cheers!
gelius59 wrote on Jan 24th, 2015 at 6:18am:
If it is of interest.
Here are the results of the study.
For digital output.
Simple sketch Blink without delay "delay (1000)"
For core "Cosa" and Arduino

https://cloud.mail.ru/public/df3dbba2d181/Arduino.jpg
https://cloud.mail.ru/public/f57cba1c9ed7/Cosa.jpg



Thanks.
It's fast, practice test. Smiley
I'm still learning core “Cosa”

Best regards.
Yrij.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint