openthread / ot-efr32

OpenThread on Silicon Labs EFR32 examples.
https://openthread.io/
BSD 3-Clause "New" or "Revised" License
25 stars 30 forks source link

How can I generate firmware for unofficial development boards? #200

Closed HeFeng1947 closed 2 years ago

HeFeng1947 commented 2 years ago

I have EFR32MG21A020F768 module, and the official development board (4180A) chip is a different version of Flash. How do I change the chip model without modifying any peripheral IO?

lmnotran commented 2 years ago

Hi @HeFeng1947 ,

While we only officially support a few boards in this repository, there are a couple methods that might achieve what you're trying to do.

Please keep in mind that this is unsupported officially and is not guaranteed to work.

Shorter method

The easiest, albeit a bit crude, solution might be to edit this line so that it defines the correct MCU value for your device

if(BOARD_LOWERCASE STREQUAL "brd4180a")
    set(MCU "EFR32MG21A020F768IM32")
elseif(BOARD_LOWERCASE STREQUAL "brd4180b")
    set(MCU "EFR32MG21A020F1024IM32")
else()

Afterward, you should be able to launch a build with

./script/build efr32mg21 -DBOARD=brd4180a

Longer method

The longer solution would be to make a copy of the board config files so that you aren't tied to the brd4180a config files.

  1. Copy config files to a new folder

    mkdir src/efr32mg21/my-board/
    cp third_party/silabs/sdk_support/hardware/board/config/brd4180a_brd4001a/* src/efr32mg21/my-board/
    cp third_party/silabs/sdk_support/hardware/kit/EFR32MG21_BRD4180A/config/* src/efr32mg21/my-board/
    cp src/efr32mg21/brd4180a/* src/efr32mg21/my-board
  2. Next, edit the appropriate CMake files to include your new board config.

  1. Finally, you should be able to launch a build with
    ./script/build efr32mg21 -DBOARD=my-board
HeFeng1947 commented 2 years ago

Hi @HeFeng1947 ,

While we only officially support a few boards in this repository, there are a couple methods that might achieve what you're trying to do.

Please keep in mind that this is unsupported officially and is not guaranteed to work.

Shorter method

The easiest, albeit a bit crude, solution might be to edit this line so that it defines the correct MCU value for your device

if(BOARD_LOWERCASE STREQUAL "brd4180a")
    set(MCU "EFR32MG21A020F768IM32")
elseif(BOARD_LOWERCASE STREQUAL "brd4180b")
    set(MCU "EFR32MG21A020F1024IM32")
else()

Afterward, you should be able to launch a build with

./script/build efr32mg21 -DBOARD=brd4180a

Longer method

The longer solution would be to make a copy of the board config files so that you aren't tied to the brd4180a config files.

  1. Copy config files to a new folder
mkdir src/efr32mg21/my-board/
cp third_party/silabs/sdk_support/hardware/board/config/brd4180a_brd4001a/* src/efr32mg21/my-board/
cp third_party/silabs/sdk_support/hardware/kit/EFR32MG21_BRD4180A/config/* src/efr32mg21/my-board/
cp src/efr32mg21/brd4180a/* src/efr32mg21/my-board
  1. Next, edit the appropriate CMake files to include your new board config.
if(BOARD_LOWERCASE STREQUAL "brd4180a")
    set(MCU "EFR32MG21A020F1024IM32")
elseif(BOARD_LOWERCASE STREQUAL "brd4180b")
    set(MCU "EFR32MG21A020F1024IM32")
elseif(BOARD_LOWERCASE STREQUAL "my-board")
    set(MCU "EFR32MG21A020F768IM32")
else()
  • third_party/silabs/cmake/includes.cmake:L31

    • Delete this line
    • Note that deleting this line will prevent you from building for other boards
    • An alternative to deleting this line is to revisit Step 1. Instead of copying third_party/silabs/sdk_support/hardware/kit/EFR32MG21_BRD4180A/config/* to src/efr32mg21/my-board/, you could create a copy in the third_party/silabs/sdk_support/hardware/kit/ directory
cp -R third_party/silabs/sdk_support/hardware/kit/EFR32MG21_BRD4180A/ third_party/silabs/sdk_support/hardware/kit/EFR32MG21_MY-BOARD/
file(GLOB gsdk_board_config_dir "${SILABS_GSDK_DIR}/hardware/board/config/*${BOARD_LOWERCASE}*")
list(APPEND SILABS_GSDK_INCLUDES ${gsdk_board_config_dir})
list(APPEND SILABS_GSDK_INCLUDES "${PROJECT_SOURCE_DIR}/src/efr32mg21/my-board")
  1. Finally, you should be able to launch a build with
./script/build efr32mg21 -DBOARD=my-board

Thanks so much for your feedback! I have tried the two methods on your list, but nothing works. I see the definition of Flash in the src/efr32mg21/efr32mg21.ld, but I'm not sure if I should change it

HeFeng1947 commented 2 years ago

I have successfully replaced the chip model of BRD4180A with EFR32MG21A020F768.

The following is the patch:

diff --git a/src/efr32mg21/efr32mg21.cmake b/src/efr32mg21/efr32mg21.cmake
index eaaffdd..0fbdba9 100644
--- a/src/efr32mg21/efr32mg21.cmake
+++ b/src/efr32mg21/efr32mg21.cmake
@@ -30,7 +30,7 @@
 # Verify board is supported for platform
 # ==============================================================================
 if(BOARD_LOWERCASE STREQUAL "brd4180a")
-    set(MCU "EFR32MG21A020F1024IM32")
+    set(MCU "EFR32MG21A020F768IM32")
 elseif(BOARD_LOWERCASE STREQUAL "brd4180b")
     set(MCU "EFR32MG21A020F1024IM32")
 else()
diff --git a/src/efr32mg21/efr32mg21.ld b/src/efr32mg21/efr32mg21.ld
index 3d877e8..15eb9ed 100644
--- a/src/efr32mg21/efr32mg21.ld
+++ b/src/efr32mg21/efr32mg21.ld
@@ -35,8 +35,8 @@

 MEMORY
 {
-  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 1024K
-  RAM (rwx)  : ORIGIN = 0x20000000, LENGTH = 96K
+  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 768K
+  RAM (rwx)  : ORIGIN = 0x20000000, LENGTH = 64K
 }

 /* Linker script to place sections and symbol values. Should be used together