Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
clydebarrow committed Mar 23, 2017
0 parents commit 81f66df
Show file tree
Hide file tree
Showing 39 changed files with 11,514 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ota_service.txt
ota_key.txt
build-debug/
build-release/
.idea/
.DS_store
cmake-build-debug/

68 changes: 68 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.6)
project(bgbootload)

set(CMAKE_C_STANDARD 99)
add_definitions(-D__NO_SYSTEM_INIT)
add_definitions(-DEFR32BG1B232F256GM48)
add_definitions(-D__FPU_PRESENT)

include_directories(inc)
include_directories(gatt)
include_directories(libs/SEGGER_RTT_V612j/RTT)
include_directories(platform/emlib/inc)
include_directories(platform/Device/SiliconLabs/EFR32BG1B/Include)
include_directories(platform/CMSIS/Include)

set(GATT_DB gatt_db)
set(GATT_DIR ${CMAKE_SOURCE_DIR}/gatt)
set(BLE_STACK_DIR ${CMAKE_SOURCE_DIR}/libs/ble.v2.1.1.0)
set(GATT_SRC ${GATT_DIR}/gatt.bgproj)
set(GATT_XML ${GATT_DIR}/gatt.xml)
set(GATT_OUTPUTS ${GATT_DIR}/${GATT_DB}.c ${GATT_DIR}/${GATT_DB}.h)
set(BGBUILD_CMD "/Users/clyde/dev/tools/ble/v2.1.1.0/protocol/bluetooth_2.1/bin/bgbuild")
set(EBL_CMD "/Applications/Simplicity Studio.app/Contents/Eclipse/developer/adapter_packs/commander/Commander.app/Contents/MacOS/commander")

file(GLOB_RECURSE USER_SOURCES "src/*.c")
file(GLOB_RECURSE USER_HEADERS "inc/*.h")

IF (CMAKE_BUILD_TYPE MATCHES Debug)
file(GLOB_RECURSE RTT_LIBS "libs/SEGGER_RTT_V612j/RTT/*.c")
add_definitions(-DDEBUG)
ENDIF (CMAKE_BUILD_TYPE MATCHES Debug)

set(LIBRARIES ${BLE_STACK_DIR}/stack.a ${BLE_STACK_DIR}/binstack.o )
SET(LINKER_SCRIPT bgbootload.ld)
set(STARTUP "src/startup.c")
#set_property(SOURCE ${STARTUP} PROPERTY LANGUAGE C)


# add library sources needed

SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.ld)
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${LINKER_SCRIPT} --specs=nosys.specs")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_NAME}.map")

add_custom_command(
OUTPUT ${GATT_OUTPUTS}
DEPENDS ${GATT_SRC} ${GATT_XML}
COMMAND ${BGBUILD_CMD} -gn ${GATT_SRC})
set_source_files_properties(${GATT_OUTPUTS} PROPERTIES GENERATED TRUE)

add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${USER_HEADERS} ${LINKER_SCRIPT} gatt/${GATT_DB}.c ${RTT_LIBS})
target_link_libraries(${PROJECT_NAME}.elf ${LIBRARIES})
set_target_properties(${PROJECT_NAME}.elf PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT})

set(BIN_FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Obinary --gap-fill 255 $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${BIN_FILE}"
COMMAND ${OBJSIZE} ${PROJECT_NAME}.elf)

IF (CMAKE_BUILD_TYPE MATCHES Release)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Osrec -j .text_stack\* $<TARGET_FILE:${PROJECT_NAME}.elf> file.srec
COMMAND ${CMAKE_OBJCOPY} -Osrec -j .text_app\* $<TARGET_FILE:${PROJECT_NAME}.elf> file.srec
#COMMAND rm file.srec
)
ENDIF (CMAKE_BUILD_TYPE MATCHES Release)

15 changes: 15 additions & 0 deletions EFR32BG1.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
INCLUDE(CMakeForceCompiler)

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)

set(GCC_DIR /Users/clyde/dev/tools/4.9_2015q3)
set(OBJSIZE ${GCC_DIR}/bin/arm-none-eabi-size)
# specify the cross compiler
CMAKE_FORCE_C_COMPILER(${GCC_DIR}/bin/arm-none-eabi-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(${GCC_DIR}/bin/arm-none-eabi-g++ GNU)

#SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=soft -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
SET(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
SET(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
201 changes: 201 additions & 0 deletions bgbootload.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/* Linker script for Silicon Labs EFR32MG1P devices */
/* */
/* This file is subject to the license terms as defined in ARM's */
/* CMSIS END USER LICENSE AGREEMENT.pdf, governing the use of */
/* Example Code. */
/* */
/* Silicon Laboratories, Inc. 2015 */
/* */
/* Version 4.1.1 */
/* */
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000
RAM (rwx) : ORIGIN = 0x20003000, LENGTH = 0x4C00-4
}

/* This is the linker script for the bootloader.

Linker script to place sections and symbol values. Should be used together
* with other linker script that defines memory regions FLASH and RAM.
* It references following symbols, which must be defined in code:
* Reset_Handler : Entry of reset handler
*
* It defines following symbols, which code can use without definition:
* __exidx_start
* __exidx_end
* __copy_table_start__
* __copy_table_end__
* __zero_table_start__
* __zero_table_end__
* __etext
* __data_start__
* __preinit_array_start
* __preinit_array_end
* __init_array_start
* __init_array_end
* __fini_array_start
* __fini_array_end
* __data_end__
* __bss_start__
* __bss_end__
* __end__
* end
* __HeapLimit
* __StackLimit
* __StackTop
* __stack
* __Vectors_End
* __Vectors_Size
*/
ENTRY(Reset_Handler)

SECTIONS
{
/* At zero; start with the vector table for the bootloader main. */
.boot_vectors :
{
KEEP(*(.vectors))
__Vectors_End = .;
__Vectors_Size = __Vectors_End - __Vectors;
} > FLASH

/* The next major section will be at 0x4000 so pack some other
in here as well so it's not wasted. */
.text_app_ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH

__exidx_start = .;
.text_app_ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;

.gecko_table :
{
KEEP(*(.gecko_configuration))
KEEP(*(.xo_configuration))
KEEP(*(.gatt_header))
KEEP(*(.gatt_data))
KEEP(*(.init))
KEEP(*(.fini))
*(.text*)
/* .ctors */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)

/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)

*(.rodata*)

KEEP(*(.eh_frame*))
} > FLASH

__etext = .;

_stack_start = 0x4000;
.text_stack_bin _stack_start :
{
__stack_AAT = .;
KEEP(*(.binstack*))
__end__ = .;
. = ALIGN(0x800);
}> FLASH

/* here goes the dfu app ATT, vectors */
.dfu_text :
{
KEEP(*(.AAT))
. = ALIGN(0x80);
__dfu_VectorTable = .;
KEEP(*(.dfu_vectors))
. = ALIGN(4);
} >FLASH

.text_app_data : AT (__etext)
{
__data_start__ = .;
*(vtable)
*(.data*)
. = ALIGN (4);
*(.ram)

. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);

. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);

KEEP(*(.jcr*))
. = ALIGN(4);
/* All data end */
__data_end__ = .;

} > RAM

.bss :
{
. = ALIGN(4);
__bss_start__ = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > RAM

.heap (COPY):
{
__HeapBase = .;
__end__ = .;
end = __end__;
_end = __end__;
KEEP(*(.heap*))
__HeapLimit = .;
} > RAM

/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy (COPY):
{
KEEP(*(.stack*))
} > RAM
__padding = (((__etext + SIZEOF(.text_app_data) +16 +0x800-1)&0xFFFFF800)-16) - (__etext + SIZEOF(.text_app_data));

/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);

/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")

/* Check if FLASH usage exceeds FLASH size */
/*ASSERT( LENGTH(FLASH) >= (__etext + SIZEOF(.data)), "FLASH memory overflowed !")*/
}
6 changes: 6 additions & 0 deletions gatt/constants
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
service_changed_char 3
serialnum 16
hwrev 18
fwrev 20
ota_control 23
ota_data 26
8 changes: 8 additions & 0 deletions gatt/gatt.bgproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>

<project device="bgm111">

<!-- GATT service database -->
<gatt in="gatt.xml" />

</project>
69 changes: 69 additions & 0 deletions gatt/gatt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>

<gatt prefix="GATTDB_" out="gatt_db.c" header="gatt_db.h" generic_attribute_service="true">

<!-- Generic Access Service -->
<!-- https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.generic_access.xml -->
<service uuid="1800">

<!-- Device Name -->
<!-- https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.device_name.xml -->
<characteristic uuid="2a00">
<properties read="true" const="true"/>
<value>BG_OTA_DFU</value><!-- TODO:: Set value or change type to "user" and add handling for it -->
</characteristic>

<!-- Appearance -->
<!-- https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml -->
<characteristic uuid="2a01">
<properties read="true" const="true"/>
<value type="hex">0000</value><!-- TODO:: Set value or change type to "user" and add handling for it -->
</characteristic>

</service>

<!-- Device Information Service -->
<service uuid="180A">
<!-- Manufacturer name string -->
<characteristic uuid="2A29">
<properties read="true" const="true"/>
<value>Your name goes here</value>
</characteristic>
<!-- Model number string -->
<characteristic uuid="2A24">
<properties read="true" const="true"/>
<value>1</value>
</characteristic>
<!-- Serial number string -->
<characteristic uuid="2A23" id="serialnum">
<properties read="true"/>
<value length="16" const="true" variable_length="true">sernum</value>
</characteristic>
<!-- Hardware revision -->
<characteristic uuid="2A27" id="hwrev">
<properties read="true" const="true"/>
<value>1</value>
</characteristic>
<!-- Firmware revision -->
<characteristic uuid="2A27" id="fwrev">
<properties read="true" const="true"/>
<value>1.0</value>
</characteristic>
</service>

<service uuid="95301000-963F-46B1-B801-0B23E8904835">
<description>EFR32BG OTA</description>
<characteristic uuid="95301001-963F-46B1-B801-0B23E8904835" id="ota_control">
<properties write="true"/>
<value length="8" type="user"/>
<description>OTA CTRL</description>
</characteristic>
<characteristic uuid="95301002-963F-46B1-B801-0B23E8904835" id="ota_data">
<properties write="true" write_no_response="true"/>
<value length="20"/>
<description>OTA DATA</description>
</characteristic>
</service>


</gatt>
Loading

0 comments on commit 81f66df

Please sign in to comment.