Show Posts
Pages: 1 2 3 [4] 5 6 ... 32
46  Development / Other Software Development / Re: Coroutines library on: July 21, 2014, 09:22:52 am

Interesting approach! I have studied and implemented three+ variants in Cosa; Event/FSM driven, proto-threads and coroutines. Below are some links to example sketches.

1. Event driven (and FSM)

2. Proto-threads

3. Coroutines (Cosa Nucleo)

More info can be found on the Cosa blog and the on-line documentation and research papers.

47  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 21, 2014, 01:59:42 am

Around 4400 characters sound about right. That is the number of characters that would get sent before the large IOBuffers are filled up. For every 10 characters on the fast side one(1) character is sent on the slow side.

The next step is to get a measure on the maximum burst size and the minimum time between bursts to calculate the average bps.  

Using the IOBuffers for the UARTs is the simpler solution and it is possible to modify the IOBuffer to allow "any" size (ie remove the power of 2 restriction). This would allow you to use more of the Mega 1280 8K byte SRAM for the buffers.

Yes, it is possible to use SPI or extended SRAM. Typical size is 32 K byte. The interesting design would be to implement the IOBuffer interface with an IOStream::Device driver for these storage types. The UART requires an implementation of the IOStream::Device interface. It is possible to hook any implementation of the interface directly to the UART. The restriction is that putchar() cannot block as the UART will call that from the ISR and the implementation must not take longer time than the minimum time between received characters. Below is the "simple" Cosa OOP ISR for the RX interrupt.
void UART::on_rx_interrupt()

Once and awhile I get the question of porting Cosa to other processors/boards. This will take some time before it happens. There are several issues. The one that is my greatest concern is adding the necessary components and infra-structure to allow scaling and reuse of libraries.

This implies a different approach with a micro kernel/multi-tasking, interfaces for applications and drivers, build system with libraries, delivery and support, etc. Cosa is moving slowly in this direction with the new build system, multi-tasking, etc, but there is a lot left before considering porting. Then there is the next issue which also goes for any hardware/device drivers added to Cosa; the software must be able to regression test. That implies a lot of hardware for other than my own projects. And suddenly this is not simply sharing any more.

I have done the numbers on software development for Due/Teensy3+/ARM with port and it is in the range of 2-3 man months (400-600 h, excluding the time needed to read up on all the hardware and build the necessary test setups). That is also difficult to motivate without a target application/project/etc of my own.

48  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 20, 2014, 04:43:26 pm

Hi Adam. I have pushed an IOBuffer update that should fix this issue. Please download and test it. There is also an update of the CosaBenchmarkUART to include large IOBuffers and burst write/measure.

49  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 20, 2014, 03:10:47 pm

That was a great test case. I have not pushed the Mega UARTs in this way. That generates a fair amount of interrupt calls and stresses the UART/IOBuffer implementation.

I think we need to do the numbers. The average baud rate cannot be larger than the lowest in the chain. The bursts must leave enough time for the buffer to be transmitted. 10X the baud rate means busts must give at least X10 time period for the average baud rate to avoid buffer overflow.

Assume that you send a burst of 2000 characters at the high baud rate and they are more or less queued directly. It will take X10 the time to empty the buffer. A continues flow at the high baud rate will not work. 2000 character takes about 2 seconds at 9600 to transfer but less than 200 ms at 115200. If you send another burst within the 2 seconds the buffers will just fill up and overflow. Think of the problem as water flow, pipes and buckets ;-)

So more details required; what does your test data feed program look like?

50  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 20, 2014, 01:00:21 pm

Hi Adam. Some more details; What is the chip set on the converters? Need to check the internal buffer size. It sounds like a buffer overflow problem. The smallest buffer in the upward flow will be filled and overflow.

For example, the CP2102 has 640B TX/576B RX buffer. which seems close to your numbers.

Another this to consider is that the putchar() is blocking when the IOBuffer is full.

As long as the high bps works we can rule out problems in the UART ISR's, i.e. UART internal buffer overrun on the ATmega1280. Right now there is no capture of the error bits in the driver. Might be something to consider.

51  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 19, 2014, 06:09:59 pm

Hi Adam.

The difference between sizeof() and the IOBuffer template size parameter is easy; there is more to the IOBuffer than the storage area/SIZE. The extra memory is for the "hidden" vtable pointer (2 bytes), io-mode (1 byte), head and tail index (2X2=4 bytes).

If you are getting garbage at exactly the same position that is an interesting problem. Need more information to understand this. What is the circuit? Wiring? Length of wires? etc.

52  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 18, 2014, 04:43:19 pm

No problems. The intent is more in the line "Please remember to...". And there is no problem with links to the copied code and just posting the changes and some of the context.

Testing new combinations gives insights to new usage and possible conflicts between components or as in this case the drawback with default parameters. They are great when the API is know but while learning they might hide issues.

During the testing I found an issue with the pin numbering in the SNMP part. The SNMP pin index to Cosa Board pin mapping was missing. There is an update with this change and an updated map. Please note that the mapping is not the full Arduino Mega pin set. The SNMP and Web Server part will deliver the same value.

53  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 18, 2014, 02:53:14 pm

The quick answer is add a timeout to the requests and it works fine.
void loop()
   const uint32_t TIMEOUT = 100L;
  // Service incoming requests;
  // Service SNMP requests with given MIB handlers
  SNMP::PDU pdu;
  snmp.request(pdu, TIMEOUT);
Tested it on an Arduino Leonardo :-) with an Ethernet Shield.
user@host: cosa leonardo upload
AVR Memory Usage
Device: atmega32u4

Program:   22380 bytes (68.3% Full)
(.text + .data + .bootloader)

Data:        793 bytes (31.0% Full)
(.data + .bss + .noinit)
The long answer is if you look at the description of HTTP::Server::run() and SNMP:request() there is a timeout parameter that is default blocking.



BW: You left out the code in the first post and then in the next post you had removed the copyright notice. And you have only pasted together two example sketches. That is very very very bad practice.

Always post code. Always post environment; board, core, host, versions, versions, version. And always keep copyright notices if you are copying.

54  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 16, 2014, 11:48:44 am
The latest Cosa development have been focused on implementing a file system for the flash device driver (S25FL127S). The device is accessed through SPI and has a total size of 16 Mbyte (128 Mbit). Typical access time with the optimized Cosa SPI functions are approx. 600 Kbyte/s read and 200 Kbyte/s at 16 MHz clock and DIV2 SPI clock (i.e. 8 Mhz).

The Cosa Flash File System takes advantage of the S25FL127S hybrid sector structure with 16 X 4 Kbyte sectors followed by 255 x 64 Kbyte sectors. The file system allows for up to 16 directories with up to 128 files per directory. The total number of data files is limited to 255. The file and directory API is very traditional Linux with open, close, remove, tell, seek, read, write and ls, cd, mkdir and more.

The API follows the Cosa FAT16 interface so that SD and Flash access can replace each other in a sketch. Also the CFFS::File and FAT16::File classes implement the Cosa IOStream interface and all the output functions and operators can be used directly. Both binary and text data can be written to files on the flash. The only restriction is that the last data entry cannot be 0xff. This works fine for text while binary data records must be padded.


Example sketch:

The example sketch demonstrates the file system functionality and binding a file to an iostream for log output in text (i.e. analog sample written to the file). Above is a screen shot of the output.

55  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 16, 2014, 11:27:26 am
I can confirm, Mega1280 is working now smiley, however it seems that the uart1 doesn't work, I've tried the MegaUARTs example and had to change to uart2 to test it.
Thanks for the info. Great that you got your Mega 1280 board up and running with Cosa. I will look into the UART numbering. Seems like the ISRs might have got mixed up.

56  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 14, 2014, 11:47:16 am
Good news ans super fast response, thank you very much.
This is my beginning of the adventure with Cosa plaftorm smiley The note is taken where to post questions smiley
Kind regards,
You are welcome. Please let me know how the update works with Arduino Mega 1280 as I do not have that specific board to test. As the MCU is very similar to the Mega 2560,  half the amount of program memory but otherwise the same, I believe that it should work just fine.

I have also added support for the Arduino Diecimila ( All boards can be built with the command line tool.

57  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 13, 2014, 04:40:58 pm
Hello, I hope this is right place to ask the question. I have Mega1280 board and I don't know what should I choose in tools/boards. In the arduino ide there is mega1280, what would be equivalent in cosa?
Kind Regards,

Hi Adam! Ok with the question here on the Arduino forum but you would get faster response on the Cosa github issues list.

The current Mega 2560 support will not work for the Mega 1280 as this board has a different bootloader. To fix this I have added a board definition for the Mega 1280 to the Cosa boards definition file. Please download from github and install


58  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 06, 2014, 09:32:28 am
The latest update of the Cosa command line build script adds support for attiny devices. The below example command line will build the CosaBlink sketch for an ATtiny84 (internal clock 8 MHz) and upload with ISP device on the given port.
user@host:~/Sketchbook/hardware/Cosa/examples/Blink/CosaBlink$ cosa attiny84-8 ispload ISP_PORT=/dev/ttyACM0
The command "cosa boards" lists the devices that require ISP device upload as "Cosa Breadboard" with the MCU and clock type/frequency. The default ISP device is defined as "arduino:arduinoisp" in the Cosa/boards.txt file.

The latest update also includes an updated version of (serial monitor) so that 1) the board may signal shutdown of the serial monitor and 2) LF/CR is handled correctly both for RX and TX to the board. The shutdown signal is used by the Cosa ASSERT macro and the Trace::fatal_P() member function on error detect. The ASSERT error message uses the same format as GCC compiler errors and warnings so that the M-X goto-next-locus (F3) command can be used in GNU Emacs to directly step to the ASSERT code line.

59  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 03, 2014, 03:10:44 pm
The latest update of Cosa includes a device driver for MAX7219/MAX7221 Serially Interfaced, 8-digit LED Display Drivers.

The device driver implements the Cosa LCD/IOStream::Driver interface. It handles carriage-return-line-feed, backspace, alert, horizontal tab and form-feed. The period character is translated to the 7-segment LED decimal point of the previous written character. The example sketch ( shows how to output floating-point numbers to a Cosa IOStream.


60  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 01, 2014, 06:57:35 pm
Command line build of Cosa based sketches is now as easy as it gets.  A new shell script (cosa)  eliminates the need for makefiles. Used as follows:
Where BOARD is one of the BOARD_TAGs and COMMAND is what is passed to make (Arduino-Makefile). Typical usage are:

1. Some basic instructions on how to use the tool and make targets.
user@host:~/Sketchbook/hardware/Cosa/examples/Blink/CosaBlink$ cosa help
Available targets (default is compile the code):
  upload            - upload
  ispload           - upload using an ISP
  raw_upload        - upload without first resetting
  eeprom            - upload the eep file
  raw_eeprom        - upload the eep file without first resetting
  clean             - remove all our dependencies
  depends           - update dependencies
  reset             - reset the Arduino by tickling DTR or changing baud
                      rate on the serial port.
  boards            - list all the boards defined in boards.txt
  config            - list configuration
  monitor           - connect to the Arduino's serial port
  size              - show the size of the compiled output (relative to
                      resources, if you have a patched avr-size).
  verify_size       - verify that the size of the final file is less than
                      the capacity of the micro controller.
  symbol_sizes      - generate a .sym file containing symbols and their
  disasm            - generate a .lss file that contains disassembly
                      of the compiled file interspersed with your
                      original source code.
  generate_assembly - generate a .s file containing the compiler
                      generated assembly of the main sketch.
  burn_bootloader   - burn bootloader and fuses
  set_fuses         - set fuses without burning bootloader
  help_vars         - print all variables that can be overridden
  avanti            - short cut for upload and monitor
  help              - show this help
More details in:

2. Get the current configuration.
user@host:~/Sketchbook/hardware/Cosa/examples/Blink/CosaBlink$ cosa uno config
------------------------- Configuration:
- [USER]               ARDMK_DIR = /home/user/Sketchbook/hardware/Cosa/build/Arduino-Makefile
- [USER]               ARDUINO_DIR = /home/user/opt/arduino-1.0.5
- [AUTODETECTED]       ARDUINO_PREFERENCES_PATH = /home/user/.arduino/preferences.txt
- [AUTODETECTED]       ARDUINO_SKETCHBOOK = /home/user/Sketchbook (from arduino preferences file)
- [BUNDLED]            AVR_TOOLS_DIR = /home/user/opt/arduino-1.0.5/hardware/tools/avr (in Arduino distribution)
- [COMPUTED]           ARDUINO_LIB_PATH = /home/user/opt/arduino-1.0.5/libraries (from ARDUINO_DIR)
- [USER]               ARDUINO_CORE_PATH = /home/user/Sketchbook/hardware/Cosa/cores/cosa
- [USER]               ARDUINO_VAR_PATH = /home/user/Sketchbook/hardware/Cosa/variants
- [USER]               BOARDS_TXT = /home/user/Sketchbook/hardware/Cosa/boards.txt
- [DEFAULT]            USER_LIB_PATH = /home/user/Sketchbook/libraries (in user sketchbook)
- [DEFAULT]            PRE_BUILD_HOOK =
- [USER]               BOARD_TAG = uno
- [COMPUTED]           OBJDIR = build-uno (from BOARD_TAG)
- [ASSUMED]            MONITOR_BAUDRATE = 9600
- [DEFAULT]            MCU_FLAG_NAME = mmcu
- [DEFAULT]            CFLAGS_STD = -std=gnu99
- [AUTODETECTED]       Size utility: AVR-aware for enhanced output
- [COMPUTED]           BOOTLOADER_PARENT = /home/user/opt/arduino-1.0.5/hardware/arduino/bootloaders (from ARDUINO_DIR)
Please refer to /home/user/Sketchbook/hardware/Cosa/build/Arduino-Makefile/ for more details.

3. Get a list of the available boards.
user@host:~/Sketchbook/hardware/Cosa/examples/Blink/CosaBlink$ cosa boards
atmega328-8           Cosa Breadboard (ATmega328, 8 MHz internal clock)
attiny84-8            Cosa Breadboard (ATtiny84, 8 MHz internal clock)
attiny85-8            Cosa Breadboard (ATtiny85, 8 MHz internal clock)
attiny861-8           Cosa Breadboard (ATtiny861, 8 MHz internal clock)
duemilanove           Cosa Arduino Duemilanove (ATmega328/BOOT_168)
leonardo              Cosa Arduino Leonardo (ATmega32U4/Caterina)
lilypad               Cosa LilyPad Arduino (ATmega328/BOOT_168, 8 MHz)
lilypad-usb           Cosa LilyPad Arduino USB (ATmega32U4/Caterina, 8 MHz)
mega                  Cosa Arduino Mega (ATmega2560/STK500v2)
microduino-core32u4   Cosa Microduino-Core32u4 (ATmega32U4/Caterina)
microduino-core       Cosa Microduino-Core (ATmega328/Optiboot)
microduino-core-plus  Cosa Microduino-Core+ (ATmega644P/Optiboot)
mighty                Cosa Breadboard (ATmega1284/BOOT_1284P)
mighty-opt            Cosa Breadboard (ATmega1284/Optiboot)
miniwireless          Cosa Anarduino MiniWireless (ATmega328/BOOT_168)
moteino               Cosa LowPowerLab Moteino (ATmega328/DualOptiboot)
nano                  Cosa Arduino Nano (ATmega328/BOOT_168)
pinoccio              Cosa Pinoccio Scout (ATmega256RFR2/STK500v2)
pro-micro             Cosa Arduino Pro Micro (ATmega32U4/Caterina)
pro-mini-8            Cosa Arduino Pro Mini (ATmega328/BOOT_168, 3.3V, 8 MHz)
pro-mini              Cosa Arduino Pro Mini (ATmega328/BOOT_168)
uno                   Cosa Arduino Uno (ATmega328/Optiboot)

4. Build the CosaBenchmarkPins sketch for Arduino Uno, upload and start the serial monitor.
user@host:~/Sketchbook/hardware/Cosa/examples/Benchmarks/CosaBenchmarkPins$ cosa uno avanti

To install this new build feature please either add Cosa/build to your PATH or symbolic link from you local bin directory to the build script $COSA_DIR/build/cosa. The default path for COSA_DIR is $HOME/Sketchbook/hardware/Cosa. You can set COSA_DIR as an exported environment variable.

To use GNU Emacs as the Cosa IDE simply use the command M-X compile with "cosa BOARD upload" (only needed the first time per session). You can directly move to any compile error with M-X goto-next-locus. Add the following to your .emacs file to allow bind compile-upload to F2 and goto-next-error to F3. The first line below will make GNU Emacs recognize .pde/.ino files as C++ and automatically switch to the correct mode.  
(setq auto-mode-alist (cons '("\\.\\(pde\\|ino\\)$" . c++-mode) auto-mode-alist))
(global-set-key (quote [f2]) (quote compile))
(global-set-key (quote [f3]) (quote goto-next-locus))
Below is an example of compiling the CosaBlink example sketch with a bad modification and stepping to the error line (F2 and F3).

GNU Emacs will help you with indentation, quick incremental search,  color coding comments, etc. Together with the new Cosa build script GNU Emacs gives a productive IDE for Arduino programming that is easy to customize.  

The Arduino version is configured in the file Cosa/build/ There is support for the following Arduino versions; 1.0.5, 1.5.6-r2 and the nightly build with GCC 4.8.1.

Pages: 1 2 3 [4] 5 6 ... 32