I stripped down the code to:
static void VsInitPorts()
{
RLPext->GPIO.EnableInputMode(33, RLP_GPIO_RESISTOR_DISABLED); //DREQ
RLPext->GPIO.EnableOutputMode(31, RLP_TRUE); //XCS
RLPext->GPIO.EnableOutputMode(32, RLP_TRUE); //XDCS
RLPext->GPIO.EnableOutputMode(34, RLP_TRUE); //RESET
PINSEL0 &= ~((0x03 << 14) | (0x03 << 16) | (0x03 << 19)); //set SCK, SO and SI as GPIO
PINSEL0 |= (0x02 << 14) | (0x02 << 16) | (0x02 << 18); //set SCK, SO and SI as SSP1
}
int VsInit(unsigned char *generalArray, void **args, unsigned int argsCount, unsigned int *argSize)
{
if (argsCount > 1) return 2;
//init I/O
VsInitPorts();
return 0;
}
(also tried without changing PINSEL0 register)
and this is the managed code:
RLP.Unlock(...);
byte[] elf_file = Extension.GetBytes(Extension.BinaryResources.Extension);
RLP.LoadELF(elf_file);
RLP.Procedure VsInit = RLP.GetProcedure(elf_file, "VsInit");
if ((result = VsInit.Invoke()) != 0) throw new Exception("Could not init VS Driver. Reason " + result.ToString());
I put a breakpoint at VsInit.Invoke(), start debugging, step over that line and it freezes. Everything freezes (debugging, etc.), only a reset works. After the reset, it freezes again (not in debugging but I can see that because it doesn’t draw the UI). After the 2nd freeze, if I reset the board everything works well every time no matter what I do (reset from switch, reset power).
I also tried:
static void VsInitPorts()
{
PINSEL0 &= ~((0x03 << 12) | (0x03 << 14) | (0x03 << 16) | (0x03 << 19)); //set DREQ, SCK, SO and SI as GPIO
PINSEL0 |= (0x02 << 14) | (0x02 << 16) | (0x02 << 18); //set SCK, SO and SI as SSP1
PINSEL4 &= ~(0x03 << 2); //set XDCS as GPIO
PINSEL7 &= ~((0x03 << 4) | (0x03 << 28)); //set RESET and XCS as GPIO
FIO0DIR &= ~(1<<6); //set DREQ as input
FIO2DIR |= (1<<1); //set XDCS as output
FIO3DIR |= (1<<18) | (1<<30); //set RESET and XCS as output
}
but it’s the same behavior. Also tried checking if the pins are reserved and reserving them if not or abort but still freezes.
The only thing that works is commenting the VsInitPorts function call.
This is the makefile I’m using:
OUTFILE=Extension
LINKERSCRIPT = LinkScript.lds
INCL=./include
CC =arm-none-eabi-gcc
LD =arm-none-eabi-gcc
CCFLAGS= -g -mlittle-endian -mcpu=arm7tdmi -std=gnu99 -Wall -I. -I$(INCL)
CCFLAGS+= -mapcs-frame -fno-builtin -g0 -O3
LDFLAGS =-nostartfiles -Wl,--Map -Wl,$(OUTFILE).map
LDFLAGS+=-lc -lgcc -Wl,--omagic
LDFLAGS+=-T $(LINKERSCRIPT)
SRCS=Extension.c
OBJS=$(SRCS:.c=.o)
rebuild: clean all
all: $(OBJS)
$(LD) $(LDFLAGS) -o $(OUTFILE).elf $(OBJS)
%.o: %.c
$(CC) -c $(CCFLAGS) $< -o $@
clean:
-rm *.o *.elf *.map
This is the linkscript file:
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
MEMORY
{
SDRAM (wx) : ORIGIN = 0xA0F00000, LENGTH = 0x000FFFFC
}
SECTIONS
{
. = ALIGN(4);
.text :
{
*(.text)
}
. = ALIGN(4);
.rodata :
{
*(.rodata )
}
. = ALIGN(4);
.data :
{
*(.data)
}
. = ALIGN(4);
.bss :
{
__bss_start__ = .;
*(.bss)
__bss_end__ = .;
}
}
end = .; /* define a global symbol marking the end of application RAM */
And the RLP.h file is the same with the EMX lines uncommented.
If anyone can test the exact same code on an EMX, please do.
Thanks
Later edit:
Could the -std=gnu99 flag for the compiler be the issue? I’m away right now and I can’t test it but it hit me when I looked over the Makefile.