Skip to content

Commit a2e64e6

Browse files
Parallel parking working code
0 parents  commit a2e64e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3796
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
arch/
2+
3+
*.o
4+
*.d
5+
*.elf
6+
*.bin
7+
*.map
8+
*.srec

Autonomous_Parallel_Parking/.DS_Store

8 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/***************************************************************************************************************
2+
3+
Authors: Harikrishnan G Nair
4+
Denny Mathews
5+
John Vasquez
6+
Steven Pill
7+
Harish Puvvada
8+
Description: This is the file that contains the applicaiton source code. More coming up!!
9+
*****************************************************************************************************************
10+
Copyright © 2017 Harikrishnan G Nair, Denny Mathews, John Vasquez, Steven Pill, Harish Puvvada @ NYU
11+
****************************************************************************************************************/
12+
13+
// C standard include(s):
14+
#include <math.h>
15+
#include <stdio.h>
16+
17+
// Custom user APIs needed for hardware access specific to this board:
18+
#include "cpu.h"
19+
#include "interrupts.h"
20+
#include "uart.h"
21+
#include <stdio.h>
22+
#include "motion.h"
23+
#include "state_machine.h"
24+
#include "sensor_timer.h"
25+
#include "pwm_hal.h"
26+
#include "encoder.h"
27+
// Custom user APIs needed for generic algorithmic libraries that are hardware-independent:
28+
#include "foo.h"
29+
30+
int main()
31+
{
32+
/*
33+
Initialize the PLL, clock tree to all peripherals, flash and Systick 1 ms time reference:
34+
*/
35+
cpu_init();
36+
encoders_init();
37+
38+
uart_debug_init();
39+
//GPIOInterruptSetup();
40+
printf("Before Sensor\n\r");
41+
42+
init_sensor();
43+
printf("After Sensor\n\r");
44+
state_init();
45+
printf("After Sensor2\n\r");
46+
47+
48+
//Set PE8, blue LED
49+
Pin_Set(GPIOE, GPIO_PIN_8, GPIO_MODE_OUTPUT_PP, GPIO_PULLDOWN, GPIO_SPEED_FREQ_LOW);
50+
Pin_Set(GPIOE, GPIO_PIN_9, GPIO_MODE_OUTPUT_PP, GPIO_PULLDOWN, GPIO_SPEED_FREQ_LOW);
51+
printf("After LED3\n\r");
52+
53+
/*
54+
Initialize the PWM outputs by configuring the corresponding channels
55+
*/
56+
init_pwm();
57+
58+
/*
59+
Test a series of movements:
60+
*/
61+
62+
int i = 0;
63+
uint8_t next_dir;
64+
while(1)
65+
{
66+
//printf("IN while\n\r");
67+
68+
/*
69+
Carry out a simple unit test of foo() declared in foo.h:
70+
*/
71+
if(TEST_FOO(i, i+1) < 0)
72+
{
73+
/*
74+
If the above fails there is either a hardware, code or other undefined error.
75+
Now we're in an undefined state regarding processor core behavior...
76+
*/
77+
while(1); // We probably have had a radiation hit or a major malfunction on the ALU of the processor...
78+
}
79+
else
80+
{
81+
// move_robot(STOP);
82+
//cpu_sw_delay(10U);
83+
84+
// printf("IN FORWARD\n\r");
85+
86+
next_dir = state_execute();
87+
move_robot(next_dir);
88+
//print_all();
89+
//cpu_sw_delay(10U);
90+
91+
92+
//trigger_sensor(sensor_front) ;
93+
94+
// cpu_sw_delay(10U);
95+
// if (g_inches_f < 20)
96+
// move_back();
97+
// cpu_sw_delay(500U);
98+
// turn_f_right();
99+
// cpu_sw_delay(500U);
100+
// turn_f_left();
101+
// cpu_sw_delay(500U);
102+
// brake();
103+
// cpu_sw_delay(500U);
104+
105+
}
106+
}
107+
108+
return 0;
109+
}

Autonomous_Parallel_Parking/Makefile

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Based on https://github.com/sergioprado/bare-metal-arm/blob/master/Makefile
2+
# But heavily-edited for our purposes:
3+
# (c) Abhimanyu Ghosh, 2016
4+
TOOLCHAIN_ROOT=../../../../gcc-arm-none-eabi-5_4-2016q3
5+
TOOLCHAIN=$(TOOLCHAIN_ROOT)/bin/
6+
PREFIX=$(TOOLCHAIN)/arm-none-eabi-
7+
8+
ARCHFLAGS=-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -I$(TOOLCHAIN_ROOT)/arm-none-eabi/include -fsingle-precision-constant
9+
CFLAGS=-nostdlib -I../arch/stm32/f3/inc/ -I../arch/stm32/f3/inc/CMSIS -I../arch/stm32/f3/inc/Legacy -I./user_include -I./user_include/hal_interface -g -O2 -Wall
10+
LDFLAGS=--specs=nosys.specs -Wl,--gc-sections,-Map,$(TARGET).map,-Tlinker.ld
11+
LDFLAGS+=$(ARCHFLAGS)
12+
13+
CC=$(PREFIX)gcc
14+
LD=$(PREFIX)gcc
15+
OBJCOPY=$(PREFIX)objcopy
16+
SIZE=$(PREFIX)size
17+
RM=rm -f
18+
19+
TARGET=Autonomous_Parallel_Parking
20+
21+
SRC=$(wildcard ../arch/stm32/f3/src/*.c)
22+
SRC+=$(wildcard ../arch/stm32/f3/src/CMSIS/*.c)
23+
ASM_SRC=$(wildcard ../arch/stm32/f3/src/*.s)
24+
ASM_SRC+=$(wildcard ../arch/stm32/f3/src/CMSIS/*.s)
25+
USER_SRC=$(wildcard user_source/*.c)
26+
USER_SRC+=$(wildcard user_source/hal_interface/*.c)
27+
USER_ASM_SRC=$(wildcard user_source/*.s)
28+
29+
OBJ=$(patsubst %.c, %.o, $(SRC))
30+
ASM_OBJS=$(patsubst %.s, %.o, $(ASM_SRC))
31+
TARGET_OBJ=$(TARGET).o
32+
USER_OBJ=$(patsubst %.c, %.o, $(USER_SRC))
33+
USER_ASM_OBJ=$(patsubst %.s, %.o, $(USER_ASM_SRC))
34+
35+
DEPS:=$(OBJ:.o=.d)
36+
DEPS+=$(TARGET_OBJ:.o=.d)
37+
DEPS+=$(USER_OBJ:.o=.d)
38+
39+
all: build size
40+
build: elf srec bin
41+
elf: $(TARGET).elf
42+
srec: $(TARGET).srec
43+
bin: $(TARGET).bin
44+
md5sums: all
45+
md5sum $(TARGET).elf > user_app_md5sum
46+
check: all
47+
md5sum $(TARGET).elf > tmp && diff tmp user_app_md5sum && rm tmp
48+
load: all
49+
./load_fw.sh $(TOOLCHAIN)
50+
51+
clean:
52+
$(RM) $(TARGET).srec $(TARGET).elf $(TARGET).bin $(TARGET).map $(OBJ) $(ASM_OBJS) $(USER_ASM_OBJ) $(TARGET_OBJ) $(USER_OBJ) $(DEPS)
53+
54+
$(TARGET).elf: $(ASM_OBJS) $(USER_ASM_OBJ) $(OBJ) $(TARGET_OBJ) $(USER_OBJ)
55+
$(LD) $(LDFLAGS) -o $@ $(OBJ) $(ASM_OBJS) $(USER_ASM_OBJ) $(TARGET_OBJ) $(USER_OBJ) -lm -lc
56+
57+
%.o: %.s
58+
$(CC) -c $(ARCHFLAGS) $(CFLAGS) -o $@ $<
59+
60+
-include $(DEPS)
61+
62+
%.o: %.c
63+
$(CC) $(ARCHFLAGS) $(CFLAGS) -MM -MT $@ -MF $(patsubst %.o,%.d,$@) $<
64+
$(CC) $(ARCHFLAGS) $(CFLAGS) -c -o $@ $<
65+
66+
%.srec: %.elf
67+
$(OBJCOPY) -O srec $< $@
68+
69+
%.bin: %.elf
70+
$(OBJCOPY) -O binary $< $@
71+
72+
size: $(TARGET).elf
73+
$(SIZE) $(TARGET).elf
74+
75+
.PHONY: clean

Autonomous_Parallel_Parking/linker.ld

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/* Entry Point = reset NMI handler */
2+
ENTRY(Reset_Handler)
3+
4+
/* Top of stack */
5+
_estack = 0x2000a000; /* RAM end */
6+
7+
/* Generate a link error if heap and stack don't fit into RAM */
8+
_Min_Heap_Size = 0x200; /* required amount of heap */
9+
_Min_Stack_Size = 0x400; /* required amount of stack */
10+
11+
/* Definition of Flash and RAM layout: */
12+
MEMORY
13+
{
14+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K
15+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 40K
16+
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 8K
17+
}
18+
19+
/* Section definitions: */
20+
SECTIONS
21+
{
22+
/* The startup code goes into beginning of FLASH */
23+
.isr_vector :
24+
{
25+
. = ALIGN(4);
26+
KEEP(*(.isr_vector)) /* Startup code */
27+
. = ALIGN(4);
28+
} >FLASH
29+
30+
.text :
31+
{
32+
. = ALIGN(4);
33+
*(.text)
34+
*(.text*)
35+
*(.glue_7)
36+
*(.glue_7t)
37+
*(.eh_frame)
38+
39+
KEEP (*(.init))
40+
KEEP (*(.fini))
41+
42+
. = ALIGN(4);
43+
_etext = .;
44+
} >FLASH
45+
46+
/* Constants go in flash */
47+
.rodata :
48+
{
49+
. = ALIGN(4);
50+
*(.rodata)
51+
*(.rodata*)
52+
. = ALIGN(4);
53+
} >FLASH
54+
55+
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
56+
.ARM : {
57+
__exidx_start = .;
58+
*(.ARM.exidx*)
59+
__exidx_end = .;
60+
} >FLASH
61+
62+
.preinit_array :
63+
{
64+
PROVIDE_HIDDEN (__preinit_array_start = .);
65+
KEEP (*(.preinit_array*))
66+
PROVIDE_HIDDEN (__preinit_array_end = .);
67+
} >FLASH
68+
.init_array :
69+
{
70+
PROVIDE_HIDDEN (__init_array_start = .);
71+
KEEP (*(SORT(.init_array.*)))
72+
KEEP (*(.init_array*))
73+
PROVIDE_HIDDEN (__init_array_end = .);
74+
} >FLASH
75+
.fini_array :
76+
{
77+
PROVIDE_HIDDEN (__fini_array_start = .);
78+
KEEP (*(SORT(.fini_array.*)))
79+
KEEP (*(.fini_array*))
80+
PROVIDE_HIDDEN (__fini_array_end = .);
81+
} >FLASH
82+
83+
/* used by the startup to initialize data */
84+
_sidata = LOADADDR(.data);
85+
86+
/* Initialized data sections goes into RAM, load LMA copy after code */
87+
.data :
88+
{
89+
. = ALIGN(4);
90+
_sdata = .;
91+
*(.data)
92+
*(.data*)
93+
94+
. = ALIGN(4);
95+
_edata = .;
96+
} >RAM AT> FLASH
97+
98+
_siccmram = LOADADDR(.ccmram);
99+
100+
.ccmram :
101+
{
102+
. = ALIGN(4);
103+
_sccmram = .;
104+
*(.ccmram)
105+
*(.ccmram*)
106+
107+
. = ALIGN(4);
108+
_eccmram = .;
109+
} >CCMRAM AT> FLASH
110+
111+
112+
/* Uninitialized data section */
113+
. = ALIGN(4);
114+
.bss :
115+
{
116+
/* .bss init section */
117+
_sbss = .;
118+
__bss_start__ = _sbss;
119+
*(.bss)
120+
*(.bss*)
121+
*(COMMON)
122+
123+
. = ALIGN(4);
124+
_ebss = .;
125+
__bss_end__ = _ebss;
126+
} >RAM
127+
128+
._user_heap_stack :
129+
{
130+
. = ALIGN(4);
131+
PROVIDE ( end = . );
132+
PROVIDE ( _end = . );
133+
. = . + _Min_Heap_Size;
134+
. = . + _Min_Stack_Size;
135+
. = ALIGN(4);
136+
} >RAM
137+
138+
/DISCARD/ :
139+
{
140+
libc.a ( * )
141+
libm.a ( * )
142+
libgcc.a ( * )
143+
}
144+
145+
.ARM.attributes 0 : { *(.ARM.attributes) }
146+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
openocd -f ./stm32f3discovery.cfg &
3+
sleep 2
4+
$1/arm-none-eabi-gdb --batch --command=runme.gdb
5+
echo "Killing OpenOCD..."
6+
pkill openocd
7+
echo "Done."

Autonomous_Parallel_Parking/proj_name

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Autonomous_Parallel_Parking

Autonomous_Parallel_Parking/runme.gdb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target remote localhost:3333
2+
monitor reset halt
3+
load Autonomous_Parallel_Parking.elf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This is an STM32F3 discovery board with a single STM32F303VCT6 chip.
2+
# http://www.st.com/internet/evalboard/product/254044.jsp
3+
4+
source [find interface/stlink-v2.cfg]
5+
6+
source [find target/stm32f3x_stlink.cfg]
7+
8+
# use hardware reset, connect under reset
9+
reset_config srst_only srst_nogate connect_assert_srst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
048904b8462c4e0f799c16a4d406b793 f3_basic_app.elf

0 commit comments

Comments
 (0)