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

User/Alend/actual-embedded-training #338

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
181 changes: 181 additions & 0 deletions Recruit-Training/Embedded-Recruit-Training/.cproject

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions Recruit-Training/Embedded-Recruit-Training/.mxproject

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion Recruit-Training/Embedded-Recruit-Training/.project
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
</buildCommand>
</buildSpec>
<natures>
<nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUCubeProjectNature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCURootProjectNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1705241123" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-541002047242307172" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.112611237" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-541002047242307172" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
635E684B79701B039C64EA45C3F84D30=3F27462B86B474062A1A36D4299F386A
66BE74F758C12D739921AEA421D593D3=1
8DF89ED150041C4CBC7CB9A9CAA90856=494F066AADE2E4DA6E94BA6B7D189B56
DC22A860405A8BF2F2C095E5B6529F12=494F066AADE2E4DA6E94BA6B7D189B56
eclipse.preferences.version=1

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "stm32l1xx.h"
#include "stm32l1xx_hal_gpio.h"
#include "CAN.h"
#include "cmsis_os.h"
#include "main.h"

extern osMutexId_t SPIMutexHandle;

void blueSwitchTask(void const* arg);
34 changes: 34 additions & 0 deletions Recruit-Training/Embedded-Recruit-Training/Core/Inc/CAN.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "main.h"
#include <stdint.h>
#include "cmsis_os.h"
#include "CANRegisters.h"

typedef struct {
uint8_t DLC;
uint16_t ID;
uint64_t extendedID;
uint8_t* data;
} CANMsg;

// https://www.codesdope.com/blog/article/making-a-queue-using-linked-list-in-c/

#define TX_CHANNEL_CHECK_DELAY 1

void CAN_IC_READ_REGISTER(uint8_t address, uint8_t* buffer);
void CAN_IC_WRITE_REGISTER_BITWISE(uint8_t address, uint8_t mask, uint8_t value);
void CAN_IC_WRITE_REGISTER(uint8_t address, uint8_t value);
void ConfigureCANSPI(void);
void sendCANMessage(CANMsg* msg);
void sendExtendedCANMessage(CANMsg* msg);
void receiveCANMessage(uint8_t channel, uint32_t* ID, uint8_t* DLC, uint8_t* data);
uint8_t checkAvailableTXChannel();

extern SPI_HandleTypeDef hspi1;
extern osMutexId_t SPIMutexHandle;
extern osMessageQueueId_t CANInterruptQueue;
extern osMessageQueueId_t CANTxMessageQueue;

extern uint8_t blueStatus;
extern uint8_t greenStatus;
91 changes: 91 additions & 0 deletions Recruit-Training/Embedded-Recruit-Training/Core/Inc/CANRegisters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#pragma once

// Transmit message channels
#define TX_CHANNEL0 0
#define TX_CHANNEL1 1
#define TX_CHANNEL2 2

// Receive message channels
#define RX_CHANNEL0 0
#define RX_CHANNEL1 1

// CAN register definitions
#define CNF1 0x2A
#define CNF2 0x29
#define CNF3 0x28
#define CANINTE 0x2B
#define CANINTF 0x2C
#define TEC 0x1C
#define REC 0x1D
#define EFLG 0x2D
#define CANCTRL 0xXF //todo
#define CANSTAT 0xXE //todo
#define TXRTSCTRL 0x0D
#define BFPCTRL 0x0C
#define TXB0CTRL 0x30 //these are the three trasmit channels
#define TXB1CTRL 0x40
#define TXB2CTRL 0x50
#define RXB0CTRL 0x60 //two receive buffers
#define RXB1CTRL 0x70
#define TXB0SIDH 0x31
#define TXB1SIDH 0x41
#define TXB2SIDH 0x51
#define TXB0SIDL 0x32
#define TXB1SIDL 0x42
#define TXB2SIDL 0x52
#define TXB0EID8 0x33
#define TXB1EID8 0x43
#define TXB2EID8 0x53
#define TXB0EID0 0x34
#define TXB1EID0 0x44
#define TXB2EID0 0x54
#define TXB0DLC 0x35
#define TXB1DLC 0x45
#define TXB2DLC 0x55
#define TXB0Dm 0x36-0x3D //todo
#define TXB1Dm 0x46-0x4D //todo
#define TXB2Dm 0x56-0x5D
#define RXB0SIDH 0x61
#define RXB1SIDH 0x71
#define RXB0SIDL 0x62
#define RXB1SIDL 0x72
#define RXB0EID8 0x63
#define RXB1EID8 0x73
#define RXB0EID0 0x64
#define RXB1EID0 0x74
#define RXB0DLC 0x65
#define RXB1DLC 0x75
#define RXB0DM 0x66-0x6D //todo
#define RXB1DM 0x76-0x7D //todo
#define RXF0SIDH 0x00
#define RXF1SIDH 0x04
#define RXF2SIDH 0x08
#define RXF3SIDH 0x10
#define RXF4SIDH 0x14
#define RXF5SIDH 0x18
#define RXF0SIDL 0x01
#define RXF1SIDL 0x05
#define RXF2SIDL 0x09
#define RXF3SIDL 0x11
#define RXF4SIDL 0x15
#define RXF5SIDL 0x19
#define RXF0EID8 0x02
#define RXF1EID8 0x06
#define RXF2EID8 0x0A
#define RXF3EID8 0x12
#define RXF4EID8 0x16
#define RXF5EID8 0x1A
#define RXF0EID0 0x03
#define RXF1EID0 0x07
#define RXF2EID0 0x0B
#define RXF3EID0 0x13
#define RXF4EID0 0x17
#define RXF5EID0 0x1B
#define RXM0SIDH 0x20
#define RXM1SIDH 0x24
#define RXM0SIDL 0x21
#define RXM1SIDL 0x25
#define RXM0EID8 0x22
#define RXM1EID8 0x26
#define RXM0EID0 0x23
#define RXM1EID0 0x27
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

/* Ensure definitions are only used by the compiler, and not by the assembler. */
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif
#define configUSE_PREEMPTION 1
#define configSUPPORT_STATIC_ALLOCATION 1
Expand All @@ -60,7 +60,7 @@ extern uint32_t SystemCoreClock;
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 56 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)15360)
#define configTOTAL_HEAP_SIZE ((size_t)3072)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
Expand All @@ -80,6 +80,9 @@ extern uint32_t SystemCoreClock;
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH 256

/* The following flag must be enabled only when using newlib */
#define configUSE_NEWLIB_REENTRANT 1

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
Expand All @@ -103,10 +106,10 @@ to exclude the API function. */

/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4
#define configPRIO_BITS 4
#endif

/* The lowest interrupt priority that can be used in a call to a "set priority"
Expand Down Expand Up @@ -139,6 +142,7 @@ standard names. */

/* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,
to prevent overwriting SysTick_Handler defined within STM32Cube HAL */

#define xPortSysTickHandler SysTick_Handler

/* USER CODE BEGIN Defines */
Expand Down

This file was deleted.

11 changes: 11 additions & 0 deletions Recruit-Training/Embedded-Recruit-Training/Core/Inc/GreenSwitch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "stm32l1xx.h"
#include "stm32l1xx_hal_gpio.h"
#include "CAN.h"
#include "cmsis_os.h"
#include "main.h"

extern osMutexId_t SPIMutexHandle;

void greenSwitch(void const* arg);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "stm32l1xx.h"
#include "stm32l1xx_hal_gpio.h"
#include "CAN.h"
#include "cmsis_os.h"
#include "main.h"

extern osMutexId_t SPIMutexHandle;

void greenSwitchTask(void const* arg);
53 changes: 29 additions & 24 deletions Recruit-Training/Embedded-Recruit-Training/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
Expand All @@ -28,7 +27,7 @@ extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
#include "stm32l1xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
Expand Down Expand Up @@ -58,28 +57,34 @@ void Error_Handler(void);
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define PH0_OSC_IN_Pin GPIO_PIN_0
#define PH0_OSC_IN_GPIO_Port GPIOH
#define PH1_OSC_OUT_Pin GPIO_PIN_1
#define PH1_OSC_OUT_GPIO_Port GPIOH
#define LED_RED_Pin GPIO_PIN_5
#define LED_RED_GPIO_Port GPIOA
#define LED_GREEN_Pin GPIO_PIN_6
#define LED_GREEN_GPIO_Port GPIOA
#define SWDIO_Pin GPIO_PIN_13
#define SWDIO_GPIO_Port GPIOA
#define SWCLK_Pin GPIO_PIN_14
#define SWCLK_GPIO_Port GPIOA
#define SWO_Pin GPIO_PIN_3
#define SWO_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
#define SPI1_CS_Pin GPIO_PIN_4
#define SPI1_CS_GPIO_Port GPIOA
#define CANINT_Pin GPIO_PIN_4
#define CANINT_GPIO_Port GPIOC
#define CAN_RX0BF_Pin GPIO_PIN_5
#define CAN_RX0BF_GPIO_Port GPIOC
#define CAN_RX0BF_EXTI_IRQn EXTI9_5_IRQn
#define CAN_RX1BF_Pin GPIO_PIN_0
#define CAN_RX1BF_GPIO_Port GPIOB
#define GND_Pin GPIO_PIN_12
#define GND_GPIO_Port GPIOB
#define VDD_Pin GPIO_PIN_13
#define VDD_GPIO_Port GPIOB
#define BLUE_SWITCH_Pin GPIO_PIN_8
#define BLUE_SWITCH_GPIO_Port GPIOC
#define GREEN_SWITCH_Pin GPIO_PIN_9
#define GREEN_SWITCH_GPIO_Port GPIOC
#define LED_BLUE_Pin GPIO_PIN_10
#define LED_BLUE_GPIO_Port GPIOC
#define LED_RED_Pin GPIO_PIN_12
#define LED_RED_GPIO_Port GPIOC

/* USER CODE BEGIN Private defines */
static const unsigned int TASK_QUEUE_TIMEOUT = 0; // 0ms
/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Loading