Skip to content

Commit 418945c

Browse files
committed
[NRF5_SDK13] fix:
- bad number of pin from nRF52840 , - bad type of mask of gpio for nRF52940 - typo (object.h) - revert abort func. to spi_master driver - update twi_master driver to the newest (e8527f65e90eee6a4dd48ca55d3fc051a556320a master SDK nRF5)
1 parent 0d88bcd commit 418945c

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/gpio_api.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
#include "nrf_drv_gpiote.h"
2121

2222
#if defined(TARGET_MCU_NRF51822)
23-
#define GPIO_PIN_COUNT 48
24-
#elif defined(TARGET_MCU_NRF51822)
2523
#define GPIO_PIN_COUNT 31
26-
#else
24+
#elif defined(TARGET_MCU_NRF52832)
2725
#define GPIO_PIN_COUNT 32
26+
#elif defined(TARGET_MCU_NRF52840)
27+
#define GPIO_PIN_COUNT 48
28+
#else
29+
#error not recognized gpio count for mcu
2830
#endif
2931

3032
typedef struct {
@@ -38,7 +40,7 @@ typedef struct {
3840
} gpio_cfg_t;
3941

4042
#if GPIO_PIN_COUNT > 32
41-
typedef uint32_t gpio_mask_t;
43+
typedef uint64_t gpio_mask_t;
4244
#else
4345
typedef uint32_t gpio_mask_t;
4446
#endif

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* 1. Redistributions of source code must retain the above copyright notice, this list
99
* of conditions and the following disclaimer.
1010
*
11-
* 2. Redistributions in// binary form, except as embedded into a Nordic Semiconductor ASA
11+
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
1212
* integrated circuit in a product or a software update for such product, must reproduce
1313
* the above copyright notice, this list of conditions and the following disclaimer in
1414
* the documentation and/or other materials provided with the distribution.

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/drivers_nrf/spi_master/nrf_drv_spi.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ typedef struct
129129

130130
bool tx_done : 1;
131131
bool rx_done : 1;
132+
bool abort : 1;
132133
} spi_control_block_t;
133134
static spi_control_block_t m_cb[ENABLED_SPI_COUNT];
134135

@@ -401,6 +402,19 @@ static bool transfer_byte(NRF_SPI_Type * p_spi, spi_control_block_t * p_cb)
401402
// see how the transfer is started in the 'nrf_drv_spi_transfer'
402403
// function.
403404
uint16_t bytes_used = p_cb->bytes_transferred + 1;
405+
406+
if (p_cb->abort)
407+
{
408+
if (bytes_used < p_cb->evt.data.done.tx_length)
409+
{
410+
p_cb->evt.data.done.tx_length = bytes_used;
411+
}
412+
if (bytes_used < p_cb->evt.data.done.rx_length)
413+
{
414+
p_cb->evt.data.done.rx_length = bytes_used;
415+
}
416+
}
417+
404418
if (bytes_used < p_cb->evt.data.done.tx_length)
405419
{
406420
nrf_spi_txd_set(p_spi, p_cb->evt.data.done.p_tx_buffer[bytes_used]);
@@ -577,6 +591,7 @@ ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
577591
p_cb->evt.data.done = *p_xfer_desc;
578592
p_cb->tx_done = false;
579593
p_cb->rx_done = false;
594+
p_cb->abort = false;
580595

581596
if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
582597
{

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/drivers_nrf/twi_master/nrf_drv_twi.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#define NRF_LOG_DEBUG_COLOR TWI_CONFIG_DEBUG_COLOR
5858
#define EVT_TO_STR(event) (event == NRF_DRV_TWI_EVT_DONE ? "EVT_DONE" : \
5959
(event == NRF_DRV_TWI_EVT_ADDRESS_NACK ? "EVT_ADDRESS_NACK" : \
60-
(event == NRF_DRV_TWI_EVT_DATA_NACK ? "EVT_DATA_NACK" : "UNKNOWN ERROR"))))))
60+
(event == NRF_DRV_TWI_EVT_DATA_NACK ? "EVT_DATA_NACK" : "UNKNOWN ERROR")))
6161
#define EVT_TO_STR_TWI(event) (event == NRF_TWI_EVENT_STOPPED ? "NRF_TWI_EVENT_STOPPED" : \
6262
(event == NRF_TWI_EVENT_RXDREADY ? "NRF_TWI_EVENT_RXDREADY" : \
6363
(event == NRF_TWI_EVENT_TXDSENT ? "NRF_TWI_EVENT_TXDSENT" : \
@@ -129,6 +129,7 @@
129129
| (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos))
130130
#define SDA_PIN_INIT_CONF_CLR SCL_PIN_INIT_CONF_CLR
131131

132+
#define HW_TIMEOUT 10000
132133

133134
// Control block - driver instance local data.
134135
typedef struct
@@ -530,7 +531,10 @@ static ret_code_t twi_tx_start_transfer(twi_control_block_t * p_cb,
530531
bool no_stop)
531532
{
532533
ret_code_t ret_code = NRF_SUCCESS;
533-
534+
volatile int32_t hw_timeout;
535+
536+
hw_timeout = HW_TIMEOUT;
537+
534538
nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_STOPPED);
535539
nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_ERROR);
536540
nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_TXDSENT);
@@ -556,9 +560,11 @@ static ret_code_t twi_tx_start_transfer(twi_control_block_t * p_cb,
556560
}
557561
else
558562
{
559-
while (twi_transfer(p_twi, &p_cb->error, &p_cb->bytes_transferred, (uint8_t *)p_data, length, no_stop))
560-
{}
561-
563+
while ((hw_timeout > 0) && twi_transfer(p_twi, &p_cb->error, &p_cb->bytes_transferred, (uint8_t *)p_data, length, no_stop))
564+
{
565+
hw_timeout--;
566+
}
567+
562568
if (p_cb->error)
563569
{
564570
uint32_t errorsrc = nrf_twi_errorsrc_get_and_clear(p_twi);
@@ -569,6 +575,13 @@ static ret_code_t twi_tx_start_transfer(twi_control_block_t * p_cb,
569575
}
570576
}
571577

578+
if (hw_timeout <= 0)
579+
{
580+
nrf_twi_disable(p_twi);
581+
nrf_twi_enable(p_twi);
582+
ret_code = NRF_ERROR_INTERNAL;
583+
}
584+
572585
}
573586
return ret_code;
574587
}
@@ -579,6 +592,9 @@ static ret_code_t twi_rx_start_transfer(twi_control_block_t * p_cb,
579592
uint8_t length)
580593
{
581594
ret_code_t ret_code = NRF_SUCCESS;
595+
volatile int32_t hw_timeout;
596+
597+
hw_timeout = HW_TIMEOUT;
582598

583599
nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_STOPPED);
584600
nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_ERROR);
@@ -610,9 +626,11 @@ static ret_code_t twi_rx_start_transfer(twi_control_block_t * p_cb,
610626
}
611627
else
612628
{
613-
while (twi_transfer(p_twi, &p_cb->error, &p_cb->bytes_transferred, (uint8_t*)p_data, length, false))
614-
{}
615-
629+
while ((hw_timeout > 0) && twi_transfer(p_twi, &p_cb->error, &p_cb->bytes_transferred, (uint8_t*)p_data, length, false))
630+
{
631+
hw_timeout--;
632+
}
633+
616634
if (p_cb->error)
617635
{
618636
uint32_t errorsrc = nrf_twi_errorsrc_get_and_clear(p_twi);
@@ -622,6 +640,13 @@ static ret_code_t twi_rx_start_transfer(twi_control_block_t * p_cb,
622640
ret_code = twi_process_error(errorsrc);
623641
}
624642
}
643+
644+
if (hw_timeout <= 0)
645+
{
646+
nrf_twi_disable(p_twi);
647+
nrf_twi_enable(p_twi);
648+
ret_code = NRF_ERROR_INTERNAL;
649+
}
625650
}
626651
return ret_code;
627652
}

0 commit comments

Comments
 (0)