Multi Source Translation Content

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multi Source Translation Content

Discussions

Sort by:
GPIO 简介:如何读取微控制器 (MCX A153) 的引脚并控制 LED(日语博客) 目录 介绍 了解MCX A153微控制器的引脚配置 GPIO 使用设置 检查引脚与电路板(FRDM-MCXA153)之间的关系。 演示:执行 GPIO 设置并体验 LED 控制。 额外知识点:了解LED灯的“开/关”原理 附加题——如果将两个LED并联会发生什么?   介绍 作为嵌入式系统开发的初学者,我是在接到撰写一篇关于GPIO文章的邀请后开始学习它的。本文记录了我尝试点亮单个LED灯的过程中,通过反复试验所学到的知识和心得体会。 本文解释了如何使用 GPIO(通用输入/输出),它是微控制器开发中最基本的外部设备之一。 GPIO 是嵌入式系统的基础,用于将微控制器连接到外部电路,实现诸如打开 LED、读取开关状态和接收来自传感器的信号等功能。 另一方面,在实际的微控制器开发中,“使用GPIO”并不仅仅意味着编写程序。微控制器有许多引脚,每个引脚除了GPIO之外还被分配了其他功能,例如定时器和通信接口。 所以, 要使用 GPIO,您需要了解数据手册中的引脚分配和功能。 PinMUX(引脚复用)设置,用于将GPIO分配给引脚 输入/输出方向设置 这件事必须妥善处理。 这次,我们将以FRDM-MCXA153为例,研究 MCX A153 的引脚配置和 PinMUX 机制,使用 Pins Tool 配置 GPIO 设置,最后演示连接到面包板上的 LED 闪烁。   了解MCX A153微控制器的引脚配置 FRDM-MCXA153搭载了一颗型号为 MCXA153VLH 的微控制器。该微控制器采用 LQFP 64 封装,共有 64 个引脚。其中 52 个引脚可用作 GPIO。其余引脚包括电源引脚 (VDD/VSS)、USB 引脚和模拟输入引脚,这些引脚不能用作 GPIO。 然而,即使它标有“52个GPIO”,这并不意味着这52个引脚都专用于GPIO。许多可用于GPIO的引脚也与其他外设功能(例如UART、SPI、I²C和定时器)共享。因此,要真正将它们用作GPIO,您需要使用PinMUX函数将这些引脚配置为GPIO。 让我们从数据手册中查看MCX A153的引脚配置。从第54页开始列出了每个引脚可以分配的功能。 例如,查看引脚名称为 P1_8 的“引脚复用分配”信息,可以看到有六种可能的功能。GPIO 被分配到“ALT0 - P1_8”。其他分配包括“ALT2 - LPUART1_RXD”,表示它将被用作 UART 接收端 (RXD);以及“ALT3 - LPI2C0_SDA”,表示它将被用作 I²C 数据线 (SDA)。 如您所见,一个引脚可以分配给多个功能,不仅包括 GPIO,还包括 UART、I²C 和定时器。   GPIO 使用设置 1. 选择引脚功能(PinMUX) 如前文所述,P1_8 引脚有多种潜在功能,包括 GPIO、UART 和 I²C。但是,同一个引脚不能同时用作 GPIO 和 UART。 因此,典型的微控制器都配备了一种称为 PinMUX 的机制。 PinMUX 就像一个拨动开关,用于将单个物理引脚连接到内部外设。 例如,P1_8 有六个潜在的连接目标。通过使用 PinMUX 选择 GPIO,P1_8 即可用作 GPIO 引脚。 2. 设置引脚的电气特性。 引脚不仅可以配置其功能,还可以配置其电气特性。典型设置包括: • 引体向上 • 下拉 驱动力 明渠 以下是一些示例。例如,开关输入通常会启用上拉电阻,驱动 LED 或高速信号时可以调整驱动强度。即使用作 GPIO,也必须根据应用进行适当的电气设置。 本文将省略对这些电气特性的详细解释。 3. 设置 GPIO 的输入/输出方向。 最后一步是确定信号流的方向。GPIO 有两种主要的工作模式。 • 输入 – 接收来自外部的信号 • 输出 – 向外部发送信号 微控制器内部在输入输出方面究竟发生了什么? MCX A153 是一款工作电压为 3.3V 的微控制器。因此,其 GPIO 引脚基本上处理两种状态:低电平(约 0V)和高电平(约 3.3V)。A153 的工作电压范围为 1.71V 至 3.6V,FRDM 板使用 3.3V。 GPIO输出值 引脚电压 低(0) 大约 0V 高(1) 约3.3伏 例如,如果您将某个 GPIO 引脚设置为输出并连接一个外部 LED,将其设置为高电平(约 3.3V)会在 GPIO 引脚和 GND 之间产生电位差,从而允许电流流过 LED。将其设置为低电平(约 0V)会消除与 GND 之间的电位差,因此没有电流流过。换句话说,LED 的“闪烁”是由于 GPIO 引脚的电压在高电平 (1) 和低电平 (0) 之间反复切换,从而导致 LED 闪烁和熄灭交替发生。 另一方面,在输入模式下,微控制器会监控GPIO引脚的状态。例如,如果从外部电路输入约3.3V电压,则识别为高电平(1);如果输入约0V电压,则识别为低电平(0)。 上述引脚功能选择、电气特性设置和输入/输出设置均可通过 GUI 使用引脚工具(NXP 的免费配置工具中包含)进行配置。   检查引脚与电路板(FRDM-MCXA153)之间的关系。 到目前为止,我们已经了解到,要使用 GPIO,需要配置 PinMUX 设置和输入/输出方向设置。 接下来,让我们确认 FRDM-MCXA153 板上 MCU 引脚的连接位置,同时牢记我们将要进行的演示。 检查原理图,确认上一章中作为示例使用的引脚“P1_8”的布线位置。 查看电路图第 8 页,我们可以看到 P1_8 连接到 FRDM-MCXA153 上的Arduino 接头 J2 的 D18 。 FRDM-MCXA153原理图 那么,Arduino 接头 J2 上的 D18 在哪里呢? 接下来,我们来查阅一下电路板用户手册。 FRDM-MCXA153 开发板用户手册 第 6 页包含板上安装的连接器的示意图,这使我能够确定 Arduino 接头 J2 上的 D18 的位置。 在本练习中,我们将使用面包板上的 D18 引脚连接一个外部 LED。但是,如果您没有面包板或 LED,也可以使用 FRDM-MCXA153 开发板上自带的 RGB LED。 然而,有一点需要注意。当使用板载 RGB LED 时,LED 的阳极 (+) 连接到 VDD_BOARD (3.3V),阴极 (-) 连接到 GPIO。因此,与前面提到的外接 LED 不同,将 GPIO 设置为高电平 (1) 也会使 GPIO 电压达到约 3.3V,LED 两端的电位差几乎消失,导致 LED 熄灭。 另一方面,将 GPIO 设置为低电平 (0) 会在 LED 两端产生电位差,从而导致电流流动并使 LED 点亮。 当你检查电路图中的每个引脚时…… P3_12 是一个红色 LED P3_13 是一个绿色 LED P3_0 是一个蓝色 LED 它支持这些功能。通过配置引脚复用器 (PinMUX) 设置和输入/输出设置,您还可以使用板上的 LED 指示灯来验证其运行情况。 这样,您就可以使用电路图和电路板用户手册来检查微控制器内部的物理引脚在电路板上的连接位置。   演示:执行 GPIO 设置并体验 LED 控制。 在本章中,我们将使用 MCUXpresso 配置工具中的引脚工具来配置 GPIO 并控制面包板上外部连接的 LED。 演示中使用的设备: FRDM-MCXA153 面包板 LED • 电阻器和跳线 本演示将假设您已在 VS Code 环境中安装了 MCUXpresso SDK 和配置工具。 *如果您尚未安装 MCUXpresso SDK 和配置工具,请参阅此博客文章。 MCUXpresso 配置工具:引脚工具的使用方法(日语博客) 注意:虽然博客文章描述了 FRDM-MCXN947 的 SDK 安装,但本文中请安装 FRDM-MCXA153 的 SDK。 我手头有一个红色LED和一个绿色LED,但我不知道它们的型号,所以我先尝试点亮红色LED。我有一个390Ω的电阻。红色LED的正向电压(Vf)通常在1.8~2.2V之间,所以我假设它是2.0V,并计算流过LED的电流。 微控制器的工作电压为3.3V。Vf使用 2.0V 电压和 390Ω 电阻,可以根据欧姆定律计算电流值,如下所示。请注意,LED 具有规定的最大正向电流 (Ifmax),许多通用 LED 的 Ifmax 为 20mA。务必谨慎选择电阻值,因为超过 20mA 的电流可能会损坏 LED。 此外,GPIO引脚的输出电流也有限制。根据数据手册,MCX A153在正常工作状态下的电气特性是基于4mA电流(高驱动引脚为6mA)设定的。因此,当使用GPIO引脚直接点亮LED时,需要选择一个合适的电阻值,该电阻值不仅要考虑LED的电流限制,还要考虑GPIO引脚的电流限制。 电路板和面包板接线 首先,我们要进行线路连接。 在 FRDM 板上,我们将使用之前确定的 Arduino 接头 J2 上的“D18”和“14 GND” 。 下图是根据电路板用户手册绘制的。 FRDM-MCXA153 开发板用户手册 请参考以下视频了解接线说明。 (function() { var wrapper = document.getElementById('lia-vid-6405195304112w960h540r888'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (显示我的视频) 导入示例代码 接下来,我们将从 FRDM-MCXA153 SDK 导入示例代码。 点击左侧面板中的“从存储库导入示例”。 在右侧显示的选项卡中,选择“存储库”下的导入的 FRDM-MCXA153 SDK,然后选择“板”下的 FRDM-MCXA153。 使用的模板是“driver_examples/gpio/gpio_led_output”。 选择所需的工具链,然后单击“导入”。 导入完成后,它将被添加到左侧面板的“项目”部分。 查看源代码 gpio_led_output.c。 这次,我们要使用引脚工具配置 GPIO 输入/输出设置,因此我们将从源代码中删除红色方框内包含的 GPIO 输出设置代码。 使用引脚工具配置GPIO设置。 接下来,打开配置工具。右键单击项目,然后选择“使用 MCUXpresso 配置工具打开”。稍等片刻,配置工具将启动。 打开配置工具后,首先在右侧面板的“概览”中选择“引脚”。 图钉工具现已打开。 启用引脚 P1_8。 点击 P1_8 将打开另一个窗口,如下图所示。在此窗口中找到“GPIO1:GPIO,8(P1_8)”,并勾选其旁边的复选框。 选中该复选框后,将出现以下窗口,但您可以单击“否”将其关闭。 完成这些步骤后,P1_8 将添加到引脚工具底部的布线详细信息中。 接下来,按如下方式更改 GPIO 输入/输出设置。 将输出端的引脚 #38 (P3_12) 连接到未指定端,将未指定端的引脚 #2 (P1_8) 连接到输出端。 GPIO #38 的初始状态将出现错误,请将其从逻辑 0 更改为 n/a。 完成这些步骤后,您就可以重写示例代码了。首先,点击“配置工具”屏幕左上角的“更新代码”。 此时会弹出一个窗口。您可以在这里根据需要查看代码更改。已修改的文件旁边会显示“更改”字样。 返回 VS Code 后,您会在屏幕顶部看到三个复选框。请确保选中它们,然后单击“确定”。 不久之后,源代码的修改就会完成。 接下来,我们将修改源代码 gpio_led_output.c 中的 GPIO 控制目标。 打开 gpio_led_output.c 文件时, 内容如下:   while (1) { delay(); GPIO_PortToggle(BOARD_LED_GPIO, 1u << BOARD_LED_GPIO_PIN); } 按如下方式修改 GPIO_PinInit() 和 GPIO_PortToggle() 的内容: 这里,P1_8 被指定为控制目标,每次调用该函数时,P1_8 的状态都会在高 (1) 和低 (0) 之间切换。 while (1) { delay(); GPIO_PortToggle(GPIO1, 1u << 8); } 更多详情:GPIO 引脚以 Px_y 格式表示,其中x为 GPIO 端口号, y为该端口内的位位置。例如, P1_8表示“GPIO 端口 1 的第 8 位”。 在代码中 GPIO_PortToggle(GPIO1, 1U << 8); 在, GPIO1 1U << 8 表示 GPIO 端口 1, 是一个位掩码,其中只有第 8 位设置为 1。 1U << 8 ↓ 0000 0001 0000 0000 (2進数) 这样就可以只反转(在高电平和低电平之间切换)GPIO 端口 1 中的第 8 位。 将 PC 连接到 FRDM-MCXA153。 调试(构建、编写和运行应用程序)。 调试过程完成后,程序将在断点处停止,因此请点击屏幕顶部的“|▶”图标。 LED灯将开始闪烁。 (function() { var wrapper = document.getElementById('lia-vid-6404528566112w304h540r105'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (显示我的视频) 额外知识——了解 LED 的“开/关”状态 顺便问一下,这个LED灯何时亮起,取决于GPIO输出是高电平(1)还是低电平(0)?我之前提到过,当输出高电平(1)时它会亮起,但我们来验证一下是否正确。 以下是我们之前使用的代码。 `while(1)` 语句表示一个无限循环,重复执行花括号 {} 内的代码。 此外,delay() 函数用于等待特定时间段。GPIO_PortToggle() 是一个 GPIO 控制函数,用于反转高电平 (1) 和低电平 (0)。 while (1) { delay(); GPIO_PortToggle(GPIO1, 1u<<8); } } 但是,这段代码并没有告诉我们,当 LED 为高电平 (1) 或低电平 (0) 时,LED 是亮起还是熄灭。 因此,我们使用不同的函数 GPIO_PinWrite() 来显式控制 GPIO 的状态。 具体来说,代码将修改为在高电平 (1) 状态下等待一次 delay() 调用,然后在低电平 (0) 状态下等待五次 delay() 调用。这样应该能让 LED 保持熄灭状态更长时间。 while (1) { GPIO_PinWrite (GPIO1,8U ,1); delay(); GPIO_PinWrite(GPIO1,8U ,0); delay(); delay(); delay(); delay(); delay(); } 运行调试程序,然后点击屏幕顶部的“|▶”图标。 (function() { var wrapper = document.getElementById('lia-vid-6404528052112w304h540r114'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (显示我的视频) 正如预期的那样,LED灯关闭了更长时间。 这使我们能够验证 LED 在点亮时输出高电平 (1),在熄灭时输出低电平 (0)。 总结一下,当 GPIO 为高电平 (1) 时,设置为 GPIO 引脚的 P1_8 处的电压约为 3.3V。该电压与 GND 之间形成电位差,导致电流流过电阻和 LED。此时,LED 两端施加正向电压(约 2.0V),剩余的约 1.3V 电压施加在电阻两端。因此,LED 点亮。 另一方面,当 GPIO 为低电平 (0) 时,P1_8 端的电压接近 0V。由于 GPIO 引脚与 GND 之间没有电位差,因此没有电流流过,LED 熄灭。 如果你觉得使用大量的 `delay()` 函数看起来很丑陋,你也可以使用循环函数。 while (1) { GPIO_PinWrite(GPIO1, 8U, 1); delay(); GPIO_PinWrite(GPIO1, 8U, 0); for (int i = 0; i < 5; i++) { delay(); } } 附加题——如果将两个LED并联会发生什么? 我尝试将手边的一个绿色LED与一个红色LED并联起来。 由于绿色 LED 的正向电压 (Vf) 一般为 2.0 至 2.2V,我假设它与红色 LED 类似,为 2.0V,并搭建了以下电路。 由于无需更改引脚设置,我使用之前的代码进行调试,红色 LED 闪烁,但绿色 LED 没有闪烁。这是为什么呢? (function() { var wrapper = document.getElementById('lia-vid-6404530194112w304h540r514'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (显示我的视频) LED的特性是,当正向电压(Vf)超过其值时,电流会迅速增加。因此,如果将一个红色LED和一个绿色LED简单地并联,电流会集中在Vf较低的LED上,而另一个LED可能几乎不会发光。在这种情况下,红色LED的Vf低于绿色LED,因此电流集中在红色LED上。 当我用测试仪实际测量 LED 两端的电压时,红色 LED 的电压为 1.765V,绿色 LED 的电压为 1.766V。 在这个电压下,红色LED可以点亮,但绿色LED接收到的电压不足以产生足够的电流。因此,红色LED会亮,而绿色LED不会亮,因为几乎没有电流流过它。 如上图所示,简单地将不同类型的LED并联,即使正向电压(Vf)存在微小差异,也会导致电流出现显著偏差。因此,并联LED时,通常的做法是为每个LED串联一个限流电阻。 添加电阻时,需要考虑 GPIO 的电流限制。如果我们像之前那样直接添加一个 390Ω 的电阻并计算电流,那么施加到 GPIO 上的电流将超过 6mA。因此,为了确保总电流不超过 4mA,我们连接了两个 680Ω 的电阻,并搭建了以下电路。 当我再次调试同一段代码时,红色和绿色 LED 都亮了起来。 (function() { var wrapper = document.getElementById('lia-vid-6405719291112w304h540r698'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (显示我的视频) 测量LED两端的电压时,红色LED的电压为1.750V,绿色LED的电压为1.906V。通过在每个LED上串联一个电阻,可以使合适的电流流过每个LED。 本文解释了嵌入式开发初学者会遇到的“问题”和“障碍”,内容涵盖如何解读各种文档、使用配置工具以及LED的工作原理等。我们希望本文能对那些首次尝试使用NXP微控制器实现LED闪烁的用户有所帮助。 =========================​ 我们目前无法 回复 此帖子“ 评论”部分留下的评论。 对于由此造成的不便,我们深表歉意,但 在进行咨询时, 请 参考“ NXP 技术问题 - 如何联系我们 ( 日语博客 ) ” 。 (如果您已经是 恩智浦的 分销商或 与 恩智浦 有合作关系 ,您可以直接咨询您的代表。) 本文以 LED 闪烁为例,解释了如何使用 GPIO(通用输入/输出),这是微控制器开发中最基本的外部设备之一。 GPIO 是许多微控制器开发人员最先接触的外设之一。很多人想用 GPIO 来点亮 LED,但他们可能不知道如何阅读数据手册或如何配置引脚。本文以 FRDM-MCXA153 为例,讲解 GPIO 的基础知识,面向微控制器开发初学者。我们将学习如何从数据手册和电路图中读取引脚信息,如何使用引脚工具配置设置,并最终体验如何控制外部 LED。 (预计时间:15 分钟)*假设开发环境已安装。 MCUXpresso MCUXpresso 配置工具 MCUXpresso IDE MCUXpresso SDK MCX 日本博客
View full article
GPIO入門:マイコン(MCX A153)のピンを読み解き、LEDを制御する方法(日本語ブログ) 目次 はじめに MCX A153マイコンのピン構成を理解する GPIOを使用するための設定 ピンとボード(FRDM-MCXA153)の関係を確認する デモンストレーション:GPIO設定を行いLED制御を体感する おまけ LEDの「点・滅」について理解する おまけ – 2つのLEDを並列に接続したら?   はじめに 組み込み開発初心者である筆者は、「GPIOについて記事を書いてほしい」という依頼をきっかけにGPIOの学習を始めました。本記事は、LEDを一つ点灯させるために試行錯誤する中で学んだ内容や気づきを、備忘録としてまとめたものです。 本記事では、マイコンを使った開発において最も基本的なペリフェラルの一つであるGPIO(General Purpose Input/Output)の使い方を解説します。 GPIOは、LEDを点灯したり、スイッチの状態を読み取ったり、センサからの信号を受け取ったりと、マイコンと外部回路をつなぐための組み込みシステムの基盤となっています。 一方で、実際のマイコン開発において、「GPIOを使う」と言っても、単にプログラムを書くだけではありません。マイコンには多数のピンが存在し、それぞれのピンにはGPIO以外にもタイマや通信インターフェースなどの機能が割り当てられています。 そのため、 GPIOを利用するには、データシートからピンの配置や機能を理解すること GPIOをピンに割り当てるためのPinMUX(ピン・マルチプレックス)設定 入出力方向の設定 を適切に行う必要があります。 今回はFRDM-MCXA153を題材に、MCX A153のピン構成やPinMUXの仕組みを確認しながら、Pins Tool上でGPIO設定を行い、最終的にはブレッドボード上に接続したLED点滅のデモンストレーションを紹介します。   MCX A153マイコンのピン構成を理解する FRDM-MCXA153にはMCXA153VLHという型番のマイコンが搭載されています。このマイコンはLQFP 64パッケージを採用しており、全部で64本のピンが存在します。そのうち52本がGPIOとして利用可能です。残りは電源端子(VDD/VSS)やUSB端子、アナログ専用端子などGPIOとして利用できない端子で構成されています。 ただし、「52本のGPIOがある」といっても、52本のGPIO専用ピンが用意されているわけではありません。GPIOとして利用可能なピンの多くは、UARTやSPI、I²C、タイマなどの周辺機能と共有されています。そのため、実際にGPIOとして利用する際には、PinMUX機能を使い、そのピンをGPIOとして動作させるための設定が必要になります。 MCX A153のピン構成をデータシートから確認してみます。54ページ以降に各ピンに割り当て可能な機能が一覧で記載されています。 例えば、Pin Name :P1_8 の「Pinmux Assignment」を見ると、6つの機能候補があります。GPIOは”ALT0 - P1_8”が該当します。他にも”ALT2 - LPUART1_RXD”はUARTの受信端子(RXD)、”ALT3 - LPI2C0_SDA”はI²Cデータ線(SDA)として使用することを意味します。 このように1本のピンに対してGPIOだけでなく、UARTやI²C、タイマなどの複数の機能が割り振られていることがわかります。   GPIOを使用するための設定 1. ピン機能の選択(PinMUX) 前節で確認したように、P1_8にはGPIO、UART、I²Cなど複数の機能候補が存在します。しかし、同じピンを同時にGPIOとUARTとして利用することはできません。 そこで一般的なマイコンには PinMUXという仕組みが用意されています。 PinMUXは、1本の物理ピンと内部ペリフェラルを接続するための切替スイッチのようなものです。 例えばP1_8には6つの接続先候補がありました。PinMUXによってGPIOを選択すると、P1_8はGPIOとして利用することができるようになります。 2. ピンの電気的特性を設定する ピンには機能だけでなく、電気的な振る舞いも設定できます。 代表的な設定として、 ・Pull-up(プルアップ) ・Pull-down(プルダウン) ・Drive Strength(ドライブ強度) ・Open Drain(オープンドレイン) などがあります。 例えばスイッチ入力ではプルアップ抵抗を有効にすることが多く、LEDや高速信号を駆動する場合にはドライブ強度を調整することがあります。 GPIOとして使用する場合でも、アプリケーションに応じた適切な電気的設定を行うことが重要です。 本記事ではこの電気的特性に関する詳細な説明は割愛します。 3. GPIOの入出力方向を設定する 最後に決めるのが信号の流れる方向です。GPIOには大きく分けて2つの動作モードがあります。 ・Input(入力) – 外部から信号を受け取る ・Output(出力) – 外部へ信号を出力する Input・Outputとはマイコン内部で何が起こっているのでしょうか? MCX A153は3.3Vで動作するマイコンです。そのためGPIOピンは、基本的にLow(約0V)とHigh(約3.3V)の2つの状態を扱います(なお、MCX A153の動作電圧範囲は1.71V〜3.6Vであり、FRDMボードでは3.3Vが採用されています)。 GPIO出力値 ピン電圧 Low (0) 約0V High (1) 約3.3V 例えば特定のGPIOピンをOutputに設定し、外部にLEDを接続した場合、High(約3.3V)にするとGPIOとGNDの間に電位差が生じ、LEDに電流が流れ、Low(約0V)の状態にするとGNDとの電位差がなくなるので電流が流れなくなります。つまり、LEDの”点滅”はGPIOピンの電圧をHigh(1)とLow(0)の間で切り替えることで点滅と消灯という動作を繰り返していることになります。 一方、InputではGPIOピンの状態をマイコンが監視します。例えば外部回路から約3.3Vが入力されればHigh(1)、約0Vが入力されればLow(0)として認識します。 ここまで説明したピンの機能選択・電気的特性の設定・入出力設定はPins Tool(Pins ToolはNXPが無償提供しているConfig Toolsに含まれます)を用いてGUI上で設定することが可能です。   ピンとボード(FRDM-MCXA153)の関係を確認する ここまでで、GPIOを利用するためにはPinMUX設定や入出力方向の設定が必要であることが分かりました。 続いて今回のデモンストレーションを想定し、MCUのピンがFRDM-MCXA153ボード上のどこに接続されているのかを確認しておきましょう。 Schematics(回路図)を確認し、前章で例として取り上げたピン "P1_8"はどこに引き出されているのかを確認します。 回路図の8ページを見てみると、P1_8はFRDM-MCXA153上にあるArduinoヘッダー: J2のD18に接続されていることがわかります。 FRDM-MCXA153 Schematics では、Arduinoヘッダー J2のD18とはどこでしょうか? 続いてBoard User Manualを確認します。 FRDM-MCXA153 Board User Manual 6ページ目にボードに搭載されているコネクタの外観図が載っており、ArduinoヘッダーJ2のD18はどこかを特定することができました。 今回は勉強のため、D18ピンからブレッドボードを経由してLEDを外部接続しますが、ブレッドボードやLEDをお持ちでない場合は、FRDM-MCXA153のボード上に搭載されているRGB LEDを活用することができます。 ただし一点注意があります。ボード上のRGB LEDを使用する場合はLEDのアノード側(+)がVDD_BOARD(3.3V)に接続されており、カソード側(-)がGPIOに接続されています。そのため、先ほどの外部接続したLEDとは逆でGPIOをHigh(1)にするとGPIO側も約3.3Vとなり、LED両端の電位差がほとんどなくなるためLEDは消灯します。 一方、GPIOをLow(0)にするとLED両端に電位差が生じて電流が流れ、LEDは点灯します。 回路図でそれぞれのピンを確認すると P3_12は赤色LED P3_13は緑色のLED P3_0は青色LED に対応しています。これらのPinMUX設定や入出力設定を行うことでボードに搭載されているLEDを使った動作を確認することもできます。 このように回路図やBoard User Manualを使って、マイコン内部の物理ピンがボード上のどこに接続されているかを確認することができます。   デモンストレーション:GPIO設定を行いLED制御を体感する この章では、MCUXpresso Config Toolsの Pins Tool を使用してGPIOの設定を行い、ブレッドボード上に外部接続したLEDを制御してみます。 デモンストレーションで使用した備品 ・FRDM-MCXA153 ・ブレッドボード ・LED ・抵抗 ・ジャンパ線 また今回はVS Code環境にてMCUXpresso SDKとConfig Toolsをインストール済みという前提でデモンストレーションを進めます。 ※MCUXpresso SDKとConfig Toolsのインストールがお済みでない方はこちらのブログをご参照ください。 MCUXpresso Config Tools : Pins Toolの使い方 (日本語ブログ) 注意:ブログ内ではFRDM-MCXN947のSDKをインストールしていますが本記事においてはFRDM-MCXA153のSDKをインストールしてください。 手元に品番不明の赤色LEDと緑色LEDがあったので、まずは赤色LEDの点灯から試してみます。抵抗は390Ωのものがありました。赤色LEDの順方向電圧(Vf)は一般的に1.8~2.2Vのため、仮に2.0VとしてLEDに流れる電流値を求めます。 マイコンの動作電圧は3.3Vです。Vf 2.0Vと抵抗390Ωを用いると、オームの法則から以下のように電流値が求められます。なおLEDには最大順方向電流(Ifmax)が規定されており、多くの汎用LEDでは20mAと言われています。20mAを超える電流が流れると破損する可能性があるので抵抗値にはご注意ください。 また、GPIOにも出力可能な電流に制限があります。データシートを参照するとMCX A153の通常動作時の電気特性は4mA(High Drive対応ピンでは6mA)を基準として規定されています。このため、GPIOからLEDを直接点灯する場合は、LEDだけでなくGPIO側の電流制限も考慮して抵抗値を選定する必要があります。 ボードとブレッドボードの配線 はじめに配線を行います FRDMボード上では、先ほど特定した ArduinoヘッダーJ2の"D18"と"14 GND"を使用します。 以下の図はBoard User Manualを参照しています。 FRDM-MCXA153 Board User Manual 以下の動画を参考に配線してください。 (function() { var wrapper = document.getElementById('lia-vid-6405195304112w960h540r888'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (マイビデオを表示) サンプルコードのインポート 続いて、FRDM-MCXA153のSDKからサンプルコードのインポートへ進みます。 左側のパネルから「Import Example From Repository」をクリックしてください。 右側に表示された各タブ内で、「Repository」ではインポートしたFRDM-MCXA153のSDKを選択、「Board」はFRDM-MCXA153を選択してください。 「Template」は、「driver_examples/gpio/gpio_led_output」を使用します。 任意のToolchainを選択して、「Import」をクリックしてください。 Importが完了すると左側のパネルのProjectsに追加されます。 ソースコード gpio_led_output.cを確認します。 今回は、Pins Toolを用いてGPIOの入出力設定を行いたいので、ソースコード側から赤枠で囲んだGPIO出力設定に関する記述を削除します。 Pins ToolでGPIOの設定を行う 続いてConfig Toolsを開きます。Project上で右クリックして「Open with MCUXpresso Config Tools」を選択してください。少し待つとConfig Toolsが立ち上がります。 Config Toolsが開いたらまずは右側のパネルにあるOverviewよりPinsを選択します。 これでPins Toolが開いた状態になりました。 ピンP1_8を有効にします。 P1_8をクリックすると、下記画像のように別のWindowが開くので、ここから「GPIO1:GPIO,8(P1_8)」を探して✓を入れてください。 ✓を入れると同時に下記のWindowが表示されますがNoで閉じていただいて問題ありません。 ここまで完了するとPins Tool下部のRouting DetailsにP1_8が追加されます。 続いてGPIOの入出力設定を以下のように変更します。 #38(P3_12)のピンをOutput → Not Specifiedへ、#2(P1_8)のピンをNot Specified → Output へ。 #38のGPIO initial stateにエラーが出ますので、Logical 0→n/aへ変更してください。 ここまで完了したらサンプルコードを書き換えます。まずはConfig Toolsの画面左上にあるUpdate Codeをクリックしてください。 その後Windowが表示されます。ここで必要に応じてコードの変更点を確認することができます。変更が生じたファイルには「change」の記載があります。 VS Codeに戻ると、画面上部に3つのチェックボックスが表示されているので✓が入った状態でOKをクリックします。 少し時間が経つと、ソースコードへの変更が完了します。 続いてソースコード gpio_led_output.cよりGPIOの制御対象を変更します。 gpio_led_output.cを開くと、 以下の記述があります。   while (1) { delay(); GPIO_PortToggle(BOARD_LED_GPIO, 1u << BOARD_LED_GPIO_PIN); } GPIO_PinInit()およびGPIO_PortToggle()の中身を以下のように変更します。 ここではP1_8を制御対象として指定しており、関数が呼ばれるたびにP1_8の状態がHigh(1)とLow(0)の間で切り替わります。 while (1) { delay(); GPIO_PortToggle(GPIO1, 1u << 8); } さらに詳しく:GPIOピンは Px_y という形式で表記されます。ここで x はGPIOポート番号、y はそのポート内のビット位置を表します。例えば P1_8 は「GPIOポート1の8ビット目」を意味します。 コード中の GPIO_PortToggle(GPIO1, 1U << 8); において、 GPIO1 はGPIOポート1を表し、 1U << 8 は8ビット目だけを1にしたビットマスクです。 1U << 8 ↓ 0000 0001 0000 0000 (2進数) となり、GPIOポート1の中の8ビット目のみを反転(HighとLowを切り替える)させることができます。 PCとFRDM-MCXA153を接続します。 デバッグ(ビルド&書き込み&アプリケーションの実行)します。 デバッグのプロセスが完了したら、プログラムがブレイクポイントで止まっているので、画面上部のアイコン内の"|▶"をクリックします。 LEDが点滅を開始します。 (function() { var wrapper = document.getElementById('lia-vid-6404528566112w304h540r105'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (マイビデオを表示) おまけ – LEDの「点・滅」について理解する  ところで、このLEDはGPIOからHigh(1) , Low(0) どちらを出力したときに点灯しているのでしょうか?先ほどはHigh(1)を出力したときに点灯していると言及しましたが、本当か検証してみます。 以下が先ほど使用したコードです。 while(1)は無限ループを意味し、波括弧{}の中の処理を繰り返し実行します。 また、delay()は一定時間待機するための関数です。GPIO_PortToggle()はGPIO制御関数なので、High(1)とLow(0)を反転します。 while (1) { delay(); GPIO_PortToggle(GPIO1, 1u<<8); } } しかしながら、このコードではLEDがHigh(1)のときに点灯しているのか、Low(0)のときに点灯しているのかがわかりません。 そこで異なる関数GPIO_PinWrite() を使用して、GPIOの状態を明示的に制御します。 具体的には以下のようにHigh(1)の状態でdelay()1回分待機し、その後Low(0)の状態でdelay()5回分待機するコードへ変更します。これでLEDの消灯時間のほうが長くなるはずです。 while (1) { GPIO_PinWrite (GPIO1,8U ,1); delay(); GPIO_PinWrite(GPIO1,8U ,0); delay(); delay(); delay(); delay(); delay(); } デバッグを実行し、画面上部のアイコン内の"|▶"をクリックします。 (function() { var wrapper = document.getElementById('lia-vid-6404528052112w304h540r114'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (マイビデオを表示) 狙い通り、LEDの消灯時間のほうが長くなりました。 これによりLEDが点灯しているときにはHigh(1)を出力し、消灯しているときにはLow(0)を出力していることが検証できました。 おさらいすると、GPIOがHigh(1)になると、GPIOピンとして設定したP1_8は約3.3Vになります。GNDとの間に電位差が生じるため、抵抗とLEDを通して電流が流れます。このときLEDの両端には順方向電圧(約2.0V)がかかり、残りの約1.3Vが抵抗にかかります。その結果、LEDが発光します。 一方、GPIOがLow(0)になるとP1_8の電圧は約0Vになります。GPIOピンとGNDの間に電位差がなくなるため電流は流れず、LEDは消灯します。 delay()がたくさん並ぶのはかっこ悪いという方はループ関数も使えます。 while (1) { GPIO_PinWrite(GPIO1, 8U, 1); delay(); GPIO_PinWrite(GPIO1, 8U, 0); for (int i = 0; i < 5; i++) { delay(); } } おまけ – 2つのLEDを並列に接続したら? 手元にあった緑色のLEDを赤色LEDと並列接続しようと試みました。 緑色の順方向電圧(Vf)は一般的に2.0~2.2Vのため、赤色LEDと同様に仮に2.0Vとして以下のような回路を組みました。 ピンの設定は変える必要がないため、そのまま先ほど使ったコードでデバッグを行ったところ、赤色LEDは点滅しますが緑色LEDは点滅しません。なぜでしょうか? (function() { var wrapper = document.getElementById('lia-vid-6404530194112w304h540r514'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (マイビデオを表示) LEDには、順方向電圧(Vf)を超えると急激に電流が流れ始めるという特性があります。そのため赤色LEDと緑色LEDを単純に並列接続すると、Vfの低いLEDに電流が集中し、もう一方はほとんど点灯しないことがあります。つまり今回の場合は赤色LEDのVfが緑色LEDに比べて低いので、赤色LEDに電流が集中したという状態となっています。 実際にテスターでLED両端の電圧を測定したところ、赤色LEDは1.765V , 緑色LEDは1.766Vでした。 この電圧では赤色LEDは発光できるものの、緑色LEDは十分な電流が流れるほどの電圧に達していません。その結果、赤色LEDには電流が流れて点灯しますが、緑色LEDにはほとんど電流が流れず点灯しませんでした。 このように、LEDを異なる種類のまま単純に並列接続すると、わずかなVfの差によって電流の流れ方が大きく偏ることがあります。そのためLEDを並列接続する場合は、LEDごとに電流制限抵抗を設けるのが一般的です。 抵抗を追加する際にはGPIOの電流制限を考慮する必要があります。単純にこれまで使ってきた390Ωをひとつ追加して電流値を計算すると計算上では6mAを超える電流がGPIOに掛かってしまいます。したがって、総電流が4mA超えないよう680Ωの抵抗を2つ接続し、以下のような回路を組みました。 再度同じコードでデバッグを行ったところ、赤色LED、緑色LEDともに点灯しました。 (function() { var wrapper = document.getElementById('lia-vid-6405719291112w304h540r698'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (マイビデオを表示) LED両端の電圧を測定したところ、赤色LEDは1.750V , 緑色LEDは1.906Vでした。抵抗をそれぞれのLEDに追加したことで、各LEDに適切な電流が流れるようになりました。 以上、今回は各種ドキュメントの読み解き方、Config Toolsの使い方からLEDの動作原理にいたるまで組み込み開発初心者の目線から「困った」「詰まった」点を解説しました。NXPマイコンを使って初めてLチカにチャレンジするという方のご参考になれば幸いです。 =========================​ 本投稿の「Comment」欄にコメントをいただいても、現在返信に対応しておりません。​ お手数をおかけしますが、お問い合わせの際には「NXPへの技術質問 - 問い合わせ方法 (日本語ブログ)」をご参照ください。​ (既に弊社NXP代理店、もしくはNXPとお付き合いのある方は、直接担当者へご質問いただいてもかまいません。) マイコンを使った開発において最も基本的なペリフェラルの一つであるGPIO(General Purpose Input/Output)をLEDの点滅を例に使い方を解説します。 GPIOは多くのマイコン開発者が最初に学ぶペリフェラルです。GPIOを使ってLEDを光らせてみたいけれど、「データシートの見方がわからない」「ピンの設定方法がわからない」という方も多いのではないでしょうか。本記事ではマイコン開発初心者向けに、FRDM-MCXA153を使ったGPIO入門を解説します。データシートや回路図からピン情報を読み解き、Pins Toolを使った設定を行いながら、最終的に外部LEDの制御を体験します。 (作業時間:15分) ※開発環境をインストール済みの前提 MCUXpresso MCUXpresso Conig Tools MCUXpresso IDE MCUXpresso SDK MCX 日本語ブログ
View full article
GPIO Introduction: How to Read the Pins of a Microcontroller (MCX A153) and Control an LED (Japanese Blog) table of contents Introduction Understanding the pin configuration of the MCX A153 microcontroller Settings for using GPIO Check the relationship between the pins and the board (FRDM-MCXA153). Demonstration: Perform GPIO settings and experience LED control. Bonus: Understanding the "on/off" of LEDs Bonus – What happens if you connect two LEDs in parallel?   Introduction As a beginner in embedded systems development, I began learning about GPIO after receiving a request to write an article about it. This article is a record of what I learned and the insights I gained through trial and error while trying to light up a single LED. This article explains how to use GPIO (General Purpose Input/Output), one of the most basic peripherals in microcontroller development. GPIO is the foundation of embedded systems for connecting microcontrollers to external circuits, enabling functions such as turning on LEDs, reading the state of switches, and receiving signals from sensors. On the other hand, in actual microcontroller development, "using GPIO" doesn't simply mean writing a program. Microcontrollers have numerous pins, and each pin is assigned functions other than GPIO, such as timers and communication interfaces. Therefore, To use GPIO, you need to understand the pin assignments and functions from the datasheet. PinMUX (pin multiplex) settings for assigning GPIO to pins Input/Output Direction Settings This needs to be done properly. This time, using the FRDM-MCXA153 as an example, we will examine the pin configuration of the MCX A153 and the mechanism of PinMUX, configure GPIO settings using Pins Tool, and finally demonstrate blinking LEDs connected to a breadboard.   Understanding the pin configuration of the MCX A153 microcontroller The FRDM-MCXA153 is equipped with a microcontroller with the model number MCXA153VLH. This microcontroller uses an LQFP 64 package and has a total of 64 pins. Of these, 52 are available as GPIOs. The remaining pins consist of power terminals (VDD/VSS), USB terminals, and analog-only terminals, which cannot be used as GPIOs. However, even though it has "52 GPIOs," this doesn't mean that 52 pins are dedicated to GPIO. Many of the pins available for GPIO use are shared with peripheral functions such as UART, SPI, I²C, and timers. Therefore, to actually use them as GPIOs, you need to use the PinMUX function to configure those pins to function as GPIOs. Let's check the pin configuration of the MCX A153 from the datasheet . A list of functions that can be assigned to each pin is provided starting on page 54. For example, looking at the "Pinmux Assignment" for Pin Name: P1_8, there are six possible functions. GPIO is assigned to "ALT0 - P1_8". Other assignments include "ALT2 - LPUART1_RXD" which means it will be used as the UART receive terminal (RXD), and "ALT3 - LPI2C0_SDA" which means it will be used as the I²C data line (SDA). As you can see, a single pin can be assigned to multiple functions, including not only GPIO but also UART, I²C, and timers.   Settings for using GPIO 1. Select pin function (PinMUX) As confirmed in the previous section, P1_8 has several potential functions, including GPIO, UART, and I²C. However, the same pin cannot be used as both GPIO and UART simultaneously. Therefore, typical microcontrollers are equipped with a mechanism called PinMUX. PinMUX is like a toggle switch for connecting a single physical pin to an internal peripheral. For example, P1_8 had six potential connection destinations. By selecting GPIO using PinMUX, P1_8 becomes available for use as a GPIO pin. 2. Set the electrical characteristics of the pins. Pins can be configured not only for their function but also for their electrical behavior. Typical settings include: • Pull-up • Pull-down Drive Strength Open Drain These are some examples. For instance, pull-up resistors are often enabled for switch inputs, and the drive strength may be adjusted when driving LEDs or high-speed signals. Even when used as GPIO, it is important to make appropriate electrical settings according to the application. This article will omit a detailed explanation of these electrical characteristics. 3. Set the input/output direction of the GPIO. The final step is determining the direction in which the signal flows. GPIO has two main operating modes. • Input – Receives signals from the outside • Output – Sends signals to the outside What exactly is happening inside the microcontroller when it comes to Input and Output? The MCX A153 is a microcontroller that operates at 3.3V. Therefore, the GPIO pins basically handle two states: Low (approximately 0V) and High (approximately 3.3V).The A153 has an operating voltage range of 1.71V to 3.6V, and 3.3V is used for the FRDM board. GPIO output values Pin voltage Low (0) Approximately 0V High (1) Approximately 3.3V For example, if you set a specific GPIO pin to Output and connect an external LED, setting it to High (approximately 3.3V) creates a potential difference between the GPIO and GND, allowing current to flow through the LED. Setting it to Low (approximately 0V) eliminates the potential difference with GND, so no current flows. In other words, the "blinking" of the LED is caused by repeatedly switching the voltage of the GPIO pin between High (1) and Low (0), alternating between blinking and being off. On the other hand, in Input mode, the microcontroller monitors the state of the GPIO pins. For example, if approximately 3.3V is input from an external circuit, it is recognized as High (1), and if approximately 0V is input, it is recognized as Low (0). The pin function selection, electrical characteristic settings, and input/output settings described above can all be configured via a GUI using the Pins Tool (which is included in NXP's free Config Tools).   Check the relationship between the pins and the board (FRDM-MCXA153). So far, we've learned that in order to use GPIO, you need to configure PinMUX settings and input/output direction settings. Next, let's confirm where the MCU pins are connected on the FRDM-MCXA153 board, keeping in mind the demonstration we'll be performing. Check the schematics and confirm where pin "P1_8", which was used as an example in the previous chapter, is routed. Looking at page 8 of the circuit diagram, we can see that P1_8 is connected to D18 of Arduino header J2 on the FRDM-MCXA153. FRDM-MCXA153 Schematics So, where is D18 on the Arduino header J2? Next, let's check the Board User Manual. FRDM-MCXA153 Board User Manual Page 6 contains a diagram of the connectors mounted on the board, which allowed me to identify the location of D18 on the Arduino header J2. For this learning exercise, we will connect an external LED via a breadboard using the D18 pin. However, if you do not have a breadboard or LED, you can use the RGB LED mounted on the FRDM-MCXA153 board. However, there is one point to note. When using the RGB LED on the board, the anode (+) of the LED is connected to VDD_BOARD (3.3V), and the cathode (-) is connected to GPIO. Therefore, unlike the externally connected LED mentioned earlier, setting GPIO to High (1) will also bring the GPIO voltage to approximately 3.3V, and the potential difference across the LED will almost disappear, causing the LED to turn off. On the other hand, setting GPIO to Low (0) creates a potential difference across the LED, causing current to flow and the LED to light up. When you check each pin in the circuit diagram... P3_12 is a red LED P3_13 is a green LED P3_0 is a blue LED It supports these features. By configuring these PinMUX settings and input/output settings, you can also verify the operation using the LEDs on the board. In this way, you can use the circuit diagram and the Board User Manual to check where the physical pins inside the microcontroller are connected on the board.   Demonstration: Perform GPIO settings and experience LED control. In this chapter, we will use the Pins Tool in MCUXpresso Config Tools to configure GPIO and control an externally connected LED on a breadboard. Equipment used in the demonstration: FRDM-MCXA153 Breadboard LED • Resistors and jumper wires This demonstration will assume that you have already installed the MCUXpresso SDK and Config Tools in your VS Code environment. *If you have not yet installed the MCUXpresso SDK and Config Tools, please refer to this blog post. MCUXpresso Config Tools: How to Use the Pins Tool (Japanese Blog) Note: While the blog post describes installing the SDK for FRDM-MCXN947, please install the SDK for FRDM-MCXA153 in this article. I had a red LED and a green LED on hand, but I didn't know the part numbers, so I'll start by trying to light up the red LED. I had a 390Ω resistor. The forward voltage (Vf) of a red LED is generally 1.8~2.2V, so I'll assume it's 2.0V and calculate the current flowing through the LED. The microcontroller's operating voltage is 3.3V. VfUsing 2.0V and a 390Ω resistor, the current value can be calculated using Ohm's law as follows. Note that LEDs have a specified maximum forward current (Ifmax), which is said to be 20mA for many general-purpose LEDs. Be careful with the resistance value, as currents exceeding 20mA may cause damage. Furthermore, GPIO pins also have limitations on the current they can output. According to the datasheet, the MCX A153's electrical characteristics during normal operation are specified based on 4mA (6mA for High Drive pins). Therefore, when directly lighting an LED using a GPIO pin, you need to select a resistor value that takes into account not only the LED's current limit but also the GPIO's current limit. Board and breadboard wiring First, we'll do the wiring. On the FRDM board, we will use "D18" and "14 GND" on the Arduino header J2 that we identified earlier . The following diagram is based on the Board User Manual. FRDM-MCXA153 Board User Manual Please refer to the following video for wiring instructions. (function() { var wrapper = document.getElementById('lia-vid-6405195304112w960h540r888'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (Show My Videos) Importing sample code Next, we will proceed to import the sample code from the FRDM-MCXA153 SDK. Click "Import Example From Repository" in the panel on the left. In the tabs displayed on the right, select the imported FRDM-MCXA153 SDK under "Repository" and select FRDM-MCXA153 under "Board". The template used is "driver_examples/gpio/gpio_led_output". Select your desired Toolchain and click "Import". Once the import is complete, it will be added to the Projects section in the left-hand panel. Check the source code gpio_led_output.c. This time, we want to configure GPIO input/output settings using Pins Tool, so we will remove the GPIO output setting code enclosed in the red box from the source code. Configure GPIO settings using Pins Tool. Next, open Config Tools. Right-click on the Project and select "Open with MCUXpresso Config Tools". After a short wait, Config Tools will launch. Once Config Tools opens, first select Pins from Overview in the right-hand panel. The Pins Tool is now open. Enable pin P1_8. Clicking on P1_8 will open another window as shown in the image below. Find "GPIO1:GPIO,8(P1_8)" in this window and check the box next to it. When you check the box, the following window will appear, but you can close it by clicking No. Once you've completed these steps, P1_8 will be added to the Routing Details at the bottom of the Pins Tool. Next, change the GPIO input/output settings as follows. Connect pin #38 (P3_12) from Output to Not Specified, and pin #2 (P1_8) from Not Specified to Output. An error will occur in the GPIO initial state of #38, so please change it from Logical 0 to n/a. Once you've completed these steps, you can rewrite the sample code. First, click Update Code in the upper left corner of the Config Tools screen. A window will then appear. Here you can review the code changes as needed. Files that have been modified will have "change" written next to them. When you return to VS Code, you will see three checkboxes at the top of the screen. Make sure they are checked and click OK. After a short while, the changes to the source code will be completed. Next, we will change the target of GPIO control in the source code gpio_led_output.c. When you open gpio_led_output.c, The following is stated:   while (1) { delay(); GPIO_PortToggle(BOARD_LED_GPIO, 1u << BOARD_LED_GPIO_PIN); } Modify the contents of GPIO_PinInit() and GPIO_PortToggle() as follows: Here, P1_8 is specified as the control target, and each time the function is called, the state of P1_8 switches between High (1) and Low (0). while (1) { delay(); GPIO_PortToggle(GPIO1, 1u << 8); } Further details: GPIO pins are represented in the format Px_y, where x is the GPIO port number and y represents the bit position within that port. For example, P1_8 means "bit 8 of GPIO port 1". In the code GPIO_PortToggle(GPIO1, 1U << 8); In, GPIO1 1U << 8 represents GPIO port 1, is a bitmask where only the 8th bit is set to 1. 1U << 8 ↓ 0000 0001 0000 0000 (2進数) This allows you to invert (switch between High and Low) only the 8th bit in GPIO port 1. Connect the PC to the FRDM-MCXA153. Debugging (build, write, and run the application). Once the debugging process is complete, the program will have stopped at the breakpoint, so click the "|▶" icon at the top of the screen. The LED will start blinking. (function() { var wrapper = document.getElementById('lia-vid-6404528566112w304h540r105'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (Show My Videos) Bonus – Understanding LED "on/off" By the way, when does this LED light up, based on whether the GPIO outputs High (1) or Low (0)? Earlier I mentioned that it lights up when High (1) is output, but let's verify if that's true. The following is the code we used earlier. The `while(1)` statement implies an infinite loop, repeatedly executing the code within the curly braces {}. Additionally, delay() is a function for waiting for a certain period of time. GPIO_PortToggle() is a GPIO control function, so it inverts High (1) and Low (0). while (1) { delay(); GPIO_PortToggle(GPIO1, 1u<<8); } } However, this code doesn't tell us whether the LED is lit when it's High (1) or Low (0). Therefore, we use a different function, GPIO_PinWrite(), to explicitly control the state of the GPIO. Specifically, the code will be changed to wait for one delay() call while in a High (1) state, and then wait for five delay() calls while in a Low (0) state. This should make the LED stay off for a longer period of time. while (1) { GPIO_PinWrite (GPIO1,8U ,1); delay(); GPIO_PinWrite(GPIO1,8U ,0); delay(); delay(); delay(); delay(); delay(); } Run the debug and click the "|▶" icon at the top of the screen. (function() { var wrapper = document.getElementById('lia-vid-6404528052112w304h540r114'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (Show My Videos) As intended, the LEDs were turned off for a longer period. This allowed us to verify that the LED outputs High (1) when it is lit and Low (0) when it is off. To recap, when the GPIO goes high (1), the voltage at P1_8, which is set as the GPIO pin, becomes approximately 3.3V. A potential difference is created between this voltage and GND, causing current to flow through the resistor and the LED. At this time, a forward voltage (approximately 2.0V) is applied across the LED, and the remaining approximately 1.3V is applied across the resistor. As a result, the LED lights up. On the other hand, when GPIO goes low (0), the voltage at P1_8 becomes approximately 0V. Since there is no potential difference between the GPIO pin and GND, no current flows, and the LED turns off. If you think having a lot of `delay()` functions looks ugly, you can also use loop functions. while (1) { GPIO_PinWrite(GPIO1, 8U, 1); delay(); GPIO_PinWrite(GPIO1, 8U, 0); for (int i = 0; i < 5; i++) { delay(); } } Bonus – What happens if you connect two LEDs in parallel? I tried connecting a green LED I had on hand in parallel with a red LED. Since the forward voltage (Vf) of a green LED is generally 2.0 to 2.2V, I assumed it to be 2.0V, similar to the red LED, and built the following circuit. Since there was no need to change the pin settings, I debugged using the same code as before, and the red LED blinked, but the green LED did not. Why is that? (function() { var wrapper = document.getElementById('lia-vid-6404530194112w304h540r514'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (Show My Videos) LEDs have the characteristic that current starts flowing rapidly when the forward voltage (Vf) is exceeded. Therefore, if a red LED and a green LED are simply connected in parallel, the current will concentrate on the LED with the lower Vf, and the other LED may hardly light up at all. In this case, the Vf of the red LED is lower than that of the green LED, so the current is concentrated on the red LED. When I actually measured the voltage across the LEDs with a tester, the red LED was 1.765V and the green LED was 1.766V. At this voltage, the red LED can light up, but the green LED does not receive enough voltage to generate sufficient current. As a result, the red LED lights up, but the green LED does not light up because almost no current flows through it. As shown above, simply connecting different types of LEDs in parallel can cause significant bias in current flow due to even small differences in forward voltage (Vf). Therefore, when connecting LEDs in parallel, it is common practice to install a current-limiting resistor for each LED. When adding resistors, you need to consider the GPIO current limit. If you simply add one more 390Ω resistor as we've been using and calculate the current, the calculated current applied to the GPIO will exceed 6mA. Therefore, to ensure the total current does not exceed 4mA, we connected two 680Ω resistors and built the following circuit. When I debugged the same code again, both the red and green LEDs lit up. (function() { var wrapper = document.getElementById('lia-vid-6405719291112w304h540r698'); var videoEl = wrapper ? wrapper.querySelector('video-js') : null; if (videoEl) { if (window.videojs) { window.videojs(videoEl).ready(function() { this.on('loadedmetadata', function() { this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) { bar.setAttribute('role', 'presentation'); bar.setAttribute('aria-hidden', 'true'); }); }); }); } }})(); (Show My Videos) When the voltage across the LEDs was measured, the red LED was 1.750V and the green LED was 1.906V. By adding a resistor to each LED, the appropriate current was able to flow through each LED. In this article, we've explained the "problems" and "stumbling blocks" encountered by a beginner in embedded development, from how to interpret various documents and use Config Tools to the operating principles of LEDs. We hope this will be helpful for those attempting to blink an LED for the first time using an NXP microcontroller. =========================​ We are currently unable to respond to comments left in the " Comment " section of this post . We apologize for the inconvenience, but please refer to " Technical Questions to NXP - How to Contact Us ( Japanese Blog ) " when making inquiries . (If you are already an NXP distributor or have a relationship with NXP , you may ask your representative directly.) This article explains how to use GPIO (General Purpose Input/Output), one of the most basic peripherals in microcontroller development, using the blinking of an LED as an example. GPIO is one of the first peripherals that many microcontroller developers learn about. Many people want to use GPIO to light up an LED, but they may not know how to read the datasheet or how to configure the pins. This article explains the basics of GPIO using the FRDM-MCXA153, aimed at beginners in microcontroller development. We will learn to read pin information from the datasheet and circuit diagram, configure settings using Pins Tool, and finally experience controlling an external LED. (Estimated time: 15 minutes) *Assuming the development environment is already installed. MCUXpresso MCUXpresso Configuration Tools MCUXpresso IDE MCUXpresso SDK MCX Japanese Blog
View full article
[RTD701 MCAL] FRDM-A-S32K344 CAN <-> ETH Gateway Interrupt **************************************************************************** * Detailed Description: * * CAN <-> Ethernet gateway demo for FRDM-A-S32K344. * * CAN FD frames are encapsulated into raw Ethernet frames and * transmitted over the 100BASE-TX link. Received Ethernet frames * are decapsulated and forwarded to the CAN FD bus. * * Key Functionality: * - Interrupt-driven CAN FD reception via CanIf_RxIndication callback. * - Interrupt-driven Ethernet reception via EthIf_RxIndication callback * (EthCtrlEnableIngressQueueInterrupt, GMAC0_CH_RX_IRQHandler). * - GMAC TX confirmation interrupt processing (GMAC0_CH_TX_IRQHandler). * - Custom gateway format for CAN ID, DLC, flags and * payload (up to 64 bytes CAN FD) in a fixed 72-byte Ethernet payload. * - PHY CAN transceiver initialization. * - Ethernet PHY auto-detection and MDIO configuration via EthPhy driver. * - PHY initialization selectable at compile time: * PHY_INIT_BY_PIN_STRAPPING (default) * PHY_INIT_BY_SOFTWARE (MDIO register write) * * Main Loop Flow: * - CAN -> ETH : CanIf_bRxFlag set by ISR -> App_EthTransmit() * - ETH -> CAN : ethReceiveFlag set by ISR -> App_CanTransmit() * * Notes: * - Red LED set if Gateway_Init returns E_NOT_OK. * - Green LED toggles upon CAN reception. * - Blue LED toggles upon ETH reception. * - EthIf.c contains the custom EthIf_RxIndication gateway implementation. * - During S32 Configuration Tool code generation select "Keep Existing" * for EthIf.c to avoid overwriting the custom callback. * - Eth_43_GMAC_ReleaseRxBuffer() must be called unconditionally inside * EthIf_RxIndication. * * ------------------------------------------------------------------------- * Test HW : FRDM-A-S32K344 Rev A * MCU : S32K344_257BGA * IDE : S32DS 3.6.10 * RTD : S32K3_RTD_7_0_1_D2602_ASR_REL_4_9_REV_0000_20260206 * AUTOSAR : 4.9.0 * Debugger : P&E Micro * Target : Internal_FLASH * CAN : CAN FD, 500 Kbps nominal / 2 Mbps data, TJA1043 transceiver * Ethernet : RMII 100BASE-TX, DP83848 PHY **************************************************************************** ETH Reception with Wireshark:ETH Reception with Wireshark: CAN Reception with PCAN-USB.CAN Reception with PCAN-USB. Note: Inside project you can comment NODE_1 and define NODE_2 as 1 to enable simple routine which sends out a CAN frame if SW3 is pressed, and an ETH frame if SW2 is pressed.
View full article
Example FRMD-A-S32K344 FlexCAN TX_RX FreeRTOS S32DS36 RTD600 * ================================================================================================= * Detailed Description: * * This example demonstrates Classical CAN and CAN FD reception and transmission using * interrupt-driven Message Buffers and FreeRTOS. * * FlexCAN0 is configured in Normal mode. MB0 receives standard-ID frames and MB1 receives * extended-ID frames. The FlexCAN callback copies every received frame into a FreeRTOS queue * and immediately rearms the corresponding RX Message Buffer. * * A dedicated FreeRTOS task waits for frames in the queue and echoes them through CAN TX MB2. * The transmitted frame preserves the received identifier type, identifier, payload length, * payload, CAN FD EDL state, and BRS state. The user LED is toggled after a transmit request * is accepted by the driver. * * Note: * FreeRTOS API functions such as xQueueSendFromISR() are used from the FlexCAN callback. * Therefore, the FlexCAN interrupt priority must comply with the FreeRTOS interrupt-priority * requirements defined by configMAX_SYSCALL_INTERRUPT_PRIORITY. * * ================================================================================================= * Test HW: FRDM-A-S32K344 (SCH-94921 / SPF-94921 Rev. C) * MCU: S32K344 * Compiler: S32DS 3.6.x * RTD release: S32K3_RTD_6_0_0_D2506_ASR_REL_4_7_REV_0000_20250610 * Debugger: On-Board Debugger * Target: Internal_FLASH * Communication: Classical CAN / CAN FD, STD and EXT ID, optional BRS * =================================================================================================
View full article
Example S32K344 LPSPI LCD-PAR-S035 FRDM S32DS 3.6.6 RTD 7.0.1 * Detailed Description: * * This project provides a minimal bring-up and reference example for the LCD-PAR-S035 * display and GT911 capacitive touchscreen on the S32K344. It includes standalone LCD * and touchscreen diagnostic modes, together with an LVGL demonstration mode. * * The display is controlled through the LPSPI interface using the ST7796S * display controller driver. The touchscreen is controlled through the LPI2C * interface and uses GPIO signals for interrupt and reset control. * * The original LCD, DBI and touchscreen drivers were obtained from an NXP * App Code Hub MCUXpresso SDK example and adapted to the S32K3 RTD * environment. The project also integrates LVGL 9.4 as the graphical user * interface library. * * The application mode is selected at compile time using the APP_MODE macro * defined in this file. It allows the user to select a standalone display * test, a standalone touchscreen test or the complete LVGL demonstration. * Only one application mode shall be selected for each build. * * A graphical application can be designed using NXP GUI Guider 2.0.1. * GUI Guider is configured for LVGL 9.4.0. The contents of the GUI Guider * "generated" and "custom" output directories can be copied directly into * the corresponding gui_guider directories in this project. After replacing * the generated output, the project shall be rebuilt to include the updated * screens, widgets, events and custom callbacks. * * Installed packages for S32 Design Studio 3.6.6: * * SW32K3_S32M27x_RTD_R23-11_7.0.1_D2603_DesignStudio_updatesite.zip * * Software Sources: * * NXP App Code Hub demo: * https://github.com/nxp-appcodehub/dm-https-lcd-led-demo * * LVGL release/v9.4: * https://github.com/lvgl/lvgl/tree/release/v9.4 * * NXP GUI Guider 2.0.1: * https://www.nxp.com/webapp/Download?colCode=GUI-GUIDER-INSTALLER-2.0.1-WIN&appType=license * * Hardware: * * FRDM-A-S32K344: * Remove jumper JP11 when using an external debugger. * * LCD-PAR-S035: * Set SW1 to 111. * * Board Connections: * * +------------------+----------------------+-----------------+-------------------+------------------------------+ * | FRDM-A-S32K344 | MCU Signal | LCD-PAR-S035 | LCD-PAR-S035 | Function | * | Connector | | Signal | Connector | | * +------------------+----------------------+-----------------+-------------------+------------------------------+ * | J2-20 | PTC27 / GPIO | TP_INT | J5-12 | Touch interrupt, active low | * | J2-19 | PTC7 / LPI2C1_SCL | TP_SCL | J5-8 | Touchscreen I2C clock | * | J2-17 | PTC6 / LPI2C1_SDA | TP_SDA | J5-6 | Touchscreen I2C data | * | J2-13 | GND | GND | J5-4 | Signal ground | * | J2-11 | PTB14 / LPSPI1_SCK | LCD_WR | J5-5 | LCD SPI clock | * | J2-9 | PTB15 / LPSPI1_SIN | LCD_RD | Not connected | SPI data from LCD | * | J2-7 | PTB16 / LPSPI1_SOUT | LCD_MOSI | J5-9 | SPI data to LCD | * | J2-5 | PTB17 / GPIO | LCD_CS | J5-11 | LCD chip select, active low | * | J2-3 | PTC10 / GPIO | LCD_D_C | J5-7 | Command low, data high | * | J2-1 | PTC11 / GPIO | LCD_RST | J5-10 | LCD reset, active low | * | JA3-3 | VDD_HV_A | VCC | J5-1 or J5-2 | 3.3 V supply | * | JA3-13 or JA3-15 | GND | GND | J5-3 | Power ground | * +------------------+----------------------+-----------------+-------------------+------------------------------+ * * Project Files: * * Format: * File or directory - Description - Source - License * * | lvgl_app.c/.h * | LVGL application layer * | Created for this project * | NXP proprietary license * | * | lv_conf.h * | Project-specific LVGL configuration * | Derived from the LVGL v9.4.0 configuration template * | MIT License * | * | lv_port.c/.h * | LVGL initialization and S32K3 port layer * | Created for this project * | NXP proprietary license * | * | main.c * | Application entry point and compile-time mode selection * | Created for this project * | NXP proprietary license * | * +---gui_guider * | +---custom * | | User callbacks and custom GUI logic * | | GUI Guider 2.0.1 output * | | NXP proprietary license * | | * | \---generated * | Generated screens, widgets and events * | GUI Guider 2.0.1 output * | NXP proprietary license * | * +---lcdc * | fsl_st7796s.c/.h * | ST7796S LCD controller driver * | NXP App Code Hub demo * | BSD-3-Clause License * | * +---lcd_par_s035 * | lcd_par_s035.c/.h * | LCD-PAR-S035 board and display integration * | Created for this project * | NXP proprietary license * | * | lcd_par_s035_config.h * | LCD-PAR-S035 project configuration * | Created for this project * | NXP proprietary license * | * +---lvgl * | \---src * | LVGL 9.4 graphics library * | LVGL release/v9.4 * | MIT License * | * +---platform * | display_compat.h * | MCUXpresso SDK and S32K3 RTD compatibility definitions * | Created for this project * | NXP proprietary license * | * | fsl_dbi.c/.h * | Generic display bus interface implementation * | NXP App Code Hub demo * | BSD-3-Clause License * | * | lcd_dbi_s32k3.c/.h * | S32K3 DBI transport implementation using LPSPI * | Created for this project * | NXP proprietary license * | * | lcd_platform.c/.h * | S32K344 board and platform abstraction * | Created for this project * | NXP proprietary license * | * \---touchpanel * fsl_gt911.c/.h * GT911 touchscreen controller driver * NXP App Code Hub demo * BSD-3-Clause License * * gt911_s32k3.c/.h * S32K3 adaptation using LPI2C and GPIO * Created for this project * NXP proprietary license * * ---------------------------------------------------------------------------- * Test Hardware: FRDM-A-S32K344, schematic revision B * MCU: S32K344 * Display: LCD-PAR-S035 with ST7796S controller * Touchscreen: GT911 capacitive touchscreen controller * Debugger: Lauterbach TRACE32 * Build Target: internal_FLASH
View full article
cst creates invalid RSA-PSS signatures with old OpenSSL When using cst with OpenSSL < 3.1 the salt used in the PSS signatures is too long. Processors like the i.MX91 expect the salt to have the same length as the digest, but before OpenSSL 3.1 the default was to make the salt as big as possible. But even with newer OpenSSL versions using the default is not good as it will accept shorter salts during signature verification. The fix is to call EVP_PKEY_CTX_set_rsa_pss_saltlen with second parameter set to RSA_PSS_SALTLEN_DIGEST. Note that OpenSSL 3.0 is EOL since last month. Security
View full article
私を驚かせたストリーミングサービス これまでいくつかのストリーミングサービスを試してきましたが、一貫性のあるものを見つけるのは思ったより難しいことがあります。 最近、 NexusIPTV を しばらくテストして み たところ、全体的な体験に非常に驚きました。ストリーミング品質は良好で、チャネルの読み込みも速く、テストしたデバイス間でサービスも良好に動作しました。 アメリカ、イギリス、カナダ にお住まいの方にとっては 、比較検討するサービスのリストに加えておく価値があるかもしれません。 私の体験談については、こちらに詳しく書きました。 👉 私の全体験
View full article
ARA2-M2-16G-GT In the ARA2-M2-16G-GT Board User Manual Pin 40 is I2C_SDA and Pin 42 is I2C_SCL. in the FRDM-IMX8MPLUS schematic Pin 40 is I2C_SCL and Pin 42 is I2C_SDA. what the correct pinout? thanks  Board Design
View full article
GUI Guider画面(i.MX RT)で短いループ状の製品動画を表示する i.MX RTボード上で動作するGUI Guiderプロジェクトのアイドル画面で、約10秒ほどの短いループ状の製品デモクリップをお見せしたいと思います。これらのクリップは、Nereo( https://www.nereo.io/ )などのAIビデオツールを使用して作成された短いマーケティングビデオです。したがって、ソースは通常のH.264 MP4です。 質問: GUI Guiderでは、MP4を画像シーケンスに変換してアニメーション画像ウィジェットを使用する方法が推奨されていますか?それとも、より適切な方法(例えばMJPEG/AVIプレーヤーなど)はありますか? RT1170 / RT1060 i.MX タッチの応答性に影響を与えずに現実的なフレームレートと解像度はどれくらいでしょうか? この用途でフレームを外部フラッシュに保存するのとSDカードで保存する方法について、何かアドバイスはありますか? 参考になる例やアプリの説明書などがあれば教えていただけると助かります。
View full article
ADC转换时间问题 您好,NXP技术支持, 我正在使用 S32 设计工作室和 RTD 驱动程序对 S32K312 MCU 进行开发,并且我正在尝试了解单通道正常转换的 SAR ADC 的实际转换时序。 我的配置如下: MCU:S32K312 核心频率:120 MHz ADC功能时钟:120 MHz ADC模式:正常转换 通道数:1 预采样:已禁用 采样时间:33 个 ADC 时钟周期 我计算中使用的转换时间:48 个 ADC 时钟周期 硬件平均值:此测试中已禁用 已启用链结束通知/中断 相关代码如下: int main(void) { Clock_Ip_Init(&Clock_Ip_aClockConfig[0]); IntCtrl_Ip_Init(&IntCtrlConfig_0); IntCtrl_Ip_EnableIrq(ADC0_IRQn); Siul2_Port_Ip_Init( NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals ); volatile Adc_Sar_Ip_StatusType status = ADC_SAR_IP_STATUS_ERROR; status = Adc_Sar_Ip_Init(0, &AdcHwUnit_0); 状态 = Adc_Sar_Ip_DoCalibration(0); Adc_Sar_Ip_EnableNotifications( 0, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN ); Siul2_Dio_Ip_TogglePins(PTA_L_HALF, 1U < 1U); Adc_Sar_Ip_StartConversion( 0, ADC_SAR_IP_CONV_CHAIN_NORMAL ); while(1) { __asm__ ("nop"); } } void Adc_EndOfNormalChain_Callback(void) { Siul2_Dio_Ip_TogglePins(PTA_L_HALF, 1U < 1U); } 我使用逻辑分析仪测量两次 GPIO 转换之间的时间。 仅根据 ADC 时序,我计算得出大约为 700ns。 然而,测得的 GPIO 脉冲宽度约为 4us。 我想了解以下内容: 当禁用预采样和硬件平均时,单次法线转换的正确公式是什么? Adc_Sar_Ip_DoCalibration()执行的 ADC 校准是否会影响后续每次 ADC 转换的时序,还是仅在初始化期间计算/存储校准值? 增益校正、偏移校正、内部电容充电、建立时间或任何内部ADC处理是否会给每次转换增加额外的周期? S32K312 SAR ADC 在正常转换模式下,单通道的精确转换时间公式是什么? 测量的时间间隔是否为: Adc_Sar_Ip_StartConversion() 和Adc_EndOfNormalChain_Callback() 是否包括显著的RTD软件开销、中断延迟、ISR处理或回调开销? 是否有推荐的方法可以只测量ADC硬件转换时间,而不包括RTD和中断开销? 如果可以,能否提供此配置下预期的ADC时序(以时钟周期为单位)? 我的主要目标是确定大约 4 µs 的测量结果主要是由 ADC 硬件时序引起的,还是由 RTD/中断/软件开销引起的。 任何关于ADC转换的帮助都将不胜感激! 谢谢。 Re: ADC Conversion time issue 您好, ADC转换时间方程直接在S32K3参考手册第60.3.18节中给出。“转换时间”。对于您的配置(单通道,预采样禁用,硬件平均禁用),可以使用该公式和配置的 ADC 时钟计算转换时间。 补充几点: 1. Adc_Sar_Ip_DoCalibration() 不会影响后续转换的时机。校准在初始化期间执行,然后校准值被ADC硬件使用。 2. 测得的 ~4 µs 不仅仅是 ADC 转换时间。您的测量范围: Adc_Sar_Ip_StartConversion() ADC采样和转换 ADC中断生成 NVIC中断延迟 RTD ISR 处理 回调调度 GPIO 切换操作 因此,测得的脉冲宽度包括ADC硬件时间和软件开销。预计转换时间将明显长于仅使用 RM 公式计算出的转换时间。 3. 为了更准确地测量ADC硬件转换时间,我们可以推荐以下方法: Adc_Sar_Ip_StartConversion() 返回后立即切换第一个 GPIO。这样就从测量的脉冲中消除了大部分启动 API 执行时间。 在 ADC 中断处理程序中,在调用配置的通知回调之前,尽早切换 GPIO。这样就将中断入口与回调分发开销分开了。 为了最大限度地降低 GPIO 软件开销,暂时使用直接写入 SIUL2 GPIO 寄存器,而不是使用 Siul2_Dio_Ip_TogglePins()。 或者,轮询 ADC 链结束状态标志,并在硬件标志设置后立即切换 GPIO。这不包括 NVIC 和回调开销,但轮询循环和 GPIO 写入延迟仍然存在。 因此,根据所提供的信息,~4 µs 的测量结果很可能是由整个软件/中断路径主导,而不是 ADC 转换本身。 BR,彼得
View full article
My Experience Finding a Reliable IPTV Service in 2026 After trying and comparing different IPTV services, I found that Nexusiptv.live has been one of the better options for my needs, especially when looking at streaming stability, video quality, and content availability for viewers in the USA, UK, and Canada. Of course, performance can depend on your internet connection and location, but my overall experience has been positive so far. I wrote a more detailed article about what I looked for when choosing a reliable IPTV service in 2026: 👉 Read my full experience on Medium
View full article
ARA2-M2-16G-GT 在 ARA2-M2-16G-GT 板用户手册中,引脚 40 为 I2C_SDA,引脚 42 为 I2C_SCL。 在 FRDM-IMX8MPLUS 原理图中,引脚 40 为 I2C_SCL,引脚 42 为 I2C_SDA。 正确的引脚排列是什么? 谢谢  电路板设计
View full article
2026年に信頼できるIPTVサービスを見つける私の経験 さまざまなIPTVサービスを試して比較した結果、特にアメリカ、イギリス、カナダの視聴者のストリーミングの安定性、映像品質、コンテンツの利用可能性を考えると、Nexusiptv.live が私のニーズに合った選択肢の一つだと感じました。 もちろん、パフォーマンスはインターネット接続や場所によって変わりますが、全体的にはこれまでのところ良い経験です。 2026年に信頼できるIPTVサービスを選ぶ際に私が重視した点について、より詳細な記事を書きました。 👉 Mediumで私の体験談全文をお読みください。
View full article
我在2026年寻找可靠IPTV服务的经验 在尝试和比较了不同的 IPTV 服务之后,我发现Nexusiptv.live是比较符合我需求的选择之一,尤其是在流媒体稳定性、视频质量以及为美国、英国和加拿大的观众提供内容方面。 当然,性能可能取决于您的网络连接和所在位置,但到目前为止,我的整体体验是积极的。 我写了一篇更详细的文章,介绍了我在2026年选择可靠的IPTV服务时所考虑的因素: 👉 在 Medium 上阅读我的完整经历。
View full article
ADC変換時間の問題 こんにちは、NXPサポートの皆さん、 私はS32 Design StudioとRTDドライバーを使ってS32K312 MCUを扱っており、シングルチャネルの通常変換におけるSAR ADCの実際の変換タイミングを理解しようとしています。 私の設定は以下の通りです。 MCU:S32K312 コアクロック:120MHz ADC機能クロック:120MHz ADCモード:通常変換 チャネル数:1 プリサンプリング:無効 サンプリング時間:33 ADCクロックサイクル 計算に使用した変換時間:48 ADCクロックサイクル ハードウェア平均化:このテストでは無効になっています チェーン終了通知/割り込みが有効 該当するコードは以下のとおりです。 int main(void) { Clock_Ip_Init(&Clock_Ip_aClockConfig[0]); IntCtrl_Ip_Init(&IntCtrlConfig_0); IntCtrl_Ip_EnableIrq(ADC0_IRQn); Siul2_Port_Ip_Init( NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals ); volatile Adc_Sar_Ip_StatusType status = ADC_SAR_IP_STATUS_ERROR; status = Adc_Sar_Ip_Init(0, &AdcHwUnit_0); ステータス = Adc_Sar_Ip_DoCalibration(0); Adc_Sar_Ip_EnableNotifications( 0, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN ); Siul2_Dio_Ip_TogglePins(PTA_L_HALF, 1U < 1U); Adc_Sar_Ip_StartConversion( 0, ADC_SAR_IP_CONV_CHAIN_NORMAL ); while(1) { __asm__ ("nop"); } } void Adc_EndOfNormalChain_Callback(void) { Siul2_Dio_Ip_TogglePins(PTA_L_HALF, 1U < 1U); } ロジックアナライザを使用して、2つのGPIO遷移間の時間を測定します。 ADCのタイミングのみに基づいて計算したところ、約700ナノ秒という値が得られました。 しかし、測定されたGPIOパルス幅は約4μsである。 以下の点について理解を深めたいです。 プリサンプリングとハードウェア平均化が無効になっている場合、単一の正規変換を行うための正しい式は何ですか? Adc_Sar_Ip_DoCalibration()によって実行される ADC キャリブレーションは、後続のすべての ADC 変換のタイミングに影響しますか、それとも初期化時にのみキャリブレーション値を計算/保存しますか? ゲイン補正、オフセット補正、内部コンデンサの充電、セトルタイム、または内部ADCプロセッシングは変換ごとに追加のサイクルを加えるのでしょうか? 通常の変換モードでの1チャネルのS32K312 SAR ADCの正確な変換時間公式は何ですか? 測定された時間間隔は: Adc_Sar_Ip_StartConversion() およびAdc_EndOfNormalChain_Callback() RTDソフトウェアのオーバーヘッド、割り込みレイテンシ、ISR処理、またはコールバックオーバーヘッドを含むべきか? RTDや割り込みのオーバーヘッドを除き、ADCハードウェア変換時間のみを測定する推奨される方法はありますか? 可能であれば、この構成で期待されるADCタイミング(クロックサイクル単位)を教えてもらえますか? 私の主な目的は、約4μsの測定値が主にADCのハードウェアタイミングによるものか、RTD/割り込み/ソフトウェアのオーバーヘッドによるものかを明らかにすることです。 このADC変換に関するご協力は大歓迎です! ありがとう。 Re: ADC Conversion time issue こんにちは、 ADC変換時間の方程式はS32K3リファレンスマニュアル60.3.18節に直接記載されています「変換時間」あなたの設定(シングルチャネル、プリサンプリング無効、ハードウェア平均無効)では、その式と設定されたADCクロックを使って変換時間を計算できます。 補足事項: 1. Adc_Sar_Ip_DoCalibration() は、後続の変換のタイミングに影響を与えません。キャリブレーションは初期化時に実行され、そのキャリブレーション値はADCハードウェアによって使用されます。 2. 測定された約4µsは、ADC変換時間だけではありません。測定範囲: Adc_Sar_Ip_StartConversion() ADCサンプリングと変換 ADC割り込み生成 NVIC割り込みレイテンシ RTD ISRプロセッシング コールバックディスパッチ GPIOトグル操作 したがって、測定されたパルス幅にはADCのハードウェア時間とソフトウェアのオーバーヘッドの両方が含まれます。これは、RM式のみから計算される変換時間よりも明らかに長くなると予想される。 3. ADCハードウェア変換時間をより正確に測定するために、以下に推奨します Adc_Sar_Ip_StartConversion() が戻った直後に、最初の GPIO をトグルします。これにより、測定されたパルスから、起動APIの実行時間の大部分が除去されます。 ADC割り込みハンドラでは、設定された通知コールバックを呼び出す前に、できるだけ早い段階でGPIOを切り替えてください。これにより、割り込み処理の開始とコールバックディスパッチのオーバーヘッドが分離されます。 GPIOソフトウェアの負荷を最小限に抑えるために、Siul2_Dio_Ip_TogglePins()の代わりに一時的に直接SIUL2 GPIOレジスタ書き込みを使用してください。 あるいは、ADCのチェーン終了ステータスフラグをポーリングし、ハードウェアフラグがセットされたらすぐにGPIOを切り替える。これによりNVICやコールバックのオーバーヘッドは除外されますが、ポーリングループやGPIO書き込みレイテンシは残ります。 したがって、提供された情報に基づくと、~4μsの測定値はADC変換自体よりもソフトウェア/割り込み経路全体に支配されている可能性が高いです。 BR、ペトル
View full article
cst は古い OpenSSL を使用して無効な RSA-PSS 署名を作成する OpenSSL 3.1未満でcstを使用する場合、PSS署名で使用されるソルトが長すぎます。i.MX91のようなプロセッサはソルトの長さがダイジェストと同じであることを期待していますが、OpenSSL 3.1以前はデフォルトでソルトをできるだけ大きくするのが一般的でした。 しかし、新しいバージョンのOpenSSLであっても、デフォルト設定を使用するのは良くありません。なぜなら、署名検証時に短いソルトを受け入れてしまうからです。 解決策は、EVP_PKEY_CTX_set_rsa_pss_saltlen 関数を呼び出し、2 番目のパラメータを RSA_PSS_SALTLEN_DIGEST に設定することです。 なお、OpenSSL 3.0は先月からサポート終了となっています。 Security
View full article
ARA2-M2-16G-GT ARA2-M2-16G-GTボードのユーザーマニュアルでは、ピン40はI2C_SDA、ピン42はI2C_SCLされています。 FRDM-IMX8MPLUSの回路図では、ピン40はI2C_SCL、ピン42はI2C_SDAです。 正しいピン配置は何ですか? よろしくお願いします。 ボード設計
View full article
ADC Conversion time issue Hello NXP Support, I am working with an S32K312 MCU using S32 Design Studio and RTD drivers, and I am trying to understand the actual conversion timing of the SAR ADC for a single-channel normal conversion. My setup is: MCU: S32K312 Core clock: 120 MHz ADC functional clock: 120 MHz ADC mode: Normal conversion Number of channels: 1 Pre-sampling: Disabled Sampling time: 33 ADC clock cycles Conversion time used in my calculation: 48 ADC clock cycles Hardware averaging: Disabled for this test End-of-chain notification/interrupt enabled The relevant code is: int main(void) { Clock_Ip_Init(&Clock_Ip_aClockConfig[0]); IntCtrl_Ip_Init(&IntCtrlConfig_0); IntCtrl_Ip_EnableIrq(ADC0_IRQn); Siul2_Port_Ip_Init( NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals ); volatile Adc_Sar_Ip_StatusType status = ADC_SAR_IP_STATUS_ERROR; status = Adc_Sar_Ip_Init(0, &AdcHwUnit_0); status = Adc_Sar_Ip_DoCalibration(0); Adc_Sar_Ip_EnableNotifications( 0, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN ); Siul2_Dio_Ip_TogglePins(PTA_L_HALF, 1U << 1U); Adc_Sar_Ip_StartConversion( 0, ADC_SAR_IP_CONV_CHAIN_NORMAL ); while (1) { __asm__("nop"); } } void Adc_EndOfNormalChain_Callback(void) { Siul2_Dio_Ip_TogglePins(PTA_L_HALF, 1U << 1U); } I measure the time between the two GPIO transitions using a logic analyzer. Based on the ADC timing alone, I calculated it, which gives approximately 700ns. However, the measured GPIO pulse width is approximately 4us. I would like to understand the following: What is the correct formula for a single normal conversion when pre-sampling and hardware averaging are disabled? Does the ADC calibration performed by Adc_Sar_Ip_DoCalibration() affect the timing of every subsequent ADC conversion, or does it only calculate/store calibration values during initialization? Do gain correction, offset correction, internal capacitor charging, settling time, or any internal ADC processing add additional cycles to every conversion? What is the exact conversion-time formula for the S32K312 SAR ADC for one channel in normal conversion mode? Does the measured time between: Adc_Sar_Ip_StartConversion() and Adc_EndOfNormalChain_Callback() include significant RTD software overhead, interrupt latency, ISR processing, or callback overhead? Is there a recommended method to measure only the ADC hardware conversion time, excluding RTD and interrupt overhead? If possible, could you provide the expected ADC timing in clock cycles for this configuration? My main objective is to determine whether the approximately 4 µs measurement is caused mainly by ADC hardware timing or by RTD/interrupt/software overhead. Any help related to this ADC conversion is appreciated!! Thank you.  Re: ADC Conversion time issue Hi, The ADC conversion-time equation is provided directly in S32K3 Reference Manual, section 60.3.18 "Conversion time". For your configuration (single channel, pre-sampling disabled, hardware averaging disabled), the conversion time can be calculated using that formula and the configured ADC clock. A few additional notes: 1. Adc_Sar_Ip_DoCalibration() does not affect the timing of subsequent conversions. Calibration is executed during initialization and the calibration values are then used by the ADC hardware. 2. The measured ~4 µs is not ADC conversion time only. Your measurement spans: Adc_Sar_Ip_StartConversion() ADC sampling and conversion ADC interrupt generation NVIC interrupt latency RTD ISR processing Callback dispatch GPIO toggle operations Therefore, the measured pulse width includes both ADC hardware time and software overhead. It is expected to be noticeably larger than the conversion time calculated from the RM formula alone. 3. To measure the ADC hardware conversion time more accurately, we can recommend below Toggle the first GPIO immediately after Adc_Sar_Ip_StartConversion() returns. This removes most of the start-API execution time from the measured pulse. In the ADC interrupt handler, toggle GPIO as early as possible, before calling the configured notification callback. This separates interrupt entry from callback-dispatch overhead. For the lowest GPIO software overhead, temporarily use a direct SIUL2 GPIO register write instead of Siul2_Dio_Ip_TogglePins(). Alternatively, poll the ADC end-of-chain status flag and toggle the GPIO immediately when the hardware flag becomes set. This excludes NVIC and callback overhead, although polling-loop and GPIO-write latency remain. So, based on the information provided, the ~4 µs measurement is most likely dominated by the complete software/interrupt path rather than the ADC conversion itself. BR, Petr
View full article
适用于 Mcuxpresso 的 MIMXRT1010 SDK 您好, 我一直使用 mcuxpresso ide(版本 25.6)和 SDK_2.x_FRDM-K64F,利用连接到 FRDM-K64F 评估套件上的 nrf24l01 芯片,在 2.4 GHz 频段上构建网络。我想在网络中添加几套MIMXRT1010评估套件。我正在尝试安装 SDK_2_11_0_EVK-MIMXRT1010-AGM01.zip,以便使用同一个 IDE 在 RT1010s 上构建系统。它似乎已经下载并安装,但却被默默忽略了。系统提示该软件已存在,但在“已安装的SDK”面板中只有FRDM-K64F。我已经仔细地重新编译了SDK,确保包含了mcuxpresso IDE,并且我是在Linux系统上进行开发。 我是否可能受到了某种未知病毒的攻击? 非常感谢您的帮助。 干杯 奈杰尔
View full article