Skip to content

Commit 206b3a2

Browse files
committed
Merge branch 'feat/spi_std_timing_and_bit_trans_v5.4' into 'release/v5.4'
feat(driver_spi): support adjust master rx to standard timing (v5.4) See merge request espressif/esp-idf!36399
2 parents 473771b + 6c64543 commit 206b3a2

File tree

20 files changed

+313
-16
lines changed

20 files changed

+313
-16
lines changed

components/esp_driver_spi/include/driver/spi_master.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ typedef struct {
7878
delay before the MISO is ready on the line. Leave at 0 unless you know you need a delay. For better timing
7979
performance at high frequency (over 8MHz), it's suggest to have the right value.
8080
*/
81+
spi_sampling_point_t sample_point; ///< Sample point tuning of spi master receiving bit.
8182
int spics_io_num; ///< CS GPIO pin for this device, or -1 if not used
8283
uint32_t flags; ///< Bitwise OR of SPI_DEVICE_* flags
8384
int queue_size; ///< Transaction queue size. This sets how many transactions can be 'in the air' (queued using spi_device_queue_trans but not yet finished using spi_device_get_trans_result) at the same time

components/esp_driver_spi/src/gpspi/spi_master.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ esp_err_t spi_bus_add_device(spi_host_device_t host_id, const spi_device_interfa
487487
SPI_CHECK(ret == ESP_OK, "assigned clock speed not supported", ret);
488488
temp_timing_conf.clock_source = clk_src;
489489
temp_timing_conf.source_pre_div = clock_source_div;
490+
temp_timing_conf.rx_sample_point = dev_config->sample_point;
491+
if (temp_timing_conf.rx_sample_point == SPI_SAMPLING_POINT_PHASE_1) {
492+
SPI_CHECK(spi_ll_master_is_rx_std_sample_supported(), "SPI_SAMPLING_POINT_PHASE_1 is not supported on this chip", ESP_ERR_NOT_SUPPORTED);
493+
}
490494

491495
//Allocate memory for device
492496
dev = malloc(sizeof(spi_device_t));

components/hal/esp32/include/hal/spi_ll.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
611611
/*------------------------------------------------------------------------------
612612
* Configs: parameters
613613
*----------------------------------------------------------------------------*/
614+
/**
615+
* Set the standard clock mode for master.
616+
*
617+
* @param hw Beginning address of the peripheral registers.
618+
* @param enable_std True for std timing, False for half cycle delay sampling.
619+
*/
620+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
621+
{
622+
//This is not supported
623+
}
624+
625+
/**
626+
* Get if standard clock mode is supported.
627+
*/
628+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
629+
{
630+
return false;
631+
}
632+
614633
/**
615634
* Set the clock for master by stored value.
616635
*
@@ -648,7 +667,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
648667
*/
649668
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
650669
{
651-
typeof(SPI1.clock) reg;
670+
typeof(SPI1.clock) reg = {.val = 0};
652671
int eff_clk;
653672

654673
//In hw, n, h and l are 1-64, pre is 1-8K. Value written to register is one lower than used value.

components/hal/esp32c2/include/hal/spi_ll.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
696696
/*------------------------------------------------------------------------------
697697
* Configs: parameters
698698
*----------------------------------------------------------------------------*/
699+
/**
700+
* Set the standard clock mode for master.
701+
*
702+
* @param hw Beginning address of the peripheral registers.
703+
* @param enable_std True for std timing, False for half cycle delay sampling.
704+
*/
705+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
706+
{
707+
//This is not supported
708+
}
709+
710+
/**
711+
* Get if standard clock mode is supported.
712+
*/
713+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
714+
{
715+
return false;
716+
}
717+
699718
/**
700719
* Set the clock for master by stored value.
701720
*
@@ -733,7 +752,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
733752
*/
734753
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
735754
{
736-
typeof(GPSPI2.clock) reg;
755+
typeof(GPSPI2.clock) reg = {.val = 0};
737756
int eff_clk;
738757

739758
//In hw, n, h and l are 1-64, pre is 1-8K. Value written to register is one lower than used value.

components/hal/esp32c3/include/hal/spi_ll.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
698698
/*------------------------------------------------------------------------------
699699
* Configs: parameters
700700
*----------------------------------------------------------------------------*/
701+
/**
702+
* Set the standard clock mode for master.
703+
*
704+
* @param hw Beginning address of the peripheral registers.
705+
* @param enable_std True for std timing, False for half cycle delay sampling.
706+
*/
707+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
708+
{
709+
//This is not supported
710+
}
711+
712+
/**
713+
* Get if standard clock mode is supported.
714+
*/
715+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
716+
{
717+
return false;
718+
}
719+
701720
/**
702721
* Set the clock for master by stored value.
703722
*
@@ -735,7 +754,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
735754
*/
736755
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
737756
{
738-
typeof(GPSPI2.clock) reg;
757+
typeof(GPSPI2.clock) reg = {.val = 0};
739758
int eff_clk;
740759

741760
//In hw, n, h and l are 1-64, pre is 1-8K. Value written to register is one lower than used value.

components/hal/esp32c5/include/hal/spi_ll.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
696696
/*------------------------------------------------------------------------------
697697
* Configs: parameters
698698
*----------------------------------------------------------------------------*/
699+
/**
700+
* Set the standard clock mode for master.
701+
*
702+
* @param hw Beginning address of the peripheral registers.
703+
* @param enable_std True for std timing, False for half cycle delay sampling.
704+
*/
705+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
706+
{
707+
//This is not supported
708+
}
709+
710+
/**
711+
* Get if standard clock mode is supported.
712+
*/
713+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
714+
{
715+
return false;
716+
}
717+
699718
/**
700719
* Set the clock for master by stored value.
701720
*
@@ -733,7 +752,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
733752
*/
734753
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
735754
{
736-
typeof(GPSPI2.clock) reg;
755+
typeof(GPSPI2.clock) reg = {.val = 0};
737756
int eff_clk;
738757

739758
//In hw, n, h and l are 1-64, pre is 1-8K. Value written to register is one lower than used value.

components/hal/esp32c6/include/hal/spi_ll.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
690690
/*------------------------------------------------------------------------------
691691
* Configs: parameters
692692
*----------------------------------------------------------------------------*/
693+
/**
694+
* Set the standard clock mode for master.
695+
*
696+
* @param hw Beginning address of the peripheral registers.
697+
* @param enable_std True for std timing, False for half cycle delay sampling.
698+
*/
699+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
700+
{
701+
//This is not supported
702+
}
703+
704+
/**
705+
* Get if standard clock mode is supported.
706+
*/
707+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
708+
{
709+
return false;
710+
}
711+
693712
/**
694713
* Set the clock for master by stored value.
695714
*
@@ -727,7 +746,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
727746
*/
728747
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
729748
{
730-
typeof(GPSPI2.clock) reg;
749+
typeof(GPSPI2.clock) reg = {.val = 0};
731750
int eff_clk;
732751

733752
//In hw, n, h and l are 1-64, pre is 1-8K. Value written to register is one lower than used value.

components/hal/esp32c61/include/hal/spi_ll.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
710710
/*------------------------------------------------------------------------------
711711
* Configs: parameters
712712
*----------------------------------------------------------------------------*/
713+
/**
714+
* Set the standard clock mode for master.
715+
*
716+
* @param hw Beginning address of the peripheral registers.
717+
* @param enable_std True for std timing, False for half cycle delay sampling.
718+
*/
719+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
720+
{
721+
//This is not supported
722+
}
723+
724+
/**
725+
* Get if standard clock mode is supported.
726+
*/
727+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
728+
{
729+
return false;
730+
}
731+
713732
/**
714733
* Set the clock for master by stored value.
715734
*
@@ -747,7 +766,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
747766
*/
748767
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
749768
{
750-
typeof(GPSPI2.clock) reg;
769+
typeof(GPSPI2.clock) reg = {.val = 0};
751770
int eff_clk;
752771

753772
//In hw, n, h and l are 1-64, pre is 1-8K. Value written to register is one lower than used value.

components/hal/esp32h2/include/hal/spi_ll.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
#include "esp_types.h"
2121
#include "soc/spi_periph.h"
2222
#include "soc/spi_struct.h"
23+
#include "soc/chip_revision.h"
24+
#include "soc/pcr_struct.h"
2325
#include "soc/lldesc.h"
2426
#include "hal/assert.h"
2527
#include "hal/misc.h"
28+
#include "hal/efuse_hal.h"
2629
#include "hal/spi_types.h"
27-
#include "soc/pcr_struct.h"
2830

2931
#ifdef __cplusplus
3032
extern "C" {
@@ -689,6 +691,26 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
689691
/*------------------------------------------------------------------------------
690692
* Configs: parameters
691693
*----------------------------------------------------------------------------*/
694+
/**
695+
* Set the standard clock mode for master.
696+
* This config take effect only when SPI_CLK (pre-div before periph) div >=2
697+
*
698+
* @param hw Beginning address of the peripheral registers.
699+
* @param enable_std True for std timing, False for half cycle delay sampling.
700+
*/
701+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
702+
{
703+
hw->clock.clk_edge_sel = (sample_point == SPI_SAMPLING_POINT_PHASE_1);
704+
}
705+
706+
/**
707+
* Get if standard clock mode is supported.
708+
*/
709+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
710+
{
711+
return ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 102);
712+
}
713+
692714
/**
693715
* Set the clock for master by stored value.
694716
*
@@ -726,7 +748,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
726748
*/
727749
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
728750
{
729-
typeof(GPSPI2.clock) reg;
751+
typeof(GPSPI2.clock) reg = {.val = 0};
730752
int eff_clk;
731753

732754
//In hw, n, h and l are 1-64, pre is 1-8K. Value written to register is one lower than used value.

components/hal/esp32p4/include/hal/spi_ll.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
746746
/*------------------------------------------------------------------------------
747747
* Configs: parameters
748748
*----------------------------------------------------------------------------*/
749+
/**
750+
* Set the standard clock mode for master.
751+
*
752+
* @param hw Beginning address of the peripheral registers.
753+
* @param enable_std True for std timing, False for half cycle delay sampling.
754+
*/
755+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
756+
{
757+
//This is not supported
758+
}
759+
760+
/**
761+
* Get if standard clock mode is supported.
762+
*/
763+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
764+
{
765+
return false;
766+
}
767+
749768
/**
750769
* Set the clock for master by stored value.
751770
*
@@ -783,7 +802,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
783802
*/
784803
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
785804
{
786-
typeof(GPSPI2.clock) reg;
805+
typeof(GPSPI2.clock) reg = {.val = 0};
787806
int eff_clk;
788807

789808
//In hw, n, h and l are 1-64, pre is 1-8K. Value written to register is one lower than used value.

0 commit comments

Comments
 (0)