Hello Jeremy,
jeremyzhou wrote:
According to your statement, I got that the original project would change after copy/paste operation, whether my consideration is right.
Yes you're right. I reproduce this with a very simple example code.
- Copy/paste the blinky example project "demos_switch_blinky",
- Modification of the main file "switch_blinky.c" with the following code (BTW, any option for formatted code in the post editor?):
/** Simple template with 1ms timer */
// For reusing clock configuration and pin-muxing
#include "board.h"
// Timer
#define TIMER_PRESCALE_2KHZ (0x5DC0)
// Function declarations
void setup_1ms_timer();
void start_1ms_timer();
void stop_1ms_timer();
/** Handle interrupt from 16-bit timer 0 */
void TIMER16_0_IRQHandler(void)
{
static uint16_t counter_500ms = 0;
if (Chip_TIMER_MatchPending(LPC_TIMER16_0, 1)) {
// 1ms tick
Chip_TIMER_ClearMatch(LPC_TIMER16_0, 1);
// Process 1ms
//...
// Pseudo-timer
if (counter_500ms >= 500) {
// 500ms tick
counter_500ms = 0;
// Process 500ms
// ...
} else {
counter_500ms++;
}
}
}
/** Setup 1ms timer */
void setup_1ms_timer() {
/* Initialize 16-bit timer 0 clock */
Chip_TIMER_Init(LPC_TIMER16_0);
/* Timer setup for match and interrupt at TICKRATE_HZ */
Chip_TIMER_Reset(LPC_TIMER16_0);
/* Enable timer to generate interrupts when time matches */
Chip_TIMER_MatchEnableInt(LPC_TIMER16_0, 1);
/* Setup prescale value on 16-bit timer to extend range */
Chip_TIMER_PrescaleSet(LPC_TIMER16_0, TIMER_PRESCALE_2KHZ);
/* Setup 16-bit timer's duration (16-bit match time) */
Chip_TIMER_SetMatch(LPC_TIMER16_0, 1, 0x0001);
/* Setup timer to restart when match occurs */
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_0, 1);
/* Clear both timers of any pending interrupts */
NVIC_ClearPendingIRQ(TIMER_16_0_IRQn);
/* Enable timer interrupts */
NVIC_EnableIRQ(TIMER_16_0_IRQn);
}
/** Starts the 1ms timer */
void start_1ms_timer() {
/* Reset timer counts */
Chip_TIMER_Reset(LPC_TIMER16_0);
/* Clear match interrupt */
Chip_TIMER_ClearMatch(LPC_TIMER16_0, 1);
/* Start timer */
Chip_TIMER_Enable(LPC_TIMER16_0);
}
/**
* Stops 1ms timer */
void stop_1ms_timer() {
/* Stop timer */
Chip_TIMER_Disable(LPC_TIMER16_0);
}
/** Main routine */
int main(void)
{
SystemCoreClockUpdate();
// Initialize GPIO (and set system clock)
Chip_GPIO_Init(LPC_GPIO);
while (1) {
__WFI();
// Process after interrupt routine
// ...
}
return 0;
}
I expect that the "sysinit.c" procedure do the board config with no problem but I have the following error:
13:07:04 **** Incremental Build of configuration Debug for project copy_demos_switch_blinky ****
make -r -j4 all
Building file: ../src/switch_blinky.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -DDEBUG -D__CODE_RED -D__USE_LPCOPEN -DCORE_M0PLUS -D__USE_ROMDIVIDE -I"D:\MCUXpresso_LPCOpen_workspace\lpc_chip_11u6x\inc" -I"D:\MCUXpresso_LPCOpen_workspace\lpc_board_nxp_lpcxpresso_11u68\inc" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb -D__REDLIB__ -specs=redlib.specs -MMD -MP -MF"src/switch_blinky.d" -MT"src/switch_blinky.o" -MT"src/switch_blinky.d" -o "src/switch_blinky.o" "../src/switch_blinky.c"
Finished building: ../src/switch_blinky.c
Building target: copy_demos_switch_blinky.axf
Invoking: MCU Linker
arm-none-eabi-gcc -nostdlib -L"D:\MCUXpresso_LPCOpen_workspace\lpc_chip_11u6x\Debug" -L"D:\MCUXpresso_LPCOpen_workspace\lpc_board_nxp_lpcxpresso_11u68\Debug" -Xlinker -Map="copy_demos_switch_blinky.map" -Xlinker --gc-sections -Xlinker --allow-multiple-definition -mcpu=cortex-m0 -mthumb -T "demos_switch_blinky_Debug.ld" -o "copy_demos_switch_blinky.axf" ./src/cr_startup_lpc11u6x.o ./src/crp.o ./src/switch_blinky.o ./src/sysinit.o -llpc_board_nxp_lpcxpresso_11u68 -llpc_chip_11u6x
D:\MCUXpresso_LPCOpen_workspace\lpc_chip_11u6x\Debug\liblpc_chip_11u6x.a(clock_11u6x.o): In function `Chip_Clock_GetMainOscRate':
D:\MCUXpresso_workspace\lpc_chip_11u6x\inc/clock_11u6x.h:518: undefined reference to `OscRateIn'
D:\MCUXpresso_LPCOpen_workspace\lpc_chip_11u6x\Debug\liblpc_chip_11u6x.a(clock_11u6x.o): In function `Chip_Clock_GetRTCOscRate':
D:\MCUXpresso_workspace\lpc_chip_11u6x\inc/clock_11u6x.h:536: undefined reference to `RTCOscRateIn'
collect2.exe: error: ld returned 1 exit status
make: *** [copy_demos_switch_blinky.axf] Error 1