function(FUNC_CREATE_MEMORY_MAP filename flash_size boot_size eeprom_size)
    #memory map for linker
    SET(MEM_MAP_FILE "${filename}" )
    set(FLASH_SIZE ${flash_size}*1024)
    MATH(EXPR FLASH_SIZE "${FLASH_SIZE}")
    MATH(EXPR FLASH_BOOT_SIZE "${boot_size}*1024" OUTPUT_FORMAT HEXADECIMAL)
    MATH(EXPR FLASH_EEPROM_EMU_SIZE "${eeprom_size}*1024" OUTPUT_FORMAT HEXADECIMAL)
    MATH(EXPR FLASH_MAIN_PROG_SIZE "${FLASH_SIZE} - ${FLASH_BOOT_SIZE} - ${FLASH_EEPROM_EMU_SIZE} " OUTPUT_FORMAT HEXADECIMAL)
    MATH(EXPR  FLASH_SIZE_CALC "${FLASH_BOOT_SIZE} + ${FLASH_MAIN_PROG_SIZE} + ${FLASH_SUPPORTING_AREA_SIZE} + ${FLASH_EEPROM_EMU_SIZE}")
    if (${FLASH_SIZE_CALC} GREATER ${FLASH_SIZE} )
        message(FATAL_ERROR "FLASH_SIZE in MCU - ${FLASH_SIZE} bytes less than CALCULATED_SIZE ${FLASH_SIZE_CALC} bytes")
    elseif(${FLASH_SIZE_CALC} LESS ${FLASH_SIZE})
        message(NOTICE "FLASH_SIZE in MCU - ${FLASH_SIZE} greater than CALCULATED_SIZE ${FLASH_SIZE_CALC} , some memory areas can be increase")
    endif()

    MATH(EXPR FLASH_START_ADDRESS "0x08000000" OUTPUT_FORMAT HEXADECIMAL)
    MATH(EXPR FLASH_BOOT_START_ADDRESS "${FLASH_START_ADDRESS}" OUTPUT_FORMAT HEXADECIMAL)
    MATH(EXPR FLASH_MAIN_PROG_START_ADDRESS "${FLASH_START_ADDRESS} + ${FLASH_BOOT_SIZE}" OUTPUT_FORMAT HEXADECIMAL)
    MATH(EXPR FLASH_MAIN_PROG_END_ADDRESS "${FLASH_MAIN_PROG_START_ADDRESS} + ${FLASH_MAIN_PROG_SIZE} " OUTPUT_FORMAT HEXADECIMAL)
    MATH(EXPR FLASH_EEPROM_EMU_START_ADDRESS "${FLASH_START_ADDRESS} + ${FLASH_SIZE} - ${FLASH_EEPROM_EMU_SIZE}" OUTPUT_FORMAT HEXADECIMAL)
    MATH(EXPR EEPROM_EMU_START_ADDRESS "${FLASH_EEPROM_EMU_START_ADDRESS}" OUTPUT_FORMAT HEXADECIMAL)
    file(WRITE "${MEM_MAP_FILE}" "
    _flash_eeprom_emu_size = ${FLASH_EEPROM_EMU_SIZE};
    _flash_eeprom_emu_address = ${FLASH_EEPROM_EMU_START_ADDRESS};
    _flash_main_prog_size = ${FLASH_MAIN_PROG_SIZE};
    _flash_main_prog_address = ${FLASH_MAIN_PROG_START_ADDRESS};
    _flash_boot_size = ${FLASH_BOOT_SIZE};
    _flash_boot_address = ${FLASH_BOOT_START_ADDRESS};
")
    MATH(EXPR CRC32_USER_AREA_ADDRESS "${FLASH_MAIN_PROG_END_ADDRESS}" OUTPUT_FORMAT HEXADECIMAL)
    message(${CRC32_USER_AREA_ADDRESS})
    add_compile_definitions("EEPROM_START_ADDRESS=${FLASH_EEPROM_EMU_START_ADDRESS}"  "FLASH_USER_PROG_ADDRESS=${FLASH_MAIN_PROG_START_ADDRESS}")
    set(FLASH_MAIN_ADDRESS ${FLASH_MAIN_PROG_START_ADDRESS} PARENT_SCOPE)
endfunction()


function (FUNC_GENERATE_KEYS path_to_user_key_file path_to_user_cert_file path_to_ca_file path_for_header login_file )
    if(EXISTS "${path_to_user_key_file}" )
        file(SIZE ${path_to_user_key_file} SIZE_FILE)
        if (SIZE_FILE EQUAL 0)
            message(FATAL_ERROR "${path_to_user_key_file} file is empty")
            return()
        endif()
        file(STRINGS "${path_to_user_key_file}" USER_KEY)
        file(WRITE "${path_for_header}" "char const user_key[] = ")
        foreach(X IN LISTS USER_KEY)
            file (APPEND "${path_for_header}" "\"${X}\\n\"\n")
            message("\"${X}\"\n")
        endforeach()
        file(APPEND "${path_for_header}" ";\n")
    else()
        message(FATAL_ERROR "Please create user_key.cer in /keys directory" )
        return()
    endif()



    if(EXISTS "${path_to_user_cert_file}" )
        file(SIZE ${path_to_user_cert_file} SIZE_FILE)
        if (SIZE_FILE EQUAL 0)
            message(FATAL_ERROR "${path_to_user_cert_file} file is empty")
            return()
        endif()
        file(STRINGS "${path_to_user_cert_file}" USER_CERT )
        file(APPEND "${path_for_header}" "char const user_cert[] = ")
        foreach(X IN LISTS USER_CERT)
            file (APPEND keys/keys.h "\"${X}\\n\"\n")
        endforeach()
        file(APPEND  "${path_for_header}" ";\n")
    else()
        message(FATAL_ERROR "Please create user_cert.cer in /keys directory" )
        return()
    endif()

    if(EXISTS "${path_to_ca_file}" )
        file(SIZE ${path_to_ca_file} SIZE_FILE)
        if (SIZE_FILE EQUAL 0)
            message(FATAL_ERROR "${path_to_ca_file} file is empty")
            return()
        endif()
        file(STRINGS "${path_to_ca_file}" CA_CERT )
        file(APPEND "${path_for_header}" "char const ca[] = ")
        foreach(X IN LISTS CA_CERT)
            file (APPEND "${path_for_header}" "\"${X}\\n\"\n" )
        endforeach()
        file(APPEND  "${path_for_header}" ";\n")
    else()
        message(FATAL_ERROR "Please create ca.cer in /keys directory" )
        return()
    endif()

    if (EXISTS "${login_file}")
        file(STRINGS ${login_file}  BANKSPACE)
        list(GET BANKSPACE 4 STR1)
        message("${STR1}")
        file(APPEND "${path_for_header}" "const char* hostname = \"${STR1}\";\n")
        list(GET BANKSPACE 5 STR1)
        file(APPEND "${path_for_header}" "uint16_t port = ${STR1};\n")
    endif()
    endfunction()