Multi Source Translation Content

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Multi Source Translation Content

讨论

排序依据:
MCXA153:LPSPIデータバースト転送。 こんにちは、 リファレンス・マニュアルMCXA153 TDBRnおよびRDBRn LPSPIレジスタの説明が含まれています。 「TDBRnおよびRDBRnレジスタは、DMAコントローラで使用するための送信FIFOへのバースト転送をサポートします」。 これらのレジスタを使ったバースト転送のサンプルコードを誰か共有してもらえますか? よろしくお願いします ボグダン 通信・制御(I3C |I2C |SPI |FlexCAN |イーサネット |FlexIO) MCXA Re: MCXA153: LPSPI data burst transfer. こんにちは、 @bogdan_u 申し訳ありませんが、現在、関連する事例はございません。 私が見つけた最も近い例はMCXA153 LPSPI_MasterTransferEDMALite()とeDMAを使っていますが、ドライバーはTDR/RDRをLPSPI_GetTxRegisterAddress() / LPSPI_GetRxRegisterAddress()経由でターゲットにしており、バーストエイリアスウィンドウではありません。 でも、試してみることはできると思います。 typedef struct { uint32_t cmd; uint32_t data[128]; } lpspi_burst_tx_t; static inline uint32_t LPSPI_TCBR_Address(LPSPI_Type *base) { return ((uint32_t)base + LPSPI_TCBR_OFFSET); } static inline uint32_t LPSPI_TDBR0_Address(LPSPI_Type *base) { return ((uint32_t)base + LPSPI_TDBR0_OFFSET); } static inline uint32_t LPSPI_RDBR0_Address(LPSPI_Type *base) { return ((uint32_t)base + LPSPI_RDBR0_OFFSET); } void LPSPI_StartTxBurstDMA(LPSPI_Type *base, edma_handle_t *txDmaHandle, uint32_t *cmd_plus_data, uint32_t nwords) { edma_transfer_config_t cfg = {0}; cfg.srcAddr = (uint32_t)&cmd_plus_data[0]; cfg.destAddr = LPSPI_TCBR_Address(base); cfg.srcOffset = 4; cfg.destOffset = 4; cfg.srcTransferSize = kEDMA_TransferSize4Bytes; cfg.destTransferSize = kEDMA_TransferSize4Bytes; cfg.minorLoopBytes = 4; cfg.majorLoopCounts = nwords + 1u; EDMA_ResetChannel(txDmaHandle->base, txDmaHandle->channel); EDMA_SetTransferConfig(txDmaHandle->base, txDmaHandle->channel, &cfg, NULL); EDMA_StartTransfer(txDmaHandle); LPSPI_EnableDMA(base, kLPSPI_TxDmaEnable); } void LPSPI_StartRxBurstDMA(LPSPI_Type *base, edma_handle_t *rxDmaHandle, uint32_t *rx_words, uint32_t nwords) { edma_transfer_config_t cfg = {0}; cfg.srcAddr = LPSPI_RDBR0_Address(base); cfg.destAddr = (uint32_t)&rx_words[0]; cfg.srcOffset = 4; cfg.destOffset = 4; cfg.srcTransferSize = kEDMA_TransferSize4Bytes; cfg.destTransferSize = kEDMA_TransferSize4Bytes; cfg.minorLoopBytes = 4; cfg.majorLoopCounts = nwords; EDMA_ResetChannel(rxDmaHandle->base, rxDmaHandle->channel); EDMA_SetTransferConfig(rxDmaHandle->base, rxDmaHandle->channel, &cfg, NULL); EDMA_StartTransfer(rxDmaHandle); LPSPI_EnableDMA(base, kLPSPI_RxDmaEnable); } BR ハリー
查看全文
关于 s32k344 的 CAN 问题 我目前使用的编译器是s32ds3.4,RTD2.0.0。其中,CAN FD 功能对 can0-can5 启用,ENABLE RX FIFO 功能对 can0 启用。实现的功能是:can1 向 can0 发送 64 位数据,can4 向 can2 发送 64 位数据,can3 向 can5 发送 64 位数据。但是,为什么 can0 和 can5 可以正常接收数据,而 can2 却无法接收数据?当我将 can4 设置为环回模式时,can4 也能正常接收数据。硬件连接是通过使用杜邦线将 can1 的 CANH 连接到 can0 的 CANH,将 can1 的 CANL 连接到 can0 的 CANL,将 can4 的 CANH 连接到 can2 的 CANH,将 can4 的 CANL 连接到 can2 的 CANL,将 can5 的 CANH 连接到 can3 的 CANH,以及将 can5 的 CANL 连接到 can3 的 CANL 来实现的。这是我的代码 回复: Regarding the CAN issue of s32k344 我发现了一个问题。引脚配置错误
查看全文
MCXA265VPN布局建议 NXP团队 您有MCXA265VPN扇出示例吗?需要根据垫片和孔径尺寸进行推荐。过孔是在焊盘内还是引脚之间?BGA下方是否需要完整的接地层? 请帮忙。 谢谢丹·罗杰斯 电路板设计
查看全文
MCXA265VPN Layout Suggestion NXP Team, Do you have a MCXA265VPN fanout example?  Need recommended via pad and hole size.  Are the vias in pads or between pins?  Need to have a solid GND plane under BGA? Please help. Thanks Dan Rogers Board Design
查看全文
S32k344のCAN問題について 現在使用しているコンパイラはs32ds3.4です。RTD2.0.0その中で、can0-can5ではCAN FD機能が有効、can0ではENABLE RX FIFO機能が有効です。実装された機能は、can1がcan0に64ビットのデータを送信し、can4がcan2に64ビットのデータを送信し、can3がcan5に64ビットのデータを送信するというものです。しかし、なぜcan0とcan5は通常データを受け取れるのにcan2はデータを受け取れないのでしょうか?can4をループバックモードに設定すると、can4は通常通りデータを受け取ることができます。ハードウェア接続は、デュポンワイヤを使用して、can1のCANHとcan0のCANH、can1のCANLとcan0のCANL、can4のCANHとcan2のCANH、can4のCANLとcan2のCANL、can5のCANHとcan3のCANH、can5のCANLとcan3のCANLを接続することによって実現されます。これが私のコードです 回复: Regarding the CAN issue of s32k344 問題点を見つけました。ピン配置が間違っています
查看全文
S32K342 FOTA Bootloader Architecture Guidance Required (UART-Based Update) Hello NXP Team, We are developing a custom Firmware Over-The-Air (FOTA) solution for the S32K342 and would like guidance on the recommended flash architecture and boot flow. MCU Details Device: S32K342 PFlash: 2 MB Bank 0: 1 MB Bank 1: 1 MB DFlash: 128 KB Current Status We are using UART as the firmware update interface. So far, we have successfully: Receive the firmware (.bin) over UART Store the complete binary into flash memory Verify that the received image is stored correctly Our remaining challenge is implementing the bootloader architecture and application switching mechanism. We would like clarification on the following: 1. Recommended FOTA Flash Layout What is the recommended memory layout for an S32K342 dual-image FOTA implementation? Specifically, we would like to know the recommended locations for: Bootloader Application Slot A Application Slot B Metadata / Boot flags Version information CRC Rollback information An example memory map with addresses would be extremely helpful. 2. Recommended Boot Flow Could someone explain the complete boot sequence recommended by NXP? For example: Reset Bootloader starts Check boot flags Select active application Validate image (CRC/signature) Jump to application We would appreciate a flow diagram or explanation of the complete process. 3. Bootloader to Application Jump For S32K342, is the standard Cortex-M7 jump sequence sufficient? For example: Read MSP from application base address Read Reset_Handler from base + 4 Set MSP Update VTOR Jump to Reset_Handler Are there any S32K342-specific requirements or initialization steps before transferring control? 4. Dual Application Images If App A and App B are located at different flash addresses: Should each application have its own linker script? Or is there a recommended NXP approach for building dual-slot applications? 5. Flash Bank Usage Since S32K342 has two 1 MB PFlash banks: Is the recommended approach to: Execute the bootloader from Bank 0 Program the new firmware into Bank 1 Switch execution after successful verification Are there any Read-While-Write or erase/programming restrictions between the two PFlash banks? 6. Metadata Storage Where is the preferred location to store: Active image flag Image validity Firmware version CRC Rollback status Should these be stored in: Reserved PFlash DFlash Another dedicated region? 7. UART-Based FOTA Since our update interface is UART, we would like to know the recommended workflow. Is the following flow correct? PC │ UART │ Bootloader receives .bin │ Store firmware into inactive flash slot │ Verify CRC │ Update boot metadata │ Reset MCU │ Bootloader selects new image │ Jump to application Or does NXP recommend a different approach? 8. AB_SWAP vs Custom Bootloader Is HSE AB_SWAP mandatory for production FOTA on S32K342? Or is a fully custom bootloader with dual application slots also a supported and commonly used architecture? If there are any application notes, reference projects, bootloader examples, or documentation specifically covering S32K342 FOTA, UART firmware updates, or dual-image bootloaders, we would greatly appreciate the references. Thank you for your support. S32K3 S32DS-ARM  Re: S32K342 FOTA Bootloader Architecture Guidance Required (UART-Based Update) Hi @bavinkumar_02  1. In case of S32K342, there’s only one possible setup for AB_SWAP. See “3.5.3.2 Illustrations of Flash memory layout in AB_SWAP” in HSE Firmware reference manual which can be downloaded from Documentation -> Secure files: https://www.nxp.com/products/S32K3 In your case, the most convenient and most common layout is: It’s necessary to install AB_SWAP version of HSE firmware (the swap is a feature of HSE, it’s not possible to do that without HSE firmware). The firmware is installed to both partitions and it occupies last 176KB in both blocks as shown on the picture. Because whole blocks are swapped, it’s necessary to have exact copy of the bootloader in both blocks. The rest is allocated for applications. The code is always running from active block, so the bootloader and all applications are compiled for addresses in active block. When bootloader updates an application, it programs the application to passive block, so there’s no problem with read-while-write issues during flash programming. Once the application is programmed, you can trigger HSE_SRV_ID_ACTIVATE_PASSIVE_BLOCK HSE service. After next reset, the partitions will be swapped and bootloader will jump to application as usual (to new application which is in active block now). 2. The flow is application dependent. In modern automotive applications, simple CRC-based validation is no longer considered sufficient. Integrity and authenticity of the software are typically ensured using Secure Boot mechanisms. On S32K3 devices, this is handled by the Hardware Security Engine (HSE), which performs cryptographic verification (e.g. signature-based) autonomously during boot. Production automotive systems are expected to leverage these hardware-backed security features rather than relying on CRC-only validation. We provide Secure Boot application note including demo projects. It can be downloaded from: https://www.nxp.com/products/S32K3 Application note can be found here: Documentation -> Secure Files -> Secure Boot Application note v0.1.1.0 (AN744511) Associated demo project can be downloaded here: Design Resources -> Software -> Secure Files -> SecureBootAppNoteDemo (SW745310) Other examples for secure boot can be found in HSE Demo Examples: https://www.nxp.com/webapp/Download?colCode=S32K3_HSE_DemoExamples There are examples for all three modes – advanced secure boot, basic secure boot and SHE secure boot. Advanced secure boot is recommended. See Readme.md file which is included in all projects. 3. Yes, that’s standard jump sequence. It’s just highly recommended to de-initialize all resources initialized by bootloader before the jump. 4. As mentioned above, the code is always executed from active partition, so the application always uses the same linker file. 5. Already discussed above. 6. This is up to user. You can store the data behind the application image or to data flash. 7. For a production automotive use case, the proposed flow is generally correct from the data-transfer point of view, but as already mentioned, I would not recommend relying on CRC as the main validation mechanism. In automotive applications, the received image is typically protected cryptographically - for example, the image may be encrypted and its authenticity/integrity is verified using a digital signature, not only by CRC. Also, when using the HSE AB_SWAP mechanism, the bootloader does not simply select the new image by software metadata after reset. After the new image is programmed into the passive partition and successfully verified, the application/bootloader should call the HSE service HSE_SRV_ID_ACTIVATE_PASSIVE_BLOCK. This activates the passive block, so after reset the device boots from the newly activated partition. 8. HSE AB_SWAP is not strictly mandatory, but for a production automotive FOTA solution on S32K342 it is strongly recommended. Implementing FOTA without HSE would mean you are not leveraging one of the key advantages of the S32K3 platform. The main benefit of these devices is the built-in support for A/B swap (partition remapping) handled by HSE. Without it, the bootloader would have to manage everything manually. Specifically, without HSE AB_SWAP: You would need to implement your own mechanism for selecting between A/B images You would have to carefully manage the address space and link each application to different fixed locations The swap between images would not be handled autonomously by the hardware, but entirely in your software There is no alternative hardware-supported remapping mechanism available outside of HSE AB swap feature In addition, you would lose the simplicity and robustness of Secure Boot integrated with AB_SWAP. With HSE, image activation, validation, and switching between partitions are handled in a much more controlled and efficient way, aligned with automotive security requirements. In summary, doing this without HSE is possible, but it significantly increases complexity and removes key benefits of the platform. You can take a look at “S32K3XX HSE and OTA Advance Training [TR744101]” which can be downloaded Documentation -> Secure files: https://www.nxp.com/products/S32K3 Regards, Lukas
查看全文
Additional materials related to DRM099 application note Dear all, I'm an Electrical Engineering student and I'm using the document "Sensorless PMSM Vector Control with a Sliding Mode Observer for Compressors Using MC56F8013" (document number DRM099) to learn about the sliding mode observer for permanent magnet synchronous machines. So far this document has been very useful, and I'm really thankful that NXP made it available! In the document the authors mention some functions such as "PMSM_SL_DQSMOBemfSpedObservSclUniv32()", "EstimProcessing()", which would be very useful for me to look their code. In this way, I hope to better understand the concepts explained in DRM099, and hopefully tackle the challenge of implementing and tuning the SMO in the dq frame. Therefore, if it is not asking too much, I was wondering if I could have access to these additional files and materials, if possible. Anything you can share will be immensely appreciated and helpful. Thank you in advance for your time and consideration! I wish you a great day. Best regards, Rafael Re: Additional materials related to DRM099 application note Hello @Rafael1 , Thanks for your post. I think the information below is what you are looking for: RDDSCPMSMVCSMO: Sensorless PMSM Vector Control for Compressors Reference Design Using MC56F8013 https://www.nxp.com/search?keyword=pmsm_sensorlesscl&start=0  Download link: https://www.nxp.com/webapp/Download?colCode=PMSM_SENSORLESSCL_DQHREL&appType=license&location=null Hope it helps. BR Celeste Re: Additional materials related to DRM099 application note Thank you so much, @Celeste_Liu  After downloading and executing the .exe file, I was able to get the C code for the motor control with sliding mode observer. That was exactly what I was looking for. Thank you for your time and consideration! Have a nice day! Re: Additional materials related to DRM099 application note Glad to help! Any new questions, welcome to create a new post.
查看全文
MPC5748G: MachineCheck exception hen trying to access peripherals in user mode Hello, I ported OpenPicoRTOS to PowerPC platforms & ran into an issue. Despite configuring the PBRIDGE (correctly ?) i get a MachineCheck exception every time i try to access a peripheral in user mode. Supervisor mode works fine but it's not really what i'm after, i want user/supervisor mode management (+MPU) & being able to access peripherals in user mode. I tried various things but nothing seems to work, i don't know if i'm doing something wrong of it it's simply not possible. Right now i just kept everything in supervisor mode for demonstration purposes, here's the current state of the code:  - My attempt at configuring the PBRIDGE: https://github.com/jnaulet/OpenPicoRTOS/blob/v1.11.x/arch/powerpc/e200z4/mach-mpc574x/startup.S  - The de-activated user mode (in arch_save_first_context): https://github.com/jnaulet/OpenPicoRTOS/blob/v1.11.x/arch/powerpc/e200z4/picoRTOS_portasm.S  - The complete demo i use for debugging this system: https://github.com/jnaulet/OpenPicoRTOS/tree/v1.11.x/demo/devkit-mpc5748g Any help is appreciated. Kind regards. Re: MPC5748G: MachineCheck exception hen trying to access peripherals in user mode Hello, there can be multiple reasons for user mode access rejection: Most probably PBRIDGE or MPU configuration. You can start checking following: PBRIDGE PACR/OPACR initialization. Whether all peripheral slots are configured for user access. MPU region definitions covering: 0xFxxxxxxx peripheral space read/write permissions supervisor/user attributes. MSR value after the RTOS drops to user mode. The exact peripheral address that causes the fault. MCSR/ESR/DEAR at IVOR1 entry. Best Regards, Peter
查看全文
MCXA153: LPSPI data burst transfer. Hello, The Reference Manual MCXA153 contains a description of the TDBRn and RDBRn LPSPI registers: "TDBRn and RDBRn registers supports burst transfers of data to the transmit FIFO for use with the DMA controller". Can anyone share sample code for a burst transfer using these registers? best regards Bogdan Communication & Control(I3C | I2C | SPI | FlexCAN | Ethernet | FlexIO) MCXA Re: MCXA153: LPSPI data burst transfer. Hi @bogdan_u  Sorry, there are currently no relevant examples available. The closest MCXA153 example I found uses LPSPI_MasterTransferEDMALite() with eDMA, but the driver targets TDR/RDR via LPSPI_GetTxRegisterAddress() / LPSPI_GetRxRegisterAddress() , not the burst alias window. But i think you can try to use. typedef struct { uint32_t cmd; uint32_t data[128]; } lpspi_burst_tx_t; static inline uint32_t LPSPI_TCBR_Address(LPSPI_Type *base) { return ((uint32_t)base + LPSPI_TCBR_OFFSET); } static inline uint32_t LPSPI_TDBR0_Address(LPSPI_Type *base) { return ((uint32_t)base + LPSPI_TDBR0_OFFSET); } static inline uint32_t LPSPI_RDBR0_Address(LPSPI_Type *base) { return ((uint32_t)base + LPSPI_RDBR0_OFFSET); } void LPSPI_StartTxBurstDMA(LPSPI_Type *base, edma_handle_t *txDmaHandle, uint32_t *cmd_plus_data, uint32_t nwords) { edma_transfer_config_t cfg = {0}; cfg.srcAddr = (uint32_t)&cmd_plus_data[0]; cfg.destAddr = LPSPI_TCBR_Address(base); cfg.srcOffset = 4; cfg.destOffset = 4; cfg.srcTransferSize = kEDMA_TransferSize4Bytes; cfg.destTransferSize = kEDMA_TransferSize4Bytes; cfg.minorLoopBytes = 4; cfg.majorLoopCounts = nwords + 1u; EDMA_ResetChannel(txDmaHandle->base, txDmaHandle->channel); EDMA_SetTransferConfig(txDmaHandle->base, txDmaHandle->channel, &cfg, NULL); EDMA_StartTransfer(txDmaHandle); LPSPI_EnableDMA(base, kLPSPI_TxDmaEnable); } void LPSPI_StartRxBurstDMA(LPSPI_Type *base, edma_handle_t *rxDmaHandle, uint32_t *rx_words, uint32_t nwords) { edma_transfer_config_t cfg = {0}; cfg.srcAddr = LPSPI_RDBR0_Address(base); cfg.destAddr = (uint32_t)&rx_words[0]; cfg.srcOffset = 4; cfg.destOffset = 4; cfg.srcTransferSize = kEDMA_TransferSize4Bytes; cfg.destTransferSize = kEDMA_TransferSize4Bytes; cfg.minorLoopBytes = 4; cfg.majorLoopCounts = nwords; EDMA_ResetChannel(rxDmaHandle->base, rxDmaHandle->channel); EDMA_SetTransferConfig(rxDmaHandle->base, rxDmaHandle->channel, &cfg, NULL); EDMA_StartTransfer(rxDmaHandle); LPSPI_EnableDMA(base, kLPSPI_RxDmaEnable); } BR Harry
查看全文
DRM099 应用笔记的相关补充材料 尊敬的各位, 我是一名电气工程专业的学生,我正在使用文档“基于MC56F8013的压缩机的无传感器PMSM矢量控制与滑模观测器”(文档编号DRM099)来学习永磁同步电机的滑模观测器。到目前为止,这份文件非常有用,我非常感谢恩智浦将其提供出来! 文档中作者提到了一些函数,例如“PMSM_SL_DQSMOBemfSpedObservSclUniv32()”、“EstimProcessing()”,查看他们的代码对我来说非常有用。通过这种方式,我希望能够更好地理解 DRM099 中解释的概念,并希望能够解决在 dq 帧中实现和调整 SMO 的挑战。因此,如果要求不太过分的话,我想知道我是否可以查阅这些额外的文件和资料。您的任何分享都将不胜感激,并对我们大有帮助。 感谢您抽出宝贵时间并考虑我的请求!祝你今天过得愉快。 顺祝商祺! 拉斐尔 Re: Additional materials related to DRM099 application note 你好@Rafael1 , 感谢您的帖子。我认为以下信息正是您要找的: RDDSCPMSMVCSMO:基于MC56F8013的无传感器永磁同步电机压缩机矢量控制参考设计 https://www.nxp.com/search?keyword=pmsm_sensorlesscl&start=0 下载链接: https://www.nxp.com/webapp/Download?colCode=PMSM_SENSORLESSCL_DQHREL &appType=license&location=null 希望对您有所帮助。 BR 塞莱斯特 Re: Additional materials related to DRM099 application note 非常感谢你, @Celeste_Liu 下载并运行 .exe 文件后从文件中,我得到了带有滑模观察器的电机控制的 C 代码。这正是我想要的。 感谢您抽出宝贵时间并考虑我的请求!祝你今天过得愉快! Re: Additional materials related to DRM099 application note 乐意效劳!如有任何新问题,欢迎发帖提问。
查看全文
MPC5748G:尝试在用户模式下访问外围设备时发生 MachineCheck 异常 你好, 我将 OpenPicoRTOS 移植到 PowerPC 平台时遇到了问题。 尽管我已正确配置了 PBRIDGE,但每次尝试在用户模式下访问外围设备时,都会出现 MachineCheck 异常。 管理员模式运行良好,但这并不是我想要的,我想要用户/管理员模式管理(+MPU)并且能够在用户模式下访问外围设备。 我尝试了各种方法,但似乎都行不通,我不知道是我做错了什么,还是根本就做不到。 目前为了演示目的,我将所有程序都保持在管理模式下,以下是当前代码状态: - 我尝试配置 PBRIDGE: https://github.com/jnaulet/OpenPicoRTOS/blob/v1.11.x/arch/powerpc/e200z4/mach-mpc574x/startup.S - 已停用的用户模式(在 arch_save_first_context 中): https://github.com/jnaulet/OpenPicoRTOS/blob/v1.11.x/arch/powerpc/e200z4/picoRTOS_portasm.S - 我用于调试此系统的完整演示: https://github.com/jnaulet/OpenPicoRTOS/tree/v1.11.x/demo/devkit-mpc5748g 非常感谢您的帮助。 亲切的问候。 Re: MPC5748G: MachineCheck exception hen trying to access peripherals in user mode 你好, 用户模式访问被拒绝的原因可能有多种: 很可能是 PBRIDGE 或 MPU 配置。 您可以开始检查以下内容: PBRIDGE PACR/OPACR 初始化。 所有外围设备插槽是否都已配置为供用户访问。 MPU区域定义涵盖: 0xFxxxxxxx 外围空间 读/写权限 管理员/用户属性。 RTOS 降至用户模式后的 MSR 值。 导致故障的确切外围设备地址。 MCSR/ESR/DEAR 在 IVOR1 入口处。 顺祝商祺! Peter
查看全文
S32K358 + FS2633: RSTB stays LOW with MCU assembled, but goes HIGH when JTAG is connected I am using S32K358 with FS2633. When I test only the FS2633 section (MCU removed), the RSTB is released (HIGH) and the 3.3 V rail is present. After assembling the MCU and all components, RSTB stays LOW, and the MCU does not boot. If I connect a JTAG debugger, RSTB goes HIGH, I can successfully program the MCU, and the application runs normally. However, once I disconnect the JTAG, RSTB goes LOW again and the MCU stops running. One observation is that the FS2633 RSTB output is a 3.3 V signal, while the S32K358 RESET line is pulled up to 5 V on my board. Despite this voltage difference, the system works correctly whenever the JTAG debugger is connected. Could this reset voltage level or the debugger be influencing the reset or power-up sequence? Could this issue be related to the power-up sequence, reset timing, FS2633 startup configuration, or debugger-related behavior? Has anyone experienced a similar issue or have suggestions for debugging? Re: S32K358 + FS2633: RSTB stays LOW with MCU assembled, but goes HIGH when JTAG is connected You'd better try to test by pulling up the FS2633 RSTB to 3.3 V and check whether this issue has or not.
查看全文
DRM099アプリケーションノートに関連する追加資料 皆様、 私は電気工学を専攻する学生で、永久磁石同期機のスライディングモードオブザーバについて学ぶために、「MC56F8013を使用したコンプレッサ用センサレスPMSMベクトル制御(スライディングモードオブザーバ付き)」(文書番号DRM099)という文書を使用しています。これまでのところ、このドキュメントは非常に役立っており、NXPが提供してくれたことに本当に感謝しています! 文書の中で著者らは「PMSM_SL_DQSMOBemfSpedObservSclUniv32()」、「EstimProcessing()」といった関数について言及しており、それらのコードを確認することは私にとって非常に役立つだろう。このようにして、DRM099で説明されている概念をより深く理解し、dqフレームにおけるSMOの実装と調整という課題に取り組めることを期待しています。ですので、もし無理がなければ、これらの追加ファイルや資料にアクセスできないかと思いまして。どんなことでも共有していただけると大変ありがたいし、役に立ちます。 お時間を割いてご検討いただき、誠にありがとうございます!素敵な一日をお過ごしください。 よろしくお願いいたします。 ラファエル Re: Additional materials related to DRM099 application note こんにちは、 @Rafael1 さん。 投稿ありがとうございます。以下の情報が、あなたが探しているものだと思います。 RDDSCPMSMVCSMO:コンプレッサー向けセンサーレスPMSMベクトル制御リファレンスデザイン MC56F8013 https://www.nxp.com/search?keyword=pmsm_sensorlesscl&start=0 ダウンロードリンク: https://www.nxp.com/webapp/Download?colCode =PMSM_SENSORLESSCL_DQHREL&appType=license&location=null お役に立てば幸いです。 BR セレステ Re: Additional materials related to DRM099 application note 本当にありがとうございます、 @Celeste_Liu  .exeファイルをダウンロードして実行した後スライドモードのオブザーバーでモーター制御のCコードを入手できました。まさに私が探していたものだった。 お時間を割いていただき、ご検討いただきありがとうございます!良い1日を! Re: Additional materials related to DRM099 application note お役に立てて嬉しいです!他に質問があれば、新しい投稿を作成してください。
查看全文
MPC5748G: ユーザーモードでペリフェラルにアクセスしようとする際にMachineCheck例外が発生する こんにちは、 OpenPicortoをPowerPCプラットフォームに移植したところ、問題が発生しました。 PBRIDGEの設定は正しくできているのに、ユーザーモードでペリフェラルにアクセスしようとするたびにMachineCheckの例外が出ます。 スーパーバイザーモードは問題なく動作しますが、私が求めているものではありません。ユーザー/スーパーバイザーモードのマネジメント(+MPU)と、ユーザーモードでペリフェラルにアクセスできるようにしたいです。 いろいろ試してみましたが、どれもうまくいきません。私が何か間違ったことをしているのか、それともそもそも不可能なことなのか分かりません。 現時点では、デモンストレーション目的で全てをスーパーバイザーモードにしています。現在のコードの状態は以下のとおりです。 - PBRIDGEの設定を試みた結果: https://github.com/jnaulet/OpenPicoRTOS/blob/v1.11.x/arch/powerpc/e200z4/mach-mpc574x/startup.S - 無効化されたユーザーモード(arch_save_first_contextでは): https://github.com/jnaulet/OpenPicoRTOS/blob/v1.11.x/arch/powerpc/e200z4/picoRTOS_portasm.S - このシステムのデバッグに使用している完全なデモ: https://github.com/jnaulet/OpenPicoRTOS/tree/v1.11.x/demo/devkit-mpc5748g どんなご協力でもありがたいです。 敬具。 Re: MPC5748G: MachineCheck exception hen trying to access peripherals in user mode こんにちは、 ユーザーモードアクセス拒否には複数の理由があります: おそらくPBRIDGEまたはMPU構成でしょう。 以下から確認を始めることができます: PBRIDGE PACR/OPACRの初期化。 すべてのペリフェラルスロットがユーザーアクセスに設定されているかどうか。 MPU領域の定義対象: 0xFxxxxxxx ペリフェラル空間 読み取り/書き込み権限 スーパーバイザー/ユーザー属性。 RTOSがユーザーモードに切り替わった後のMSR値。 故障を引き起こす正確なペリフェラルアドレス。 IVOR1入力時のMCSR/ESR/DEAR。 よろしくお願いいたします。 ピーター
查看全文
S32K342 FOTAブートローダーアーキテクチャに関するガイダンスが必要(UARTベースのアップデート) NXPチームの皆様、こんにちは。 S32K342向けにカスタムファームウェア無線アップデート(FOTA)ソリューションを開発しており、推奨されるフラッシュアーキテクチャとブートフローについてアドバイスをいただきたいと考えています。 MCU詳細 装置:S32K342 PFlash: 2 MB バンク0:1MB バンク1:1MB DFlash: 128 KB 現状 私たちはファームウェアアップデートインターフェースとしてUARTを使用しています。 これまでに、私たちは以下のことに成功しました: UART経由でファームウェア(.binファイル)を受信する バイナリ全体をフラッシュメモリに保存する 受信した画像が正しく保存されていることを確認してください。 残された課題は、ブートローダーアーキテクチャとアプリケーションスイッチングの仕組みを実装することです。 以下の点についてご説明をお願いいたします。 1. 推奨されるFOTAフラッシュレイアウト S32K342デュアルイメージFOTA実装における推奨メモリレイアウトは何ですか? 具体的には、以下の場所について推奨される場所を知りたいです。 ブートローダ アプリケーションスロットA アプリケーションスロットB メタデータ/ブートフラグ バージョン情報 CRC ロールバック情報 アドレスを含むメモリマップの例があると非常に助かります。 2. 推奨ブートフロー NXPが推奨する完全な起動手順を誰か説明してもらえますか? 例: リセット ブートローダーが起動します ブートフラグを確認する アクティブアプリケーションを選択してください 画像の検証(CRC/署名) アプリケーションへジャンプ フロー図またはプロセス全体の説明をいただけると幸いです。 3. ブートローダーからアプリケーションジャンプへ S32K342の場合、標準的なCortex-M7ジャンプシーケンスで十分でしょうか? 例: アプリケーションベースアドレスからMSPを読み込みます Reset_Handlerをベース+4から読み込む MSPを設定する VTORをアップデート Reset_Handlerへジャンプ 制御を移管する前に、S32K342固有の要件や初期化手順はありますか? 4. デュアルアプリケーションイメージ もしアプリAとアプリBが異なるフラッシュアドレスにある場合: 各アプリケーションに独自のリンカースクリプトを持つべきでしょうか? それともデュアルスロットアプリケーションをビルディングするための推奨されるNXPのアプローチはありますか? 5. フラッシュバンクの使用 S32K342には1MBのPFlashバンクが2つあるため、 推奨されるアプローチは以下ですか? バンク0からブートローダーを実行する 新しいファームウェアをバンク1にプログラムする 検証成功後のスイッチ実行 2つのPFlashバンク間で、書き込み中の読み出しや消去/プログラミングに関する制限はありますか? 6. メタデータの保存 保管場所として最適な場所はどこですか? アクティブイメージフラグ 画像の妥当性 ファームウェアのバージョン CRC ロールバックステータス これらはどこに保管すべきでしょうか? 予約済みPFlash DFlash 別の専用地域ですか? 7. UARTベースのFOTA 当社のアップデートインターフェースはUARTなので、推奨されるワークフローを知りたいです。 以下の流れは正しいですか? PC │ UART │ ブートローダーは.binファイルを受け取ります │ ファームウェアを非アクティブなフラッシュスロットに保存します │ CRCの確認 │ 起動メタデータの更新 │ MCUをリセット │ ブートローダーが新しいイメージを選択する │ アプリケーションへジャンプ それともNXPは別のアプローチを推奨しているのでしょうか? 8. AB_SWAPとカスタムブートローダーの比較 S32K342で本番環境のFOTAを実施する場合、HSE AB_SWAPは必須ですか? それとも、デュアルアプリケーションスロットを備えた完全カスタムブートローダーもサポートされ、一般的に使われるアーキテクチャなのでしょうか? もしFOTA、UARTファームウェアアップデート、デュアルイメージブートローダーに関するアプリケーションノート、参考プロジェクト、ブートローダーの例、またはドキュメントなど、S32K342を網羅したものがあれば、ぜひご参考いただけると幸いです。 ごサポートありがとうございます。 S32K3 S32DS-ARM  Re: S32K342 FOTA Bootloader Architecture Guidance Required (UART-Based Update) こんにちは、 @bavinkumar_02さん 1.S32K342のCASE、AB_SWAPには一つのセットアップしか考えられません。「3.5.3.2」を参照HSE FirmwareリファレンスマニュアルのAB_SWAP」に掲載されたフラッシュメモリのレイアウトのイラストは、ドキュメントからダウンロード可能です -> Secure files: https://www.nxp.com/products/S32K3 あなたのCASE、最も便利で一般的なレイアウトは以下の通りです: HSEファームウェアのAB_SWAPバージョンをインストールする必要があります(スワップはHSEの機能であり、HSEファームウェアなしでは実行できません)。ファームウェアは両方のパーティションにインストールされており、図に示すように、両方のブロックで最後の176KBを占有しています。 ブロック全体が交換されるため、両方のブロックにブートローダーの正確なコピーが存在する必要がある。残りはアプリケーションに割り当てられます。 コードは常にアクティブブロックから動作しているため、ブートローダーやすべてのアプリケーションはアクティブブロック内のアドレスに合わせてコンパイルされます。 ブートローダーがアプリケーションを更新すると、そのアプリケーションは受動的なブロックにプログラムされるため、フラッシュプログラミング中の読み書き問題はありません。アプリケーションがプログラムされると、HSEサービスをHSE_SRV_ID_ACTIVATE_PASSIVE_BLOCK発動CAN。次回リセット後、パーティションはスワップされ、ブートローダーは通常通りアプリケーション(現在アクティブなブロックにある新しいアプリケーション)にジャンプします。 2. フローはアプリケーションに依存します。現代の自動車用途では、単純なCRCベースの検証はもはや十分とはみなされていません。ソフトウェアの整合性と真正性は通常、セキュアブート機構によって保証されます。S32K3デバイスでは、これはハードウェアセキュリティエンジン(HSE)によって処理され、暗号学的検証(例:署名ベース)ブート中に自律的に実行されます。量産型自動車システムは、CRCのみの検証に頼るのではなく、これらのハードウェアによるセキュリティ機能を活用することが期待されています。 セキュアブートのアプリケーションノート(デモプロジェクトを含む)を提供しています。ダウンロード可能: https://www.nxp.com/products/S32K3 アプリケーションノートはこちらでご覧いただけます: ドキュメント -> Secure Files -> Secure Boot アプリケーションノート v0.1.1.0(AN744511) 関連するデモプロジェクトはこちらからダウンロードできます: デザインリソース - > ソフトウェア - > Secure Files - > SecureBootAppNoteDemo(SW745310) セキュアブートの他の例はHSEデモ例で見ることができます: https://www.nxp.com/webapp/Download?colCode=S32K3_HSE_DemoExamples 3つのモードすべてに例があります — 高度なセキュアブート、ベーシックセキュアブート、そしてSHEセキュアブートです。高度なセキュアブートを推奨します。 すべてのプロジェクトに含まれている Readme.md ファイルを参照してください。 3. はい、それは標準的なジャンプシーケンスです。ジャンプする前に、ブートローダーによって初期化されたすべてのリソースを初期化解除することを強くお勧めします。 4. 前述の通り、コードは常にアクティブパーティションから実行されるため、アプリケーションは常に同じリンカーファイルを使用します。 5. 前述の内容です。 6.これはユーザー次第です。アプリケーションイメージの背後やデータフラッシュの背後にデータを保存できます。 7. 量産オートモーティブCASEユースケースでは、提案されたフローはデータ転送の観点から一般的に正しいですが、前述の通りCRCを主な検証メカニズムとして利用することはお勧めしません。 オートモーティブ用途では、受信画像は通常暗号的に保護されており、例えば画像は暗号化され、その真正性や完全性はCRCだけでなくデジタル署名によって検証されます。 また、HSE AB_SWAP機構を使用する場合、ブートローダーはリセット後にソフトウェアのメタデータで新しいイメージを選択するわけではありません。新しいイメージがパッシブパーティションにプログラムされ、正常に検証された後、アプリケーション/ブートローダーはHSEサービスHSE_SRV_ID_ACTIVATE_PASSIVE_BLOCKを呼び出します。これによりパッシブブロックが有効化され、リセット後は新たに起動したパーティションからデバイスが起動します。 8. HSE AB_SWAPは厳密に必須ではありませんが、S32K342の量産オートモーティブFOTAソリューションには強く推奨されます。 HSEなしでFOTAを導入すると、S32K3プラットフォームの主要な利点の一つを活かせないことになります。これらのデバイスの主な利点は、HSEが処理するA/Bスワップ(パーティションリマッピング)の組み込みサポートです。それがなければ、ブートローダーはすべてを手動で管理しなければならないだろう。 具体的には、HSE AB_SWAPなしの場合: A/B画像の選択には独自の仕組みを実装する必要があります アドレス空間を慎重に管理し、各アプリケーションを異なる固定場所にリンクする必要があります 画像の交換はハードウェアが自動的に行うのではなく、完全にソフトウェア内で行われます HSE ABスワップ機能以外に利用可能な代替ハードウェア対応のリマッピング機構はありません さらに、AB_SWAPと統合されたセキュアブートのシンプルさと堅牢性が失われます。HSEでは、画像の有効化、検証、パーティション間の切り替えが自動車のセキュリティ要件に沿った、より管理的かつ効率的に処理されます。 まとめると、HSEなしでこれを行うことは可能ですが、複雑さが大幅に増し、プラットフォームの重要な利点を失ってしまいます。 「S32K3XX HSE and OTA Advance トレーニング [TR744101]」はダウンロード可能です。ドキュメント - > Secure ファイル: https://www.nxp.com/products/S32K3 よろしくお願いいたします。 ルーカス
查看全文
S32K358 + FS2633:MCU组装完成后,RSTB保持低电平;连接JTAG后,RSTB变为高电平。 我正在使用S32K358和FS2633 。当我只测试 FS2633 部分(移除 MCU)时, RSTB 被释放(高电平) ,并且3.3V 电源轨存在。 组装好 MCU 和所有元器件后, RSTB 保持低电平,MCU 无法启动。 如果我连接JTAG 调试器, RSTB 变为高电平,我可以成功地对 MCU 进行编程,应用程序也能正常运行。但是,一旦我断开 JTAG, RSTB 就会再次变为低电平,MCU 就会停止运行。 一个观察结果是, FS2633 RSTB 输出为 3.3 V 信号,而我的板上的 S32K358 RESET 线被拉高至 5 V。尽管存在这种电压差,但只要连接 JTAG 调试器,系统就能正常工作。RESET电压等级或调试器是否会影响RESET或上电顺序? 这个问题是否与上电顺序、RESET 时序、FS2633 启动配置或调试器相关行为有关?有没有人遇到过类似的问题?或者有什么调试建议吗? Re: S32K358 + FS2633: RSTB stays LOW with MCU assembled, but goes HIGH when JTAG is connected 你最好尝试将FS2633 RSTB 的电压拉高到 3.3V 进行测试,看看是否存在这个问题。
查看全文
Winbond W664GG6RB-06 的 IMX-8M-MINI DDR 控制器时序 你好, 我们正在寻找 DDR4 时序设置不工作的原因。简而言之, DDR工具生成的时序数据通过了校准和压力测试,但导致了 Linux 内核在启动过程中偶尔崩溃,并出现“未定义指令”错误。 基本情况(原始数据): - 该SoC为i.MX8M Mini Solo(单核Cortex-A53),DDR4(Winbond W664GG6RB-06)。 1200 MHz (DDR4-2400),采用 1:2 DFI (DDR PHY 接口) 频率比模式,具有 单 x16 4 Gb 设备(512 MB,无 ECC)。 - 电路板支持包为 NXP L4.14.98_2.0.0(Linux 4.14.98,U-Boot 2018.03);DDR 配置为 使用 MSCALE DDR Tool v3.31(Windows 版本)和 PHY 训练固件生成 v201709。Yocto 也使用相同的固件来构建 U-Boot 启动映像。 我们正在为三条可互换的 4Gb x16 DDR4 内存条验证一套通用的时序集。 部件(Alliance AS4C256M16D4、ISSI IS43QR16256B、Winbond W664GG6RB-06),全部运行 频率为 1200 MHz。 - 为了满足最慢部件(Winbond)的 tRCD/tRP/tAA 要求(在 2400 像素档位下约为 14.16 ns),我们 设置 CL=17 (17-17-17),该工具将其编码为 MR0 = 0x0864,并与之匹配。 CL衍生寄存器(例如)DFITMG0 = 0x038C8207,DRAMTMG2 = 0x0609050D)。 - 动态随机存取存储器(DRAM) 以静态模式运行在 2400 设定点(设备中已禁用 DVFS/总线频率)。 因此,Linux 在运行时不会进行频率缩放。 观察结果: - 17-17-17 配置通过了 DDR 工具压力测试(约 24 小时)和 U-Boot mtest(约 1 小时)测试。 没有错误。 - 在 Linux 系统下(启动到 shell 提示符时),它也能通过 stressapptest+ 测试。 fio(经 crc32c 验证),即使在 Tj = 84 °C 下,也能持续超过一小时。 数据无错误。 然而,Linux 在启动过程中偶尔会崩溃,并显示“内部错误: 未定义的指令”(内核.text文件损坏),内核运行约 1.1 秒后,大约 5-7% 的冷启动(通过自动冷启动循环测量)。 - 该故障与芯片无关:CL=17 映像在一秒钟内以相同的方式崩溃 这些部分(ISSI),而 CL=16 镜像可以在同一个 ISSI 上可靠地启动 Linux。 部分。 - 两种 even-CL 配置都能可靠地启动 Linux:16-16-16(我们长期使用的生产环境配置) 时序)以及新版本的 18-18-18 内核(未观察到内核崩溃)——仅奇数 CL 17-17-17 失败。 - 故障配置和正常工作配置之间只有 CL 衍生寄存器不同 (MR0) CAS 位,DFITMG0 dfi_t_rddata_en,DRAMTMG2 读取延迟 / rd2wr,DFITMG2 rdcslat, ODTCFG rd_odt_delay)。 假设: 我们怀疑1:2 DFI比率下异常的CAS延迟是根本原因:读取数据 DFI 时钟的返回延迟为 CL/2——对于 CL=17,返回延迟为非整数 8.5,而对于整数 8.0,返回延迟为 8.0。 / CL=16 时为 9.0 / 18。由于读取 FIFO(由 DQS 写入,由控制器读取) 时钟(参考手册 §9.3.2.2.2)处理稳态和稳态应力 我们怀疑,边缘性会在读取突发到突发转换时显现出来,其中 奇怪的 CL 的半个 DFI 时钟偏移会触发 RM 不会触发的首尾节拍极端情况。 文档。 问题: 异常CAS延迟(例如)i.MX8M Mini DDR4 PHY 支持 CL=17,采用 1:2 DFI 模式。 模式,或者对于奇数CL是否存在已知的限制/勘误?特别是——DDR能否做到这一点 该工具生成了一种特殊的CL配置,虽然它通过了自身的压力测试,但性能却很差。 在实际启动流量下,是否有推荐的方法来限制读取操作? 奇数 CL 的突发间时序? 附件:内核崩溃控制台转储文件,CL=17 .dsDDR 工具的脚本,以及 生成了 ddr4_timing.c。 任何建议都将不胜感激。 Re: IMX-8M-MINI DDR Controller timings for Winbond W664GG6RB-06 抱歉,附件不知为何没有上传成功。以下是它们。 Re: IMX-8M-MINI DDR Controller timings for Winbond W664GG6RB-06 你好, 请尝试将 CL 值从 17 改为18,运行 DDR 测试并再次测试您的 Linux 系统,我建议您升级到更新的版本。 Re: IMX-8M-MINI DDR Controller timings for Winbond W664GG6RB-06 请检查以下各部分的时序参数,包括 CAS 延迟 tRCD(ns) 和 tRP(ns)。 Alliance AS4C256M16D4 DDR4-2400 17 14.1614.16 ISSI IS43QR16256B 2400Mbps 16-16-16 (-083R) Winbond W664GG6RB-06 DDR4-2400 17-17-17 IS43QR16256B 的第 3 个参数不同。所以您可能需要为这 3 个部分分别设置不同的参数,而不是使用一个参数来控制所有 3 个部分。看来这个问题只在冷启动时出现,对吗?
查看全文
IMX-8M-MINI DDR Controller timings for Winbond W664GG6RB-06 Hello, We are looking for an explanation for a non-working DDR4 timing set. In short, the timings generated by the DDR Tool passed calibration and stress tests, but led to sporadic Linux kernel crashes during boot, with an "undefined instruction" error. Setup (raw facts): - The SoC is an i.MX8M Mini Solo (single Cortex-A53), DDR4 (Winbond W664GG6RB-06) at 1200 MHz (DDR4-2400) in 1:2 DFI (DDR PHY Interface) frequency-ratio mode, with a single x16 4 Gb device (512 MB, no ECC). - The BSP is NXP L4.14.98_2.0.0 (Linux 4.14.98, U-Boot 2018.03); the DDR config was generated with MSCALE DDR Tool v3.31 (Windows version) and PHY training firmware v201709. The same firmware is used in Yocto to build the U-Boot image. - We are qualifying one common timing set for three interchangeable 4 Gb x16 DDR4 parts (Alliance AS4C256M16D4, ISSI IS43QR16256B, Winbond W664GG6RB-06), all operated at 1200 MHz. - To meet the slowest part's (Winbond) tRCD/tRP/tAA (~14.16 ns at the 2400 bin) we set CL=17 (17-17-17), which the Tool encodes as MR0 = 0x0864 with the matching CL-derived registers (e.g. DFITMG0 = 0x038C8207, DRAMTMG2 = 0x0609050D). - The DRAM runs static at the 2400 setpoint (DVFS/busfreq disabled in the device tree), so there is no frequency scaling by Linux at runtime. Observations: - The 17-17-17 config passes the DDR Tool stress test (~24 h) and U-Boot mtest (~1 h) with no errors. - Under Linux (on boots that reach the shell prompt) it also passes stressapptest + fio (crc32c-verified), continuously and even at Tj = 84 °C, for over an hour with zero data errors. - Nevertheless, Linux sporadically crashes during boot with "Internal error: undefined instruction" (corrupted kernel .text), ~1.1 s into the kernel, on roughly 5–7 % of cold boots (measured with an automated cold power-cycle loop). - The failure is die-independent: the CL=17 image crashes the same way on a second of these parts (ISSI), while the CL=16 image boots Linux reliably on that same ISSI part. - Both even-CL configs boot Linux reliably: 16-16-16 (our long-standing production timing) and a newly built 18-18-18 (no kernel crashes observed) — only the odd-CL 17-17-17 fails. - Only the CL-derived registers differ between the failing and working configs (MR0 CAS bits, DFITMG0 dfi_t_rddata_en, DRAMTMG2 read latency / rd2wr, DFITMG2 rdcslat, ODTCFG rd_odt_delay). Hypothesis: We suspect odd CAS latency at the 1:2 DFI ratio is the root cause: the read-data return latency is CL/2 in DFI clocks — a non-integer 8.5 for CL=17 versus integer 8.0 / 9.0 for CL=16 / 18. Since the read FIFO (written by DQS, read by the controller clock, Reference Manual §9.3.2.2.2) handles the steady state and steady stress passes, we suspect the marginality surfaces at read burst-to-burst transitions, where odd CL's half-DFI-clock offset would hit a first/last-beat edge case the RM does not document. Questions: Is odd CAS latency (e.g. CL=17) supported on the i.MX8M Mini DDR4 PHY in 1:2 DFI mode, or are there known constraints/errata for odd CL? In particular — can the DDR Tool produce an odd-CL configuration that passes its own stress test yet is marginal under real boot traffic, and is there a recommended way to constrain read burst-to-burst timing for odd CL? Attached: kernel crash console dump, the CL=17 .ds script for the DDR Tool, and the produced ddr4_timing.c. Any advice will be appreciated. Re: IMX-8M-MINI DDR Controller timings for Winbond W664GG6RB-06 Sorry, somehow attachments didn't attach. Here are they. Re: IMX-8M-MINI DDR Controller timings for Winbond W664GG6RB-06 Hello,  Please try again by modifying from CL=17 to CL=18, run ddr test and test your linux again, I recommend you to upgrade to a newer release.  Re: IMX-8M-MINI DDR Controller timings for Winbond W664GG6RB-06 Please check the timing parameter for the parts below for  CAS Latency   tRCD(ns)  tRP(ns) Alliance AS4C256M16D4     DDR4-2400                                             17      14.16   14.16 ISSI IS43QR16256B                   2400Mbps                                            16-16-16 (-083R) Winbond W664GG6RB-06  DDR4-2400                                            17-17-17 The 3 parameter for IS43QR16256B is different. So you may need dedicated setting for 3 parts instead using one setting for all 3 part. It seems the issue only happened at cold boots, right?
查看全文
[Zephyr ® Series] Part 4: Overview and Practical Applications of Kconfig and Device Trees (Japanese Blog)   From this point on, we'll be moving on to the advanced topics of Zephyr. This session will cover an overview of Kconfig and device trees, followed by hands-on programming exercises to help you utilize them effectively.   One of the key features of Zephyr RTOS, as mentioned previously, is its software scalability (reusability), which makes it easy to reuse software developed once in other projects or derivative products, enabling rapid development.   Furthermore, to support a wide range of hardware platforms, Zephyr employs a powerful configuration system called "Kconfig" and "Devicetree".   This allows you to port programs to different microcontroller boards simply by changing configuration files, without having to rewrite the source code in the same C/C++ language. This article explains the basic mechanisms of Kconfig and the device tree. As a practical application, we will modify the hardware-independent LED blinking program created in Part 3 to run on two different microcontroller boards: " FRDM-MCXA153 " and " FRDM-MCXN947 ".   To run the same application on different boards (microcontrollers and processors), we will explain practical programming methods using Kconfig and the device tree.     table of contents   Preparation Kconfig Basics Device tree fundamentals Best practices for improving software reusability Kconfig and the Device Tree in Practice Create a simple program (hands-on) 1. Program Specifications 2. Directory structure 3. Create Kconfig and prj.conf 4. Creating device tree overlays and board-specific settings 5. Hardware-independent common code (main.c) Create 6. Build and run summary Preparation   Hardware preparation   This article will primarily use the following boards to create and test programs. FRDM-MCXA153 (main use) Additionally, the following boards will be used as supplementary tools to verify the portability of the program you have created. FRDM-MCXN947   SW preparation   This guide assumes that you have already set up the Zephyr development environment (Zephyr SDK, West command, etc.). If you haven't set it up yet, please refer to the second article on environment setup. [Zephyr ® Series] Part 2: First Build and Testing (Japanese Blog)   We will be using the LED blinking program created in the third installment of the Zephyr series. If you haven't created it yet, we recommend creating it by referring to the previous article. [Zephyr ® Series] Part 3: First Steps in Blinking an LED and Software Reusability (Japanese Blog)   Kconfig Basics     Kconfig is a configuration system also used in the Linux kernel. In Zephyr, it is used to manage whether to "enable or disable" software features, or "what parameters to set," such as kernel functions, device drivers, subsystems, and application-specific settings. The following two files are important for Kconfig: The "Kconfig" file defines the selectable configuration items (symbols), their default values, and dependencies. "prj.conf" file *: This file is where application developers specify the values they want to set for items defined in "Kconfig" (such as enabling them with "y" or providing specific numerical values). Using Kconfig, you can exclude unnecessary code from compilation and optimize memory usage. Furthermore, the Kconfig and prj.conf files are all written in text format. How to enable the feature The prj.conf file enables features for the entire project. For example, the ADC, DAC, and OPAMP drivers are defined in Kconfig. When using the functions defined in Kconfig, you declare them by adding "CONFIG_" to the beginning of prj.conf. Kconfig:ADCの定義Kconfig: ADC definition prj.conf例prj.conf example   Device tree fundamentals   Devicetree例Example of a device tree   The device tree is a text file that describes what hardware (CPU, memory, peripherals, pin settings, etc.) a microcontroller supports, as well as the settings and configuration of that hardware. These settings and configurations are then expanded into macros.   Instead of directly writing hardware addresses into C code (hardcoding), information described in the device tree can be read through Zephyr macros, enabling hardware-independent programming. Nodes and Properties: Each element of hardware is represented as a "node" in a hierarchical structure, and register addresses, interrupt numbers, etc., are described as "properties." ".dts" and ".dtsi": Standard hardware configurations for each microcontroller and board are predefined within the Zephyr repository in ".dts" (Devicetree Source) and ".dtsi" (Include) files. dts: Described as the device tree of the board. dtsi: Describes the device tree of an SoC/microcontroller and is provided by the device manufacturer. ".overlay" file: This file is created when you want to override application-specific wiring (e.g., connecting an LED to a specific GPIO pin) or default settings.   Best practices for improving software reusability   To enhance software reusability in Zephyr, it is important to follow the following design principles: Separation of hardware-dependent and hardware-independent parts: C code (`main.c`) For example, avoid directly writing about specific microcontroller register operations or pin numbers. Leverage device tree aliases: Instead of directly referencing actual hardware nodes (e.g., `&red_led` or `&gpioa`), applications should reference abstract names defined in the `aliases` node (e.g., `led0`). This allows you to adapt to different boards simply by changing what the alias points to. Prepare a board-specific device tree (overlay) : When there are differences in some functions, such as in derivative products, you can overwrite (overlay) only the parts with hardware differences for each board. Switching features with Kconfig : Application behavior parameters and the on/off status of specific features are controlled using Kconfig symbols instead of C language "#define".   Kconfig and the Device Tree in Practice   From here, we will learn how to use Kconfig and the device tree by creating a simple program so that we can actually use them in practice .     Create a simple program (hands-on) The program will be created by modifying the LED blinking program we created last time, and will have the following specifications.   Here, as a practical exercise, we will create a common application that runs on both "FRDM-MCXA153" and "FRDM-MCXN947". 1. Program Specifications Source code : Use the code from "Part 3: Your First LED Blinking Program" and make the following modifications. LED blinking speed: The blinking interval can be set using Kconfig. Button Function (Enable/Disable): The button function can be enabled or disabled via Kconfig settings. When enabled, pressing the button will toggle between blinking and constant illumination of the LED. Outputting board name: At startup, the "device (board) name" configured in Kconfig will be output to standard output (terminal). 2. Directory structure   The project directory structure should be as follows:   Add the Kconfig file and boards folder to the "my_hello" folder of the LED blinking program you created last time. Any method of adding the files is fine. On Windows, use the PowerShell `ni` command or a text editor to create a new file and save it in the `my_hello` folder. In Linux, you can create a new, empty file using the `touch` command.   The files under "boards/" handle hardware differences and unique settings specific to each board.     my_hello/ ├── CMakeLists.txt ├── Kconfig <- 新規追加:アプリ独自のKconfig ├── prj.conf <- アプリの共通設定 ├── src/ │ └── main.c <- ハードウェア非依存の共通コード └── boards/ <- 新規作成フォルダ  ├── frdm_mcxa153.overlay <- 新規作成:FRDM-MCXA153用のデバイスツリー設定  ├── frdm_mcxa153.conf <- 新規作成:FRDM-MCXA153用のKconfig設定  ├── frdm_mcxn947_cpu0.overlay <- 新規作成:FRDM-MCXN947用のデバイスツリー設定  └── frdm_mcxn947_cpu0.conf <- 新規作成:FRDM-MCXN947用のKconfig設定   Note : By creating specific files within your application's directory, Zephyr's build system (West) will automatically recognize them and apply the settings. Adding Kconfig: You can add your own configuration symbols by placing a "Kconfig" file in your Applications folder. Board-specific settings ("boards/" directory): By creating a "boards" directory within your application and placing "[board name].overlay" or "[board name].conf" files there, the overlay and Kconfig overrides will be automatically applied only when building with that board as the target.   3. Create Kconfig and prj.conf First, create your own "Kconfig" in the application root directory and define application-specific parameters. my_hello/Kconfig   mainmenu "my LED blink" config CUSTOM_BLINK_RATE_MS int "LED blink rate in milliseconds" default 1000 help Set LED blink frequency. #LEDの点滅周期(ミリ秒)を設定します config ENABLE_BUTTON_TOGGLE bool "Enable button to toggle LED state" default y help Enable button to toggle LED state. # ボタン入力によるLEDの点滅/点灯状態>の切り替え機能を有効にします。 config BOARD_NAME_STRING string "Board Name String" default "Unknown Board" help Set board name for printf. # 標準出力に表示するボード名を設定します。 source "Kconfig.zephyr"     Next, as a common setting for the entire application, there is "prj.conf". This will be written. In this prj.conf file, use the Kconfig symbol you just created to configure it as follows: my_hello/prj.conf   # GPIOの有効化 CONFIG_GPIO=y # アプリケーションの共通設定 CONFIG_CUSTOM_BLINK_RATE_MS=500 CONFIG_ENABLE_BUTTON_TOGGLE=y   4. Creating device tree overlays and board-specific settings Create a directory called "boards" and prepare the necessary files for each board. Main board for FRDM-MCXA153     We map the button on the board (`sw2`) so that it can be accessed from the application using the standard alias `sw0`. `led0` is already in the board definition so it can be omitted here, but it can be explicitly overridden if needed.   my_hello/boards/frdm_mcxa153.overlay / { aliases { sw0 = &user_button_2; /* FRDM-MCXA153のユーザーボタン */ }; };   my_hello/boards/frdm_mcxa153.conf   CONFIG_BOARD_NAME_STRING="FRDM-MCXA153 Board"   By referencing the symbols in this .conf (board-specific Kconfig) within the application (main.c), it becomes possible to output the board name to standard output using the printf function. For FRDM-MCXN947 Similarly, we define "sw0" in the FRDM-MCXN947. This handles any differences in the hardware names of the buttons.   In fact, if the hardware names (which differ depending on the peripheral or instance) vary across boards, you assign the actual hardware to the alias node in the device tree. my_hello/boards/frdm_mcxn947_cpu0.overlay   / { aliases { sw0 = &user_button_3; /* FRDM-MCXN947のユーザーボタン */ }; };   my_hello/ boards/frdm_mcxn947_cpu0.conf   I'll try overriding the LED blinking speed to 250ms only when building with MCXN947.   CONFIG_BOARD_NAME_STRING="FRDM-MCXN947 Board" CONFIG_CUSTOM_BLINK_RATE_MS=250 The application code is the same for FRDM-MCXA153 and FRDM-MCXN947, but you can configure the blinking behavior of the LED separately here. 5. Hardware-independent common code (main.c) Create Write the following in "my_hello/src/main.c":   The LED control section reuses the hardware-independent code (using the "led0" alias) created in the previous article, and incorporates Kconfig and button control into it. my_hello/ src/main.c   #include #include #include /* Devicetreeのエイリアスを参照する */ /* どのボードでも、一番目のLEDは通常 "led0" と定義されています */ #define LED0_NODE DT_ALIAS(led0) #define SW0_NODE DT_ALIAS(sw0) /* エイリアスからGPIO仕様(ポート、ピン、フラグ)を取得 */ static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); /* ボタン機能がKconfigで有効化されている場合のみコンパイルされる部分 */ #ifdef CONFIG_ENABLE_BUTTON_TOGGLE static const struct gpio_dt_spec sw = GPIO_DT_SPEC_GET(SW0_NODE, gpios); static struct gpio_callback button_cb_data; static bool is_blinking = true; void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { is_blinking = !is_blinking; if (!is_blinking) { /* 点滅オフ時はLEDを点灯させた状態にする */ gpio_pin_set_dt(&led, 1); } } #endif //CONFIG_ENABLE_BUTTON_TOGGLE int main(void) { int ret; /* Kconfigで設定されたボード名を出力 */ printf("Starting application on %s\n", CONFIG_BOARD_NAME_STRING); /* デバイスの準備確認 */ if (!gpio_is_ready_dt(&led)) { return -1; } /* ピンの設定 (Devicetreeで定義された初期状態などを考慮して設定) */ ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); if (ret < 0) { return -1; } #ifdef CONFIG_ENABLE_BUTTON_TOGGLE if (!gpio_is_ready_dt(&sw)) { return -1; } ret = gpio_pin_configure_dt(&sw, GPIO_INPUT); if (ret < 0) { return -1; } ret = gpio_pin_interrupt_configure_dt(&sw, GPIO_INT_EDGE_TO_ACTIVE); if (ret < 0) { return -1; } gpio_init_callback(&button_cb_data, button_pressed, BIT(sw.pin)); gpio_add_callback(sw.port, &button_cb_data); #endif //CONFIG_ENABLE_BUTTON_TOGGLE while (1) { #ifdef CONFIG_ENABLE_BUTTON_TOGGLE if (is_blinking) { ret = gpio_pin_toggle_dt(&led); } #else /* ピンの状態を反転 (ボタン機能が無効な場合は常に点滅) */ ret = gpio_pin_toggle_dt(&led); #endif //CONFIG_ENABLE_BUTTON_TOGGLE /* Kconfigで設定された点滅間隔で待機 */ k_msleep(CONFIG_CUSTOM_BLINK_RATE_MS); } return 0; }     6. Build and run Now, let's actually test its functionality. Please refer to the previous article for instructions on setting up the build environment and enabling the west command. First, navigate to the directory of your installed zephyrproject repository as shown in the command instructions below, enable west, and then proceed. Operation confirmed with FRDM-MCXA153 (main) Build using the following command and write it to the FRDM-MCXA153.   ## ホームディレクトリからZephyrprojectディレクトリに移動 cd ~/zephyrproject ## west環境を有効化 source .venv/bin/activate ## zephyr v4.3をチェックアウトしていない場合は、前回(第3回 初めてのLチカとソフトウェアの再利用性)を参考にv4.3をチェックアウトしてください。 west build -b frdm_mcxa153 my_hello west flash     Execution result   コンソール出力Console output   LED点滅、点灯モード切り替えLED flashing and steady light mode switching   The message "Starting application on FRDM-MCXA153 Board" will appear in the terminal. The LED blinks at 500ms intervals ("prj.conf"). (Settings). Pressing SW2 ("custom-sw") will turn it on, and pressing it again will return it to blinking. Operation confirmed with FRDM-MCXN947 We'll build the project using the exact same C source code, only changing the board specification.   # -pオプションを使用し、frdm_mcxa153のビルド情報をクリーンしてビルドします。 west build -p -b frdm_mcxn947//cpu0 my_hello west flash   Execution result   The contents of "boards/frdm_mcxn947_cpu0.conf" will be automatically applied, and the terminal will display "Starting application on FRDM-MCXN947 Board". The LED blinks rapidly at 250ms intervals (configured in "prj.conf"). Pressing SW3 (the button mapped to "user_button_3" on the MCXN947) will similarly switch between LED illumination and blinking. While the FRDM-MCXA153 and FRDM-MCXN947 use different GPIOs for controlling LEDs and switch buttons, the device tree effectively absorbs these differences, demonstrating how cleanly the application program and hardware are separated.   summary     In this session, we learned the basics of Kconfig and device trees in Zephyr, and practiced techniques to separate hardware-dependent parts from C code by utilizing them.   I believe you've experienced a powerful mechanism for reusing the same source code across multiple different boards, where hardware settings are absorbed by the device tree overlay (".overlay"), application parameters can be flexibly changed and features can be easily enabled or disabled using board-specific Kconfig files (".conf").   ========================== 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 document provides an overview of the device tree and Kconfig, features designed to enhance Zephyr's software reusability. It then outlines the steps required to utilize these features in practice. After reading through this Zephyr series, from the first installment to the fourth, you will be able to write programs using the Zephyr RTOS. General Purpose Microcontrollers MCX Japanese Blog
查看全文
[Zephyr®シリーズ] 第4回 Kconfigとデバイスツリーの概要と実践的活用法 (日本語ブログ)   今回からZephyrの応用編に突入していきます。 今回は、Kconfigとデバイスツリーの概要とそしてそれを活用できるようハンズオンによるプログラミングの実践を行っていきます。   Zephyr RTOSの特徴として前回紹介したソフトウェアのスケーラビリティ(再利用性)により一度開発したソフトウェアを別のプロジェクトや派生製品に再利用することが容易に行えるようになり迅速な開発が可能になります。   そして、幅広いハードウェアプラットフォームに対応するために、Zephyrには「Kconfig」 と 「デバイスツリー (Devicetree)」 という強力な構成システムを採用しています。   これにより、同じC/C++言語のソースコードを書き換えることなく、設定ファイルの変更だけで異なるマイコンボードにプログラムを移植することができます。 本記事では、Kconfigとデバイスツリーの基本的な仕組みを解説します。そして実践的な活用法として、第3回で作成したハードウェアに依存しないLチカプログラムを修正して、それを「FRDM-MCXA153」と「FRDM-MCXN947」という異なるマイコンのボードで動作するようにします。   異なるボード(マイコンやプロセッサ)で同じアプリケーションを動作させるため、Kconfigとデバイスツリーを使って実践的プログラミング方法を説明していきます。     目次   前準備 Kconfigの基礎 デバイスツリー(Devicetree)の基礎 ソフトウェアの再利用性を高めるためのベストプラクティス Kconfigとデバイスツリーの実践 簡単なプログラムを作成する(ハンズオン) 1. プログラムの仕様 2. ディレクトリ構成 3. Kconfig と prj.conf の作成 4. デバイスツリーオーバーレイとボード別設定の作成 5. ハードウェア非依存の共通コード (main.c) の作成 6. ビルドと実行 まとめ 前準備   HWの準備   本記事では、主に以下のボードを使用してプログラムの作成と動作確認を行います。 FRDM-MCXA153 (メインで使用) また、作成したプログラムのポータビリティ(移植性)を確認するための補足として、以下のボードも使用します。 FRDM-MCXN947   SWの準備   Zephyrの開発環境(Zephyr SDK, Westコマンドなど)がすでに構築されていることを前提とします。構築がまだの場合は、第2回の環境構築の記事を参照してください。 [Zephyr® シリーズ] 第2回 はじめてのビルドと実機動作(日本語ブログ)   Zephyrシリーズ第3回で作成したLチカプログラムを使用します。まだ作成していない方は、前回の記事を参考に作成することをおすすめします。 [Zephyr® シリーズ] 第3回 初めてのLチカとソフトウェアの再利用性(日本語ブログ)   Kconfigの基礎     Kconfigは、Linuxカーネルでも採用されている設定システムです。Zephyrでは、カーネル機能、デバイスドライバー、サブシステム、アプリケーションの固有設定など、ソフトウェア機能を「有効にするか無効にするか」、あるいは「どのようなパラメータを設定するか」を管理するために使用されます。 Kconfigには以下2つのファイルが重要になります。 「Kconfig」 ファイル: 選択可能な設定項目(シンボル)とそのデフォルト値、依存関係を定義します。 「prj.conf」 ファイル*: アプリケーションの開発者が、「Kconfig」 で定義された項目に対して実際に設定したい値(「y」 で有効化、あるいは具体的な数値など)を記述するファイルです。 Kconfigを使用することで、不要なコードをコンパイルから除外し、メモリ使用量を最適化することができます。 そして、Kconfigやprj.confファイルはすべてテキストで記述されています。 機能を有効にする方法 prj.confファイルではプロジェクト全体に対して機能の有効化を行っています。 例えば、ADCとDAC、そしてOPAMPドライバはKconfigで定義されています。このKconfigで定義されている機能を利用する場合に、prj.confに「CONFIG_」を先頭に追加して宣言します。 Kconfig:ADCの定義Kconfig:ADCの定義 prj.conf例prj.conf例   デバイスツリー(Devicetree)の基礎   Devicetree例Devicetree例   デバイスツリーは、マイコンがどのようなハードウェア(CPU、メモリ、周辺機器、ピン設定など)に対応しているか、それらのハードウェアの設定や構成を記述するテキストファイルです。 そして、こられ設定や構成はマクロに展開されます。   C言語のコードの中にハードウェアのアドレスを直接書き込む(ハードコーディングする)代わりに、デバイスツリーに記述された情報をZephyrのマクロを通じて読み込むことで、ハードウェア非依存のプログラミングが可能になります。 ノードとプロパティ: ハードウェアの各要素は「ノード」として階層構造で表現され、レジスタアドレスや割り込み番号などが「プロパティ」として記述されます。 「.dts」 と 「.dtsi」: マイコンやボードごとの標準的なハードウェア構成は 「.dts」 (Devicetree Source) や 「.dtsi」 (Include) ファイルでZephyrリポジトリ内にあらかじめ定義されています。 dts: ボードのデバイスツリーとして記述 dtsi: SoC・マイコンのデバイスツリーとして記述され、デバイスメーカーから提供されます。 「.overlay」 ファイル: アプリケーション固有の配線(例:特定のGPIOピンにLEDを繋いだ)や、標準設定に対して上書きを行いたい場合に作成するファイルです。   ソフトウェアの再利用性を高めるためのベストプラクティス   Zephyrでソフトウェアの再利用性を高めるためには、以下の設計原則に従うことが重要です。 ハードウェア依存部分と非依存部分の分離: Cコード(`main.c` など)には、特定のマイコンのレジスタ操作やピン番号を直接書かないようにします。 デバイスツリーの「エイリアス」を活用する: アプリケーションからは、実際のハードウェアノード(例:「`&red_led`」 や 「`&gpioa`」)を直接参照するのではなく、「aliases(エイリアス)」 ノードで定義した抽象的な名前(例:「`led0`」など)を参照するようにします。これにより、ボードが変わってもエイリアスの指す先を変更するだけで対応できます。 ボード別デバイスツリー(オーバーレイ)を準備する :派生製品など一部の機能に違いがある場合に、ボード別にハードウェアの差分がある部分のみ上書き(オーバーレイ)することができます。 Kconfigによる機能の切り替え : アプリケーションの動作パラメータや特定の機能のオン・オフは、C言語の 「#define」 ではなく Kconfig シンボルを使用して制御します。   Kconfigとデバイスツリーの実践   ここから、実際に実践で使用できるようになるために簡単なプログラムを作成しながらKconfigとデバイスツリーの使い方を学んでいきます。     簡単なプログラムを作成する(ハンズオン) プログラムは、前回作成したLチカプログラムを変更して以下のような仕様のプログラムを作成します。   ここでは実践として、「FRDM-MCXA153」と「FRDM-MCXN947」の両方で動く共通アプリケーションを作成します。 1. プログラムの仕様 ソースコード: 「第3回 始めてのLチカプログラム〜」を利用し、以下修正を加える LEDの点滅速度: Kconfigを用いて点滅間隔を設定可能にする。 ボタン機能(機能の有効/無効化): Kconfigの設定により、ボタン機能の有効/無効を切り替えられるようにする。有効な場合は、ボタンを押すたびにLEDの「点滅」と「常時点灯」が切り替わる。 ボード名の出力: 起動時に標準出力(ターミナル)へ、Kconfigで設定した「デバイス(ボード)名」を出力する。 2. ディレクトリ構成   プロジェクトのディレクトリ構成を以下のようにします。   前回作成したLチカプログラムの「my_hello」フォルダにKconifgファイルやboardsフォルダを追加します。ファイルの追加はどのような方法でも問題ありません。 WindowsではPowerShellの`ni`コマンドやテキストエディターで「新規ファイル作成」をして、my_helloフォルダに保存してください。 LInuxでは、`touch`コマンドを使用することで空の新規ファイルを作成することが可能です。   「boards/」 以下のファイルによって、ボードごとのハードウェア差異や固有設定を吸収します。     my_hello/ ├── CMakeLists.txt ├── Kconfig <- 新規追加:アプリ独自のKconfig ├── prj.conf <- アプリの共通設定 ├── src/ │ └── main.c <- ハードウェア非依存の共通コード └── boards/ <- 新規作成フォルダ  ├── frdm_mcxa153.overlay <- 新規作成:FRDM-MCXA153用のデバイスツリー設定  ├── frdm_mcxa153.conf <- 新規作成:FRDM-MCXA153用のKconfig設定  ├── frdm_mcxn947_cpu0.overlay <- 新規作成:FRDM-MCXN947用のデバイスツリー設定  └── frdm_mcxn947_cpu0.conf <- 新規作成:FRDM-MCXN947用のKconfig設定   参考: アプリケーションのディレクトリ内に特定のファイルを作成することで、Zephyrのビルドシステム(West)は自動的にそれらを認識し、設定を適用します。 Kconfigの追加:  アプリケーションフォルダに 「Kconfig」 ファイルを置くことで、独自のコンフィグシンボルを追加できます。 ボードごとの設定 (「boards/」 ディレクトリ): アプリケーション内に 「boards」 ディレクトリを作成し、そこに 「[ボード名].overlay」 や 「[ボード名].conf」 を配置すると、そのボードをターゲットとしてビルドした時にのみ、自動的にオーバーレイやKconfigの上書きが適用されます。   3. Kconfig と prj.conf の作成 まず、アプリケーションルートに独自の 「Kconfig」 を作成し、アプリケーション専用のパラメータを定義します。 my_hello/Kconfig   mainmenu "my LED blink" config CUSTOM_BLINK_RATE_MS int "LED blink rate in milliseconds" default 1000 help Set LED blink frequency. #LEDの点滅周期(ミリ秒)を設定します config ENABLE_BUTTON_TOGGLE bool "Enable button to toggle LED state" default y help Enable button to toggle LED state. # ボタン入力によるLEDの点滅/点灯状態>の切り替え機能を有効にします。 config BOARD_NAME_STRING string "Board Name String" default "Unknown Board" help Set board name for printf. # 標準出力に表示するボード名を設定します。 source "Kconfig.zephyr"     次に、アプリケーション全体の共通設定として 「prj.conf」 を記述します。 このprj.confに先ほど作成したKconfigシンボルを使って以下のように設定します。 my_hello/prj.conf   # GPIOの有効化 CONFIG_GPIO=y # アプリケーションの共通設定 CONFIG_CUSTOM_BLINK_RATE_MS=500 CONFIG_ENABLE_BUTTON_TOGGLE=y   4. デバイスツリーオーバーレイとボード別設定の作成 「boards」ディレクトリを作成し、各ボードに向けたファイルを用意します。 FRDM-MCXA153用 (メインボード)     アプリケーションからは `sw0` という標準的なエイリアスでアクセスできるように、ボード上のボタン(`sw2`)をマッピングします。`led0` はすでにボード定義にあるためここでは省略できますが、必要に応じて明示的に上書きすることも可能です。   my_hello/boards/frdm_mcxa153.overlay / { aliases { sw0 = &user_button_2; /* FRDM-MCXA153のユーザーボタン */ }; };   my_hello/boards/frdm_mcxa153.conf   CONFIG_BOARD_NAME_STRING="FRDM-MCXA153 Board"   アプリケーション(main.c)内でこの.conf(ボード別Kconfig)のシンボルを参照して、printf関数でボード名を標準出力させることが可能になります。 FRDM-MCXN947用  FRDM-MCXN947でも同様に 「sw0」 を定義します。ボタンのハードウェア名が異なる場合でも、ここで吸収します。   実際、ボードによりハードウェア(ペリフェラルやインスタンスが異なる)名が異なる場合は、デバイスツリー内のエイリアスノードに実際のハードウェアを割当てます。 my_hello/boards/frdm_mcxn947_cpu0.overlay   / { aliases { sw0 = &user_button_3; /* FRDM-MCXN947のユーザーボタン */ }; };   my_hello/boards/frdm_mcxn947_cpu0.conf   MCXN947でビルドした時だけ、LEDの点滅速度を250msに上書き変更してみます。   CONFIG_BOARD_NAME_STRING="FRDM-MCXN947 Board" CONFIG_CUSTOM_BLINK_RATE_MS=250 FRDM-MCXA153とFRDM-MCXN947では、アプリケーションコードは同じですが、Lチカの点滅の挙動をここでそれぞれ設定することができます。 5. ハードウェア非依存の共通コード (main.c) の作成 「my_hello/src/main.c」を以下のように記述します。   LED制御部分は、前回の記事で作成したハードウェア非依存のコード(「led0」 エイリアスを使用)を再利用し、そこにKconfigとボタンの制御を組み込んでいます。 my_hello/src/main.c   #include #include #include /* Devicetreeのエイリアスを参照する */ /* どのボードでも、一番目のLEDは通常 "led0" と定義されています */ #define LED0_NODE DT_ALIAS(led0) #define SW0_NODE DT_ALIAS(sw0) /* エイリアスからGPIO仕様(ポート、ピン、フラグ)を取得 */ static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); /* ボタン機能がKconfigで有効化されている場合のみコンパイルされる部分 */ #ifdef CONFIG_ENABLE_BUTTON_TOGGLE static const struct gpio_dt_spec sw = GPIO_DT_SPEC_GET(SW0_NODE, gpios); static struct gpio_callback button_cb_data; static bool is_blinking = true; void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { is_blinking = !is_blinking; if (!is_blinking) { /* 点滅オフ時はLEDを点灯させた状態にする */ gpio_pin_set_dt(&led, 1); } } #endif //CONFIG_ENABLE_BUTTON_TOGGLE int main(void) { int ret; /* Kconfigで設定されたボード名を出力 */ printf("Starting application on %s\n", CONFIG_BOARD_NAME_STRING); /* デバイスの準備確認 */ if (!gpio_is_ready_dt(&led)) { return -1; } /* ピンの設定 (Devicetreeで定義された初期状態などを考慮して設定) */ ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); if (ret < 0) { return -1; } #ifdef CONFIG_ENABLE_BUTTON_TOGGLE if (!gpio_is_ready_dt(&sw)) { return -1; } ret = gpio_pin_configure_dt(&sw, GPIO_INPUT); if (ret < 0) { return -1; } ret = gpio_pin_interrupt_configure_dt(&sw, GPIO_INT_EDGE_TO_ACTIVE); if (ret < 0) { return -1; } gpio_init_callback(&button_cb_data, button_pressed, BIT(sw.pin)); gpio_add_callback(sw.port, &button_cb_data); #endif //CONFIG_ENABLE_BUTTON_TOGGLE while (1) { #ifdef CONFIG_ENABLE_BUTTON_TOGGLE if (is_blinking) { ret = gpio_pin_toggle_dt(&led); } #else /* ピンの状態を反転 (ボタン機能が無効な場合は常に点滅) */ ret = gpio_pin_toggle_dt(&led); #endif //CONFIG_ENABLE_BUTTON_TOGGLE /* Kconfigで設定された点滅間隔で待機 */ k_msleep(CONFIG_CUSTOM_BLINK_RATE_MS); } return 0; }     6. ビルドと実行 さて、実際に動作を確認してみます。ビルド環境セットアップやwestコマンド有効化については、前回の記事を参考にしてください。 まずは、下記のコマンド手順の様にインストールしているzephyrprojectリポジトリのディレクトリに移動し、west 有効化を行ってから進めます。 FRDM-MCXA153 での動作確認(メイン) 以下のコマンドでビルドし、FRDM-MCXA153に書き込みます。   ## ホームディレクトリからZephyrprojectディレクトリに移動 cd ~/zephyrproject ## west環境を有効化 source .venv/bin/activate ## zephyr v4.3をチェックアウトしていない場合は、前回(第3回 初めてのLチカとソフトウェアの再利用性)を参考にv4.3をチェックアウトしてください。 west build -b frdm_mcxa153 my_hello west flash     実行結果   コンソール出力コンソール出力   LED点滅、点灯モード切り替えLED点滅、点灯モード切り替え   ターミナルに 「Starting application on FRDM-MCXA153 Board」 と表示されます。 LEDは 500ms 間隔で点滅します(「prj.conf」 の設定)。 SW2(「custom-sw」)を押すと点灯状態になり、再度押すと点滅に戻ります。 FRDM-MCXN947 での動作確認 全く同じC言語のソースコードのまま、ボード指定だけを変えてビルドします。   # -pオプションを使用し、frdm_mcxa153のビルド情報をクリーンしてビルドします。 west build -p -b frdm_mcxn947//cpu0 my_hello west flash   実行結果   「boards/frdm_mcxn947_cpu0.conf」 の内容が自動的に反映され、ターミナルには 「Starting application on FRDM-MCXN947 Board」 と表示されます。 LEDは 250ms 間隔で速く点滅します(「prj.conf」の設定)。 SW3(MCXN947側のボタンにマッピングされた 「user_button_3」)を押すことでLED点灯、点滅動作が同様に切り替わります。 FRDM-MCXA153とFRDM-MCXN947では、LED制御しているGPIOやスイッチボタンに繋がっているGPIOが異なりますが、デバイスツリーによりその差分が吸収され、アプリケーションのプログラムとハードウェアがきれいに分離できていることが実感できたと思います。   まとめ     今回は、ZephyrにおけるKconfigとデバイスツリーの基本を学び、それらを活用してハードウェア依存部分をCコードから分離する手法を実践しました。   デバイスツリーのオーバーレイ(「.overlay」)によってハードウェア設定を吸収し、ボード別Kconfigファイル(「.conf」)によってアプリケーションのパラメータを柔軟に変更したり、機能を簡単に有効、無効にすることができ、同一のソースコードを複数の異なるボードで再利用する強力な仕組みを体験できたかと思います。   =========================​ 本投稿の「Comment」欄にコメントをいただいても、現在返信に対応しておりません。​ お手数をおかけしますが、お問い合わせの際には「NXPへの技術質問 - 問い合わせ方法 (日本語ブログ)」をご参照ください。​ (既に弊社NXP代理店、もしくはNXPとお付き合いのある方は、直接担当者へご質問いただいてもかまいません。)​ Zephyrのソフトウェア再利用性を高めるための特徴であるデバイスツリーとKconfigの概要を説明します。そして、それらを実践で利用するためにステップを踏んで説明していきます。 このぜZephyrシリーズ第1回から今回の第4回までを読み終えると、Zephyr RTOSを利用してプログラムが書けるようになります。 General Purpose Microcontrollers MCX 日本語ブログ
查看全文