Compare commits
4 Commits
stack-debu
...
atmega8u2
| Author | SHA1 | Date | |
|---|---|---|---|
| 13cd30069d | |||
| 1a780ac319 | |||
| 71d0b686d0 | |||
| 15806b6571 |
12
Makefile
12
Makefile
@@ -1,6 +1,6 @@
|
||||
MCU = atmega32u2
|
||||
MCU = atmega8u2
|
||||
ARCH = AVR8
|
||||
BOARD = MINIMUS
|
||||
BOARD = USER
|
||||
F_CPU = 16000000
|
||||
F_USB = 16000000
|
||||
OPTIMIZATION = s
|
||||
@@ -13,7 +13,6 @@ SRC = \
|
||||
main.c \
|
||||
ftdi.c \
|
||||
reset.c \
|
||||
stack.c \
|
||||
$(LUFA_SRC_USB)
|
||||
|
||||
# Default target
|
||||
@@ -29,6 +28,10 @@ term:
|
||||
python terminal.py $(DEVICE)
|
||||
.PHONY: term
|
||||
|
||||
AVRDUDE_PROGRAMMER := buspirate
|
||||
AVRDUDE_PORT := /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AH00S82Y-if00-port0
|
||||
AVRDUDE_FLAGS := -V
|
||||
|
||||
# Include LUFA build script makefiles
|
||||
include $(LUFA_PATH)/Build/lufa_sources.mk
|
||||
include $(LUFA_PATH)/Build/lufa_build.mk
|
||||
@@ -42,3 +45,6 @@ $(LUFA_PATH)/Build/lufa_core.mk:
|
||||
|
||||
# Remove some stuff from BASE_CC_FLAGS that the LUFA core put in there.
|
||||
BASE_CC_FLAGS := $(filter-out -fno-inline-small-functions,$(BASE_CC_FLAGS))
|
||||
|
||||
prog: main.hex
|
||||
avrdude -p atmega8u2 -P /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AH00S82Y-if00-port0 -c buspirate -V -U flash:w:main.hex
|
||||
|
||||
6
main.c
6
main.c
@@ -9,7 +9,6 @@
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "ftdi.h"
|
||||
#include "stack.h"
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
@@ -37,10 +36,7 @@ int main(void)
|
||||
c = getchar();
|
||||
/* If FTDI_NONBLOCKING was provided to ftdi_init,
|
||||
c will be -1 if no data was available. */
|
||||
if (c >= 0) {
|
||||
if (c >= 0)
|
||||
printf("You sent %d (%c)\n", c, isprint(c) ? c : '?');
|
||||
printf("Maximum stack space used: %d / %d bytes\n",
|
||||
(stack_total() - stack_min()), stack_total());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
46
stack.c
46
stack.c
@@ -1,46 +0,0 @@
|
||||
#include "stack.h"
|
||||
#include <stdint.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
extern uint8_t _end;
|
||||
extern uint8_t __stack;
|
||||
|
||||
void __stack_canary_init(void)
|
||||
__attribute__ ((naked))
|
||||
__attribute__ ((section (".init1")));
|
||||
void __stack_canary_init(void)
|
||||
{
|
||||
__asm volatile (" ldi r30,lo8(_end)\n"
|
||||
" ldi r31,hi8(_end)\n"
|
||||
" ldi r24,lo8(0xaa)\n" // canary
|
||||
" ldi r25,hi8(__stack)\n"
|
||||
" rjmp 2f\n"
|
||||
"1:\n"
|
||||
" wdr\n"
|
||||
" st Z+,r24\n"
|
||||
"2:\n"
|
||||
" cpi r30,lo8(__stack)\n"
|
||||
" cpc r31,r25\n"
|
||||
" brlo 1b\n"
|
||||
" breq 1b"
|
||||
:
|
||||
:
|
||||
: "memory");
|
||||
}
|
||||
|
||||
/* return low level mark of free stack space */
|
||||
uint16_t stack_min(void)
|
||||
{
|
||||
const uint8_t *p;
|
||||
uint16_t c = 0;
|
||||
|
||||
for (p = &_end; *p == 0xaa && p <= &__stack; p++)
|
||||
c++;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* return total amount of stack */
|
||||
uint16_t stack_total(void)
|
||||
{
|
||||
return &__stack - &_end;
|
||||
}
|
||||
Reference in New Issue
Block a user