Skip to content

Commit

Permalink
pi-pico: work on i2c
Browse files Browse the repository at this point in the history
  • Loading branch information
deater committed Jun 29, 2021
1 parent e1a8a54 commit e1e9ae5
Show file tree
Hide file tree
Showing 21 changed files with 6,023 additions and 0 deletions.
82 changes: 82 additions & 0 deletions pi-pico/i2c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
CC = arm-none-eabi-gcc
AS = arm-none-eabi-as
LD = arm-none-eabi-ld

OBJDUMP = arm-none-eabi-objdump
OBJCOPY = arm-none-eabi-objcopy
#CFLAGS = -g -O2 -Wall
CFLAGS = -g -O3 -Wall -I..
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m0plus
CFLAGS += -fno-common
CFLAGS += -ffunction-sections -fdata-sections
ASFLAGS =

ELF2UF2 = ../elf2uf2/elf2uf2

##### Project specific libraries #####
SRC_FILES = i2c-display.c

all: i2c-display.uf2 i2c-display.dis

clean:
rm -f i2c-display.bin i2c-display.elf *~ *.o *.dis *.uf2

crt0.o: crt0.S
$(AS) $(ASFLAGS) -o crt0.o -c crt0.S

#boot2_w25q080.o: boot2_w25q080.S
# $(AS) $(ASFLAGS) -o boot2_w25q080.o -c boot2_w25q080.S

idivmod.o: idivmod.S
$(AS) $(ASFLAGS) -o idivmod.o -c idivmod.S

uldivmod.o: uldivmod.S
$(AS) $(ASFLAGS) -o uldivmod.o -c uldivmod.S

runtime.o: runtime.c
$(CC) $(CFLAGS) -c runtime.c

i2c-display.elf: i2c-display.o \
crt0.o bootrom.o runtime.o \
mmio.o timer.o clocks.o gpio.o i2c.o idivmod.o uldivmod.o
$(LD) -v -Tmemmap_default.ld -nostartfiles -o i2c-display.elf i2c-display.o \
bootrom.o crt0.o runtime.o \
mmio.o timer.o clocks.o gpio.o i2c.o idivmod.o uldivmod.o
# boot2_w25q080.o

bootrom.o: bootrom.c
$(CC) $(CFLAGS) -c bootrom.c

clocks.o: clocks.c
$(CC) $(CFLAGS) -c clocks.c

timer.o: timer.c
$(CC) $(CFLAGS) -c timer.c

i2c-display.o: i2c-display.c
$(CC) $(CFLAGS) -c i2c-display.c

i2c-display.uf2: i2c-display.elf
$(ELF2UF2) i2c-display.elf i2c-display.uf2

i2c-display.dis: i2c-display.elf
$(OBJDUMP) -h i2c-display.elf > i2c-display.dis
$(OBJDUMP) -d i2c-display.elf >> i2c-display.dis

####

gpio.o: gpio.c ../include/gpio.h
$(CC) $(CFLAGS) -c gpio.c

####

i2c.o: i2c.c ./i2c.h
$(CC) $(CFLAGS) -c i2c.c

####

mmio.o: mmio.c
$(CC) $(CFLAGS) -c mmio.c



40 changes: 40 additions & 0 deletions pi-pico/i2c/bootrom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdint.h>

//#include "pico/bootrom.h"

/// \tag::table_lookup[]

// Bootrom function: rom_table_lookup
// Returns the 32 bit pointer into the ROM if found or NULL otherwise.
typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code);

// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
#define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)rom_address)

void *rom_func_lookup(uint32_t code) {
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(0x18);
uint16_t *func_table = (uint16_t *) rom_hword_as_ptr(0x14);
return rom_table_lookup(func_table, code);
}

void *rom_data_lookup(uint32_t code) {
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(0x18);
uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(0x16);
return rom_table_lookup(data_table, code);
}
/// \end::table_lookup[]

int rom_funcs_lookup(uint32_t *table, unsigned int count) {
int ok = 1;
for (unsigned int i = 0; i < count; i++) {
table[i] = (uintptr_t) rom_func_lookup(table[i]);
if (!table[i]) ok = 0;
}
return ok;
}
23 changes: 23 additions & 0 deletions pi-pico/i2c/bs2_default_padded_checksummed.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Padded and checksummed version of: /home/vince/research/vmw-meter.git/pi-pico/pico/pico-examples/build/pico-sdk/src/rp2_common/boot_stage2/bs2_default.bin

.cpu cortex-m0plus
.thumb

.section .boot2, "ax"

.byte 0x00, 0xb5, 0x32, 0x4b, 0x21, 0x20, 0x58, 0x60, 0x98, 0x68, 0x02, 0x21, 0x88, 0x43, 0x98, 0x60
.byte 0xd8, 0x60, 0x18, 0x61, 0x58, 0x61, 0x2e, 0x4b, 0x00, 0x21, 0x99, 0x60, 0x02, 0x21, 0x59, 0x61
.byte 0x01, 0x21, 0xf0, 0x22, 0x99, 0x50, 0x2b, 0x49, 0x19, 0x60, 0x01, 0x21, 0x99, 0x60, 0x35, 0x20
.byte 0x00, 0xf0, 0x44, 0xf8, 0x02, 0x22, 0x90, 0x42, 0x14, 0xd0, 0x06, 0x21, 0x19, 0x66, 0x00, 0xf0
.byte 0x34, 0xf8, 0x19, 0x6e, 0x01, 0x21, 0x19, 0x66, 0x00, 0x20, 0x18, 0x66, 0x1a, 0x66, 0x00, 0xf0
.byte 0x2c, 0xf8, 0x19, 0x6e, 0x19, 0x6e, 0x19, 0x6e, 0x05, 0x20, 0x00, 0xf0, 0x2f, 0xf8, 0x01, 0x21
.byte 0x08, 0x42, 0xf9, 0xd1, 0x00, 0x21, 0x99, 0x60, 0x1b, 0x49, 0x19, 0x60, 0x00, 0x21, 0x59, 0x60
.byte 0x1a, 0x49, 0x1b, 0x48, 0x01, 0x60, 0x01, 0x21, 0x99, 0x60, 0xeb, 0x21, 0x19, 0x66, 0xa0, 0x21
.byte 0x19, 0x66, 0x00, 0xf0, 0x12, 0xf8, 0x00, 0x21, 0x99, 0x60, 0x16, 0x49, 0x14, 0x48, 0x01, 0x60
.byte 0x01, 0x21, 0x99, 0x60, 0x01, 0xbc, 0x00, 0x28, 0x00, 0xd0, 0x00, 0x47, 0x12, 0x48, 0x13, 0x49
.byte 0x08, 0x60, 0x03, 0xc8, 0x80, 0xf3, 0x08, 0x88, 0x08, 0x47, 0x03, 0xb5, 0x99, 0x6a, 0x04, 0x20
.byte 0x01, 0x42, 0xfb, 0xd0, 0x01, 0x20, 0x01, 0x42, 0xf8, 0xd1, 0x03, 0xbd, 0x02, 0xb5, 0x18, 0x66
.byte 0x18, 0x66, 0xff, 0xf7, 0xf2, 0xff, 0x18, 0x6e, 0x18, 0x6e, 0x02, 0xbd, 0x00, 0x00, 0x02, 0x40
.byte 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x07, 0x00, 0x00, 0x03, 0x5f, 0x00, 0x21, 0x22, 0x00, 0x00
.byte 0xf4, 0x00, 0x00, 0x18, 0x22, 0x20, 0x00, 0xa0, 0x00, 0x01, 0x00, 0x10, 0x08, 0xed, 0x00, 0xe0
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0xb2, 0x4e, 0x7a
Loading

0 comments on commit e1e9ae5

Please sign in to comment.