我正在尝试在 MSP430 Launchpad 上运行“Hello world”,这是最简单和基本的代码(具体来说,MSP430FR5994 Launchpad)。我想运行它并将其显示在 CCStudio 控制台或另一个屏幕上。但是,我找不到任何有关为 Launchpad 运行“hello world”并将其打印在计算机屏幕上的信息。
这感觉应该很简单,但我似乎无法在任何地方找到解释。
当前代码,包括闪烁灯光:
#include <msp430.h>
#include <stdio.h>
int main(void) {
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer
P1OUT &= ~BIT0; // Meant to clear P1
P1DIR = 0b00000010; // Set P1.0 to output direction, p.131
unsigned int i; //Delay variable
PM5CTL0 &= ~LOCKLPM5; //The datasheet told me to include it. Haven't found out why the datasheet asked me to do this.
printf("Not C programming again!\n");
while(1)
{
for(i=0;i<20000;i++){
}
P1OUT = 0x02; //Turn on Port 1.1
for(i=0;i<20000;i++){
}
P1OUT = 0x01; //Turn on Port 1.0
}
return 0;
}
我试图这样做是为了熟悉电路板并获得更简单的调试方法。我最终想创建一个低频三角波,并将两个模拟输入与比较器进行比较,然后在计算机屏幕上显示该比较器信息。不知道这有什么帮助,但最好让您知道。
如果这个问题需要更多解释,请告诉我。如果这个问题变得简单得令人难以置信,我很抱歉,我花了几个小时寻找解释,但只发现了闪烁的灯光。
I am trying to run "Hello world", the most simple and basic code there is, on an MSP430 Launchpad (specifically, the MSP430FR5994 Launchpad). I want to run this and have it be displayed on the CCStudio console or another screen. However, I can't find any information on running "hello world" for the Launchpad and having it print on a computer screen.
This feels like it should be simple, but I can't seem to find an explanation anywhere.
Current code, which includes blinking the lights:
#include <msp430.h>
#include <stdio.h>
int main(void) {
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer
P1OUT &= ~BIT0; // Meant to clear P1
P1DIR = 0b00000010; // Set P1.0 to output direction, p.131
unsigned int i; //Delay variable
PM5CTL0 &= ~LOCKLPM5; //The datasheet told me to include it. Haven't found out why the datasheet asked me to do this.
printf("Not C programming again!\n");
while(1)
{
for(i=0;i<20000;i++){
}
P1OUT = 0x02; //Turn on Port 1.1
for(i=0;i<20000;i++){
}
P1OUT = 0x01; //Turn on Port 1.0
}
return 0;
}
I am trying to do this as a way to familiarize myself with the board and to get an easier method of debugging. I eventually want to create a low frequency triangle wave, and compare two analog inputs with the comparator then displaying that comparator information on a computer screen. Don't know how this helps but better to let you know.
Please let me know if this question needs more explanation. I apologize if this question turns out to be mindbogglingly simple, I have spent hours looking for explanations and only found blinking lights.
发布评论
评论(2)
声明:
实际上低估了
printf()
的复杂性。首先,您必须定义与 stdout 关联的输出设备。对于调试控制台中的输出,您需要在项目调试属性中启用 CIO(显然...我只是 谷歌搜索这些东西)。
然而,这种输出方式仅在调试时有用,因为您需要运行 CCSTUDIO 调试器才能查看输出。
关于您的最终目标:
... 为此,您需要实现支持 stdio 流所需的低级 I/O。例如,您可以将 stdio 映射到 Launchpad 的“应用程序/反向通道 UART”(Launchpad 手册),它是一个 MSP430 UART1/USB 桥接器。然后,您可以使用 PC 上的终端仿真器(例如 TeraTerm 或 PuTTY)与开发板进行交互。这样做的优点是可以通过 Launchpad 的 USB 连接在主机上显示为虚拟串行端口。
要了解如何创建合适的设备驱动程序并将 stdio 从调试器重定向到应用程序 UART,请参阅 编译器参考手册,以及前面关于所需设备驱动程序接口的部分。
您可能会选择不考虑将应用程序 UART 与 stdio 集成的复杂性(尽管我很难相信有人还没有完成这项工作),而只是直接读/写 UART。您还可以绕过标准库的 stdio 实现并实现您自己的简化格式化 I/O。例如 这个 TinyPrint 实现,其中
tfp_printf()
可以工作中,您只需要实现一个putc()
函数即可将字符写入您选择的任何输出设备(本例中为 UART1)。请注意,应用程序 UART 用于 Launchpad 的开箱即用演示,以与主机上的 GUI 界面进行通信。如果您拥有必要的 PC GUI 和串行 I/O 开发技能,您最终可以做类似的事情,这可能比简单的终端 I/O 更引人注目。该演示的源代码(嵌入的 这里)。
The statment:
is to to really underestimate complexity of
printf()
.First of all you have to define what output device is associated with stdout. For output in the debug console, you need to enable CIO in the project debug properties (apparently... I am just Googling this stuff).
Outputting that way however is only useful in debug because you need CCSTUDIO debugger running to see the output.
With respect to your ultimate goal:
... for that you will need to implement the low level I/O required to support stdio streams. You might for example map stdio to the Launchpad's "Application/Backchannel UART" (§2.2.4 of the Launchpad manual) which is an MSP430 UART1/USB bridge. Then you can interact with the board using a terminal emulator such as TeraTerm or PuTTY on the PC. That has the advantage of appearing on your host as a virtual serial port via the Launchpad's USB connection.
To see how to create a suitable device driver and redirect stdio from the debugger to the Application UART see §7.2.4 of the Compiler reference manual, and the preceding section on the required device driver interface.
You might choose not to go to the complexity of integrating the Application UART with stdio (though I find it hard to believe someone has not already done that work), and simply read/write directly to the UART. You could also bypass the standard library's stdio implementation and implement your own simplified formatted I/O. For example this TinyPrint implementation where for
tfp_printf()
to work you need only implement a singleputc()
function to write a character to whatever output device you choose (UART1 in this case).Note that the application UART is used for the Launchpad's Out-of-Box Demo to communicate with a GUI interface on the host. If you have the necessary PC GUI and serial I/O development skills, you could ultimately do something similar, which might be more compelling than simple terminal I/O. The source code for that demo (the embedded here).
我发现为什么我的终端不显示文本。这是动态内存分配的问题,没有分配足够的内存来使 printf 成功运行。事实证明 printf 的计算成本比我预期的要高。
为了处理分配问题,堆大小(在 MSP C 编译器手册第 155 页)需要增加到 320。这可以通过(我正在使用CCStudio 11.1)打开您的项目或项目中的文件,转到项目(位于顶部栏),打开属性,然后打开 Build/MSP430 Linker/Basic Options。
使用 Project 中的属性而不是 File 中的属性非常重要,因为 File 中的属性不包含链接器。
如果有效,打印文本应从 CIO 终端中输出。
I found out why my terminal was not displaying the text. This is an issue with dynamic memory allocation, where not enough of it was allocated for printf to be successfully run. As it turns out printf is more computationally expensive than I could have expected.
In order to deal with the allocation issue, the heap size (explained in page 155 of the MSP C Compiler Manual) needs to be increased to 320. This can be done by (I am using CCStudio 11.1) opening your project or a file in your project, going to Project (which is on the top bar), opening properties, and opening Build/MSP430 Linker/Basic Options.
It's very important to use the properties in Project instead of the one in File, as the properties in File does not contain the linker.
If it works, the printed text should come out of a CIO terminal.