Skip to content

Commit d78f270

Browse files
committed
Merge branch 'feat/spi_std_timing_and_bit_trans' into 'master'
feat(driver_spi): support adjust master rx to standard timing Closes IDF-11396 See merge request espressif/esp-idf!36058
2 parents 057bae8 + 460380b commit d78f270

File tree

20 files changed

+312
-13
lines changed

20 files changed

+312
-13
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
@@ -613,6 +613,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
613613
/*------------------------------------------------------------------------------
614614
* Configs: parameters
615615
*----------------------------------------------------------------------------*/
616+
/**
617+
* Set the standard clock mode for master.
618+
*
619+
* @param hw Beginning address of the peripheral registers.
620+
* @param enable_std True for std timing, False for half cycle delay sampling.
621+
*/
622+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
623+
{
624+
//This is not supported
625+
}
626+
627+
/**
628+
* Get if standard clock mode is supported.
629+
*/
630+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
631+
{
632+
return false;
633+
}
634+
616635
/**
617636
* Set the clock for master by stored value.
618637
*
@@ -650,7 +669,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
650669
*/
651670
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
652671
{
653-
typeof(SPI1.clock) reg;
672+
typeof(SPI1.clock) reg = {.val = 0};
654673
int eff_clk;
655674

656675
//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
@@ -689,6 +689,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
689689
/*------------------------------------------------------------------------------
690690
* Configs: parameters
691691
*----------------------------------------------------------------------------*/
692+
/**
693+
* Set the standard clock mode for master.
694+
*
695+
* @param hw Beginning address of the peripheral registers.
696+
* @param enable_std True for std timing, False for half cycle delay sampling.
697+
*/
698+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
699+
{
700+
//This is not supported
701+
}
702+
703+
/**
704+
* Get if standard clock mode is supported.
705+
*/
706+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
707+
{
708+
return false;
709+
}
710+
692711
/**
693712
* Set the clock for master by stored value.
694713
*
@@ -726,7 +745,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
726745
*/
727746
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
728747
{
729-
typeof(GPSPI2.clock) reg;
748+
typeof(GPSPI2.clock) reg = {.val = 0};
730749
int eff_clk;
731750

732751
//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
@@ -709,6 +709,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
709709
/*------------------------------------------------------------------------------
710710
* Configs: parameters
711711
*----------------------------------------------------------------------------*/
712+
/**
713+
* Set the standard clock mode for master.
714+
*
715+
* @param hw Beginning address of the peripheral registers.
716+
* @param enable_std True for std timing, False for half cycle delay sampling.
717+
*/
718+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
719+
{
720+
//This is not supported
721+
}
722+
723+
/**
724+
* Get if standard clock mode is supported.
725+
*/
726+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
727+
{
728+
return false;
729+
}
730+
712731
/**
713732
* Set the clock for master by stored value.
714733
*
@@ -746,7 +765,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
746765
*/
747766
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
748767
{
749-
typeof(GPSPI2.clock) reg;
768+
typeof(GPSPI2.clock) reg = {.val = 0};
750769
int eff_clk;
751770

752771
//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" {
@@ -688,6 +690,26 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
688690
/*------------------------------------------------------------------------------
689691
* Configs: parameters
690692
*----------------------------------------------------------------------------*/
693+
/**
694+
* Set the standard clock mode for master.
695+
* This config take effect only when SPI_CLK (pre-div before periph) div >=2
696+
*
697+
* @param hw Beginning address of the peripheral registers.
698+
* @param enable_std True for std timing, False for half cycle delay sampling.
699+
*/
700+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
701+
{
702+
hw->clock.clk_edge_sel = (sample_point == SPI_SAMPLING_POINT_PHASE_1);
703+
}
704+
705+
/**
706+
* Get if standard clock mode is supported.
707+
*/
708+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
709+
{
710+
return ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 102);
711+
}
712+
691713
/**
692714
* Set the clock for master by stored value.
693715
*
@@ -725,7 +747,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
725747
*/
726748
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
727749
{
728-
typeof(GPSPI2.clock) reg;
750+
typeof(GPSPI2.clock) reg = {.val = 0};
729751
int eff_clk;
730752

731753
//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
@@ -745,6 +745,25 @@ static inline void spi_ll_master_keep_cs(spi_dev_t *hw, int keep_active)
745745
/*------------------------------------------------------------------------------
746746
* Configs: parameters
747747
*----------------------------------------------------------------------------*/
748+
/**
749+
* Set the standard clock mode for master.
750+
*
751+
* @param hw Beginning address of the peripheral registers.
752+
* @param enable_std True for std timing, False for half cycle delay sampling.
753+
*/
754+
static inline void spi_ll_master_set_rx_timing_mode(spi_dev_t *hw, spi_sampling_point_t sample_point)
755+
{
756+
//This is not supported
757+
}
758+
759+
/**
760+
* Get if standard clock mode is supported.
761+
*/
762+
static inline bool spi_ll_master_is_rx_std_sample_supported(void)
763+
{
764+
return false;
765+
}
766+
748767
/**
749768
* Set the clock for master by stored value.
750769
*
@@ -782,7 +801,7 @@ static inline int spi_ll_freq_for_pre_n(int fapb, int pre, int n)
782801
*/
783802
static inline int spi_ll_master_cal_clock(int fapb, int hz, int duty_cycle, spi_ll_clock_val_t *out_reg)
784803
{
785-
typeof(GPSPI2.clock) reg;
804+
typeof(GPSPI2.clock) reg = {.val = 0};
786805
int eff_clk;
787806

788807
//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)