Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
25d37e9
primeiras funcoes
GabrielKrishna Sep 15, 2024
1ca7957
utf8len att
GabrielKrishna Sep 19, 2024
52084e8
utf8maiuscilosminusculo
GabrielKrishna Sep 25, 2024
ebe14ea
debug para funcao mai/min
GabrielKrishna Oct 16, 2024
6394da9
Add basic float support to atmega and implements a bitcast operator
thborges Sep 30, 2024
afbdb43
Fixes to build with LLVM19
thborges Sep 30, 2024
9da62d2
Added float_to_int32 and float_to_64 assembly support on atmega328p.
thborges Oct 3, 2024
bb54457
Fix declaration of string variable initialized by string constant and…
thborges Oct 19, 2024
42d228d
Fix build of function calls with string constants.
thborges Oct 30, 2024
f65b1c3
last corrections str mai min
GabrielKrishna Oct 23, 2024
332972b
mai min corrections
GabrielKrishna Oct 30, 2024
c6ccabc
test
GabrielKrishna Oct 31, 2024
f9ba4b7
att
GabrielKrishna Nov 14, 2024
3f13a67
.
GabrielKrishna Nov 18, 2024
a31dae0
testes funcoes
GabrielKrishna Nov 28, 2024
c78d98a
Initial support to avr1284p; add test folder to stm32f1.
thborges Nov 9, 2024
dff880c
Small fix when passing array as argument to function. When the array …
thborges Nov 9, 2024
caa12fc
Missing stm32 functions.
thborges Nov 19, 2024
e4f6a45
Fix function call passing array size.
thborges Nov 28, 2024
223cb51
Basic float support to stm32f1, using pre-built libgcc.
thborges Dec 4, 2024
9bb4e9b
Add stm32f1 test sample with uart.
thborges Dec 4, 2024
677bd57
att
GabrielKrishna Nov 28, 2024
c9d38ef
att
GabrielKrishna Nov 28, 2024
c14944c
correcoes nas funcoes uppercase e lowercase alem da adicao dos testes…
GabrielKrishna Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ test/atmega328p/out
platformio/toolchain-robcmp/bin
platformio/toolchain-robcmp/lib
platformio/avr-gdb-build
Documentation
hack
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ add_dependencies(robcmp parsers)
llvm_map_components_to_libnames(llvm_libs support core irreader passes
armasmparser armcodegen
avrasmparser avrcodegen
x86asmparser x86codegen)
x86asmparser x86codegen
aarch64asmparser aarch64codegen)

target_link_libraries(robcmp ${llvm_libs})

Expand Down
13 changes: 8 additions & 5 deletions hack/avr/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
INCLUDES=-I/Users/thborges/.platformio/packages/toolchain-atmelavr/avr/include
#AVRLIB=-L~/.platformio/packages/toolchain-atmelavr/lib/gcc/avr/7.3.0/avr5 -lgcc
CC=/usr/local/robllvm/bin/clang
LLC=/usr/local/robllvm/bin/llc
CC=clang
LLC=llc
CCPLAT=-target avr -mmcu=atmega328p -DF_CPU=16000000
ROBCMP=../../robcmp
ROBCMP=../../build/robcmp

AVRDUDECFG=-C /Users/thborges/.platformio/packages/tool-avrdude/avrdude.conf
AVRDUDEPORT=`ls /dev/cu.usb*`
Expand Down Expand Up @@ -36,10 +36,13 @@ all: ${ROBCMP} ${ALL}
%.elf : %.o
@#${CC} -v ${CCPLAT} ${AVRLIB} $< -o $@
@#avr-gcc -v -mmcu=atmega328p $< -o $@
avr-ld -o $@ -Tdata=0x800100 $<
#avr-ld -o $@ -Tdata=0x800100 $<
ld.lld -o $@ -Tdata=0x800100 $<


%.hex : %.elf
avr-objcopy -Oihex $< $@
#avr-objcopy -Oihex $< $@
llvm-objcopy -Oihex $< $@

%.up: %.hex
avrdude ${AVRDUDECFG} -v -V -c arduino -p m328p -U flash:w:$<:i -P ${AVRDUDEPORT}
Expand Down
22 changes: 12 additions & 10 deletions hack/stm32/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#GCC=~/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc
CC=/usr/local/robllvm/bin/clang
LLC=/usr/local/robllvm/bin/llc
OBJCOPY=/usr/local/robllvm/bin/llvm-objcopy
CC=~/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc
#CC=/usr/local/opt/llvm/bin/clang
LLC=/usr/local/opt/llvm/bin/llc
OBJCOPY=/usr/local/opt/llvm/bin/llvm-objcopy
INCLUDES=
CCPLAT=-target arm-none-eabi -mcpu=cortex-m3 -mthumb
ROBCMP=../../robcmp
#CCPLAT=-target arm-none-eabi -mcpu=cortex-m3 -mthumb
CCPLAT=-mcpu=cortex-m3 -mthumb
ROBCMP=../../build/robcmp

USBPORT=`ls /dev/cu.usb*`

Expand All @@ -15,10 +16,11 @@ ALL=${ALL_C} ${ALL_ROB}
all: ${ROBCMP} ${ALL}

%.c.ll: %.c
${CC} ${CCPLAT} -Oz -S -emit-llvm ${INCLUDES} $< -o $@
#${CC} ${CCPLAT} -Oz -S -emit-llvm ${INCLUDES} $< -o $@
${CC} ${CCPLAT} -Os -S -emit-llvm ${INCLUDES} $< -o $@

%.c.o: %.c
${CC} ${CCPLAT} -Oz -c ${INCLUDES} $< -o $@
${CC} -v ${CCPLAT} -Os -c ${INCLUDES} $< -o $@



Expand All @@ -34,8 +36,8 @@ all: ${ROBCMP} ${ALL}
${LLC} $< -o $@ -filetype=asm

%.elf : %.o
${CC} -v ${CCPLAT} -nostdlib -Wl,-entry=main -Wl,-Tmemory.lld.ld $< -o $@
@#${GCC} -mthumb -mcpu=cortex-m3 -nostdlib -Wl,-Tmemory.gcc.ld $< -o $@
#${CC} ${CCPLAT} -nostdlib -Wl,-entry=main -Wl,-Tmemory.lld.ld $< -o $@
${CC} -mthumb -mcpu=cortex-m3 -nostdlib -Wl,-Tmemory.gcc.ld $< -o $@


%.bin : %.elf
Expand Down
14 changes: 11 additions & 3 deletions lib/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@

GEN=avr5.o
GEN=avr5.o avr51.o cortex-m3-arm-missing.o

all: ${GEN}

avr5.o: avr5.S
@#here we are interested in the fastest possible code, intead of size
@#avr-gcc -mmcu=avr5 -O3 -c $<
clang --target=avr -mmcu=avr5 -O3 -c $<
avr-gcc -mmcu=avr5 -O3 -c $<
@#clang --target=avr -mmcu=avr5 -O3 -c $<

avr51.o: avr51.S
@#here we are interested in the fastest possible code, intead of size
avr-gcc -mmcu=avr51 -O3 -c $<
@#clang --target=avr -mmcu=avr51 -O3 -c $<

cortex-m3-arm-missing.o: arm-missing.c
clang --target=arm-none-eabi -mcpu=cortex-m3 -mthumb -O3 -c $< -o $@

clean:
rm -f ${GEN}
115 changes: 107 additions & 8 deletions lib/arch/stm32/stm32f1.rob
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,48 @@ type stm32f1 implements mcu {
return;
}

a2 implements digitalport {
void mode_input(PIN_MODE mode, INPUT_MODE cnf) inline {
GPIOA_CRL.mode2 = mode;
GPIOA_CRL.cnf2 = cnf;
}
void mode_output(PIN_MODE mode, OUTPUT_MODE cnf) inline {
GPIOA_CRL.mode2 = mode;
GPIOA_CRL.cnf2 = cnf;
}
void mode(port_mode m) {
APB2EN.iopa = true;
if (m == port_mode.input) {
mode_input(PIN_MODE.INPUT, INPUT_MODE.PULLUPDOWN);
} else {
mode_output(PIN_MODE.OUTPUT50MHz, OUTPUT_MODE.PUSHPULL);
}
}
void set(bool v) inline { GPIOA_ODR.odr2 = v; }
bool get() inline { return GPIOA_IDR.idr2; }
}

a3 implements digitalport {
void mode_input(PIN_MODE mode, INPUT_MODE cnf) inline {
GPIOA_CRL.mode3 = mode;
GPIOA_CRL.cnf3 = cnf;
}
void mode_output(PIN_MODE mode, OUTPUT_MODE cnf) inline {
GPIOA_CRL.mode3 = mode;
GPIOA_CRL.cnf3 = cnf;
}
void mode(port_mode m) {
APB2EN.iopa = true;
if (m == port_mode.input) {
mode_input(PIN_MODE.INPUT, INPUT_MODE.PULLUPDOWN);
} else {
mode_output(PIN_MODE.OUTPUT50MHz, OUTPUT_MODE.PUSHPULL);
}
}
void set(bool v) inline { GPIOA_ODR.odr3 = v; }
bool get() inline { return GPIOA_IDR.idr3; }
}

c13 implements digitalport {
void mode(port_mode m) {
APB2EN.iopc = true;
Expand Down Expand Up @@ -86,6 +128,14 @@ type stm32f1 implements mcu {
}
}

uint32 micros() {
return SYSTICK_VAL / (clock()/1E6);
}

uint32 millis() {
return micros() / 1000;
}

spi implements databus {
/* setup hardware SPI at:
xx = MOSI
Expand All @@ -100,20 +150,67 @@ type stm32f1 implements mcu {
bool has_data() { return false; }
bool start_transaction(uint16 address) { return true; }
void end_transaction() { }
void async_read_to(interrupt_i8 i) {}

databus_protocol get_protocol() {
return databus_protocol.SPI;
}
}

uart0 implements databus {
void setup(uint32 baud) {}
void enable() {}
void disable() {}
void write(uint8 b) {}
void write_array(int8[] data) {}
uint8 read() { return 0; }
bool has_data() { return false; }
uart2 implements databus {
void setup(uint32 baud) {
APB1EN.usart2 = true; // enable usart2 clock
//AHBENR.sdio = true; // enable SDIO clock
APB2EN.afio = true; //? enable alternate function I/O clock
APB2EN.iopa = true; // port A clock

// set ports a2 (output TX) and a3 (input RX)
a2.mode_output(PIN_MODE.OUTPUT2MHz, OUTPUT_MODE.APUSH_PULL);
a3.mode_input(PIN_MODE.INPUT, INPUT_MODE.FLOATING);

// assuming reset configuration, that is 8 bits per byte,
// no parity checks, and 1 “stop bit”.

// set baudrate
uartdiv = clock() / baud;
USART2_BRR.DIV_Fraction = uint4(uartdiv % 16);
USART2_BRR.DIV_Mantissa = uint12(uartdiv / 16);
}

void async_read_to(interrupt_i8 i) {}

void enable() {
USART2_CR1.RE = true; // receptor
USART2_CR1.TE = true; // transmiter
USART2_CR1.UE = true; // usart enable
}

void disable() {
USART2_CR1.UE = false;
}

void write(uint8 b) inline {
while !USART2_SR.TXE;
USART2_DR.DR = b;
}

void write_array(int8[] data) {
i = 0u;
while i < data.size {
write(uint8(data[i]));
i++;
}
}

uint8 read() {
while !USART2_SR.RXNE;
return uint8(USART2_DR.DR);
}

bool has_data() {
return USART2_SR.RXNE;
}

bool start_transaction(uint16 address) { return true; }
void end_transaction() {}

Expand Down Expand Up @@ -158,6 +255,8 @@ type stm32f1 implements mcu {
I2C1_CCR.ccr = uint12(((1.0/400000)/2) / (3.0/clock()));
I2C1_TRISE = uint16(clock()/1E6*0.3+1);
}

void async_read_to(interrupt_i8 i) {}

void enable() {
I2C1_CR1.pe = true;
Expand Down
63 changes: 63 additions & 0 deletions lib/arch/stm32/stm32f1regs.rob
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,66 @@ register I2C_SR2_t I2C2_SR2 at 0x40005818;
register I2C_CCR_t I2C2_CCR at 0x4000581C;
// I2C 2 T RISE register
register uint16 I2C2_TRISE at 0x40005820;

/*
* USART types
*/

type SR_t {
PE = false; // Parity error
FE = false; // Framing error
NE = false; // Noise error flag
ORE = false; // Overrun error
IDLE = false; // IDLE line detected
RXNE = false; // Read data register not empty
TC = false; // Transmission complete
TXE = false; // Transmit data register empty
LBD = false; // LIN break detection flag
CTS = false; // CTS flag
_res1 = uint16(0); // Reserved, 22 bits
_res2 = uint6(0); //
}

type CR1_t {
SBK = false; // Send break
RWU = false; // Receiver wakeup
RE = false; // Receiver enable
TE = false; // Transmitter enable
IDLEIE = false; // IDLE interrupt enable
RXNEIE = false; // RXNE interrupt enable
TCIE = false; // Transmission complete interrupt enable
TXEIE = false; // TXE interrupt enable
PEIE = false; // PE interrupt enable
PS = false; // Parity selection
PCE = false; // Parity control enable
WAKE = false; // Wakeup method
M = false; // Word length
UE = false; // USART enable
_res1 = uint16(0); // Reserved, 18 bits
_res2 = uint2(0); //
}

type DR_t {
DR = uint9(0); // Data value
_res1 = uint16(0); // Reserved, 23 bits
_res2 = uint7(0); //
}

type BRR_t {
DIV_Fraction = uint4(0); // fraction of USARTDIV
DIV_Mantissa = uint12(0); // mantissa of USARTDIV
_res1 = uint16(0); // Reserved, 16 bits
}

// Status register
register SR_t USART2_SR at 0x40004400;

// Data register
register DR_t USART2_DR at 0x40004404;

// Baud rate register
register BRR_t USART2_BRR at 0x40004408;

// Control register 1
register CR1_t USART2_CR1 at 0x4000440C;

Binary file added lib/arm-eabi-libgcc.a
Binary file not shown.
16 changes: 16 additions & 0 deletions lib/arm-missing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

void abort (void) {
while(1);
}

void *memcpy(void *dst, const void *src, unsigned int len)
{
const char *s = src;
char *d = dst;

while (len--)
*d++ = *s++;

return dst;
}

17 changes: 17 additions & 0 deletions lib/atmega1284p.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* RobCmp linker script for atmega1284p
*/

MEMORY
{
text (rx) : ORIGIN = 0, LENGTH = 128K
data (rw!x) : ORIGIN = 0x800100, LENGTH = 16K
eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 4K
fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K
lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K
signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K
user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = 1K
}

INCLUDE avr5.ld

Loading