Skip to content

Commit

Permalink
version1 added (incomplete!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Varga committed Mar 28, 2023
1 parent c57132f commit dc3dbac
Show file tree
Hide file tree
Showing 184 changed files with 187,800 additions and 0 deletions.
317 changes: 317 additions & 0 deletions 04_canSniffer_FW/board1_STM/.cproject

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions 04_canSniffer_FW/board1_STM/.mxproject

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions 04_canSniffer_FW/board1_STM/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dipCAN</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>?children?</key>
<value>?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\||</value>
</dictionary>
<dictionary>
<key>?name?</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>make</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildLocation</key>
<value>${workspace_loc:/STM32100B-EVAL/Debug}</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>true</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUTSConvertedProjectNature</nature>
</natures>
</projectDescription>
101 changes: 101 additions & 0 deletions 04_canSniffer_FW/board1_STM/Application/dc_ble.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "dc_ble.h"
#include "FreeRTOS.h"
#include "task.h"
#include <string.h>
#include "dc_can.h"
#include "dc_main.h"
//---------------------------------------------------------------------------------------------------------------------
extern UART_HandleTypeDef huart3;
//---------------------------------------------------------------------------------------------------------------------
#define RX_BUFFER_LEN 255
//---------------------------------------------------------------------------------------------------------------------
static TaskHandle_t xTaskToNotify = NULL;
static uint8_t rxBuffer[RX_BUFFER_LEN], rxPtr;
static bool bleDfuIsActive = false;
//---------------------------------------------------------------------------------------------------------------------
const uint8_t DFU_INIT_ARRAY[] = {0x09, 0x01, 0xC0};
const uint8_t DFU_END_ARRAY[] = "DipCan Started\r\n";
uint8_t dfuEndArrayPtr = 0;
uint8_t START_NRF_BL_CMD[] = "NRF_BL\r";
//---------------------------------------------------------------------------------------------------------------------
bool dc_ble_dfu_is_active(void){
return bleDfuIsActive;
}

void dc_ble_init(void){
rxPtr = 0;
HAL_UART_Receive_IT(&huart3, &rxBuffer[rxPtr], 1);
}

void dc_ble_task(void * pvParameters){
xTaskToNotify = xTaskGetCurrentTaskHandle();
dc_usb_packet_t txPacket;

dc_ble_init();

for(;;){
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
while (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(5))) {}

txPacket.len = rxPtr;
memcpy(txPacket.data, rxBuffer, rxPtr);
HAL_UART_AbortReceive_IT(&huart3);
dc_ble_init();
dc_usb_send_data(&txPacket);
}
}

void dc_ble_check_dfu_end(uint8_t lastByte){
dfuEndArrayPtr = lastByte == DFU_END_ARRAY[dfuEndArrayPtr] ? dfuEndArrayPtr+1 : 0;
if ( dfuEndArrayPtr == strlen((char*)DFU_END_ARRAY) ){
dfuEndArrayPtr = 0;
bleDfuIsActive = false;
dc_main_led_off();
}
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
if (huart == &huart3){
rxPtr++;

if (rxPtr >= RX_BUFFER_LEN){
rxPtr = 0;
}
dc_ble_check_dfu_end(rxBuffer[rxPtr-1]);

HAL_UART_Receive_IT(&huart3, &rxBuffer[rxPtr], 1);

BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(xTaskToNotify, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}

HAL_StatusTypeDef dc_ble_send(uint8_t * pData, uint8_t len){
return HAL_UART_Transmit(&huart3, pData, len, 10);
}

void dc_ble_usb_rx(dc_usb_packet_t *rxPacket){
if (!bleDfuIsActive) {
if ( rxPacket->len == sizeof(DFU_INIT_ARRAY) &&
!memcmp( rxPacket->data, DFU_INIT_ARRAY, sizeof(DFU_INIT_ARRAY) ) &&
!dc_can_is_active(CAN_MAX_CH) )
{
dc_ble_send(START_NRF_BL_CMD, strlen((char*)START_NRF_BL_CMD));
vTaskDelay(pdMS_TO_TICKS(100));
bleDfuIsActive = true;
dc_main_led_on();
} else {
return;
}
}


uint8_t maxRetries = 10;
while (maxRetries && HAL_OK != dc_ble_send(rxPacket->data, rxPacket->len)){
maxRetries--;
}
}

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
}
12 changes: 12 additions & 0 deletions 04_canSniffer_FW/board1_STM/Application/dc_ble.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef DC_BLE_H_
#define DC_BLE_H_
//---------------------------------------------------------------------------------------------------------------------
#include "dc_usb.h"
#include "main.h"
//---------------------------------------------------------------------------------------------------------------------
void dc_ble_task(void * pvParameters);
void dc_ble_usb_rx(dc_usb_packet_t *rxPacket);
bool dc_ble_dfu_is_active(void);
HAL_StatusTypeDef dc_ble_send(uint8_t * pData, uint8_t len);
//---------------------------------------------------------------------------------------------------------------------
#endif /* DC_BLE_H_ */
18 changes: 18 additions & 0 deletions 04_canSniffer_FW/board1_STM/Application/dc_buzzer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "dc_buzzer.h"
#include "dc_main.h"
#include "main.h"
//---------------------------------------------------------------------------------------------------------------------
extern TIM_HandleTypeDef htim12;
//---------------------------------------------------------------------------------------------------------------------
void dc_buzzer_init(void){
for (uint8_t i = 0; i < 2; i++){
HAL_TIM_PWM_Start(&htim12, TIM_CHANNEL_2);
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
vTaskDelay(pdMS_TO_TICKS(50));
HAL_TIM_PWM_Stop(&htim12, TIM_CHANNEL_2);
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
vTaskDelay(pdMS_TO_TICKS(50));
}
}

//---------------------------------------------------------------------------------------------------------------------
8 changes: 8 additions & 0 deletions 04_canSniffer_FW/board1_STM/Application/dc_buzzer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef DC_BUZZER_H_
#define DC_BUZZER_H_
//---------------------------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------------------------
void dc_buzzer_init(void);
//---------------------------------------------------------------------------------------------------------------------
#endif /* DC_BUZZER_H_ */
Loading

0 comments on commit dc3dbac

Please sign in to comment.