.. |OLD_STACK_VER| replace:: |DEVICE| SDK 8.20
.. |NEW_STACK_VER| replace:: |DEVICE| SDK 8.40

|OLD_STACK_VER| to |NEW_STACK_VER|
==================================

This section will describe how to port a project from |OLD_STACK_VER| to
a |NEW_STACK_VER| project.

.. note:: Vulnerability reports and mitigations can be found on `Report potential product security vulnerabilities <https://www.ti.com/PSIRT>`_.

.. _ble-porting-sdk-8-40:

Porting Bluetooth LE Projects
-----------------------------

The recommended method for porting an existing project from |OLD_STACK_VER|
to |NEW_STACK_VER| is to modify the ProjectSpec file to import the project as
a |NEW_STACK_VER| project.

Porting by modifying the CCS ProjectSpec file (``.projectspec``) can be done
when a ProjectSpec file has been updated and maintained throughout the
project's development. All example projects included in the SDK each come with
their own ProjectSpec file. During development, the included ProjectSpec file
should be updated to match any changes or additions made to the project. This
will make a project more easily package-able and ease migration efforts when
future SDK's are released. For example, the ProjectSpec file of the basic_ble
project is located in
``{SDK_INSTALL_DIR}/examples/rtos/{BOARD}/ble5stack/basic_ble/freertos/ticlang``

The following steps will detail the changes needed when porting an out of the box
example from the SDK such as ``basic_ble``:

.. note:: This porting method might be more complex for customer specific projects. 
         The following steps are the minimum set of changes required to port a project from |OLD_STACK_VER| to |NEW_STACK_VER|.

1. Open the ProjectSpec file in a text editor and modify the product definition
   line to reflect the new SDK revision and the corresponding SysConfig revision.
   ``products="com.ti.SIMPLELINK_LOWPOWER_F3_SDK:x.xx.xx.xx;sysconfig:x.xx.x"``
   Also update line ``cgtVersion="TICLANG_x.x.x"`` if it exists in the file.
   Refer to the Dependencies section in the SDK release notes for the correct
   SysConfig (and compiler) version. The SDK release notes may be found in
   ``{SDK_INSTALL_DIR}/docs/simplelink_mcu_sdk/release_notes_coresdk_lpf3_x_xx_xx_xx.html``

2. In the ProjectSpec file, add the following line right before ``${CG_TOOL_ROOT}/bin/tiarmobjcopy -O ihex ${BuildArtifactFileName} ${BuildArtifactFileBaseName}.hex`` inside the ``postBuildStep`` section:

   * ``${COM_TI_SIMPLELINK_LOWPOWER_F3_SOURCE_SDK_INSTALL_DIR}/tools/common/crc_tool/crc_tool patch-image --elf ${BuildArtifactFileBaseName}.out --symbol-prefix ti_utils_build_GenMap_sym_CRC_CCFG -o ${BuildArtifactFileBaseName}.out;``

3. In the SysConfig file, the return behavior of the RNG must be modified
   within the Global Parameters tab of the RNG module. Starting in the |NEW_STACK_VER|
   , the expected return behavior is ``Blocking`` instead of ``Polling``. using
   the incorrect option will cause the RNG to hang indefinitely in a BLE example.

     .. figure:: ./resources/cc23xx_sdk_8_20_to_8_40_return_behavior_rng.png
      :align: center

      Modification of RNG return behavior in SysConfig.

To learn more information about ProjectSpec files, please
reference `ProjectSpec Documentation <https://software-dl.ti.com/ccs/esd/documents/ccs_projectspecs.html>`_.

It is also possible to migrate a project only using Code Composer Studio interface.
The following steps will detail the changes needed when porting an out of the box
example from the SDK such as ``basic_ble``:

1. Import the project into Code Composer Studio.

2. In order to modify the SDK version and corresponding SysConfig version, do
   right click on the imported project folder inside the Project Explorer.
   Go to ``General`` and select ``Products`` and choose the ``SimpleLink Low Power F3 SDK``
   version as well as the ``SysConfig`` version. Refer to the Dependencies section in the
   SDK release notes for the correct SysConfig (and compiler) version. The SDK release notes 
   may be found in ``{SDK_INSTALL_DIR}/docs/simplelink_mcu_sdk/release_notes_coresdk_lpf3_x_xx_xx_xx.html``

  .. figure:: ./resources/ccs_migration_SDK_Sys_version.png
      :align: center

      Code Composer Studio - Change SDK and SysConfig Version.

3. In order to add the ``postbuild`` steps, right click on the imported project and select ``Properties``.
   Search for ``Build`` |rarr| ``Steps`` |rarr| ``Post-build steps`` and include the following line:

   * ``${COM_TI_SIMPLELINK_LOWPOWER_F3_SOURCE_SDK_INSTALL_DIR}/tools/common/crc_tool/crc_tool patch-image --elf ${BuildArtifactFileBaseName}.out --symbol-prefix ti_utils_build_GenMap_sym_CRC_CCFG -o ${BuildArtifactFileBaseName}.out``
          
Legacy Porting
--------------

.. warning::
   The following section covers a legacy porting method. Current SDK porting
   does not require this process and should instead see
   :ref:`ble-porting-sdk-8-40`.

For this guide, a peripheral project from |OLD_STACK_VER| will be
ported over to |NEW_STACK_VER|. The recommended approach is to start with the
Basic BLE project on |NEW_STACK_VER| and modify the base configuration to
match the peripheral configuration used in the |OLD_STACK_VER| project.
Afterwards, the custom application code should be transferred to the new
project.

#. Import a |NEW_STACK_VER| Basic BLE project.

#. Change the default Basic BLE project configuration options in the BLE Module
   present in SysConfig to match the configuration used in the |OLD_STACK_VER| project.

#. Transfer all custom application logic from the |OLD_STACK_VER| into the
   |NEW_STACK_VER| Basic BLE project.

#. Move any profiles and services that the application is using to the
   |NEW_STACK_VER| project.

#. Transfer the SysConfig settings either visually through the GUI or open both
   the old and the new project ``.syscfg`` files and copy-paste the desired
   settings.

#. If necessary, update the project to use the newer TI drivers that are
   supplied with the |SDK|. Additional details are provided
   in :ref:`noteworthy-ble-migration-sdk-8-40`.

#. Refer to the Core SDK release notes for additional information and the
   FreeRTOS examples included with |SDK|. The Core SDK release notes may be
   found in
   ``{SDK_INSTALL_DIR}/docs/simplelink_mcu_sdk/release_notes_coresdk_lpf3_x_xx_xx_xx.html``

   For additional information on how |NEW_STACK_VER| uses FreeRTOS see
   :ref:`sec-freertos-overview`.

   For any utilized TI Drivers, review |TI_DRIVERS_API|.

.. _noteworthy-ble-migration-sdk-8-40:

A Few Noteworthy Changes from |OLD_STACK_VER| to |NEW_STACK_VER|
----------------------------------------------------------------

You can follow the guide above without addressing these updates; they are listed
for your information only. All fine grained details might not be mentioned.
Please refer to the specific example you need to port and do a compare between
the old and new project files. Please refer to the |STACK| Release Notes for
all the details.