Skip to content

Commit

Permalink
driver/at86rf215: add functions to set trim & clock output at run-time
Browse files Browse the repository at this point in the history
To calibrate the at86rf215 radio, trim value has to be set at run-time
during board production.
Add two helper functions to control the trim value and clock output register.
  • Loading branch information
benpicco committed Dec 2, 2020
1 parent 5d248a1 commit 2ccc91e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/at86rf215/at86rf215.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ if (!IS_ACTIVE(CONFIG_AT86RF215_USE_CLOCK_OUTPUT)){
}
/* allow to configure board-specific trim */
#ifdef CONFIG_AT86RF215_TRIM_VAL
at86rf215_reg_write(dev, RG_RF_XOC, CONFIG_AT86RF215_TRIM_VAL | XOC_FS_MASK);
at86rf215_set_trim(dev, CONFIG_AT86RF215_TRIM_VAL);
#endif

/* enable TXFE & RXFE IRQ */
Expand Down
12 changes: 12 additions & 0 deletions drivers/at86rf215/at86rf215_getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ uint8_t at86rf215_get_chan(const at86rf215_t *dev)
return at86rf215_reg_read16(dev, dev->RF->RG_CNL);
}

void at86rf215_set_trim(at86rf215_t *dev, uint8_t trim)
{
assert(trim <= 0xF);
at86rf215_reg_write(dev, RG_RF_XOC, trim | XOC_FS_MASK);
}

void at86rf215_set_clock_output(at86rf215_t *dev,
at86rf215_clko_cur_t cur, at86rf215_clko_freq_t freq)
{
at86rf215_reg_write(dev, RG_RF_CLKO, cur | freq);
}

void at86rf215_set_chan(at86rf215_t *dev, uint16_t channel)
{
at86rf215_await_state_end(dev, RF_STATE_TX);
Expand Down
63 changes: 63 additions & 0 deletions drivers/include/at86rf215.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,33 @@ enum {
AT86RF215_MODE_MR_FSK
};

/**
* @name Clock Output Driver Strength
* @{
*/
typedef enum {
AT86RF215_CLKO_2mA = 0 << 3, /**< 2 mA */
AT86RF215_CLKO_4mA = 1 << 3, /**< 4 mA */
AT86RF215_CLKO_6mA = 2 << 3, /**< 6 mA */
AT86RF215_CLKO_8mA = 3 << 3, /**< 8 mA */
} at86rf215_clko_cur_t;
/** @} */

/**
* @name Clock Output Frequency
* @{
*/
typedef enum {
AT86RF215_CLKO_OFF = 0, /**< Clock Output Disabled */
AT86RF215_CLKO_26_MHz, /**< 26 MHz */
AT86RF215_CLKO_32_MHz, /**< 32 MHz */
AT86RF215_CLKO_16_MHz, /**< 16 MHz */
AT86RF215_CLKO_8_MHz, /**< 8 MHz */
AT86RF215_CLKO_4_MHz, /**< 4 MHz */
AT86RF215_CLKO_2_MHz, /**< 2 MHz */
AT86RF215_CLKO_1_MHz, /**< 1 MHz */
} at86rf215_clko_freq_t;

/**
* @name Internal device option flags
* @{
Expand Down Expand Up @@ -526,6 +553,42 @@ int8_t at86rf215_get_ed_level(at86rf215_t *dev);
*/
void at86rf215_set_option(at86rf215_t *dev, uint16_t option, bool state);

/**
* @brief Set crystal oscillator trim value.
*
* An internal capacitance array is connected to the
* crystal oscillator pins TCXO and XTAL2.
*
* Each increment of the trim value adds 0.3pF capacitance
* to the oscillator circuit.
*
* To trim a board, enable the clock output with
* @ref at86rf215_set_clock_output and connect a frequency
* counter to the clock output pin.
* Then adjust the trim value until it the measured frequency
* closely matches the configured output frequency.
*
* It is recommended to use a 26 MHz output frequency for the
* test as this is the raw frequency of the external oscillator.
*
* The resulting trim value must then be stored in a persistent
* memory area of the board to be set via @ref CONFIG_AT86RF215_TRIM_VAL
*
* @param[in] dev device to configure
* @param[in] trim trim value
*/
void at86rf215_set_trim(at86rf215_t *dev, uint8_t trim);

/**
* @brief Configure the Clock Output pin
*
* @param[in] dev device to configure
* @param[in] cur Clock output current
* @param[in] freq Clock output frequency
*/
void at86rf215_set_clock_output(at86rf215_t *dev,
at86rf215_clko_cur_t cur, at86rf215_clko_freq_t freq);

/**
* @brief Convenience function for simply sending data
*
Expand Down

0 comments on commit 2ccc91e

Please sign in to comment.