| Author |
Message |
|
|
Posted: Dec 10, 2010 - 08:49 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
With the help of this tutorial by Kubark42, http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=66846&start=0&postdays=0&postorder=asc&highlight=data+logging
I got fatfs to compile. However:
Code:
Program: 48800 bytes (148.9% Full)
(.text + .data + .bootloader)
Data: 2861 bytes (139.7% Full)
(.data + .bss + .noinit)
The ATmega324p has 32k flash, 2k sram, and 1k eeprom.
This is the makefile:
Code:
TARGET = avr_mmc
CSRC = main.c uart.c ff.c mmc.c rtc.c cc932_avr.c
ASRC = xitoa.S
MCU_TARGET = atmega324p
OPTIMIZE = -Os -mcall-prologues
DEFS =
LIBS =
DEBUG = dwarf-2
CC = avr-gcc
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
ALL_ASFLAGS = -mmcu=$(MCU_TARGET) -I. -x assembler-with-cpp $(ASFLAGS)
CFLAGS = -Wall -g$(DEBUG) $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
LDFLAGS = -Wl,-Map,$(TARGET).map
OBJ = $(CSRC:.c=.o) $(ASRC:.S=.o)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
all: $(TARGET).elf lst text size
$(TARGET).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
clean:
rm -rf *.o $(TARGET).elf *.eps *.bak *.a
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
rm -rf $(TARGET).hex
size: $(TARGET).elf
$(SIZE) -C --mcu=$(MCU_TARGET) $(TARGET).elf
lst: $(TARGET).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.o : %.S
$(CC) -c $(ALL_ASFLAGS) $< -o $@
text: hex
hex: $(TARGET).hex
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
I downloaded the petite version, but before I start preparing it, maybe someone could help me shoehorn this in. I usually use AVR Studio 4, so I've never looked at makefiles before. This time I used 'programmer's notepad. So the flags are new to me.
Thanks |
|
|
| |
|
|
|
|
|
Posted: Dec 10, 2010 - 08:51 PM |
|


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| See a recent thread where we modified PetitFS from using USI on the Tiny85 to produce a working template that uses SPI and would be suitable for 324P. It compiles to well under 8K. |
_________________
|
| |
|
|
|
|
|
Posted: Dec 10, 2010 - 09:22 PM |
|


Joined: Feb 19, 2001
Posts: 25904
Location: Wisconsin USA
|
|
|
Quote:
It compiles to well under 8K.
And TinyFatFs is also around 8k, read+write.
I'd suggest that you look at your configuration file and the selected options. But even fully-loaded I wouldn't think it would be 32k of code space for the "monitor" demo.
And you obviously cannot have as many buffers as you specified and still use the same class of AVR--2k+!!!. Four buffers plus the internal one? |
|
|
| |
|
|
|
|
|
Posted: Dec 10, 2010 - 09:54 PM |
|


Joined: Mar 28, 2001
Posts: 20355
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
You will need to see what you don't need like RTC or other functions. Petitfs is a stripped down version. So you either accept the limitation of Petitfs or a cut down version of fatfs or get a larger chip.
edit by the way with Petitfs I had to remove the WRITE function to get it just under 8K (7374 bytes)to use with a M88 otherwise it's almost 9K (8808 bytes). I guess another version of winAvr (or a more expensive compiler... ) could get it under 8K. |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Dec 11, 2010 - 12:26 AM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
I downloaded clawson's download package from:
[url]http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=100182&highlight=tiny85 [/url]
and it compiled to:
Code:
avr-objcopy -j .text -j .data -O ihex pfftest.elf pfftest.hex
avr-size -C --mcu=atmega324p pfftest.elf
AVR Memory Usage
----------------
Device: atmega324p
Program: 4022 bytes (12.3% Full)
(.text + .data + .bootloader)
Data: 145 bytes (7.1% Full)
(.data + .bss + .noinit)
I have yet to attach an sd to the chip. Can one troubleshoot this or at least find out if it's working using a terminal? |
|
|
| |
|
|
|
|
|
Posted: Dec 11, 2010 - 02:09 AM |
|


Joined: Mar 28, 2001
Posts: 20355
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
|
|
|
|
|
Posted: Dec 11, 2010 - 12:15 PM |
|


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Also note that my download WON'T WORK. You need to read the complete thread and you'll see the point where John spotted my SPCR/SPSR error.
BTW for normal use you would want to ditch the "monitor" (especially if trying to shoe-horn the code into a bootloader section). So the 4K probably is the "cost" for using PetitFs functions in your code.
Cliff |
_________________
|
| |
|
|
|
|
|
Posted: Dec 11, 2010 - 03:33 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
Well. clawson and js you guys are just terrific (and also because of your responses)
I still can't get anything on the terminal, but I'll keep messing around.
I just wanted to voice my appreciation. As a beginner you've saved me a lot of time and frustration. |
|
|
| |
|
|
|
|
|
Posted: Dec 11, 2010 - 09:21 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
I'm unable to get any response on a terminal. I beleive "di" or "fi" should get a response, right?
js's 'sample monitor commands came unformatted and I find it difficult to understand them. Is ">" required? Are all the commands 2 char? Is there a response?
Where is this documented? thanks |
|
|
| |
|
|
|
|
|
Posted: Dec 11, 2010 - 09:25 PM |
|


Joined: Feb 19, 2001
Posts: 25904
Location: Wisconsin USA
|
|
Didja ever think that if you don't see the prompt character, that your comms aren't set up correctly?
And surely if you are gong to build an advanced app--and I'd call an SD app to be well above "newbie" level--then you should be able to decipher the monitor main loop.
When you put out Hello World to your monitoring terminal at the beginning of the app, what do you get? |
|
|
| |
|
|
|
|
|
Posted: Dec 11, 2010 - 09:41 PM |
|


Joined: Mar 28, 2001
Posts: 20355
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
|
Quote:
monitor commands came unformatted
I just used Notepad, so download the file and open it with Notepad.
Quote:
Is ">" required?
That's the system's prompt, if you don't get it then there is no comms.
Is your RS232 driver chip connected to USART0? Did you change the clock to suit your system? If you tell us more about your setup then we can help a bit more. |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Dec 12, 2010 - 12:24 AM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
Here are the changes I've made:
In mmc.c:
Code:
// Port Controls (Platform dependent)
//changed for atmega324p
#define SELECT() PORTB &= ~0x10 // MMC CS = L
#define DESELECT() PORTB |= 0x10 // MMC CS = H
#define MMC_SEL !(PORTB & 0x10) // MMC CS status (true:selected)
In main.c:
Code:
#define SYSCLK 20000000UL
//Modified to run on atmega324p at 20Mhz
PORTB = 0b00010000; // SS high
DDRB = 0b10110000; // !SS,SCK and MOSI outputs
//Modified to use USART0 pins
PORTD = 0xff; // all pullup
DDRD = 0b00000010; // PD1 outputs
spi.c seemed alright the way it was:
Code:
BYTE xmit_spi(BYTE c) {
SPDR = c;
while (!(SPSR & (1<<SPIF)));
return SPDR;
}
//-----------------------------------------------------------------------
// Receive a byte from MMC via SPI (Platform dependent)
//-----------------------------------------------------------------------
BYTE rcv_spi(void) {
return xmit_spi(0xFF);
}
I assume suast.s is in assembler which I'm unfamiliar with, but it looked alright. Thanks
edit:yes I'm using USART0 |
|
|
| |
|
|
|
|
|
Posted: Dec 12, 2010 - 07:02 AM |
|


Joined: Mar 28, 2001
Posts: 20355
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
|
Quote:
but it looked alright
But it isn't. you need to change the delay. This needs to change to say 172 for 38.4kbps for 20MHz
Code:
; Bit rate settings:
;
; 1MHz 2MHz 4MHz 6MHz 8MHz 10MHz 12MHz 16MHz 20MHz
; 2.4kbps 138 - - - - - - - -
; 4.8kbps 68 138 - - - - - - -
; 9.6kbps 33 68 138 208 - - - - -
; 19.2kbps - 33 68 102 138 173 208 - -
; 38.4kbps - - 33 50 68 85 102 138 172
; 57.6kbps - - 21 33 44 56 68 91 114
; 115.2kbps - - - - 21 27 33 44 56
.nolist
#include <avr/io.h>
.list
// Modified to run on Ampertronics CONT-3 With M64 at 16MHz
// The comms is duplex,38.4kbps, but there is no echo and local
// echo needs to be enabled on the terminal.
// This code uses the same pins as USART0
#define BPS 172 // Was 138 Bit delay. (see above table)
you also need to change PORTE/PINE to PORTD/PIND (if you are using the M64 code)
Code:
#define OUT_0 cbi _SFR_IO_ADDR(PORTD), 1 // Output 0
#define OUT_1 sbi _SFR_IO_ADDR(PORTD), 1 // Output 1
#define SKIP_IN_1 sbis _SFR_IO_ADDR(PIND), 0 // Skip if 1
#define SKIP_IN_0 sbic _SFR_IO_ADDR(PIND), 0 // Skip if 0
|
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Dec 12, 2010 - 02:50 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
I've been combing the code to find out why the terminal (realterm) isn't receiving anything.
I searched for "UDR0" in the folder containing all the files thinking that the i/o data register would be referenced if USART0 was being used and I could find no instance of it. |
|
|
| |
|
|
|
|
|
Posted: Dec 12, 2010 - 05:49 PM |
|


Joined: Feb 19, 2001
Posts: 25904
Location: Wisconsin USA
|
|
|
Quote:
I searched for "UDR0" in the folder containing all the files thinking that the i/o data register would be referenced if USART0 was being used and I could find no instance of it.
I thought you were working with the Tiny85 version as a base. Does the Tiny85 have a UART?
I'm out. |
|
|
| |
|
|
|
|
|
Posted: Dec 12, 2010 - 06:03 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
I'm using a Gator board from Rugged Circuits which has an atmega324p running at 20Mhz.
Unfortunately not all the pins are brought out. Like
RXD0 and TXD0, PD0 and PD1 respectively.
edit: they are pre-wired through a USB port. That all works as I've set up USART0 and communicated to a terminal with it.
In the title of suart.s is the description:
Quote:
Software implemented UART module
so maybe it doesn't use the UDR0 but writes directly to the pins.
I assume this sets up the pins in assembler:
Code:
#define OUT_0 cbi _SFR_IO_ADDR(PORTD), 1 // Output 0
#define OUT_1 sbi _SFR_IO_ADDR(PORTD), 1 // Output 1
#define SKIP_IN_1 sbis _SFR_IO_ADDR(PIND), 0 // Skip if 1
#define SKIP_IN_0 sbic _SFR_IO_ADDR(PIND), 0 // Skip if 0
does this look alright for
PD0 & PD1?
edit: I tried changing this to (PIND), 2 and (PORTD), 3. Upon reset I got no signals on the o'scope. |
|
|
| |
|
|
|
|
|
Posted: Dec 12, 2010 - 09:03 PM |
|


Joined: Mar 28, 2001
Posts: 20355
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
suart.s (SOFTWARE UART) does not use the real USART but just the pins to make it easier for boards that have a RS232 connection like the ones I tested it on.
The example was left as original as possible therefore suart.s was left in.
If I get some time today I'll run it on the STK500 or another board with a Mega324. |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Dec 12, 2010 - 09:05 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
Thanks John
edit: yes, I have to use PD0 and PD1 as they are wired to the USB port on the Gator board. |
|
|
| |
|
|
|
|
|
Posted: Dec 12, 2010 - 09:47 PM |
|


Joined: Mar 28, 2001
Posts: 20355
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
| Ok it was easy enough to do it now as everything was hooked up to the STK500. It's using a M164p which is what I had around the bench (same pinout as the M324p) and running at 16MHz so you still need to change the bit rate setting as follows:
Code:
#define BPS 172 // Was 138 Bit delay. (see above table)
and the project setting (don't think it matters here but just in case) |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Dec 13, 2010 - 01:51 AM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
| It didn't work right off (I changed the SYSCLK and BPS) I'll look more closely tomorrow. Thanks for doing that John! |
|
|
| |
|
|
|
|
|
Posted: Dec 13, 2010 - 01:54 AM |
|


Joined: Mar 28, 2001
Posts: 20355
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
| You should start looking at your harware then. It should have worked even if you got rubbish on the screen because of the higher clock speed. |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Dec 15, 2010 - 09:07 AM |
|

Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca
|
|
|
Quote:
I downloaded the petite version, but before I start preparing it, maybe someone could help me shoehorn this in.
For your m324, look in the *.h that configures FF. In my version it's ffconf.h . Go down the list of options and choose what works for U. That knocks out plenty. For english users, for ex.
Code:
#define _CODE_PAGE 437
, does a body good. I know you're working on some tiny stuff, but it's also good to have a big gun rdy when you need it. Best for last, try these in your PN makefile for m324 :
put these in "compiler options" section:
Code:
CFLAGS += -fno-inline-small-functions
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -mcall-prologues
these in " linker options"
Code:
LDFLAGS += -Wl,--relax
LDFLAGS += -Wl,--gc-sections
|
_________________ 1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
|
| |
|
|
|
|
|
Posted: Dec 15, 2010 - 10:29 AM |
|


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
does a body good.
I think you'll find:
Code:
#define _CODE_PAGE 1
does the best job possible as long as you stick to ASCII filenames. This ditches the need for code page support all together (it's all about the characters 128..255 used in filenames - just avoid them) |
_________________
|
| |
|
|
|
|
|
Posted: Dec 15, 2010 - 10:55 AM |
|

Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca
|
|
|
Code:
#define _CODE_PAGE 1
You just saved me 130 bytes on my mp3 player, sir !!! Sweeter than honey sonnie !! |
_________________ 1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
|
| |
|
|
|
|
|
Posted: Dec 15, 2010 - 04:56 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
Thanks indianajones and clawson. I'll try to get petit fs working before trying what you suggest.
@js: I received this comment from Ryan Lush on the Rugged Circuits forum:
Quote:
if you are trying to receive over USB through the FTDI chip then the FTDI chip will be driving the RX pin appropriately.
So I'm trying to find where in the code the PD0 pin is referenced. I'm new at assembler but I'm learning.
I traced it back to suart.s. I don't see PD0 anywhere.
Code:
; Receive a byte
;
;Prototype: uint8_t rcvr (void);
;Size: 19 words
.global rcvr
.func rcvr
rcvr:
in r0, _SFR_IO_ADDR(SREG) ;Save flags
ldi r24, 0x80 ;Receiving shift reg
cli ;Start critical section
1: SKIP_IN_1 ;Wait for idle
rjmp 1b
2: SKIP_IN_0 ;Wait for start bit
rjmp 2b
ldi r25, BPS/2 ;Wait for half bit time
3: dec r25
brne 3b
4: ldi r25, BPS ;----- Bit receiving loop
5: dec r25 ;Wait for a bit time
brne 5b ;/
lsr r24 ;Next bit
SKIP_IN_0 ;Get a data bit into r24.7
ori r24, 0x80
brcc 4b ;All bits received? no, continue
out _SFR_IO_ADDR(SREG), r0 ;End of critical section
ret
.endfunc
EDIT Where's it rjmp ing to?(2b, 3b, 5b) |
Last edited by Gowan on Dec 15, 2010 - 08:25 PM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Dec 15, 2010 - 05:01 PM |
|


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
You need to find/show the SKIP_IN_1 macro. That's where the input pin is actually being read.
EDIT: found it myself:
Code:
D:\pfsample\avr>grep SKIP_IN *
suart.S:#define SKIP_IN_1 sbis _SFR_IO_ADDR(PINB), 4 /* Skip if 1 */
suart.S:#define SKIP_IN_0 sbic _SFR_IO_ADDR(PINB), 4 /* Skip if 0 */
suart.S:1: SKIP_IN_1 ;Wait for idle
suart.S:2: SKIP_IN_0 ;Wait for start bit
suart.S: SKIP_IN_0 ;Get a data bit into r24.7
So it's using PORTB pin 4 as the RX pin in this code.
But I just realised that the thread title say 324P so why not use the real UART rather than "bit banging" it with suart.S ? If you look at suart.h the only functions provided by suart.S are:
Code:
void xmit(uint8_t);
uint8_t rcvr();
So use a real UART and implement these yourself in C then drop suart.S from the list of files to be built (replaced by the .c file where you implement xmit() and rcvr() instead) |
_________________
|
| |
|
|
|
|
|
Posted: Dec 15, 2010 - 05:19 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
Sounds good, I'll try it.
EDIT: actually, I'm going to try to get this working. js sent me the code, and it should work.
Code:
#define OUT_0 cbi _SFR_IO_ADDR(PORTD), 1 // Output 0
#define OUT_1 sbi _SFR_IO_ADDR(PORTD), 1 // Output 1
#define SKIP_IN_1 sbis _SFR_IO_ADDR(PIND), 0 // Skip if 1
#define SKIP_IN_0 sbic _SFR_IO_ADDR(PIND), 0 // Skip if 0
This is fine. Using PD0 for input.
Code:
.global rcvr
.func rcvr
rcvr:
in r0, _SFR_IO_ADDR(SREG) ;Save flags
ldi r24, 0x80 ;Receiving shift reg
cli ;Start critical section
1: SKIP_IN_1 ;Wait for idle
rjmp 1b
2: SKIP_IN_0 ;Wait for start bit
rjmp 2b
ldi r25, BPS/2 ;Wait for half bit time
3: dec r25
brne 3b
4: ldi r25, BPS ;----- Bit receiving loop
5: dec r25 ;Wait for a bit time
brne 5b ;/
lsr r24 ;Next bit
SKIP_IN_0 ;Get a data bit into r24.7
ori r24, 0x80
brcc 4b ;All bits received? no, continue
out _SFR_IO_ADDR(SREG), r0 ;End of critical section
ret
.endfunc
Where is it rjmp 'ing and brne 'ing to? 3b,4b,5b? |
|
|
| |
|
|
|
|
|
Posted: Dec 15, 2010 - 11:30 PM |
|


Joined: Mar 28, 2001
Posts: 20355
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
The code I posted here http://www.avrfreaks.net/index.php?name ... 155#775155 IS RUNNING on the Mega164p which is pin compatible with the M324p.
The USART is NOT being used therefore no UDRx or anything, it is using the ORIGINAL bit banged uart code. |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Dec 16, 2010 - 09:29 AM |
|


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
Where is it rjmp 'ing and brne 'ing to? 3b,4b,5b?
The way GCC assembler local labels work is that you use 1:, 2:, 3: etc. Then to aid the assembler when you BRxx or RJMP to these labels you add 'f' or 'b' for 'forward' or 'backward' so in:
Code:
ldi r25, BPS/2 ;Wait for half bit time
3: dec r25
brne 3b
that's simply looping back to the '3:' label to implement a delay. |
_________________
|
| |
|
|
|
|
|
Posted: Dec 16, 2010 - 06:19 PM |
|

Joined: May 17, 2010
Posts: 49
Location: Nanaimo BC Canada
|
|
@clawson: Thanks for the education.
@John Samperi: well, it's probably been running just fine for awhile, I didn't have the wit to grok it.
I sprinkled a few xputc()'s and xputs()'s around and now I can see the flow.
Thanks John
Now I'll connect the SD card, add seven files to read the ADC,(using Dean's tutorial on modularizing c code) and, I suspect, be back here with a question or two.
Thanks to all who participated in this thread. |
|
|
| |
|
|
|
|
|