summaryrefslogtreecommitdiff
path: root/ports/stm32f4
diff options
context:
space:
mode:
authorAditya Naik2020-08-03 14:42:06 -0400
committerAditya Naik2020-08-03 14:42:06 -0400
commit11a52e4e88bcad1e6bddcf02f78e1cc5eaaec508 (patch)
treed7f725c30e618994a0650607ede73ab3efc72c67 /ports/stm32f4
parent81b3f3d5336eab67e8eb21bb4011e552f3895a4e (diff)
RTOS skeleton with (UNIX) POSIX calls. Reorg of stream files
Diffstat (limited to 'ports/stm32f4')
-rw-r--r--ports/stm32f4/makefile5
-rw-r--r--ports/stm32f4/src/stream_i2c.c37
2 files changed, 42 insertions, 0 deletions
diff --git a/ports/stm32f4/makefile b/ports/stm32f4/makefile
index c3701b9..df447d1 100644
--- a/ports/stm32f4/makefile
+++ b/ports/stm32f4/makefile
@@ -1,11 +1,15 @@
# Makefile for the STM32F4 port
+PREFIX = arm-none-eabi-
+
# These variables are dependent on the target MCU
LDSCRIPT=STM32F405RGTx_FLASH.ld
ASM_FILE=startup_stm32f405xx.s
C_DEFS += \
-DSTM32F405xx
+LDFLAGS = $(MCU) -specs=nosys.specs -specs=nano.specs -u _printf_float -T$(PORT_DIR)/$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
+
FLOAT-ABI = -mfloat-abi=hard
CPU = -mcpu=cortex-m4
FPU = -mfpu=fpv4-sp-d16
@@ -34,6 +38,7 @@ lib/f4/stm32f4xx_hal_uart.c \
ports/stm32f4/src/stm32f4xx_it.c \
ports/stm32f4/src/stm32f4xx_hal_msp.c \
ports/stm32f4/src/system_stm32f4xx.c \
+ports/stm32f4/src/stream_i2c.c
C_INCLUDES += \
-Ilib/f4 \
diff --git a/ports/stm32f4/src/stream_i2c.c b/ports/stm32f4/src/stream_i2c.c
new file mode 100644
index 0000000..3e8fc95
--- /dev/null
+++ b/ports/stm32f4/src/stream_i2c.c
@@ -0,0 +1,37 @@
+#include "stream_i2c.h"
+#include "port.h"
+#include "stream.h"
+
+int i2c_read(uint8_t* buf, size_t count, void **vptr, void *sptr)
+{
+ p_stream_t *stream = (p_stream_t*)sptr;
+ I2C_HandleTypeDef dev = *(I2C_HandleTypeDef*)stream->props[0];
+
+ uint16_t addr = *(uint16_t*)vptr[0];
+ uint32_t timeout = *(uint32_t*)vptr[1];
+ uint16_t AF_limit = *(uint32_t*)vptr[2];
+
+ int error, AF_counter = 0;
+ while (HAL_I2C_Master_Receive(&dev, addr, buf, count, timeout) != HAL_OK) {
+ if ((error = HAL_I2C_GetError(&dev)) != HAL_I2C_ERROR_AF) {
+ return error;
+ }
+ else if (++AF_counter > AF_limit) {
+ return HAL_I2C_ERROR_AF;
+ }
+ }
+ return 0;
+}
+
+int i2c_write(uint8_t* buf, size_t count, void **vptr, void *sptr)
+{
+ p_stream_t *stream = (p_stream_t*)sptr;
+ I2C_HandleTypeDef dev = *(I2C_HandleTypeDef*)stream->props[0];
+ uint16_t addr = *(uint16_t*)vptr[1];
+ uint32_t timeout = *(uint32_t*)vptr[2];
+
+ while (HAL_I2C_Master_Transmit(&dev, addr, buf, count, timeout) != HAL_OK) {
+ return HAL_I2C_GetError(&dev);
+ }
+ return 0;
+}