[Troubleshooting] Can't get the FatFs R0.13 example running on my Atmega32

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Edit: Ha! Finally works.

 

Intended post:

 

Hello everyone,

I am trying to adapt the AVR example from the latest FatFS R0.13 version from May 21, 2017 to get it working on my Atmega32.

 

The idea was to figure out how to use it and then to reduce it to the parts that I need to write some data on a SD card.

 

The Atmega32 itself works fine and sits on a small development/test board.

 

I wasn't sure if I should post this in the FatFS [TUT] thread or to create a thread for my specific problem. I didn't want to clog the

 

With that build, a few things have changed compared to the older release I found, which was based on R0.11 from May 13, 2015 and some of the sample code was stripped away and replaced with "To be filled" notes. I checked the old R0.11 version to see what code is expected in these spots and tried to fill them.

I adjusted the UART module, the timer and interrupt, removed the sound.c file and made some adjustments to the rtc_ds1338.c, as I don't want to use a RTC for the example as of now.

 

My project (attached as zip file) contains the following files from the example:

diskio.c/.h ; ff.c/.h ; ffconf.h ; main.c ; mmc_avr.h ; mmc_avr_spi.c ; rtc.h ; rtc_ds1338.c ; uart.c/.h ; xitoa.s/.h

 

So far the code compiles without any errors and barely fit into the Atmega32.

Program Memory Usage       :      28308 bytes   86,4 % Full

Data Memory Usage          :      1971 bytes   96,2 % Full

 

The idea was to use the example for getting a grasp on the  different functions and then to implement the parts that I need into another project based on the same hardware:

 

Atmega32 with 14,7456MHz crystal , programmed with Atmel Studio 6.2 and GCC

SD Card Shield with a LVC125A as level shifter (looks like this)

Length of wires between SD module and MCU: 20cm (later on it will be put on the same PCB)

 

Pin connection between SD module and MCU:
CS       <->      SS (PB4)

SCK    <->      SCK (PB7)

MOSI  <->      MOSI (PB5)

MISO  <->      MISO (PB6)

VCC   <->      VCC

GND   <->      GND

 

SD Card:    Sandisk 8GB µSDHC, FAT32, Volume "CARD1"

                  

Formatted with Tuxera SD Card Formatter 5

Sending commands via UART with Termite 3.3

 

 

 

 

My current problem:

The UART communication works and I get the initial message, but when I transmit a letter to use the menu it only sends that letter back with the get_line function. The whole program interface doesn't show up. When I send a "command", the letter d for example, only that letter gets returned. (and a 3 from one of the if conditions inside the get_line function)

 

If I send a \r or a \b to the controller, it outputs each individual character with a 3 behind it  instead of going into the if-conditions.

 

I have a feeling that I made some fundamental mistake or missed something, but I don't see what.

 

One thing I am nott sure about is the DRV_MMC definition. What does it have to look like and where does it go? It wasn't in the R0.11 example since the whole diskio.c didn't exist back then and I assume I won't need it in the final program since I don't use a CFC. But for now, I wanted to leave the diskio.c in the project.

 

If I define DRV_MMC as 1 and put it in the diskio.h, the program loops around the ioinit function.

If I put it in mmc_avr.h, it isn't seen by the main.c. (xprintf(PSTR("MMC ==> %u\n"), DRV_MMC); in line 261 isnt executed)

 

The general I/O settings are in the ioinit function in the main.c.
The macros and SPI settings are in the power_on / power_off functions in the mmc_avr_spi.c.

 

Maybe someone could take a look at this and give me a few hints or ideas to help me with troubleshooting the problem? That would be nice. smiley

 

If I forgot some information, please let me know.

Attachment(s): 

Last Edited: Sat. Sep 16, 2017 - 02:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My suspicion is that "Data Memory Usage : 1971 bytes 96,2 % Full" is the problem.
Change FIL File[2]; to FIL File[1]; and temporarily comment-out/remove the 'x' command.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did that, now it's down to "Data Memory Usage   : 1937 bytes   94,6 % Full" but still shows the same behaviour.

 

Edit: Forgot to reduce the FATFS FatFs[] from 2 to 1.

Program Memory Usage   :  27584 bytes   84,2 % Full
Data Memory Usage    :  1374 bytes   67,1 % Full

 

Now, when I type in "d", it returns "di". Edit 2: That was a mistake on my end, Termite input autocompleted "d" to "di" since I typed "di" once and I just didn't notice.

I'll try to strip down the main.c to get some basic functionality running.

 

Last Edited: Sat. Sep 16, 2017 - 08:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need the RAM % down below 80%, preferably 70%. The FatFs demo has a nasty habit of allocating FATFS structures that cost 568 bytes each. Ditch the use of all but one.
.
In fact I'd ditch their entire main() and just write something that mounts, opens then reads.
.
To reduce Flash drop LFN and hence the code page stuff.

Last Edited: Sat. Sep 16, 2017 - 02:10 PM