Compare commits

...

40 Commits

Author SHA1 Message Date
Matthew Kennedy d91c29a10b
Merge 6b97de0523 into 316915ec4c 2024-08-30 10:49:04 -07:00
Matthew Kennedy 6b97de0523 Merge remote-tracking branch 'origin/master' into openblt-can 2023-11-07 12:22:22 -08:00
Matthew Kennedy 2e114d1e17 Merge remote-tracking branch 'origin/master' into openblt-can 2023-08-27 17:07:53 -07:00
Matthew Kennedy 2abe1a3937 Merge remote-tracking branch 'origin/master' into openblt-can 2023-08-27 10:55:36 -07:00
Matthew Kennedy 7ad7f55eb8 wire up CAN init 2023-08-27 10:49:33 -07:00
Matthew Kennedy 71327511e0 enable CAN 2023-08-27 10:36:21 -07:00
Matthew Kennedy 2c39d18585 Merge remote-tracking branch 'origin/master' into openblt-can 2023-08-27 10:35:30 -07:00
Matthew Kennedy 571bf9624a enable 2023-08-26 23:21:39 -07:00
Matthew Kennedy bc1ac26a29 can stub 2023-08-26 23:21:33 -07:00
Matthew Kennedy 0375ea3168 cleanup 2023-08-26 23:02:43 -07:00
Matthew Kennedy 72d7b61ce1 makefiles cleanup 2023-08-26 17:44:39 -07:00
Matthew Kennedy c7ea65f9a7 dead 2023-08-26 17:39:21 -07:00
Matthew Kennedy c138631096 comment 2023-08-26 12:08:49 -07:00
Matthew Kennedy 2ef2e835d7 format 2023-08-26 12:00:38 -07:00
Matthew Kennedy fa47e3a3e3 simplify memcpy 2023-08-26 11:51:35 -07:00
Matthew Kennedy ce6ff8c032 flash layout is handled entirely by FOME flash driver 2023-08-26 11:34:02 -07:00
Matthew Kennedy 6394894828 script tweaks 2023-08-26 11:28:25 -07:00
Matthew Kennedy f8c500f916 simplifying linker logic 2023-08-26 11:22:39 -07:00
Matthew Kennedy d41c53f39c delete bootloader crust 2023-08-26 11:13:32 -07:00
Matthew Kennedy 03573b26d3 cleanup 2023-08-26 01:26:41 -07:00
Matthew Kennedy f5bd2e6a19 common_make.sh 2023-08-26 01:04:34 -07:00
Matthew Kennedy 1cec4d7f36 no ccache 2023-08-26 01:01:59 -07:00
Matthew Kennedy 5e1ec57bfa boards no longer need specific openblt files 2023-08-26 01:00:53 -07:00
Matthew Kennedy f75aa47a9e blt conf, linker 2023-08-26 00:28:45 -07:00
Matthew Kennedy 296bbb5144 implement flash driver 2023-08-26 00:28:08 -07:00
Matthew Kennedy 197aba3685 openblt responds over USB! 2023-08-26 00:10:18 -07:00
Matthew Kennedy db442baee4 flash.h 2023-08-25 23:46:40 -07:00
Matthew Kennedy 78e31d9c93 stub flash 2023-08-25 23:46:33 -07:00
Matthew Kennedy dd9fa926da nonfunctional openblt 2023-08-25 23:44:05 -07:00
Matthew Kennedy 9dffa8e453 shared params 2023-08-25 23:17:15 -07:00
Matthew Kennedy a5f793a6bd cleanup 2023-08-25 23:05:59 -07:00
Matthew Kennedy b0e81a055f USB enumerates! 2023-08-25 23:04:36 -07:00
Matthew Kennedy 4b090da610 kinda usb? 2023-08-25 22:57:43 -07:00
Matthew Kennedy 0944e5c2c8 loader gets USB but not MSD 2023-08-25 22:48:00 -07:00
Matthew Kennedy 024380f289 bootloader gets hardfault 2023-08-25 22:42:58 -07:00
Matthew Kennedy cb37a3ef99 strip out dfu 2023-08-25 22:34:36 -07:00
Matthew Kennedy a77ad48193 hard fp 2023-08-25 20:09:06 -07:00
Matthew Kennedy 0beb2ba89d output name 2023-08-25 20:08:23 -07:00
Matthew Kennedy 14bd7e79ae bootloader builds 2023-08-25 20:07:14 -07:00
Matthew Kennedy cbae02676e flash layout 2023-08-25 19:25:23 -07:00
3 changed files with 106 additions and 3 deletions

View File

@ -22,8 +22,6 @@ DDEFS += -DHAL_USE_FLASH=FALSE
DDEFS += -DEFI_USE_UART_DMA=FALSE
DDEFS += -DEFI_USB_SERIAL=TRUE -DHAL_USE_USB_MSD=FALSE
# disable CAN
DDEFS += -DEFI_CAN_SUPPORT=FALSE
# Cache is disabled on F7, H7
DDEFS += -DSTM32_SRAM2_NOCACHE=FALSE -DSTM32_NOCACHE_SRAM1_SRAM2=FALSE -DSTM32_NOCACHE_SRAM3=FALSE
@ -189,8 +187,10 @@ CPPSRC = $(ALLCPPSRC) \
$(HW_LAYER_EMS_CPP) \
$(BOARDCPPSRC) \
$(PROJECT_DIR)/util/efilib.cpp \
$(PROJECT_DIR)/hw_layer/drivers/can/can_config.cpp \
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
$(RUSEFI_LIB_CPP) \
$(PROJECT_DIR)/bootloader/openblt_chibios/openblt_can.cpp \
$(PROJECT_DIR)/bootloader/openblt_chibios/openblt_chibios.cpp \
$(PROJECT_DIR)/bootloader/openblt_chibios/openblt_flash.cpp \
$(PROJECT_DIR)/bootloader/openblt_chibios/openblt_usb.cpp \

View File

@ -0,0 +1,101 @@
#include "pch.h"
#include "hal.h"
#include "can_hw.h"
extern "C" {
#include "boot.h"
}
/************************************************************************************//**
** \brief Initializes the CAN controller and synchronizes it to the CAN bus.
** \return none.
**
****************************************************************************************/
extern "C" void CanInit(void)
{
// TODO: init pins?
auto cfg = findCanConfig(B500KBPS);
canStart(&CAND1, cfg);
}
/************************************************************************************//**
** \brief Transmits a packet formatted for the communication interface.
** \param data Pointer to byte array with data that it to be transmitted.
** \param len Number of bytes that are to be transmitted.
** \return none.
**
****************************************************************************************/
extern "C" void CanTransmitPacket(blt_int8u *data, blt_int8u len)
{
blt_int32u txMsgId = BOOT_COM_CAN_TX_MSG_ID;
CANTxFrame frame;
if ((txMsgId & 0x80000000) == 0)
{
/* set the 11-bit CAN identifier. */
frame.SID = txMsgId;
frame.IDE = false;
}
else
{
txMsgId &= ~0x80000000;
/* set the 29-bit CAN identifier. */
frame.EID = txMsgId & ~0x80000000; // negate the ID-type bit
frame.IDE = true;
}
// Copy data/DLC
frame.DLC = len;
memcpy(frame.data8, data, len);
canTransmitTimeout(&CAND1, CAN_ANY_MAILBOX, &frame, TIME_MS2I(100));
}
/************************************************************************************//**
** \brief Receives a communication interface packet if one is present.
** \param data Pointer to byte array where the data is to be stored.
** \param len Pointer where the length of the packet is to be stored.
** \return BLT_TRUE is a packet was received, BLT_FALSE otherwise.
**
****************************************************************************************/
extern "C" blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len)
{
constexpr blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
blt_bool result = BLT_FALSE;
CANRxFrame frame;
if (MSG_OK != canReceiveTimeout(&CAND1, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE)) {
// no message was waiting
return BLT_FALSE;
}
// Check that the ID type matches this frame (std vs ext)
constexpr bool configuredAsExt = (rxMsgId & 0x80000000) == 0;
if (configuredAsExt != frame.IDE) {
// Wrong frame type
return BLT_FALSE;
}
// Check that the frame's ID matches
if (frame.IDE) {
if (frame.EID != (rxMsgId & ~0x80000000)) {
// Wrong ID
return BLT_FALSE;
}
} else {
if (frame.SID != rxMsgId) {
// Wrong ID
return BLT_FALSE;
}
}
// Copy data and length out
*len = frame.DLC;
memcpy(data, frame.data8, frame.DLC);
return BLT_TRUE;
}

View File

@ -71,7 +71,7 @@
*
*/
/** \brief Enable/disable CAN transport layer. */
#define BOOT_COM_CAN_ENABLE (0)
#define BOOT_COM_CAN_ENABLE (1)
/** \brief Configure the desired CAN baudrate. */
#define BOOT_COM_CAN_BAUDRATE (500000)
/** \brief Configure CAN message ID target->host. */
@ -83,6 +83,8 @@
/** \brief Configure number of bytes in the host->target CAN message. */
#define BOOT_COM_CAN_RX_MAX_DATA (8)
#define BOOT_COM_CAN_CHANNEL_INDEX (1)
/* The RS232 communication interface is selected by setting the BOOT_COM_RS232_ENABLE
* configurable to 1. Configurable BOOT_COM_RS232_BAUDRATE selects the communication speed
* in bits/second. The maximum amount of data bytes in a message for data transmission