diff --git a/CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake b/CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake index f11d9526a0..33c18f5395 100644 --- a/CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake +++ b/CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake @@ -29,7 +29,7 @@ set(CHIBIOS_PORT_SRCS hal_i2c_lld.c hal_mac_lld.c hal_rtc_lld.c - #hal_sdc_lld.c + hal_sdc_lld.c #hal_i2s_lld.c hal_spi_lld.c hal_st_lld.c @@ -97,7 +97,7 @@ list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/por list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/MACv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/OTGv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RTCv2) -#list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDIOv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SPIv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/TIMv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/USARTv1) diff --git a/CMake/Modules/CHIBIOS_STM32F7xx_sources.cmake b/CMake/Modules/CHIBIOS_STM32F7xx_sources.cmake index fd51bc5dcd..8fddb24d2c 100644 --- a/CMake/Modules/CHIBIOS_STM32F7xx_sources.cmake +++ b/CMake/Modules/CHIBIOS_STM32F7xx_sources.cmake @@ -29,7 +29,7 @@ set(CHIBIOS_PORT_SRCS hal_i2c_lld.c hal_mac_lld.c hal_rtc_lld.c - #hal_sdc_lld.c + hal_sdc_lld.c #hal_i2s_lld.c hal_spi_lld.c hal_st_lld.c @@ -68,7 +68,7 @@ foreach(SRC_FILE ${CHIBIOS_PORT_SRCS}) ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/MACv1 ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/OTGv1 ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RTCv2 - #${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1 ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SPIv2 ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/TIMv1 ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/USARTv2 @@ -97,7 +97,7 @@ list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/por list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/MACv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/OTGv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RTCv2) -#list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SPIv2) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/TIMv1) list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/USARTv2) diff --git a/CMake/Modules/FindCHIBIOS_FATFS.cmake b/CMake/Modules/FindCHIBIOS_FATFS.cmake index c54bf84d34..765ebb16fb 100644 --- a/CMake/Modules/FindCHIBIOS_FATFS.cmake +++ b/CMake/Modules/FindCHIBIOS_FATFS.cmake @@ -10,8 +10,6 @@ execute_process( # List of the required FatFs include files. -#list(APPEND CHIBIOS_FATFS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/various) -#list(APPEND CHIBIOS_FATFS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/various/fatfs_bindings) list(APPEND CHIBIOS_FATFS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/fatfs/src) @@ -43,3 +41,18 @@ endforeach() include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(CHIBIOS_FATFS DEFAULT_MSG CHIBIOS_FATFS_INCLUDE_DIRS CHIBIOS_FATFS_SOURCES) + +# setup target to unzip ChibiOS external filesystem components +add_custom_target( CHIBIOS_FILESYSTEM_COMPONENTS ALL ) + +add_custom_command(TARGET CHIBIOS_FILESYSTEM_COMPONENTS +PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E tar xvf ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/fatfs-0.13_patched.7z + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/ + DEPENDS ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/fatfs-0.13_patched.7z + + VERBATIM +) + +# this depends on ChibiOS target being already downloaded +add_dependencies(CHIBIOS_FILESYSTEM_COMPONENTS ChibiOS) diff --git a/CMake/Modules/FindWindows.Storage.cmake b/CMake/Modules/FindWindows.Storage.cmake new file mode 100644 index 0000000000..9f6a3384dc --- /dev/null +++ b/CMake/Modules/FindWindows.Storage.cmake @@ -0,0 +1,41 @@ +# +# Copyright (c) 2017 The nanoFramework project contributors +# See LICENSE file in the project root for full license information. +# + +# native code directory +set(BASE_PATH_FOR_THIS_MODULE "${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/Windows.Storage") + + +# set include directories +list(APPEND Windows.Storage_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/fatfs/src") +list(APPEND Windows.Storage_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/Include") +list(APPEND Windows.Storage_INCLUDE_DIRS "${BASE_PATH_FOR_THIS_MODULE}") + +# source files +set(Windows.Storage_SRCS + + win_storage_native_Windows_Storage_StorageFolder.cpp + win_storage_native.cpp + + Target_Windows_Storage.c +) + +foreach(SRC_FILE ${Windows.Storage_SRCS}) + set(Windows.Storage_SRC_FILE SRC_FILE-NOTFOUND) + find_file(Windows.Storage_SRC_FILE ${SRC_FILE} + PATHS + + "${BASE_PATH_FOR_THIS_MODULE}" + "${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common" + + CMAKE_FIND_ROOT_PATH_BOTH + ) + # message("${SRC_FILE} >> ${Windows.Storage_SRC_FILE}") # debug helper + list(APPEND Windows.Storage_SOURCES ${Windows.Storage_SRC_FILE}) +endforeach() + + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Windows.Storage DEFAULT_MSG Windows.Storage_INCLUDE_DIRS Windows.Storage_SOURCES) diff --git a/CMake/Modules/NF_NativeAssemblies.cmake b/CMake/Modules/NF_NativeAssemblies.cmake index 1b598a2d3b..dec6044d93 100644 --- a/CMake/Modules/NF_NativeAssemblies.cmake +++ b/CMake/Modules/NF_NativeAssemblies.cmake @@ -22,6 +22,7 @@ option(API_Windows.Devices.Pwm "option for Windows.Devices.Pwm option(API_Windows.Devices.SerialCommunication "option for Windows.Devices.SerialCommunication API") option(API_Windows.Devices.Spi "option for Windows.Devices.Spi API") option(API_Windows.Networking.Sockets "option for Windows.Networking.Sockets") +option(API_Windows.Storage "option for Windows.Storage") # Esp32 only @@ -175,6 +176,12 @@ macro(ParseNativeAssemblies) ##### API name here (doted name) PerformSettingsForApiEntry("Windows.Devices.Wifi") endif() + + # Windows.Storage + if(API_Windows.Storage) + ##### API name here (doted name) + PerformSettingsForApiEntry("Windows.Storage") + endif() # Interop assemblies ParseInteropAssemblies() diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e5337adb8..c258e04c82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -374,20 +374,6 @@ endif() # set default option for SNTP to ON option(NF_NETWORKING_SNTP "option to use add SNTP support, requires networking otherwise has no effect" ON) -################################################################# -# enables filesysytem support in nanoCLR -# (default is OFF so the filesystem is NOT supported) -option(NF_FEATURE_USE_FILESYSTEM "option to use filesystem") - -if(NF_FEATURE_USE_FILESYSTEM) - set(USE_FILESYSTEM_OPTION TRUE CACHE INTERNAL "NF feature FILESYSTEM") - set(HAL_USE_SDC_OPTION TRUE CACHE INTERNAL "HAL SDC for NF_FEATURE_USE_FILESYSTEM") - message(STATUS "Support for filesystem enabled") -else() - set(USE_FILESYSTEM_OPTION FALSE CACHE INTERNAL "NF feature FILESYSTEM") - set(HAL_USE_SDC_OPTION FALSE CACHE INTERNAL "HAL SDC for NF_FEATURE_USE_FILESYSTEM") -endif() - ################################################################# @@ -526,6 +512,21 @@ endif() ################################################################# +################################################################# +# enables filesysytem support in nanoCLR + +if(API_Windows.Storage) + set(USE_FILESYSTEM_OPTION TRUE CACHE INTERNAL "NF feature FILESYSTEM") + set(HAL_USE_SDC_OPTION TRUE CACHE INTERNAL "HAL SDC for NF_FEATURE_USE_FILESYSTEM") + message(STATUS "Support for filesystem enabled") +else() + set(USE_FILESYSTEM_OPTION FALSE CACHE INTERNAL "NF feature FILESYSTEM") + set(HAL_USE_SDC_OPTION FALSE CACHE INTERNAL "HAL SDC for NF_FEATURE_USE_FILESYSTEM") +endif() + +################################################################# + + ################################################################# # RTC (real time clock) (default is OFF so RTC is NOT included) option(NF_FEATURE_RTC "option to use hardware RTC") @@ -645,7 +646,10 @@ if(RTOS_CHIBIOS_CHECK) TIMEOUT 10 LOG_DOWNLOAD 1 + # install command has to perform TWO extracts + # in order to set multiple commands with INSTALL_COMMAND they have to be concatenated by a COMMAND keyword INSTALL_COMMAND ${CMAKE_COMMAND} -E tar xvf ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/lwip-2.0.3-patched.7z WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/ + COMMAND ${CMAKE_COMMAND} -E tar xvf ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/fatfs-0.13_patched.7z WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/ # Disable all other steps CONFIGURE_COMMAND "" @@ -680,8 +684,10 @@ if(RTOS_CHIBIOS_CHECK) PREFIX ChibiOS SOURCE_DIR ${CMAKE_BINARY_DIR}/ChibiOS_Source - INSTALL_COMMAND ${CMAKE_COMMAND} -E tar xvf ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/lwip-2.0.3-patched.7z WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/ - + # install command has to perform TWO extracts + # in order to set multiple commands with INSTALL_COMMAND they have to be concatenated by a COMMAND keyword + INSTALL_COMMAND ${CMAKE_COMMAND} -E tar xvf ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/lwip-2.0.3-patched.7z WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/ COMMAND ${CMAKE_COMMAND} -E tar xvf ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/fatfs-0.13_patched.7z WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ChibiOS_Source/ext/ + # Disable all other steps CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3c28c2f032..c2cc493cb2 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -79,7 +79,7 @@ jobs: NeedsDFU: true NETDUINO3_WIFI: BoardName: NETDUINO3_WIFI - BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.Devices.OneWire=ON + BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_Windows.Storage=ON NeedsDFU: true ST_STM32F429I_DISCOVERY: BoardName: ST_STM32F429I_DISCOVERY @@ -91,7 +91,7 @@ jobs: NeedsDFU: false ST_STM32F769I_DISCOVERY: BoardName: ST_STM32F769I_DISCOVERY - BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON + BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_Windows.Storage=ON NeedsDFU: false variables: diff --git a/cmake-variants.TEMPLATE.json b/cmake-variants.TEMPLATE.json index e9303ec79b..f55d9d0b0b 100644 --- a/cmake-variants.TEMPLATE.json +++ b/cmake-variants.TEMPLATE.json @@ -77,6 +77,7 @@ "API_Windows.Devices.SerialCommunication" : "OFF-default-ON-to-add-this-API", "API_Windows.Devices.Spi" : "OFF-default-ON-to-add-this-API", "API_Windows.Networking.Sockets" : "OFF-default-ON-to-add-this-API", + "API_Windows.Storage" : "OFF-default-ON-to-add-this-API", "API_Hardware.Esp32" : "OFF-default-ON-to-add-this-API", "API_Hardware.Stm32" : "OFF-default-ON-to-add-this-API" } diff --git a/get-stm32-targets-to-build.ps1 b/get-stm32-targets-to-build.ps1 new file mode 100644 index 0000000000..671c725890 --- /dev/null +++ b/get-stm32-targets-to-build.ps1 @@ -0,0 +1,111 @@ +#build matrx with target names and build options +$BuildMatrix = ("MBN_QUAIL", "-DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=ON -DUSE_RNG=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON", 'True'), +("ST_STM32F4_DISCOVERY", "-DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=ON -DUSE_RNG=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON", 'False'), +("ST_STM32F429I_DISCOVERY", "-DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DUSE_RNG=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON", 'False'), +("ST_NUCLEO64_F091RC", "-DTARGET_SERIES=STM32F0xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=OFF -DNF_PLATFORM_NO_CLR_TRACE=ON -DNF_CLR_NO_IL_INLINE=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON", 'False'), +("ST_NUCLEO144_F746ZG", "-DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DUSE_RNG=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON", 'False'), +("ST_STM32F769I_DISCOVERY", "-DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=ON -DUSE_RNG=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON", 'False'), +("NETDUINO3_WIFI", "-DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON", 'True') + +# get commit message +$commitMessage = "$env:APPVEYOR_REPO_COMMIT_MESSAGE" + " " + "$env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED" + +# is there a target name in the commit message? +$targetCandidate = [regex]::Matches("$commitMessage",'[#]+\w+[#]').Value + +if($targetCandidate -is [array]) +{ + $global:BUILD_MATRIX = @(,@()) + + ForEach($candidate in $targetCandidate) + { + # remove the leading and trailinig '#' + $thisCandidate = $candidate -replace "#", "" + + # find if there is a target with this name + ForEach($item in $BuildMatrix) + { + if(!$item[0].CompareTo($thisCandidate)) + { + if($global:BUILD_MATRIX) + { + $global:BUILD_MATRIX += , $item + } + else + { + $global:BUILD_MATRIX = , $item + } + + break; + } + } + } +} +else +{ + if($targetCandidate) + { + # special case for #ALL_STM32# (build all targets) + if(!$targetCandidate.CompareTo('#ALL_STM32#')) + { + # target to build is the board name + $env:BOARD_NAME = "STM32" + + $global:BUILD_MATRIX = $BuildMatrix + } + else + { + # remove the leading and trailinig '#' + $targetCandidate = $targetCandidate -replace "#", "" + + # find if there is a target with this name + ForEach($item in $BuildMatrix) + { + if(!$item[0].CompareTo($targetCandidate)) + { + $env:BOARD_NAME = $item[0] + $env:BUILD_OPTIONS = $item[1] + $env:NEEDS_DFU = $item[2] + + break; + } + } + } + } + else + { + # default is to build all STM32 targets + $env:BOARD_NAME = 'STM32' + + $global:BUILD_MATRIX = $BuildMatrix + } +} + +if($env:BOARD_NAME) +{ + if(!$env:BOARD_NAME.CompareTo('STM32')) + { + Write-Host "Build all STM32 targets" + } + else + { + Write-Host "Target board is " $env:BOARD_NAME + } +} +else +{ + if($global:BUILD_MATRIX) + { + Write-Host "Build targets:" + + ForEach($item in $global:BUILD_MATRIX) + { + $env:BOARD_NAME += $item[0]+'|' + Write-Host $item[0] + } + } + else + { + Write-Host "No STM32 target to build" + } +} diff --git a/targets/CMSIS-OS/ChibiOS/Include/Target_Windows_Storage.h b/targets/CMSIS-OS/ChibiOS/Include/Target_Windows_Storage.h new file mode 100644 index 0000000000..b420270cb8 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/Include/Target_Windows_Storage.h @@ -0,0 +1,30 @@ +// +// Copyright (c) 2018 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _TARGET_WINDOWS_STORAGE_H_ +#define _TARGET_WINDOWS_STORAGE_H_ 1 + +#include <ch.h> +#include <cmsis_os.h> +#include <hal.h> +#include <ff.h> + +#define POLLING_INTERVAL 10 +#define POLLING_DELAY 10 + +// void RemoveHandler(eventid_t id); +// void InsertHandler(eventid_t id); + +#ifdef __cplusplus +extern "C" { +#endif + +void Target_FileSystemInit(void); + +#ifdef __cplusplus +} +#endif + +#endif //_TARGET_WINDOWS_STORAGE_H_ diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt index 9ad1240caa..d9b9ef6f6d 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt @@ -121,6 +121,13 @@ add_executable( add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf ChibiOS) add_dependencies(${NANOCLR_PROJECT_NAME}.elf ChibiOS) +# add dependencies from CHIBIOS_FILESYSTEM_COMPONENTS (this is required to make sure that ChibiOS filesystem components are unzip at the proper locations before the build starts) +# only required if filesystem is ON +if(USE_FILESYSTEM_OPTION) + add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf CHIBIOS_FILESYSTEM_COMPONENTS) + add_dependencies(${NANOCLR_PROJECT_NAME}.elf CHIBIOS_FILESYSTEM_COMPONENTS) +endif() + # include common directories include_directories( "${CMAKE_CURRENT_BINARY_DIR}" diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf.h index 7d65b3c260..60a895dd4d 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf.h @@ -228,8 +228,8 @@ */ #define STM32_SDC_SDIO_DMA_PRIORITY 3 #define STM32_SDC_SDIO_IRQ_PRIORITY 9 -#define STM32_SDC_WRITE_TIMEOUT_MS 250 -#define STM32_SDC_READ_TIMEOUT_MS 25 +#define STM32_SDC_WRITE_TIMEOUT_MS 1000 +#define STM32_SDC_READ_TIMEOUT_MS 1000 #define STM32_SDC_CLOCK_ACTIVATION_DELAY 10 #define STM32_SDC_SDIO_UNALIGNED_SUPPORT TRUE #define STM32_SDC_SDIO_DMA_STREAM STM32_DMA_STREAM_ID(2, 3) diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt index 75e40b1813..a1a9dd99a7 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt @@ -113,6 +113,9 @@ add_executable( "${NF_Debugger_SOURCES}" "${NF_Diagnostics_SOURCES}" + # sources for ChibiOS FatFS + "${CHIBIOS_FATFS_SOURCES}" + # sources for nanoFramework APIs "${TARGET_NANO_APIS_SOURCES}" ) @@ -121,6 +124,13 @@ add_executable( add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf ChibiOS) add_dependencies(${NANOCLR_PROJECT_NAME}.elf ChibiOS) +# add dependencies from CHIBIOS_FILESYSTEM_COMPONENTS (this is required to make sure that ChibiOS filesystem components are unzip at the proper locations before the build starts) +# only required if filesystem is ON +if(USE_FILESYSTEM_OPTION) + add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf CHIBIOS_FILESYSTEM_COMPONENTS) + add_dependencies(${NANOCLR_PROJECT_NAME}.elf CHIBIOS_FILESYSTEM_COMPONENTS) +endif() + # include common directories include_directories( "${CMAKE_CURRENT_BINARY_DIR}" @@ -165,6 +175,9 @@ target_include_directories(${NANOCLR_PROJECT_NAME}.elf PUBLIC # includes for nanoFramework APIs "${TARGET_NANO_APIS_INCLUDES}" + # includes for ChibiOS FatFS + "${CHIBIOS_FATFS_INCLUDE_DIRS}" + # includes for ChibiOS LwIP "${CHIBIOS_LWIP_INCLUDE_DIRS}" ) diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/ffconf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/ffconf.h new file mode 100644 index 0000000000..9cac849284 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/ffconf.h @@ -0,0 +1,272 @@ +/* CHIBIOS FIX */ +#include "ch.h" + +/*---------------------------------------------------------------------------/ +/ FatFs - Configuration file +/---------------------------------------------------------------------------*/ + +#define FFCONF_DEF 87030 /* Revision ID */ + +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: All basic functions are enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + + +#define FF_USE_STRFUNC 0 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + + +#define FF_USE_FIND 1 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + + +#define FF_USE_MKFS 0 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + + +#define FF_USE_FASTSEEK 0 +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + + +#define FF_USE_CHMOD 0 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ + + +#define FF_USE_LABEL 1 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) */ + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 850 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect code page setting can cause a file open failure. +/ +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +/ 0 - Include all code pages above and configured by f_setcp() +*/ + + +#define FF_USE_LFN 3 +#define FF_MAX_LFN 255 +/* The FF_USE_LFN switches the support for LFN (long file name). +/ +/ 0: Disable LFN. FF_MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added +/ to the project. The working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and +/ additional 608 bytes at exFAT enabled. FF_MAX_LFN can be in range from 12 to 255. +/ It should be set 255 to support full featured LFN operations. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree(), must be added to the project. */ + + +#define FF_LFN_UNICODE 0 +/* This option switches character encoding on the API, 0:ANSI/OEM or 1:UTF-16, +/ when LFN is enabled. Also behavior of string I/O functions will be affected by +/ this option. When LFN is not enabled, this option has no effect. +*/ + + +#define FF_STRF_ENCODE 3 +/* When FF_LFN_UNICODE = 1 with LFN enabled, string I/O functions, f_gets(), +/ f_putc(), f_puts and f_printf() convert the character encoding in it. +/ This option selects assumption of character encoding ON THE FILE to be +/ read/written via those functions. +/ +/ 0: ANSI/OEM +/ 1: UTF-16LE +/ 2: UTF-16BE +/ 3: UTF-8 +*/ + + +#define FF_FS_RPATH 2 +/* This option configures support for relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 3 +/* Number of volumes (logical drives) to be used. (1-10) */ + + +#define FF_STR_VOLUME_ID 1 +#define FF_VOLUME_STRS "D","E","F" +/* FF_STR_VOLUME_ID switches string support for volume ID. +/ When FF_STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive +/ number in the path name. FF_VOLUME_STRS defines the drive ID strings for each +/ logical drives. Number of items must be equal to FF_VOLUMES. Valid characters for +/ the drive ID strings are: A-Z and 0-9. */ + + +#define FF_MULTI_PARTITION 0 +/* This option switches support for multiple volumes on the physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When this function is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + + +#define FF_MIN_SS 512 +#define FF_MAX_SS 512 +/* This set of options configures the range of sector size to be supported. (512, +/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured +/ for variable sector size mode and disk_ioctl() function needs to implement +/ GET_SECTOR_SIZE command. */ + + +#define FF_USE_TRIM 0 +/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + + +#define FF_FS_NOFSINFO 0 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 0 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ + + +#define FF_FS_EXFAT 0 +/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) +/ When enable exFAT, also LFN needs to be enabled. +/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ + + +#define FF_FS_NORTC 1 +#define FF_NORTC_MON 8 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2018 +/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have +/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable +/ the timestamp function. All objects modified by FatFs will have a fixed timestamp +/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. +/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */ + + +#define FF_FS_LOCK 0 +/* The option FF_FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + + +#define FF_FS_REENTRANT 1 +#define FF_FS_TIMEOUT TIME_MS2I(1000) +#define FF_SYNC_t semaphore_t* +/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. +/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.h. */ + +/* #include <windows.h> // O/S definitions */ + + + +/*--- End of configuration options ---*/ diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/main.c b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/main.c index efa331b7d9..1489526237 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/main.c +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/main.c @@ -3,8 +3,6 @@ // See LICENSE file in the project root for full license information. // -// Using Devantech LCD03 display in I2C mode @ address 0xC8 - #include <ch.h> #include <hal.h> #include <cmsis_os.h> @@ -17,6 +15,13 @@ #include <nanoPAL_BlockStorage.h> #include <nanoHAL_v2.h> #include <targetPAL.h> +#include <Target_Windows_Storage.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +extern evhandler_t sdcardEventHandler[]; // need to declare the Receiver thread here osThreadDef(ReceiverThread, osPriorityHigh, 2048, "ReceiverThread"); @@ -52,7 +57,7 @@ int main(void) { // HAL initialization, this also initializes the configured device drivers // and performs the board-specific initializations. halInit(); - + // init SWO as soon as possible to make it available to output ASAP #if (SWO_OUTPUT == TRUE) SwoInit(); @@ -95,8 +100,12 @@ int main(void) { // start kernel, after this main() will behave like a thread with priority osPriorityNormal osKernelStart(); - + + // start file system sub-system + Target_FileSystemInit(); + while (true) { - osDelay(100); + //osDelay(100); + chEvtDispatch(sdcardEventHandler, chEvtWaitOneTimeout(ALL_EVENTS, TIME_MS2I(500))); } } diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf.h index c86bd19f5b..98721f66dd 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf.h @@ -229,8 +229,8 @@ */ #define STM32_SDC_SDIO_DMA_PRIORITY 3 #define STM32_SDC_SDIO_IRQ_PRIORITY 9 -#define STM32_SDC_WRITE_TIMEOUT_MS 250 -#define STM32_SDC_READ_TIMEOUT_MS 25 +#define STM32_SDC_WRITE_TIMEOUT_MS 1000 +#define STM32_SDC_READ_TIMEOUT_MS 1000 #define STM32_SDC_CLOCK_ACTIVATION_DELAY 10 #define STM32_SDC_SDIO_UNALIGNED_SUPPORT TRUE #define STM32_SDC_SDIO_DMA_STREAM STM32_DMA_STREAM_ID(2, 3) diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_storage_config.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_storage_config.h new file mode 100644 index 0000000000..fb0198addd --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_storage_config.h @@ -0,0 +1,7 @@ +// +// Copyright (c) 2018 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +// the following macro defines a function that configures the GPIO pins for a STM32 UART/USART +#define SD_CARD_DRIVER SDCD1 \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/CMakeLists.txt new file mode 100644 index 0000000000..a3214848e8 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/CMakeLists.txt @@ -0,0 +1,236 @@ +# +# Copyright (c) 2017 The nanoFramework project contributors +# See LICENSE file in the project root for full license information. +# + +cmake_minimum_required(VERSION 3.0) +ENABLE_LANGUAGE(ASM) + +# add header files with common OS definitions and board definitions specific for each image +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nanoBooter/target_board.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/nanoBooter/target_board.h" @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR/target_board.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/nanoCLR/target_board.h" @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/target_common.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/target_common.h" @ONLY) + +set(NANOBOOTER_PROJECT_NAME "nanoBooter") +set(NANOCLR_PROJECT_NAME "nanoCLR") + +find_package(BuildUtils REQUIRED) +find_package(CHIBIOS REQUIRED) +find_package(ChibiOSnfOverlay REQUIRED) +find_package(WireProtocol REQUIRED) + +# packages for nanoFramework libraries +####################################### +# mandatory +find_package(NF_CoreCLR REQUIRED) + +####################################### +# optional + +# nF feature: debugger +if(NF_FEATURE_DEBUGGER) + find_package(NF_Debugger REQUIRED) + find_package(NF_Diagnostics REQUIRED) +endif() + +# nF feature: networking +if(USE_NETWORKING_OPTION) + find_package(CHIBIOS_LWIP REQUIRED) + find_package(NF_NETWORKING REQUIRED) +endif() + +# nF feature: filesystem +if(USE_FILESYSTEM_OPTION) + find_package(CHIBIOS_FATFS REQUIRED) +endif() + +# security provider is mbedTLS +if(NF_SECURITY_MBEDTLS) + find_package(mbedTLS REQUIRED) +endif() + +####################################### + +add_subdirectory("common") +add_subdirectory("nanoBooter") +add_subdirectory("nanoCLR") + +####################### +# nanoBooter executable + +add_executable( + # executables for project, project sources + ${NANOBOOTER_PROJECT_NAME}.elf + + "${CMAKE_CURRENT_SOURCE_DIR}/target_common.c" + + # need to add configuration manager to allow get/store configuration blocks + "${PROJECT_SOURCE_DIR}/src/HAL/nanoHAL_ConfigurationManager.c" + + ${COMMON_PROJECT_SOURCES} + ${NANOBOOTER_PROJECT_SOURCES} + + ${TARGET_CMSIS_COMMON_SOURCES} + ${TARGET_CMSIS_NANOBOOTER_SOURCES} + + ${TARGET_CHIBIOS_COMMON_SOURCES} + ${TARGET_CHIBIOS_NANOBOOTER_SOURCES} + + ${CHIBIOS_SOURCES} + ${ChibiOSnfOverlay_SOURCES} + + ${WireProtocol_SOURCES} +) + +####################### +# nanoCLR executable + +add_executable( + # executables for project, project sources + ${NANOCLR_PROJECT_NAME}.elf + + "${CMAKE_CURRENT_SOURCE_DIR}/target_common.c" + + ${COMMON_PROJECT_SOURCES} + ${NANOCLR_PROJECT_SOURCES} + + ${TARGET_CMSIS_COMMON_SOURCES} + ${TARGET_CMSIS_NANOCLR_SOURCES} + + ${TARGET_CHIBIOS_COMMON_SOURCES} + ${TARGET_CHIBIOS_NANOCLR_SOURCES} + + ${CHIBIOS_SOURCES} + ${ChibiOSnfOverlay_SOURCES} + + ${WireProtocol_SOURCES} + + # sources for nanoFramework libraries + "${NF_CoreCLR_SOURCES}" + "${NF_Debugger_SOURCES}" + "${NF_Diagnostics_SOURCES}" + + # sources for ChibiOS FatFS + "${CHIBIOS_FATFS_SOURCES}" + + # sources for nanoFramework Network LWIP, Sockets and TLS + "${CHIBIOS_LWIP_SOURCES}" + "${NF_Networking_SOURCES}" + "${mbedTLS_SOURCES}" + + # sources for nanoFramework APIs + "${TARGET_NANO_APIS_SOURCES}" +) + +# add dependency from ChibiOS (this is required to make sure the ChibiOS repo is downloaded before the build starts) +add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf ChibiOS) +add_dependencies(${NANOCLR_PROJECT_NAME}.elf ChibiOS) + +# add dependencies from CHIBIOS_NETWORK_COMPONENTS (this is required to make sure that ChibiOS network components are unzip at the proper locations before the build starts) +# only required if networking is ON +if(USE_NETWORKING_OPTION) + add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf CHIBIOS_NETWORK_COMPONENTS) + add_dependencies(${NANOCLR_PROJECT_NAME}.elf CHIBIOS_NETWORK_COMPONENTS) + + # add dependency for security provider mbedTLS + if(NF_SECURITY_MBEDTLS) + add_dependencies(${NANOCLR_PROJECT_NAME}.elf mbedTLS) + endif() +endif() + +# include common directories +include_directories( + "${CMAKE_CURRENT_BINARY_DIR}" + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/common + ${PROJECT_SOURCE_DIR}/src/CLR/Core + ${PROJECT_SOURCE_DIR}/src/CLR/Include + ${PROJECT_SOURCE_DIR}/src/HAL/Include + ${PROJECT_SOURCE_DIR}/src/PAL/Include + + ${WireProtocol_INCLUDE_DIRS} + ${CHIBIOS_INCLUDE_DIRS} + ${ChibiOSnfOverlay_INCLUDE_DIRS} + + ${TARGET_CMSIS_COMMON_INCLUDE_DIRS} + ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS} +) + +# include directories for nanoBooter +target_include_directories(${NANOBOOTER_PROJECT_NAME}.elf PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}/nanoBooter" + ${CMAKE_CURRENT_SOURCE_DIR}/nanoBooter + + ${TARGET_CMSIS_NANOBOOTER_INCLUDE_DIRS} + ${TARGET_CHIBIOS_NANOBOOTER_INCLUDE_DIRS} + + # includes for ChibiOS LwIP + "${CHIBIOS_LWIP_INCLUDE_DIRS}" +) + +# include directories for nanoCLR +target_include_directories(${NANOCLR_PROJECT_NAME}.elf PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}/nanoCLR" + ${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR + + ${TARGET_CMSIS_NANOCLR_INCLUDE_DIRS} + ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS} + + # directories for nanoFramework libraries + "${NF_CoreCLR_INCLUDE_DIRS}" + "${NF_Debugger_INCLUDE_DIRS}" + "${NF_Diagnostics_INCLUDE_DIRS}" + + # includes for nanoFramework APIs + "${TARGET_NANO_APIS_INCLUDES}" + + # includes for ChibiOS FatFS + "${CHIBIOS_FATFS_INCLUDE_DIRS}" + + # includes for ChibiOS LwIP + "${CHIBIOS_LWIP_INCLUDE_DIRS}" + + # incudes for Networking and TLS + "${NF_Networking_INCLUDE_DIRS}" + "${mbedTLS_INCLUDE_DIRS}" +) + +# set compiler options +nf_set_compiler_options(${NANOBOOTER_PROJECT_NAME}.elf) +nf_set_compiler_options(${NANOCLR_PROJECT_NAME}.elf) + +# mbed TLS requires a config file +if(NF_SECURITY_MBEDTLS) + # this seems to be only option to properly set a compiler define through the command line that needs to be a string literal + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBEDTLS_CONFIG_FILE=\"<${CMAKE_CURRENT_SOURCE_DIR}/mbedtls_config.h>\"") +endif() + +# set compiler definitions +nf_set_compiler_definitions(${NANOBOOTER_PROJECT_NAME}.elf) +nf_set_compiler_definitions(${NANOCLR_PROJECT_NAME}.elf) + +# set linker files +if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) + nf_set_linker_file(${NANOBOOTER_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoBooter/STM32F746xG_booter-DEBUG.ld) + nf_set_linker_file(${NANOCLR_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR/STM32F746xG_CLR-DEBUG.ld) +else() + nf_set_linker_file(${NANOBOOTER_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoBooter/STM32F746xG_booter.ld) + nf_set_linker_file(${NANOCLR_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR/STM32F746xG_CLR.ld) +endif() + +# set linker options +nf_set_linker_options(${NANOBOOTER_PROJECT_NAME}.elf) +nf_set_linker_options(${NANOCLR_PROJECT_NAME}.elf) + +# add other linker flags +########################################################### +# the sizes of CRT heap and ChibiOS stacks are defined here +set_property(TARGET ${NANOBOOTER_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__crt_heap_size__=0x1000") +set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x800,--defsym=__crt_heap_size__=0x2800") + +# generate output files +nf_generate_build_output_files(${NANOBOOTER_PROJECT_NAME}.elf) +nf_generate_build_output_files(${NANOCLR_PROJECT_NAME}.elf) diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/ffconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/ffconf.h new file mode 100644 index 0000000000..7ffb3957ea --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/ffconf.h @@ -0,0 +1,272 @@ +/* CHIBIOS FIX */ +#include "ch.h" + +/*---------------------------------------------------------------------------/ +/ FatFs - Configuration file +/---------------------------------------------------------------------------*/ + +#define FFCONF_DEF 87030 /* Revision ID */ + +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: All basic functions are enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + + +#define FF_USE_STRFUNC 0 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + + +#define FF_USE_FIND 0 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + + +#define FF_USE_MKFS 0 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + + +#define FF_USE_FASTSEEK 0 +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + + +#define FF_USE_CHMOD 0 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ + + +#define FF_USE_LABEL 0 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) */ + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 850 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect code page setting can cause a file open failure. +/ +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +/ 0 - Include all code pages above and configured by f_setcp() +*/ + + +#define FF_USE_LFN 3 +#define FF_MAX_LFN 255 +/* The FF_USE_LFN switches the support for LFN (long file name). +/ +/ 0: Disable LFN. FF_MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added +/ to the project. The working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and +/ additional 608 bytes at exFAT enabled. FF_MAX_LFN can be in range from 12 to 255. +/ It should be set 255 to support full featured LFN operations. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree(), must be added to the project. */ + + +#define FF_LFN_UNICODE 0 +/* This option switches character encoding on the API, 0:ANSI/OEM or 1:UTF-16, +/ when LFN is enabled. Also behavior of string I/O functions will be affected by +/ this option. When LFN is not enabled, this option has no effect. +*/ + + +#define FF_STRF_ENCODE 3 +/* When FF_LFN_UNICODE = 1 with LFN enabled, string I/O functions, f_gets(), +/ f_putc(), f_puts and f_printf() convert the character encoding in it. +/ This option selects assumption of character encoding ON THE FILE to be +/ read/written via those functions. +/ +/ 0: ANSI/OEM +/ 1: UTF-16LE +/ 2: UTF-16BE +/ 3: UTF-8 +*/ + + +#define FF_FS_RPATH 0 +/* This option configures support for relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 1 +/* Number of volumes (logical drives) to be used. (1-10) */ + + +#define FF_STR_VOLUME_ID 0 +#define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3" +/* FF_STR_VOLUME_ID switches string support for volume ID. +/ When FF_STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive +/ number in the path name. FF_VOLUME_STRS defines the drive ID strings for each +/ logical drives. Number of items must be equal to FF_VOLUMES. Valid characters for +/ the drive ID strings are: A-Z and 0-9. */ + + +#define FF_MULTI_PARTITION 0 +/* This option switches support for multiple volumes on the physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When this function is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + + +#define FF_MIN_SS 512 +#define FF_MAX_SS 512 +/* This set of options configures the range of sector size to be supported. (512, +/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured +/ for variable sector size mode and disk_ioctl() function needs to implement +/ GET_SECTOR_SIZE command. */ + + +#define FF_USE_TRIM 0 +/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + + +#define FF_FS_NOFSINFO 0 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 0 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ + + +#define FF_FS_EXFAT 0 +/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) +/ When enable exFAT, also LFN needs to be enabled. +/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ + + +#define FF_FS_NORTC 1 +#define FF_NORTC_MON 8 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2018 +/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have +/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable +/ the timestamp function. All objects modified by FatFs will have a fixed timestamp +/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. +/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */ + + +#define FF_FS_LOCK 0 +/* The option FF_FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + + +#define FF_FS_REENTRANT 0 +#define FF_FS_TIMEOUT TIME_MS2I(1000) +#define FF_SYNC_t semaphore_t* +/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. +/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.h. */ + +/* #include <windows.h> // O/S definitions */ + + + +/*--- End of configuration options ---*/ diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt index dbe6ecf40a..54dfdecace 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt @@ -114,6 +114,9 @@ add_executable( "${NF_Debugger_SOURCES}" "${NF_Diagnostics_SOURCES}" + # sources for ChibiOS FatFS + "${CHIBIOS_FATFS_SOURCES}" + # sources for nanoFramework APIs "${TARGET_NANO_APIS_SOURCES}" ) @@ -166,6 +169,9 @@ target_include_directories(${NANOCLR_PROJECT_NAME}.elf PUBLIC # includes for nanoFramework APIs "${TARGET_NANO_APIS_INCLUDES}" + # includes for ChibiOS FatFS + "${CHIBIOS_FATFS_INCLUDE_DIRS}" + # includes for ChibiOS LwIP "${CHIBIOS_LWIP_INCLUDE_DIRS}" ) diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt index 4b69134796..1fa323c267 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt @@ -115,6 +115,9 @@ add_executable( "${NF_Debugger_SOURCES}" "${NF_Diagnostics_SOURCES}" + # sources for ChibiOS FatFS + "${CHIBIOS_FATFS_SOURCES}" + # sources for nanoFramework APIs "${TARGET_NANO_APIS_SOURCES}" ) @@ -167,6 +170,9 @@ target_include_directories(${NANOCLR_PROJECT_NAME}.elf PUBLIC # includes for nanoFramework APIs "${TARGET_NANO_APIS_INCLUDES}" + # includes for ChibiOS FatFS + "${CHIBIOS_FATFS_INCLUDE_DIRS}" + # includes for ChibiOS LwIP "${CHIBIOS_LWIP_INCLUDE_DIRS}" ) diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/ffconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/ffconf.h new file mode 100644 index 0000000000..7ffb3957ea --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/ffconf.h @@ -0,0 +1,272 @@ +/* CHIBIOS FIX */ +#include "ch.h" + +/*---------------------------------------------------------------------------/ +/ FatFs - Configuration file +/---------------------------------------------------------------------------*/ + +#define FFCONF_DEF 87030 /* Revision ID */ + +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: All basic functions are enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + + +#define FF_USE_STRFUNC 0 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + + +#define FF_USE_FIND 0 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + + +#define FF_USE_MKFS 0 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + + +#define FF_USE_FASTSEEK 0 +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + + +#define FF_USE_CHMOD 0 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ + + +#define FF_USE_LABEL 0 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) */ + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 850 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect code page setting can cause a file open failure. +/ +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +/ 0 - Include all code pages above and configured by f_setcp() +*/ + + +#define FF_USE_LFN 3 +#define FF_MAX_LFN 255 +/* The FF_USE_LFN switches the support for LFN (long file name). +/ +/ 0: Disable LFN. FF_MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added +/ to the project. The working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and +/ additional 608 bytes at exFAT enabled. FF_MAX_LFN can be in range from 12 to 255. +/ It should be set 255 to support full featured LFN operations. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree(), must be added to the project. */ + + +#define FF_LFN_UNICODE 0 +/* This option switches character encoding on the API, 0:ANSI/OEM or 1:UTF-16, +/ when LFN is enabled. Also behavior of string I/O functions will be affected by +/ this option. When LFN is not enabled, this option has no effect. +*/ + + +#define FF_STRF_ENCODE 3 +/* When FF_LFN_UNICODE = 1 with LFN enabled, string I/O functions, f_gets(), +/ f_putc(), f_puts and f_printf() convert the character encoding in it. +/ This option selects assumption of character encoding ON THE FILE to be +/ read/written via those functions. +/ +/ 0: ANSI/OEM +/ 1: UTF-16LE +/ 2: UTF-16BE +/ 3: UTF-8 +*/ + + +#define FF_FS_RPATH 0 +/* This option configures support for relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 1 +/* Number of volumes (logical drives) to be used. (1-10) */ + + +#define FF_STR_VOLUME_ID 0 +#define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3" +/* FF_STR_VOLUME_ID switches string support for volume ID. +/ When FF_STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive +/ number in the path name. FF_VOLUME_STRS defines the drive ID strings for each +/ logical drives. Number of items must be equal to FF_VOLUMES. Valid characters for +/ the drive ID strings are: A-Z and 0-9. */ + + +#define FF_MULTI_PARTITION 0 +/* This option switches support for multiple volumes on the physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When this function is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + + +#define FF_MIN_SS 512 +#define FF_MAX_SS 512 +/* This set of options configures the range of sector size to be supported. (512, +/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured +/ for variable sector size mode and disk_ioctl() function needs to implement +/ GET_SECTOR_SIZE command. */ + + +#define FF_USE_TRIM 0 +/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + + +#define FF_FS_NOFSINFO 0 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 0 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ + + +#define FF_FS_EXFAT 0 +/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) +/ When enable exFAT, also LFN needs to be enabled. +/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ + + +#define FF_FS_NORTC 1 +#define FF_NORTC_MON 8 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2018 +/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have +/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable +/ the timestamp function. All objects modified by FatFs will have a fixed timestamp +/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. +/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */ + + +#define FF_FS_LOCK 0 +/* The option FF_FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + + +#define FF_FS_REENTRANT 0 +#define FF_FS_TIMEOUT TIME_MS2I(1000) +#define FF_SYNC_t semaphore_t* +/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. +/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.h. */ + +/* #include <windows.h> // O/S definitions */ + + + +/*--- End of configuration options ---*/ diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf.h index 4b19bca8f5..73a2424474 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf.h @@ -228,8 +228,8 @@ */ #define STM32_SDC_SDIO_DMA_PRIORITY 3 #define STM32_SDC_SDIO_IRQ_PRIORITY 9 -#define STM32_SDC_WRITE_TIMEOUT_MS 250 -#define STM32_SDC_READ_TIMEOUT_MS 25 +#define STM32_SDC_WRITE_TIMEOUT_MS 1000 +#define STM32_SDC_READ_TIMEOUT_MS 1000 #define STM32_SDC_CLOCK_ACTIVATION_DELAY 10 #define STM32_SDC_SDIO_UNALIGNED_SUPPORT TRUE #define STM32_SDC_SDIO_DMA_STREAM STM32_DMA_STREAM_ID(2, 3) diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/CMakeLists.txt new file mode 100644 index 0000000000..55c49e5318 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/CMakeLists.txt @@ -0,0 +1,203 @@ +# +# Copyright (c) 2017 The nanoFramework project contributors +# See LICENSE file in the project root for full license information. +# + +cmake_minimum_required(VERSION 3.0) +ENABLE_LANGUAGE(ASM) + +# add header files with common OS definitions and board definitions specific for each image +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nanoBooter/target_board.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/nanoBooter/target_board.h" @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR/target_board.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/nanoCLR/target_board.h" @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/target_common.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/target_common.h" @ONLY) + +set(NANOBOOTER_PROJECT_NAME "nanoBooter") +set(NANOCLR_PROJECT_NAME "nanoCLR") + +find_package(BuildUtils REQUIRED) +find_package(CHIBIOS REQUIRED) +find_package(ChibiOSnfOverlay REQUIRED) +find_package(WireProtocol REQUIRED) + +# packages for nanoFramework libraries +####################################### +# mandatory +find_package(NF_CoreCLR REQUIRED) + +####################################### +# optional + +# nF feature: debugger +if(NF_FEATURE_DEBUGGER) + find_package(NF_Debugger REQUIRED) + find_package(NF_Diagnostics REQUIRED) +endif() + +# nF feature: networking +if(USE_NETWORKING_OPTION) + find_package(CHIBIOS_LWIP REQUIRED) +endif() + +# nF feature: filesystem +if(USE_FILESYSTEM_OPTION) + find_package(CHIBIOS_FATFS REQUIRED) +endif() + +####################################### + +add_subdirectory("common") +add_subdirectory("nanoBooter") +add_subdirectory("nanoCLR") + +####################### +# nanoBooter executable + +add_executable( + # executables for project, project sources + ${NANOBOOTER_PROJECT_NAME}.elf + + "${CMAKE_CURRENT_SOURCE_DIR}/target_common.c" + + # need to add configuration manager to allow get/store configuration blocks + "${PROJECT_SOURCE_DIR}/src/HAL/nanoHAL_ConfigurationManager_stubs.c" + + ${COMMON_PROJECT_SOURCES} + ${NANOBOOTER_PROJECT_SOURCES} + + ${TARGET_CMSIS_COMMON_SOURCES} + ${TARGET_CMSIS_NANOBOOTER_SOURCES} + + ${TARGET_CHIBIOS_COMMON_SOURCES} + ${TARGET_CHIBIOS_NANOBOOTER_SOURCES} + + ${CHIBIOS_SOURCES} + ${ChibiOSnfOverlay_SOURCES} + + ${WireProtocol_SOURCES} +) + +####################### +# nanoCLR executable + +add_executable( + # executables for project, project sources + ${NANOCLR_PROJECT_NAME}.elf + + "${CMAKE_CURRENT_SOURCE_DIR}/target_common.c" + + ${COMMON_PROJECT_SOURCES} + ${NANOCLR_PROJECT_SOURCES} + + ${TARGET_CMSIS_COMMON_SOURCES} + ${TARGET_CMSIS_NANOCLR_SOURCES} + + ${TARGET_CHIBIOS_COMMON_SOURCES} + ${TARGET_CHIBIOS_NANOCLR_SOURCES} + + ${CHIBIOS_SOURCES} + ${ChibiOSnfOverlay_SOURCES} + + ${WireProtocol_SOURCES} + + # sources for nanoFramework libraries + "${NF_CoreCLR_SOURCES}" + "${NF_Debugger_SOURCES}" + "${NF_Diagnostics_SOURCES}" + + # sources for ChibiOS FatFS + "${CHIBIOS_FATFS_SOURCES}" + + # sources for nanoFramework APIs + "${TARGET_NANO_APIS_SOURCES}" +) + +# add dependency from ChibiOS (this is required to make sure the ChibiOS repo is downloaded before the build starts) +add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf ChibiOS) +add_dependencies(${NANOCLR_PROJECT_NAME}.elf ChibiOS) + +# include common directories +include_directories( + "${CMAKE_CURRENT_BINARY_DIR}" + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/common + ${PROJECT_SOURCE_DIR}/src/CLR/Core + ${PROJECT_SOURCE_DIR}/src/CLR/Include + ${PROJECT_SOURCE_DIR}/src/HAL/Include + ${PROJECT_SOURCE_DIR}/src/PAL/Include + + ${WireProtocol_INCLUDE_DIRS} + ${CHIBIOS_INCLUDE_DIRS} + ${ChibiOSnfOverlay_INCLUDE_DIRS} + + ${TARGET_CMSIS_COMMON_INCLUDE_DIRS} + ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS} +) + +# include directories for nanoBooter +target_include_directories(${NANOBOOTER_PROJECT_NAME}.elf PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}/nanoBooter" + ${CMAKE_CURRENT_SOURCE_DIR}/nanoBooter + + ${TARGET_CMSIS_NANOBOOTER_INCLUDE_DIRS} + ${TARGET_CHIBIOS_NANOBOOTER_INCLUDE_DIRS} +) + +# include directories for nanoCLR +target_include_directories(${NANOCLR_PROJECT_NAME}.elf PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}/nanoCLR" + ${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR + + ${TARGET_CMSIS_NANOCLR_INCLUDE_DIRS} + ${TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS} + + # directories for nanoFramework libraries + "${NF_CoreCLR_INCLUDE_DIRS}" + "${NF_Debugger_INCLUDE_DIRS}" + "${NF_Diagnostics_INCLUDE_DIRS}" + + # includes for nanoFramework APIs + "${TARGET_NANO_APIS_INCLUDES}" + + # includes for ChibiOS FatFS + "${CHIBIOS_FATFS_INCLUDE_DIRS}" + + # includes for ChibiOS LwIP + "${CHIBIOS_LWIP_INCLUDE_DIRS}" +) + +# set compiler options +nf_set_compiler_options(${NANOBOOTER_PROJECT_NAME}.elf) +nf_set_compiler_options(${NANOCLR_PROJECT_NAME}.elf) + +# set compiler definitions +nf_set_compiler_definitions(${NANOBOOTER_PROJECT_NAME}.elf) +nf_set_compiler_definitions(${NANOCLR_PROJECT_NAME}.elf) + +# set linker files +if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) + nf_set_linker_file(${NANOBOOTER_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoBooter/STM32F407xG_booter-DEBUG.ld) + nf_set_linker_file(${NANOCLR_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR/STM32F407xG_CLR-DEBUG.ld) +else() + nf_set_linker_file(${NANOBOOTER_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoBooter/STM32F407xG_booter.ld) + nf_set_linker_file(${NANOCLR_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR/STM32F407xG_CLR.ld) +endif() + +# set linker options +nf_set_linker_options(${NANOBOOTER_PROJECT_NAME}.elf) +nf_set_linker_options(${NANOCLR_PROJECT_NAME}.elf) + +# add other linker flags +########################################################### +# the sizes of CRT heap and ChibiOS stacks are defined here +############################################################################ +# CRT heap is assigned to RAM4 region @ CCM SRAM so we are OK to use it all +############################################################################ +set_property(TARGET ${NANOBOOTER_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__crt_heap_size__=0x10000") +set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x800,--defsym=__crt_heap_size__=0x10000") + +# generate output files +nf_generate_build_output_files(${NANOBOOTER_PROJECT_NAME}.elf) +nf_generate_build_output_files(${NANOCLR_PROJECT_NAME}.elf) diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/ffconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/ffconf.h new file mode 100644 index 0000000000..7ffb3957ea --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/ffconf.h @@ -0,0 +1,272 @@ +/* CHIBIOS FIX */ +#include "ch.h" + +/*---------------------------------------------------------------------------/ +/ FatFs - Configuration file +/---------------------------------------------------------------------------*/ + +#define FFCONF_DEF 87030 /* Revision ID */ + +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: All basic functions are enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + + +#define FF_USE_STRFUNC 0 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + + +#define FF_USE_FIND 0 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + + +#define FF_USE_MKFS 0 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + + +#define FF_USE_FASTSEEK 0 +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + + +#define FF_USE_CHMOD 0 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ + + +#define FF_USE_LABEL 0 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) */ + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 850 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect code page setting can cause a file open failure. +/ +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +/ 0 - Include all code pages above and configured by f_setcp() +*/ + + +#define FF_USE_LFN 3 +#define FF_MAX_LFN 255 +/* The FF_USE_LFN switches the support for LFN (long file name). +/ +/ 0: Disable LFN. FF_MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added +/ to the project. The working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and +/ additional 608 bytes at exFAT enabled. FF_MAX_LFN can be in range from 12 to 255. +/ It should be set 255 to support full featured LFN operations. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree(), must be added to the project. */ + + +#define FF_LFN_UNICODE 0 +/* This option switches character encoding on the API, 0:ANSI/OEM or 1:UTF-16, +/ when LFN is enabled. Also behavior of string I/O functions will be affected by +/ this option. When LFN is not enabled, this option has no effect. +*/ + + +#define FF_STRF_ENCODE 3 +/* When FF_LFN_UNICODE = 1 with LFN enabled, string I/O functions, f_gets(), +/ f_putc(), f_puts and f_printf() convert the character encoding in it. +/ This option selects assumption of character encoding ON THE FILE to be +/ read/written via those functions. +/ +/ 0: ANSI/OEM +/ 1: UTF-16LE +/ 2: UTF-16BE +/ 3: UTF-8 +*/ + + +#define FF_FS_RPATH 0 +/* This option configures support for relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 1 +/* Number of volumes (logical drives) to be used. (1-10) */ + + +#define FF_STR_VOLUME_ID 0 +#define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3" +/* FF_STR_VOLUME_ID switches string support for volume ID. +/ When FF_STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive +/ number in the path name. FF_VOLUME_STRS defines the drive ID strings for each +/ logical drives. Number of items must be equal to FF_VOLUMES. Valid characters for +/ the drive ID strings are: A-Z and 0-9. */ + + +#define FF_MULTI_PARTITION 0 +/* This option switches support for multiple volumes on the physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When this function is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + + +#define FF_MIN_SS 512 +#define FF_MAX_SS 512 +/* This set of options configures the range of sector size to be supported. (512, +/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured +/ for variable sector size mode and disk_ioctl() function needs to implement +/ GET_SECTOR_SIZE command. */ + + +#define FF_USE_TRIM 0 +/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + + +#define FF_FS_NOFSINFO 0 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 0 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ + + +#define FF_FS_EXFAT 0 +/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) +/ When enable exFAT, also LFN needs to be enabled. +/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ + + +#define FF_FS_NORTC 1 +#define FF_NORTC_MON 8 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2018 +/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have +/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable +/ the timestamp function. All objects modified by FatFs will have a fixed timestamp +/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. +/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */ + + +#define FF_FS_LOCK 0 +/* The option FF_FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + + +#define FF_FS_REENTRANT 0 +#define FF_FS_TIMEOUT TIME_MS2I(1000) +#define FF_SYNC_t semaphore_t* +/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. +/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.h. */ + +/* #include <windows.h> // O/S definitions */ + + + +/*--- End of configuration options ---*/ diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt index 27c44b9776..d51dd5ad3e 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt @@ -121,6 +121,9 @@ add_executable( "${NF_CoreCLR_SOURCES}" "${NF_Debugger_SOURCES}" "${NF_Diagnostics_SOURCES}" + + # sources for ChibiOS FatFS + "${CHIBIOS_FATFS_SOURCES}" # sources for nanoFramework Network LWIP, Sockets and TLS "${CHIBIOS_LWIP_SOURCES}" @@ -136,7 +139,7 @@ add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf ChibiOS) add_dependencies(${NANOCLR_PROJECT_NAME}.elf ChibiOS) # add dependencies from CHIBIOS_NETWORK_COMPONENTS (this is required to make sure that ChibiOS network components are unzip at the proper locations before the build starts) -# only required if networking in ON +# only required if networking is ON if(USE_NETWORKING_OPTION) add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf CHIBIOS_NETWORK_COMPONENTS) add_dependencies(${NANOCLR_PROJECT_NAME}.elf CHIBIOS_NETWORK_COMPONENTS) @@ -147,6 +150,13 @@ if(USE_NETWORKING_OPTION) endif() endif() +# add dependencies from CHIBIOS_FILESYSTEM_COMPONENTS (this is required to make sure that ChibiOS filesystem components are unzip at the proper locations before the build starts) +# only required if filesystem is ON +if(USE_FILESYSTEM_OPTION) + add_dependencies(${NANOBOOTER_PROJECT_NAME}.elf CHIBIOS_FILESYSTEM_COMPONENTS) + add_dependencies(${NANOCLR_PROJECT_NAME}.elf CHIBIOS_FILESYSTEM_COMPONENTS) +endif() + # include common directories include_directories( "${CMAKE_CURRENT_BINARY_DIR}" @@ -194,6 +204,9 @@ target_include_directories(${NANOCLR_PROJECT_NAME}.elf PUBLIC # includes for nanoFramework APIs "${TARGET_NANO_APIS_INCLUDES}" + # includes for ChibiOS FatFS + "${CHIBIOS_FATFS_INCLUDE_DIRS}" + # includes for ChibiOS LwIP "${CHIBIOS_LWIP_INCLUDE_DIRS}" diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/ffconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/ffconf.h new file mode 100644 index 0000000000..9cac849284 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/ffconf.h @@ -0,0 +1,272 @@ +/* CHIBIOS FIX */ +#include "ch.h" + +/*---------------------------------------------------------------------------/ +/ FatFs - Configuration file +/---------------------------------------------------------------------------*/ + +#define FFCONF_DEF 87030 /* Revision ID */ + +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: All basic functions are enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + + +#define FF_USE_STRFUNC 0 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + + +#define FF_USE_FIND 1 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + + +#define FF_USE_MKFS 0 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + + +#define FF_USE_FASTSEEK 0 +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + + +#define FF_USE_CHMOD 0 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ + + +#define FF_USE_LABEL 1 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) */ + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 850 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect code page setting can cause a file open failure. +/ +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +/ 0 - Include all code pages above and configured by f_setcp() +*/ + + +#define FF_USE_LFN 3 +#define FF_MAX_LFN 255 +/* The FF_USE_LFN switches the support for LFN (long file name). +/ +/ 0: Disable LFN. FF_MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added +/ to the project. The working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and +/ additional 608 bytes at exFAT enabled. FF_MAX_LFN can be in range from 12 to 255. +/ It should be set 255 to support full featured LFN operations. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree(), must be added to the project. */ + + +#define FF_LFN_UNICODE 0 +/* This option switches character encoding on the API, 0:ANSI/OEM or 1:UTF-16, +/ when LFN is enabled. Also behavior of string I/O functions will be affected by +/ this option. When LFN is not enabled, this option has no effect. +*/ + + +#define FF_STRF_ENCODE 3 +/* When FF_LFN_UNICODE = 1 with LFN enabled, string I/O functions, f_gets(), +/ f_putc(), f_puts and f_printf() convert the character encoding in it. +/ This option selects assumption of character encoding ON THE FILE to be +/ read/written via those functions. +/ +/ 0: ANSI/OEM +/ 1: UTF-16LE +/ 2: UTF-16BE +/ 3: UTF-8 +*/ + + +#define FF_FS_RPATH 2 +/* This option configures support for relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 3 +/* Number of volumes (logical drives) to be used. (1-10) */ + + +#define FF_STR_VOLUME_ID 1 +#define FF_VOLUME_STRS "D","E","F" +/* FF_STR_VOLUME_ID switches string support for volume ID. +/ When FF_STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive +/ number in the path name. FF_VOLUME_STRS defines the drive ID strings for each +/ logical drives. Number of items must be equal to FF_VOLUMES. Valid characters for +/ the drive ID strings are: A-Z and 0-9. */ + + +#define FF_MULTI_PARTITION 0 +/* This option switches support for multiple volumes on the physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When this function is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + + +#define FF_MIN_SS 512 +#define FF_MAX_SS 512 +/* This set of options configures the range of sector size to be supported. (512, +/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured +/ for variable sector size mode and disk_ioctl() function needs to implement +/ GET_SECTOR_SIZE command. */ + + +#define FF_USE_TRIM 0 +/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + + +#define FF_FS_NOFSINFO 0 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 0 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the filesystem object (FATFS) is used for the file data transfer. */ + + +#define FF_FS_EXFAT 0 +/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) +/ When enable exFAT, also LFN needs to be enabled. +/ Note that enabling exFAT discards ANSI C (C89) compatibility. */ + + +#define FF_FS_NORTC 1 +#define FF_NORTC_MON 8 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2018 +/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have +/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable +/ the timestamp function. All objects modified by FatFs will have a fixed timestamp +/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. +/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to read current time form real-time clock. FF_NORTC_MON, +/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. +/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */ + + +#define FF_FS_LOCK 0 +/* The option FF_FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + + +#define FF_FS_REENTRANT 1 +#define FF_FS_TIMEOUT TIME_MS2I(1000) +#define FF_SYNC_t semaphore_t* +/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The FF_FS_TIMEOUT defines timeout period in unit of time tick. +/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.h. */ + +/* #include <windows.h> // O/S definitions */ + + + +/*--- End of configuration options ---*/ diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/chconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/chconf.h index 0b8c98e002..73bdfa06cf 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/chconf.h @@ -3,7 +3,6 @@ // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // - /** * @file templates/chconf.h * @brief Configuration file template. @@ -32,26 +31,34 @@ * @brief System time counter resolution. * @note Allowed values are 16 or 32 bits. */ +#if !defined(CH_CFG_ST_RESOLUTION) #define CH_CFG_ST_RESOLUTION 32 +#endif /** * @brief System tick frequency. * @details Frequency of the system timer that drives the system ticks. This * setting also defines the system tick time unit. */ +#if !defined(CH_CFG_ST_FREQUENCY) #define CH_CFG_ST_FREQUENCY 10000 +#endif /** * @brief Time intervals data size. * @note Allowed values are 16, 32 or 64 bits. */ +#if !defined(CH_CFG_INTERVALS_SIZE) #define CH_CFG_INTERVALS_SIZE 32 +#endif /** * @brief Time types data size. * @note Allowed values are 16 or 32 bits. */ +#if !defined(CH_CFG_TIME_TYPES_SIZE) #define CH_CFG_TIME_TYPES_SIZE 32 +#endif /** * @brief Time delta constant for the tick-less mode. @@ -61,7 +68,9 @@ * The value one is not valid, timeouts are rounded up to * this value. */ +#if !defined(CH_CFG_ST_TIMEDELTA) #define CH_CFG_ST_TIMEDELTA 2 +#endif /** @} */ @@ -84,7 +93,9 @@ * @note The round robin preemption is not supported in tickless mode and * must be set to zero in that case. */ +#if !defined(CH_CFG_TIME_QUANTUM) #define CH_CFG_TIME_QUANTUM 0 +#endif /** * @brief Managed RAM size. @@ -97,7 +108,9 @@ * provide the @p __heap_base__ and @p __heap_end__ symbols. * @note Requires @p CH_CFG_USE_MEMCORE. */ +#if !defined(CH_CFG_MEMCORE_SIZE) #define CH_CFG_MEMCORE_SIZE 0 +#endif /** * @brief Idle thread automatic spawn suppression. @@ -106,7 +119,9 @@ * function becomes the idle thread and must implement an * infinite loop. */ +#if !defined(CH_CFG_NO_IDLE_THREAD) #define CH_CFG_NO_IDLE_THREAD FALSE +#endif /** @} */ @@ -125,7 +140,9 @@ * @note This is not related to the compiler optimization options. * @note The default is @p TRUE. */ +#if !defined(CH_CFG_OPTIMIZE_SPEED) #define CH_CFG_OPTIMIZE_SPEED TRUE +#endif /** @} */ @@ -143,7 +160,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_TM) #define CH_CFG_USE_TM FALSE +#endif /** * @brief Threads registry APIs. @@ -151,7 +170,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_REGISTRY) #define CH_CFG_USE_REGISTRY TRUE +#endif /** * @brief Threads synchronization APIs. @@ -160,7 +181,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_WAITEXIT) #define CH_CFG_USE_WAITEXIT TRUE +#endif /** * @brief Semaphores APIs. @@ -168,7 +191,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_SEMAPHORES) #define CH_CFG_USE_SEMAPHORES TRUE +#endif /** * @brief Semaphores queuing mode. @@ -179,7 +204,9 @@ * requirements. * @note Requires @p CH_CFG_USE_SEMAPHORES. */ +#if !defined(CH_CFG_USE_SEMAPHORES_PRIORITY) #define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE +#endif /** * @brief Mutexes APIs. @@ -187,7 +214,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_MUTEXES) #define CH_CFG_USE_MUTEXES TRUE +#endif /** * @brief Enables recursive behavior on mutexes. @@ -197,7 +226,9 @@ * @note The default is @p FALSE. * @note Requires @p CH_CFG_USE_MUTEXES. */ +#if !defined(CH_CFG_USE_MUTEXES_RECURSIVE) #define CH_CFG_USE_MUTEXES_RECURSIVE FALSE +#endif /** * @brief Conditional Variables APIs. @@ -207,7 +238,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_MUTEXES. */ +#if !defined(CH_CFG_USE_CONDVARS) #define CH_CFG_USE_CONDVARS TRUE +#endif /** * @brief Conditional Variables APIs with timeout. @@ -217,7 +250,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_CONDVARS. */ +#if !defined(CH_CFG_USE_CONDVARS_TIMEOUT) #define CH_CFG_USE_CONDVARS_TIMEOUT TRUE +#endif /** * @brief Events Flags APIs. @@ -225,7 +260,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_EVENTS) #define CH_CFG_USE_EVENTS TRUE +#endif /** * @brief Events Flags APIs with timeout. @@ -235,7 +272,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_EVENTS. */ +#if !defined(CH_CFG_USE_EVENTS_TIMEOUT) #define CH_CFG_USE_EVENTS_TIMEOUT TRUE +#endif /** * @brief Synchronous Messages APIs. @@ -244,7 +283,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_MESSAGES) #define CH_CFG_USE_MESSAGES TRUE +#endif /** * @brief Synchronous Messages queuing mode. @@ -255,7 +296,9 @@ * requirements. * @note Requires @p CH_CFG_USE_MESSAGES. */ +#if !defined(CH_CFG_USE_MESSAGES_PRIORITY) #define CH_CFG_USE_MESSAGES_PRIORITY FALSE +#endif /** * @brief Mailboxes APIs. @@ -265,7 +308,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_SEMAPHORES. */ +#if !defined(CH_CFG_USE_MAILBOXES) #define CH_CFG_USE_MAILBOXES TRUE +#endif /** * @brief Core Memory Manager APIs. @@ -274,7 +319,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_MEMCORE) #define CH_CFG_USE_MEMCORE TRUE +#endif /** * @brief Heap Allocator APIs. @@ -286,7 +333,9 @@ * @p CH_CFG_USE_SEMAPHORES. * @note Mutexes are recommended. */ +#if !defined(CH_CFG_USE_HEAP) #define CH_CFG_USE_HEAP TRUE +#endif /** * @brief Memory Pools Allocator APIs. @@ -295,7 +344,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_MEMPOOLS) #define CH_CFG_USE_MEMPOOLS TRUE +#endif /** * @brief Objects FIFOs APIs. @@ -304,7 +355,9 @@ * * @note The default is @p TRUE. */ +#if !defined(CH_CFG_USE_OBJ_FIFOS) #define CH_CFG_USE_OBJ_FIFOS TRUE +#endif /** * @brief Dynamic Threads APIs. @@ -315,7 +368,9 @@ * @note Requires @p CH_CFG_USE_WAITEXIT. * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS. */ +#if !defined(CH_CFG_USE_DYNAMIC) #define CH_CFG_USE_DYNAMIC TRUE +#endif /** @} */ @@ -333,39 +388,53 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_CFG_USE_FACTORY) #define CH_CFG_USE_FACTORY FALSE +#endif /** * @brief Maximum length for object names. * @details If the specified length is zero then the name is stored by * pointer but this could have unintended side effects. */ +#if !defined(CH_CFG_FACTORY_MAX_NAMES_LENGTH) #define CH_CFG_FACTORY_MAX_NAMES_LENGTH 8 +#endif /** * @brief Enables the registry of generic objects. */ +#if !defined(CH_CFG_FACTORY_OBJECTS_REGISTRY) #define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE +#endif /** * @brief Enables factory for generic buffers. */ +#if !defined(CH_CFG_FACTORY_GENERIC_BUFFERS) #define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE +#endif /** * @brief Enables factory for semaphores. */ +#if !defined(CH_CFG_FACTORY_SEMAPHORES) #define CH_CFG_FACTORY_SEMAPHORES TRUE +#endif /** * @brief Enables factory for mailboxes. */ +#if !defined(CH_CFG_FACTORY_MAILBOXES) #define CH_CFG_FACTORY_MAILBOXES TRUE +#endif /** * @brief Enables factory for objects FIFOs. */ +#if !defined(CH_CFG_FACTORY_OBJ_FIFOS) #define CH_CFG_FACTORY_OBJ_FIFOS TRUE +#endif /** @} */ @@ -381,7 +450,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_STATISTICS) #define CH_DBG_STATISTICS FALSE +#endif /** * @brief Debug option, system state check. @@ -390,7 +461,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_SYSTEM_STATE_CHECK) #define CH_DBG_SYSTEM_STATE_CHECK FALSE +#endif /** * @brief Debug option, parameters checks. @@ -399,7 +472,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_ENABLE_CHECKS) #define CH_DBG_ENABLE_CHECKS FALSE +#endif /** * @brief Debug option, consistency checks. @@ -409,7 +484,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_ENABLE_ASSERTS) #define CH_DBG_ENABLE_ASSERTS FALSE +#endif /** * @brief Debug option, trace buffer. @@ -417,14 +494,18 @@ * * @note The default is @p CH_DBG_TRACE_MASK_DISABLED. */ +#if !defined(CH_DBG_TRACE_MASK) #define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED +#endif /** * @brief Trace buffer entries. * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is * different from @p CH_DBG_TRACE_MASK_DISABLED. */ +#if !defined(CH_DBG_TRACE_BUFFER_SIZE) #define CH_DBG_TRACE_BUFFER_SIZE 128 +#endif /** * @brief Debug option, stack checks. @@ -436,7 +517,9 @@ * @note The default failure mode is to halt the system with the global * @p panic_msg variable set to @p NULL. */ +#if !defined(CH_DBG_ENABLE_STACK_CHECK) #define CH_DBG_ENABLE_STACK_CHECK FALSE +#endif /** * @brief Debug option, stacks initialization. @@ -446,7 +529,9 @@ * * @note The default is @p FALSE. */ +#if !defined(CH_DBG_FILL_THREADS) #define CH_DBG_FILL_THREADS FALSE +#endif /** * @brief Debug option, threads profiling. @@ -457,7 +542,9 @@ * @note This debug option is not currently compatible with the * tickless mode. */ +#if !defined(CH_DBG_THREADS_PROFILING) #define CH_DBG_THREADS_PROFILING FALSE +#endif /** @} */ diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h index d9f5b53e7d..2240475974 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h @@ -31,6 +31,13 @@ #define HAL_USE_PAL TRUE #endif +#if !defined(FATFS_HAL_DEVICE) || defined(__DOXYGEN__) +//this board requires SDCD2 not SDCD1 +#define FATFS_HAL_DEVICE SDCD2 +#endif + +//#define STM32_SDC_SDMMC_50MHZ TRUE + /** * @brief Enables the ADC subsystem. */ @@ -519,4 +526,4 @@ #include "halconf_nf.h" #endif /* HALCONF_H */ -/** @} */ \ No newline at end of file +/** @} */ diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/main.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/main.c index 567ebcdbf1..e119d0b6e7 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/main.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/main.c @@ -15,6 +15,13 @@ #include <nanoPAL_BlockStorage.h> #include <nanoHAL_v2.h> #include <targetPAL.h> +#include <Target_Windows_Storage.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +extern evhandler_t sdcardEventHandler[]; // need to declare the Receiver thread here osThreadDef(ReceiverThread, osPriorityHigh, 2048, "ReceiverThread"); @@ -29,7 +36,7 @@ int main(void) { halInit(); // init SWO as soon as possible to make it available to output ASAP - #if (SWO_OUTPUT == TRUE) + #if (SWO_OUTPUT == TRUE) SwoInit(); #endif @@ -72,7 +79,11 @@ int main(void) { // start kernel, after this main() will behave like a thread with priority osPriorityNormal osKernelStart(); + // start file system sub-system + Target_FileSystemInit(); + while (true) { - osDelay(100); + //osDelay(100); + chEvtDispatch(sdcardEventHandler, chEvtWaitOneTimeout(ALL_EVENTS, TIME_MS2I(500))); } -} +} \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf.h index a3e422aaea..6b9c5e8eac 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf.h @@ -81,7 +81,8 @@ #define STM32_LPTIM1SEL STM32_LPTIM1SEL_PCLK1 #define STM32_CECSEL STM32_CECSEL_LSE #define STM32_CK48MSEL STM32_CK48MSEL_PLL -#define STM32_SDMMCSEL STM32_SDMMCSEL_PLL48CLK +#define STM32_SDMMC1SEL STM32_SDMMC1SEL_PLL48CLK +#define STM32_SDMMC2SEL STM32_SDMMC2SEL_PLL48CLK #define STM32_SRAM2_NOCACHE FALSE /* @@ -249,13 +250,17 @@ * SDC driver system settings. */ #define STM32_SDC_USE_SDMMC1 TRUE +#define STM32_SDC_USE_SDMMC2 TRUE #define STM32_SDC_SDMMC_UNALIGNED_SUPPORT TRUE #define STM32_SDC_SDMMC_WRITE_TIMEOUT 1000 #define STM32_SDC_SDMMC_READ_TIMEOUT 1000 #define STM32_SDC_SDMMC_CLOCK_DELAY 10 #define STM32_SDC_SDMMC1_DMA_STREAM STM32_DMA_STREAM_ID(2, 3) +#define STM32_SDC_SDMMC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 0) #define STM32_SDC_SDMMC1_DMA_PRIORITY 3 +#define STM32_SDC_SDMMC2_DMA_PRIORITY 3 #define STM32_SDC_SDMMC1_IRQ_PRIORITY 9 +#define STM32_SDC_SDMMC2_IRQ_PRIORITY 9 /* * SERIAL driver system settings. @@ -382,4 +387,4 @@ // header for nanoFramework overlay drivers #include "mcuconf_nf.h" -#endif /* MCUCONF_H */ \ No newline at end of file +#endif /* MCUCONF_H */ diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_storage_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_storage_config.h new file mode 100644 index 0000000000..b22d4199b3 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_storage_config.h @@ -0,0 +1,7 @@ +// +// Copyright (c) 2018 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +// the following macro defines a function that configures the GPIO pins for a STM32 UART/USART +#define SD_CARD_DRIVER SDCD2 \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c b/targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c new file mode 100644 index 0000000000..f1a0b28858 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c @@ -0,0 +1,149 @@ +// +// Copyright (c) 2018 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +#include <Target_Windows_Storage.h> +#include <target_windows_storage_config.h> + +static FATFS SDC_FS; +static SDCConfig SDC_CFG; + +// Card monitor timer +static virtual_timer_t cardMonitorTimer; + +// Debounce counter +static unsigned debounceCounter; + +// FS mounted and ready +static bool fileSystemReady = FALSE; + +// Card event sources +static event_source_t insertedEvent, removedEvent; + +/** + * @brief Insertion monitor timer callback function. + * + * @param[in] p pointer to the @p BaseBlockDevice object + * + * @notapi + */ +static void InsertionMonitorCallback(void *p) +{ + BaseBlockDevice *bbdp = p; + + chSysLockFromISR(); + + if (debounceCounter > 0) + { + if (blkIsInserted(bbdp)) + { + if (--debounceCounter == 0) + { + chEvtBroadcastI(&insertedEvent); + } + } + else + { + debounceCounter = POLLING_INTERVAL; + } + } + else + { + if (!blkIsInserted(bbdp)) + { + debounceCounter = POLLING_INTERVAL; + chEvtBroadcastI(&removedEvent); + } + } + + chVTSetI(&cardMonitorTimer, TIME_MS2I(POLLING_DELAY), InsertionMonitorCallback, bbdp); + chSysUnlockFromISR(); +} + +// Card monitor start +static void StartCardMonitor(void *p) +{ + chEvtObjectInit(&insertedEvent); + chEvtObjectInit(&removedEvent); + + chSysLock(); + + debounceCounter = POLLING_INTERVAL; + chVTSetI(&cardMonitorTimer, TIME_MS2I(POLLING_DELAY), InsertionMonitorCallback, p); + + chSysUnlock(); +} + +// Card insertion event handler +static void InsertHandler(eventid_t id) +{ + FRESULT err; + + (void)id; + + /* + * On insertion SDC initialization and FS mount. + */ + if (sdcConnect(&SD_CARD_DRIVER)) + { + return; + } + + err = f_mount(&SDC_FS, "D:", 1); + + if (err != FR_OK) + { + osDelay(1000); + + sdcDisconnect(&SD_CARD_DRIVER); + return; + } + else + { + fileSystemReady = TRUE; + } + + if (fileSystemReady) + { + //****** Test - Create a file! + FIL fileObj; + err = f_open(&fileObj, "TestMessage.txt", FA_CREATE_ALWAYS); + f_close(&fileObj); + + if (err != FR_OK) + { + osDelay(1000); + } + else + { + + } + //******* End Test + } +} + +// Card removal event handler +static void RemoveHandler(eventid_t id) +{ + (void)id; + + sdcDisconnect(&SD_CARD_DRIVER); + + fileSystemReady = FALSE; +} + +const evhandler_t sdcardEventHandler[] = { InsertHandler, RemoveHandler }; +event_listener_t eventListener0, eventListener1; + +void Target_FileSystemInit() +{ + // activates the SDC driver 2 using default configuration + sdcStart(&SD_CARD_DRIVER, &SDC_CFG); + + // activates the card insertion monitor + StartCardMonitor(&SD_CARD_DRIVER); + + chEvtRegister(&insertedEvent, &eventListener0, 0); + chEvtRegister(&removedEvent, &eventListener1, 1); +} diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native.cpp new file mode 100644 index 0000000000..6161021716 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native.cpp @@ -0,0 +1,41 @@ +// +// Copyright (c) 2018 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +#include "win_storage_native.h" + + +static const CLR_RT_MethodHandler method_lookup[] = +{ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder, + Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder, + NULL, + NULL, + NULL, +}; + +const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Storage = +{ + "Windows.Storage", + 0x1EDE08F3, + method_lookup, + { 1, 0, 0, 9 } +}; diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native.h new file mode 100644 index 0000000000..95f46ac7e0 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native.h @@ -0,0 +1,52 @@ +// +// Copyright (c) 2018 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + + +#ifndef _WIN_STORAGE_NATIVE_H_ +#define _WIN_STORAGE_NATIVE_H_ + +#include <nanoCLR_Interop.h> +#include <nanoCLR_Runtime.h> +#include <hal.h> + +struct Library_win_storage_native_Windows_Storage_StorageFile +{ + static const int FIELD___contentType = 1; + static const int FIELD___fileType = 2; + static const int FIELD___name = 3; + static const int FIELD___path = 4; + + + //--// + +}; + +struct Library_win_storage_native_Windows_Storage_StorageFolder +{ + static const int FIELD___knownFolderId = 1; + static const int FIELD___dateCreated = 2; + static const int FIELD___name = 3; + static const int FIELD___path = 4; + + NANOCLR_NATIVE_DECLARE(GetRemovableStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder); + NANOCLR_NATIVE_DECLARE(GetStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder); + + //--// + +}; + +struct Library_win_storage_native_Windows_Storage_StorageProvider +{ + static const int FIELD___displayName = 1; + static const int FIELD___id = 2; + + + //--// + +}; + +extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Storage; + +#endif //_WIN_STORAGE_NATIVE_H_ diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp new file mode 100644 index 0000000000..339126be3b --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp @@ -0,0 +1,286 @@ +// +// Copyright (c) 2018 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +#include <ff.h> +#include "win_storage_native.h" +#include <target_windows_storage_config.h> + + +// FatFs define for size of file name members +// ANSI/OEM at DBCS +#define FF_LFN_BUF 255 +#define SDCARD_DRIVE_LETTER "D:\\" + + +// defining this type here to make it shorter and improve code readability +typedef Library_win_storage_native_Windows_Storage_StorageFolder StorageFolderType; + +SYSTEMTIME GetDateTime(uint16_t date, uint16_t time) +{ + SYSTEMTIME fileTime; + + memset(&fileTime, 0, sizeof(SYSTEMTIME)); + + // date (bit15:9) Year origin from 1980 (0..127) + fileTime.wYear = (date >> 9) + 1980; + // date (bit8:5) Month (1..12) + fileTime.wMonth = (date >> 5) & 0x000F; + // date (bit4:0) Day (1..31) + fileTime.wDay = date & 0x001F; + + // time (bit15:11) Hour (0..23) + fileTime.wHour = (time >> 11) & 0x001F; + // time (bit10:5) Minute (0..59) + fileTime.wMinute = (time >> 5) & 0x003F; + // time (bit4:0) Second / 2 (0..29) + fileTime.wSecond = time & 0x001F; + + return fileTime; +} + +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + + char* stringBuffer; + uint32_t driveCount = 0; + + CLR_RT_HeapBlock* storageFolder; + CLR_RT_TypeDef_Index storateFolderTypeDef; + CLR_RT_HeapBlock* hbObj; + CLR_RT_HeapBlock& top = stack.PushValue(); + + // default to NULL (which is the expected outcome when no devices are connected) + hbObj = top.Dereference(); + hbObj->SetObjectReference( NULL ); + + // is there an SD card inserted and is driver in ready state? + if(sdc_lld_is_card_inserted(&SD_CARD_DRIVER) && SD_CARD_DRIVER.state == BLK_READY) + { + driveCount++; + } + + // FIXME (no support for USB thumb drive) + // is there an USB thumb driver inserted? + // driveCount++; + + if(sdc_lld_is_card_inserted(&SD_CARD_DRIVER) && SD_CARD_DRIVER.state == BLK_READY) + { + // find <StorageFolder> type definition, don't bother checking the result as it exists for sure + g_CLR_RT_TypeSystem.FindTypeDef( "StorageFolder", "Windows.Storage", storateFolderTypeDef ); + + // create an array of <StorageFolder> + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, driveCount, storateFolderTypeDef )); + + // get a pointer to the first object in the array (which is of type <StorageFolder>) + storageFolder = (CLR_RT_HeapBlock*)top.DereferenceArray()->GetFirstElement(); + + // create an instance of <StorageFolder> + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*storageFolder, storateFolderTypeDef)); + + // dereference the object in order to reach its fields + hbObj = storageFolder->Dereference(); + + // set the managed fields + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ FIELD___name ], SDCARD_DRIVE_LETTER )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ FIELD___path ], SDCARD_DRIVE_LETTER )); + + // malloc stringBuffer to work with FS + stringBuffer = (char*)platform_malloc(FF_LFN_BUF + 1); + + // sanity check for successfull malloc + if(stringBuffer == NULL) + { + // failed to allocate memory + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } + else + { + // read the drive volume label + // don't bother checking the result, if anything goes wrong we'll end up with an empty string which is OK + f_getlabel(SDCARD_DRIVE_LETTER, stringBuffer, NULL); + + // add the driver letter separated it with an empty space, if the volume label isn't empty + if(*stringBuffer != '\0') + { + strcat(stringBuffer, " "); + } + strcat(stringBuffer, "("); + strcat(stringBuffer, SDCARD_DRIVE_LETTER); + strcat(stringBuffer, ")"); + + // set the field with the volume label + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ FIELD___name ], stringBuffer )); + + + // free stringBuffer + platform_free(stringBuffer); + } + } + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + + CLR_RT_TypeDef_Index storateFolderTypeDef; + CLR_RT_HeapBlock* storageFolder; + CLR_RT_HeapBlock* hbObj; + SYSTEMTIME fileInfoTime; + + const char* path; + char drive[2]; + + DIR currentDirectory; + FRESULT operationResult; + static FILINFO fileInfo; + uint16_t directoryCount = 0; + char* stringBuffer = NULL; + char* workingBuffer = NULL; + + CLR_RT_HeapBlock& top = stack.PushValue(); + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + // is there an SD card inserted and is driver in ready state? + if(!sdc_lld_is_card_inserted(&SD_CARD_DRIVER) || SD_CARD_DRIVER.state != BLK_READY) + { + NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); + } + + // copy the first 2 letters of the path for the drive + // path is 'D:\folder\file.txt', so we need 'D:' + memcpy(drive, pThis[ FIELD___name ].DereferenceString()->StringText(), 2); + + // get a pointer to the path in managed field + path = pThis[ FIELD___path ].DereferenceString()->StringText(); + + // change drive + if(f_chdrive(drive) == FR_OK) + { + // need to perform this in two passes + // 1st: count the directory objects + // 2nd: create the array items with each directory object + + // open directory + operationResult = f_opendir(¤tDirectory, path); + + // perform 1st pass + for (;;) + { + // read next directory item + operationResult = f_readdir(¤tDirectory, &fileInfo); + + // break on error or at end of dir + if (operationResult != FR_OK || fileInfo.fname[0] == 0) + { + break; + } + + // check if this is a directory + if (fileInfo.fattrib & AM_DIR) + { + directoryCount++; + } + } + + // find <StorageFolder> type, don't bother checking the result as it exists for sure + g_CLR_RT_TypeSystem.FindTypeDef( "StorageFolder", "Windows.Storage", storateFolderTypeDef ); + + // create an array of <StorageFolder> + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, directoryCount, storateFolderTypeDef )); + + // get a pointer to the first object in the array (which is of type <StorageFolder>) + storageFolder = (CLR_RT_HeapBlock*)top.DereferenceArray()->GetFirstElement(); + + if(directoryCount > 0) + { + // allocate memory for buffers + stringBuffer = (char*)platform_malloc(FF_LFN_BUF + 1); + workingBuffer = (char*)platform_malloc(2 * FF_LFN_BUF + 1); + + // sanity check for successfull malloc + if(stringBuffer == NULL || workingBuffer == NULL) + { + // failed to allocate memory + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } + + // perform 2nd pass + // need to rewind the directory read index first + f_readdir(¤tDirectory, NULL); + + for (;;) + { + // read next directory item + operationResult = f_readdir(¤tDirectory, &fileInfo); + + // break on error or at end of dir + if (operationResult != FR_OK || fileInfo.fname[0] == 0) + { + break; + } + + // check if this is a directory + if (fileInfo.fattrib & AM_DIR) + { + // create an instance of <StorageFolder> + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*storageFolder, storateFolderTypeDef)); + + // dereference the object in order to reach its fields + hbObj = storageFolder->Dereference(); + + // directory name + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ FIELD___name ], fileInfo.fname )); + + // clear working buffer + memset(workingBuffer, 0, 2 * FF_LFN_BUF + 1); + + // compose directory path + strcat(workingBuffer, path); + strcat(workingBuffer, fileInfo.fname); + + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ FIELD___path ], workingBuffer )); + + // compute directory date + fileInfoTime = GetDateTime(fileInfo.fdate, fileInfo.ftime); + + // get a reference to the dateCreated managed field... + CLR_RT_HeapBlock& dateFieldRef = hbObj[ FIELD___dateCreated ]; + CLR_INT64* pRes = (CLR_INT64*)&dateFieldRef.NumericByRef().s8; + // ...and set it with the fileInfoTime + *pRes = HAL_Time_ConvertFromSystemTime( &fileInfoTime ); + + // move the storage folder pointer to the next item in the array + storageFolder++; + } + } + } + else + { + // failed to open directory + NANOCLR_SET_AND_LEAVE(CLR_E_DIRECTORY_NOT_FOUND); + } + } + else + { + // failed to change drive + NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); + } + + NANOCLR_CLEANUP(); + + // close directory + f_closedir(¤tDirectory); + + // free buffers memory + platform_free(stringBuffer); + platform_free(workingBuffer); + + NANOCLR_CLEANUP_END(); +}