Skip to content

Commit

Permalink
Merge pull request #91 from bitcraze/krichardsson/make-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ataffanel authored Oct 19, 2023
2 parents 18b66fb + 51e3b9f commit 8a6e189
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 44 deletions.
70 changes: 38 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#Put your personal build config in config.mk and DO NOT COMMIT IT!
-include config.mk

PLATFORM ?= cf2
-include platform/platform_$(PLATFORM).mk

CLOAD_SCRIPT ?= python3 -m cfloader

S110 ?= 1 # SoftDevice flashed or not
BLE ?= 1 # BLE mode activated or not. If disabled, CRTP mode is active
DEBUG_PRINT_ON_SEGGER_RTT ?= 0 # debug prints

PLATFORM ?= cf2

CROSS_COMPILE?=arm-none-eabi-

CC=$(CROSS_COMPILE)gcc
Expand Down Expand Up @@ -42,45 +43,50 @@ CFLAGS+=$(PROCESSOR) $(NRF) $(PERSONAL_DEFINES) $(INCLUDES) $(CONFIG) $(BUILD_OP
ASFLAGS=$(PROCESSOR)
LDFLAGS=$(PROCESSOR) --specs=nano.specs -Wl,-Map=$(PROGRAM).map# -Wl,--gc-sections
ifdef SEMIHOSTING
LDFLAGS+= --specs=rdimon.specs -lc -lrdimon
CFLAGS+= -DSEMIHOSTING
LDFLAGS+= --specs=rdimon.specs -lc -lrdimon
CFLAGS+= -DSEMIHOSTING
endif

CFLAGS += -I$(NRF51_SDK)/Include/gcc
CFLAGS += -I$(NRF51_SDK)/Include/

## S110 ################################################################
ifeq ($(strip $(S110)), 1)
LDFLAGS += -T gcc_nrf51_s110_xxaa.ld
CFLAGS += -DS110=1
LDFLAGS += -T gcc_nrf51_s110_xxaa.ld
CFLAGS += -DS110=1

CFLAGS += -I$(NRF_S110)/s110_nrf51822_7.3.0_API/include
CFLAGS += -I$(NRF_S110)/Include/
else
LDFLAGS += -T gcc_nrf51_blank_xxaa.ld
LDFLAGS += -T gcc_nrf51_blank_xxaa.ld
endif

## BLE ################################################################
ifeq ($(strip $(BLE)), 1)
CFLAGS += -DBLE=1
CFLAGS += -DBLE=1

CFLAGS += -DBLE_STACK_SUPPORT_REQD -DNRF51
CFLAGS += -I$(NRF51_SDK)/Include/ble/
CFLAGS += -I$(NRF51_SDK)/Include/ble/ble_services/
CFLAGS += -I$(NRF51_SDK)/Include/ble/device_manager/
CFLAGS += -I$(NRF51_SDK)/Include/app_common/
CFLAGS += -I$(NRF51_SDK)/Include/sd_common/
CFLAGS += -I$(NRF51_SDK)/Include/sdk/

OBJS += src/ble/ble.o
OBJS += src/ble/ble_crazyflies.o
OBJS += src/ble/timeslot.o

OBJS += $(NRF51_SDK)/Source/ble/ble_advdata.o
OBJS += $(NRF51_SDK)/Source/ble/ble_conn_params.o
OBJS += $(NRF51_SDK)/Source/ble/ble_services/ble_srv_common.o
OBJS += $(NRF51_SDK)/Source/ble/ble_services/ble_dis.o
OBJS += $(NRF51_SDK)/Source/ble/device_manager/device_manager_peripheral.o
OBJS += $(NRF51_SDK)/Source/sd_common/softdevice_handler.o
OBJS += $(NRF51_SDK)/Source/app_common/app_timer.o
OBJS += $(NRF51_SDK)/Source/app_common/pstorage.o
endif

OBJS += src/ble/ble.o
OBJS += src/ble/ble_crazyflies.o
OBJS += src/ble/timeslot.o

OBJS += $(NRF51_SDK)/Source/ble/ble_advdata.o
OBJS += $(NRF51_SDK)/Source/ble/ble_conn_params.o
OBJS += $(NRF51_SDK)/Source/ble/ble_services/ble_srv_common.o
OBJS += $(NRF51_SDK)/Source/ble/ble_services/ble_dis.o
OBJS += $(NRF51_SDK)/Source/sd_common/softdevice_handler.o
OBJS += $(NRF51_SDK)/Source/app_common/app_timer.o
OBJS += $(NRF51_SDK)/Source/app_common/pstorage.o
OBJS += $(NRF51_SDK)/Source/ble/device_manager/device_manager_peripheral.o

CFLAGS += -DBLE_STACK_SUPPORT_REQD -DNRF51
CFLAGS += -I$(NRF51_SDK)/Include/gcc
CFLAGS += -I$(NRF51_SDK)/Include/
CFLAGS += -I$(NRF51_SDK)/Include/ble/
CFLAGS += -I$(NRF51_SDK)/Include/ble/ble_services/
CFLAGS += -I$(NRF51_SDK)/Include/ble/device_manager/
CFLAGS += -I$(NRF_S110)/s110_nrf51822_7.3.0_API/include
CFLAGS += -I$(NRF_S110)/Include/
CFLAGS += -I$(NRF51_SDK)/Include/app_common/
CFLAGS += -I$(NRF51_SDK)/Include/sd_common/
CFLAGS += -I$(NRF51_SDK)/Include/sdk/

OBJS += src/main.o gcc_startup_nrf51.o system_nrf51.o src/uart.o \
src/syslink.o src/pm.o src/systick.o src/button.o src/swd.o src/ow.o \
Expand Down
1 change: 1 addition & 0 deletions interface/pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifndef __PM_H__
#define __PM_H__
#include <stdbool.h>
#include <stdint.h>

typedef enum {pmAllOff=0, pmSysOff=1, pmSysPowered=2, pmSysBootSetup=3, pmSysRunning=4} PmState;

Expand Down
2 changes: 2 additions & 0 deletions platform/platform_bolt.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
S110=1
BLE=0
2 changes: 2 additions & 0 deletions platform/platform_cf2.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
S110=1
BLE=1
2 changes: 2 additions & 0 deletions platform/platform_flapper.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
S110=1
BLE=1
2 changes: 2 additions & 0 deletions platform/platform_tag.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
S110=1
BLE=0
7 changes: 3 additions & 4 deletions src/ble/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
/* Core of the Crazyflie bluetooth implementation. Instanciate Crazyflie
* service
*/
#ifndef S110
#error S110 shall be used when using BLE
#endif

#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -40,10 +43,6 @@

#include "ble_crazyflies.h"

#if S110==0
#error S110 shall be used when using BLE
#endif

#define DEVICE_NAME "Crazyflie" /**< Name of device. Will be included in the advertising data. */
#define MANUFACTURER_NAME "Bitcraze" /**< Manufacturer. Will be passed to Device Information Service. */
#define APP_ADV_INTERVAL 200 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 125 ms). */
Expand Down
8 changes: 5 additions & 3 deletions src/esb.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@

#include <nrf.h>

#include <ble_gap.h>
#include <nrf_soc.h>

#define RXQ_LEN 8
#define TXQ_LEN 8

Expand Down Expand Up @@ -468,21 +465,26 @@ void esbSetDatarate(EsbDatarate dr)
esbReset();
}


#ifdef BLE
void ble_advertising_stop(void);
void advertising_start(void);
void ble_sd_stop(void);
#endif

void esbSetContwave(bool enable)
{
contwave = enable;

#ifdef BLE
if (bleEnabled) {
if (enable) {
ble_advertising_stop();
} else {
advertising_start();
}
}
#endif

esbReset();
}
Expand Down
24 changes: 19 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@
#include "pm.h"
#include "pinout.h"
#include "systick.h"
#include "nrf_sdm.h"
#include "nrf_soc.h"
#include "version.h"
#include "shutdown.h"

#ifdef BLE
#include "nrf_sdm.h"
#include "ble_crazyflies.h"
#endif

#include "memory.h"
#include "ownet.h"

#include "ble_crazyflies.h"

extern void initialise_monitor_handles(void);
extern int ble_init(void);
Expand Down Expand Up @@ -115,7 +117,9 @@ int main()
msDelay(1000);

if (bleEnabled) {
#ifdef BLE
ble_init();
#endif
} else {
NRF_CLOCK->TASKS_HFCLKSTART = 1UL;
while(!NRF_CLOCK->EVENTS_HFCLKSTARTED);
Expand Down Expand Up @@ -180,7 +184,7 @@ void mainloop()

while(1)
{

#ifdef BLE
if (bleEnabled) {
if ((esbReceived == false) && bleCrazyfliesIsPacketReceived()) {
EsbPacket* packet = bleCrazyfliesGetRxPacket();
Expand All @@ -190,6 +194,7 @@ void mainloop()
bleCrazyfliesReleaseRxPacket(packet);
}
}
#endif

#ifndef CONT_WAVE_TEST

Expand Down Expand Up @@ -292,6 +297,7 @@ static void handleSyslinkEvents(bool slReceived)
bzero(slRxPacket.data, SYSLINK_MTU);
}

#ifdef BLE
if (bleEnabled) {
if (slRxPacket.length < SYSLINK_MTU) {
static EsbPacket pk;
Expand All @@ -300,6 +306,7 @@ static void handleSyslinkEvents(bool slReceived)
bleCrazyfliesSendPacket(&pk);
}
}
#endif

break;
case SYSLINK_RADIO_CHANNEL:
Expand Down Expand Up @@ -559,9 +566,11 @@ static void handleBootloaderCmd(struct esbPacket_s *packet)
memcpy(&(txpk.data[3]), (uint32_t*)NRF_FICR->DEVICEADDR, 6);

txpk.size = 9;
#ifdef BLE
if (bleEnabled) {
bleCrazyfliesSendPacket(&txpk);
}
#endif

if (esbCanTxPacket()) {
struct esbPacket_s *pk = esbGetTxPacket();
Expand All @@ -580,7 +589,9 @@ static void handleBootloaderCmd(struct esbPacket_s *packet)
NRF_POWER->GPREGRET |= 0x20U;
}
if (bleEnabled) {
#ifdef BLE
sd_nvic_SystemReset();
#endif
} else {
NVIC_SystemReset();
}
Expand Down Expand Up @@ -626,9 +637,12 @@ static void handleBootloaderCmd(struct esbPacket_s *packet)
}

static void disableBle() {
#ifdef BLE
if (bleEnabled) {
sd_softdevice_disable();
bleEnabled = 0;
esbInit();
}
#endif

bleEnabled = 0;
}
5 changes: 5 additions & 0 deletions src/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

#include <nrf.h>
#include <nrf_gpio.h>

#ifdef S110
#include <nrf_soc.h>
#endif

#include "pm.h"
#include "button.h"
Expand Down Expand Up @@ -165,7 +168,9 @@ static void pmNrfPower(bool enable)
NRF_POWER->GPREGRET |= 0x01; // Workaround for not being able to determine reset reason...

if (bleEnabled) {
#ifdef BLE
sd_power_system_off();
#endif
} else {
NRF_POWER->SYSTEMOFF = 1UL;
}
Expand Down

0 comments on commit 8a6e189

Please sign in to comment.