I haven't posted for a while due to being busy @ work and I see there is a new release out - cool

I am currently trying to run a ChibiOS on a LPCXpresso 1769 board using LPCXpresso IDE as a project management and build system.
There are some difficulties in organizing a project into many sub-folders and for it to compile....therefore I have a main folder with my main.c file and ChibiOSAll sub-folder which has all the files relevant to the LPC1769 Cortex M3 MCU.
Once LPCXpresso IDE makes a project, it by default makes all the startup code files, vectors and the like so I didn't use those from ChibiOS. I will rely on them from LPCXpresso IDE since I know they work (did many bare-metal projects).
What I did change is that in chcore_v7m.c name of SysTick handler from Chibi distribution is different as in LPCXpresso IDE vectors, so I have changed the name:
CH_IRQ_HANDLER(SysTick_Handler) { and not SysTickVector.
Same with
Code: Select all
SVCall_Handler(void)
Code: Select all
SVCallVector
Second, LPCXpresso IDE and its compiler options / linker scripts do not provide __heap_base_ and __heap_end_ but they provide other vars:
so I have modified them to be able to compile:
Code: Select all
void _core_init(void) {
#if CH_MEMCORE_SIZE == 0
//extern uint8_t __heap_base__[];
//extern uint8_t __heap_end__[];
//nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__);
//endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__);
extern uint8_t _pvHeapStart[];
extern uint8_t __end_of_heap[];
nextmem = (uint8_t *)MEM_ALIGN_NEXT(_pvHeapStart);
endmem = (uint8_t *)MEM_ALIGN_PREV(__end_of_heap);
#else
static stkalign_t buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE];
nextmem = (uint8_t *)&buffer[0];
endmem = (uint8_t *)&buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE];
#endif
}
When I stepped with debugger I see that start is 268435880 and end is 268435872 meaning 8 bytes....??????? Something is wrong. Maybe I can use CH_MEMCORE_SIZE some larger number (say 1024) and forget about dynamic allocation.
After that I have copied all other files, and ChibiOS compiles well. I did not do anything with HAL now and all other subsystems.
In main.c at the beginning I would start SysTick timer and later on I would start ChibiOS.
However, the thing does not work......in main, when I call sleep, it never returns; I stepped with debugger from reset, and things seems fine; when sleep is called idle thread takes over and there it sits in port_wait_for_interrupt in that while loop. I did put a SysTick_Handler breakpoint and one time I got a hit, it executed all the methods there but went into a HardFault handler.
Any ideas?
In main below I didn't even bother with threads, because when I tried first, they execute and once they hit sleep they also break.
My main:
Code: Select all
int main(void) {
uint32_t dummy = 0;
// TODO: insert code here
while(dummy<5000000)
{
dummy++;
}
SystemCoreClockUpdate();
SysTick_Config(SystemCoreClock/1000);
unsigned long ulLEDState;
// Enter an infinite loop, just incrementing a counter
volatile static int i = 0 ;
SetupIO();
Setup7SegmentSPI();
LPC_PINCON->PINSEL1 &= ( ~( 3 << 12 ) );
LPC_GPIO0->FIODIR |= ( 1 << mainLED_BIT );
chSysInit();
/*
* Creates the blinker threads.
*/
//chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
//chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
i = 0;
while (TRUE) {
ulLEDState = LPC_GPIO0->FIOPIN;
/* Turn the LED off if it was on, and on if it was off. */
LPC_GPIO0->FIOCLR = ulLEDState & ( 1 << mainLED_BIT );
LPC_GPIO0->FIOSET = ( ( ~ulLEDState ) & ( 1 << mainLED_BIT ) );
chThdSleepMilliseconds(500);
for(ulLEDState = 0; ulLEDState < 2000000; ++ ulLEDState);
i = (i + 1) & 15;
}
return 0 ;
}