Skip to content

Commit 7f80c44

Browse files
authored
ESP32 now uses IDF hardware implementation if available (#2156)
***NO_CI***
1 parent edffc8d commit 7f80c44

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

CMake/Modules/FindESP32_IDF.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ list(APPEND ESP32_IDF_INCLUDE_DIRS ${esp32_idf_SOURCE_DIR}/components/wear_level
5353

5454
list(APPEND ESP32_IDF_INCLUDE_DIRS ${esp32_idf_SOURCE_DIR}/components/esp_rom/include/${TARGET_SERIES_SHORT}/rom)
5555
list(APPEND ESP32_IDF_INCLUDE_DIRS ${esp32_idf_SOURCE_DIR}/components/esp_rom/include)
56+
list(APPEND ESP32_IDF_INCLUDE_DIRS ${esp32_idf_SOURCE_DIR}/components/esp_rom/${TARGET_SERIES_SHORT})
5657

5758
# includes specific to ESP32S2
5859
if(${TARGET_SERIES_SHORT} STREQUAL "esp32s2")

CMake/Modules/FindNF_CoreCLR.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ set(NF_CoreCLR_SRCS
7575
TypeSystemLookup.cpp
7676
StringTableData.cpp
7777
TypeSystem.cpp
78-
nanoSupport_CRC32.c
7978
nanoHAL_SystemInformation.cpp
8079
Various.cpp
8180

@@ -159,6 +158,11 @@ set(NF_CoreCLR_SRCS
159158
GenericPort_stubs.c
160159
)
161160

161+
# append CRC32, if not already included with Wire Protocol
162+
if(NOT WireProtocol_FOUND)
163+
list(APPEND NF_CoreCLR_SRCS nanoSupport_CRC32.c)
164+
endif()
165+
162166
# include System.Reflection API files depending on build option
163167
if(NF_FEATURE_SUPPORT_REFLECTION)
164168
list(APPEND NF_CoreCLR_SRCS corlib_native_System_Reflection_Assembly.cpp)

src/CLR/Core/nanoSupport_CRC32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// CRC 32 table for use under ZModem protocol, IEEE 802
1313
// G(x) = x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
1414
//
15-
static const uint32_t c_CRCTable[256] = {
15+
const uint32_t c_CRCTable[256] = {
1616
0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, 0x2608EDB8,
1717
0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7,
1818
0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75, 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6,

targets/ESP32/_Include/esp32_idf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include <soc/uart_channel.h>
5252
#include <spiffs_config.h>
5353
#include <esp_spiffs.h>
54+
#include <esp_rom_crc.h>
55+
#include <esp_rom_caps.h>
5456

5557
// includes specific for TinyUSB and CDC
5658
#if CONFIG_USB_CDC_ENABLED

targets/ESP32/_common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WireProt
1616

1717
list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigStorageSPIFFS.c)
1818
list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigurationManager.cpp)
19+
list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nanoSupport_CRC32.c)
1920

2021
# add device mapping
2122
# check if there is a specific one for the target...
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
4+
// See LICENSE file in the project root for full license information.
5+
//
6+
7+
#include <esp32_idf.h>
8+
9+
#ifndef ESP_ROM_HAS_CRC_BE
10+
extern const uint32_t c_CRCTable[256];
11+
const uint32_t *myCRCTable = c_CRCTable;
12+
#endif
13+
14+
// strong implementation of this function specific to the ESP32
15+
uint32_t SUPPORT_ComputeCRC(const void *rgBlock, const uint32_t nLength, const uint32_t crc)
16+
{
17+
uint8_t const *ptr = (const unsigned char *)rgBlock;
18+
int32_t lenght = nLength;
19+
uint32_t newCrc = crc;
20+
21+
#ifdef ESP_ROM_HAS_CRC_BE
22+
23+
// this series has ROM support for CRC32
24+
25+
// IDF CRC32 polinomial required this tweak
26+
if (crc == 0)
27+
{
28+
newCrc = 0xFFFFFFFF;
29+
}
30+
31+
newCrc = ~esp_rom_crc32_be(newCrc, ptr, lenght);
32+
33+
#else
34+
35+
// this series does not have ROM support for CRC32
36+
// use our implementation and CRC table
37+
while (lenght-- > 0)
38+
{
39+
newCrc = myCRCTable[((newCrc >> 24) ^ (*ptr++)) & 0xFF] ^ (newCrc << 8);
40+
}
41+
42+
#endif
43+
44+
return newCrc;
45+
}

0 commit comments

Comments
 (0)