Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openblt can #231

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cbae026
flash layout
mck1117 Aug 26, 2023
14bd7e7
bootloader builds
mck1117 Aug 26, 2023
0beb2ba
output name
mck1117 Aug 26, 2023
a77ad48
hard fp
mck1117 Aug 26, 2023
cb37a3e
strip out dfu
mck1117 Aug 26, 2023
024380f
bootloader gets hardfault
mck1117 Aug 26, 2023
0944e5c
loader gets USB but not MSD
mck1117 Aug 26, 2023
4b090da
kinda usb?
mck1117 Aug 26, 2023
b0e81a0
USB enumerates!
mck1117 Aug 26, 2023
a5f793a
cleanup
mck1117 Aug 26, 2023
9dffa8e
shared params
mck1117 Aug 26, 2023
dd9fa92
nonfunctional openblt
mck1117 Aug 26, 2023
78e31d9
stub flash
mck1117 Aug 26, 2023
db442ba
flash.h
mck1117 Aug 26, 2023
197aba3
openblt responds over USB!
mck1117 Aug 26, 2023
296bbb5
implement flash driver
mck1117 Aug 26, 2023
f75aa47
blt conf, linker
mck1117 Aug 26, 2023
5e1ec57
boards no longer need specific openblt files
mck1117 Aug 26, 2023
1cec4d7
no ccache
mck1117 Aug 26, 2023
f5bd2e6
common_make.sh
mck1117 Aug 26, 2023
03573b2
cleanup
mck1117 Aug 26, 2023
d41c53f
delete bootloader crust
mck1117 Aug 26, 2023
f8c500f
simplifying linker logic
mck1117 Aug 26, 2023
6394894
script tweaks
mck1117 Aug 26, 2023
ce6ff8c
flash layout is handled entirely by FOME flash driver
mck1117 Aug 26, 2023
fa47e3a
simplify memcpy
mck1117 Aug 26, 2023
2ef2e83
format
mck1117 Aug 26, 2023
c138631
comment
mck1117 Aug 26, 2023
c7ea65f
dead
mck1117 Aug 27, 2023
72d7b61
makefiles cleanup
mck1117 Aug 27, 2023
0375ea3
cleanup
mck1117 Aug 27, 2023
bc1ac26
can stub
mck1117 Aug 27, 2023
571bf96
enable
mck1117 Aug 27, 2023
2c39d18
Merge remote-tracking branch 'origin/master' into openblt-can
mck1117 Aug 27, 2023
7132751
enable CAN
mck1117 Aug 27, 2023
7ad7f55
wire up CAN init
mck1117 Aug 27, 2023
2abe1a3
Merge remote-tracking branch 'origin/master' into openblt-can
mck1117 Aug 27, 2023
2e114d1
Merge remote-tracking branch 'origin/master' into openblt-can
mck1117 Aug 28, 2023
6b97de0
Merge remote-tracking branch 'origin/master' into openblt-can
mck1117 Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions firmware/bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -188,8 +186,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 \
Expand Down
101 changes: 101 additions & 0 deletions firmware/bootloader/openblt_chibios/openblt_can.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 3 additions & 1 deletion firmware/hw_layer/openblt/blt_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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
Expand Down
Loading