Skip to content

Commit 9cb8ce6

Browse files
authored
Merge pull request #4412 from kamtom480/spi_and_i2c
spresense: minor changes for i2c, spi and uart
2 parents 05ed179 + ed3f636 commit 9cb8ce6

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

ports/cxd56/common-hal/busio/I2C.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <arch/chip/pin.h>
2828
#include <nuttx/i2c/i2c_master.h>
2929
#include <cxd56_i2c.h>
30+
#include <cxd56_pinconfig.h>
3031

3132
#include "py/runtime.h"
3233

@@ -49,6 +50,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
4950
self->sda_pin = sda;
5051
self->frequency = frequency;
5152
self->i2c_dev = cxd56_i2cbus_initialize(0);
53+
CXD56_PIN_CONFIGS(PINCONFS_I2C0);
5254
}
5355

5456
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {

ports/cxd56/common-hal/busio/SPI.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <arch/chip/pin.h>
2828
#include <cxd56_spi.h>
29+
#include <cxd56_pinconfig.h>
2930

3031
#include "py/runtime.h"
3132

@@ -39,10 +40,12 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
3940
(mosi == NULL || mosi->number == PIN_SPI4_MOSI) &&
4041
(miso == NULL || miso->number == PIN_SPI4_MISO)) {
4142
port = 4;
43+
CXD56_PIN_CONFIGS(PINCONFS_SPI4);
4244
} else if (clock->number == PIN_EMMC_CLK &&
4345
(mosi == NULL || mosi->number == PIN_EMMC_DATA0) &&
4446
(miso == NULL || miso->number == PIN_EMMC_DATA1)) {
4547
port = 5;
48+
CXD56_PIN_CONFIGS(PINCONFS_EMMCA_SPI5);
4649
}
4750

4851
if (port < 0) {

ports/cxd56/common-hal/busio/UART.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
5959
uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop,
6060
mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
6161
bool sigint_enabled) {
62+
int i;
63+
int count;
64+
char tmp;
6265
struct termios tio;
6366

6467
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
@@ -96,6 +99,14 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
9699
if (busio_uart_dev[self->number].fd < 0) {
97100
mp_raise_ValueError(translate("Could not initialize UART"));
98101
}
102+
103+
// Wait to make sure the UART is ready
104+
usleep(1000);
105+
// Clear RX FIFO
106+
ioctl(busio_uart_dev[self->number].fd, FIONREAD, (long unsigned int)&count);
107+
for (i = 0; i < count; i++) {
108+
read(busio_uart_dev[self->number].fd, &tmp, 1);
109+
}
99110
}
100111

101112
ioctl(busio_uart_dev[self->number].fd, TCGETS, (long unsigned int)&tio);

0 commit comments

Comments
 (0)