Show Posts
Pages: 1 ... 57 58 [59] 60 61 ... 112
871  Using Arduino / Storage / Re: Random Error Codes on: November 02, 2012, 10:19:59 am
The SparkFun microSD shields uses pin 8 for SD chip select.  Sometimes it will almost work with the wrong chip select pin.  This happens if pin 8 floats low.

Try changing this line
const uint8_t chipSelect = SS;
to this
const uint8_t chipSelect = 8;
872  Products / Arduino Due / Incorrect type for link() in syscalls.h prevents use of unistd.h on: October 30, 2012, 08:59:26 pm
The link() stub for newlib in syscalls.h has the wrong type and causes a conflicts with the correct definition in unistd.h. 

Here is an example sketch:

#include <unistd.h>
void setup() {
void loop() {}

That results in this error:
D:\\arduino-1.5\hardware\arduino\sam\cores\arduino/syscalls.h:43: error: declaration of C function 'int link(char*, char*)' conflicts with
D:\arduino-1.5\hardware\tools\g++_arm_none_eabi\bin\../lib/gcc/arm-none-eabi/4.4.1/../../../../arm-none-eabi/include/sys/unistd.h:107: error: previous declaration 'int link(const char*, const char*)' here

Changing the definition in syscalls.h to this:
extern int link(const  char *cOld, const char *cNew ) ;

And the implementation in syscalls_sam3.c to this:
extern int link(const char *cOld, const char *cNew )
    return -1 ;

Seems to fix the problem.
873  Using Arduino / Storage / Re: SD examples and chip select definition on: October 28, 2012, 11:00:00 am
The SD library has a long history and many of the examples are out of date or just plain wrong.

This comment is wrong.
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);

The SD library always sets SS high as an output so no code is needed for that purpose.  Here is the code from Sd2Card.cpp in IDE version 1.01.
  // SS must be in output mode even it is not chip select
  pinMode(SS_PIN, OUTPUT);
  digitalWrite(SS_PIN, HIGH); // disable any SPI device using hardware SS pin

Future versions of the SD.h library will use the SPI.h library and it also makes SS as an output.  Here is code from the 1.5 SPI.h library.
  // Set SS to high so a connected chip will be "deselected" by default
  digitalWrite(SS, HIGH);

  // When the SS pin is set as OUTPUT, it can be used as
  // a general purpose output port (it doesn't influence
  // SPI operations).
  pinMode(SS, OUTPUT);

Here is the reason you may need to make some pins outputs and high.  If you have more than one device on the SPI bus, you must disable all devices other than the SD by making their chip select pin an output and high.

For the Ethernet shield, pin 10 is chip select for the Ethernet controller and pin 4 is chip select for the SD card.  So you should make pin 10 an output and set it high to disable the Ethernet controller, not because pin 10 is SS.

Much confusion results from the fact that on 328 Arduinos pin 10 is also SS.  On the Mega, people change the 10 to 53, the SS pin for the Mega, and then the SD on the Ethernet shield will not initialize.  The problem is that the Ethernet controller is no longer disabled on the Mega.

For the Ethernet shield you must always make pin 10 an output and high before initializing the SD card.  It has nothing to do with SS.

874  Development / Other Hardware Development / Re: Teensy 3.0 on: October 25, 2012, 09:39:06 pm
Yes you can connect it directly.
875  Using Arduino / Storage / Re: FAT16 vs FAT32 on: October 25, 2012, 06:36:34 am
Many of the fastest most reliable SD cards for embedded systems are small, 2GB or less, and based on SLC flash.  Larger SLC cards are available but are very expensive.
Due to the lower complexity in managing SLC flash, the write performance for SLC at the IC level is typically twice as fast. With controller multiplexing this can be reduced, but this accounts for the main delta in read speed versus write speed in retail flash products today.

SLC flash SDs last 20-100 times longer than consumer grade MLC flash SDs.
3-Bit MLC technology (a.k.a. TLC) has an exponentially lower number of program/erase cycles. SLC technology, targeting embedded and mission critical applications, will continue to maintain an emphasis on endurance and reliability.
876  Using Arduino / Storage / Re: FAT16 vs FAT32 on: October 24, 2012, 04:51:01 pm
First, the SD standard specifies that 2GB and smaller cards should be formatted FAT16 and very small cards are FAT12.

Cards larger than 2GB must be FAT32.

The practical reason is that SD cards perform better with large clusters.  Small clusters causes many accessed to the FAT (File Allocation Table) and SD cards don't tolerate random access well.  They are designed for contiguous reads and writes

I's best to format SD cards with the SD Association's formatter  This program aligns file structures with the internal flash chips for optimum performance.

OS format utilities do not always produce an optimal layout.
877  Using Arduino / Storage / Re: New SdFat optimized for Mega and Teensy 3.0 on: October 24, 2012, 04:41:20 pm
I don't use the chip select feature in the SPI module since SD transfers are so large.

To use this feature you must select the proper pin multiplexing mode with the Port Control Module.

See chapter 10 and 11 of the chip data sheet.
Chapter 10
Signal Multiplexing and Signal Descriptions
10.1 Introduction
To optimize functionality in small packages, pins have several functions available via
signal multiplexing. This chapter illustrates which of this device's signals are multiplexed
on which external pin.
The Port Control block controls which signal is present on the external pin. Reference
that chapter to find which register controls the operation of a specific pin.
Chapter 11
Port control and interrupts (PORT)
11.1 Introduction
For the chip-specific implementation details of this module's
instances see the chip configuration chapter.
11.1.1 Overview
The port control and interrupt (PORT) module provides support for port control, and
external interrupt functions. Most functions can be configured independently for each pin
in the 32-bit port and affect the pin regardless of its pin muxing state.
There is one instance of the PORT module for each port. Not all pins within each port are
implemented on a specific device.

I am not very knowledgeable about the Kinetis chip, Paul Stoffregen helped me configure the SPI to be compatible with his software for Teensy 3.0. 
878  Using Arduino / Storage / Re: New SdFat optimized for Mega and Teensy 3.0 on: October 23, 2012, 09:13:52 am
Yes you can read SPIx_POPR as a 32 bit register but only 16 bits are data.  See
Figure 43-1. DSPI Block Diagram  - shows 32bit data path to the shift register (and and extra for command)
Figure 43-1 is wrong.  See rule 8 in my previous post.  See  43.3.7 for the format of PUSHR.
43.1.2 "SPI frames longer than 16 bits can be supported using the continuous selection format"..
Continuous selection format just insures that CS remains low, it has nothing to do with the FIFOs.
Continuous Peripheral Chip Select Enable
Selects a continuous selection format. The bit is used in SPI Master mode. The bit enables the selected
PCS signals to remain asserted between transfers.
0 Return PCSn signals to their inactive state between transfers.
1 Keep PCSn signals asserted between transfers.

43.4.2 "The SPI frames can be 32 bits long."..

Frames can be any size but a max of 16 bits can be transferred to/from the FIFOs.  Unfortunately the data sheet uses Frame size for two things.

In the CTAR 43.3.3 it is how many bits wide the data field is in a FIFO.

In other places it is how many bits are sent in a transfer while CS is low.

Again the datasheet is a clue for Kinetis and point 8 above applies to many sections.
879  Using Arduino / Storage / Re: Program hangs on SD.begin() on: October 23, 2012, 08:42:49 am
If you want to use a serial port in SPI mode start with this version of SdFat

It is designed to support various SPI controllers.  You just need to write the low level spi read/write functions for AVR serial ports.
880  Using Arduino / Storage / Re: New SdFat optimized for Mega and Teensy 3.0 on: October 23, 2012, 06:20:07 am
The RX FIFO appears to be 32-bits wide but:
Quote RX FIFO Size
SPI supports up to 16-bit frame size during reception.
The TX FIFO is 32-bits wide but the high 16-bits are command bits.
43.3.7 DSPI PUSH TX FIFO Register In Master Mode (SPIx_PUSHR)
PUSHR provides the means to write to the TX FIFO. Data written to this register is
transferred to the TX FIFO . 8- or 16-bit write accesses to the Data Field of PUSHR
transfers the 16 bit Data field of PUSHR to the TX FIFO. Write accesses to the
Command Field of PUSHR transfers the 16 bit Command Field of PUSHR to the TX
FIFO. The register structure is different in Master and Slave modes. In Master mode, the
register provides 16-bit command and data to the TX FIFO. In Slave mode, the 16 bit
Command Field of PUSHR is reserved.

Even if you could send 32 bits, the byte order in memory is not in the correct order due to nature of a little-endian fetch from memory to a 32 bit register.

See above for the problem with 16-bit transfers.

The datasheet is not too clear in spots.  See point 8 in this list:
10. There are at least 10 types of capacitors.
9. Theory tells you how a circuit works, not why it does not work.
8. Not everything works according to the specs in the databook.
7. Anything practical you learn will be obsolete before you use it,
except the complex math, which you will never use.
6. Always try to fix the hardware with software.
5. Engineering is like having an 8 a.m. class and a late afternoon lab
every day for the rest of your life.
4. Overtime pay? What overtime pay?
3. Managers, not engineers, rule the world.
2. If you like junk food, caffeine and all-nighters, go into software.
1. Dilbert is not a comic strip, it's a documentary.
881  Development / Other Hardware Development / Re: Teensy 3.0 on: October 22, 2012, 09:56:21 pm
The main difference is that industrial cards use SLC flash and consumer cards use MLC flash.

SLC flash tends to perform better in embedded applications.  For example wear leveling remaps occurs more frequently for MLC flash since each cell has a lower maximum number of write cycles.

A comment on bus speed. 

The Teensy uses 1-bit wide SPI at 24 MHz.

Common Version 2.0 SD and SDHC cards support the 4-bit SD bus at 50 MHz.  This is about eight times the bandwidth that Teensy has.
882  Using Arduino / Storage / Re: New SdFat optimized for Mega and Teensy 3.0 on: October 22, 2012, 04:48:48 pm

I was able to try 16-bit frames.  The write rate increased from 1776.44 KB/sec to 2013.34 KB/sec.

The overhead is increased since a byte swap is required.  I form the 16-bit word to be sent like this:

    uint16_t w = *src++ << 8;
    w |= *src++;
883  Using Arduino / Storage / Re: New SdFat optimized for Mega and Teensy 3.0 on: October 22, 2012, 03:38:27 pm
I am using the FIFO on Teensy 3.0.

The maximum SPI frame size for the K20 is 16 bits, not 32 bits.

I have not tried 16 bit frames yet since the Freescale examples were a mess.  I suspect 16 bit frames could help a lot.

I plan to try DMA in the future.

The absolute limit for SPI at 24 MHz is 3000 KB/sec but I don't think I will get close to that for 4 KB writes, even with DMA.
884  Using Arduino / Storage / Re: New SdFat optimized for Mega and Teensy 3.0 on: October 22, 2012, 09:56:07 am

The SPI clock for SD.h on the Mega was 4 MHz.  The standard Arduino SD library has no option for SPI clock speed.

I did a test at 8 MHz with SD.h by editing the source for begin().  Doubling the SPI clock speed increased the write speed from 265.95 KB/sec to 376.29 KB/sec and the read speed from 314.07 KB/sec to 463.86 KB/sec.
File size 5MB
Buffer size 4096 bytes
Starting write test.  Please wait up to a minute
Write 376.29 KB/sec
Maximum latency: 78644 usec, Minimum Latency: 9808 usec, Avg Latency: 10873 usec

Starting read test.  Please wait up to a minute
Read 463.86 KB/sec
Maximum latency: 9940 usec, Minimum Latency: 8784 usec, Avg Latency: 8823 usec

The SPI clock speed for Mega was 8 MHz with the new version of SdFat.

The SPI clock speed for Teensy 3.0 was 24 MHz.

The key to high speed writes is to use a record size that is a multiple of 512 bytes.  This insures that very little data needs to be copied to the cache.  In these tests with the new SdFat, only directory entries and the FAT table need to be cached.

Using a record size that is a power of two increases performance slightly.  This insures that writes are aligned with file clusters.

It is very important to use a freshly formatted SD card so that a contiguous file is created.  SD cards perform very poorly for random writes since the internal flash for most cards have a very large page size.  The entire page must be rewritten to newly erased flash for a random write.

The new SdFat still has only one block of cache so overhead is dramatically increased if write data must be cached.  This means that the cache block must be used for both write data and the FAT table.

I am considering options to use more cache but this adds complexity and there is still the overhead of copying data to the cache.  Adding cache would not improve the above results but would help when record size is not a multiple of 512.
885  Using Arduino / Storage / New SdFat optimized for Mega and Teensy 3.0 on: October 21, 2012, 09:33:59 am
I have posted a new SdFat beta -

This beta supports AVR boards and the new ARM Teensy 3.0 board

Performance is greatly improved for large reads and writes. 

The following benchmarks were done using this ATP 1GB Industrial Grade SD card

The results are in increasing order of performance.

Mega 2560 using the standard Arduino SD.h library with 4096 byte reads and writes.
File size 5MB
Buffer size 4096 bytes
Starting write test.  Please wait up to a minute
Write 265.95 KB/sec
Maximum latency: 84184 usec, Minimum Latency: 14144 usec, Avg Latency: 15388 usec

Starting read test.  Please wait up to a minute
Read 314.07 KB/sec
Maximum latency: 14752 usec, Minimum Latency: 13020 usec, Avg Latency: 13035 usec

Mega 2560 using the new SdFat library with 4096 byte reads and writes.
File size 5MB
Buffer size 4096 bytes
Starting write test.  Please wait up to a minute
Write 658.38 KB/sec
Maximum latency: 65816 usec, Minimum Latency: 6036 usec, Avg Latency: 6210 usec

Starting read test.  Please wait up to a minute
Read 616.40 KB/sec
Maximum latency: 7624 usec, Minimum Latency: 6628 usec, Avg Latency: 6638 usec

Teensy 3.0 at 96 MHz using the new SdFat library with 4096 byte reads and writes.
File size 5MB
Buffer size 4096 bytes
Starting write test.  Please wait up to a minute
Write 1776.44 KB/sec
Maximum latency: 65790 usec, Minimum Latency: 2146 usec, Avg Latency: 2300 usec

Starting read test.  Please wait up to a minute
Read 2037.15 KB/sec
Maximum latency: 2356 usec, Minimum Latency: 1999 usec, Avg Latency: 2008 usec

Here is my best Teensy 3.0 result using an old Corsair 1GB SD (no longer available) with 8192 byte reads and writes.
File size 10MB
Buffer size 8192 bytes
Starting write test.  Please wait up to a minute
Write 2002.05 KB/sec
Maximum latency: 6777 usec, Minimum Latency: 4007 usec, Avg Latency: 4089 usec

Starting read test.  Please wait up to a minute
Read 2121.47 KB/sec
Maximum latency: 4231 usec, Minimum Latency: 3853 usec, Avg Latency: 3860 usec
Pages: 1 ... 57 58 [59] 60 61 ... 112