Multi Source Translation Content

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

Multi Source Translation Content

Discussions

Sort by:
PQC compliance is too late after shipment! Quantum-proofing measures considered from the perspective of secure boot and firmware updates (Japanese blog) Following the i.MX 94 and i.MX 95 , NXP has announced the MCX A5 family, which features a secure boot loader built into ROM that supports PQC ( Post-Quantum Cryptography) hybrid Secure Boot and Secure Firmware Update. NXP plans to continue expanding its range of PQC-compatible products. NXP Announces New MCX A5 MCU to Simplify Secure Industrial Connectivity | NXP Semiconductors Even though quantum computers are still under development and concrete attacks using quantum computers have not yet begun, adopting products with built-in PQC-compatible secure bootloaders now is extremely important, especially for equipment intended for long-term use, such as industrial equipment. If you are considering addressing the issue later through a firmware update, in particular, you need to understand the significant limitations involved and what needs to be done at the time of product manufacturing to ensure PQC compliance. Main reasons why PQC compliance is required Here are three main reasons why PQC compliance is required from the product design stage. Product lifecycles may overlap with the arrival of practical attacks by quantum computers . Industrial equipment, automotive equipment, medical equipment, etc., are sometimes used for more than 10 years. If these products have already been shipped by the time quantum computers become practical, countermeasures will be needed in the market afterward. "Harvest Now, Decrypt Later" means that encrypted communication data obtained now could be decrypted in the future using future quantum computing capabilities. Especially for products requiring long-term confidentiality, responding after an attack has begun is too late. Resource requirements can be very large and difficult to address later. Depending on the specific algorithm, PQC algorithms may have higher resource requirements (ROM, RAM, Flash, processing time, power) than conventional ECC/RSA algorithms, making later implementation difficult. If you plan to support PQC in the future, you need to ensure sufficient resources for PQC from the outset, in addition to meeting current product specifications. The above are the commonly cited reasons, but based on the above alone, you might think, "If the data being handled doesn't pose much of a problem even if it's deciphered later, wouldn't it be better to design it with ample resources at the moment and then add PQC support later with a firmware update?" However, in reality, there are significant constraints. Issues with PQC support due to firmware update The biggest constraint for later PQC compliance is, "The 1st SBL (described later) must be made unrewritable." "Firmware update images contain intellectual property (IP)." That's the point. The first SBL (First SBL) is related to Secure Boot. Secure Boot is an essential security mechanism that verifies the integrity of the firmware (that it has not been damaged or tampered with) through signature verification before starting the firmware. To do this, a Secure Bootloader (SBL) is required, which exists independently of the firmware being verified, runs before the firmware being verified starts, and performs signature verification. In particular, the SBL that is executed first after system startup is referred to here as the 1st SBL, and this 1st SBL must be immutable. For the reason why, please refer to the section "The 1st SBL must not be overwritten" in the following article. The basics of secure boot and secure (OTA) updates in MCUs (Japanese blog) In other words, it is impossible to use ECC/RSA as the firmware verification algorithm by the 1st SBL at the time of product shipment, without a PQC-compatible algorithm, and then add support for a PQC-compatible algorithm later. If the firmware verification algorithm by the 1st SBL remains ECC/RSA, there is a risk that its signature will be forged and malicious firmware will be launched after quantum computers become practical. The second point is that even if the data handled by the product itself is not a major problem when it is later deciphered, the product's firmware generally contains a lot of intellectual property (IP). If the encryption algorithm of the firmware update image does not support PQC, there is a risk of IP leakage in the future due to the decryption of the contents of the firmware update image. Furthermore, if the firmware update image's signature algorithm does not support PQC, there is a risk that the firmware update image's signature could be forged and malicious firmware could be loaded. Based on the above, if we are considering future PQC support, it is reasonable to conclude that at a minimum, the firmware verification algorithm using the 1st SBL and the signing and encryption algorithms for the firmware update image must be PQC-compatible at the time of product manufacturing. NXP products can solve the challenges of PQC compliance. The MCX A5's Boot ROM integrates PQC-compatible secure boot functionality, allowing it to be used as the 1st SBL. Furthermore, this Boot ROM also includes support for PQC-compatible secure updates. Compared to placing the SBL on Flash, it also reduces the required Flash capacity. Productizing PQC-compliant functionality requires verification of key management, signature infrastructure, manufacturing provisioning, OTA updates, authentication, performance evaluation, and standards compliance, necessitating a long preparation period. This is especially true for the 1st SBL, which, as mentioned earlier, cannot be updated, requiring even more rigorous verification. As of the time of writing, the MCX A5 is not yet in mass production and is in the process of obtaining certification, but it is designed with the goal of obtaining PSA Level 3 and SESIP Level 3 third-party security certifications (NXP already has a track record of obtaining PSA/SESIP certifications for many products). After certification is obtained, documentation including the Security Target (a document that defines the evaluation target, security claims, requirements, scope, etc.) will be provided. By utilizing the MCX A5's PQC-compatible secure boot integrated Boot ROM, along with NXP's toolset such as the MCUXpresso secure provisioning tool and MCUXpresso SDK , we can reduce the implementation and verification effort required for PQC-compatible secure boot and firmware updates. Key points for selecting SESIP Level 3 certified products One important point to note regarding SESIP certification is that even among products with the same SESIP Level 3 certification, the scope of functionality included in the certification can vary significantly from product to product. Therefore, it is crucial to check not only the SESIP certification level but also the contents of the Security Target document. Documentation for certified products can be downloaded from the link below. SESIP Certificates - TrustCB For example, in NXP's SESIP Level 3 product, "MCX N94x / 54x / 23x SESIP Security Target Rev 1.1," Fig. 3 shows that the Certification Scope includes not only the SoC ROM, including Secure Boot, but also numerous security features, including the EdgeLock ® Secure Enclave (ELS S50) . While some other companies' SESIP Level 3 certified products lack many of these security features , some logical scope products have obtained SESIP Level 3 certification with only lifecycle management and memory protection features.   Furthermore, NXP's SESIP Security Target includes mappings to security standards/regulations such as IEC 62443-4-2, which can be used to address these standards and similar requirements in future security standards/regulations. As of the time of writing this article, the latest certified product, "i.MX RT700 SESIP Security Target Rev. 1.0," also includes mapping to the CRA's EU 2024/2847 Annex I Essential Cybersecurity Requirements. Note: The document version names for Security Target mentioned above are current as of the time of writing and are subject to change. Furthermore, SESIP certification and mapping to security standards/regulations do not guarantee compliance with standards/regulations for the entire final product using NXP products. Integration at the final product level and additional measures as required may be necessary. ========================= 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 an inquiry. (If you are already an NXP distributor or have a relationship with NXP, you may ask your representative directly.) Following the i.MX 94 and i.MX 95 , NXP has announced the MCX A5 family, which features a secure boot loader built into ROM that supports PQC ( Post-Quantum Cryptography) hybrid Secure Boot and Secure Firmware Update. NXP plans to continue expanding its range of PQC-compatible products. NXP Announces New MCX A5 MCU to Simplify Secure Industrial Connectivity | NXP Semiconductors Even though quantum computers are still under development and concrete attacks using quantum computers have not yet begun, adopting products with built-in PQC-compatible secure bootloaders now is extremely important, especially for equipment intended for long-term use, such as industrial equipment. If you are considering addressing the issue later through a firmware update, in particular, you need to understand the significant limitations involved and what needs to be done at the time of product manufacturing to ensure PQC compliance. (Reading time: 10 minutes) i.MX RT Processors i.MX Processors MCX Security Japanese Blog
View full article
[MCX A153] ADC模块基础知识及使用方法(日语博客) 本文介绍了MCX A153中安装的ADC(模数转换器)模块的基本用法。首先通过ADC的应用示例,总结了其主要功能、模块结构和使用注意事项,然后介绍了如何使用SDK示例代码进行设备初始化,以及如何使用DMA传输ADC转换结果。 本文旨在帮助您了解在应用中使用 MCX A153 ADC 所需的基本原理,使您能够实现从 ADC 转换的初始设置到利用 DMA 进行高效数据传输的一切操作。   目录 1. 应用中的常见用例 1.1 主要用途 1.2 使用示例 2. MCX A153 ADC模块的主要功能和框图 2.1 概述 2.2 主要特点 2.3 方框图 3. 注意事项和限制 4. ADC 示例代码(设备初始化) 4.1 示例代码概述 4.2 打开 SDK 示例项目 4.3 宏观定义 4.4 设备初始化 5. 使用MCX A153 DMA传输AD转换值 5.1 与ADC相关的代码 5.2 DMA相关代码 总结 1. 应用中的常见用例 ADC 将来自传感器、电位器等的模拟信号(连续变化的电压)转换为微控制器可用于计算的数字值(数值)。 1.1 主要用途 将电位器输入的模拟电压值转换为数字值。 电位器安装在伺服电机(例如无线电遥控车辆中使用的伺服电机)的轴上,通过输出的变化来检测电机的旋转角度。 将来自各种传感器的模拟信号转换为数字值。 它通过转换来自加速度计的模拟信号来检测物体的倾斜度。例如,这可以用于检测智能手机的方向。 环境温度是通过转换温度传感器的模拟信号来测量的。   1.2 使用示例(以下示例旨在说明一般概念,因此省略了细节。) 电位器应用示例:         2. 主要功能和框图   2.1 概述 MCX A153 配备了一个 16 位模数转换器 (ADC)。ADC 是一种将模拟电压转换为数字值的电路。   2.2 主要特点 配备一个逐次逼近型AD转换器单元。 支持 16 位或 12 位分辨率和单端输入(更高的分辨率可以更精细地表示输入电压)。 已安装频道数量(因套餐而异): 64 引脚 LQFP 封装:24 通道,48 引脚 LQFP 封装:16 通道,48 引脚 HVQFN 封装:18 通道,32 引脚 HVQFN 封装:9 通道 采样率(每秒数据转换次数) 16 位模式:最高 3.2 Msps,12 位模式:最高 4 Msps 可以设置采样时间。 可在微控制器的低功耗模式下运行。 支持四种触发源(软件或硬件触发)。 七个命令缓冲区可以扫描连续通道。 支持比较功能(自动比较较小、较大、在范围内、超出范围,保存为匹配项等) 配备八个用于存储转换结果数据的FIFO,具有水印和溢出检测功能。 支持中断、DMA 和轮询。 校准功能 内置温度传感器,带专用输入通道   2.3 方框图 MCX A153 参考手册(MCXAP64M96FS3RM) 图 165。ADC框图摘录   SDK示例代码使用示例(连接电位器)     3. MCX A153 ADC 模块 本节解释了在使用 MCX A153 的 ADC 之前需要考虑的重要事项和限制。 16 位模式下的速度降低 MCX A153 的 ADC 支持两种模式:16 位(ENOB16:16 位有效分辨率)和 12 位(ENOB12:12 位有效分辨率)。但是,16 位模式的采样率低于 12 位模式。 (摘自MCX A153 数据手册表 34) 校准执行时间 校准请求和执行必须在复位或上电期间进行。此外,必须先配置时钟源和频率才能执行校准。 转化率结果的平均值 ADC模块可以在保存转换结果之前,对同一通道的多个结果进行平均。当CMDHa[AVGS]位域设置为非零值时,硬件平均功能启用。该功能可用于任何转换模式,并减轻软件计算平均值的负担。 4. AD转换示例代码 4.1 示例代码概述 主序列执行时,将进行设备初始化。设备初始化首先设置时钟、配置外部接口,并选择要连接到接口的外设。之后,初始化外设(ADC、UART)并启用中断。初始化过程完成后,循环内会设置一个软件触发信号以启动ADC转换,并在控制台上显示ADC转换值和转换次数。 硬件方面,我们将使用MCX A153开发板“FRDM-MCXA153”。   4.2 在 VS Code 中打开 ADC 示例项目的步骤 4.2.1 准备 VS Code 和扩展程序 安装 VS Code。 在扩展视图(Ctrl+Shift+X)中搜索“MCUXpresso for VS Code”并安装。 MCUXpresso 图标将出现在左侧的活动栏中。点击该图标即可打开快速入门面板。   4.2.2 安装依赖工具 在快速启动面板中运行“打开 MCUXpresso 安装程序”。 请选择并安装以下工具。 Arm GNU 工具链 CMake / Ninja Python / 西方 Git LinkServer(MCU-Link 的调试探针) SDK相关工具 完成后,重启 VS Code。   4.2.3整合 SDK 存储库 在快速入门面板中单击“导入存储库”。 选择“远程”作为数据导入源。   指定目标文件夹。路径应简短,且不得包含日文字符或空格。 您可以通过勾选“我同意”并按下“导入”按钮来导入存储库。   4.2.4 导入样品 在“快速入门面板”中,单击“从存储库导入示例”。 设置方法如下:   您可以点击“导入”按钮导入项目。 项目 设置值 存储库 步骤 3 中导入的 SDK (frdm_mcxa153) 工具链 Arm GNU 工具链 木板 frdmmcxa153 (FRDM-MCXA153) 模板 driver_examples → lpadc → interrupt(lpadc_interrupt) 地点 项目保存位置 姓名 可选(默认值为 lpadc_interrupt) 4.3 宏观定义 这是 ADC 功能的宏定义代码(摘自 lpadc\interrupt\app.h)。 请调整输入通道、分辨率设置和参考电压源,以匹配您的实际电路设计和预期用途。 定义 //(lpadc\interrupt\app.hから抜粋) /******************************************************************************/ #define DEMO_LPADC_BASE ADC0 //ADCのinstance、ベースアドレス、MCX A153は1個 ADCしかない #define DEMO_LPADC_IRQn ADC0_IRQn #define DEMO_LPADC_IRQ_HANDLER_FUNC ADC0_IRQHandler #define DEMO_LPADC_USER_CHANNEL 0U //チャンネル番号 #define DEMO_LPADC_USER_CMDID 1U //コマンドID #define DEMO_LPADC_VREF_SOURCE kLPADC_ReferenceVoltageAlt3 //参考電圧ソース #define DEMO_LPADC_DO_OFFSET_CALIBRATION true //オフセットキャリブレーションの利用可否 #define DEMO_LPADC_USE_HIGH_RESOLUTION true //高分解能の利用可否 与ADC相关的变量 变量 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) volatile bool g_LpadcConversionCompletedFlag = false; volatile uint32_t g_LpadcInterruptCounter = 0U; lpadc_conv_result_t g_LpadcResultConfigStruct; #if (defined(DEMO_LPADC_USE_HIGH_RESOLUTION) && DEMO_LPADC_USE_HIGH_RESOLUTION) //高分解能 const uint32_t g_LpadcFullRange = 65536U; const uint32_t g_LpadcResultShift = 0U; #else //低分解能 const uint32_t g_LpadcFullRange = 4096U; const uint32_t g_LpadcResultShift = 3U; #endif /* DEMO_LPADC_USE_HIGH_RESOLUTION */ ADC 配置结构的默认值(详情请参见 fsl_lpadc.c),转换结果的平均值。 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) LPADC_GetDefaultConfig(&mLpadcConfigStruct); mLpadcConfigStruct.enableAnalogPreliminary = true; //ADCアナログ回路は事前に有効化され、起動遅延なしで変換を実行する準備 #if defined(DEMO_LPADC_VREF_SOURCE) mLpadcConfigStruct.referenceVoltageSource = DEMO_LPADC_VREF_SOURCE; //参考電圧ソース #endif /* DEMO_LPADC_VREF_SOURCE */ #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS) && FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS mLpadcConfigStruct.conversionAverageMode = kLPADC_ConversionAverage; //変換結果平均化設定、平均しない/2回の平均/4回の平均/8回の平均/16回の平均....1024回の平均化選択可能 #endif     4.4 设备初始化     时钟分频比初始化 CLOCK_SetClockDiv 函数处理 ADC 外设使用的时钟分频设置。 //(lpadc\interrupt\hardware_init.cから抜粋) /* Attach peripheral clock */ CLOCK_SetClockDiv(kCLOCK_DivADC0, 1u); div_name:选择枚举定义的分频器。 值:除法比率 *以下代码是从 fsl_clock.c 开始的驱动程序部分,不建议用户修改。 //(fsl_clock.cから抜粋) void CLOCK_SetClockDiv(clock_div_name_t div_name, uint32_t value) { volatile uint32_t *pDivCtrl = (volatile uint32_t *)(MRCC0_BASE + (uint32_t)div_name); assert(div_name <= kCLOCK_DivMax); /* Unlock clock configuration */ SYSCON->CLKUNLOCK &= ~SYSCON_CLKUNLOCK_UNLOCK_MASK; /* halt and reset clock dividers */ *pDivCtrl = 0x3UL << 29U; if (value == 0U) /*!< halt */ { *pDivCtrl |= (1UL << 30U); } else { *pDivCtrl = (value - 1U); } /* Freeze clock configuration */ SYSCON->CLKUNLOCK |= SYSCON_CLKUNLOCK_UNLOCK_MASK; }   时钟选择 CLOCK_AttachClk 选择 ADC 外设要使用的四个时钟源之一。 驱动程序通过将 `clock_attach_id_t` 结构中定义的值作为参数传递给 `void CLOCK_AttachClk(clock_attach_id_t connection)` 函数来配置连接。 //(fsl_clock.hから抜粋) kFRO12M_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 0U), /* Attach FRO12M to ADC0. */ kFRO_HF_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 1U), /* Attach FRO_HF to ADC0. */ kCLK_IN_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 3U), /* Attach CLK_IN to ADC0. */ kCLK_1M_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 5U), /* Attach CLK_1M to ADC0. */ kNONE_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 7U), /* Attach NONE to ADC0. */ //(lpadc\interrupt\hardware_init.cから抜粋) CLOCK_AttachClk(kFRO12M_to_ADC0); 以下函数是 SDK 提供的驱动程序部分的一部分,从 fsl_clock.c 开始,不建议用户修改它们。 //(fsl_clock.hから抜粋) void CLOCK_AttachClk(clock_attach_id_t connection) { const uint32_t reg_offset = CLK_ATTACH_REG_OFFSET(connection); const uint32_t clk_sel = CLK_ATTACH_CLK_SEL(connection); if (kNONE_to_NONE != connection) { CLOCK_SetClockSelect((clock_select_name_t)reg_offset, clk_sel); } } //(fsl_clock.hから抜粋) void CLOCK_SetClockSelect(clock_select_name_t sel_name, uint32_t value) { volatile uint32_t *pClkCtrl = (volatile uint32_t *)(MRCC0_BASE + (uint32_t)sel_name); assert(sel_name <= kCLOCK_SelMax); if (sel_name == kCLOCK_SelSCGSCS) { SCG0->RCCR = (SCG0->RCCR & ~(SCG_RCCR_SCS_MASK)) | SCG_RCCR_SCS(value); while ((SCG0->CSR & SCG_CSR_SCS_MASK) != SCG_CSR_SCS(value)) { } } else { /* Unlock clock configuration */ SYSCON->CLKUNLOCK &= ~SYSCON_CLKUNLOCK_UNLOCK_MASK; *pClkCtrl = value; /* Freeze clock configuration */ SYSCON->CLKUNLOCK |= SYSCON_CLKUNLOCK_UNLOCK_MASK; } } 关于电路板初始化功能 时钟将被初始化。   引脚初始化 调用 InitPins() 函数,并处理 pin_mux.c 文件。pin_mux.c 文件由 NXP 的 MCUXPresso 使用。可以使用集成到 IDE 中的引脚配置工具来覆盖此设置。 //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitPins(); BOARD_InitPins() 函数执行四个操作。 启用外围时钟 禁用外围设备复位 外部引脚对引脚和外设连接(MUX 配置)-> 结构体参数设置 在登记簿中写入 3   初始化启动时钟 MCX A153 支持中等驱动模式和标准驱动模式。这两种模式分别对应 1.0 V 和 1.1 V 的 VDD_CORE 电压,以及 48 MHz 或 96 MHz 的 rfo_hf 时钟频率。切换模式需要外部电源,并且需要配置与电压相关的寄存器,例如 LDO。 //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitBootClocks(); 时钟是通过与工作频率相对应的寄存器设置功能来设置的。 //(fsl_clock.cから抜粋) void BOARD_InitBootClocks(void) { BOARD_BootClockFRO96M(); }     初始化调试端口 //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitDebugConsole();   //(board.cから抜粋) void BOARD_InitDebugConsole(void) { /* attach 12 MHz clock to LPUART0 (debug console) */ CLOCK_SetClockDiv(kCLOCK_DivLPUART0, 1u); CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH); RESET_PeripheralReset(BOARD_DEBUG_UART_RST); DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, BOARD_DEBUG_UART_CLK_FREQ); }   应用程序初始化 ADC 初始化在 LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct) 函数中处理。LPADC_Init() 函数位于 fsl_lpadc.c 的驱动程序部分。 DEMO_LPADC_BASE:0x400A_F000 -> ADC 的起始地址 定义结构表并配置ADC。 typedef struct {} lpadc_config_t 姓名 属性 说明 lpadc_config_t 类型 LPADC配置参数信息 启用休眠模式 布尔值 ADC转换期间的操作设置基于模式 转换平均模式 lpadc_conversion_average_mode_t 与自动校准相关的设置 启用模拟初步 布尔值 ADC启动前设置 上电延迟 uint32_t ADC电路的稳定时间 参考电压源 lpadc_reference_voltage_source_t 参考电压源 功率级别模式 lpadc_power_level_mode_t 电源配置选择 触发优先级策略 lpadc_trigger_priority_policy_t 如何处理高利润触发因素 启用会话暂停 布尔值 设置 AD 转换执行间隔。 对话暂停延迟 uint32_t 命令序列期间的暂停时间 先进先出水印 uint32_t FIFO 中数据点数量的阈值设置。 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct); //(fsl_lpadc.cから抜粋) void LPADC_Init(ADC_Type *base, const lpadc_config_t *config) { /* 省略 */ base->CTRL |= ADC_CTRL_CAL_AVGS(config->conversionAverageMode); /* 省略 */ }   关于ADC校准   在使用模数转换器 (ADC) 之前,需要进行校准以校正转换结果中包含的偏移误差和其他因素,从而提高模数转换的精度。 校准过程大致可分为以下两个阶段: 设置校准模式和条件。 执行校准并将校正值应用于ADC。   在默认示例中,ADC 校准在执行完 LPADC_Init() 之后、AD 转换开始之前进行。首先,使用 LPADC_SetOffsetCalibrationMode() 在相应的器件上设置偏移校准模式。然后,如果启用了 DEMO_LPADC_DO_OFFSET_CALIBRATION,则执行 LPADC_DoOffsetCalibration();否则,使用预先通过 LPADC_SetOffsetValue() 设置的偏移值。 此外,如果启用了相应的函数宏,则在延迟 1 µs 或更长时间后执行 LPADC_DoAutoCalibration() 函数。该函数用于校准增益误差和线性误差。仅当器件支持的功能宏启用时,才会编译相应的进程。 以下是LPADC校准模式的设置。 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) /* Request LPADC calibration. */ #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE) && FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE LPADC_SetOffsetCalibrationMode(DEMO_LPADC_BASE, DEMO_LPADC_OFFSET_CALIBRATION_MODE); #endif /* FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE */     执行偏移校准 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFS) && \ FSL_FEATURE_LPADC_HAS_CTRL_CALOFS #if defined(DEMO_LPADC_DO_OFFSET_CALIBRATION) && \ DEMO_LPADC_DO_OFFSET_CALIBRATION L PADC_DoOffsetCalibration(DEMO_LPADC_BASE); //キャリブレーションを実行しない場合 #else /* Update OFSTRIM register manually. */   5. MCX A153 DMA 为什么ADC转换要使用DMA传输? 当仅通过软件处理ADC采集的数据时,CPU需要监控ADC转换的完成情况,读取转换结果并将其写入内存。对于单次ADC转换而言,这并非主要问题;但当以固定间隔连续采样或处理多个输入通道时,此过程会反复发生。因此,CPU的处理负载会增加,从而可能减少可用于其他应用程序处理的时间。 解决此问题的一种方法是使用 DMA(直接内存访问)传输 ADC 转换结果。使用 DMA,ADC 转换完成后,转换结果可以自动传输到内存。换句话说,由于从获取 ADC 转换结果到将其存储到内存的过程可以由硬件处理,因此可以减少 CPU 执行的数据传输处理量,从而降低软件的处理负载。 鉴于以上原因,ADC和DMA的组合配置常用于需要连续模数转换和高速数据采集的应用中。本文将首先介绍ADC的基本初始化方法,然后介绍如何使用MCX A153通过DMA将ADC转换结果传输到存储器。 使用DMA进行AD转换值传输概述 AD转换后的数据存储在ADC外设的缓冲区中。ADC无需每次都手动读取数据,而是可以通过DMA传输数据。例如,程序可以修改为连续执行五次AD转换,然后通过DMA将数据保存到RAM缓冲区,并在控制台上显示平均值、最小值和最大值。 使用DMA传输AD转换值的步骤 我们将修改ADC示例代码,添加DMA处理功能。 DMA 激活是通过来自 ADC 的 DMA 请求信号执行的。 使用 DMA,将 ADC FIFO 值(5 次转换)复制到 RAM,并向 CPU 发出中断通知。 CPU 在 DMA 传输完成后,在主循环中取平均值,并将最小值、最大值和平均值显示在控制台上。     防范措施 要添加 DMA 代码,您需要将 DMA 驱动程序头文件和源代码添加到您的项目中。最简单的方法是从 MCUXpresso IDE 创建一个示例 DMA 代码 (frdmmcxa153_edma3_memory_to_memory_transfer) 并复制它。只需从 drivers 目录复制以下文件即可。 fsl_edma_core.h fsl_edma_soc.c fsl_edma_soc.h fsl_edma.c fsl_edma.h   5.1 与ADC相关的代码修改和新增   代码修改步骤 ADC转换完成后发生的中断已被禁用。 添加了ADC配置。 设置为连续执行 5 次 AD 转换。 启用DMA请求 将先进先出 (FIFO) 水印设置为 4。 增加了处理功能,以获取 DMA 传输值的平均值、最小值和最大值,并将它们输出到控制台。     1. 当ADC转换完成后,禁用中断。 由于中断使能寄存器 (IE) 是通过 LPADC_EnableInterrupts() 函数和 kLPADC_FIFOWatermarkInterruptEnable 启用的,因此我们将注释掉这一行。 // LPADC_EnableInterrupts(DEMO_LPADC_BASE, kLPADC_FIFOWatermarkInterruptEnable);   2. 添加ADC配置 ADC 配置为循环 5 次(= 5 次 AD 转换)。 mLpadcCommandConfigStruct.loopCount = 4 //loopCount +1回の変換 启用DMA请求 //178行目 LPADC_EnableFIFOWatermarkDMA(DEMO_LPADC_BASE, 1); // 1でDMA Requestがイネーブル     3. 将先进先出 (FIFO) 中的水印级别数设置为 4。 // 33行目 /* ++ ADCのマクロ */ #define FIFO0WatermarkLEVEL (4) //108行目 mLpadcConfigStruct.FIFOWatermark = FIFO0WatermarkLEVEL;   4. 增加了处理,以获取 DMA 传输的值和控制台输出的平均值、最小值和最大值。 uint32_t adc_values[5] = {0}; PRINTF("Please press any key to get user channel's ADC value.\r\n"); while(1) { GETCHAR(); EXAMPLE_DMA_BASEADDR->CH[0].CH_CSR = DMA_CH_CSR_ERQ(1); EXAMPLE_DMA_BASEADDR->CH[0].TCD_DLAST_SGA = -0x14; LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */ while (!g_Transfer_Done) { /* DMA転送終了割り込み待ち */ } g_Transfer_Done = false; uint16_t min=adc_values[0]; uint16_t max=adc_values[0]; uint32_t sum=0; for(uint32_t i=0; i<5; i++) { if(max < (0x0000FFFF & adc_values[i])) max = adc_values[i]; if(min > (0x0000FFFF & adc_values[i])) min = adc_values[i]; sum += 0x0000FFFF & adc_values[i]; } PRINTF("ADC Min: %d, Max: %d, ave: %d\r\n", min, max, sum/5); for(size_t i=0; i<5; i++) { adc_values[i] = 0; } sum = 0; }   5.2 添加DMA相关代码   代码添加政策 包含头文件 添加了与DMA相关的宏。 DMA配置和初始化 DMA传输配置 DMA传输完成中断处理   1. 包含标题 // 10行目 #include "fsl_debug_console.h" #include "pin_mux.h" #include "clock_config.h" #include "board.h" #include "fsl_lpadc.h" /* ++ */ #include "fsl_edma.h" // DMAドライバヘッダファイルの追加 #include "fsl_clock.h" #include "fsl_reset.h"   2. 添加与 DMA 相关的宏。 // 32行目 #define EXAMPLE_DMA_BASEADDR DMA0 #define DEMO_DMA_CHANNEL_0 0U #define APP_DMA_IRQ DMA_CH0_IRQn #define APP_DMA_IRQ_HANDLER DMA_CH0_IRQHandler     3. DMA配置 // 197行目 edma_transfer_config_t transferConfig; edma_config_t userConfig; // 203行目 RESET_PeripheralReset(kDMA_RST_SHIFT_RSTn); /* Configure EDMA channel for one shot transfer */ EDMA_GetDefaultConfig(&userConfig); EDMA_Init(EXAMPLE_DMA_BASEADDR, &userConfig);     4. DMA传输配置 // 209行目 EDMA_PrepareTransfer(&transferConfig, (void *)0x400AF300, // eDMA transfer source address. sizeof(uint32_t), // eDMA transfer source address width(bytes) (void *)adc_values, // eDMA transfer destination address sizeof(&adc_values), // eDMA transfer destination address width(bytes) sizeof(adc_values), // eDMA transfer bytes per channel request sizeof(adc_values), // eDMA transfer bytes to be transferred kEDMA_PeripheralToMemory // eDMA transfer type ); EDMA_SetTransferConfig(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, &transferConfig, NULL); EDMA_SetChannelMux(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kDma0RequestMuxAdc0FifoRequest); EnableIRQ(APP_DMA_IRQ); EDMA_EnableChannelInterrupts(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kEDMA_MajorInterruptEnable); 在用软件触发启动软件 ADC 之前,添加 EDMA_TriggerChannelStart() 以在 DMA 通道 0 上触发中断。当 DMA 中断标志被清除时,DMA 触发的中断将被禁用,因此该处理是在 ADC 的软件触发之前添加的。 // 242行目 while(1) { GETCHAR(); EDMA_TriggerChannelStart(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0); EXAMPLE_DMA_BASEADDR->CH[0].TCD_DLAST_SGA = -0x14; LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */ while (!g_Transfer_Done) { /* DMA転送終了割り込み待ち */ } g_Transfer_Done = false;   5. DMA传输完成中断处理 void APP_DMA_IRQ_HANDLER(void) { if ((EDMA_GetChannelStatusFlags(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0) & kEDMA_InterruptFlag) != 0U) { EDMA_ClearChannelStatusFlags(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kEDMA_InterruptFlag); g_Transfer_Done = true; } } 概括: 本文介绍了MCX A153 ADC的基本功能和注意事项,以及如何使用VS Code SDK的ADC示例项目进行初始化和转换。阅读本文后半部分,您将看到一些配置示例和代码流程,这些内容在实际开发中非常有用,涵盖了从使用ADC示例进行初始化和转换,到使用DMA自动传输转换结果等各个环节。(建议您先运行ADC示例并确认其运行正常,然后再添加DMA,这样更容易排查问题。) =========================​ 我们目前无法 回复 此帖子“ 评论”部分留下的评论。 对于由此造成的不便,我们深表歉意,但在进行咨询时,请参考“ NXP技术问题-如何联系我们(日语博客) ”。 (如果您已经是 恩智浦的 分销商或 与 恩智浦 有合作关系 ,您可以直接咨询您的代表。 ) 本文全面讲解了MCX A153中ADC(模数转换器)的基础知识,包括如何使用MCUXpresso SDK进行初始化,以及如何使用DMA自动传输转换结果。如果您是第一次使用ADC或DMA,建议您先阅读第1章和第2章,了解整体概念,然后再阅读第4章的示例代码和第5章的DMA设置,以便更好地理解。 ADC:一种将模拟信号(例如来自传感器的信号)转换为微控制器可以处理的数字值的功能。 DMA:一种无需经过 CPU 即可在外围设备和内存之间传输数据的功能。 SDK:包含软件开发所需的驱动程序和示例代码的开发工具包。 (阅读时间:30分钟) 通用微控制器 介绍 MCUXpresso IDE MCUXpresso SDK 日本博客
View full article
[MCX A153] Basics and Usage of the ADC Module (Japanese Blog) This article explains the basic usage of the ADC (Analog-to-Digital Converter) module installed in the MCX A153 . Starting with application examples using the ADC, it summarizes the main functions, block structure, and points to note when using it, and then introduces device initialization using SDK sample code and how to transfer ADC conversion results using DMA. This article aims to help you understand the fundamentals required when using the MCX A153 ADC in your applications, enabling you to implement everything from initial setup for ADC conversion to efficient data transfer utilizing DMA.   table of contents 1. Common use cases in applications 1.1 Main Uses 1.2 Usage example 2. Main functions and block diagram of the MCX A153 ADC module 2.1 Overview 2.2 Main Features 2.3 Block Diagram 3. Points to note and restrictions 4. ADC Sample Code (Device Initialization) 4.1 Overview of Sample Code 4.2 Opening the SDK Sample Project 4.3 Macro Definitions 4.4 Device Initialization 5. Transfer of AD conversion values using MCX A153 DMA 5.1 Code related to ADC 5.2 DMA-related code summary 1. Common use cases in applications An ADC converts analog signals (continuously changing voltages) input from sensors, potentiometers, etc., into digital values (numerical values) that a microcontroller can use for calculations. 1.1 Main Uses Converts the analog voltage value input from the potentiometer to a digital value. A potentiometer is attached to the shaft of a servo motor, such as those used in radio-controlled vehicles, to detect the angle of rotation of the motor from the change in output. Convert analog signals from various sensors into digital values. It detects the tilt of an object by converting analog signals from an accelerometer. This can be applied to detecting the orientation of a smartphone, for example. The ambient temperature is measured by converting the analog signal from the temperature sensor.   1.2 Usage Examples (These are examples illustrating the general concept, so details are omitted.) Examples of potentiometer usage:         2. Main Functions and Block Diagram   2.1 Overview The MCX A153 is equipped with a 16-bit analog-to-digital converter (ADC). An ADC is a circuit that converts analog voltages into digital values.   2.2 Main Features Equipped with one successive approximation AD converter unit. Supports 16-bit or 12-bit resolution and single-ended input (higher resolution allows for finer representation of input voltage). Number of channels installed (varies depending on the package): 64-pin LQFP: 24 channels, 48-pin LQFP: 16 channels, 48-pin HVQFN: 18 channels, 32-pin HVQFN: 9 channels Sampling rate (how many times per second the data can be converted) 16-bit mode: up to 3.2 Msps, 12-bit mode: up to 4 Msps Sample time can be set. Can operate in low-power mode of the microcontroller. Supports four trigger sources (software or hardware triggers). Seven command buffers enable scanning of consecutive channels. Supports compare function (automatically compares smaller, larger, within range, outside range, save as match, etc.) Equipped with eight FIFOs for conversion result data, featuring watermark and overflow detection functions. Supports interrupts, DMA, and polling. Calibration function Built-in temperature sensor with dedicated input channel   2.3 Block Diagram MCX A153 Reference Manual (MCXAP64M96FS3RM) Figure 165. Excerpt from ADC block diagram   Example of using SDK sample code (connecting a potentiometer)     3. MCX A153 ADC Module This section explains important points and limitations to consider before using the MCX A153's ADC. Speed reduction in 16-bit mode The MCX A153's ADC supports two modes: 16-bit (ENOB16: 16-bit effective resolution) and 12-bit (ENOB12: 12-bit effective resolution). However, the 16-bit mode has a lower sampling rate than the 12-bit mode. (Excerpt from MCX A153 DataSheet Table.34) Timing of calibration execution Calibration requests and execution must be performed during reset or power-on. Furthermore, the clock source and frequency must be configured before calibration can be performed. Averaging of conversion results The ADC module can average multiple results for the same channel before saving the conversion result. The hardware averaging function is enabled when the CMDHa[AVGS] bit field is set to a non-zero value. It can be used in any conversion mode and reduces the burden of calculating the average in software. 4. Sample code for AD conversion 4.1 Overview of Sample Code When the main sequence is executed, device initialization is performed. Device initialization begins with setting the clock, configuring the external terminals, and selecting the peripherals to connect to the terminals. After that, the peripherals (ADC, UART) are initialized and interrupts are enabled. After the initialization process, a software trigger is set within the loop to start ADC conversion, and the AD conversion value and the number of conversions are displayed on the console. For hardware, we will use the MCX A153 development board "FRDM-MCXA153".   4.2 Steps to open the ADC sample project in VS Code 4.2.1 Preparing VS Code and Extensions Install VS Code. Search for "MCUXpresso for VS Code" in the Extensions view (Ctrl+Shift+X) and install it. The MCUXpresso icon will appear in the activity bar on the left. Click it to open the QUICKSTART PANEL.   4.2.2 Installing Dependent Tools Run "Open MCUXpresso Installer" in the QUICKSTART PANEL. Select and install the following tool. Arm GNU Toolchain CMake / Ninja Python / West Git LinkServer (Debug probe for MCU-Link) SDK-related tools After completion, restart VS Code.   4.2.3Incorporating the SDK repository Click "Import Repository" in the QUICKSTART PANEL. Select "Remote" as the source for importing data.   Specify the destination folder. The path should be short and should not contain Japanese characters or spaces. You can import the repository by checking "I agree" and pressing the Import button.   4.2.4 Importing Samples In the QUICKSTART PANEL, click "Import Example from Repository". Set it as follows:   You can import the project by clicking the Import button. item Set value Repository The SDK (frdm_mcxa153) imported in step 3 Toolchain Arm GNU Toolchain Board frdmmcxa153 (FRDM-MCXA153) Template driver_examples → lpadc → interrupt(lpadc_interrupt) Location Project save location Name Optional (default is lpadc_interrupt) 4.3 Macro Definitions This is the macro definition code for the ADC's functions (excerpted from lpadc\interrupt\app.h). Please adjust the input channels, resolution settings, and reference voltage sources to match your actual circuit design and intended use. Definitions //(lpadc\interrupt\app.hから抜粋) /******************************************************************************/ #define DEMO_LPADC_BASE ADC0 //ADCのinstance、ベースアドレス、MCX A153は1個 ADCしかない #define DEMO_LPADC_IRQn ADC0_IRQn #define DEMO_LPADC_IRQ_HANDLER_FUNC ADC0_IRQHandler #define DEMO_LPADC_USER_CHANNEL 0U //チャンネル番号 #define DEMO_LPADC_USER_CMDID 1U //コマンドID #define DEMO_LPADC_VREF_SOURCE kLPADC_ReferenceVoltageAlt3 //参考電圧ソース #define DEMO_LPADC_DO_OFFSET_CALIBRATION true //オフセットキャリブレーションの利用可否 #define DEMO_LPADC_USE_HIGH_RESOLUTION true //高分解能の利用可否 Variables related to ADC Variables //(lpadc\interrupt\lpadc_interrupt.cから抜粋) volatile bool g_LpadcConversionCompletedFlag = false; volatile uint32_t g_LpadcInterruptCounter = 0U; lpadc_conv_result_t g_LpadcResultConfigStruct; #if (defined(DEMO_LPADC_USE_HIGH_RESOLUTION) && DEMO_LPADC_USE_HIGH_RESOLUTION) //高分解能 const uint32_t g_LpadcFullRange = 65536U; const uint32_t g_LpadcResultShift = 0U; #else //低分解能 const uint32_t g_LpadcFullRange = 4096U; const uint32_t g_LpadcResultShift = 3U; #endif /* DEMO_LPADC_USE_HIGH_RESOLUTION */ Defaulting of the ADC configuration structure (details can be found in fsl_lpadc.c), averaging of conversion results. //(lpadc\interrupt\lpadc_interrupt.cから抜粋) LPADC_GetDefaultConfig(&mLpadcConfigStruct); mLpadcConfigStruct.enableAnalogPreliminary = true; //ADCアナログ回路は事前に有効化され、起動遅延なしで変換を実行する準備 #if defined(DEMO_LPADC_VREF_SOURCE) mLpadcConfigStruct.referenceVoltageSource = DEMO_LPADC_VREF_SOURCE; //参考電圧ソース #endif /* DEMO_LPADC_VREF_SOURCE */ #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS) && FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS mLpadcConfigStruct.conversionAverageMode = kLPADC_ConversionAverage; //変換結果平均化設定、平均しない/2回の平均/4回の平均/8回の平均/16回の平均....1024回の平均化選択可能 #endif     4.4 Device Initialization     Initialization of clock division ratio The CLOCK_SetClockDiv function handles the clock division settings used by the ADC peripheral. //(lpadc\interrupt\hardware_init.cから抜粋) /* Attach peripheral clock */ CLOCK_SetClockDiv(kCLOCK_DivADC0, 1u); div_name: Select a frequency divider defined by the enumeration. value: division ratio *The following code is the driver section starting with fsl_clock.c, and user modification is not recommended. //(fsl_clock.cから抜粋) void CLOCK_SetClockDiv(clock_div_name_t div_name, uint32_t value) { volatile uint32_t *pDivCtrl = (volatile uint32_t *)(MRCC0_BASE + (uint32_t)div_name); assert(div_name <= kCLOCK_DivMax); /* Unlock clock configuration */ SYSCON->CLKUNLOCK &= ~SYSCON_CLKUNLOCK_UNLOCK_MASK; /* halt and reset clock dividers */ *pDivCtrl = 0x3UL << 29U; if (value == 0U) /*!< halt */ { *pDivCtrl |= (1UL << 30U); } else { *pDivCtrl = (value - 1U); } /* Freeze clock configuration */ SYSCON->CLKUNLOCK |= SYSCON_CLKUNLOCK_UNLOCK_MASK; }   Clock selection CLOCK_AttachClk selects one of four clock sources to be used by the ADC peripheral. The driver configures the connection by passing a value defined in the `clock_attach_id_t` structure as an argument to the `void CLOCK_AttachClk(clock_attach_id_t connection)` function. //(fsl_clock.hから抜粋) kFRO12M_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 0U), /* Attach FRO12M to ADC0. */ kFRO_HF_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 1U), /* Attach FRO_HF to ADC0. */ kCLK_IN_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 3U), /* Attach CLK_IN to ADC0. */ kCLK_1M_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 5U), /* Attach CLK_1M to ADC0. */ kNONE_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 7U), /* Attach NONE to ADC0. */ //(lpadc\interrupt\hardware_init.cから抜粋) CLOCK_AttachClk(kFRO12M_to_ADC0); The following functions are part of the driver section provided by the SDK, starting with fsl_clock.c, and it is not recommended that users modify them. //(fsl_clock.hから抜粋) void CLOCK_AttachClk(clock_attach_id_t connection) { const uint32_t reg_offset = CLK_ATTACH_REG_OFFSET(connection); const uint32_t clk_sel = CLK_ATTACH_CLK_SEL(connection); if (kNONE_to_NONE != connection) { CLOCK_SetClockSelect((clock_select_name_t)reg_offset, clk_sel); } } //(fsl_clock.hから抜粋) void CLOCK_SetClockSelect(clock_select_name_t sel_name, uint32_t value) { volatile uint32_t *pClkCtrl = (volatile uint32_t *)(MRCC0_BASE + (uint32_t)sel_name); assert(sel_name <= kCLOCK_SelMax); if (sel_name == kCLOCK_SelSCGSCS) { SCG0->RCCR = (SCG0->RCCR & ~(SCG_RCCR_SCS_MASK)) | SCG_RCCR_SCS(value); while ((SCG0->CSR & SCG_CSR_SCS_MASK) != SCG_CSR_SCS(value)) { } } else { /* Unlock clock configuration */ SYSCON->CLKUNLOCK &= ~SYSCON_CLKUNLOCK_UNLOCK_MASK; *pClkCtrl = value; /* Freeze clock configuration */ SYSCON->CLKUNLOCK |= SYSCON_CLKUNLOCK_UNLOCK_MASK; } } Regarding the board initialization function The clock will be initialized.   Pin initialization The InitPins() function is called, and the pin_mux.c file is processed. The pin_mux.c file is used by NXP's MCUXPressoThis can be overridden using the Pin Config tool integrated into the IDE. //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitPins(); The BOARD_InitPins() function performs four operations. Enable peripheral clock Disable peripheral reset External pin-to-pin and peripheral connection (MUX configuration) -> Parameter setting for the structure Write 3 to the register   Initializing the boot clock The MCX A153 supports Mid Drive Mode and Standard Drive Mode. These modes operate with VDD_CORE voltage levels of 1.0 V and 1.1 V, respectively, and with an rfo_hf clock of 48 MHz or 96 MHz. Switching modes requires external power supply and configuration of voltage-related registers such as the LDO. //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitBootClocks(); The clock is set using a register setting function that corresponds to the operating frequency. //(fsl_clock.cから抜粋) void BOARD_InitBootClocks(void) { BOARD_BootClockFRO96M(); }     Initializing the debug port //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitDebugConsole();   //(board.cから抜粋) void BOARD_InitDebugConsole(void) { /* attach 12 MHz clock to LPUART0 (debug console) */ CLOCK_SetClockDiv(kCLOCK_DivLPUART0, 1u); CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH); RESET_PeripheralReset(BOARD_DEBUG_UART_RST); DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, BOARD_DEBUG_UART_CLK_FREQ); }   Application initialization ADC initialization is handled within the LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct); function. The LPADC_Init() function is a function in the driver section of fsl_lpadc.c. DEMO_LPADC_BASE: 0x400A_F000 -> Starting address of the ADC Define the structure table and configure the ADC. typedef struct {} lpadc_config_t name attribute explanation lpadc_config_t type LPADC Configuration Parameter Information enableInDozeMode bool Operation settings based on mode during ADC conversion conversionAverageMode lpadc_conversion_average_mode_t Settings related to Auto Calibration enableAnalogPreliminary bool ADC pre-startup settings PowerUpDelay uint32_t Stabilization time of ADC circuit referenceVoltageSource lpadc_reference_voltage_source_t Source of reference voltage powerLevelMode lpadc_power_level_mode_t Power supply configuration selection triggerPriorityPolicy lpadc_trigger_priority_policy_t How to process high-profitability triggers EnableConvPause bool Setting the AD conversion execution interval. convPauseDelay uint32_t Pause time during command sequence FIFOWatermark uint32_t Threshold setting for the number of data points in FIFO //(lpadc\interrupt\lpadc_interrupt.cから抜粋) LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct); //(fsl_lpadc.cから抜粋) void LPADC_Init(ADC_Type *base, const lpadc_config_t *config) { /* 省略 */ base->CTRL |= ADC_CTRL_CAL_AVGS(config->conversionAverageMode); /* 省略 */ }   About ADC calibration   Before using an ADC, calibration is performed to correct for offset errors and other factors included in the conversion result, thereby improving the accuracy of the AD conversion. The calibration process can be broadly divided into the following two stages: Set the calibration mode and conditions. Perform calibration and apply the correction values to the ADC.   In the default sample, ADC calibration is performed after LPADC_Init() is executed and before AD conversion begins. First, the offset calibration mode is set with LPADC_SetOffsetCalibrationMode() on the corresponding device. Then, if DEMO_LPADC_DO_OFFSET_CALIBRATION is enabled, LPADC_DoOffsetCalibration() is executed; otherwise, the offset value set in advance with LPADC_SetOffsetValue() is used. Furthermore, if the corresponding function macro is enabled, LPADC_DoAutoCalibration() is executed after a delay of 1 µs or more. This performs calibration of gain errors and linearity errors. Each process is compiled only if the function macro supported by the device is enabled. The following are the settings for the LPADC calibration mode. //(lpadc\interrupt\lpadc_interrupt.cから抜粋) /* Request LPADC calibration. */ #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE) && FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE LPADC_SetOffsetCalibrationMode(DEMO_LPADC_BASE, DEMO_LPADC_OFFSET_CALIBRATION_MODE); #endif /* FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE */     Performing offset calibration //(lpadc\interrupt\lpadc_interrupt.cから抜粋) #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFS) && \ FSL_FEATURE_LPADC_HAS_CTRL_CALOFS #if defined(DEMO_LPADC_DO_OFFSET_CALIBRATION) && \ DEMO_LPADC_DO_OFFSET_CALIBRATION L PADC_DoOffsetCalibration(DEMO_LPADC_BASE); //キャリブレーションを実行しない場合 #else /* Update OFSTRIM register manually. */   5. MCX A153 DMA Why use DMA transfer for ADC conversion? When processing data acquired by an ADC solely in software, the CPU needs to monitor the completion of the ADC conversion, read the conversion results, and write them to memory. This is not a major problem for a single AD conversion, but when sampling continuously at regular intervals or when handling multiple input channels, this process occurs repeatedly. As a result, the CPU processing load increases, potentially reducing the time available for other application processing. One way to solve this problem is to transfer the ADC conversion results using DMA (Direct Memory Access). Using DMA, the ADC conversion results can be automatically transferred to memory as soon as the ADC conversion is complete. In other words, since the process from acquiring the ADC conversion results to storing them in memory can be handled by hardware, the amount of data transfer processing performed by the CPU can be reduced, and the processing load on the software can be lowered. For these reasons, configurations combining ADC and DMA are often used in applications requiring continuous AD conversion and high-speed data acquisition. This article will first explain the basic initialization method of the ADC, and then introduce how to transfer the ADC conversion result to memory using DMA with the MCX A153. Overview of AD conversion value transfer using DMA The data after AD conversion is stored in a buffer within the ADC peripheral. Instead of reading the data manually each time, the ADC may trigger DMA to transfer the data. For example, the program will be modified to perform AD conversion five times consecutively, then save the data to a RAM buffer via DMA, and display the average, minimum, and maximum values on the console. Procedure for transferring AD conversion values using DMA We will modify the ADC sample code to add DMA processing. DMA activation is performed using a DMA Request signal from the ADC. Using DMA, the ADC FIFO values (for 5 conversions) are copied to RAM, and an interrupt is notified to the CPU. The CPU takes the average value within the main loop after the DMA transfer is complete and displays the min, max, and ave values to the console.     Precautions To add DMA code, you need to add the DMA driver header file and source code to your project. The easiest way to do this is to create a sample DMA code (frdmmcxa153_edma3_memory_to_memory_transfer) from the MCUXpresso IDE and copy it. Simply copy the following files from the drivers directory. fsl_edma_core.h fsl_edma_soc.c fsl_edma_soc.h fsl_edma.c fsl_edma.h   5.1 Code modifications and additions related to ADC   Code modification steps The interrupt that occurs when ADC conversion is complete has been disabled. Added ADC configuration. Setting to perform AD conversion 5 times consecutively. Enable DMA requests Set the FIFO watermark to 4. Added processing to obtain the average, minimum, and maximum values of the values transferred by DMA, and to output them to the console.     1. Disable interrupts when ADC conversion is complete. Since the Interrupt Enable Register (IE) is enabled using the LPADC_EnableInterrupts() function and kLPADC_FIFOWatermarkInterruptEnable, we will comment out this line. // LPADC_EnableInterrupts(DEMO_LPADC_BASE, kLPADC_FIFOWatermarkInterruptEnable);   2. Add ADC configuration The ADC is configured to loop 5 times (= 5 AD conversions). mLpadcCommandConfigStruct.loopCount = 4 //loopCount +1回の変換 Enable DMA requests //178行目 LPADC_EnableFIFOWatermarkDMA(DEMO_LPADC_BASE, 1); // 1でDMA Requestがイネーブル     3. Set the number of Watermark levels in the FIFO to 4. // 33行目 /* ++ ADCのマクロ */ #define FIFO0WatermarkLEVEL (4) //108行目 mLpadcConfigStruct.FIFOWatermark = FIFO0WatermarkLEVEL;   4. Added processing to obtain the average, minimum, and maximum values of the values transferred by DMA, and console output. uint32_t adc_values[5] = {0}; PRINTF("Please press any key to get user channel's ADC value.\r\n"); while(1) { GETCHAR(); EXAMPLE_DMA_BASEADDR->CH[0].CH_CSR = DMA_CH_CSR_ERQ(1); EXAMPLE_DMA_BASEADDR->CH[0].TCD_DLAST_SGA = -0x14; LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */ while (!g_Transfer_Done) { /* DMA転送終了割り込み待ち */ } g_Transfer_Done = false; uint16_t min=adc_values[0]; uint16_t max=adc_values[0]; uint32_t sum=0; for(uint32_t i=0; i<5; i++) { if(max < (0x0000FFFF & adc_values[i])) max = adc_values[i]; if(min > (0x0000FFFF & adc_values[i])) min = adc_values[i]; sum += 0x0000FFFF & adc_values[i]; } PRINTF("ADC Min: %d, Max: %d, ave: %d\r\n", min, max, sum/5); for(size_t i=0; i<5; i++) { adc_values[i] = 0; } sum = 0; }   5.2 Adding DMA-related code   Code Addition Policy Include header files Added DMA-related macros. DMA configuration and initialization DMA transfer configuration DMA transfer completion interrupt handling   1. Include headers // 10行目 #include "fsl_debug_console.h" #include "pin_mux.h" #include "clock_config.h" #include "board.h" #include "fsl_lpadc.h" /* ++ */ #include "fsl_edma.h" // DMAドライバヘッダファイルの追加 #include "fsl_clock.h" #include "fsl_reset.h"   2. Add DMA-related macros. // 32行目 #define EXAMPLE_DMA_BASEADDR DMA0 #define DEMO_DMA_CHANNEL_0 0U #define APP_DMA_IRQ DMA_CH0_IRQn #define APP_DMA_IRQ_HANDLER DMA_CH0_IRQHandler     3. DMA Configuration // 197行目 edma_transfer_config_t transferConfig; edma_config_t userConfig; // 203行目 RESET_PeripheralReset(kDMA_RST_SHIFT_RSTn); /* Configure EDMA channel for one shot transfer */ EDMA_GetDefaultConfig(&userConfig); EDMA_Init(EXAMPLE_DMA_BASEADDR, &userConfig);     4. DMA transfer configuration // 209行目 EDMA_PrepareTransfer(&transferConfig, (void *)0x400AF300, // eDMA transfer source address. sizeof(uint32_t), // eDMA transfer source address width(bytes) (void *)adc_values, // eDMA transfer destination address sizeof(&adc_values), // eDMA transfer destination address width(bytes) sizeof(adc_values), // eDMA transfer bytes per channel request sizeof(adc_values), // eDMA transfer bytes to be transferred kEDMA_PeripheralToMemory // eDMA transfer type ); EDMA_SetTransferConfig(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, &transferConfig, NULL); EDMA_SetChannelMux(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kDma0RequestMuxAdc0FifoRequest); EnableIRQ(APP_DMA_IRQ); EDMA_EnableChannelInterrupts(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kEDMA_MajorInterruptEnable); Before starting the software ADC with a software trigger, add EDMA_TriggerChannelStart() to trigger an interrupt on DMA channel 0. When the DMA interrupt flag is cleared, DMA-triggered interrupts are disabled, so this processing is added before the ADC's software trigger. // 242行目 while(1) { GETCHAR(); EDMA_TriggerChannelStart(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0); EXAMPLE_DMA_BASEADDR->CH[0].TCD_DLAST_SGA = -0x14; LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */ while (!g_Transfer_Done) { /* DMA転送終了割り込み待ち */ } g_Transfer_Done = false;   5. DMA transfer completion interrupt handling void APP_DMA_IRQ_HANDLER(void) { if ((EDMA_GetChannelStatusFlags(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0) & kEDMA_InterruptFlag) != 0U) { EDMA_ClearChannelStatusFlags(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kEDMA_InterruptFlag); g_Transfer_Done = true; } } summary: This article explained the basic functions and points to note about the MCX A153 ADC, as well as the initialization and conversion process using the VS Code SDK's ADC sample project . Following the latter part of this article, you should be able to see configuration examples and code flows that will be useful in actual development, from initialization and conversion using the ADC sample to automatic transfer of conversion results using DMA. (It's easier to isolate problems if you first run the ADC sample and confirm its operation before adding DMA.) =========================​ 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 everything from the basics of the ADC (analog-to-digital converter) in the MCX A153 , to initialization using the MCUXpresso SDK, and even automatic transfer of conversion results using DMA. If you are using ADC or DMA for the first time, it is recommended to first review the overall picture in Chapters 1 and 2, and then proceed to the sample code in Chapter 4 and the DMA settings in Chapter 5 for easier understanding. ADC: A function that converts analog signals, such as those from sensors, into digital values that can be handled by a microcontroller. DMA: A function that transfers data between peripherals and memory without going through the CPU. SDK: A development kit containing drivers and sample code necessary for software development. (Reading time: 30 minutes) General Purpose Microcontrollers Introduction MCUXpresso IDE MCUXpresso SDK Japanese Blog
View full article
[MCX A153] ADCモジュールの基本と使い方 (日本語ブログ)    この記事はMCX A153に搭載されたADC(Analog-to-Digital Converter)モジュールの基本的な使い方を説明します。ADCを利用したアプリケーション例から始め、主な機能、ブロック構成、使用時の注意点を整理したうえで、SDKサンプルコードを使ったデバイス初期化と、DMAによるADC変換結果の転送方法を紹介します。 この記事を読むことで、MCX A153のADCをアプリケーションで使用する際に必要となる基本事項を理解し、ADC変換を行うための初期設定から、DMAを活用した効率的なデータ転送までを実装できるようになることを目指します。   目次 1. アプリケーション上のよくある使用例        1.1 主な用途        1.2 使用例 2. MCX A153 ADCモジュールの主な機能とブロック図               2.1 概要               2.2 主な機能               2.3 ブロック図 3. 注意点、制限事項 4. ADCサンプルコード(デバイスの初期化)             4.1 サンプルコードの概要             4.2 SDKサンプルプロジェクトを開くまで             4.3 マクロ定義             4.4 デバイスの初期化 5. MCX A153 DMAを用いたAD変換値の転送           5.1 ADCに関するコード           5.2 DMAに関するコード まとめ 1. アプリケーション上のよくある使用例 ADCは、センサやポテンショメータなどから入力されたアナログ信号(連続的に変化する電圧)を、マイコンが計算に使えるデジタル値(数値)へ変換します。 1.1 主な用途 ポテンショメータから入力されたアナログの電圧値をデジタル値に変換 ポテンショメータをラジコンなどのサーボモータの軸に取り付けて、出力の変化からモータが回転した角度を検出する。 各種センサからのアナログ信号をデジタル値に変換 加速度センサからのアナログ信号を変換して物体の傾きを検出する。スマホの縦横の向きの検知などに応用できる。 温度センサからのアナログ信号を変換して周囲温度を測定する。   1.2 使用例 (概要を説明している例なので詳細は割愛しています) ポテンショメータの使用例:         2. 主な機能とブロック図   2.1 概要   MCX A153には、16ビットのADコンバータ(ADC)が搭載されています。ADコンバータは、アナログ電圧をデジタル値に変換する回路です。   2.2 主な機能 逐次比較型ADコンバータを1ユニット搭載 16ビットまたは12ビットの分解能で、シングルエンド入力に対応(分解能が高いほど、入力電圧を細かく表現できます) 搭載チャネル数 (パッケージにより異なる): 64ピンLQFP:24ch、48ピンLQFP:16ch、48ピンHVQFN:18ch、32ピンHVQFN:9ch サンプリング速度 (1秒間に何回変換できるか) 16ビットモード:最大3.2Msps、12ビットモード:最大4Msps サンプル時間が設定可能 マイコンの低電力モードで動作可能 4つのトリガーソースに対応 (ソフトウェアまたはハードウェアトリガーに対応) 7つのコマンドバッファにより連続したチャネルのスキャンが可能 コンペア機能をサポート (より小さい、より大きい、範囲内、範囲外、一致で保存、などを自動比較) ウォーターマークとオーバーフロー検出機能を持つ8つ変換結果データFIFOを搭載 割り込み、DMA、ポーリングに対応 キャリブレーション機能 専用入力チャネルを持つ温度センサを内蔵   2.3 ブロック図 MCX A153リファレンスマニュアル(MCXAP64M96FS3RM) Figure 165. ADC block diagramから抜粋   SDKサンプルコードの使用例 (ポテンショメータを接続)     3. MCX A153 ADCモジュール <注意点、制限事項> ここでは、MCX A153のADCを使う前に確認しておきたい注意点と制限事項を説明します。 16bitモードの速度低下 MCX A153のADCは、16ビット(ENOB16:実効分解能16ビット)と12ビット(ENOB12:実効分解能12ビット)の2つのモードに対応しています。ただし、16ビットモードは12ビットモードよりも、サンプリング速度が低下します。 (MCX A153 DataSheet Table.34から抜粋) キャリブレーションの実行タイミング キャリブレーションへのリクエスト&実行は、リセットまたは電源投入時に行わなければなりません。そして、キャリブレーション実行する前に、クロックソースと周波数をコンフィグする必要があります。 変換結果の平均化 ADCモジュールは、変換結果を保存する前に、同じチャネルの複数の結果を平均化できます。ハードウェア平均機能は、CMDHa[AVGS]ビットフィールドを0以外に設定すると有効になります。どの変換モードでも使用でき、ソフトウェアで平均値を計算する負担を減らせます。 4. AD変換のサンプルコード 4.1 サンプルコードの概要 mainシーケンスが実行されると、デバイスの初期化が実行されます。 デバイスの初期化は、クロックの設定に始まり、外部端子の構成と端子に接続するペリフェ ラルの選択をします。その後、ペリフェラル(ADC、UART)の初期化と、割り込みを有効に します。 初期化処理後、ループ処理内でADC変換開始のソフトウェアトリガをかけて、コンソールに AD変換の値と変換回数を表示します。 ハードウェアとしては、MCX A153の開発ボード「FRDM-MCXA153」を使用します。   4.2 VS codeでADCのサンプルプロジェクトを開くまでの手順 4.2.1 VS Codeと拡張機能の準備 VS Codeをインストールします。 拡張機能ビュー(Ctrl+Shift+X)で 「MCUXpresso for VS Code」 を検索してインストールします。 左のアクティビティバーにMCUXpressoアイコンが出ます。それをクリックして QUICKSTART PANEL を開きます。   4.2.2 依存ツールのインストール QUICKSTART PANELで 「Open MCUXpresso Installer」 を実行します。 次のツールを選んでインストールします。 Arm GNU Toolchain CMake / Ninja Python / West Git LinkServer(MCU-Link用デバッグプローブ) SDK 関連ツール 完了後、VS Codeを再起動します。   4.2.3 SDKリポジトリの取り込み QUICKSTART PANELで 「Import Repository」 をクリックします。 取り込み元として、リモートを選びます   保存先フォルダを指定します。パスは短く、日本語やスペースを含まないものにします  "I agree"をチェックして、Importボタンを押すことでレポジトリをインポートできます。   4.2.4 サンプルのインポート QUICKSTART PANELで 「Import Example from Repository」 をクリックします。 次のように設定します。   Importボタンを押すことで、プロジェクトをimportできます。 項目 設定値 Repository 手順3で取り込んだSDK(frdm_mcxa153) Toolchain Arm GNU Toolchain Board frdmmcxa153(FRDM-MCXA153) Template driver_examples → lpadc → interrupt(lpadc_interrupt) Location プロジェクト保存先 Name 任意(既定はlpadc_interrupt) 4.3 マクロ定義 ADCの機能に関するマクロ定義のコードです(lpadc\interrupt\app.hから抜粋)。 実際の回路設計と使用目的に合わせて、入力チャンネル、分解能設定、参考電圧ソースを修正してください。 Definitions //(lpadc\interrupt\app.hから抜粋) /******************************************************************************/ #define DEMO_LPADC_BASE ADC0 //ADCのinstance、ベースアドレス、MCX A153は1個 ADCしかない #define DEMO_LPADC_IRQn ADC0_IRQn #define DEMO_LPADC_IRQ_HANDLER_FUNC ADC0_IRQHandler #define DEMO_LPADC_USER_CHANNEL 0U //チャンネル番号 #define DEMO_LPADC_USER_CMDID 1U //コマンドID #define DEMO_LPADC_VREF_SOURCE kLPADC_ReferenceVoltageAlt3 //参考電圧ソース #define DEMO_LPADC_DO_OFFSET_CALIBRATION true //オフセットキャリブレーションの利用可否 #define DEMO_LPADC_USE_HIGH_RESOLUTION true //高分解能の利用可否 ADCに関する変数 Variables //(lpadc\interrupt\lpadc_interrupt.cから抜粋) volatile bool g_LpadcConversionCompletedFlag = false; volatile uint32_t g_LpadcInterruptCounter = 0U; lpadc_conv_result_t g_LpadcResultConfigStruct; #if (defined(DEMO_LPADC_USE_HIGH_RESOLUTION) && DEMO_LPADC_USE_HIGH_RESOLUTION) //高分解能 const uint32_t g_LpadcFullRange = 65536U; const uint32_t g_LpadcResultShift = 0U; #else //低分解能 const uint32_t g_LpadcFullRange = 4096U; const uint32_t g_LpadcResultShift = 3U; #endif /* DEMO_LPADC_USE_HIGH_RESOLUTION */ ADCに関する設定の構造体のデフォルト化(詳細はfsl_lpadc.cにある)、変換結果の平均化設定 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) LPADC_GetDefaultConfig(&mLpadcConfigStruct); mLpadcConfigStruct.enableAnalogPreliminary = true; //ADCアナログ回路は事前に有効化され、起動遅延なしで変換を実行する準備 #if defined(DEMO_LPADC_VREF_SOURCE) mLpadcConfigStruct.referenceVoltageSource = DEMO_LPADC_VREF_SOURCE; //参考電圧ソース #endif /* DEMO_LPADC_VREF_SOURCE */ #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS) && FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS mLpadcConfigStruct.conversionAverageMode = kLPADC_ConversionAverage; //変換結果平均化設定、平均しない/2回の平均/4回の平均/8回の平均/16回の平均....1024回の平均化選択可能 #endif     4.4 デバイスの初期化     クロック分周比の初期化 CLOCK_SetClockDiv関数では、ADCペリフェラルで使用するクロック分周設定を処理します。 //(lpadc\interrupt\hardware_init.cから抜粋) /* Attach peripheral clock */ CLOCK_SetClockDiv(kCLOCK_DivADC0, 1u); div_name: 列挙体で定義された分周器を選択 value: 分周比 ※以下のコードは、fsl_clock.cで始まるドライバ部となり、ユーザによる変更はオススメしません。 //(fsl_clock.cから抜粋) void CLOCK_SetClockDiv(clock_div_name_t div_name, uint32_t value) { volatile uint32_t *pDivCtrl = (volatile uint32_t *)(MRCC0_BASE + (uint32_t)div_name); assert(div_name <= kCLOCK_DivMax); /* Unlock clock configuration */ SYSCON->CLKUNLOCK &= ~SYSCON_CLKUNLOCK_UNLOCK_MASK; /* halt and reset clock dividers */ *pDivCtrl = 0x3UL << 29U; if (value == 0U) /*!< halt */ { *pDivCtrl |= (1UL << 30U); } else { *pDivCtrl = (value - 1U); } /* Freeze clock configuration */ SYSCON->CLKUNLOCK |= SYSCON_CLKUNLOCK_UNLOCK_MASK; }   クロック選択 CLOCK_AttachClkでは、ADCペリフェラルで用いるクロックソースを4つから選択します。 void CLOCK_AttachClk(clock_attach_id_t connection)関数の引数に 構造体clock_attach_id_tで定義された値を入れることで、ドライバにより設定が行われます。 //(fsl_clock.hから抜粋) kFRO12M_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 0U), /* Attach FRO12M to ADC0. */ kFRO_HF_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 1U), /* Attach FRO_HF to ADC0. */ kCLK_IN_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 3U), /* Attach CLK_IN to ADC0. */ kCLK_1M_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 5U), /* Attach CLK_1M to ADC0. */ kNONE_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 7U), /* Attach NONE to ADC0. */ //(lpadc\interrupt\hardware_init.cから抜粋) CLOCK_AttachClk(kFRO12M_to_ADC0); 以下の関数は、fsl_clock.cで始まるSDKで提供されているドライバ部の関数になり、ユーザーにより変更することはオススメしません。 //(fsl_clock.hから抜粋) void CLOCK_AttachClk(clock_attach_id_t connection) { const uint32_t reg_offset = CLK_ATTACH_REG_OFFSET(connection); const uint32_t clk_sel = CLK_ATTACH_CLK_SEL(connection); if (kNONE_to_NONE != connection) { CLOCK_SetClockSelect((clock_select_name_t)reg_offset, clk_sel); } } //(fsl_clock.hから抜粋) void CLOCK_SetClockSelect(clock_select_name_t sel_name, uint32_t value) { volatile uint32_t *pClkCtrl = (volatile uint32_t *)(MRCC0_BASE + (uint32_t)sel_name); assert(sel_name <= kCLOCK_SelMax); if (sel_name == kCLOCK_SelSCGSCS) { SCG0->RCCR = (SCG0->RCCR & ~(SCG_RCCR_SCS_MASK)) | SCG_RCCR_SCS(value); while ((SCG0->CSR & SCG_CSR_SCS_MASK) != SCG_CSR_SCS(value)) { } } else { /* Unlock clock configuration */ SYSCON->CLKUNLOCK &= ~SYSCON_CLKUNLOCK_UNLOCK_MASK; *pClkCtrl = value; /* Freeze clock configuration */ SYSCON->CLKUNLOCK |= SYSCON_CLKUNLOCK_UNLOCK_MASK; } } ボードの初期化関数について クロックの初期化を行います。   ピンの初期化 InitPins()を読み出し、pin_mux.cファイルの処理を行います。 pin_mux.cファイルは、NXPのMCUXPresso IDEに統合されているPin Configツールを用いて上書き可能です。 //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitPins(); BOARD_InitPins()関数では、4つの処理を行います。 ペリフェラルのクロックの有効化 ペリフェラルのリセット解除 外部ピンとピンとペリフェラルの接続(MUXの設定)構成 -> 構造体へのパラメータ設定 3をレジスタへ書き込み   ブートクロックの初期化 MCX A153では、Mid Drive ModeとStandard Drive Modeをサポートしています。 それぞれ、VDD_COREの電圧レベルが、1.0 Vと1.1 Vで、rfo_hfクロックが48MHzもしくは96MHzで動作します。 モードを切り換えるには、外部からの電源供給に加えて、LDO等の電圧関連のレジスタ設定が必要です。 //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitBootClocks(); 動作周波数に応じたレジスタ設定用の関数を用いて、クロックを設定します。 //(fsl_clock.cから抜粋) void BOARD_InitBootClocks(void) { BOARD_BootClockFRO96M(); }     デバッグポートの初期化 //(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitDebugConsole();   //(board.cから抜粋) void BOARD_InitDebugConsole(void) { /* attach 12 MHz clock to LPUART0 (debug console) */ CLOCK_SetClockDiv(kCLOCK_DivLPUART0, 1u); CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH); RESET_PeripheralReset(BOARD_DEBUG_UART_RST); DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, BOARD_DEBUG_UART_CLK_FREQ); }   アプリケーションの初期化 ADCの初期化は、LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct);関数内で処理されます。 LPADC_Init()の関数は、fsl_lpadc.cのドライバ部分の関数になります。 DEMO_LPADC_BASE: 0x400A_F000 -> ADCの先頭アドレス 構造体テーブルを定義して、ADCのコンフィギュレーションを行います。 typedef struct {} lpadc_config_t 名称 属性 説明 lpadc_config_t 型 LPADCコンフィグパラメータ情報 enableInDozeMode bool ADC変換中のモードによる動作設定 conversionAverageMode lpadc_conversion_average_mode_t Auto Calibrationに関する設定 enableAnalogPreliminary bool ADC事前起動設定 powerUpDelay uint32_t ADC回路の安定時間 referenceVoltageSource lpadc_reference_voltage_source_t 基準電圧のソース powerLevelMode lpadc_power_level_mode_t 電源構成の選択 triggerPriorityPolicy lpadc_trigger_priority_policy_t 高プロイオリティトリガの処理方法 enableConvPause bool AD変換実行間隔の設定 convPauseDelay uint32_t コマンドシーケンス中のポーズ時間 FIFOWatermark uint32_t FIFO内データ数の閾値設定 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct); //(fsl_lpadc.cから抜粋) void LPADC_Init(ADC_Type *base, const lpadc_config_t *config) { /* 省略 */ base->CTRL |= ADC_CTRL_CAL_AVGS(config->conversionAverageMode); /* 省略 */ }   ADCのキャリブレーションについて   ADCでは、変換結果に含まれるオフセット誤差などを補正し、AD変換の精度を向上させるために、ADCの使用開始前にキャリブレーションを実行します。 キャリブレーション処理は、主に次の2段階に分けて考えることができます。 キャリブレーションのモードや条件を設定する キャリブレーションを実行し、補正値をADCへ反映する   デフォルトサンプルでは、LPADC_Init()の実行後、AD変換を開始する前にADCキャリブレーションを実行します。まず、対応するデバイスではLPADC_SetOffsetCalibrationMode()でオフセットキャリブレーションのモードを設定します。その後、DEMO_LPADC_DO_OFFSET_CALIBRATIONが有効な場合はLPADC_DoOffsetCalibration()を実行し、無効な場合はLPADC_SetOffsetValue()であらかじめ設定したオフセット値を使用します。 さらに、対応する機能マクロが有効な場合は、1 µs以上の待ち時間を置いてLPADC_DoAutoCalibration()を実行します。これにより、ゲイン誤差や直線性誤差のキャリブレーションを行います。各処理は、デバイスがサポートする機能マクロが有効な場合にのみコンパイルされます。   下記はLPADCのキャリブレーションモードの設定です。 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) /* Request LPADC calibration. */ #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE) && FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE LPADC_SetOffsetCalibrationMode(DEMO_LPADC_BASE, DEMO_LPADC_OFFSET_CALIBRATION_MODE); #endif /* FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE */     オフセットキャリブレーションの実行 //(lpadc\interrupt\lpadc_interrupt.cから抜粋) #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFS) && \ FSL_FEATURE_LPADC_HAS_CTRL_CALOFS #if defined(DEMO_LPADC_DO_OFFSET_CALIBRATION) && \ DEMO_LPADC_DO_OFFSET_CALIBRATION L PADC_DoOffsetCalibration(DEMO_LPADC_BASE); //キャリブレーションを実行しない場合 #else /* Update OFSTRIM register manually. */   5. MCX A153 DMA ADC変換にDMA転送を用いる理由 ADCで取得したデータをソフトウェアだけで処理する場合、ADC変換の完了をCPUが監視し、変換結果を読み出してメモリへ書き込む処理が必要になります。単発のAD変換であれば大きな問題にはなりませんが、一定周期で連続的にサンプリングする場合や、複数の入力チャネルを扱う場合には、この処理が繰り返し発生します。その結果、CPUの処理負荷が増加し、他のアプリケーション処理に割り当てられる時間が少なくなる可能性があります。 この課題を解決する方法の一つが、DMA(Direct Memory Access)を用いたADC変換結果の転送です。DMAを使用すると、ADC変換の完了をきっかけに、ADCの変換結果をメモリへ自動的に転送できます。つまり、AD変換結果の取得からメモリへの格納までをハードウェアで処理できるため、CPUによるデータ転送処理を減らし、ソフトウェアの処理負荷を低減できます。 このような理由から、連続的なAD変換や高速なデータ取得が必要なアプリケーションでは、ADCとDMAを組み合わせた構成がよく利用されます。本記事では、まずADCの基本的な初期化方法を説明した後、MCX A153でDMAを使用してADC変換結果をメモリへ転送する方法を紹介します。 DMAを用いたAD変換値の転送 概要 AD変換後のデータはADCペリフェラル内のバッファに格納されます。都度、ソフトウェアで読み出さずに、ADCのトリガによりDMA を起動し、データを転送することがあります。1例として、AD変換を連続で5回おこなった後、DMAにてRAM上のバッファに保存し、コンソールに平均値と最小、最大を表示するプログラムに変更します。 DMAを用いたAD変換値の転送手順 ADCのサンプルコードを変更し、DMAの処理を追加していきます。 DMA起動は、ADCからのDMA Request信号を用います。 DMAを用いて、ADC FIFOの値(5回変換分)をRAMへコピーし、CPUへ割り込みを通知します。 CPUは、DMA転送完了後にmainループ内で平均値をとり、min, max, aveをコンソールに表示させます。     注意事項 DMAのコードを追加するにあたり、DMAドライバのヘッダファイルとソースコードをプロジェクトに追加してください。 一番簡単と思われる方法は、MCUXpresso IDEからDMAのサンプルコード(frdmmcxa153_edma3_memory_to_memory_transfer)を作成し、コピーする方法です。 driversディレクトリから、以下のファイルをコピーすればOKです。 fsl_edma_core.h fsl_edma_soc.c fsl_edma_soc.h fsl_edma.c fsl_edma.h   5.1  ADCに関するコードの修正と追加   コードの修正手順 ADC変換完了時の割り込みをディスエーブルに修正 ADCのコンフィグレーションを追加 AD変換を連続5回実行する設定 DMAリクエストをイネーブル設定 FIFOのWatermarkを4に設定 DMAが転送した値の平均、最小、最大値取得処理とコンソール出力を追加     1. ADC変換完了時の割り込みを無効 LPADC_EnableInterrupts()関数とkLPADC_FIFOWatermarkInterruptEnableを用いて、Interrupt Enable Register (IE)を有効にしているため、この行をコメントアウトします。 // LPADC_EnableInterrupts(DEMO_LPADC_BASE, kLPADC_FIFOWatermarkInterruptEnable);   2. ADCのコンフィグレーションを追加 ADCを5回ループ設定(=5回のAD変換) mLpadcCommandConfigStruct.loopCount = 4 //loopCount +1回の変換 DMAリクエストをイネーブルに設定 //178行目 LPADC_EnableFIFOWatermarkDMA(DEMO_LPADC_BASE, 1); // 1でDMA Requestがイネーブル     3. FIFOのWaterMarkの段数を4に設定 // 33行目 /* ++ ADCのマクロ */ #define FIFO0WatermarkLEVEL (4) //108行目 mLpadcConfigStruct.FIFOWatermark = FIFO0WatermarkLEVEL;   4. DMAが転送した値の平均、最小、最大値取得処理とコンソール出力を追加 uint32_t adc_values[5] = {0}; PRINTF("Please press any key to get user channel's ADC value.\r\n"); while(1) { GETCHAR(); EXAMPLE_DMA_BASEADDR->CH[0].CH_CSR = DMA_CH_CSR_ERQ(1); EXAMPLE_DMA_BASEADDR->CH[0].TCD_DLAST_SGA = -0x14; LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */ while (!g_Transfer_Done) { /* DMA転送終了割り込み待ち */ } g_Transfer_Done = false; uint16_t min=adc_values[0]; uint16_t max=adc_values[0]; uint32_t sum=0; for(uint32_t i=0; i<5; i++) { if(max < (0x0000FFFF & adc_values[i])) max = adc_values[i]; if(min > (0x0000FFFF & adc_values[i])) min = adc_values[i]; sum += 0x0000FFFF & adc_values[i]; } PRINTF("ADC Min: %d, Max: %d, ave: %d\r\n", min, max, sum/5); for(size_t i=0; i<5; i++) { adc_values[i] = 0; } sum = 0; }   5.2 DMAに関するコードの追加   コードの追加方針 ヘッダファイルのインクルード DMA関連のマクロを追加 DMAのコンフィグレションと初期化 DMA転送のコンフィグレーション DMA転送完了割り込み処理   1. ヘッダのインクルード // 10行目 #include "fsl_debug_console.h" #include "pin_mux.h" #include "clock_config.h" #include "board.h" #include "fsl_lpadc.h" /* ++ */ #include "fsl_edma.h" // DMAドライバヘッダファイルの追加 #include "fsl_clock.h" #include "fsl_reset.h"   2. DMA関連のマクロを追加 // 32行目 #define EXAMPLE_DMA_BASEADDR DMA0 #define DEMO_DMA_CHANNEL_0 0U #define APP_DMA_IRQ DMA_CH0_IRQn #define APP_DMA_IRQ_HANDLER DMA_CH0_IRQHandler     3. DMAのコンフィグレーション // 197行目 edma_transfer_config_t transferConfig; edma_config_t userConfig; // 203行目 RESET_PeripheralReset(kDMA_RST_SHIFT_RSTn); /* Configure EDMA channel for one shot transfer */ EDMA_GetDefaultConfig(&userConfig); EDMA_Init(EXAMPLE_DMA_BASEADDR, &userConfig);     4. DMA転送のコンフィグレーション // 209行目 EDMA_PrepareTransfer(&transferConfig, (void *)0x400AF300, // eDMA transfer source address. sizeof(uint32_t), // eDMA transfer source address width(bytes) (void *)adc_values, // eDMA transfer destination address sizeof(&adc_values), // eDMA transfer destination address width(bytes) sizeof(adc_values), // eDMA transfer bytes per channel request sizeof(adc_values), // eDMA transfer bytes to be transferred kEDMA_PeripheralToMemory // eDMA transfer type ); EDMA_SetTransferConfig(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, &transferConfig, NULL); EDMA_SetChannelMux(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kDma0RequestMuxAdc0FifoRequest); EnableIRQ(APP_DMA_IRQ); EDMA_EnableChannelInterrupts(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kEDMA_MajorInterruptEnable); ソフトウェアADCをソフトウェアトリガで起動する前に、DMAのチャネル0に割込みのトリガが掛るようにEDMA_TriggerChannelStart()を追加します。 DMAの割込みフラグをクリアした際、DMAトリガによる割込みがディスエーブルになるため、ADCのソフトウェアトリガの前に処理をついかします。 // 242行目 while(1) { GETCHAR(); EDMA_TriggerChannelStart(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0); EXAMPLE_DMA_BASEADDR->CH[0].TCD_DLAST_SGA = -0x14; LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */ while (!g_Transfer_Done) { /* DMA転送終了割り込み待ち */ } g_Transfer_Done = false;   5. DMA転送完了割り込み処理 void APP_DMA_IRQ_HANDLER(void) { if ((EDMA_GetChannelStatusFlags(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0) & kEDMA_InterruptFlag) != 0U) { EDMA_ClearChannelStatusFlags(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kEDMA_InterruptFlag); g_Transfer_Done = true; } } まとめ: 本記事では、MCX A153 ADCの基本機能、注意点、vscode sdkのADCサンプルプロジェクトを使った初期化と変換処理を説明しました。そして、後半の記事従い、ADCサンプルを使った初期化・変換処理から、DMAによる変換結果の自動転送まで、実際の開発に役立つ設定例とコードの流れを確認できると思います。(まずはADC単体のサンプルを動かし、動作を確認してからDMAを追加すると、問題を切り分けやすくなります。) =========================​ 本投稿の「Comment」欄にコメントをいただいても、現在返信に対応しておりません。​ お手数をおかけしますが、お問い合わせの際には「NXPへの技術質問 - 問い合わせ方法 (日本語ブログ)」をご参照ください。​ (既に弊社NXP代理店、もしくはNXPとお付き合いのある方は、直接担当者へご質問いただいてもかまいません。)​ この記事では、MCX A153に搭載されているADC(アナログ信号をデジタル値に変換する回路)の基本から、MCUXpresso SDKを使った初期化、さらにDMAを使った変換結果の自動転送までを説明します。ADCやDMAを初めて使う場合は、まず1章と2章で全体像を確認し、その後に4章のサンプルコード、5章のDMA設定へ進むと理解しやすくなります。 ADC:センサなどのアナログ信号を、マイコンで扱えるデジタル値に変換する機能 DMA:CPUを介さずに、ペリフェラルとメモリの間でデータを転送する機能 SDK:ソフトウェア開発に必要なドライバやサンプルコードをまとめた開発キット (読了:30分) General Purpose Microcontrollers introduction MCUXpresso IDE MCUXpresso SDK 日本語ブログ
View full article
VLM Edge Studio VLM Edge Studio In this post, I want to share a quick walkthrough of VLM Edge Studio, an NXP launcher application designed to interact with supported Vision-Language Models running locally on FRDM i.MX platforms with Ara240 DNPU acceleration. VLM Edge Studio provides a Qt/QML-based GUI for model selection, prompt input, and visual interaction with locally running VLMs at the edge. It communicates with the Ara240 Runtime SDK through the eIQ AAF Connector using a REST-based interface and streaming token responses.   Key Features Local Vision-Language Model inference on supported i.MX platforms Ara240 DNPU acceleration GUI-based model selection and prompt input Streaming token output Integration with eIQ AAF Connector and Ara240 Runtime SDK Support for camera-based visual input using a USB-C HD camera   Supported Model Qwen2.5-VL-7B-Instruct-Ara240 This model is provided as an Ara240-compatible model.dvm file and is intended for local execution on the target platform.   Running VLM Edge Studio ONLY for Release L6.18.37_2.1.0 apply the following command as a workaround (Check for more details at VLM Edge Studio - video analysis fails with PyAV 19.0.0 - NXP Community sed -i 's/av.open(filename, metadata_errors="ignore")/av.open(filename)/g' /usr/share/eiq/aaf-connector/venv/lib/python3.14/site-packages/torchvision/io/video.py Start the application with: run_vlm_edge_studio Before launching, make sure the Ara240 runtime service is running: systemctl status rt-sdk-ara2.service --no-pager -l Once the GUI appears, click LOAD to load the model. After the model is ready, enter a prompt and submit it to interact with the VLM locally on the i.MX platform.   Walkthrough Video In the attached video, I show how to launch VLM Edge Studio from GoPoint, load the supported Vision-Language Model, submit a prompt, and interact with the model running locally with Ara240 DNPU acceleration. (function() { var wrapper = document.getElementById('lia-vid-6405413539112w960h540r804'); 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'); }); }); }); } }})(); (view in My Videos) Summary VLM Edge Studio is a useful tool for evaluating local Vision-Language Model inference on NXP i.MX platforms using Ara240 DNPU acceleration. It provides a simple workflow for loading the model, entering prompts, and interacting with visual-language AI directly at the edge.   Link VLM Edge Studio repository Errata: On Release Linux 6.18.37_2.1.0 there is an issue when launching VLM Edge Studio due to an external dependency change. To fix it check VLM Edge Studio - video analysis fails with PyAV 19.0.0 - NXP Community   ARA2-M2-16G-GT ARA240 Hands-On Training
View full article
Getting Started with S32 Design Studio AI Support and the FRDM-A-S32K312 Board   This guide explains how to set up S32 Design Studio AI Support with Claude Desktop, and then verify the setup by importing, building and flashing the Blinking LED example from Application Code Hub on the FRDM-A-S32K312 board.   Prerequisites NXP account – free and required for all NXP downloads. You can create one when prompted in the next step. Python 3.11 to 3.14 – download the Windows installer from Python.org. During installation, select Add python.exe to PATH. On the last page, click Disable path length limit if it is shown. To verify the installation, open a new Command Prompt and run python --version or py --version . NXP S32 software tools FRDM Automotive S32K3 + S32M27 Board Installation Package - download and run the installer as administrator from Automotive Software Package Manager | NXP Semiconductors Known Windows path-length limitation: If the installation fails because a file path is too long, rerun the installer and select a shorter installation directory, such as C:\NXP\K3 S32 Design Studio v.3.6.11 - Update the version using the S32 Design Studio Platform package available in the S32DS Extensions and Updates panel: S32 Design Studio -> Help -> S32DS Extensions and Updates -> S32 Design Studio Platform package -> Update S32 Design Studio MCP Integration plugin v.1.0.3 - Install it from S32DS Extensions and Updates panel  S32 Design Studio AI Support - download the .pyz installer from the latest release on Releases · nxp-agentic-ai/s32-ds-ai-support, under Assets. Note the folder where it is saved. An MCP-compatible AI agent - this guide uses Claude Desktop as example, but any MCP-compatible AI agent can be used Claude Desktop - download it from claude.com/download, install it and sign in with your Claude account. FRDM-A-S32K312 board and a USB cable Installation Close Claude Desktop completely, including from the system tray (right-click the Claude icon → Close). Otherwise, the MCP registration may fail. Open a Command Prompt in the folder containing the s32ds-agentic-ai-installer-{version}.pyz file (open the folder in File Explorer, type cmd in the address bar and press Enter) Run the command below, replacing {version} with the version in the file name. When prompted, press Enter to accept the default install location (C:/NXP/s32ds-agentic-ai) or type another path, then press Enter again to install all components. Then, select for which agents you want the MCP Server to be configured and then the skills to be copied. Choose 1 for Claude Desktop.   For all installer options, see the README on GitHub – S32 Design Studio AI Support python s32ds-agentic-ai-installer-{version}.pyz The MCP servers and skills should be now installed and registered in the specified agent. To verify in Claude Desktop, open Settings → Developer and check that the NXP S32 Design Studio MCP Server is listed without errors. To check that the skills were installed, type / in Claude Code. The installed skills should appear in the list.  If the MCP server is not listed, check the troubleshooting section. Start prompting   Connect the board to the laptop with the USB cable, open your AI agent and send the prompt below, replacing the paths with your own. The agent imports the Blinking LED example from Application Code Hub into S32 Design Studio, builds it and flashes it to the board. “S32 Design Studio is installed in C:\NXP\S32DS.3.6.8 and my workspace is C:\S32DS_Workspace. Import the Blinking LED example for the FRDM-A-S32K312 board from Application Code Hub, generate the configuration code, build the project and flash it to the board connected over USB.” Troubleshooting Known Claude Desktop limitation on Windows (MSIX) Due to a known Claude Desktop MSIX configuration issue on Windows (community issue #26073), Claude Desktop may not detect MCP servers that were automatically registered during installation. If this occurs, manually register the MCP Gateway using the steps below: Open Claude Desktop. Go to Settings → Developer → Edit Config In the existing mcpServers object, add the following s32ds-agentic-ai entry: { "mcpServers": { "s32ds-agentic-ai": { "command": "C:/NXP/s32ds-agentic-ai/run-mcp.bat", "args": [ "nxp.mcp.gateway", "configs/gateway.stdio.yaml" ], "disabled": false } } } Important. If other MCP servers are already configured, add only the s32ds-agentic-ai entry inside the existing mcpServers object. Do not replace or overwrite the existing configuration. The example above assumes the default installation structure. If a different installation directory was selected, adjust the command path accordingly. 4. Save the configuration. 5. Restart Claude Desktop. 6. Go to Settings → Developer and verify that the MCP server is listed without errors. Getting Started
View full article
S32K312 BCTU – FIFO Watermark Callback Working, but Last Conversion Callback Not Triggered Hello NXP Community, I am working with the S32K312 MCU using S32 Design Studio and S32K3 RTD 7.0.1. I have configured the BCTU to trigger a list of ADC conversions using a software trigger. I am testing both the BCTU FIFO1 watermark callback and the BCTU last-conversion callback. Current Configuration: MCU: S32K312 Driver: S32K3 RTD 7.0.1 ADC instance: ADC0 BCTU conversion list: 4 ADC channels (0, 2, 4, 3) Trigger source: BCTU software trigger Interrupt: BCTU_IRQn enabled Notifications: FIFO1 watermark and last-conversion callbacks Observed Behavior: When I enable the FIFO1 watermark notification, the watermark callback is triggered successfully, and I can read the ADC conversion results from FIFO1. However, when I enable the BCTU last-conversion notification, the corresponding callback is not triggered. During debugging, I observed: Execution enters Bctu_0_Isr(). The driver checks the enabled BCTU interrupt sources. The condition if((*Reg & Mask) != 0U) evaluates to false for the last-conversion notification. The LIST0_Last bit in the BCTU MSR register remains 0 when inspected during interrupt handling. As a result, the last-conversion callback is not executed. Questions: Why does the FIFO1 watermark callback work correctly while the BCTU last-conversion callback is not triggered? What exact hardware condition causes MSR.LIST0_Last to become 1? Does the last-conversion interrupt require additional configuration in the BCTU conversion list, trigger configuration, or interrupt enable settings? Can both the FIFO1 watermark callback and the BCTU last-conversion callback be used for the same conversion list? Is the LIST0_Last status flag automatically cleared by hardware or by the RTD interrupt handler? If so, at what point? Which BCTU registers should I monitor to verify that the last-conversion event is generated correctly? Could you please help me understand why the FIFO watermark interrupt is functioning correctly while the BCTU last-conversion interrupt is not being generated or handled as expected? I can provide screenshots of my BCTU configuration, register values, and ISR debugging observations if required. Thank you for your support. #s32k312 #adcbctu #bctuswconv #listlastconv Re: S32K312 BCTU – FIFO Watermark Callback Working, but Last Conversion Callback Not Triggered Hi, if remember well, Last Conversion Notification can be generated only when the ADC conversion result destination is set to ADCnDR. The Reference Manual also states it in the LIST_IEN description.   BR, Petr  
View full article
mlockall(MCL_FUTURE)を呼び出すプロセスでiMX8MP GPUを使用すると、カーネルBUG() あるお客様がiMX8MPのGPU使用(EGLによる描画)に関する問題を報告しました。以前mlockall(MCL_FUTURE)と呼ばれていたGPU初期化プロセスが、CMA領域がユーザースペースにマッピングされると、カーネルは以下のBUG()を報告します: Kernel BUG at remap_pfn_range_internal+0x23c/0x2c8 Internal error: Oops - BUG: 00000000f2000800 [#1] PREEMPT SMP CPU: 0 PID: 3197 Comm: galcore_window_ Tainted: G O 6.6.142-7.7.0-devel #1-Torizon Hardware name: Toradex Verdin iMX8M Plus WB on Verdin Development Board (DT) pc : remap_pfn_range_internal+0x23c/0x2c8 x27: 00000000a2100000 x20: 0068000000000fcb x19: 0000007f90000000 ^^^^^^^^^^^^^^^^^^^^^^ the PTE already present Call trace: remap_pfn_range_internal+0x23c/0x2c8 remap_pfn_range+0x24/0x58 dma_direct_mmap+0xf4/0x150 dma_mmap_attrs+0x18/0x3c _CMAFSLMapUser+0x9c/0x150 [galcore] gckOS_LockPages+0xe4/0x148 [galcore] gckKERNEL_MapVideoMemory+0x90/0x1dc [galcore] gckVIDMEM_NODE_LockCPU+0x1b4/0x250 [galcore] _LockVideoMemory.isra.0+0x1f4/0x28c [galcore] gckKERNEL_Dispatch+0x210/0x1730 [galcore] gckDEVICE_Dispatch+0xcc/0x220 [galcore] drv_ioctl+0x340/0x444 [galcore] __arm64_sys_ioctl+0xac/0xf0 Kernel panic - not syncing: Oops - BUG: Fatal exception mlockall(MCL_FUTURE)はリアルタイムアプリケーションで一般的に使われており、問題を報告した顧客はCODESYSを使ってHMIを駆動しています。 AIを活用した分析を実施した結果、問題が発生する理由として考えられる説明が明らかになりました。 galcoreドライバーのCMAアロケーターには.mmap()が含まれていません。フック。_CMAFSLMapUser() の実行中に、mmap() を呼び出して vma を取得し、それを使用して find_vma() を使用して CMA 領域を特定します。mmap() の呼び出し方法により、カーネルは要求を満たすために SHM 領域を遅延的に割り当てることになります。通常の場合、CMAが見つかって再マッピングされると、この割り当てはすぐに破棄されます。 しかし、MCL_FUTUREがアクティブなとカーネルはもはやSHM領域を怠惰に割り当てることができなくなり、mmap()が戻る前にエリア全体を埋め尽くします。この場合、このアドレスには有効なページがあり、後のremap_pfn_range()への呼び出しはメモリ管理のハウスキーピング情報を静かに破棄することになり、これはまさにBUG()が防いでいることです。 CODESYSを実行せずに問題を再現できるプログラムのソースコードを含むzipファイルを添付します。AIエージェントは、この問題を修正するために以下のパッチを提案しました。 diff -uNr a/hal/kernel/inc/gc_hal_options.h b/hal/kernel/inc/gc_hal_options.h --- a/hal/kernel/inc/gc_hal_options.h 2026-09-04 13:00:44.596621860 +0000 +++ b/hal/kernel/inc/gc_hal_options.h 2026-09-04 13:01:15.643862002 +0000 @@ -1471,9 +1471,17 @@ * Enable this macro can replace the /dev/zero by anon_inode: * [galcore] in /proc/ /maps. * Without the macro, run 'cat /proc/ /maps' will print "/dev/zero". + * + * It is also what gives the allocators an ->mmap handler, which is + * required so that the reservation made by vm_mmap() is created as a + * device mapping (VM_IO | VM_PFNMAP) rather than as ordinary anonymous + * memory. Without it, a process that has called mlockall(MCL_FUTURE) + * gets the range pre-faulted inside vm_mmap(), and the subsequent + * remap_pfn_range() then hits BUG_ON(!pte_none()) in remap_pte_range(). + * See tmp_mmap() in gc_hal_kernel_allocator.c. */ #ifndef gcdANON_FILE_FOR_ALLOCATOR -# define gcdANON_FILE_FOR_ALLOCATOR 0 +# define gcdANON_FILE_FOR_ALLOCATOR 1 #endif /* diff -uNr a/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c b/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c --- a/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c 2026-09-04 13:00:44.605314869 +0000 +++ b/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c 2026-09-04 13:01:15.644216883 +0000 @@ -400,7 +400,13 @@ gcmkHEADER_ARG("Allocator=%p Mdl=%p Cacheable=%d", Allocator, Mdl, Cacheable); #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) +#if gcdANON_FILE_FOR_ALLOCATOR + /* Same as the gfp, dma and reserved_mem allocators: go through the + * allocator's anon file so that its ->mmap handler runs. */ + userLogical = (gctPOINTER)vm_mmap(Allocator->anon_file, +# else userLogical = (gctPOINTER)vm_mmap(gcvNULL, +# endif 0L, Mdl->numPages * PAGE_SIZE, PROT_READ | PROT_WRITE, diff -uNr a/hal/os/linux/kernel/gc_hal_kernel_allocator.c b/hal/os/linux/kernel/gc_hal_kernel_allocator.c --- a/hal/os/linux/kernel/gc_hal_kernel_allocator.c 2026-09-04 13:00:44.603242857 +0000 +++ b/hal/os/linux/kernel/gc_hal_kernel_allocator.c 2026-09-04 13:01:15.644041018 +0000 @@ -104,6 +104,36 @@ static int tmp_mmap(struct file *fp, struct vm_area_struct *vma) { + /* + * Declare the reservation as a device mapping with raw PFNs, before + * mmap() returns it to the caller. remap_pfn_range() sets both flags + * anyway; setting them here only makes them effective from the moment + * the VMA is created, and that is what matters: + * + * - the kernel treats VM_IO | VM_PFNMAP as VM_SPECIAL, documented in + * include/linux/mm.h as "Special vmas that are non-mergable, + * non-mlock()able". mmap_region() therefore clears VM_LOCKED from + * this VMA and leaves mm->locked_vm alone, and __mm_populate() + * skips it outright ("if (vma->vm_flags & (VM_IO | VM_PFNMAP)) + * continue;" in mm/gup.c). + * + * - so a process that has called mlockall(MCL_FUTURE) no longer has + * this range pre-faulted inside vm_mmap(). Every other mapping in + * that process keeps being locked and pre-faulted as before; only + * device memory, which is neither pageable nor swappable and gains + * nothing from being pre-faulted, is left out. + * + * - and the allocator's own remap_pfn_range(), a few microseconds + * later, therefore finds an empty range instead of one the kernel + * has just populated, so it no longer trips + * BUG_ON(!pte_none(ptep_get(pte))) in remap_pte_range(). + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) + vm_flags_set(vma, VM_IO | VM_PFNMAP); +#else + vma->vm_flags |= VM_IO | VM_PFNMAP; +#endif + return 0; } 上流ドライバーはこの問題を回避する別のメカニズムを使用しています。他の galcore アロケータも同じパターン (vm_mmap を呼び出して vma を取得する) を使用しているため、同じ BUG() の影響を受ける可能性があります。 この件について調べて、galcoreドライバーを直してもらえますか?この問題は実際のユースケースが正常に動作することを妨げており、直接的にお客様に影響を及ぼしています。 ありがとうございました。 ラファエル Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() こんにちは@rbeims  テストを実行してからGPUチームに確認させてください。 よろしくお願いします、 志明 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() こんにちは、 @Zhiming_Liu さん、バグを再現できましたか?はいの場合、修正が貴社のBSPに実装される予定時期を教えていただけますか? よろしくお願いいたします。 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() こんにちは、 @alvaro_tx さん。 社内チームがこのパッチをテストしました。お客様が直面した問題を直接解決したものの、他のアプリケーションのテスト中に問題を引き起こしました。現在も調査中であり、最終的な結論には至っていません。 よろしくお願いします、 志明 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() こんにちは、 @Zhiming_Liu さん。分かりやすいレポートをありがとうございます。完全に理解していて、私たちもこれが起こり得ると思いました。すべて順調です。 引き続きこの件に取り組んでいただき、進捗状況があればお知らせください。 ありがとう、 アルバロ。 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() @Zhiming_Liu さん、調査の進捗状況はいかがですか? 進展がなければ、他のアプリケーションでテスト中にどのような問題が生じたのか教えていただけますか? お客様は開発を進める必要があり、公式な解決策がなければパッチの適用を検討していますが、デメリットを知りたいと考えています。 ありがとう、 アルバロ。 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() ありがとう@Zhiming_Liu 。 NXPのR&DのパッチはLinuxドライバではなくEGLライブラリに基づいているようです。 この変更はオープンソースのLinuxドライバではなく、クローズドソースのEGLライブラリに適用されるということでしょうか? パッチを開く予定がない場合は、パッチが適用される場所、特にLinuxカーネル(6.6、6.18?)についての情報を教えていただけると助かります。 研究開発チームは、回避策とは異なるアプローチであっても、このパッチが問題を解決することを確認したと理解すべきでしょうか? Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() こんにちは、 @alvaro_tx @rbeims お客様が言及した問題についてですが、該当パッチは現在マージ中です。しかし、NXP R&DのパッチはLinuxドライバではなくEGLライブラリに基づいているようです。 よろしくお願いします、 志明
View full article
[OSM-iMX937/952] Schematic review For our new project, the iMX937 and iMX952 will be using a shared board design Could you help to review iMX937 and iMX952 schematic? Please refer to the attached file. The following questions would like to be confirmed with NXP: (1) According to the EVK and checklist descriptions, C604 and C603 in the circuit exist for the NXP iMX95. Therefore, can they be directly removed in this project? (2) To reduce component count, the additional ADC VREF and VDD_DDR capacitors on page 4 of the circuit were directly removed. According to the documentation, these designs exist for the NXP iMX95, not the iMX937/952. Thanks. Re: [OSM-iMX937/952] Schematic review iMx937 and iMx952 are pretty new product since both of them is at preproduction phase. Please contact dedicated FAE for detailed datasheet and user manual Q1 : All platforms that have transmitters supporting 8.0 GT/s must implement the 176 nf to 265 nF CTX value. Platforms operating at 2.5 or 5.0 GT/s only may increase that range to 75 nf to 265 nF. For pull down capacitor, no comments since it may not be necessary I.mX937 === 1 x PCIe Gen 3.0 x1 Lane(2.5G mux) I.mX952 === 1x PCIe Gen 3.0 x1 lane (1G SGMII mux) i.mX95 === 2x PCIe Gen 3.0 x1 Q2: There are some capacitor on page5 for DDR already. Not sure it is duplicated on page4. LPDDR5 design guideline may be request from memory vendor for more detailed information due to PI consideration For VREFH_ADC0, 1 0.01 µf+0.1 µf could be a possible option but may not be deleted due to noise filter
View full article
MC705J1ACDWE 代金引換の確認が必要です ネタバレ (ハイライトして読む) MC705J1ACDWE製品は販売終了(EOL)となりました。この製品のウェハ拡散位置(COD)をご確認いただけますでしょうか。よろしくお願いいたします。 MC705J1ACDWE製品は販売終了(EOL)となりました。この製品のウェハ拡散位置(COD)をご確認いただけますでしょうか。よろしくお願いいたします。 回复: MC705J1ACDWE Need comfirm COD ご返信とご支援ありがとうございます。 さらに、別の情報源から入手した元のラベル情報には「Diffused In:TH」と記載されています。この情報を使って確認することは可能でしょうか? Re: MC705J1ACDWE Need comfirm COD ご不便をおかけし申し訳ありません。この終末期/廃止型ファミリの部品番号に関する情報は提供できません。 よろしくお願いいたします。 回复: MC705J1ACDWE Need comfirm COD 情報源の確認を手伝ってもらえますか? この問い合わせについて、製品販売代理店にお問い合わせください。これにより、対応するCODを見つけるのに役立ちます。 よろしくお願いいたします。
View full article
在调用 mlockall(MCL_FUTURE) 的进程中使用 iMX8MP GPU 会导致内核 BUG() 一位客户报告了一个与使用 iMX8MP GPU(使用 EGL 绘图)相关的问题。当初始化 GPU 的进程先前调用 mlockall(MCL_FUTURE) 时,一旦 CMA 区域被映射到用户空间,内核就会报告以下 BUG(): Kernel BUG at remap_pfn_range_internal+0x23c/0x2c8 Internal error: Oops - BUG: 00000000f2000800 [#1] PREEMPT SMP CPU: 0 PID: 3197 Comm: galcore_window_ Tainted: G O 6.6.142-7.7.0-devel #1-Torizon Hardware name: Toradex Verdin iMX8M Plus WB on Verdin Development Board (DT) pc : remap_pfn_range_internal+0x23c/0x2c8 x27: 00000000a2100000 x20: 0068000000000fcb x19: 0000007f90000000 ^^^^^^^^^^^^^^^^^^^^^^ the PTE already present Call trace: remap_pfn_range_internal+0x23c/0x2c8 remap_pfn_range+0x24/0x58 dma_direct_mmap+0xf4/0x150 dma_mmap_attrs+0x18/0x3c _CMAFSLMapUser+0x9c/0x150 [galcore] gckOS_LockPages+0xe4/0x148 [galcore] gckKERNEL_MapVideoMemory+0x90/0x1dc [galcore] gckVIDMEM_NODE_LockCPU+0x1b4/0x250 [galcore] _LockVideoMemory.isra.0+0x1f4/0x28c [galcore] gckKERNEL_Dispatch+0x210/0x1730 [galcore] gckDEVICE_Dispatch+0xcc/0x220 [galcore] drv_ioctl+0x340/0x444 [galcore] __arm64_sys_ioctl+0xac/0xf0 Kernel panic - not syncing: Oops - BUG: Fatal exception mlockall(MCL_FUTURE) 通常用于实时应用程序,而报告此问题的客户正在使用 CODESYS 来驱动其 HMI。 我们利用人工智能辅助分析了该问题,并找到了该问题触发原因的合理解释: galcore 驱动程序中的 CMA 分配器不包含 .mmap() 方法。钩。在 _CMAFSLMapUser() 执行期间,它调用 mmap() 获取 vma,然后使用该 vma 通过 find_vma() 定位 CMA 区域。mmap() 的调用方式导致内核延迟分配 SHM 区域以满足请求。正常情况下,当找到 CMA 区域并重新映射时,此分配会在片刻后被丢弃。 但是,当 MCL_FUTURE 处于活动状态时,内核不能再延迟分配 SHM 区域,因此它会在 mmap() 返回之前填充整个区域。在这种情况下,该地址上有有效的页面,而稍后对 remap_pfn_range() 的调用最终会默默地丢弃内存管理维护信息,这正是 BUG() 所阻止的。 我将附上一个 zip 文件,其中包含一个程序的源代码,该程序可以稳定地重现该问题,而无需运行 CODESYS。AI代理建议使用以下补丁来修复此问题: diff -uNr a/hal/kernel/inc/gc_hal_options.h b/hal/kernel/inc/gc_hal_options.h --- a/hal/kernel/inc/gc_hal_options.h 2026-09-04 13:00:44.596621860 +0000 +++ b/hal/kernel/inc/gc_hal_options.h 2026-09-04 13:01:15.643862002 +0000 @@ -1471,9 +1471,17 @@ * Enable this macro can replace the /dev/zero by anon_inode: * [galcore] in /proc/ /maps. * Without the macro, run 'cat /proc/ /maps' will print "/dev/zero". + * + * It is also what gives the allocators an ->mmap handler, which is + * required so that the reservation made by vm_mmap() is created as a + * device mapping (VM_IO | VM_PFNMAP) rather than as ordinary anonymous + * memory. Without it, a process that has called mlockall(MCL_FUTURE) + * gets the range pre-faulted inside vm_mmap(), and the subsequent + * remap_pfn_range() then hits BUG_ON(!pte_none()) in remap_pte_range(). + * See tmp_mmap() in gc_hal_kernel_allocator.c. */ #ifndef gcdANON_FILE_FOR_ALLOCATOR -# define gcdANON_FILE_FOR_ALLOCATOR 0 +# define gcdANON_FILE_FOR_ALLOCATOR 1 #endif /* diff -uNr a/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c b/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c --- a/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c 2026-09-04 13:00:44.605314869 +0000 +++ b/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c 2026-09-04 13:01:15.644216883 +0000 @@ -400,7 +400,13 @@ gcmkHEADER_ARG("Allocator=%p Mdl=%p Cacheable=%d", Allocator, Mdl, Cacheable); #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) +#if gcdANON_FILE_FOR_ALLOCATOR + /* Same as the gfp, dma and reserved_mem allocators: go through the + * allocator's anon file so that its ->mmap handler runs. */ + userLogical = (gctPOINTER)vm_mmap(Allocator->anon_file, +# else userLogical = (gctPOINTER)vm_mmap(gcvNULL, +# endif 0L, Mdl->numPages * PAGE_SIZE, PROT_READ | PROT_WRITE, diff -uNr a/hal/os/linux/kernel/gc_hal_kernel_allocator.c b/hal/os/linux/kernel/gc_hal_kernel_allocator.c --- a/hal/os/linux/kernel/gc_hal_kernel_allocator.c 2026-09-04 13:00:44.603242857 +0000 +++ b/hal/os/linux/kernel/gc_hal_kernel_allocator.c 2026-09-04 13:01:15.644041018 +0000 @@ -104,6 +104,36 @@ static int tmp_mmap(struct file *fp, struct vm_area_struct *vma) { + /* + * Declare the reservation as a device mapping with raw PFNs, before + * mmap() returns it to the caller. remap_pfn_range() sets both flags + * anyway; setting them here only makes them effective from the moment + * the VMA is created, and that is what matters: + * + * - the kernel treats VM_IO | VM_PFNMAP as VM_SPECIAL, documented in + * include/linux/mm.h as "Special vmas that are non-mergable, + * non-mlock()able". mmap_region() therefore clears VM_LOCKED from + * this VMA and leaves mm->locked_vm alone, and __mm_populate() + * skips it outright ("if (vma->vm_flags & (VM_IO | VM_PFNMAP)) + * continue;" in mm/gup.c). + * + * - so a process that has called mlockall(MCL_FUTURE) no longer has + * this range pre-faulted inside vm_mmap(). Every other mapping in + * that process keeps being locked and pre-faulted as before; only + * device memory, which is neither pageable nor swappable and gains + * nothing from being pre-faulted, is left out. + * + * - and the allocator's own remap_pfn_range(), a few microseconds + * later, therefore finds an empty range instead of one the kernel + * has just populated, so it no longer trips + * BUG_ON(!pte_none(ptep_get(pte))) in remap_pte_range(). + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) + vm_flags_set(vma, VM_IO | VM_PFNMAP); +#else + vma->vm_flags |= VM_IO | VM_PFNMAP; +#endif + return 0; } 上游驱动程序使用了一种不同的机制来绕过这个问题。其他 galcore 分配器使用相同的模式(调用 vm_mmap 获取 vma),因此很可能容易受到相同的 BUG() 的影响。 请您调查并修复 galcore 驱动程序?这个问题导致实际应用场景无法正常运行,直接影响到我们的客户。 谢谢! 拉斐尔 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() 嗨@rbeims 让我先运行一下测试,然后再和GPU团队确认。 此致, 志明 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() @Zhiming_Liu ,你好,请问你成功复现了这个bug吗?如果可以,请问预计何时能在BSP中实现该修复?谢谢。 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() 您好@Zhiming_Liu ,感谢您提供的清晰报告。完全理解,我们也预料到这种情况会发生。一切都好。 请继续推进这项工作,如有任何进展,请与我们联系。 谢谢你, 阿尔瓦罗。 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() 嗨@alvaro_tx 我们的内部团队测试了这个补丁。虽然它直接解决了客户遇到的问题,但在其他应用程序的测试过程中却造成了问题。我们仍在调查此事,尚未得出最终结论。 此致, 志明 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() @Zhiming_Liu ,调查有进展吗? 如果没有进展,能否与我们联系,告知您在其他应用程序测试过程中遇到了哪些问题? 客户需要推进开发工作,如果官方没有解决方案,他们正在考虑应用此补丁,但他们想知道其缺点。 谢谢你, 阿尔瓦罗。 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() 嗨@alvaro_tx @rbeims 关于客户提到的问题,相关的补丁目前正在合并中;但是,我发现 NXP R&D 的补丁是基于 EGL 库,而不是 Linux 驱动程序。 此致, 志明 Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() 谢谢@Zhiming_Liu 。 我发现 NXP 研发部门提供的补丁是基于 EGL 库,而不是 Linux 驱动程序。 这是否意味着这项更改将应用于闭源的EGL库,而不是开源的Linux驱动程序? 如果您不打算公开此补丁,请告知我们补丁的应用范围,特别是Linux内核版本(6.6、6.18?)。 我们是否可以理解为,研发团队已经确认,即使补丁方案与之前的变通方法不同,它也能解决这个问题?
View full article
S32 Design Studio バージョン v.3.5 ライセンス こんにちは、NXPサポートチームです。 私のS32 Design Studioバージョンv.3.5のライセンスは2026年10月19日に期限切れになります。ライセンスの延長にご協力いただけますでしょうか? アクティベーションコード:30E0-0F7D-F883-9AFB ご支援ありがとうございます。
View full article
[OSM-iMX937/952] 回路図レビュー 新しいプロジェクトでは、iMX937とiMX952が共有ボード設計を採用します iMX937とiMX952の回路図の確認を手伝ってもらえますか? 添付ファイルをご参照ください。 以下の点についてNXPに確認を取りたい。 (1)EVKおよびチェックリストの説明によれば、NXP iMX95の回路にはC604およびC603が存在する。したがって、CAN、このプロジェクトで直接取り除くことは可能でしょうか? (2)部品点数を減らすため、回路図の4ページにある追加のADC VREFおよびVDD_DDRコンデンサを直接削除しました。ドキュメントによると、これらのデザインはNXP iMX95向けに存在し、iMX937/952には適用されていません。 ありがとう。 Re: [OSM-iMX937/952] Schematic review iMx937とiMx952はどちらもプリプロダクション段階なので比較的新しい製品です。詳細なデータシートおよびユーザーマニュアルについては、専属のFAEにお問い合わせください Q1:8.0 GT/s対応のトランスミッタを持つすべてのプラットフォームは、176 nfから265 nFのCTX値を実装しなければなりません。運行中のプラットフォーム 2.5または5.0 GT/sのみで、航続距離は75 nfから265 nFに増加する可能性があります。プルダウンコンデンサについては、必要ない可能性があるため、コメントは不要です。 I.mX937 === 1 x PCIe Gen 3.0 x1レーン(2.5G多重化) I.mX952 === 1x PCIe Gen 3.0 x1レーン (1G SGMIIマルチプレクサ) i.mX95 === 2x PCIe Gen 3.0 x1 Q2: DDR用のコンデンサはすでに5ページに載っています。4ページ目に重複して掲載されているかどうかは不明です。LPDDR5デザインガイドラインは、PIを考慮してメモリベンダーからより詳細な情報を求める場合があります VREFH_ADC0では、1 0.01 μf+0.1 μfのオプションが考えられますが、ノイズフィルターの関係で削除はできない場合があります
View full article
S32 Design Studio version v.3.5许可证 您好,NXP支持团队, 我的S32 Design Studio version v.3.5许可证已于2026年10月19日到期。请问您能否帮忙延长许可证期限? 激活码:30E0-0F7D-F883-9AFB 感谢您的支持。
View full article
MC705J1ACDWE Need confirm COD Spoiler (Highlight to read) The MC705J1ACDWE product has reached its end-of-life (EOL). Please help confirm the wafer diffusion location (COD) for this product. Thank you. The MC705J1ACDWE product has reached its end-of-life (EOL). Please help confirm the wafer diffusion location (COD) for this product. Thank you. 回复: MC705J1ACDWE Need comfirm COD Thank you for your reply and support. Additionally, I obtained original label information from another source, which shows "Diffused In:TH". I can still use this to confirm the information, right? Re: MC705J1ACDWE Need comfirm COD Im sorry for the inconveniences this might cause you, there is no information available to share for this End of Life/Obsolete family Part Number. Best Regards. 回复: MC705J1ACDWE Need comfirm COD Could you help us to confirm your source? Could you please contact your product distributor for further information about this inquiry? As this can help you find the correspondent COD. Best Regards
View full article
Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() A customer reported an issue related to the use of the iMX8MP GPU (drawing using EGL). When the process that initializes the GPU previously called mlockall(MCL_FUTURE), as soon as the CMA area is mapped into userspace, the kernel reports the following BUG(): Kernel BUG at remap_pfn_range_internal+0x23c/0x2c8 Internal error: Oops - BUG: 00000000f2000800 [#1] PREEMPT SMP CPU: 0 PID: 3197 Comm: galcore_window_ Tainted: G O 6.6.142-7.7.0-devel #1-Torizon Hardware name: Toradex Verdin iMX8M Plus WB on Verdin Development Board (DT) pc : remap_pfn_range_internal+0x23c/0x2c8 x27: 00000000a2100000 x20: 0068000000000fcb x19: 0000007f90000000 ^^^^^^^^^^^^^^^^^^^^^^ the PTE already present Call trace: remap_pfn_range_internal+0x23c/0x2c8 remap_pfn_range+0x24/0x58 dma_direct_mmap+0xf4/0x150 dma_mmap_attrs+0x18/0x3c _CMAFSLMapUser+0x9c/0x150 [galcore] gckOS_LockPages+0xe4/0x148 [galcore] gckKERNEL_MapVideoMemory+0x90/0x1dc [galcore] gckVIDMEM_NODE_LockCPU+0x1b4/0x250 [galcore] _LockVideoMemory.isra.0+0x1f4/0x28c [galcore] gckKERNEL_Dispatch+0x210/0x1730 [galcore] gckDEVICE_Dispatch+0xcc/0x220 [galcore] drv_ioctl+0x340/0x444 [galcore] __arm64_sys_ioctl+0xac/0xf0 Kernel panic - not syncing: Oops - BUG: Fatal exception mlockall(MCL_FUTURE) is commonly used by real time applications, and the customer who reported the issue is using CODESYS to drive their HMI. We executed an AI-assisted analysis of the issue, and uncovered a plausible explanation for the reason the issue is being triggered: The CMA allocator in the galcore driver doesn't include an .mmap() hook. During the _CMAFSLMapUser() execution, it calls mmap() to get a vma, which is then used to locate the CMA area using find_vma(). The way mmap() is called causes the kernel to lazilly allocate a SHM area to fullfil the request. In normal cases, this allocation gets discarded moments later when the CMA are is found and remapped. However, when MCL_FUTURE is active the kernel cannot lazilly allocate the SHM area anymore, so it goes and populates the entire area before mmap() returns. In this case we have valid pages on this address, and the later call to remap_pfn_range() would end up silently discarding the memory management housekeeping information, which is exactly what the BUG() prevents. I'll attach a zip file which contains the source code of a program that reproduces the issue consistently without the need to run CODESYS. The AI agent suggested the following patch to fix it: diff -uNr a/hal/kernel/inc/gc_hal_options.h b/hal/kernel/inc/gc_hal_options.h --- a/hal/kernel/inc/gc_hal_options.h 2026-09-04 13:00:44.596621860 +0000 +++ b/hal/kernel/inc/gc_hal_options.h 2026-09-04 13:01:15.643862002 +0000 @@ -1471,9 +1471,17 @@ * Enable this macro can replace the /dev/zero by anon_inode: * [galcore] in /proc/ /maps. * Without the macro, run 'cat /proc/ /maps' will print "/dev/zero". + * + * It is also what gives the allocators an ->mmap handler, which is + * required so that the reservation made by vm_mmap() is created as a + * device mapping (VM_IO | VM_PFNMAP) rather than as ordinary anonymous + * memory. Without it, a process that has called mlockall(MCL_FUTURE) + * gets the range pre-faulted inside vm_mmap(), and the subsequent + * remap_pfn_range() then hits BUG_ON(!pte_none()) in remap_pte_range(). + * See tmp_mmap() in gc_hal_kernel_allocator.c. */ #ifndef gcdANON_FILE_FOR_ALLOCATOR -# define gcdANON_FILE_FOR_ALLOCATOR 0 +# define gcdANON_FILE_FOR_ALLOCATOR 1 #endif /* diff -uNr a/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c b/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c --- a/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c 2026-09-04 13:00:44.605314869 +0000 +++ b/hal/os/linux/kernel/allocator/freescale/gc_hal_kernel_allocator_cma.c 2026-09-04 13:01:15.644216883 +0000 @@ -400,7 +400,13 @@ gcmkHEADER_ARG("Allocator=%p Mdl=%p Cacheable=%d", Allocator, Mdl, Cacheable); #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) +#if gcdANON_FILE_FOR_ALLOCATOR + /* Same as the gfp, dma and reserved_mem allocators: go through the + * allocator's anon file so that its ->mmap handler runs. */ + userLogical = (gctPOINTER)vm_mmap(Allocator->anon_file, +# else userLogical = (gctPOINTER)vm_mmap(gcvNULL, +# endif 0L, Mdl->numPages * PAGE_SIZE, PROT_READ | PROT_WRITE, diff -uNr a/hal/os/linux/kernel/gc_hal_kernel_allocator.c b/hal/os/linux/kernel/gc_hal_kernel_allocator.c --- a/hal/os/linux/kernel/gc_hal_kernel_allocator.c 2026-09-04 13:00:44.603242857 +0000 +++ b/hal/os/linux/kernel/gc_hal_kernel_allocator.c 2026-09-04 13:01:15.644041018 +0000 @@ -104,6 +104,36 @@ static int tmp_mmap(struct file *fp, struct vm_area_struct *vma) { + /* + * Declare the reservation as a device mapping with raw PFNs, before + * mmap() returns it to the caller. remap_pfn_range() sets both flags + * anyway; setting them here only makes them effective from the moment + * the VMA is created, and that is what matters: + * + * - the kernel treats VM_IO | VM_PFNMAP as VM_SPECIAL, documented in + * include/linux/mm.h as "Special vmas that are non-mergable, + * non-mlock()able". mmap_region() therefore clears VM_LOCKED from + * this VMA and leaves mm->locked_vm alone, and __mm_populate() + * skips it outright ("if (vma->vm_flags & (VM_IO | VM_PFNMAP)) + * continue;" in mm/gup.c). + * + * - so a process that has called mlockall(MCL_FUTURE) no longer has + * this range pre-faulted inside vm_mmap(). Every other mapping in + * that process keeps being locked and pre-faulted as before; only + * device memory, which is neither pageable nor swappable and gains + * nothing from being pre-faulted, is left out. + * + * - and the allocator's own remap_pfn_range(), a few microseconds + * later, therefore finds an empty range instead of one the kernel + * has just populated, so it no longer trips + * BUG_ON(!pte_none(ptep_get(pte))) in remap_pte_range(). + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) + vm_flags_set(vma, VM_IO | VM_PFNMAP); +#else + vma->vm_flags |= VM_IO | VM_PFNMAP; +#endif + return 0; } The upstream driver uses a different mechanism which bypasses this issue. Other galcore allocators use the same pattern (calling vm_mmap to get a vma) and thus are likely succeptible to the same BUG(). Could you please look into this and fix the galcore driver? This issue prevents a real use case from working properly, and is affecting our customer directly. Thank you, Rafael Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() Hi @rbeims  Let me run the test and then check with the GPU team. Best Regards, Zhiming Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() Hi @Zhiming_Liu , did you manage to reproduce the bug? If yes, do you have an ETA when the fix will be implemented in your BSP? Thanks.   Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() Hi @alvaro_tx  Our internal team tested this patch. Although it directly resolved the issue encountered by the customer, it caused problems during testing in other applications. We are still investigating the matter and have not reached a final conclusion. Best Regards, Zhiming Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() Hi @Zhiming_Liu , thanks for the clear report. Fully understood, and we also thought this could happen. All good.  Please keep working on this and let us know with any updates.  Thank you, Alvaro.  Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() Dear @Zhiming_Liu , any progress on the investigation?  If there is no progress, could you let us know what problems caused during testing in other applications? The customer needs to advance on their development and is considering applying the patch if there is no official solution, but they want to know the downsides. Thank you, Alvaro.  Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() Hi @alvaro_tx  @rbeims  Regarding the issue the customer mentioned, the relevant patch is currently being merged; however, I see that the patch from NXP R&D is based on the EGL library, not the Linux driver. Best Regards, Zhiming Re: Using iMX8MP GPU on a process that call mlockall(MCL_FUTURE) causes kernel BUG() Thanks @Zhiming_Liu .  I see that the patch from NXP R&D is based on the EGL library, not the Linux driver. Does it mean that the change will be applied to the closed source EGL library and not the open source Linux driver?  If you don't plan to open the patch, any information on where the patch be applied would be appreciated, specially what Linux kernel (6.6, 6.18?).  Should we understand that the R&D team confirmed that the patch solves this issue even if it is not the same approach than the workaround? 
View full article
MC705J1ACDWE Need comfirm COD Spoiler (Highlight to read) MC705J1ACDWE 这个产品已经EOL,请帮忙确认一下此产品的晶圆扩散地(COD),谢谢。 MC705J1ACDWE 这个产品已经EOL,请帮忙确认一下此产品的晶圆扩散地(COD),谢谢。 回复: MC705J1ACDWE Need comfirm COD 感谢您的回复和支持。 另外,我从其他方面拿到一个原厂的标签信息,看到Diffused In:TH,我这边还是可以按照这个进行确认,对吧? Re: MC705J1ACDWE Need comfirm COD 很抱歉给您带来不便,目前没有关于此停产/已淘汰系列零件编号的信息可以分享。 顺祝商祺! 回复: MC705J1ACDWE Need comfirm COD 您能帮我们确认一下您的消息来源吗? 请您联系您的产品代理商以获取有关此询价的更多信息?这样可以帮助您找到对应的货到付款方式。 顺祝商祺!
View full article
S32 Design Studio version v.3.5 license Hello, this is the NXP support team. My S32 Design Studio version v.3.5 license expires on October 19, 2026. Could you please help me extend the license? Activation code: 30E0-0F7D-F883-9AFB Thank you for your support.
View full article
[OSM-iMX937/952] 原理图审查 在我们的新项目中,iMX937 和 iMX952 将采用共享电路板设计。 能否帮忙审核一下iMX937和iMX952的原理图? 请参考附件。 以下问题希望向恩智浦半导体(NXP)确认: (1)根据 EVK 和检查清单的描述,NXP iMX95 电路中存在 C604 和 C603。因此,在这个项目中可以直接移除它们吗? (2)为了减少元器件数量,直接移除了电路图第 4 页上的附加 ADC VREF 和 VDD_DDR 电容。根据文档,这些设计是为 NXP iMX95 设计的,而不是为 iMX937/952 设计的。 谢谢。 Re: [OSM-iMX937/952] Schematic review iMx937 和 iMx952 都是相当新的产品,因为它们都处于预生产阶段。请联系专用的现场应用工程师 (FAE) 获取详细数据表和用户手册。 Q1:所有支持 8.0 GT/s 发射器的平台都必须实现 176 nF 至 265 nF 的 CTX 值。平台运营于 仅使用 2.5 或 5.0 GT/s 可能会将该范围增加到 75 nF 至 265 nF。对于下拉电容,无需赘述,因为可能并不需要。 I.mX937 === 1 个 PCIe Gen 3.0 x1 通道(2.5G)多路复用器) I.mX952 === 1 个 PCIe Gen 3.0 x1 通道(1G SGMII 多路复用器) i.mX95 === 2 个 PCIe Gen 3.0 x1 插槽 Q2:第5页已经有一些用于DDR的电容了。不确定第4页是否重复。由于产品改进 (PI) 的考虑,可能需要向内存供应商索取 LPDDR5 设计指南以获取更详细的信息。 对于 VREFH_ADC0,1 个 0.01 µf + 0.1 µf 的电容可能是一个可行的方案,但由于噪声滤波器的原因,可能不会被删除。
View full article
S32K312 BCTU – 先进先出水印回调功能正常,但最后一次转换回调未被触发 NXP社区的各位朋友,大家好! 我正在使用 S32 Design Studio 和 S32K3 RTD 7.0.1 对 S32K312 MCU 进行开发。 我已经配置 BCTU,使其使用软件触发器触发一系列 ADC 转换。我正在测试 BCTU FIFO1 水印回调和 BCTU 最后转换回调。 当前配置: MCU:S32K312 驱动程序:S32K3 RTD 7.0.1 ADC实例:ADC0 BCTU转换列表:4个ADC通道(0、2、4、3) 触发信号源:BCTU软件触发信号 中断:BCTU_IRQn 已启用 通知:FIFO1 水印和最后转换回调 观察到的行为: 当我启用 FIFO1 水印通知时,水印回调成功触发,我可以从 FIFO1 读取 ADC 转换结果。 但是,当我启用 BCTU 最后转换通知时,相应的回调函数并未触发信号。 调试过程中,我观察到: 执行进入 Bctu_0_Isr()。 驱动程序检查已启用的 BCTU 中断源。 对于最后一次转换通知,条件 if((*Reg & Mask) != 0U) 的计算结果为 false。 在中断处理期间检查时,BCTU MSR 寄存器中的 LIST0_Last 位保持为 0。 因此,最后一次转换回调函数不会被执行。 问题: 为什么 FIFO1 水印回调能够正常工作,而 BCTU 最后转换回调却无法触发? 究竟是什么硬件状况导致 MSR.LIST0_Last 变为 1? 最后一次转换中断是否需要在 BCTU 转换列表、触发信号配置或中断使能设置中进行额外配置? FIFO1 水印回调和 BCTU 最后转换回调能否同时用于同一个转换列表? LIST0_Last 状态标志是由硬件自动清除还是由 RTD 中断处理程序自动清除?如果是这样,那么是在哪个阶段? 我应该监测哪些 BCTU 寄存器来验证最后一次转换事件是否正确生成? 请问您能否帮我理解一下,为什么 FIFO 水印中断能够正常工作,而 BCTU 最后转换中断却没有按预期生成或处理? 如有需要,我可以提供我的 BCTU 配置、寄存器值和 ISR 调试观察结果的屏幕截图。 感谢您的支持。 #s32k312 #adcbctu #bctuswconv #listlastconv Re: S32K312 BCTU – FIFO Watermark Callback Working, but Last Conversion Callback Not Triggered 您好, 如果记忆没错的话,只有当 ADC 转换结果目标设置为 ADCnDR 时,才能生成上次转换通知。 参考手册在 LIST_IEN 描述中也有说明。   BR,彼得  
View full article