- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8.2k
low cost power shield solution #95056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            hakehuang
  wants to merge
  6
  commits into
  zephyrproject-rtos:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
nxp-upstream:lc_power_shield
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      58e8b87
              
                samples: adc: add power measure application
              
              
                hakehuang 3cea842
              
                tests: scripts: add general power shield support
              
              
                hakehuang 9fdc552
              
                samples: boards: nxp: enable power shield on mimxrt595_evk
              
              
                hakehuang 0e8be3f
              
                tests: pm: power_mgmt_soc: enable measurement on rt1060
              
              
                hakehuang e3a957b
              
                testsuite: option: add power measure option to test
              
              
                hakehuang c35d54b
              
                tests: pm: power_residency_time: add power measure check
              
              
                hakehuang File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|  | ||
| cmake_minimum_required(VERSION 3.20.0) | ||
|  | ||
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(adc_power_measure) | ||
|  | ||
| target_sources(app PRIVATE src/main.c) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Copyright (c) 2024 Centro de Inovacao EDGE. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|  | ||
| config SEQUENCE_SAMPLES | ||
| int "Number of samples to be made on the sequence for each channel." | ||
| default 5 | ||
|  | ||
| config SEQUENCE_RESOLUTION | ||
| int "Set the resolution of the sequence readings." | ||
| default 12 | ||
|  | ||
| config SEQUENCE_32BITS_REGISTERS | ||
| bool "ADC data sequences are on 32bits" | ||
|  | ||
| config SHELL_ADC_PS | ||
| bool "ADC power shield shell" | ||
|  | ||
| source "Kconfig.zephyr" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| .. zephyr:code-sample:: adc_power_measure | ||
| :name: Analog-to-Digital Converter (ADC) power measurement sample | ||
| :relevant-api: adc_interface | ||
|  | ||
| Read analog inputs from ADC channels, using a sequence. | ||
|  | ||
| Overview | ||
| ******** | ||
|  | ||
| This sample is to used with general power harness to measure the power. | ||
|  | ||
|  | ||
| Supported platforms | ||
| =================== | ||
|  | ||
| See overlay files in the boards folder. | ||
|  | ||
| Building and Running | ||
| ******************** | ||
|  | ||
| Make sure that the ADC is enabled (``status = "okay";``) and has each channel as a | ||
| child node, with your desired settings like gain, reference, or acquisition time and | ||
| oversampling setting (if used). It is also needed to provide an alias ``adc0`` for the | ||
| desired adc. See :zephyr_file:`boards/frdm_mcxc444.overlay | ||
| <samples/drivers/adc/adc_power_measure/boards/frdm_mcxc444.overlay>` for an example of | ||
| such setup. | ||
|  | ||
| Building and Running for NXP frdm_mcxc444 | ||
| ========================================= | ||
|  | ||
| The sample can be built and executed for the | ||
| :zephyr:board:`frdm_mcxc444` as follows: | ||
|  | ||
| .. zephyr-app-commands:: | ||
| :zephyr-app: samples/drivers/adc/adc_power_measure | ||
| :board: frdm_mcxc444/mcxc444 | ||
| :goals: build flash | ||
| :compact: | ||
|  | ||
| To build for another board, change "frdm_mcxc444/mcxc444" above to that board's name | ||
| and provide a corresponding devicetree overlay. | ||
|  | ||
| Sample output | ||
| ============= | ||
|  | ||
| the output as below, repeated every time you input any char in the console or ``adc read`` when enable shell: | ||
|  | ||
| .. code-block:: console | ||
|  | ||
| ADC sequence reading [1]: | ||
| - ADC_0, channel 0, 5 sequence samples: | ||
| - - 36 = 65mV | ||
| - - 35 = 63mV | ||
| - - 36 = 65mV | ||
| - - 35 = 63mV | ||
| - - 36 = 65mV | ||
| - ADC_0, channel 1, 5 sequence samples: | ||
| - - 0 = 0mV | ||
| - - 0 = 0mV | ||
| - - 1 = 1mV | ||
| - - 0 = 0mV | ||
| - - 1 = 1mV | ||
|  | ||
| .. note:: If the ADC is not supported, the output will be an error message. | ||
|  | ||
| You should get similar output as below, if you input a return or ``adc status`` when enable shell: | ||
|  | ||
| .. code-block:: console | ||
|  | ||
| ==== start of adc features === | ||
| CHANNEL_COUNT: 4 | ||
| Resolution: 12 | ||
| channel_id 0 features: | ||
| - is single mode | ||
| - verf is 3300 mv | ||
| channel_id 3 features: | ||
| - is single mode | ||
| - verf is 3300 mv | ||
| channel_id 4 features: | ||
| - is single mode | ||
| - verf is 3300 mv | ||
| channel_id 7 features: | ||
| - is single mode | ||
| - verf is 3300 mv | ||
| ==== end of adc features === | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_ADC_MCUX_ADC16_VREF_ALTERNATE=y | 
        
          
          
            25 changes: 25 additions & 0 deletions
          
          25 
        
  samples/drivers/adc/adc_power_measure/boards/frdm_k64f.overlay
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Copyright 2024 NXP | ||
| */ | ||
|  | ||
| / { | ||
| aliases { | ||
| adc0 = &adc0; | ||
| }; | ||
| }; | ||
|  | ||
| &adc0 { | ||
| #address-cells = <1>; | ||
| #size-cells = <0>; | ||
|  | ||
| channel@1 { | ||
| reg = <1>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_VDD_1"; | ||
| zephyr,vref-mv = <3300>; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| zephyr,resolution = <16>; | ||
| }; | ||
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_ADC_MCUX_ADC16_VREF_ALTERNATE=y | 
        
          
          
            25 changes: 25 additions & 0 deletions
          
          25 
        
  samples/drivers/adc/adc_power_measure/boards/frdm_mcxc242.overlay
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Copyright 2024 NXP | ||
| */ | ||
|  | ||
| / { | ||
| aliases { | ||
| adc0 = &adc0; | ||
| }; | ||
| }; | ||
|  | ||
| &adc0 { | ||
| #address-cells = <1>; | ||
| #size-cells = <0>; | ||
|  | ||
| channel@1 { | ||
| reg = <1>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_VDD_1"; | ||
| zephyr,vref-mv = <3300>; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| zephyr,resolution = <12>; | ||
| }; | ||
| }; | 
        
          
          
            19 changes: 19 additions & 0 deletions
          
          19 
        
  samples/drivers/adc/adc_power_measure/boards/frdm_mcxc444.conf
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| CONFIG_ADC_MCUX_ADC16_VREF_ALTERNATE=y | ||
|  | ||
| CONFIG_SHELL_ADC_PS=y | ||
| CONFIG_SHELL=y | ||
| CONFIG_SHELL_MINIMAL=y | ||
| CONFIG_SHELL_STACK_SIZE=1024 | ||
| CONFIG_SHELL_BACKEND_SERIAL=y | ||
|  | ||
| # Power management | ||
| CONFIG_PM=n | ||
|  | ||
| # Memory protection | ||
| CONFIG_THREAD_STACK_INFO=n | ||
| CONFIG_THREAD_CUSTOM_DATA=n | ||
| CONFIG_FPU=n | ||
|  | ||
| # Boot | ||
| CONFIG_BOOT_BANNER=n | ||
| CONFIG_BOOT_DELAY=0 | 
        
          
          
            68 changes: 68 additions & 0 deletions
          
          68 
        
  samples/drivers/adc/adc_power_measure/boards/frdm_mcxc444.overlay
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Copyright 2024-2025 NXP | ||
| */ | ||
|  | ||
| / { | ||
| aliases { | ||
| adc0 = &adc0; | ||
| }; | ||
| }; | ||
|  | ||
| &pinctrl { | ||
| pinmux_adc0: pinmux_adc0 { | ||
| group0 { | ||
| pinmux = <ADC0_SE0_PTE20>, <ADC0_SE4a_PTE21>, | ||
| <ADC0_SE3_PTE22>, <ADC0_SE7a_PTE23>; | ||
| drive-strength = "low"; | ||
| slew-rate = "slow"; | ||
| }; | ||
| }; | ||
| }; | ||
|  | ||
| &adc0 { | ||
| #address-cells = <1>; | ||
| #size-cells = <0>; | ||
|  | ||
| /* | ||
| * To use this sample: | ||
| * - Connect ADC0 SE0 signal to voltage between 0~3.3V (J4 pin 1) | ||
| */ | ||
|  | ||
| channel@0 { | ||
| reg = <0>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_VDD_1"; | ||
| zephyr,vref-mv = <3300>; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| zephyr,resolution = <12>; | ||
| }; | ||
|  | ||
| channel@3 { | ||
| reg = <0x3>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_VDD_1"; | ||
| zephyr,vref-mv = <3300>; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| zephyr,resolution = <12>; | ||
| }; | ||
|  | ||
| channel@4 { | ||
| reg = <0x4>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_VDD_1"; | ||
| zephyr,vref-mv = <3300>; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| zephyr,resolution = <12>; | ||
| }; | ||
|  | ||
| channel@7 { | ||
| reg = <0x7>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_VDD_1"; | ||
| zephyr,vref-mv = <3300>; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| zephyr,resolution = <12>; | ||
| }; | ||
| }; | ||
        
          
          
            1 change: 1 addition & 0 deletions
          
          1 
        
  samples/drivers/adc/adc_power_measure/boards/mimxrt1040_evk.conf
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_SEQUENCE_RESOLUTION=12 | 
        
          
          
            34 changes: 34 additions & 0 deletions
          
          34 
        
  samples/drivers/adc/adc_power_measure/boards/mimxrt1040_evk.overlay
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright (c) 2024 Centro de Inovacao EDGE | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|  | ||
| / { | ||
| aliases { | ||
| adc0 = &adc1; | ||
| }; | ||
| }; | ||
|  | ||
| &adc1 { | ||
| #address-cells = <1>; | ||
| #size-cells = <0>; | ||
|  | ||
| /* | ||
| * To use this sample connect | ||
| * J33.1 (ADC1 CH3) and J33.2 (ADC1 CH4) to voltages between 0 and 3.3V | ||
| */ | ||
| channel@3 { | ||
| reg = <3>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_INTERNAL"; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| }; | ||
|  | ||
| channel@4 { | ||
| reg = <4>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_INTERNAL"; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| }; | ||
| }; | 
        
          
          
            1 change: 1 addition & 0 deletions
          
          1 
        
  samples/drivers/adc/adc_power_measure/boards/mimxrt595_evk_cm33.conf
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_SEQUENCE_RESOLUTION=12 | 
        
          
          
            46 changes: 46 additions & 0 deletions
          
          46 
        
  samples/drivers/adc/adc_power_measure/boards/mimxrt595_evk_cm33.overlay
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright (c) 2024 Centro de Inovacao EDGE | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|  | ||
| #include <zephyr/dt-bindings/adc/mcux-lpadc.h> | ||
|  | ||
| / { | ||
| aliases { | ||
| adc0 = &lpadc0; | ||
| }; | ||
| }; | ||
|  | ||
| &lpadc0 { | ||
| #address-cells = <1>; | ||
| #size-cells = <0>; | ||
|  | ||
| /* | ||
| * To use this sample: | ||
| * LPADC0 CH0A and CH0B are set up in differential mode (B-A) | ||
| * - Connect LPADC0 CH0A signal to voltage between 0~1.8V (J30 pin 1) | ||
| * - Connect LPADC0 CH0B signal to voltage between 0~1.8V (J30 pin 2) | ||
| * LPADC0 CH2A is set up in single ended mode | ||
| * - Connect LPADC0 CH2A signal to voltage between 0~1.8V (J30 pin 3) | ||
| */ | ||
|  | ||
| channel@0 { | ||
| reg = <0>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_EXTERNAL0"; | ||
| zephyr,vref-mv = <1800>; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| zephyr,input-positive = <MCUX_LPADC_CH0B>; | ||
| zephyr,input-negative = <MCUX_LPADC_CH0A>; | ||
| }; | ||
|  | ||
| channel@1 { | ||
| reg = <1>; | ||
| zephyr,gain = "ADC_GAIN_1"; | ||
| zephyr,reference = "ADC_REF_EXTERNAL0"; | ||
| zephyr,vref-mv = <1800>; | ||
| zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
| zephyr,input-positive = <MCUX_LPADC_CH2A>; | ||
| }; | ||
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_ADC=y | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.