Skip to content

Commit d689430

Browse files
committed
stmhal: Add SPI class.
Also some updates to compile with latest changes to core py.
1 parent c7c4a84 commit d689430

17 files changed

Lines changed: 419 additions & 14 deletions

File tree

stmhal/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ SRC_C = \
9898
dac.c \
9999
adc.c \
100100
i2c.c \
101+
spi.c \
101102

102103
# pybwlan.c \
103104
@@ -124,6 +125,7 @@ SRC_HAL = $(addprefix $(HAL_DIR)/src/,\
124125
stm32f4xx_hal_rtc.c \
125126
stm32f4xx_hal_rtc_ex.c \
126127
stm32f4xx_hal_sd.c \
128+
stm32f4xx_hal_spi.c \
127129
stm32f4xx_hal_tim.c \
128130
stm32f4xx_hal_tim_ex.c \
129131
stm32f4xx_hal_uart.c \

stmhal/accel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj;
7575

7676
STATIC mp_obj_t pyb_accel_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
7777
// check arguments
78-
mp_check_nargs(n_args, 0, 0, n_kw, false);
78+
mp_arg_check_num(n_args, n_kw, 0, 0, false);
7979

8080
// init accel object
8181
pyb_accel_obj.base.type = &pyb_accel_type;

stmhal/adc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ STATIC void adc_print(void (*print)(void *env, const char *fmt, ...), void *env,
120120

121121
STATIC mp_obj_t adc_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
122122
// check number of arguments
123-
mp_check_nargs(n_args, 1, 1, n_kw, false);
123+
mp_arg_check_num(n_args, n_kw, 1, 1, false);
124124

125125
// 1st argument is the pin name
126126
mp_obj_t pin_obj = args[0];
@@ -322,7 +322,7 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) {
322322

323323
STATIC mp_obj_t adc_all_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
324324
// check number of arguments
325-
mp_check_nargs(n_args, 1, 1, n_kw, false);
325+
mp_arg_check_num(n_args, n_kw, 1, 1, false);
326326

327327
// make ADCAll object
328328
pyb_adc_all_obj_t *o = m_new_obj(pyb_adc_all_obj_t);

stmhal/dac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ STATIC pyb_dac_obj_t pyb_dac_channel_2 = {{&pyb_dac_type}, DAC_CHANNEL_2, DMA1_S
5353

5454
STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
5555
// check arguments
56-
mp_check_nargs(n_args, 1, 1, n_kw, false);
56+
mp_arg_check_num(n_args, n_kw, 1, 1, false);
5757

5858
machine_int_t dac_id = mp_obj_get_int(args[0]);
5959
uint32_t pin;

stmhal/extint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ STATIC mp_obj_t extint_regs(void) {
244244
STATIC mp_obj_t extint_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
245245
// type_in == extint_obj_type
246246

247-
mp_check_nargs(n_args, 4, 4, n_kw, false);
247+
mp_arg_check_num(n_args, n_kw, 4, 4, false);
248248

249249
extint_obj_t *self = m_new_obj(extint_obj_t);
250250
self->base.type = type_in;

stmhal/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ STATIC const mp_obj_type_t file_obj_type = {
7979
};
8080

8181
STATIC mp_obj_t file_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
82-
mp_check_nargs(n_args, 1, 2, n_kw, false);
82+
mp_arg_check_num(n_args, n_kw, 1, 2, false);
8383
const char *filename = mp_obj_str_get_str(args[0]);
8484
const char *mode = "r";
8585
if (n_args > 1) {

stmhal/hal/src/stm32f4xx_hal_spi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint1
589589

590590
/* Read CRC to Flush RXNE flag */
591591
tmpreg = hspi->Instance->DR;
592+
(void)tmpreg; // suppress compiler warning
592593
}
593594

594595
if((hspi->Init.Mode == SPI_MODE_MASTER)&&((hspi->Init.Direction == SPI_DIRECTION_1LINE)||(hspi->Init.Direction == SPI_DIRECTION_2LINES_RXONLY)))
@@ -829,6 +830,7 @@ HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxD
829830
}
830831
/* Read CRC */
831832
tmpreg = hspi->Instance->DR;
833+
(void)tmpreg; // suppress compiler warning
832834
}
833835

834836
/* Wait until Busy flag is reset before disabling SPI */
@@ -1630,6 +1632,7 @@ static void SPI_RxCloseIRQHandler(SPI_HandleTypeDef *hspi)
16301632

16311633
/* Read CRC to reset RXNE flag */
16321634
tmpreg = hspi->Instance->DR;
1635+
(void)tmpreg; // suppress compiler warning
16331636

16341637
/* Wait until RXNE flag is set to send data */
16351638
if(SPI_WaitOnFlagUntilTimeout(hspi, SPI_FLAG_RXNE, SET, SPI_TIMEOUT_VALUE) != HAL_OK)
@@ -1823,6 +1826,7 @@ static void SPI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
18231826

18241827
/* Read CRC */
18251828
tmpreg = hspi->Instance->DR;
1829+
(void)tmpreg; // suppress compiler warning
18261830

18271831
/* Wait until RXNE flag is set to send data */
18281832
if(SPI_WaitOnFlagUntilTimeout(hspi, SPI_FLAG_RXNE, SET, SPI_TIMEOUT_VALUE) != HAL_OK)
@@ -1877,6 +1881,7 @@ static void SPI_DMATransmitReceiveCplt(DMA_HandleTypeDef *hdma)
18771881
}
18781882
/* Read CRC */
18791883
tmpreg = hspi->Instance->DR;
1884+
(void)tmpreg; // suppress compiler warning
18801885
}
18811886

18821887
/* Wait until TXE flag is set to send data */

stmhal/i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ STATIC const pyb_i2c_obj_t pyb_i2c_obj[PYB_NUM_I2C] = {{{&pyb_i2c_type}, &I2cHan
7979

8080
STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
8181
// check arguments
82-
mp_check_nargs(n_args, 1, 1, n_kw, false);
82+
mp_arg_check_num(n_args, n_kw, 1, 1, false);
8383

8484
// get i2c number
8585
machine_int_t i2c_id = mp_obj_get_int(args[0]) - 1;

stmhal/led.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void led_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp
197197

198198
STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
199199
// check arguments
200-
mp_check_nargs(n_args, 1, 1, n_kw, false);
200+
mp_arg_check_num(n_args, n_kw, 1, 1, false);
201201

202202
// get led number
203203
machine_int_t led_id = mp_obj_get_int(args[0]) - 1;

stmhal/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "pybstdio.h"
1919
#include "readline.h"
2020
#include "pyexec.h"
21+
#include "i2c.h"
22+
#include "spi.h"
2123
#include "usart.h"
2224
#include "timer.h"
2325
#include "led.h"
@@ -31,7 +33,6 @@
3133
#include "ff.h"
3234
#include "lcd.h"
3335
#include "rng.h"
34-
#include "i2c.h"
3536
#include "accel.h"
3637
#include "servo.h"
3738
#include "dac.h"
@@ -466,8 +467,8 @@ int main(void) {
466467
//timer_init();
467468
#endif
468469

469-
// I2C
470470
i2c_init();
471+
spi_init0();
471472

472473
#if MICROPY_HW_HAS_MMA7660
473474
// MMA accel: init and reset

0 commit comments

Comments
 (0)