工具与软件:
当我在 Linux 命令行(Fedora FC41)上使用 MSP430-gcc 编译一个简单的闪烁程序时、它的工作方式就像 Charm 一样:
#include <msp430.h> int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P3OUT &= ~BIT0; // LED Status (Red) P3DIR |= BIT0; PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode while(1) { P3OUT ^= BIT0; __delay_cycles(500000); } }
但是、一旦我将初始化代码放入头文件中:
#include <msp430.h> #include "init.h" int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer init(); while(1) { P3OUT ^= BIT0; __delay_cycles(500000); } }
init.c
#include <msp430.h> #include "init.h" void init(void) { P3OUT &= ~BIT0; // LED Status (Red) P3DIR |= BIT0; PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode }
init.h:
#ifndef ESM_H_ #define ESM_H_ #endif /* ESM_H_ */
它会显示错误消息:
../../msp430-elf/bin/ld:DWARF 错误:行信息数据大于该段中剩余的空间(0xfffffffc)
我缺少什么? (使用 CCS 时、它可以正常工作、只是不在命令行上)。 Makefile 中的所有路径似乎都可以。
下面是我的 Makefile:
OBJECTS = main.o MAP = main.map GCC_DIR = /opt/ti/msp430-gcc/bin SUPPORT_FILE_DIRECTORY = /opt/ti/msp430-gcc/include DEVICE = MSP430FR2355 CC = $(GCC_DIR)/msp430-elf-gcc GDB = $(GCC_DIR)/msp430-elf-gdb OBJCOPY = $(GCC_DIR)/msp430-elf-objcopy CFLAGS = -I $(SUPPORT_FILE_DIRECTORY) -I. -mmcu=$(DEVICE) -ffunction-sections -fdata-sections -Og -Wall -g -DDEPRECATED -v LFLAGS = -L $(SUPPORT_FILE_DIRECTORY) -Wl,-Map,$(MAP),--gc-sections .PHONY: all clean debug all: $(DEVICE).out $(DEVICE).out: $(OBJECTS) $(CC) $(CFLAGS) $(LFLAGS) $^ -o $@ $(OBJCOPY) -O ihex $@ $(DEVICE).hex %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ clean: $(RM) $(OBJECTS) $(MAP) *.out *.hex debug: all $(GDB) $(DEVICE).out
非常感谢您的帮助!