Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Mar 26, 2024
1 parent c6fe15b commit a8f2dc7
Show file tree
Hide file tree
Showing 34 changed files with 2,695 additions and 355 deletions.
33 changes: 27 additions & 6 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.331241973" name="Debug" parent="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.331241973" name="Debug" parent="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug" prebuildStep="">
<folderInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.331241973." name="/" resourcePath="">
<toolChain id="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.debug.454728105" name="MCU ARM GCC" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.debug">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu.38962375" name="MCU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu" useByScannerDiscovery="true" value="STM32L476RGTx" valueType="string"/>
Expand All @@ -25,9 +25,11 @@
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1044600179" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.756928727" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32L476RGTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L4xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32L476xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.720046019" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="4" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.417945529" name="Toolchain" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_cpp.1406644272" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_cpp" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_cpp.value.standard_c_standard_cpp" valueType="enumerated"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.945127982" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
<builder buildPath="${workspace_loc:/task4}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.41523802" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.402925686" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
<tool command="g++" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.402925686" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel.51257419" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel.value.g3" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.definedsymbols.579244450" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.definedsymbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="DEBUG"/>
Expand All @@ -54,6 +56,7 @@
<listOptionValue builtIn="false" value="../Core/External/Proto/Generated"/>
<listOptionValue builtIn="false" value="../ThirdParty"/>
<listOptionValue builtIn="false" value="../Core/External/Proto/Buffer"/>
<listOptionValue builtIn="false" value="../Core/External/RingBuffer"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1702390565" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>
Expand All @@ -71,13 +74,24 @@
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32L4xx/Include"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../Core/External/RingBuffer"/>
<listOptionValue builtIn="false" value="../Core/External/Sensor"/>
<listOptionValue builtIn="false" value="../Core/External/Proto"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/Indicator"/>
<listOptionValue builtIn="false" value="../Core/External/Proto/Generated"/>
<listOptionValue builtIn="false" value="../ThirdParty"/>
<listOptionValue builtIn="false" value="../Core/External/Proto/Buffer/Read"/>
<listOptionValue builtIn="false" value="../Core/External/Proto/Buffer/Write"/>
<listOptionValue builtIn="false" value="../Core/External/Proto/Buffer"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.input.cpp.425825475" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.input.cpp"/>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.1926935555" name="MCU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.1926935555" name="MCU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.systemcalls.552443768" name="System calls" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.systemcalls" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.systemcalls.value.minimalimplementation" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script.695225605" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script" value="${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld}" valueType="string"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input.592307479" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.582092523" name="MCU G++ Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script.30566923" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script" value="${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld}" valueType="string"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.input.1339005471" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.input">
Expand Down Expand Up @@ -166,7 +180,14 @@
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.input.cpp.1921150143" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.input.cpp"/>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.739188134" name="MCU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.739188134" name="MCU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.systemcalls.1174496947" name="System calls" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.systemcalls" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.systemcalls.value.minimalimplementation" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script.1750919812" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script" value="${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld}" valueType="string"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input.985046144" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.2005041740" name="MCU G++ Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script.466307801" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.option.script" value="${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld}" valueType="string"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.input.1828013521" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.input">
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: xanderhendriks/action-build-stm32cubeide@v10.0
with:
project-path: '.'
project-target: './Debug'
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<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>
<nature>org.eclipse.cdt.core.ccnature</nature>
</natures>
</projectDescription>
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ else ()
add_compile_options(-Og -g)
endif ()

include_directories(Core/Inc Drivers/STM32L4xx_HAL_Driver/Inc Drivers/STM32L4xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32L4xx/Include Drivers/CMSIS/Include Core/External/Sensor Core/External/Proto Core/External/Tools/Indicator Core/External/Proto/Generated ThirdParty Core/External/Proto/Buffer)
include_directories(Core/Inc Drivers/STM32L4xx_HAL_Driver/Inc Drivers/STM32L4xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32L4xx/Include Drivers/CMSIS/Include Core/External/Sensor Core/External/Proto Core/External/Tools/Indicator Core/External/Proto/Generated ThirdParty Core/External/Proto/Buffer Core/External/RingBuffer)

add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32L476xx)

file(GLOB_RECURSE SOURCES "ThirdParty/*.*" "Core/*.*" "Drivers/*.*")

set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32L476RGTX_FLASH.ld
Core/External/Timer/timer.cpp
Core/External/Timer/timer.h
Core/External/State/state.cpp
Core/External/State/state.h)

add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
add_link_options(-mcpu=cortex-m4 -mthumb -mthumb-interwork)
Expand Down
54 changes: 54 additions & 0 deletions Core/External/Proto/Buffer/Read/read_buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "read_buffer.h"

ReadBuffer::ReadBuffer() : index(0), size(0), bytes{0U} {
}

void ReadBuffer::set_data(uint8_t *src1, const uint32_t src2) {
this->bytes = src1;
this->size = src2;
}

uint32_t ReadBuffer::get_size() const {
return index;
}

uint32_t ReadBuffer::get_max_size() const {
return size;
}

bool ReadBuffer::peek(uint8_t &byte) const {
bool result = this->index < this->size;
if (result) {
byte = this->bytes[this->index];
}

return result;
}

bool ReadBuffer::advance() {
const bool result = this->index < this->size;
if (result) {
++this->index;
}
return result;
}

bool ReadBuffer::advance(const uint32_t src) {
this->index += src;
const bool result = this->index < this->size;
if (result) {
this->index = this->size;
}

return result;
}

bool ReadBuffer::pop(uint8_t &byte) {
bool result = this->index < this->size;
if (result) {
byte = this->bytes[this->index];
++this->index;
}

return result;
}
71 changes: 71 additions & 0 deletions Core/External/Proto/Buffer/Read/read_buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef LIGHT_DETECTOR_READ_BUFFER_H
#define LIGHT_DETECTOR_READ_BUFFER_H

#include <stdio.h>
#include "ReadBufferInterface.h"

/**
* Represents read buffer implementation for protocol buffers serialization.
*/
class ReadBuffer : public EmbeddedProto::ReadBufferInterface {
public:
ReadBuffer();

virtual ~ReadBuffer() = default;

/**
* Sets given buffer data.
*
* @param src1 - given buffer source.
* @param src2 - given buffer source size.
*/
void set_data(uint8_t *src1, uint32_t src2);

/**
* @see EmbeddedProto::ReadBufferInterface
*/
[[nodiscard]] uint32_t get_size() const override;

/**
* @see EmbeddedProto::ReadBufferInterface
*/
[[nodiscard]] uint32_t get_max_size() const override;

/**
* @see EmbeddedProto::ReadBufferInterface
*/
bool peek(uint8_t &byte) const override;

/**
* @see EmbeddedProto::ReadBufferInterface
*/
bool advance() override;

/**
* @see EmbeddedProto::ReadBufferInterface
*/
bool advance(const uint32_t N) override;

/**
* @see EmbeddedProto::ReadBufferInterface
*/
bool pop(uint8_t &byte) override;

private:
/**
* Represents current size of the buffer.
*/
uint32_t index;

/**
* Represents max size of the buffer.
*/
uint32_t size;

/**
* Represents current buffer data.
*/
uint8_t *bytes;
};

#endif //LIGHT_DETECTOR_READ_BUFFER_H
49 changes: 49 additions & 0 deletions Core/External/Proto/Buffer/Write/write_buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef _DEMO_WRITE_BUFFER_H_
#define _DEMO_WRITE_BUFFER_H_

#include "write_buffer.h"

//WriteBuffer()
// : bytes_used_(0),
// bytes_{0U} {
//
//}
//
//virtual ~WriteBuffer() = default;
//
//void clear() override {
//bytes_used_ = 0;
//}
//
//uint32_t get_size() const override {
//return bytes_used_;
//}
//
//uint32_t get_max_size() const override {
//return BUFFER_SIZE;
//}
//
//uint32_t get_available_size() const override {
//return -bytes_used_;
//}
//
//bool push(const uint8_t byte) override {
//bool result = BUFFER_SIZE > bytes_used_;
//if (result) {
//bytes_[bytes_used_] = byte;
//++bytes_used_;
//}
//return result;
//}
//
//bool push(const uint8_t *bytes, const uint32_t length) override {
//bool result = BUFFER_SIZE >= (bytes_used_ + length);
//if (result) {
//memcpy(bytes_ + bytes_used_, bytes, length);
//bytes_used_ += length;
//}
//return result;
//}


#endif // _DEMO_WRITE_BUFFER_H_
82 changes: 82 additions & 0 deletions Core/External/Proto/Buffer/Write/write_buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef LIGHT_DETECTOR_WRITE_BUFFER_H
#define LIGHT_DETECTOR_WRITE_BUFFER_H

#include <WriteBufferInterface.h>
#include <stdio.h>
#include <cstring>

/**
* Represents write buffer implementation for protocol buffers serialization.
*
* @tparam BUFFER_SIZE
*/
template<uint32_t BUFFER_SIZE>
class WriteBuffer : public EmbeddedProto::WriteBufferInterface {
public:
WriteBuffer();

virtual ~WriteBuffer() = default;

/**
* @see EmbeddedProto::WriteBufferInterface
*/
void clear() override;

/**
* @see EmbeddedProto::WriteBufferInterface
*/
[[nodiscard]] uint32_t get_size() const override {
return bytes_used;
}

/**
* @see EmbeddedProto::WriteBufferInterface
*/
[[nodiscard]] uint32_t get_max_size() const override {
return BUFFER_SIZE;
}

/**
* @see EmbeddedProto::WriteBufferInterface
*/
[[nodiscard]] uint32_t get_available_size() const override {
return -bytes_used;
}

/**
* @see EmbeddedProto::WriteBufferInterface
*/
bool push(const uint8_t byte) override {
bool result = BUFFER_SIZE > bytes_used;
if (result) {
bytes[bytes_used] = byte;
++bytes_used;
}
return result;
}

/**
* @see EmbeddedProto::WriteBufferInterface
*/
bool push(const uint8_t *bytes, const uint32_t length) override {
bool result = BUFFER_SIZE >= (bytes_used + length);
if (result) {
memcpy(bytes, bytes + bytes_used, length);
bytes_used += length;
}
return result;
}

private:
/**
* Represents amount of currently used bytes by buffer.
*/
uint32_t bytes_used;

/**
* Represents current buffer data.
*/
uint8_t bytes[BUFFER_SIZE];
};

#endif //LIGHT_DETECTOR_WRITE_BUFFER_H
Loading

0 comments on commit a8f2dc7

Please sign in to comment.