Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native support for Hardware.Stm32 class lib #935

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions CMake/Modules/FindnanoFramework.Hardware.Stm32.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# 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}/nanoFramework.Hardware.Stm32")


# set include directories
# list(APPEND nanoFramework.Hardware.Stm32_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src/CLR/Core")
# list(APPEND nanoFramework.Hardware.Stm32_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src/CLR/Include")
# list(APPEND nanoFramework.Hardware.Stm32_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src/HAL/Include")
# list(APPEND nanoFramework.Hardware.Stm32_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src/PAL/Include")
list(APPEND nanoFramework.Hardware.Stm32_INCLUDE_DIRS "${BASE_PATH_FOR_THIS_MODULE}")


# source files
set(nanoFramework.Hardware.Stm32_SRCS

nf_hardware_stm32_native.cpp
nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory.cpp
nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_RTC.cpp
nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities.cpp
)

foreach(SRC_FILE ${nanoFramework.Hardware.Stm32_SRCS})
set(nanoFramework.Hardware.Stm32_SRC_FILE SRC_FILE-NOTFOUND)
find_file(nanoFramework.Hardware.Stm32_SRC_FILE ${SRC_FILE}
PATHS
"${BASE_PATH_FOR_THIS_MODULE}"

CMAKE_FIND_ROOT_PATH_BOTH
)
# message("${SRC_FILE} >> ${nanoFramework.Hardware.Stm32_SRC_FILE}") # debug helper
list(APPEND nanoFramework.Hardware.Stm32_SOURCES ${nanoFramework.Hardware.Stm32_SRC_FILE})
endforeach()


include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(nanoFramework.Hardware.Stm32 DEFAULT_MSG nanoFramework.Hardware.Stm32_INCLUDE_DIRS nanoFramework.Hardware.Stm32_SOURCES)
23 changes: 17 additions & 6 deletions CMake/Modules/NF_NativeAssemblies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ option(API_Windows.Networking.Sockets "option for Windows.Networking.S
# Esp32 only
option(API_Hardware.Esp32 "option for Hardware.Esp32")


# Stm32 only
option(API_Hardware.Stm32 "option for Hardware.Esp32")


#################################################################
# macro to perform individual settings to add an API to the build
macro(PerformSettingsForApiEntry apiNamespace)
Expand Down Expand Up @@ -64,6 +69,18 @@ endmacro()

macro(ParseNativeAssemblies)

# Hardware.Esp32
if(API_Hardware.Esp32)
##### API name here (doted name)
PerformSettingsForApiEntry("nanoFramework.Hardware.Esp32")
endif()

# Hardware.Stm32
if(API_Hardware.Stm32)
##### API name here (doted name)
PerformSettingsForApiEntry("nanoFramework.Hardware.Stm32")
endif()

# nanoFramework.Networking.Sntp
if(API_nanoFramework.Networking.Sntp)
##### API name here (doted name)
Expand Down Expand Up @@ -138,12 +155,6 @@ macro(ParseNativeAssemblies)
PerformSettingsForApiEntry("Windows.Devices.Wifi")
endif()

# Hardware.Esp32
if(API_Hardware.Esp32)
##### API name here (doted name)
PerformSettingsForApiEntry("nanoFramework.Hardware.Esp32")
endif()

# Interop assemblies
ParseInteropAssemblies()

Expand Down
3 changes: 2 additions & 1 deletion cmake-variants.TEMPLATE.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"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_Hardware.Esp32" : "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"
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions get-stm32-targets-to-build.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#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 -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 -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 -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_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 -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 -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_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')
$BuildMatrix = ("MBN_QUAIL", "-DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=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 -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 -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 -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 -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_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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include "nf_hardware_stm32_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,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory::ReadBytes___STATIC__VOID__U4__SZARRAY_U1,
Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory::WriteBytes___STATIC__VOID__U4__SZARRAY_U1,
Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory::GetSize___STATIC__I4,
NULL,
NULL,
Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_RTC::Native_RTC_SetAlarm___STATIC__VOID__U1__U1__U1__U1,
Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_RTC::Native_RTC_GetAlarm___STATIC__I8,
NULL,
NULL,
NULL,
Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities::NativeGetDeviceUniqueId___STATIC__VOID__SZARRAY_U1,
Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities::NativeGetDeviceId___STATIC__U4,
Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities::NativeGetDeviceRevisionId___STATIC__U4,
};

const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_Stm32 =
{
"nanoFramework.Hardware.Stm32",
0x3D39A14F,
method_lookup,
{ 1, 0, 0, 0 }
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#ifndef _NF_HARDWARE_STM32_NATIVE_H_
#define _NF_HARDWARE_STM32_NATIVE_H_

#include <nanoCLR_Interop.h>
#include <nanoCLR_Runtime.h>
#include <hal.h>

struct Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory
{
static const int FIELD_STATIC___size = 0;

NANOCLR_NATIVE_DECLARE(ReadBytes___STATIC__VOID__U4__SZARRAY_U1);
NANOCLR_NATIVE_DECLARE(WriteBytes___STATIC__VOID__U4__SZARRAY_U1);
NANOCLR_NATIVE_DECLARE(GetSize___STATIC__I4);

//--//

// need to address the fact that the majority of the series have 32 bits wide registers and F1 has 16bits wide.
// the backup size is calculated with the number of available backup registers and their size (in bytes)
static const int BACKUP_SIZE = RTC_BKP_NUMBER * sizeof(RTC_BKP0R_Msk);
};

struct Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_RTC
{
NANOCLR_NATIVE_DECLARE(Native_RTC_SetAlarm___STATIC__VOID__U1__U1__U1__U1);
NANOCLR_NATIVE_DECLARE(Native_RTC_GetAlarm___STATIC__I8);

//--//

};

struct Library_nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities
{
static const int FIELD_STATIC___deviceUniqueId = 1;
static const int FIELD_STATIC___deviceId = 2;
static const int FIELD_STATIC___deviceRevisionId = 3;

NANOCLR_NATIVE_DECLARE(NativeGetDeviceUniqueId___STATIC__VOID__SZARRAY_U1);
NANOCLR_NATIVE_DECLARE(NativeGetDeviceId___STATIC__U4);
NANOCLR_NATIVE_DECLARE(NativeGetDeviceRevisionId___STATIC__U4);

//--//

};

extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_Stm32;

#endif //_NF_HARDWARE_STM32_NATIVE_H_
Loading