Skip to content

Commit 245c528

Browse files
phanrahanCS107E Bot
authored and
CS107E Bot
committed
Merge branch 'master' of github.com:cs107e/staff
commit 0bc873476dd0cbf60342cbebe862d04fa75f0f84 Merge: 6c1cd5d 2bde7dc Author: Pat Hanrahan <[email protected]> Date: Fri Feb 1 08:37:00 2019 -0800 Merge branch 'master' of github.com:cs107e/staff
1 parent ccdd180 commit 245c528

Some content is hidden

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

47 files changed

+1584
-1
lines changed

_data/unreleased.csv

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ permalink,title,released
1111
"/lectures/Interrupts2/","Interrupts, cont'd",false
1212
"/lectures/FloatingPoint/","Floating Point",false
1313
"/lectures/C-mastery/","C Mastery",false
14-
"/lectures/Linking/","Modules, Libraries, and Linking",false
1514
"/lectures/Sound/","Sound",false
1615
"/lectures/GitWorkflow/","Git Workflow",false
1716
"/lectures/Sensors/","Sensors",false

lectures/Linking/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
released: true
3+
permalink: /lectures/Linking/
4+
title: Modules, Libraries, and Linking
5+
readings: |
6+
+ Read David Welch's articles on [baremetal programming](https://github.com/dwelch67/raspberrypi/tree/master/baremetal) and [bss data](https://github.com/dwelch67/raspberrypi/tree/master/bssdata).
7+
---
8+
9+
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
APPLICATION = blink
2+
MODULES =
3+
4+
CFLAGS = -Og -Wall -std=c99 -ffreestanding -I$(CS107E)/include
5+
ASFLAGS = --warn --fatal-warnings
6+
LDFLAGS = -nostdlib -T memmap -L$(CS107E)/lib
7+
LDLIBS = -lpi
8+
9+
all : $(APPLICATION).bin
10+
11+
%.bin: %.elf
12+
arm-none-eabi-objcopy $< -O binary $@
13+
14+
%.elf: %.o $(MODULES) cstart.o start.o
15+
arm-none-eabi-ld $(LDFLAGS) $^ $(LDLIBS) -o $@
16+
17+
%.o: %.c
18+
arm-none-eabi-gcc $(CFLAGS) -c $< -o $@
19+
20+
%.o: %.s
21+
arm-none-eabi-as $(ASFLAGS) $< -o $@
22+
23+
install: $(APPLICATION).bin
24+
rpi-install.py $<
25+
26+
clean:
27+
rm -f *.bin *.elf *.o *.list *~
28+
29+
.PHONY: all clean install
30+
31+
.PRECIOUS: %.o %.elf
32+
33+
# empty recipe used to disable built-in rules for native build
34+
%:%.c
35+
%:%.o
36+
%:%.s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Demonstrates how to link to cs107e libpi
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "gpio.h"
2+
#include "timer.h"
3+
4+
void main() {
5+
6+
gpio_init();
7+
timer_init();
8+
9+
gpio_set_function(GPIO_PIN20, GPIO_FUNC_OUTPUT);
10+
while(1) {
11+
gpio_write(GPIO_PIN20, 1);
12+
timer_delay(1);
13+
gpio_write(GPIO_PIN20, 0);
14+
timer_delay(1);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// linker memmap places these symbols at start/end of bss
2+
extern int __bss_start__, __bss_end__;
3+
4+
extern void main(void);
5+
6+
// The C function _cstart is called from the assembly in start.s
7+
// _cstart zeroes out the BSS section and then calls main.
8+
// After return from main(), turns on the green ACT LED as
9+
// a sign of successful completion.
10+
void _cstart(void)
11+
{
12+
int *bss = &__bss_start__;
13+
int *bss_end = &__bss_end__;
14+
15+
while (bss < bss_end) {
16+
*bss++ = 0;
17+
}
18+
19+
main();
20+
21+
// Turn on the green ACT LED (GPIO 47)
22+
volatile unsigned int *GPIO_FSEL4 = (unsigned int *)0x20200010;
23+
volatile unsigned int *GPIO_SET1 = (unsigned int *)0x20200020;
24+
*GPIO_FSEL4 = (*GPIO_FSEL4 & ~(7 << 21)) | (1 << 21);
25+
*GPIO_SET1 = 1 << 15;
26+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SECTIONS
2+
{
3+
.text 0x8000 : { start.o(.text*) *(.text*) }
4+
.data : { *(.data*) }
5+
.rodata : { *(.rodata*) }
6+
7+
__bss_start__ = .;
8+
.bss : { *(.bss*) *(COMMON) }
9+
__bss_end__ = ALIGN(8);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.globl _start
2+
_start:
3+
mov sp, #0x8000000
4+
mov fp, #0
5+
bl _cstart
6+
hang: b hang
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
APPLICATION = blink
2+
MODULES = timer.o gpio.o
3+
4+
CFLAGS = -Og -Wall -std=c99 -ffreestanding
5+
ASFLAGS = --warn --fatal-warnings
6+
LDFLAGS = -nostdlib -T memmap
7+
8+
all : $(APPLICATION).bin
9+
10+
%.bin: %.elf
11+
arm-none-eabi-objcopy $< -O binary $@
12+
13+
%.elf: %.o libpi.a
14+
arm-none-eabi-ld $(LDFLAGS) $^ -o $@
15+
16+
libpi.a: $(MODULES) cstart.o start.o
17+
arm-none-eabi-ar crf $@ $^
18+
19+
%.o: %.c
20+
arm-none-eabi-gcc $(CFLAGS) -c $< -o $@
21+
22+
%.o: %.s
23+
arm-none-eabi-as $(ASFLAGS) $< -o $@
24+
25+
install: $(APPLICATION).bin
26+
rpi-install.py $<
27+
28+
clean:
29+
rm -f *.a *.o *.i *.bin *.elf *.list *~ blink.s gpio.s timer.s cstart.s
30+
31+
.PHONY: all clean install
32+
33+
.PRECIOUS: %.o %.elf
34+
35+
# empty recipe used to disable built-in rules for native build
36+
%:%.c
37+
%:%.o
38+
%:%.s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Demonstrates libraries by making libpi.a
2+
3+
4+
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "gpio.h"
2+
#include "timer.h"
3+
4+
void main() {
5+
6+
gpio_init();
7+
timer_init();
8+
9+
gpio_set_function(GPIO_PIN20, GPIO_FUNC_OUTPUT);
10+
while(1) {
11+
gpio_write(GPIO_PIN20, 1);
12+
timer_delay(1);
13+
gpio_write(GPIO_PIN20, 0);
14+
timer_delay(1);
15+
}
16+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// linker memmap places these symbols at start/end of bss
2+
extern int __bss_start__, __bss_end__;
3+
4+
extern void main(void);
5+
6+
// The C function _cstart is called from the assembly in start.s
7+
// _cstart zeroes out the BSS section and then calls main.
8+
// After return from main(), turns on the green ACT LED as
9+
// a sign of successful completion.
10+
void _cstart(void)
11+
{
12+
int *bss = &__bss_start__;
13+
int *bss_end = &__bss_end__;
14+
15+
while (bss < bss_end) {
16+
*bss++ = 0;
17+
}
18+
19+
main();
20+
21+
// Turn on the green ACT LED (GPIO 47)
22+
volatile unsigned int *GPIO_FSEL4 = (unsigned int *)0x20200010;
23+
volatile unsigned int *GPIO_SET1 = (unsigned int *)0x20200020;
24+
*GPIO_FSEL4 = (*GPIO_FSEL4 & ~(7 << 21)) | (1 << 21);
25+
*GPIO_SET1 = 1 << 15;
26+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "gpio.h"
2+
3+
void gpio_init(void) {
4+
}
5+
6+
void gpio_set_function(unsigned int pin, unsigned int function) {
7+
// TODO: Your code goes here.
8+
}
9+
10+
unsigned int gpio_get_function(unsigned int pin) {
11+
return 0; // TODO: Your code goes here.
12+
}
13+
14+
void gpio_set_input(unsigned int pin) {
15+
// TODO: Your code goes here.
16+
}
17+
18+
void gpio_set_output(unsigned int pin) {
19+
// TODO: your code goes here.
20+
}
21+
22+
void gpio_write(unsigned int pin, unsigned int value) {
23+
// TODO: Your code goes here.
24+
}
25+
26+
unsigned int gpio_read(unsigned int pin) {
27+
return 0; // TODO: Your code goes here.
28+
}

0 commit comments

Comments
 (0)