How to use stm32pio - 10 common examples

To help you get started, we’ve selected a few stm32pio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_build(self):
        """
        Initialize a new project and try to build it
        """
        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})
        project.generate_code()
        project.pio_init()
        project.patch()

        self.assertEqual(project.build(), 0, msg="Build failed")
github ussserrr / stm32pio / tests / test_integration.py View on Github external
# Create test config
        config = configparser.ConfigParser(interpolation=None)
        config.read_dict({
            'project': {
                'platformio_ini_patch_content': config_parameter_user_value,
                'board': TEST_PROJECT_BOARD
            }
        })
        # ... save it
        with FIXTURE_PATH.joinpath(stm32pio.settings.config_file_name).open(mode='w') as config_file:
            config.write(config_file)

        # On project creation we should interpret the CLI-provided values as superseding to the saved ones and
        # saved ones, in turn, as superseding to the default ones
        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': cli_parameter_user_value}})
        project.pio_init()
        project.patch()

        # Actually, we can parse the platformio.ini via the configparser but this is simpler in our case
        after_patch_content = FIXTURE_PATH.joinpath('platformio.ini').read_text()
        self.assertIn(config_parameter_user_value, after_patch_content,
                      msg="User config parameter has not been prioritized over the default one")
        self.assertIn(cli_parameter_user_value, after_patch_content,
                      msg="User CLI parameter has not been prioritized over the saved one")
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
[test_section]
            key1 = value1
            key2 = 789
        ''')
        cli_parameter_user_value = 'nucleo_f429zi'

        # Create test config
        config = configparser.ConfigParser(interpolation=None)
        config.read_dict({
            'project': {
                'platformio_ini_patch_content': config_parameter_user_value,
                'board': TEST_PROJECT_BOARD
            }
        })
        # ... save it
        with FIXTURE_PATH.joinpath(stm32pio.settings.config_file_name).open(mode='w') as config_file:
            config.write(config_file)

        # On project creation we should interpret the CLI-provided values as superseding to the saved ones and
        # saved ones, in turn, as superseding to the default ones
        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': cli_parameter_user_value}})
        project.pio_init()
        project.patch()

        # Actually, we can parse the platformio.ini via the configparser but this is simpler in our case
        after_patch_content = FIXTURE_PATH.joinpath('platformio.ini').read_text()
        self.assertIn(config_parameter_user_value, after_patch_content,
                      msg="User config parameter has not been prioritized over the default one")
        self.assertIn(cli_parameter_user_value, after_patch_content,
                      msg="User CLI parameter has not been prioritized over the saved one")
github ussserrr / stm32pio / tests / test_cli.py View on Github external
def test_init(self):
        """
        Check for config creation and parameters presence
        """
        result = subprocess.run([PYTHON_EXEC, STM32PIO_MAIN_SCRIPT, 'init', '-d', str(FIXTURE_PATH),
                                 '-b', TEST_PROJECT_BOARD], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        self.assertEqual(result.returncode, 0, msg="Non-zero return code")

        self.assertTrue(FIXTURE_PATH.joinpath(stm32pio.settings.config_file_name).is_file(),
                        msg=f"{stm32pio.settings.config_file_name} file hasn't been created")

        config = configparser.ConfigParser(interpolation=None)
        config.read(str(FIXTURE_PATH.joinpath(stm32pio.settings.config_file_name)))
        for section, parameters in stm32pio.settings.config_default.items():
            for option, value in parameters.items():
                with self.subTest(section=section, option=option, msg="Section/key is not found in saved config file"):
                    self.assertIsNotNone(config.get(section, option, fallback=None))
        self.assertEqual(config.get('project', 'board', fallback="Not found"), TEST_PROJECT_BOARD,
                         msg="'board' has not been set")

stm32pio

Small cross-platform Python app that can create and update PlatformIO projects from STM32CubeMX .ioc files. It uses STM32CubeMX to generate a HAL-framework-based code and alongside creates PlatformIO project with compatible parameters to stick them both together. Both CLI and GUI editions are available

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis

Similar packages