Skip to content
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

Code improvement: regex centralization #284

Open
atsju opened this issue Feb 19, 2022 · 1 comment
Open

Code improvement: regex centralization #284

atsju opened this issue Feb 19, 2022 · 1 comment

Comments

@atsju
Copy link
Collaborator

atsju commented Feb 19, 2022

several regex to find STM families are reused at many places. It's complex to maintain.

We should create some functions to have regex at one place and easier to reuse.

@atsju atsju mentioned this issue Feb 19, 2022
This was referenced Oct 9, 2022
@xanthio
Copy link
Contributor

xanthio commented Jul 10, 2024

Here is a proposition for a single place regex function:

function(stm32_extract_info identifier)
    set(ARG_OPTIONS "")
    set(ARG_SINGLE FAMILY DEVICE FLASH_CODE CORE)
    set(ARG_MULTIPLE "")
    cmake_parse_arguments(PARSE_ARGV 1 INFO "${ARG_OPTIONS}" "${ARG_SINGLE}" "${ARG_MULTIPLE}")

    string(REGEX MATCH "^(STM32)?([CFGHLU][0123457]|MP[12]|WL|WB[0A]?)([0-9A-Z][0-9M]?)?([A-Z135])?([3468ABCDEFGHIJYZ])?_?(M0PLUS|M4|M7)?.*$" ID ${identifier})
    set(FAMILY ${CMAKE_MATCH_2})
    set(SUB_FAMILY ${CMAKE_MATCH_3})
    set(PIN_COUNT ${CMAKE_MATCH_4})
    set(FLASH_SIZE ${CMAKE_MATCH_5})
    set(CORE ${CMAKE_MATCH_6})

    # message(STATUS "Parsed ${identifier} and got F ${FAMILY} S ${SUB_FAMILY} P ${PIN_COUNT} R ${FLASH_SIZE} C ${CORE}")

    if (INFO_FAMILY AND FAMILY)
        set(${INFO_FAMILY} ${FAMILY} PARENT_SCOPE)
    endif()
    if (INFO_DEVICE AND FAMILY AND SUB_FAMILY AND PIN_COUNT AND FLASH_SIZE)
        set(${INFO_DEVICE} ${FAMILY}${SUB_FAMILY}${PIN_COUNT}${FLASH_SIZE} PARENT_SCOPE)
    endif()
    if (INFO_FLASH_CODE AND FLASH_SIZE)
        set(${INFO_FLASH_CODE} ${FLASH_SIZE} PARENT_SCOPE)
    endif()
    if (INFO_CORE AND CORE)
        set(${INFO_CORE} ${CORE} PARENT_SCOPE)
    endif()
endfunction()

I changed a bit the original Regex to allow future support for MP2, WBA and WB0 families.
You should notice that devices which were 6 characters long (eg F100C4) can be 7 with family WBA (eg WBA52KE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants