Skip to content

Commit ceef804

Browse files
committed
Enable PA on all platforms
1 parent 6c607c9 commit ceef804

File tree

6 files changed

+183
-18
lines changed

6 files changed

+183
-18
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SRC_FILES += \
4444
$(PROJ_DIR)/uart.c \
4545
$(PROJ_DIR)/bootloader.c \
4646
$(PROJ_DIR)/crc.c \
47+
$(PROJ_DIR)/platform.c \
4748
$(SDK_ROOT)/external/segger_rtt/RTT_Syscalls_GCC.c \
4849
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
4950
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \

config/custom_board.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050

5151
#define STM_NRST_PIN 21
5252

53+
#define RADIO_PAEN_PIN 19
54+
#define RADIO_PATX_DIS_PIN 20
55+
5356
// Pins if RFX2411N is used
5457
#define RADIO_PA_RX_EN 20
5558
#define RADIO_PA_ANT_SW 18

src/crazyflie2_pm.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "nrf.h"
44
#include "nrf_gpio.h"
55
#include "boards.h"
6+
#include "platform.h"
67

78
static pm_state_t m_state = PM_STATE_OFF;
89

@@ -28,24 +29,37 @@ void crazyflie2_pm_init(void) {
2829
// todo: setup analog measurement
2930

3031
// Setup radio PA
31-
nrf_gpio_cfg_output(RADIO_PA_RX_EN);
32-
nrf_gpio_cfg_output(RADIO_PA_MODE);
33-
nrf_gpio_cfg_output(RADIO_PA_ANT_SW);
32+
if (platformHasRfx2411n()) {
33+
// Enable RF power amplifier
34+
nrf_gpio_cfg_output(RADIO_PA_RX_EN);
35+
nrf_gpio_cfg_output(RADIO_PA_MODE);
36+
nrf_gpio_cfg_output(RADIO_PA_ANT_SW);
37+
#ifdef USE_EXT_ANTENNA
38+
// Select u.FL antenna
39+
nrf_gpio_pin_clear(RADIO_PA_ANT_SW);
40+
#else
41+
// Select chip antenna
42+
nrf_gpio_pin_set(RADIO_PA_ANT_SW);
43+
#endif
3444

35-
#ifdef USE_EXT_ANTENNA
36-
// Select u.FL antenna
37-
nrf_gpio_pin_clear(RADIO_PA_ANT_SW);
38-
#else
39-
// Select chip antenna
40-
nrf_gpio_pin_set(RADIO_PA_ANT_SW);
41-
#endif
45+
#ifdef RFX2411N_BYPASS_MODE
46+
nrf_gpio_pin_set(RADIO_PA_MODE);
47+
#else
48+
nrf_gpio_pin_set(RADIO_PA_RX_EN);
49+
nrf_gpio_pin_clear(RADIO_PA_MODE);
50+
#endif
51+
} else {
52+
// Enable RF power amplifier
53+
nrf_gpio_cfg_output(RADIO_PAEN_PIN);
4254

43-
#ifdef RFX2411N_BYPASS_MODE
44-
nrf_gpio_pin_set(RADIO_PA_MODE);
45-
#else
46-
nrf_gpio_pin_set(RADIO_PA_RX_EN);
47-
nrf_gpio_pin_clear(RADIO_PA_MODE);
48-
#endif
55+
#ifdef DISABLE_PA
56+
nrf_gpio_pin_clear(RADIO_PAEN_PIN);
57+
nrf_gpio_cfg_output(RADIO_PATX_DIS_PIN);
58+
nrf_gpio_pin_clear(RADIO_PATX_DIS_PIN);
59+
#else
60+
nrf_gpio_pin_set(RADIO_PAEN_PIN);
61+
#endif
62+
}
4963

5064
crazyflie2_pm_set_state(PM_STATE_SYSTEM_OFF);
5165
}

src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include "uart.h"
7979
#include "systick.h"
8080
#include "bootloader.h"
81+
#include "platform.h"
8182

8283
#include "crtp.h"
8384

@@ -549,6 +550,8 @@ int main(void)
549550
uint32_t err_code;
550551
static char address[5];
551552

553+
platformInitByDeviceType();
554+
552555
sd_mbr_command(&startSdCmd);
553556
sd_softdevice_vector_table_base_set(BOOTLOADER_ADDRESS);
554557

@@ -585,8 +588,8 @@ int main(void)
585588
// err_code = syslinkInit();
586589
// APP_ERROR_CHECK(err_code);
587590

588-
// crazyflie2_pm_init();
589-
// crazyflie2_pm_set_state(PM_STATE_SYSTEM_ON);
591+
crazyflie2_pm_init();
592+
crazyflie2_pm_set_state(PM_STATE_SYSTEM_ON);
590593

591594
err_code = app_mailbox_create(&m_uplink);
592595
APP_ERROR_CHECK(err_code);

src/platform.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "platform.h"
2+
3+
#include <string.h>
4+
#include <nrf.h>
5+
6+
static const char *defaultDeviceType = "0;CF20;R=D";
7+
8+
static char *deviceTypeStringLocation = (void*)PLATFORM_DEVICE_DATA_FLASH_POS;
9+
10+
static bool has_rfx2411n = false;
11+
12+
void platformGetDeviceTypeString(char *deviceTypeString)
13+
{
14+
if (deviceTypeStringLocation[0] == 0xffu) {
15+
strncpy(deviceTypeString, defaultDeviceType, 32);
16+
deviceTypeString[32] = 0;
17+
} else {
18+
strncpy(deviceTypeString, deviceTypeStringLocation, 32);
19+
deviceTypeString[32] = 0;
20+
}
21+
}
22+
23+
/**
24+
* Parse deviceType string to extract the deviceType
25+
*
26+
* Ignores the key=value sections.
27+
*
28+
* \param [in] deviceTypeString deviceTypeString extracted from the hardware
29+
* \param [out] deviceType Buffer of at least PLATFORM_DEVICE_TYPE_MAX_LEN
30+
* bytes where the device type will be stored
31+
* \return 0 in case of success, 1 in case of failure.
32+
*/
33+
static int platformParseDeviceTypeString(char* deviceTypeString, char* deviceType) {
34+
// char *state;
35+
36+
memcpy(deviceType, deviceTypeString+2, 4);
37+
deviceType[4] = '\0';
38+
39+
return 0;
40+
}
41+
42+
// This function configures the platform in runtime based on the device type.
43+
// The main reason to not move it into the platform files is that if a user
44+
// flashes the wrong binary in the NRF we still want it to start up.
45+
int platformInitByDeviceType() {
46+
static char deviceTypeString[PLATFORM_DEVICE_TYPE_STRING_MAX_LEN];
47+
static char deviceType[PLATFORM_DEVICE_TYPE_MAX_LEN];
48+
49+
platformGetDeviceTypeString(deviceTypeString);
50+
if (platformParseDeviceTypeString(deviceTypeString, deviceType) != 0) {
51+
return 1;
52+
}
53+
54+
if (0 == strcmp(deviceType, "CF20")) {
55+
has_rfx2411n = false;
56+
57+
} else if (0 == strcmp(deviceType, "CF21")) {
58+
has_rfx2411n = true;
59+
60+
} else if (0 == strcmp(deviceType, "RR10")) {
61+
has_rfx2411n = true;
62+
63+
} else if ((0 == strcmp(deviceType, "RZ10")) ||
64+
(0 == strcmp(deviceType, "CB10")) ||
65+
(0 == strcmp(deviceType, "CB11"))) {
66+
has_rfx2411n = true;
67+
68+
} else {
69+
has_rfx2411n = false;
70+
}
71+
72+
return 0;
73+
}
74+
75+
bool platformHasRfx2411n() {
76+
return has_rfx2411n;
77+
}

src/platform.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* || ____ _ __
3+
* +------+ / __ )(_) /_______________ _____ ___
4+
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
5+
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
6+
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
7+
*
8+
* Crazyflie 2.0 NRF Firmware
9+
* Copyright (c) 2024, Bitcraze AB, All rights reserved.
10+
*
11+
* This library is free software; you can redistribute it and/or
12+
* modify it under the terms of the GNU Lesser General Public
13+
* License as published by the Free Software Foundation; either
14+
* version 3.0 of the License, or (at your option) any later version.
15+
*
16+
* This library is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
* Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public
22+
* License along with this library.
23+
*/
24+
#pragma once
25+
26+
#include <stdint.h>
27+
#include <stdbool.h>
28+
29+
#define PLATFORM_DEVICE_DATA_FLASH_POS 0x3FFE0
30+
#define PLATFORM_DEVICE_TYPE_STRING_MAX_LEN 33
31+
#define PLATFORM_DEVICE_TYPE_MAX_LEN 31
32+
33+
/**
34+
* Fetch deviceType string from flash
35+
*
36+
* This function defaults to "0;CF20;R=D" if no string is present in the
37+
* hardware
38+
*
39+
* \param [out] deviceTypeString Buffer of at least
40+
* PLATFORM_DEVICE_TYPE_STRING_MAX_LEN bytes
41+
* where the platform string will be stored
42+
*/
43+
void platformGetDeviceTypeString(char *deviceTypeString);
44+
45+
/**
46+
* Initialize the platform
47+
*
48+
* Initialize the platform discovering capabilities and returns if it has been successful
49+
*
50+
* \return 0 in case of success, 1 in case of failure.
51+
*/
52+
int platformInit();
53+
54+
/**
55+
* Initialize the platform based on device type
56+
*
57+
* Generic initialization based on device type
58+
*
59+
* \return 0 in case of success, 1 in case of failure.
60+
*/
61+
int platformInitByDeviceType();
62+
63+
// ************** Capabilities functions **************
64+
// The following functions can be implemented by different platform to give
65+
// access to the current device capabilities. Not all platform has to implement
66+
// all functions
67+
bool platformHasRfx2411n();

0 commit comments

Comments
 (0)