Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/r-map/rmap
Browse files Browse the repository at this point in the history
  • Loading branch information
pat1 committed Dec 17, 2023
2 parents 993bdd0 + b028106 commit 32e5678
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 80 deletions.
3 changes: 3 additions & 0 deletions platformio/stima_v4/master/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@

// HW device
#define ENABLE_SPI1 (true)
#if defined(HAL_SD_MODULE_DISABLED) && defined(STIMAV4_MASTER_HW_VER_01_01)
#define ENABLE_SPI2 (true)
#endif
#define ENABLE_I2C1 (true)
#define ENABLE_I2C2 (true)
#define ENABLE_QSPI (true)
Expand Down
5 changes: 2 additions & 3 deletions platformio/stima_v4/master/include/debug_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define SUPERVISOR_TASK_TRACE_LEVEL TRACE_LEVEL_INFO
#define CAN_TASK_TRACE_LEVEL TRACE_LEVEL_VERBOSE
#define SD_TASK_TRACE_LEVEL TRACE_LEVEL_INFO
#define SD_TASK_TRACE_LEVEL TRACE_LEVEL_OFF
#define LCD_TASK_TRACE_LEVEL TRACE_LEVEL_OFF
#define USBSERIAL_TASK_TRACE_LEVEL TRACE_LEVEL_OFF
#define LCD_TASK_TRACE_LEVEL TRACE_LEVEL_INFO
#define USBSERIAL_TASK_TRACE_LEVEL TRACE_LEVEL_INFO
#define WDT_TASK_TRACE_LEVEL TRACE_LEVEL_OFF
#define SIM7600_TRACE_LEVEL TRACE_LEVEL_VERBOSE

Expand Down
66 changes: 53 additions & 13 deletions platformio/stima_v4/master/include/drivers/module_master_hal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@
// CPUID STM32
#define UID_BASE_ADDRESS (0x1FFF7590UL)

#if (ENABLE_I2C1 || ENABLE_I2C2)
#if (ENABLE_I2C2)
#include <Wire.h>
#define I2C_MAX_DATA_LENGTH (32)
#define I2C_MAX_ERROR_COUNT (3)
#endif

#if (ENABLE_SPI1)
// Same naming Type SPI->Spi1 for global Arduino Istance and optional Spi2 (as Wire1..Wire2)
#define Spi1 SPI
#endif
#if (ENABLE_SPI2)
#include <Spi.h>
extern SPIClass Spi2;
#endif

#if (ENABLE_I2C1)
#define I2C1_BUS_CLOCK_HZ (100000L)
#endif
Expand Down Expand Up @@ -99,13 +108,45 @@ extern CAN_HandleTypeDef hcan1;
#define PIN_ENCODER_EN5 PE5
#define PIN_ENCODER_INT PE6

// SPI1
#define PIN_SPI_SCK PA5
#define PIN_SPI_MOSI PB5
#define PIN_SPI_MISO PB4
// SPI1 SD
#define PIN_SPI_SS PA15
#define PIN_SD_LED PD14
#ifdef STIMAV4_MASTER_HW_VER_01_01
// #define SD_SPI_PORT_ID 1 (UNCECK FOR FORCE SPI EXTERNAL UPIN27 MODULE CARD, WITH NEW SPI HARDWARE)
#define SD_SPI_PORT_ID 2
#else
#define SD_SPI_PORT_ID 1
#endif

#if (SD_SPI_PORT_ID == 1)
#define SD_SPI1_SS_USER_MODE DEDICATED_SPI // USE SHARED_SPI IF SPI ARE SHARED WITH OTHER HW DEVICE
#define USE_PIN_SD_LED
#endif

#if defined(HAL_SD_MODULE_DISABLED) && defined(STIMAV4_MASTER_HW_VER_01_01)
// SPI1 AND SPI2 AVAIABLE
// SPI1 - TO EXTERNAL UPIN 27 CONNECTOR
#define PIN_SPI1_SCK PA5
#define PIN_SPI1_MOSI PB5
#define PIN_SPI1_MISO PB4
// SPI1 SD
#define PIN_SPI1_SS PA15
#ifdef USE_PIN_SD_LED
#define PIN_SD_LED PD14
#endif

// SPI2 - DIRECT DEDICATED TO SD CARD
#define PIN_SPI2_SCK PB13
#define PIN_SPI2_MOSI PC1
#define PIN_SPI2_MISO PC2
// SPI2 SD (WITHOUT LED SPI EXTERNAL STIMAV3 MODULE)
#define PIN_SPI2_SS PB12
#else
// SPI1 ONLY AVAIABLE
#define PIN_SPI1_SCK PA5
#define PIN_SPI1_MOSI PB5
#define PIN_SPI1_MISO PB4
// SPI1 SD
#define PIN_SPI1_SS PA15
#define PIN_SD_LED PD14
#endif

// I2C1 Esterna (Upin 27 A4/A5)
#define PIN_I2C1_SDA PB7
Expand All @@ -119,16 +160,15 @@ extern CAN_HandleTypeDef hcan1;
#define PIN_UP27_PA0 PC4
#define PIN_UP27_PA1 PC1
#define PIN_UP27_PA2 PC3
#define PIN_UP27_PD10 PA15
#define PIN_UP27_PD10 PA15 // SPI1_SS ENABLED
#define PIN_UP27_PD0 PIN_UART2_RX
#define PIN_UP27_PD1 PIN_UART2_TX
// #define PIN_UP27_PD2 PIN_UART1_RX
// #define PIN_UP27_PD3 PIN_UART1_TX
#define PIN_UP27_PD2 PA10
#define PIN_UP27_PD3 PB6
#define PIN_UP27_PD2 PA10 // PIN_UART1_RX
#define PIN_UP27_PD3 PB6 // PIN_UART1_TX
#define PIN_UP27_PD4 PD11
#define PIN_UP27_PD5 PD12
#define PIN_UP27_PD6 PD13
#define PIN_UP27_PD7 PA4 // SPI1_SS ALTERNATIVE
#define PIN_UP27_PD8 PD14
#define PIN_UP27_PD9 PD15

Expand Down
2 changes: 1 addition & 1 deletion platformio/stima_v4/master/include/tasks/sd_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "queue.hpp"
#include "drivers/module_master_hal.hpp"

#if (ENABLE_SPI1)
#if (ENABLE_SPI1 || ENABLE_SPI2)
#include <SPI.h>
#endif

Expand Down
5 changes: 3 additions & 2 deletions platformio/stima_v4/master/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ platform_packages =
board = stimav4_master
board_build.ldscript = $PROJECT_DIR/user_custom/bootloader.ld
; debug_build_flags = -O0 -ggdb3 -g3
build_flags =
build_flags =
-DSTIMAV4_MASTER_HW_VER_01_01
-DVECT_TAB_OFFSET=0xB000
-DPIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-DUSB_PRODUCT_STRING="\"Stima V4 Master\""
Expand All @@ -55,7 +56,7 @@ build_flags =
-DHAL_RNG_MODULE_ENABLED
-DHAL_CAN_MODULE_ENABLED
-DHAL_DAC_MODULE_DISABLED
;-DHAL_SD_MODULE_ENABLED
-DHAL_SD_MODULE_DISABLED
-DUSE_HAL_DRIVER=1
-DBXCAN_MAX_IFACE_INDEX=0
-DCDC_RECEIVE_QUEUE_BUFFER_PACKET_NUMBER=6
Expand Down
52 changes: 30 additions & 22 deletions platformio/stima_v4/master/src/debug.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
/**@file debug.cpp */

/*********************************************************************
Copyright (C) 2022 Marco Baldinetti <m.baldinetti@digiteco.it>
authors:
Marco Baldinetti <m.baldinetti@digiteco.it>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<http://www.gnu.org/licenses/>.
**********************************************************************/
/**
******************************************************************************
* @file debug.cpp
* @author Moreno Gasperini <m.gasperini@digiteco.it>
* @author Marco Baldinetti <m.baldinetti@digiteco.it>
* @brief debug and logger
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (C) 2022 Moreno Gasperini <m.gasperini@digiteco.it>
* <h2><center>&copy; Copyright (C) 2022 Marco Baldinetti <m.baldinetti@digiteco.it>
* All rights reserved.</center></h2>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* <http://www.gnu.org/licenses/>.
*
******************************************************************************
*/

#include "debug.h"

Expand Down
33 changes: 25 additions & 8 deletions platformio/stima_v4/master/src/drivers/module_master_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
TwoWire Wire2 = TwoWire(PIN_I2C2_SDA, PIN_I2C2_SCL);
#endif

#if (ENABLE_SPI2)
SPIClass Spi2(PIN_SPI2_MOSI, PIN_SPI2_MISO, PIN_SPI2_SCK);
#endif

// Non utilizzo FreRTOS LOW_Power per il Debugging
#ifdef _USE_FREERTOS_LOW_POWER
#define _EXIT_SLEEP_FOR_DEBUGGING
Expand Down Expand Up @@ -95,18 +99,30 @@ const PinMap PinMap_I2C_SCL[] = {
#ifdef HAL_SPI_MODULE_ENABLED
const PinMap PinMap_SPI_MOSI[] = {
{PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
#if defined(HAL_SD_MODULE_DISABLED) && defined(STIMAV4_MASTER_HW_VER_01_01)
{PC_1, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_SPI2)},
#endif
{NC, NP, 0}
};
const PinMap PinMap_SPI_MISO[] = {
{PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
#if defined(HAL_SD_MODULE_DISABLED) && defined(STIMAV4_MASTER_HW_VER_01_01)
{PC_2, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
#endif
{NC, NP, 0}
};
const PinMap PinMap_SPI_SCLK[] = {
{PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
#if defined(HAL_SD_MODULE_DISABLED) && defined(STIMAV4_MASTER_HW_VER_01_01)
{PB_13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
#endif
{NC, NP, 0}
};
const PinMap PinMap_SPI_SSEL[] = {
{PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
#if defined(HAL_SD_MODULE_DISABLED) && defined(STIMAV4_MASTER_HW_VER_01_01)
{PB_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
#endif
{NC, NP, 0}
};
#endif
Expand Down Expand Up @@ -498,10 +514,18 @@ void MX_GPIO_Init(void)
// ********** SETUP Port A *************

/* Unused PAx (esclude UPIN27) */
GPIO_InitStruct.Pin = GPIO_PIN_4;
#if (!ENABLE_SIM7600E)
GPIO_InitStruct.Pin = GSM_RingInd_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#else
/* Ring Indicator NoPull */
GPIO_InitStruct.Pin = GSM_RingInd_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif

/* MCO */
GPIO_InitStruct.Pin = GPIO_PIN_8;
Expand All @@ -511,13 +535,6 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* Ring Indicator NoPull */
GPIO_InitStruct.Pin = GSM_RingInd_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);


// ********** SETUP Port B *************

HAL_GPIO_WritePin(GPIOB, DISPLAY_Power_Pin, GPIO_PIN_RESET);
Expand Down
59 changes: 35 additions & 24 deletions platformio/stima_v4/master/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
/**@file main.cpp */

/*********************************************************************
Copyright (C) 2022 Marco Baldinetti <m.baldinetti@digiteco.it>
authors:
Marco Baldinetti <m.baldinetti@digiteco.it>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<http://www.gnu.org/licenses/>.
**********************************************************************/
/**
******************************************************************************
* @file main.cpp
* @author Moreno Gasperini <m.gasperini@digiteco.it>
* @author Marco Baldinetti <m.baldinetti@digiteco.it>
* @brief main program init and start scheduler task cpp
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (C) 2022 Moreno Gasperini <m.gasperini@digiteco.it>
* <h2><center>&copy; Copyright (C) 2022 Marco Baldinetti <m.baldinetti@digiteco.it>
* All rights reserved.</center></h2>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* <http://www.gnu.org/licenses/>.
*
******************************************************************************
*/

#define TRACE_LEVEL STIMA_TRACE_LEVEL

Expand Down Expand Up @@ -457,9 +465,12 @@ void init_wire()

// Setup SPI
#if (ENABLE_SPI1)
SPI.begin();
Spi1.begin();
#endif
#if (ENABLE_SPI2)
Spi2.begin();
#endif

// Start EN Pow GSM ready to SET
digitalWrite(PIN_GSM_EN_POW, HIGH);
}
Expand Down
Loading

0 comments on commit 32e5678

Please sign in to comment.