Skip to content

Commit 16d5b85

Browse files
YuguoWHWayne Ren
authored andcommitted
board: emsdp: fix spi byte loss issue in redpine wifi
adjust spi clk config,the old value may be too fast Signed-off-by: Yuguo Zou <[email protected]>
1 parent 6e59778 commit 16d5b85

File tree

4 files changed

+16
-58
lines changed

4 files changed

+16
-58
lines changed

board/emsdp/drivers/ip/subsystem/spi/dfss_spi_obj.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static SS_SPI_MASTER_DEV_CONTEXT spi_master_context0 = {
5555
IO_SPI_MST0_INT_TX_REQ,
5656
IO_SPI_MST0_INT_IDLE,
5757
IO_SPI_MST0_INT_ERR,
58-
BOARD_SPI_FREQ,
58+
EMSDP_SPI_REF_CLOCK,
5959
0,
6060
spi_rx_cb0,
6161
spi_tx_cb0,
@@ -110,7 +110,7 @@ static void dfss_spi_0_install(void)
110110
spi_master_context0.info = info;
111111
/** spi info init */
112112
info->status = DEV_DISABLED;
113-
info->freq = 2000000;
113+
info->freq = 1000000;
114114
info->opn_cnt = 0;
115115
info->mode = DEV_MASTER_MODE;
116116
info->clk_mode = SPI_CLK_MODE_DEFAULT;
@@ -143,7 +143,7 @@ static SS_SPI_MASTER_DEV_CONTEXT spi_master_context1 = {
143143
IO_SPI_MST1_INT_TX_REQ,
144144
IO_SPI_MST1_INT_IDLE,
145145
IO_SPI_MST1_INT_ERR,
146-
BOARD_SPI_FREQ,
146+
EMSDP_SPI_REF_CLOCK,
147147
0,
148148
spi_rx_cb1,
149149
spi_tx_cb1,
@@ -198,7 +198,7 @@ static void dfss_spi_1_install(void)
198198
spi_master_context1.info = info;
199199
/** spi info init */
200200
info->status = DEV_DISABLED;
201-
info->freq = 2000000;
201+
info->freq = 1000000;
202202
info->opn_cnt = 0;
203203
info->mode = DEV_MASTER_MODE;
204204
info->clk_mode = SPI_CLK_MODE_DEFAULT;
@@ -232,7 +232,7 @@ static SS_SPI_MASTER_DEV_CONTEXT spi_master_context2 = {
232232
IO_SPI_MST2_INT_TX_REQ,
233233
IO_SPI_MST2_INT_IDLE,
234234
IO_SPI_MST2_INT_ERR,
235-
BOARD_SPI_FREQ,
235+
EMSDP_SPI_REF_CLOCK,
236236
0,
237237
spi_rx_cb2,
238238
spi_tx_cb2,

board/emsdp/emsdp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@
5959
#define BOARD_CONSOLE_UART_ID DW_UART_0_ID
6060
#define BOARD_CONSOLE_UART_BAUD UART_BAUDRATE_115200
6161

62+
6263
#ifndef BOARD_SPI_FREQ
63-
#define BOARD_SPI_FREQ EMSDP_SPI_REF_CLOCK
64+
/* SPI bus working frequency, this value is not EMSDP_SPI_REF_CLOCK */
65+
#define BOARD_SPI_FREQ (1000000)
6466
#endif
6567
#define BOARD_RSI_SPI_ID DW_SPI_0_ID
6668
#define BOARD_RSI_SPI_CS 0

device/peripheral/wifi/rs9113/hal/rsi_hal_mcu_spi.c

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,15 @@
2626
#include "dev_spi.h"
2727
#include "board.h"
2828
#include "embARC_error.h"
29+
//#define DEBUG
2930
#include "embARC_debug.h"
31+
#include "arc_exception.h"
3032

3133
/**
3234
* Global Variables
3335
*/
3436
#define RSI_CHECK_EXP(EXPR, ERROR_CODE) CHECK_EXP(EXPR, ercd, ERROR_CODE, error_exit)
3537

36-
// int32_t rsi_spi_open(uint32_t freq, uint32_t clk_mode)
37-
// {
38-
// int32_t ercd = E_OK;
39-
// DEV_SPI_PTR rsi_spi_ptr;
40-
41-
// rsi_spi_ptr = spi_get_dev(BOARD_RSI_SPI_ID);
42-
// RSI_CHECK_EXP(rsi_spi_ptr != NULL, E_OBJ);
43-
44-
// DBG("rsi_spi_open DEV_MASTER_MODE= 0x%x (%d),freq= 0x%x (%d) \r\n", DEV_MASTER_MODE, DEV_MASTER_MODE, freq, freq);
45-
// ercd = rsi_spi_ptr->spi_open(DEV_MASTER_MODE, freq);
46-
// if ((ercd == E_OPNED) || (ercd == E_OK)) {
47-
// ercd = rsi_spi_ptr->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(clk_mode));
48-
// }
49-
// error_exit:
50-
// return ercd;
51-
// }
52-
5338
int32_t rsi_spi_close(void)
5439
{
5540
int32_t ercd = E_OK;
@@ -76,56 +61,27 @@ int32_t rsi_spi_close(void)
7661
* @section description
7762
* This API is used to tranfer/receive data to the Wi-Fi module through the SPI interface.
7863
*/
79-
int16_t rsi_spi_transfer(uint8_t *tx_buff, uint8_t *rx_buff, uint16_t transfer_length,uint8_t mode)
64+
int16_t rsi_spi_transfer(uint8_t *tx_buff, uint8_t *rx_buff, uint16_t transfer_length, uint8_t mode)
8065
{
8166
int32_t ercd = E_OK;
82-
uint32_t tx_cnt = transfer_length;
83-
uint32_t rx_cnt = transfer_length;
8467
uint32_t cs_line = BOARD_RSI_SPI_CS;
8568
DEV_SPI_PTR rsi_spi_ptr = spi_get_dev(BOARD_RSI_SPI_ID);
8669
RSI_CHECK_EXP(rsi_spi_ptr != NULL, E_OBJ);
8770

8871
if(mode != RSI_MODE_8BIT){
8972
DBG("rsi_spi_transfer mode = %d\r\n", mode);
9073
}
91-
if(tx_buff == NULL){
92-
tx_cnt = 0;
93-
}
94-
if(rx_buff == NULL){
95-
rx_cnt = 0;
96-
}
97-
// //! Assert the chip select pin
98-
// rsi_spi_cs(1);
99-
100-
// for(i=0; i<transfer_length; i++)
101-
// {
102-
// //! Transfer the data
103-
// if(tx_buff!=NULL){
104-
// ercd = rsi_spi_ptr -> spi_write(tx_buff+i, 1);
105-
// RSI_CHECK_EXP(ercd >= E_OK, ercd);
106-
// } else {
107-
// //tx_buff is NULL, send dummy data instead
108-
// ercd = rsi_spi_ptr -> spi_write(0x00, 1);
109-
// }
110-
// //! Receive the data
111-
// if(rx_buff!=NULL){
112-
// ercd = rsi_spi_ptr -> spi_read(rx_buff+i, 1);
113-
// RSI_CHECK_EXP(ercd >= E_OK, ercd);
114-
// }
115-
// }
116-
117-
// //! Deassert the chip select pin
118-
// rsi_spi_cs(0);
119-
// ercd = E_OK;
12074

12175
DEV_SPI_TRANSFER spi_xfer;
12276
/* Master and Slave transmit */
123-
DEV_SPI_XFER_SET_TXBUF(&spi_xfer, tx_buff, 0, tx_cnt);
124-
DEV_SPI_XFER_SET_RXBUF(&spi_xfer, rx_buff, 0, rx_cnt);
77+
DEV_SPI_XFER_SET_TXBUF(&spi_xfer, tx_buff, 0, (tx_buff == NULL) ? 0 : transfer_length);
78+
DEV_SPI_XFER_SET_RXBUF(&spi_xfer, rx_buff, 0, (rx_buff == NULL) ? 0 : transfer_length);
12579
DEV_SPI_XFER_SET_NEXT(&spi_xfer, NULL);
12680

12781
ercd = rsi_spi_ptr->spi_control(SPI_CMD_MST_SEL_DEV, CONV2VOID(cs_line));
82+
uint32_t status = cpu_lock_save();
12883
ercd = rsi_spi_ptr->spi_control(SPI_CMD_TRANSFER_POLLING, CONV2VOID(&spi_xfer));
84+
cpu_unlock_restore(status);
12985
ercd = rsi_spi_ptr->spi_control(SPI_CMD_MST_DSEL_DEV, CONV2VOID(cs_line));
13086

13187
error_exit:

device/peripheral/wifi/rs9113/rs9113_adapter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int32_t rs9113_wnic_init(DEV_WNIC_PTR rs9113_wnic, uint32_t network_type)
164164
rs9113_info->network_type = network_type; /* set network type used next */
165165
rswifi_if_ptr = (WIFI_IF_PTR)(rs9113_info->extra);
166166

167-
ercd = _rs9113_spi_open(BOARD_SPI_FREQ, SPI_CLK_MODE_0);
167+
ercd = _rs9113_spi_open(10000000, SPI_CLK_MODE_0);
168168
dbg_printf(DBG_MORE_INFO, "_rs9113_spi_open return 0x%x\r\n", ercd);
169169
RS9113_CHECK_EXP(ercd == E_OK, E_SYS);
170170
//! Driver initialization

0 commit comments

Comments
 (0)