[WIP] Add syntax check for rust and C\C++ code (#108)

* proof of concept

* fix syntax for rust and add auto fix syntax

* fix syntax for C

* fix bug with files owner

* add information to wiki

* try to add ci

* format code from master

* even more format fixes

* change docker to docker-compose

* Exclude ./target_*/build directories from format check

* Run rustfmt only on project files

* add ulimit setup for long clang list

* merge

* fix rustfmt, exclude target Inc directory

* sync with master

* abspath

Co-authored-by: aanper <mail@s3f.ru>
Co-authored-by: Vadim Kaushan <admin@disasm.info>
This commit is contained in:
Nikita Beletskii 2020-09-30 02:18:30 +03:00 committed by GitHub
parent 7ded31c19d
commit 110a9efc3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
73 changed files with 4354 additions and 4667 deletions

86
.clang-format Normal file
View File

@ -0,0 +1,86 @@
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeComma
BreakStringLiterals: false
ColumnLimit: 99
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
# Taken from git's rules
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp03
TabWidth: 4
UseTab: Never

View File

@ -23,6 +23,12 @@ jobs:
- name: Build docker image
uses: ./.github/actions/docker
- name: Check syntax
uses: ./.github/actions/docker
continue-on-error: true
with:
run: /syntax_check.sh
- name: Build target_lo in docker
uses: ./.github/actions/docker
with:

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
.idea/
target_lo/build/
target_*/build/
bindings/

View File

@ -9,9 +9,7 @@ void coreglitch_demo_0(void* p) {
fuprintf(log, "coreglitch demo!\n");
// open record
FuriRecordSubscriber* fb_record = furi_open(
"u8g2_fb", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* fb_record = furi_open("u8g2_fb", false, false, NULL, NULL, NULL);
if(fb_record == NULL) {
fuprintf(log, "[widget] cannot create fb record\n");
@ -33,13 +31,12 @@ void coreglitch_demo_0(void* p) {
1.0,
1.5,
0.75,
0.8
0.8,
};
uint8_t cnt = 0;
while(1) {
for(size_t note_idx = 0; note_idx < 400; note_idx++) {
float scale = scales[((cnt + note_idx) / 16) % 4];
@ -56,7 +53,6 @@ void coreglitch_demo_0(void* p) {
cnt++;
u8g2_t* fb = furi_take(fb_record);
if(fb != NULL) {
u8g2_SetDrawColor(fb, 0);

View File

@ -7,7 +7,8 @@ extern SPI_HandleTypeDef hspi1;
// TODO rewrite u8g2 to pass thread-local context in this handlers
static uint8_t u8g2_gpio_and_delay_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
static uint8_t
u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) {
switch(msg) {
//Initialize SPI peripheral
case U8X8_MSG_GPIO_AND_DELAY_INIT:
@ -36,7 +37,8 @@ static uint8_t u8g2_gpio_and_delay_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_
#endif
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
HAL_GPIO_WritePin(
DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
break;
default:
@ -67,7 +69,8 @@ static uint8_t u8x8_hw_spi_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, voi
#endif
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
HAL_GPIO_WritePin(
DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
break;
case U8X8_MSG_BYTE_INIT:
@ -131,8 +134,10 @@ void display_u8g2(void* p) {
HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET);
u8g2_t _u8g2;
u8g2_Setup_st7565_erc12864_alt_f(&_u8g2, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32);
u8g2_InitDisplay(&_u8g2); // send init sequence to the display, display is in sleep mode after this
u8g2_Setup_st7565_erc12864_alt_f(
&_u8g2, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32);
u8g2_InitDisplay(
&_u8g2); // send init sequence to the display, display is in sleep mode after this
u8g2_SetContrast(&_u8g2, 36);
if(!furi_create("u8g2_fb", (void*)&_u8g2, sizeof(_u8g2))) {
@ -153,9 +158,8 @@ void display_u8g2(void* p) {
DisplayCtx ctx = {.update = update, .log = log};
// subscribe to record. ctx will be passed to handle_fb_change
FuriRecordSubscriber* fb_record = furi_open(
"u8g2_fb", false, false, handle_fb_change, NULL, &ctx
);
FuriRecordSubscriber* fb_record =
furi_open("u8g2_fb", false, false, handle_fb_change, NULL, &ctx);
if(fb_record == NULL) {
fuprintf(log, "[display] cannot open fb record\n");

View File

@ -78,9 +78,8 @@ void application_ipc_display(void* p) {
IpcCtx ctx = {.events = events, .log = log};
// subscribe to record. ctx will be passed to handle_fb_change
FuriRecordSubscriber* fb_record = furi_open(
"test_fb", false, false, handle_fb_change, NULL, &ctx
);
FuriRecordSubscriber* fb_record =
furi_open("test_fb", false, false, handle_fb_change, NULL, &ctx);
if(fb_record == NULL) {
fuprintf(log, "[display] cannot open fb record\n");
@ -120,15 +119,12 @@ void application_ipc_display(void* p) {
}
}
// Widget application
void application_ipc_widget(void* p) {
FuriRecordSubscriber* log = get_default_log();
// open record
FuriRecordSubscriber* fb_record = furi_open(
"test_fb", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* fb_record = furi_open("test_fb", false, false, NULL, NULL, NULL);
if(fb_record == NULL) {
fuprintf(log, "[widget] cannot create fb record\n");

View File

@ -8,9 +8,7 @@ void u8g2_example(void* p) {
delay(1000);
// open record
FuriRecordSubscriber* fb_record = furi_open(
"u8g2_fb", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* fb_record = furi_open("u8g2_fb", false, false, NULL, NULL, NULL);
if(fb_record == NULL) {
fuprintf(log, "[widget] cannot create fb record\n");

View File

@ -30,9 +30,8 @@ bool test_furi_pipe_record(FuriRecordSubscriber* log) {
}
// 2. Open/subscribe to it
FuriRecordSubscriber* pipe_record = furi_open(
"test/pipe", false, false, pipe_record_cb, NULL, NULL
);
FuriRecordSubscriber* pipe_record =
furi_open("test/pipe", false, false, pipe_record_cb, NULL, NULL);
if(pipe_record == NULL) {
fuprintf(log, "cannot open record\n");
return false;
@ -97,9 +96,8 @@ bool test_furi_holding_data(FuriRecordSubscriber* log) {
}
// 2. Open/Subscribe on it
FuriRecordSubscriber* holding_record = furi_open(
"test/holding", false, false, holding_record_cb, NULL, NULL
);
FuriRecordSubscriber* holding_record =
furi_open("test/holding", false, false, holding_record_cb, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
return false;
@ -163,9 +161,8 @@ typedef struct {
void furi_concurent_app(void* p) {
FuriRecordSubscriber* log = (FuriRecordSubscriber*)p;
FuriRecordSubscriber* holding_record = furi_open(
"test/concurrent", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* holding_record =
furi_open("test/concurrent", false, false, NULL, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
furiac_exit(NULL);
@ -202,18 +199,15 @@ bool test_furi_concurrent_access(FuriRecordSubscriber* log) {
}
// 2. Open it
FuriRecordSubscriber* holding_record = furi_open(
"test/concurrent", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* holding_record =
furi_open("test/concurrent", false, false, NULL, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
return false;
}
// 3. Create second app for interact with it
FuriApp* second_app = furiac_start(
furi_concurent_app, "furi concurent app", (void*)log
);
FuriApp* second_app = furiac_start(furi_concurent_app, "furi concurent app", (void*)log);
// 4. multiply ConcurrentValue::a
for(size_t i = 0; i < 4; i++) {
@ -259,7 +253,6 @@ TEST: non-existent data
TODO: implement this test
*/
bool test_furi_nonexistent_data(FuriRecordSubscriber* log) {
return true;
}
@ -326,9 +319,8 @@ void furi_mute_parent_app(void* p) {
}
// 2. Open watch handler: solo=false, no_mute=false, subscribe to data
FuriRecordSubscriber* watch_handler = furi_open(
"test/mute", false, false, mute_record_cb, NULL, NULL
);
FuriRecordSubscriber* watch_handler =
furi_open("test/mute", false, false, mute_record_cb, NULL, NULL);
if(watch_handler == NULL) {
fuprintf(log, "cannot open watch handler\n");
furiac_exit(NULL);
@ -342,16 +334,13 @@ void furi_mute_parent_app(void* p) {
bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// 1. Create "parent" application:
FuriApp* parent_app = furiac_start(
furi_mute_parent_app, "parent app", (void*)log
);
FuriApp* parent_app = furiac_start(furi_mute_parent_app, "parent app", (void*)log);
delay(2); // wait creating record
// 2. Open handler A: solo=false, no_mute=false, NULL subscriber. Subscribe to state.
FuriRecordSubscriber* handler_a = furi_open(
"test/mute", false, false, NULL, mute_record_state_cb, NULL
);
FuriRecordSubscriber* handler_a =
furi_open("test/mute", false, false, NULL, mute_record_state_cb, NULL);
if(handler_a == NULL) {
fuprintf(log, "cannot open handler A\n");
return false;
@ -371,9 +360,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
}
// 3. Open handler B: solo=true, no_mute=true, NULL subscriber.
FuriRecordSubscriber* handler_b = furi_open(
"test/mute", true, true, NULL, NULL, NULL
);
FuriRecordSubscriber* handler_b = furi_open("test/mute", true, true, NULL, NULL, NULL);
if(handler_b == NULL) {
fuprintf(log, "cannot open handler B\n");
return false;
@ -400,7 +387,6 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
test_counter = 3;
// Try to write data to B and check that subscriber get data.
if(!furi_write(handler_b, &test_counter, sizeof(uint8_t))) {
fuprintf(log, "write to B failed\n");
@ -412,11 +398,8 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
return false;
}
// 4. Open hadler C: solo=true, no_mute=false, NULL subscriber.
FuriRecordSubscriber* handler_c = furi_open(
"test/mute", true, false, NULL, NULL, NULL
);
FuriRecordSubscriber* handler_c = furi_open("test/mute", true, false, NULL, NULL, NULL);
if(handler_c == NULL) {
fuprintf(log, "cannot open handler C\n");
return false;
@ -427,9 +410,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// TODO: Try to write data to C and check that subscriber get data.
// 5. Open handler D: solo=false, no_mute=false, NULL subscriber.
FuriRecordSubscriber* handler_d = furi_open(
"test/mute", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* handler_d = furi_open("test/mute", false, false, NULL, NULL, NULL);
if(handler_d == NULL) {
fuprintf(log, "cannot open handler D\n");
return false;

View File

@ -66,6 +66,5 @@ void flipper_test_app(void* p) {
rust_uart_write();
furiac_exit(NULL);
}

View File

@ -8,6 +8,8 @@ fn main() {
cbindgen::generate(&crate_dir)
.expect("Unable to generate cbindgen bindings")
.write_to_file(
Path::new(&crate_dir).join("bindings").join(format!("{}.h", pkg_name))
Path::new(&crate_dir)
.join("bindings")
.join(format!("{}.h", pkg_name)),
);
}

View File

@ -1,14 +1,13 @@
#![no_std]
#[cfg(target_arch = "arm")]
use flipper_f1_sys::hal::{HAL_UART_Transmit_IT, huart1};
use flipper_f1_sys::hal::{huart1, HAL_UART_Transmit_IT};
#[no_mangle]
pub extern "C" fn add(a: u32, b: u32) -> u32 {
a + b
}
#[no_mangle]
pub extern "C" fn rust_uart_write() {
let string = "Rust test string\n";
@ -28,12 +27,13 @@ pub extern "C" fn rust_uart_write() {
}
}
mod aux {
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop { continue }
loop {
continue;
}
}
}

View File

@ -64,28 +64,23 @@ impl BindingsGenerator {
let includes = [
// This are bindings generated by cbindgen nearby
&flipper_core_bindings.to_string_lossy(),
&self.gcc_include_dir.to_string_lossy(),
];
#[rustfmt::skip]
return bindgen::Builder::default()
.use_core()
.ctypes_prefix("self")
.blacklist_type("__uint8_t")
.blacklist_type("__uint32_t")
.blacklist_type("c_int")
.blacklist_type("__int32_t")
// TODO there's no .no_debug method, to disable only for specific type
.derive_debug(false)
.clang_arg("-DUSE_HAL_DRIVER")
.clang_arg("-DSTM32L476xx")
.clang_arg("-DBUTON_INVERT=false")
.clang_arg("-DDEBUG_UART=huart1")
.clang_args(
(includes.iter().map(|x| From::from(x as &str)).chain(stm32_sdk_includes))
.map(|include| format!("-I{}", include))

View File

@ -1,5 +1,4 @@
#![no_std]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

View File

@ -57,9 +57,8 @@ bool furi_create(const char* name, void* value, size_t size) {
}
records[current_buffer_idx].mute_counter = 0;
records[current_buffer_idx].mutex = xSemaphoreCreateMutexStatic(
&records[current_buffer_idx].mutex_buffer
);
records[current_buffer_idx].mutex =
xSemaphoreCreateMutexStatic(&records[current_buffer_idx].mutex_buffer);
records[current_buffer_idx].value = value;
records[current_buffer_idx].size = size;
records[current_buffer_idx].name = name;
@ -74,14 +73,12 @@ bool furi_create(const char* name, void* value, size_t size) {
return true;
}
FuriRecordSubscriber* furi_open(
const char* name,
FuriRecordSubscriber* furi_open(const char* name,
bool solo,
bool no_mute,
FlipperRecordCallback value_callback,
FlipperRecordStateCallback state_callback,
void* ctx
) {
void* ctx) {
#ifdef FURI_DEBUG
printf("[FURI] opening %s record\n", name);
#endif
@ -155,7 +152,6 @@ FuriRecordSubscriber* furi_open(
return subscriber;
}
void furi_close(FuriRecordSubscriber* handler) {
#ifdef FURI_DEBUG
printf("[FURI] closing %s record\n", handler->record->name);
@ -181,10 +177,7 @@ static void furi_notify(FuriRecordSubscriber* handler, const void* value, size_t
if(handler->record->subscribers[i].allocated) {
if(handler->record->subscribers[i].cb != NULL) {
handler->record->subscribers[i].cb(
value,
size,
handler->record->subscribers[i].ctx
);
value, size, handler->record->subscribers[i].ctx);
}
}
}
@ -240,7 +233,9 @@ bool furi_write(FuriRecordSubscriber* handler, const void* value, size_t size) {
if(handler == NULL || handler->record == NULL || value == NULL) {
#ifdef FURI_DEBUG
printf("[FURI] write: null param %x %x\n", (uint32_t)(size_t)handler, (uint32_t)(size_t)value);
printf("[FURI] write: null param %x %x\n",
(uint32_t)(size_t)handler,
(uint32_t)(size_t)value);
#endif
return false;
@ -262,10 +257,7 @@ bool furi_write(FuriRecordSubscriber* handler, const void* value, size_t size) {
}
// check mute
if(
handler->record->mute_counter != handler->mute_counter
&& !handler->no_mute
) {
if(handler->record->mute_counter != handler->mute_counter && !handler->no_mute) {
#ifdef FURI_DEBUG
printf("[FURI] write: muted\n");
#endif

View File

@ -90,7 +90,6 @@ bool furiac_kill(FuriApp* app);
// find task pointer by handle
FuriApp* find_task(TaskHandle_t handler);
/*!
Creates named FURI record.
\param[in] name you can open this record anywhere
@ -110,14 +109,12 @@ When appication has exited or record has closed, all handlers is unmuted.
It may be useful for concurrently acces to resources like framebuffer or beeper.
\param[in] no_mute if true, another applications cannot mute this handler.
*/
FuriRecordSubscriber* furi_open(
const char* name,
FuriRecordSubscriber* furi_open(const char* name,
bool solo,
bool no_mute,
FlipperRecordCallback value_callback,
FlipperRecordStateCallback state_callback,
void* ctx
);
void* ctx);
/*!

View File

@ -44,15 +44,14 @@ FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) {
}
// create task on static stack memory
task_buffer[current_buffer_idx].handler = xTaskCreateStatic(
(TaskFunction_t)app,
task_buffer[current_buffer_idx].handler =
xTaskCreateStatic((TaskFunction_t)app,
(const char* const)name,
DEFAULT_STACK_SIZE / 4, // freertos specify stack size in words
(void* const)param,
tskIDLE_PRIORITY + 3, // normal priority
stack_buffer[current_buffer_idx],
&task_info_buffer[current_buffer_idx]
);
&task_info_buffer[current_buffer_idx]);
// save task
task_buffer[current_buffer_idx].application = app;

View File

@ -41,7 +41,9 @@ bool register_tty_uart() {
return false;
}
FILE* fp = fopencookie(NULL, "w", (cookie_io_functions_t) {
FILE* fp = fopencookie(NULL,
"w",
(cookie_io_functions_t){
.read = NULL,
.write = stdout_write,
.seek = NULL,

View File

@ -12,4 +12,5 @@ services:
working_dir: "/project"
environment:
DISPLAY: $DISPLAY
TERM: xterm-256color
PATH: /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

View File

@ -1,6 +1,8 @@
FROM ubuntu:18.04
RUN apt-get update && \
ENV PATH /root/.cargo/bin:$PATH
RUN apt update && \
apt install -y --no-install-recommends \
make \
gcc-arm-none-eabi \
@ -17,10 +19,15 @@ RUN apt-get update && \
python \
python-pip \
libstdc++-arm-none-eabi-newlib \
libclang-10-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
libclang-10-dev \
clang-format-10 \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile=minimal --target thumbv7em-none-eabi thumbv7em-none-eabihf
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile=minimal --target thumbv7em-none-eabi thumbv7em-none-eabihf && \
rustup component add rustfmt --toolchain stable-x86_64-unknown-linux-gnu
COPY entrypoint.sh syntax_check.sh /
RUN chmod +x /syntax_check.sh
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

43
docker/syntax_check.sh Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -e
CLANG_FORMAT_BIN="/usr/bin/clang-format-10"
PATH="$HOME/.cargo/bin:${PATH}"
PROJECT_DIR=$(pwd)
cd $PROJECT_DIR
echo "RUN C\C++ SYNTAX CHECK"
C_FILES=$(find . \
-not \( -path './target_*/Middlewares' -prune \) \
-not \( -path './target_*/Drivers' -prune \) \
-not \( -path './target_*/build' -prune \) \
-not \( -path './target_*/Inc' -prune \) \
-not \( -path ./lib -prune \) \
-name *.c -o -name *.h -o -name *.cpp)
ulimit -s 65536
$CLANG_FORMAT_BIN --verbose -style=file -n --Werror --ferror-limit=0 $C_FILES
c_syntax_rc=$?
echo "RUN RUST SYNTAX CHECK"
cd $PROJECT_DIR/core-rs && cargo fmt -- --check
rust_syntax_rc=$?
if [[ $rust_syntax_rc -eq 0 ]] && [[ $c_syntax_rc -eq 0 ]]; then
echo "Code looks fine for me!"
exit 1
fi
read -p "Do you want fix syntax? (y/n): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
cd $PROJECT_DIR/core-rs && cargo fmt --
cd $PROJECT_DIR
# We use root in container and clang-format rewriting files. We'll need change owner to original
local_user=$(stat -c '%u' .clang-format)
$CLANG_FORMAT_BIN -style=file -i $C_FILES
chown $local_user $C_FILES

4
syntax_check.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "RUN SYNTAX CHECK INSIDE CONTAINER"
docker-compose exec dev ./docker/syntax_check.sh

View File

@ -111,15 +111,22 @@ PRIORITY THAN THIS! (higher priorities are lower numeric values. */
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
#define configKERNEL_INTERRUPT_PRIORITY \
(configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
#define configMAX_SYSCALL_INTERRUPT_PRIORITY \
(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
#define configASSERT(x) \
if((x) == 0) { \
taskDISABLE_INTERRUPTS(); \
for(;;) \
; \
}
/* USER CODE END 1 */
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS

View File

@ -9,11 +9,7 @@ GPIO and HAL implementations
#include <stdbool.h>
#include "main.h"
typedef enum {
GpioModeInput,
GpioModeOutput,
GpioModeOpenDrain
} GpioMode;
typedef enum { GpioModeInput, GpioModeOutput, GpioModeOpenDrain } GpioMode;
typedef struct {
GPIO_TypeDef* port;
@ -50,7 +46,8 @@ inline void app_tim_ic_init(bool both) {
HAL_TIM_OC_Stop(&htim8, TIM_CHANNEL_2);
TIM_IC_InitTypeDef sConfigIC = {0};
sConfigIC.ICPolarity = both ? TIM_INPUTCHANNELPOLARITY_BOTHEDGE : TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICPolarity = both ? TIM_INPUTCHANNELPOLARITY_BOTHEDGE :
TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;

View File

@ -38,10 +38,7 @@ extern "C" {
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
typedef enum {
TimerEventInputCapture,
TimerEventEndOfPulse
} TimerEvent;
typedef enum { TimerEventInputCapture, TimerEventEndOfPulse } TimerEvent;
/* USER CODE END ET */
@ -138,12 +135,24 @@ void register_tim8_callback_ch2(void(*callback)(uint16_t ccr, TimerEvent tim_eve
#define EM_PIN_GPIO_Port RFID_OUT_GPIO_Port
#define EM_PIN_Pin RFID_OUT_Pin
#define MISO_PIN GpioPin{.port = GPIOC, .pin = GPIO_PIN_11}
#define MISO_PIN \
GpioPin { \
.port = GPIOC, .pin = GPIO_PIN_11 \
}
// #define MOSI_PIN 11
#define SS_PIN GpioPin{.port = CC1101_CS_GPIO_Port, .pin = CC1101_CS_Pin}
#define SS_PIN \
GpioPin { \
.port = CC1101_CS_GPIO_Port, .pin = CC1101_CS_Pin \
}
//2 main, 5 remote, 3 M16
#define GDO2 GpioPin{.port = NULL, .pin = 0}
#define GDO0 GpioPin{.port = CC1101_G0_GPIO_Port, .pin = CC1101_G0_Pin}
#define GDO2 \
GpioPin { \
.port = NULL, .pin = 0 \
}
#define GDO0 \
GpioPin { \
.port = CC1101_G0_GPIO_Port, .pin = CC1101_G0_Pin \
}
/* USER CODE END Private defines */

View File

@ -141,7 +141,8 @@
* which is subject to manufacturing process variations.
*/
#if !defined(HSI48_VALUE)
#define HSI48_VALUE ((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
#define HSI48_VALUE \
((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
The real value my vary depending on manufacturing process variations.*/
#endif /* HSI48_VALUE */
@ -172,7 +173,8 @@
* frequency.
*/
#if !defined(EXTERNAL_SAI1_CLOCK_VALUE)
#define EXTERNAL_SAI1_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/
#define EXTERNAL_SAI1_CLOCK_VALUE \
((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/
#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
/**
@ -181,7 +183,8 @@
* frequency.
*/
#if !defined(EXTERNAL_SAI2_CLOCK_VALUE)
#define EXTERNAL_SAI2_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI2 External clock source in Hz*/
#define EXTERNAL_SAI2_CLOCK_VALUE \
((uint32_t)2097000U) /*!< Value of the SAI2 External clock source in Hz*/
#endif /* EXTERNAL_SAI2_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,

View File

@ -106,7 +106,8 @@
/* DEBUG macros */
#if(USBD_DEBUG_LEVEL > 0)
#define USBD_UsrLog(...) printf(__VA_ARGS__);\
#define USBD_UsrLog(...) \
printf(__VA_ARGS__); \
printf("\n");
#else
#define USBD_UsrLog(...)
@ -114,7 +115,8 @@
#if(USBD_DEBUG_LEVEL > 1)
#define USBD_ErrLog(...) printf("ERROR: ") ;\
#define USBD_ErrLog(...) \
printf("ERROR: "); \
printf(__VA_ARGS__); \
printf("\n");
#else
@ -122,7 +124,8 @@
#endif
#if(USBD_DEBUG_LEVEL > 2)
#define USBD_DbgLog(...) printf("DEBUG : ") ;\
#define USBD_DbgLog(...) \
printf("DEBUG : "); \
printf(__VA_ARGS__); \
printf("\n");
#else

View File

@ -38,7 +38,8 @@ void app_gpio_init(GpioPin gpio, GpioMode mode) {
void delay_us(uint32_t time) {
time *= 11.8;
while(time--) {}
while(time--) {
}
}
void pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) {

View File

@ -55,17 +55,20 @@
/* USER CODE END FunctionPrototypes */
/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
StackType_t** ppxIdleTaskStackBuffer,
uint32_t* pulIdleTaskStackSize);
/* GetTimerTaskMemory prototype (linked to static allocation support) */
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );
void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer,
StackType_t** ppxTimerTaskStackBuffer,
uint32_t* pulTimerTaskStackSize);
/* Hook prototypes */
void vApplicationIdleHook(void);
/* USER CODE BEGIN 2 */
__weak void vApplicationIdleHook( void )
{
__weak void vApplicationIdleHook(void) {
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
task. It is essential that code added to this hook function never attempts
@ -82,8 +85,9 @@ __weak void vApplicationIdleHook( void )
static StaticTask_t xIdleTaskTCBBuffer;
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
StackType_t** ppxIdleTaskStackBuffer,
uint32_t* pulIdleTaskStackSize) {
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
*ppxIdleTaskStackBuffer = &xIdleStack[0];
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
@ -95,8 +99,9 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackTy
static StaticTask_t xTimerTaskTCBBuffer;
static StackType_t xTimerStack[configTIMER_TASK_STACK_DEPTH];
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
{
void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer,
StackType_t** ppxTimerTaskStackBuffer,
uint32_t* pulTimerTaskStackSize) {
*ppxTimerTaskTCBBuffer = &xTimerTaskTCBBuffer;
*ppxTimerTaskStackBuffer = &xTimerStack[0];
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;

View File

@ -90,13 +90,11 @@ void StartDefaultTask(void const * argument);
* @brief The application entry point.
* @retval int
*/
int main(void)
{
int main(void) {
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
@ -160,8 +158,7 @@ int main(void)
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
while(1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
@ -173,8 +170,7 @@ int main(void)
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
@ -190,25 +186,23 @@ void SystemClock_Config(void)
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 |
RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
{
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) {
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USB
|RCC_PERIPHCLK_ADC;
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USB |
RCC_PERIPHCLK_ADC;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
@ -219,14 +213,12 @@ void SystemClock_Config(void)
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
Error_Handler();
}
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
if(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) {
Error_Handler();
}
}
@ -236,9 +228,7 @@ void SystemClock_Config(void)
* @param None
* @retval None
*/
static void MX_ADC1_Init(void)
{
static void MX_ADC1_Init(void) {
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
@ -266,15 +256,13 @@ static void MX_ADC1_Init(void)
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
if(HAL_ADC_Init(&hadc1) != HAL_OK) {
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
if(HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) {
Error_Handler();
}
/** Configure Regular Channel
@ -285,14 +273,12 @@ static void MX_ADC1_Init(void)
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
/**
@ -300,9 +286,7 @@ static void MX_ADC1_Init(void)
* @param None
* @retval None
*/
static void MX_COMP1_Init(void)
{
static void MX_COMP1_Init(void) {
/* USER CODE BEGIN COMP1_Init 0 */
/* USER CODE END COMP1_Init 0 */
@ -319,14 +303,12 @@ static void MX_COMP1_Init(void)
hcomp1.Init.Mode = COMP_POWERMODE_HIGHSPEED;
hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
if (HAL_COMP_Init(&hcomp1) != HAL_OK)
{
if(HAL_COMP_Init(&hcomp1) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN COMP1_Init 2 */
/* USER CODE END COMP1_Init 2 */
}
/**
@ -334,9 +316,7 @@ static void MX_COMP1_Init(void)
* @param None
* @retval None
*/
static void MX_DAC1_Init(void)
{
static void MX_DAC1_Init(void) {
/* USER CODE BEGIN DAC1_Init 0 */
/* USER CODE END DAC1_Init 0 */
@ -349,8 +329,7 @@ static void MX_DAC1_Init(void)
/** DAC Initialization
*/
hdac1.Instance = DAC1;
if (HAL_DAC_Init(&hdac1) != HAL_OK)
{
if(HAL_DAC_Init(&hdac1) != HAL_OK) {
Error_Handler();
}
/** DAC channel OUT1 config
@ -360,14 +339,12 @@ static void MX_DAC1_Init(void)
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE;
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
{
if(HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN DAC1_Init 2 */
/* USER CODE END DAC1_Init 2 */
}
/**
@ -375,9 +352,7 @@ static void MX_DAC1_Init(void)
* @param None
* @retval None
*/
static void MX_SPI1_Init(void)
{
static void MX_SPI1_Init(void) {
/* USER CODE BEGIN SPI1_Init 0 */
/* USER CODE END SPI1_Init 0 */
@ -400,14 +375,12 @@ static void MX_SPI1_Init(void)
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
if(HAL_SPI_Init(&hspi1) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */
/* USER CODE END SPI1_Init 2 */
}
/**
@ -415,9 +388,7 @@ static void MX_SPI1_Init(void)
* @param None
* @retval None
*/
static void MX_SPI3_Init(void)
{
static void MX_SPI3_Init(void) {
/* USER CODE BEGIN SPI3_Init 0 */
/* USER CODE END SPI3_Init 0 */
@ -440,14 +411,12 @@ static void MX_SPI3_Init(void)
hspi3.Init.CRCPolynomial = 7;
hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi3) != HAL_OK)
{
if(HAL_SPI_Init(&hspi3) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN SPI3_Init 2 */
/* USER CODE END SPI3_Init 2 */
}
/**
@ -455,9 +424,7 @@ static void MX_SPI3_Init(void)
* @param None
* @retval None
*/
static void MX_TIM5_Init(void)
{
static void MX_TIM5_Init(void) {
/* USER CODE BEGIN TIM5_Init 0 */
/* USER CODE END TIM5_Init 0 */
@ -474,29 +441,25 @@ static void MX_TIM5_Init(void)
htim5.Init.Period = 291;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_PWM_Init(&htim5) != HAL_OK)
{
if(HAL_TIM_PWM_Init(&htim5) != HAL_OK) {
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
if(HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) {
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 145;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
if(HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN TIM5_Init 2 */
/* USER CODE END TIM5_Init 2 */
HAL_TIM_MspPostInit(&htim5);
}
/**
@ -504,9 +467,7 @@ static void MX_TIM5_Init(void)
* @param None
* @retval None
*/
static void MX_TIM8_Init(void)
{
static void MX_TIM8_Init(void) {
/* USER CODE BEGIN TIM8_Init 0 */
/* USER CODE END TIM8_Init 0 */
@ -525,38 +486,32 @@ static void MX_TIM8_Init(void)
htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim8.Init.RepetitionCounter = 0;
htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim8) != HAL_OK)
{
if(HAL_TIM_Base_Init(&htim8) != HAL_OK) {
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)
{
if(HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK) {
Error_Handler();
}
if (HAL_TIM_IC_Init(&htim8) != HAL_OK)
{
if(HAL_TIM_IC_Init(&htim8) != HAL_OK) {
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)
{
if(HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK) {
Error_Handler();
}
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
if (HAL_TIM_IC_ConfigChannel(&htim8, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
{
if(HAL_TIM_IC_ConfigChannel(&htim8, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN TIM8_Init 2 */
/* USER CODE END TIM8_Init 2 */
}
/**
@ -564,9 +519,7 @@ static void MX_TIM8_Init(void)
* @param None
* @retval None
*/
static void MX_TIM15_Init(void)
{
static void MX_TIM15_Init(void) {
/* USER CODE BEGIN TIM15_Init 0 */
/* USER CODE END TIM15_Init 0 */
@ -585,14 +538,12 @@ static void MX_TIM15_Init(void)
htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim15.Init.RepetitionCounter = 0;
htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_OC_Init(&htim15) != HAL_OK)
{
if(HAL_TIM_OC_Init(&htim15) != HAL_OK) {
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
{
if(HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) {
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_TIMING;
@ -602,12 +553,10 @@ static void MX_TIM15_Init(void)
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
if(HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) {
Error_Handler();
}
if (HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
if(HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) {
Error_Handler();
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
@ -617,15 +566,13 @@ static void MX_TIM15_Init(void)
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK)
{
if(HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN TIM15_Init 2 */
/* USER CODE END TIM15_Init 2 */
HAL_TIM_MspPostInit(&htim15);
}
/**
@ -633,9 +580,7 @@ static void MX_TIM15_Init(void)
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{
static void MX_USART1_UART_Init(void) {
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
@ -653,14 +598,12 @@ static void MX_USART1_UART_Init(void)
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
if(HAL_UART_Init(&huart1) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
/**
@ -668,8 +611,7 @@ static void MX_USART1_UART_Init(void)
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
static void MX_GPIO_Init(void) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
@ -798,7 +740,6 @@ static void MX_GPIO_Init(void)
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
}
/* USER CODE BEGIN 4 */
@ -812,16 +753,14 @@ void app();
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void const * argument)
{
void StartDefaultTask(void const* argument) {
/* init code for USB_DEVICE */
MX_USB_DEVICE_Init();
/* USER CODE BEGIN 5 */
/* Infinite loop */
app();
for(;;)
{
for(;;) {
osDelay(1);
}
/* USER CODE END 5 */
@ -831,8 +770,7 @@ void StartDefaultTask(void const * argument)
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
void Error_Handler(void) {
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
@ -847,8 +785,7 @@ void Error_Handler(void)
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(char *file, uint32_t line)
{
void assert_failed(char* file, uint32_t line) {
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

View File

@ -63,8 +63,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
void HAL_MspInit(void) {
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
@ -87,11 +86,9 @@ void HAL_MspInit(void)
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hadc->Instance==ADC1)
{
if(hadc->Instance == ADC1) {
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
@ -118,7 +115,6 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
/* USER CODE END ADC1_MspInit 1 */
}
}
/**
@ -127,10 +123,8 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance==ADC1)
{
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) {
if(hadc->Instance == ADC1) {
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
@ -149,7 +143,6 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/**
@ -158,11 +151,9 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
* @param hcomp: COMP handle pointer
* @retval None
*/
void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp)
{
void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hcomp->Instance==COMP1)
{
if(hcomp->Instance == COMP1) {
/* USER CODE BEGIN COMP1_MspInit 0 */
/* USER CODE END COMP1_MspInit 0 */
@ -180,7 +171,6 @@ void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp)
/* USER CODE END COMP1_MspInit 1 */
}
}
/**
@ -189,10 +179,8 @@ void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp)
* @param hcomp: COMP handle pointer
* @retval None
*/
void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
{
if(hcomp->Instance==COMP1)
{
void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp) {
if(hcomp->Instance == COMP1) {
/* USER CODE BEGIN COMP1_MspDeInit 0 */
/* USER CODE END COMP1_MspDeInit 0 */
@ -206,7 +194,6 @@ void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
/* USER CODE END COMP1_MspDeInit 1 */
}
}
/**
@ -215,11 +202,9 @@ void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
* @param hdac: DAC handle pointer
* @retval None
*/
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hdac->Instance==DAC1)
{
if(hdac->Instance == DAC1) {
/* USER CODE BEGIN DAC1_MspInit 0 */
/* USER CODE END DAC1_MspInit 0 */
@ -239,7 +224,6 @@ void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
/* USER CODE END DAC1_MspInit 1 */
}
}
/**
@ -248,10 +232,8 @@ void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
* @param hdac: DAC handle pointer
* @retval None
*/
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
{
if(hdac->Instance==DAC1)
{
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac) {
if(hdac->Instance == DAC1) {
/* USER CODE BEGIN DAC1_MspDeInit 0 */
/* USER CODE END DAC1_MspDeInit 0 */
@ -267,7 +249,6 @@ void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
/* USER CODE END DAC1_MspDeInit 1 */
}
}
/**
@ -276,11 +257,9 @@ void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hspi->Instance==SPI1)
{
if(hspi->Instance == SPI1) {
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
@ -302,9 +281,7 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
else if(hspi->Instance==SPI3)
{
} else if(hspi->Instance == SPI3) {
/* USER CODE BEGIN SPI3_MspInit 0 */
/* USER CODE END SPI3_MspInit 0 */
@ -328,7 +305,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
/* USER CODE END SPI3_MspInit 1 */
}
}
/**
@ -337,10 +313,8 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
{
if(hspi->Instance==SPI1)
{
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) {
if(hspi->Instance == SPI1) {
/* USER CODE BEGIN SPI1_MspDeInit 0 */
/* USER CODE END SPI1_MspDeInit 0 */
@ -356,9 +330,7 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
/* USER CODE BEGIN SPI1_MspDeInit 1 */
/* USER CODE END SPI1_MspDeInit 1 */
}
else if(hspi->Instance==SPI3)
{
} else if(hspi->Instance == SPI3) {
/* USER CODE BEGIN SPI3_MspDeInit 0 */
/* USER CODE END SPI3_MspDeInit 0 */
@ -376,7 +348,6 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
/* USER CODE END SPI3_MspDeInit 1 */
}
}
/**
@ -385,10 +356,8 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
* @param htim_pwm: TIM_PWM handle pointer
* @retval None
*/
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
{
if(htim_pwm->Instance==TIM5)
{
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm) {
if(htim_pwm->Instance == TIM5) {
/* USER CODE BEGIN TIM5_MspInit 0 */
/* USER CODE END TIM5_MspInit 0 */
@ -398,7 +367,6 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
/* USER CODE END TIM5_MspInit 1 */
}
}
/**
@ -407,11 +375,9 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
* @param htim_base: TIM_Base handle pointer
* @retval None
*/
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
{
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(htim_base->Instance==TIM8)
{
if(htim_base->Instance == TIM8) {
/* USER CODE BEGIN TIM8_MspInit 0 */
/* USER CODE END TIM8_MspInit 0 */
@ -436,7 +402,6 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
/* USER CODE END TIM8_MspInit 1 */
}
}
/**
@ -445,10 +410,8 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
* @param htim_oc: TIM_OC handle pointer
* @retval None
*/
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef* htim_oc)
{
if(htim_oc->Instance==TIM15)
{
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef* htim_oc) {
if(htim_oc->Instance == TIM15) {
/* USER CODE BEGIN TIM15_MspInit 0 */
/* USER CODE END TIM15_MspInit 0 */
@ -458,14 +421,11 @@ void HAL_TIM_OC_MspInit(TIM_HandleTypeDef* htim_oc)
/* USER CODE END TIM15_MspInit 1 */
}
}
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
{
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(htim->Instance==TIM5)
{
if(htim->Instance == TIM5) {
/* USER CODE BEGIN TIM5_MspPostInit 0 */
/* USER CODE END TIM5_MspPostInit 0 */
@ -483,9 +443,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
/* USER CODE BEGIN TIM5_MspPostInit 1 */
/* USER CODE END TIM5_MspPostInit 1 */
}
else if(htim->Instance==TIM15)
{
} else if(htim->Instance == TIM15) {
/* USER CODE BEGIN TIM15_MspPostInit 0 */
/* USER CODE END TIM15_MspPostInit 0 */
@ -506,7 +464,6 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
/* USER CODE END TIM15_MspPostInit 1 */
}
}
/**
* @brief TIM_PWM MSP De-Initialization
@ -514,10 +471,8 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
* @param htim_pwm: TIM_PWM handle pointer
* @retval None
*/
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
{
if(htim_pwm->Instance==TIM5)
{
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm) {
if(htim_pwm->Instance == TIM5) {
/* USER CODE BEGIN TIM5_MspDeInit 0 */
/* USER CODE END TIM5_MspDeInit 0 */
@ -527,7 +482,6 @@ void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
/* USER CODE END TIM5_MspDeInit 1 */
}
}
/**
@ -536,10 +490,8 @@ void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
* @param htim_base: TIM_Base handle pointer
* @retval None
*/
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
{
if(htim_base->Instance==TIM8)
{
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) {
if(htim_base->Instance == TIM8) {
/* USER CODE BEGIN TIM8_MspDeInit 0 */
/* USER CODE END TIM8_MspDeInit 0 */
@ -557,7 +509,6 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
/* USER CODE END TIM8_MspDeInit 1 */
}
}
/**
@ -566,10 +517,8 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
* @param htim_oc: TIM_OC handle pointer
* @retval None
*/
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc)
{
if(htim_oc->Instance==TIM15)
{
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc) {
if(htim_oc->Instance == TIM15) {
/* USER CODE BEGIN TIM15_MspDeInit 0 */
/* USER CODE END TIM15_MspDeInit 0 */
@ -579,7 +528,6 @@ void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc)
/* USER CODE END TIM15_MspDeInit 1 */
}
}
/**
@ -588,11 +536,9 @@ void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc)
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
void HAL_UART_MspInit(UART_HandleTypeDef* huart) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(huart->Instance==USART1)
{
if(huart->Instance == USART1) {
/* USER CODE BEGIN USART1_MspInit 0 */
/* USER CODE END USART1_MspInit 0 */
@ -615,7 +561,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
/* USER CODE END USART1_MspInit 1 */
}
}
/**
@ -624,10 +569,8 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART1)
{
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) {
if(huart->Instance == USART1) {
/* USER CODE BEGIN USART1_MspDeInit 0 */
/* USER CODE END USART1_MspDeInit 0 */
@ -644,7 +587,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
/* USER CODE END USART1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */

View File

@ -70,8 +70,7 @@ extern TIM_HandleTypeDef htim8;
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
void NMI_Handler(void) {
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
@ -83,13 +82,11 @@ void NMI_Handler(void)
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
void HardFault_Handler(void) {
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
while(1) {
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
@ -98,13 +95,11 @@ void HardFault_Handler(void)
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
void MemManage_Handler(void) {
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
while(1) {
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */
}
@ -113,13 +108,11 @@ void MemManage_Handler(void)
/**
* @brief This function handles Prefetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
void BusFault_Handler(void) {
/* USER CODE BEGIN BusFault_IRQn 0 */
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
while(1) {
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */
}
@ -128,13 +121,11 @@ void BusFault_Handler(void)
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
void UsageFault_Handler(void) {
/* USER CODE BEGIN UsageFault_IRQn 0 */
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{
while(1) {
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
@ -143,8 +134,7 @@ void UsageFault_Handler(void)
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
void DebugMon_Handler(void) {
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/* USER CODE END DebugMonitor_IRQn 0 */
@ -156,15 +146,13 @@ void DebugMon_Handler(void)
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
void SysTick_Handler(void) {
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
#if(INCLUDE_xTaskGetSchedulerState == 1)
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
{
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
#endif /* INCLUDE_xTaskGetSchedulerState */
xPortSysTickHandler();
#if(INCLUDE_xTaskGetSchedulerState == 1)
@ -185,8 +173,7 @@ void SysTick_Handler(void)
/**
* @brief This function handles EXTI line0 interrupt.
*/
void EXTI0_IRQHandler(void)
{
void EXTI0_IRQHandler(void) {
/* USER CODE BEGIN EXTI0_IRQn 0 */
/* USER CODE END EXTI0_IRQn 0 */
@ -199,8 +186,7 @@ void EXTI0_IRQHandler(void)
/**
* @brief This function handles EXTI line1 interrupt.
*/
void EXTI1_IRQHandler(void)
{
void EXTI1_IRQHandler(void) {
/* USER CODE BEGIN EXTI1_IRQn 0 */
/* USER CODE END EXTI1_IRQn 0 */
@ -213,8 +199,7 @@ void EXTI1_IRQHandler(void)
/**
* @brief This function handles EXTI line2 interrupt.
*/
void EXTI2_IRQHandler(void)
{
void EXTI2_IRQHandler(void) {
/* USER CODE BEGIN EXTI2_IRQn 0 */
/* USER CODE END EXTI2_IRQn 0 */
@ -227,8 +212,7 @@ void EXTI2_IRQHandler(void)
/**
* @brief This function handles EXTI line4 interrupt.
*/
void EXTI4_IRQHandler(void)
{
void EXTI4_IRQHandler(void) {
/* USER CODE BEGIN EXTI4_IRQn 0 */
/* USER CODE END EXTI4_IRQn 0 */
@ -241,8 +225,7 @@ void EXTI4_IRQHandler(void)
/**
* @brief This function handles EXTI line[9:5] interrupts.
*/
void EXTI9_5_IRQHandler(void)
{
void EXTI9_5_IRQHandler(void) {
/* USER CODE BEGIN EXTI9_5_IRQn 0 */
/* USER CODE END EXTI9_5_IRQn 0 */
@ -262,20 +245,16 @@ void register_tim8_callback_ch2(void(*callback)(uint16_t ccr, TimerEvent tim_eve
/**
* @brief This function handles TIM8 capture compare interrupt.
*/
void TIM8_CC_IRQHandler(void)
{
void TIM8_CC_IRQHandler(void) {
/* USER CODE BEGIN TIM8_CC_IRQn 0 */
/* Capture compare 2 event */
if (__HAL_TIM_GET_FLAG(&htim8, TIM_FLAG_CC2) != RESET)
{
if (__HAL_TIM_GET_IT_SOURCE(&htim8, TIM_IT_CC2) != RESET)
{
if(__HAL_TIM_GET_FLAG(&htim8, TIM_FLAG_CC2) != RESET) {
if(__HAL_TIM_GET_IT_SOURCE(&htim8, TIM_IT_CC2) != RESET) {
__HAL_TIM_CLEAR_IT(&htim8, TIM_IT_CC2);
htim8.Channel = HAL_TIM_ACTIVE_CHANNEL_2;
/* Input capture event */
if ((htim8.Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U)
{
if((htim8.Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U) {
/*
#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
htim->IC_CaptureCallback(htim);
@ -288,8 +267,7 @@ void TIM8_CC_IRQHandler(void)
}
}
/* Output compare event */
else
{
else {
if(tim8_callback_ch2 != NULL) {
tim8_callback_ch2(0, TimerEventEndOfPulse);
}
@ -307,7 +285,6 @@ void TIM8_CC_IRQHandler(void)
}
}
/* USER CODE END TIM8_CC_IRQn 0 */
// HAL_TIM_IRQHandler(&htim8);
/* USER CODE BEGIN TIM8_CC_IRQn 1 */
@ -318,8 +295,7 @@ void TIM8_CC_IRQHandler(void)
/**
* @brief This function handles USB OTG FS global interrupt.
*/
void OTG_FS_IRQHandler(void)
{
void OTG_FS_IRQHandler(void) {
/* USER CODE BEGIN OTG_FS_IRQn 0 */
/* USER CODE END OTG_FS_IRQn 0 */

View File

@ -123,7 +123,8 @@
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
#define VECT_TAB_OFFSET \
0x00 /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
/******************************************************************************/
/**
@ -153,8 +154,18 @@
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
const uint32_t MSIRangeTable[12] = {100000U, 200000U, 400000U, 800000U, 1000000U, 2000000U, \
4000000U, 8000000U, 16000000U, 24000000U, 32000000U, 48000000U};
const uint32_t MSIRangeTable[12] = {100000U,
200000U,
400000U,
800000U,
1000000U,
2000000U,
4000000U,
8000000U,
16000000U,
24000000U,
32000000U,
48000000U};
/**
* @}
*/
@ -177,8 +188,7 @@
* @retval None
*/
void SystemInit(void)
{
void SystemInit(void) {
/* FPU settings ------------------------------------------------------------*/
#if(__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10 * 2) | (3UL << 11 * 2)); /* set CP10 and CP11 Full Access */
@ -253,25 +263,20 @@ void SystemInit(void)
* @param None
* @retval None
*/
void SystemCoreClockUpdate(void)
{
void SystemCoreClockUpdate(void) {
uint32_t tmp = 0U, msirange = 0U, pllvco = 0U, pllr = 2U, pllsource = 0U, pllm = 2U;
/* Get MSI Range frequency--------------------------------------------------*/
if((RCC->CR & RCC_CR_MSIRGSEL) == RESET)
{ /* MSISRANGE from RCC_CSR applies */
if((RCC->CR & RCC_CR_MSIRGSEL) == RESET) { /* MSISRANGE from RCC_CSR applies */
msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U;
}
else
{ /* MSIRANGE from RCC_CR applies */
} else { /* MSIRANGE from RCC_CR applies */
msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U;
}
/*MSI frequency range in HZ*/
msirange = MSIRangeTable[msirange];
/* Get SYSCLK source -------------------------------------------------------*/
switch (RCC->CFGR & RCC_CFGR_SWS)
{
switch(RCC->CFGR & RCC_CFGR_SWS) {
case 0x00: /* MSI used as system clock source */
SystemCoreClock = msirange;
break;
@ -291,8 +296,7 @@ void SystemCoreClockUpdate(void)
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U;
switch (pllsource)
{
switch(pllsource) {
case 0x02: /* HSI used as PLL clock source */
pllvco = (HSI_VALUE / pllm);
break;
@ -321,7 +325,6 @@ void SystemCoreClockUpdate(void)
SystemCoreClock >>= tmp;
}
/**
* @}
*/

View File

@ -63,27 +63,22 @@ extern USBD_DescriptorsTypeDef FS_Desc;
* Init USB device Library, add supported class and start the library
* @retval None
*/
void MX_USB_DEVICE_Init(void)
{
void MX_USB_DEVICE_Init(void) {
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
/* USER CODE END USB_DEVICE_Init_PreTreatment */
/* Init Device Library, add supported class and start the library. */
if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
{
if(USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) {
Error_Handler();
}
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)
{
if(USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) {
Error_Handler();
}
if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK)
{
if(USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) {
Error_Handler();
}
if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
{
if(USBD_Start(&hUsbDeviceFS) != USBD_OK) {
Error_Handler();
}
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */

View File

@ -139,21 +139,17 @@ static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len);
* @}
*/
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
{
CDC_Init_FS,
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = {CDC_Init_FS,
CDC_DeInit_FS,
CDC_Control_FS,
CDC_Receive_FS
};
CDC_Receive_FS};
/* Private functions ---------------------------------------------------------*/
/**
* @brief Initializes the CDC media low layer over the FS USB IP
* @retval USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Init_FS(void)
{
static int8_t CDC_Init_FS(void) {
/* USER CODE BEGIN 3 */
/* Set Application Buffers */
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
@ -166,8 +162,7 @@ static int8_t CDC_Init_FS(void)
* @brief DeInitializes the CDC media low layer
* @retval USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_DeInit_FS(void)
{
static int8_t CDC_DeInit_FS(void) {
/* USER CODE BEGIN 4 */
return (USBD_OK);
/* USER CODE END 4 */
@ -180,11 +175,9 @@ static int8_t CDC_DeInit_FS(void)
* @param length: Number of data to be sent (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) {
/* USER CODE BEGIN 5 */
switch(cmd)
{
switch(cmd) {
case CDC_SEND_ENCAPSULATED_COMMAND:
break;
@ -260,8 +253,7 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
* @param Len: Number of data received (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t* Len) {
/* USER CODE BEGIN 6 */
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
@ -280,8 +272,7 @@ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
* @param Len: Number of data to be sent (in bytes)
* @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
*/
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) {
uint8_t result = USBD_OK;
/* USER CODE BEGIN 7 */
USBD_CDC_HandleTypeDef* hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;

View File

@ -67,11 +67,9 @@ extern void SystemClock_Config(void);
*******************************************************************************/
/* MSP Init */
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
{
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(pcdHandle->Instance==USB_OTG_FS)
{
if(pcdHandle->Instance == USB_OTG_FS) {
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
/* USER CODE END USB_OTG_FS_MspInit 0 */
@ -92,14 +90,11 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
/* Enable VDDUSB */
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
{
if(__HAL_RCC_PWR_IS_CLK_DISABLED()) {
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_EnableVddUSB();
__HAL_RCC_PWR_CLK_DISABLE();
}
else
{
} else {
HAL_PWREx_EnableVddUSB();
}
@ -112,10 +107,8 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
}
}
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
{
if(pcdHandle->Instance==USB_OTG_FS)
{
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) {
if(pcdHandle->Instance == USB_OTG_FS) {
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
@ -129,14 +122,11 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11 | GPIO_PIN_12);
/* Disable VDDUSB */
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
{
if(__HAL_RCC_PWR_IS_CLK_DISABLED()) {
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_DisableVddUSB();
__HAL_RCC_PWR_CLK_DISABLE();
}
else
{
} else {
HAL_PWREx_DisableVddUSB();
}
@ -220,8 +210,7 @@ void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
{
USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
if ( hpcd->Init.speed != PCD_SPEED_FULL)
{
if(hpcd->Init.speed != PCD_SPEED_FULL) {
Error_Handler();
}
/* Set Speed. */
@ -248,8 +237,7 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData);
/* Enter in STOP mode. */
/* USER CODE BEGIN 2 */
if (hpcd->Init.low_power_enable)
{
if(hpcd->Init.low_power_enable) {
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
}
@ -271,8 +259,7 @@ void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
__HAL_PCD_UNGATE_PHYCLOCK(hpcd);
/* USER CODE BEGIN 3 */
if (hpcd->Init.low_power_enable)
{
if(hpcd->Init.low_power_enable) {
/* Reset SLEEPDEEP bit of Cortex System Control Register. */
SCB->SCR &= (uint32_t) ~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
SystemClockConfig_Resume();
@ -352,8 +339,7 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
* @param pdev: Device handle
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef* pdev) {
/* Init USB Ip. */
if(pdev->id == DEVICE_FS) {
/* Enable USB power on Pwrctrl CR2 register. */
@ -371,20 +357,21 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
{
if(HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK) {
Error_Handler();
}
#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
/* Register USB PCD CallBacks */
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback);
HAL_PCD_RegisterCallback(
&hpcd_USB_OTG_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback);
HAL_PCD_RegisterCallback(
&hpcd_USB_OTG_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback);
HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback);
HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback);
@ -403,8 +390,7 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
* @param pdev: Device handle
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef* pdev) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -435,8 +421,7 @@ USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
* @param pdev: Device handle
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef* pdev) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -467,8 +452,7 @@ USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
* @param pdev: Device handle
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef* pdev) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -502,8 +486,8 @@ USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
* @param ep_mps: Endpoint max packet size
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
{
USBD_StatusTypeDef
USBD_LL_OpenEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -535,8 +519,7 @@ USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uin
* @param ep_addr: Endpoint number
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -568,8 +551,7 @@ USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param ep_addr: Endpoint number
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -601,8 +583,7 @@ USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param ep_addr: Endpoint number
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -634,8 +615,7 @@ USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param ep_addr: Endpoint number
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -667,16 +647,12 @@ USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_add
* @param ep_addr: Endpoint number
* @retval Stall (1: Yes, 0: No)
*/
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
PCD_HandleTypeDef* hpcd = (PCD_HandleTypeDef*)pdev->pData;
if((ep_addr & 0x80) == 0x80)
{
if((ep_addr & 0x80) == 0x80) {
return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
}
else
{
} else {
return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
}
}
@ -687,8 +663,7 @@ uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param dev_addr: Device address
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
{
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef* pdev, uint8_t dev_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -722,8 +697,8 @@ USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_a
* @param size: Data size
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
{
USBD_StatusTypeDef
USBD_LL_Transmit(USBD_HandleTypeDef* pdev, uint8_t ep_addr, uint8_t* pbuf, uint16_t size) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -757,8 +732,8 @@ USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, u
* @param size: Data size
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
{
USBD_StatusTypeDef
USBD_LL_PrepareReceive(USBD_HandleTypeDef* pdev, uint8_t ep_addr, uint8_t* pbuf, uint16_t size) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -790,8 +765,7 @@ USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_a
* @param ep_addr: Endpoint number
* @retval Recived Data Size
*/
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*)pdev->pData, ep_addr);
}
@ -801,13 +775,10 @@ uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param msg: LPM message
* @retval None
*/
void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
{
switch (msg)
{
void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef* hpcd, PCD_LPM_MsgTypeDef msg) {
switch(msg) {
case PCD_LPM_L0_ACTIVE:
if (hpcd->Init.low_power_enable)
{
if(hpcd->Init.low_power_enable) {
SystemClockConfig_Resume();
/* Reset SLEEPDEEP bit of Cortex System Control Register. */
@ -822,8 +793,7 @@ void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
USBD_LL_Suspend(hpcd->pData);
/* Enter in STOP mode. */
if (hpcd->Init.low_power_enable)
{
if(hpcd->Init.low_power_enable) {
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
}
@ -836,8 +806,7 @@ void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
* @param Delay: Delay in ms
* @retval None
*/
void USBD_LL_Delay(uint32_t Delay)
{
void USBD_LL_Delay(uint32_t Delay) {
HAL_Delay(Delay);
}
@ -846,8 +815,7 @@ void USBD_LL_Delay(uint32_t Delay)
* @param size: Size of allocated memory
* @retval None
*/
void *USBD_static_malloc(uint32_t size)
{
void* USBD_static_malloc(uint32_t size) {
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */
return mem;
}
@ -857,9 +825,7 @@ void *USBD_static_malloc(uint32_t size)
* @param p: Pointer to allocated memory address
* @retval None
*/
void USBD_static_free(void *p)
{
void USBD_static_free(void* p) {
}
/* USER CODE BEGIN 5 */
@ -868,8 +834,7 @@ void USBD_static_free(void *p)
* enable HSI, PLL and select PLL as system clock source.
* @retval None
*/
static void SystemClockConfig_Resume(void)
{
static void SystemClockConfig_Resume(void) {
SystemClock_Config();
}
/* USER CODE END 5 */

View File

@ -110,7 +110,6 @@ static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len);
* @}
*/
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
* @brief Private functions declaration for FS.
* @{
@ -136,17 +135,16 @@ uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
* @{
*/
USBD_DescriptorsTypeDef FS_Desc =
{
USBD_FS_DeviceDescriptor
, USBD_FS_LangIDStrDescriptor
, USBD_FS_ManufacturerStrDescriptor
, USBD_FS_ProductStrDescriptor
, USBD_FS_SerialStrDescriptor
, USBD_FS_ConfigStrDescriptor
, USBD_FS_InterfaceStrDescriptor
USBD_DescriptorsTypeDef FS_Desc = {USBD_FS_DeviceDescriptor,
USBD_FS_LangIDStrDescriptor,
USBD_FS_ManufacturerStrDescriptor,
USBD_FS_ProductStrDescriptor,
USBD_FS_SerialStrDescriptor,
USBD_FS_ConfigStrDescriptor,
USBD_FS_InterfaceStrDescriptor
#if(USBD_LPM_ENABLED == 1)
, USBD_FS_USR_BOSDescriptor
,
USBD_FS_USR_BOSDescriptor
#endif /* (USBD_LPM_ENABLED == 1) */
};
@ -154,12 +152,12 @@ USBD_DescriptorsTypeDef FS_Desc =
#pragma data_alignment = 4
#endif /* defined ( __ICCARM__ ) */
/** USB standard device descriptor. */
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
{
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
0x12, /*bLength */
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
#if(USBD_LPM_ENABLED == 1)
0x01, /*bcdUSB */ /* changed to USB version 2.01
0x01,
/*bcdUSB */ /* changed to USB version 2.01
in order to support LPM L1 suspend
resume test of USBCV3.0*/
#else
@ -188,8 +186,7 @@ __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
#if defined(__ICCARM__) /* IAR Compiler */
#pragma data_alignment = 4
#endif /* defined ( __ICCARM__ ) */
__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
{
__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = {
0x5,
USB_DESC_TYPE_BOS,
0xC,
@ -202,8 +199,7 @@ __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
0x2, /* LPM capability bit set*/
0x0,
0x0,
0x0
};
0x0};
#endif /* (USBD_LPM_ENABLED == 1) */
/**
@ -220,13 +216,11 @@ __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
#endif /* defined ( __ICCARM__ ) */
/** USB lang indentifier descriptor. */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
{
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
USB_LEN_LANGID_STR_DESC,
USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING)
};
HIBYTE(USBD_LANGID_STRING)};
#if defined(__ICCARM__) /* IAR Compiler */
#pragma data_alignment = 4
@ -257,8 +251,7 @@ __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = {
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
*length = sizeof(USBD_FS_DeviceDesc);
return USBD_FS_DeviceDesc;
@ -270,8 +263,7 @@ uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
*length = sizeof(USBD_LangIDDesc);
return USBD_LangIDDesc;
@ -283,14 +275,10 @@ uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == 0)
{
uint8_t* USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
if(speed == 0) {
USBD_GetString((uint8_t*)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
}
else
{
} else {
USBD_GetString((uint8_t*)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
}
return USBD_StrDesc;
@ -302,8 +290,7 @@ uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
USBD_GetString((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
@ -315,8 +302,7 @@ uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *l
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
*length = USB_SIZ_STRING_SERIAL;
@ -335,14 +321,10 @@ uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == USBD_SPEED_HIGH)
{
uint8_t* USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
if(speed == USBD_SPEED_HIGH) {
USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
}
else
{
} else {
USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
}
return USBD_StrDesc;
@ -354,14 +336,10 @@ uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == 0)
{
uint8_t* USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
if(speed == 0) {
USBD_GetString((uint8_t*)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
}
else
{
} else {
USBD_GetString((uint8_t*)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
}
return USBD_StrDesc;
@ -374,8 +352,7 @@ uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
*length = sizeof(USBD_FS_BOSDesc);
return (uint8_t*)USBD_FS_BOSDesc;
@ -387,8 +364,7 @@ uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param None
* @retval None
*/
static void Get_SerialNum(void)
{
static void Get_SerialNum(void) {
uint32_t deviceserial0, deviceserial1, deviceserial2;
deviceserial0 = *(uint32_t*)DEVICE_ID1;
@ -397,8 +373,7 @@ static void Get_SerialNum(void)
deviceserial0 += deviceserial2;
if (deviceserial0 != 0)
{
if(deviceserial0 != 0) {
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8);
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4);
}
@ -411,18 +386,13 @@ static void Get_SerialNum(void)
* @param len: buffer length
* @retval None
*/
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len)
{
static void IntToUnicode(uint32_t value, uint8_t* pbuf, uint8_t len) {
uint8_t idx = 0;
for (idx = 0; idx < len; idx++)
{
if (((value >> 28)) < 0xA)
{
for(idx = 0; idx < len; idx++) {
if(((value >> 28)) < 0xA) {
pbuf[2 * idx] = (value >> 28) + '0';
}
else
{
} else {
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
}

View File

@ -111,15 +111,22 @@ PRIORITY THAN THIS! (higher priorities are lower numeric values. */
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
#define configKERNEL_INTERRUPT_PRIORITY \
(configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
#define configMAX_SYSCALL_INTERRUPT_PRIORITY \
(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
#define configASSERT(x) \
if((x) == 0) { \
taskDISABLE_INTERRUPTS(); \
for(;;) \
; \
}
/* USER CODE END 1 */
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS

View File

@ -9,11 +9,7 @@ GPIO and HAL implementations
#include <stdbool.h>
#include "main.h"
typedef enum {
GpioModeInput,
GpioModeOutput,
GpioModeOpenDrain
} GpioMode;
typedef enum { GpioModeInput, GpioModeOutput, GpioModeOpenDrain } GpioMode;
typedef struct {
GPIO_TypeDef* port;
@ -50,7 +46,8 @@ inline void app_tim_ic_init(bool both) {
HAL_TIM_OC_Stop(&htim8, TIM_CHANNEL_2);
TIM_IC_InitTypeDef sConfigIC = {0};
sConfigIC.ICPolarity = both ? TIM_INPUTCHANNELPOLARITY_BOTHEDGE : TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICPolarity = both ? TIM_INPUTCHANNELPOLARITY_BOTHEDGE :
TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;

View File

@ -38,10 +38,7 @@ extern "C" {
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
typedef enum {
TimerEventInputCapture,
TimerEventEndOfPulse
} TimerEvent;
typedef enum { TimerEventInputCapture, TimerEventEndOfPulse } TimerEvent;
/* USER CODE END ET */
@ -139,12 +136,24 @@ void register_tim8_callback_ch2(void(*callback)(uint16_t ccr, TimerEvent tim_eve
#define EM_PIN_GPIO_Port RFID_OUT_GPIO_Port
#define EM_PIN_Pin RFID_OUT_Pin
#define MISO_PIN GpioPin{.port = GPIOC, .pin = GPIO_PIN_11}
#define MISO_PIN \
GpioPin { \
.port = GPIOC, .pin = GPIO_PIN_11 \
}
// #define MOSI_PIN 11
#define SS_PIN GpioPin{.port = CC1101_CS_GPIO_Port, .pin = CC1101_CS_Pin}
#define SS_PIN \
GpioPin { \
.port = CC1101_CS_GPIO_Port, .pin = CC1101_CS_Pin \
}
//2 main, 5 remote, 3 M16
#define GDO2 GpioPin{.port = NULL, .pin = 0}
#define GDO0 GpioPin{.port = CC1101_G0_GPIO_Port, .pin = CC1101_G0_Pin}
#define GDO2 \
GpioPin { \
.port = NULL, .pin = 0 \
}
#define GDO0 \
GpioPin { \
.port = CC1101_G0_GPIO_Port, .pin = CC1101_G0_Pin \
}
/* USER CODE END Private defines */

View File

@ -141,7 +141,8 @@
* which is subject to manufacturing process variations.
*/
#if !defined(HSI48_VALUE)
#define HSI48_VALUE ((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
#define HSI48_VALUE \
((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
The real value my vary depending on manufacturing process variations.*/
#endif /* HSI48_VALUE */
@ -172,7 +173,8 @@
* frequency.
*/
#if !defined(EXTERNAL_SAI1_CLOCK_VALUE)
#define EXTERNAL_SAI1_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/
#define EXTERNAL_SAI1_CLOCK_VALUE \
((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/
#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
/**
@ -181,7 +183,8 @@
* frequency.
*/
#if !defined(EXTERNAL_SAI2_CLOCK_VALUE)
#define EXTERNAL_SAI2_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI2 External clock source in Hz*/
#define EXTERNAL_SAI2_CLOCK_VALUE \
((uint32_t)2097000U) /*!< Value of the SAI2 External clock source in Hz*/
#endif /* EXTERNAL_SAI2_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,

View File

@ -109,7 +109,8 @@
/* DEBUG macros */
#if(USBD_DEBUG_LEVEL > 0)
#define USBD_UsrLog(...) printf(__VA_ARGS__);\
#define USBD_UsrLog(...) \
printf(__VA_ARGS__); \
printf("\n");
#else
#define USBD_UsrLog(...)
@ -117,7 +118,8 @@
#if(USBD_DEBUG_LEVEL > 1)
#define USBD_ErrLog(...) printf("ERROR: ") ;\
#define USBD_ErrLog(...) \
printf("ERROR: "); \
printf(__VA_ARGS__); \
printf("\n");
#else
@ -125,7 +127,8 @@
#endif
#if(USBD_DEBUG_LEVEL > 2)
#define USBD_DbgLog(...) printf("DEBUG : ") ;\
#define USBD_DbgLog(...) \
printf("DEBUG : "); \
printf(__VA_ARGS__); \
printf("\n");
#else

View File

@ -38,7 +38,8 @@ void app_gpio_init(GpioPin gpio, GpioMode mode) {
void delay_us(uint32_t time) {
time *= 11.8;
while(time--) {}
while(time--) {
}
}
void pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) {

View File

@ -55,17 +55,20 @@
/* USER CODE END FunctionPrototypes */
/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
StackType_t** ppxIdleTaskStackBuffer,
uint32_t* pulIdleTaskStackSize);
/* GetTimerTaskMemory prototype (linked to static allocation support) */
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );
void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer,
StackType_t** ppxTimerTaskStackBuffer,
uint32_t* pulTimerTaskStackSize);
/* Hook prototypes */
void vApplicationIdleHook(void);
/* USER CODE BEGIN 2 */
__weak void vApplicationIdleHook( void )
{
__weak void vApplicationIdleHook(void) {
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
task. It is essential that code added to this hook function never attempts
@ -82,8 +85,9 @@ __weak void vApplicationIdleHook( void )
static StaticTask_t xIdleTaskTCBBuffer;
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
StackType_t** ppxIdleTaskStackBuffer,
uint32_t* pulIdleTaskStackSize) {
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
*ppxIdleTaskStackBuffer = &xIdleStack[0];
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
@ -95,8 +99,9 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackTy
static StaticTask_t xTimerTaskTCBBuffer;
static StackType_t xTimerStack[configTIMER_TASK_STACK_DEPTH];
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
{
void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer,
StackType_t** ppxTimerTaskStackBuffer,
uint32_t* pulTimerTaskStackSize) {
*ppxTimerTaskTCBBuffer = &xTimerTaskTCBBuffer;
*ppxTimerTaskStackBuffer = &xTimerStack[0];
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;

View File

@ -87,13 +87,11 @@ void StartDefaultTask(void const * argument);
* @brief The application entry point.
* @retval int
*/
int main(void)
{
int main(void) {
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
@ -156,8 +154,7 @@ int main(void)
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
while(1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
@ -169,8 +166,7 @@ int main(void)
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
@ -186,25 +182,23 @@ void SystemClock_Config(void)
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 |
RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
{
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) {
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USB
|RCC_PERIPHCLK_ADC;
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USB |
RCC_PERIPHCLK_ADC;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
@ -215,14 +209,12 @@ void SystemClock_Config(void)
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
Error_Handler();
}
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
if(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) {
Error_Handler();
}
}
@ -232,9 +224,7 @@ void SystemClock_Config(void)
* @param None
* @retval None
*/
static void MX_ADC1_Init(void)
{
static void MX_ADC1_Init(void) {
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
@ -262,15 +252,13 @@ static void MX_ADC1_Init(void)
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
if(HAL_ADC_Init(&hadc1) != HAL_OK) {
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
if(HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) {
Error_Handler();
}
/** Configure Regular Channel
@ -281,14 +269,12 @@ static void MX_ADC1_Init(void)
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
/**
@ -296,9 +282,7 @@ static void MX_ADC1_Init(void)
* @param None
* @retval None
*/
static void MX_COMP1_Init(void)
{
static void MX_COMP1_Init(void) {
/* USER CODE BEGIN COMP1_Init 0 */
/* USER CODE END COMP1_Init 0 */
@ -315,14 +299,12 @@ static void MX_COMP1_Init(void)
hcomp1.Init.Mode = COMP_POWERMODE_HIGHSPEED;
hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
if (HAL_COMP_Init(&hcomp1) != HAL_OK)
{
if(HAL_COMP_Init(&hcomp1) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN COMP1_Init 2 */
/* USER CODE END COMP1_Init 2 */
}
/**
@ -330,9 +312,7 @@ static void MX_COMP1_Init(void)
* @param None
* @retval None
*/
static void MX_SPI1_Init(void)
{
static void MX_SPI1_Init(void) {
/* USER CODE BEGIN SPI1_Init 0 */
/* USER CODE END SPI1_Init 0 */
@ -355,14 +335,12 @@ static void MX_SPI1_Init(void)
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
if(HAL_SPI_Init(&hspi1) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */
/* USER CODE END SPI1_Init 2 */
}
/**
@ -370,9 +348,7 @@ static void MX_SPI1_Init(void)
* @param None
* @retval None
*/
static void MX_SPI3_Init(void)
{
static void MX_SPI3_Init(void) {
/* USER CODE BEGIN SPI3_Init 0 */
/* USER CODE END SPI3_Init 0 */
@ -395,14 +371,12 @@ static void MX_SPI3_Init(void)
hspi3.Init.CRCPolynomial = 7;
hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi3) != HAL_OK)
{
if(HAL_SPI_Init(&hspi3) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN SPI3_Init 2 */
/* USER CODE END SPI3_Init 2 */
}
/**
@ -410,9 +384,7 @@ static void MX_SPI3_Init(void)
* @param None
* @retval None
*/
static void MX_TIM5_Init(void)
{
static void MX_TIM5_Init(void) {
/* USER CODE BEGIN TIM5_Init 0 */
/* USER CODE END TIM5_Init 0 */
@ -429,29 +401,25 @@ static void MX_TIM5_Init(void)
htim5.Init.Period = 291;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_PWM_Init(&htim5) != HAL_OK)
{
if(HAL_TIM_PWM_Init(&htim5) != HAL_OK) {
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
if(HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) {
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 145;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
if(HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN TIM5_Init 2 */
/* USER CODE END TIM5_Init 2 */
HAL_TIM_MspPostInit(&htim5);
}
/**
@ -459,9 +427,7 @@ static void MX_TIM5_Init(void)
* @param None
* @retval None
*/
static void MX_TIM8_Init(void)
{
static void MX_TIM8_Init(void) {
/* USER CODE BEGIN TIM8_Init 0 */
/* USER CODE END TIM8_Init 0 */
@ -480,38 +446,32 @@ static void MX_TIM8_Init(void)
htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim8.Init.RepetitionCounter = 0;
htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim8) != HAL_OK)
{
if(HAL_TIM_Base_Init(&htim8) != HAL_OK) {
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)
{
if(HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK) {
Error_Handler();
}
if (HAL_TIM_IC_Init(&htim8) != HAL_OK)
{
if(HAL_TIM_IC_Init(&htim8) != HAL_OK) {
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)
{
if(HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK) {
Error_Handler();
}
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
if (HAL_TIM_IC_ConfigChannel(&htim8, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
{
if(HAL_TIM_IC_ConfigChannel(&htim8, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN TIM8_Init 2 */
/* USER CODE END TIM8_Init 2 */
}
/**
@ -519,9 +479,7 @@ static void MX_TIM8_Init(void)
* @param None
* @retval None
*/
static void MX_TIM15_Init(void)
{
static void MX_TIM15_Init(void) {
/* USER CODE BEGIN TIM15_Init 0 */
/* USER CODE END TIM15_Init 0 */
@ -540,14 +498,12 @@ static void MX_TIM15_Init(void)
htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim15.Init.RepetitionCounter = 0;
htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_OC_Init(&htim15) != HAL_OK)
{
if(HAL_TIM_OC_Init(&htim15) != HAL_OK) {
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
{
if(HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) {
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_TIMING;
@ -557,12 +513,10 @@ static void MX_TIM15_Init(void)
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
if(HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) {
Error_Handler();
}
if (HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
if(HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) {
Error_Handler();
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
@ -572,15 +526,13 @@ static void MX_TIM15_Init(void)
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK)
{
if(HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN TIM15_Init 2 */
/* USER CODE END TIM15_Init 2 */
HAL_TIM_MspPostInit(&htim15);
}
/**
@ -588,9 +540,7 @@ static void MX_TIM15_Init(void)
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{
static void MX_USART1_UART_Init(void) {
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
@ -608,14 +558,12 @@ static void MX_USART1_UART_Init(void)
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
if(HAL_UART_Init(&huart1) != HAL_OK) {
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
/**
@ -623,8 +571,7 @@ static void MX_USART1_UART_Init(void)
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
static void MX_GPIO_Init(void) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
@ -759,7 +706,6 @@ static void MX_GPIO_Init(void)
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
}
/* USER CODE BEGIN 4 */
@ -773,16 +719,14 @@ void app();
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void const * argument)
{
void StartDefaultTask(void const* argument) {
/* init code for USB_DEVICE */
MX_USB_DEVICE_Init();
/* USER CODE BEGIN 5 */
/* Infinite loop */
app();
for(;;)
{
for(;;) {
osDelay(1);
}
/* USER CODE END 5 */
@ -792,8 +736,7 @@ void StartDefaultTask(void const * argument)
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
void Error_Handler(void) {
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
@ -808,8 +751,7 @@ void Error_Handler(void)
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(char *file, uint32_t line)
{
void assert_failed(char* file, uint32_t line) {
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

View File

@ -63,8 +63,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
void HAL_MspInit(void) {
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
@ -87,11 +86,9 @@ void HAL_MspInit(void)
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hadc->Instance==ADC1)
{
if(hadc->Instance == ADC1) {
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
@ -118,7 +115,6 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
/* USER CODE END ADC1_MspInit 1 */
}
}
/**
@ -127,10 +123,8 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance==ADC1)
{
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) {
if(hadc->Instance == ADC1) {
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
@ -149,7 +143,6 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/**
@ -158,11 +151,9 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
* @param hcomp: COMP handle pointer
* @retval None
*/
void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp)
{
void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hcomp->Instance==COMP1)
{
if(hcomp->Instance == COMP1) {
/* USER CODE BEGIN COMP1_MspInit 0 */
/* USER CODE END COMP1_MspInit 0 */
@ -180,7 +171,6 @@ void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp)
/* USER CODE END COMP1_MspInit 1 */
}
}
/**
@ -189,10 +179,8 @@ void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp)
* @param hcomp: COMP handle pointer
* @retval None
*/
void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
{
if(hcomp->Instance==COMP1)
{
void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp) {
if(hcomp->Instance == COMP1) {
/* USER CODE BEGIN COMP1_MspDeInit 0 */
/* USER CODE END COMP1_MspDeInit 0 */
@ -206,7 +194,6 @@ void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
/* USER CODE END COMP1_MspDeInit 1 */
}
}
/**
@ -215,11 +202,9 @@ void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hspi->Instance==SPI1)
{
if(hspi->Instance == SPI1) {
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
@ -241,9 +226,7 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
else if(hspi->Instance==SPI3)
{
} else if(hspi->Instance == SPI3) {
/* USER CODE BEGIN SPI3_MspInit 0 */
/* USER CODE END SPI3_MspInit 0 */
@ -267,7 +250,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
/* USER CODE END SPI3_MspInit 1 */
}
}
/**
@ -276,10 +258,8 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
{
if(hspi->Instance==SPI1)
{
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) {
if(hspi->Instance == SPI1) {
/* USER CODE BEGIN SPI1_MspDeInit 0 */
/* USER CODE END SPI1_MspDeInit 0 */
@ -295,9 +275,7 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
/* USER CODE BEGIN SPI1_MspDeInit 1 */
/* USER CODE END SPI1_MspDeInit 1 */
}
else if(hspi->Instance==SPI3)
{
} else if(hspi->Instance == SPI3) {
/* USER CODE BEGIN SPI3_MspDeInit 0 */
/* USER CODE END SPI3_MspDeInit 0 */
@ -315,7 +293,6 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
/* USER CODE END SPI3_MspDeInit 1 */
}
}
/**
@ -324,10 +301,8 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
* @param htim_pwm: TIM_PWM handle pointer
* @retval None
*/
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
{
if(htim_pwm->Instance==TIM5)
{
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm) {
if(htim_pwm->Instance == TIM5) {
/* USER CODE BEGIN TIM5_MspInit 0 */
/* USER CODE END TIM5_MspInit 0 */
@ -337,7 +312,6 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
/* USER CODE END TIM5_MspInit 1 */
}
}
/**
@ -346,11 +320,9 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
* @param htim_base: TIM_Base handle pointer
* @retval None
*/
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
{
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(htim_base->Instance==TIM8)
{
if(htim_base->Instance == TIM8) {
/* USER CODE BEGIN TIM8_MspInit 0 */
/* USER CODE END TIM8_MspInit 0 */
@ -375,7 +347,6 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
/* USER CODE END TIM8_MspInit 1 */
}
}
/**
@ -384,10 +355,8 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
* @param htim_oc: TIM_OC handle pointer
* @retval None
*/
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef* htim_oc)
{
if(htim_oc->Instance==TIM15)
{
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef* htim_oc) {
if(htim_oc->Instance == TIM15) {
/* USER CODE BEGIN TIM15_MspInit 0 */
/* USER CODE END TIM15_MspInit 0 */
@ -397,14 +366,11 @@ void HAL_TIM_OC_MspInit(TIM_HandleTypeDef* htim_oc)
/* USER CODE END TIM15_MspInit 1 */
}
}
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
{
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(htim->Instance==TIM5)
{
if(htim->Instance == TIM5) {
/* USER CODE BEGIN TIM5_MspPostInit 0 */
/* USER CODE END TIM5_MspPostInit 0 */
@ -422,9 +388,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
/* USER CODE BEGIN TIM5_MspPostInit 1 */
/* USER CODE END TIM5_MspPostInit 1 */
}
else if(htim->Instance==TIM15)
{
} else if(htim->Instance == TIM15) {
/* USER CODE BEGIN TIM15_MspPostInit 0 */
/* USER CODE END TIM15_MspPostInit 0 */
@ -445,7 +409,6 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
/* USER CODE END TIM15_MspPostInit 1 */
}
}
/**
* @brief TIM_PWM MSP De-Initialization
@ -453,10 +416,8 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
* @param htim_pwm: TIM_PWM handle pointer
* @retval None
*/
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
{
if(htim_pwm->Instance==TIM5)
{
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm) {
if(htim_pwm->Instance == TIM5) {
/* USER CODE BEGIN TIM5_MspDeInit 0 */
/* USER CODE END TIM5_MspDeInit 0 */
@ -466,7 +427,6 @@ void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
/* USER CODE END TIM5_MspDeInit 1 */
}
}
/**
@ -475,10 +435,8 @@ void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
* @param htim_base: TIM_Base handle pointer
* @retval None
*/
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
{
if(htim_base->Instance==TIM8)
{
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) {
if(htim_base->Instance == TIM8) {
/* USER CODE BEGIN TIM8_MspDeInit 0 */
/* USER CODE END TIM8_MspDeInit 0 */
@ -496,7 +454,6 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
/* USER CODE END TIM8_MspDeInit 1 */
}
}
/**
@ -505,10 +462,8 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
* @param htim_oc: TIM_OC handle pointer
* @retval None
*/
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc)
{
if(htim_oc->Instance==TIM15)
{
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc) {
if(htim_oc->Instance == TIM15) {
/* USER CODE BEGIN TIM15_MspDeInit 0 */
/* USER CODE END TIM15_MspDeInit 0 */
@ -518,7 +473,6 @@ void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc)
/* USER CODE END TIM15_MspDeInit 1 */
}
}
/**
@ -527,11 +481,9 @@ void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc)
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
void HAL_UART_MspInit(UART_HandleTypeDef* huart) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(huart->Instance==USART1)
{
if(huart->Instance == USART1) {
/* USER CODE BEGIN USART1_MspInit 0 */
/* USER CODE END USART1_MspInit 0 */
@ -554,7 +506,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
/* USER CODE END USART1_MspInit 1 */
}
}
/**
@ -563,10 +514,8 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART1)
{
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) {
if(huart->Instance == USART1) {
/* USER CODE BEGIN USART1_MspDeInit 0 */
/* USER CODE END USART1_MspDeInit 0 */
@ -583,7 +532,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
/* USER CODE END USART1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */

View File

@ -70,8 +70,7 @@ extern TIM_HandleTypeDef htim8;
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
void NMI_Handler(void) {
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
@ -83,13 +82,11 @@ void NMI_Handler(void)
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
void HardFault_Handler(void) {
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
while(1) {
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
@ -98,13 +95,11 @@ void HardFault_Handler(void)
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
void MemManage_Handler(void) {
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
while(1) {
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */
}
@ -113,13 +108,11 @@ void MemManage_Handler(void)
/**
* @brief This function handles Prefetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
void BusFault_Handler(void) {
/* USER CODE BEGIN BusFault_IRQn 0 */
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
while(1) {
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */
}
@ -128,13 +121,11 @@ void BusFault_Handler(void)
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
void UsageFault_Handler(void) {
/* USER CODE BEGIN UsageFault_IRQn 0 */
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{
while(1) {
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
@ -143,8 +134,7 @@ void UsageFault_Handler(void)
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
void DebugMon_Handler(void) {
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/* USER CODE END DebugMonitor_IRQn 0 */
@ -156,15 +146,13 @@ void DebugMon_Handler(void)
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
void SysTick_Handler(void) {
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
#if(INCLUDE_xTaskGetSchedulerState == 1)
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
{
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
#endif /* INCLUDE_xTaskGetSchedulerState */
xPortSysTickHandler();
#if(INCLUDE_xTaskGetSchedulerState == 1)
@ -185,8 +173,7 @@ void SysTick_Handler(void)
/**
* @brief This function handles EXTI line0 interrupt.
*/
void EXTI0_IRQHandler(void)
{
void EXTI0_IRQHandler(void) {
/* USER CODE BEGIN EXTI0_IRQn 0 */
/* USER CODE END EXTI0_IRQn 0 */
@ -199,8 +186,7 @@ void EXTI0_IRQHandler(void)
/**
* @brief This function handles EXTI line1 interrupt.
*/
void EXTI1_IRQHandler(void)
{
void EXTI1_IRQHandler(void) {
/* USER CODE BEGIN EXTI1_IRQn 0 */
/* USER CODE END EXTI1_IRQn 0 */
@ -213,8 +199,7 @@ void EXTI1_IRQHandler(void)
/**
* @brief This function handles EXTI line2 interrupt.
*/
void EXTI2_IRQHandler(void)
{
void EXTI2_IRQHandler(void) {
/* USER CODE BEGIN EXTI2_IRQn 0 */
/* USER CODE END EXTI2_IRQn 0 */
@ -227,8 +212,7 @@ void EXTI2_IRQHandler(void)
/**
* @brief This function handles EXTI line4 interrupt.
*/
void EXTI4_IRQHandler(void)
{
void EXTI4_IRQHandler(void) {
/* USER CODE BEGIN EXTI4_IRQn 0 */
/* USER CODE END EXTI4_IRQn 0 */
@ -241,8 +225,7 @@ void EXTI4_IRQHandler(void)
/**
* @brief This function handles EXTI line[9:5] interrupts.
*/
void EXTI9_5_IRQHandler(void)
{
void EXTI9_5_IRQHandler(void) {
/* USER CODE BEGIN EXTI9_5_IRQn 0 */
/* USER CODE END EXTI9_5_IRQn 0 */
@ -262,20 +245,16 @@ void register_tim8_callback_ch2(void(*callback)(uint16_t ccr, TimerEvent tim_eve
/**
* @brief This function handles TIM8 capture compare interrupt.
*/
void TIM8_CC_IRQHandler(void)
{
void TIM8_CC_IRQHandler(void) {
/* USER CODE BEGIN TIM8_CC_IRQn 0 */
/* Capture compare 2 event */
if (__HAL_TIM_GET_FLAG(&htim8, TIM_FLAG_CC2) != RESET)
{
if (__HAL_TIM_GET_IT_SOURCE(&htim8, TIM_IT_CC2) != RESET)
{
if(__HAL_TIM_GET_FLAG(&htim8, TIM_FLAG_CC2) != RESET) {
if(__HAL_TIM_GET_IT_SOURCE(&htim8, TIM_IT_CC2) != RESET) {
__HAL_TIM_CLEAR_IT(&htim8, TIM_IT_CC2);
htim8.Channel = HAL_TIM_ACTIVE_CHANNEL_2;
/* Input capture event */
if ((htim8.Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U)
{
if((htim8.Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U) {
/*
#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
htim->IC_CaptureCallback(htim);
@ -288,8 +267,7 @@ void TIM8_CC_IRQHandler(void)
}
}
/* Output compare event */
else
{
else {
if(tim8_callback_ch2 != NULL) {
tim8_callback_ch2(0, TimerEventEndOfPulse);
}
@ -307,7 +285,6 @@ void TIM8_CC_IRQHandler(void)
}
}
/* USER CODE END TIM8_CC_IRQn 0 */
// HAL_TIM_IRQHandler(&htim8);
/* USER CODE BEGIN TIM8_CC_IRQn 1 */
@ -318,8 +295,7 @@ void TIM8_CC_IRQHandler(void)
/**
* @brief This function handles USB OTG FS global interrupt.
*/
void OTG_FS_IRQHandler(void)
{
void OTG_FS_IRQHandler(void) {
/* USER CODE BEGIN OTG_FS_IRQn 0 */
/* USER CODE END OTG_FS_IRQn 0 */

View File

@ -123,7 +123,8 @@
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
#define VECT_TAB_OFFSET \
0x00 /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
/******************************************************************************/
/**
@ -153,8 +154,18 @@
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
const uint32_t MSIRangeTable[12] = {100000U, 200000U, 400000U, 800000U, 1000000U, 2000000U, \
4000000U, 8000000U, 16000000U, 24000000U, 32000000U, 48000000U};
const uint32_t MSIRangeTable[12] = {100000U,
200000U,
400000U,
800000U,
1000000U,
2000000U,
4000000U,
8000000U,
16000000U,
24000000U,
32000000U,
48000000U};
/**
* @}
*/
@ -177,8 +188,7 @@
* @retval None
*/
void SystemInit(void)
{
void SystemInit(void) {
/* FPU settings ------------------------------------------------------------*/
#if(__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10 * 2) | (3UL << 11 * 2)); /* set CP10 and CP11 Full Access */
@ -253,25 +263,20 @@ void SystemInit(void)
* @param None
* @retval None
*/
void SystemCoreClockUpdate(void)
{
void SystemCoreClockUpdate(void) {
uint32_t tmp = 0U, msirange = 0U, pllvco = 0U, pllr = 2U, pllsource = 0U, pllm = 2U;
/* Get MSI Range frequency--------------------------------------------------*/
if((RCC->CR & RCC_CR_MSIRGSEL) == RESET)
{ /* MSISRANGE from RCC_CSR applies */
if((RCC->CR & RCC_CR_MSIRGSEL) == RESET) { /* MSISRANGE from RCC_CSR applies */
msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U;
}
else
{ /* MSIRANGE from RCC_CR applies */
} else { /* MSIRANGE from RCC_CR applies */
msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U;
}
/*MSI frequency range in HZ*/
msirange = MSIRangeTable[msirange];
/* Get SYSCLK source -------------------------------------------------------*/
switch (RCC->CFGR & RCC_CFGR_SWS)
{
switch(RCC->CFGR & RCC_CFGR_SWS) {
case 0x00: /* MSI used as system clock source */
SystemCoreClock = msirange;
break;
@ -291,8 +296,7 @@ void SystemCoreClockUpdate(void)
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U;
switch (pllsource)
{
switch(pllsource) {
case 0x02: /* HSI used as PLL clock source */
pllvco = (HSI_VALUE / pllm);
break;
@ -321,7 +325,6 @@ void SystemCoreClockUpdate(void)
SystemCoreClock >>= tmp;
}
/**
* @}
*/

View File

@ -63,27 +63,22 @@ extern USBD_DescriptorsTypeDef FS_Desc;
* Init USB device Library, add supported class and start the library
* @retval None
*/
void MX_USB_DEVICE_Init(void)
{
void MX_USB_DEVICE_Init(void) {
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
/* USER CODE END USB_DEVICE_Init_PreTreatment */
/* Init Device Library, add supported class and start the library. */
if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
{
if(USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) {
Error_Handler();
}
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)
{
if(USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) {
Error_Handler();
}
if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK)
{
if(USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) {
Error_Handler();
}
if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
{
if(USBD_Start(&hUsbDeviceFS) != USBD_OK) {
Error_Handler();
}
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */

View File

@ -139,21 +139,17 @@ static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len);
* @}
*/
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
{
CDC_Init_FS,
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = {CDC_Init_FS,
CDC_DeInit_FS,
CDC_Control_FS,
CDC_Receive_FS
};
CDC_Receive_FS};
/* Private functions ---------------------------------------------------------*/
/**
* @brief Initializes the CDC media low layer over the FS USB IP
* @retval USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Init_FS(void)
{
static int8_t CDC_Init_FS(void) {
/* USER CODE BEGIN 3 */
/* Set Application Buffers */
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
@ -166,8 +162,7 @@ static int8_t CDC_Init_FS(void)
* @brief DeInitializes the CDC media low layer
* @retval USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_DeInit_FS(void)
{
static int8_t CDC_DeInit_FS(void) {
/* USER CODE BEGIN 4 */
return (USBD_OK);
/* USER CODE END 4 */
@ -180,11 +175,9 @@ static int8_t CDC_DeInit_FS(void)
* @param length: Number of data to be sent (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) {
/* USER CODE BEGIN 5 */
switch(cmd)
{
switch(cmd) {
case CDC_SEND_ENCAPSULATED_COMMAND:
break;
@ -260,8 +253,7 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
* @param Len: Number of data received (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t* Len) {
/* USER CODE BEGIN 6 */
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
@ -280,8 +272,7 @@ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
* @param Len: Number of data to be sent (in bytes)
* @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
*/
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) {
uint8_t result = USBD_OK;
/* USER CODE BEGIN 7 */
USBD_CDC_HandleTypeDef* hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;

View File

@ -67,11 +67,9 @@ extern void SystemClock_Config(void);
*******************************************************************************/
/* MSP Init */
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
{
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(pcdHandle->Instance==USB_OTG_FS)
{
if(pcdHandle->Instance == USB_OTG_FS) {
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
/* USER CODE END USB_OTG_FS_MspInit 0 */
@ -92,14 +90,11 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
/* Enable VDDUSB */
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
{
if(__HAL_RCC_PWR_IS_CLK_DISABLED()) {
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_EnableVddUSB();
__HAL_RCC_PWR_CLK_DISABLE();
}
else
{
} else {
HAL_PWREx_EnableVddUSB();
}
@ -112,10 +107,8 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
}
}
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
{
if(pcdHandle->Instance==USB_OTG_FS)
{
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) {
if(pcdHandle->Instance == USB_OTG_FS) {
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
@ -129,14 +122,11 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11 | GPIO_PIN_12);
/* Disable VDDUSB */
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
{
if(__HAL_RCC_PWR_IS_CLK_DISABLED()) {
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_DisableVddUSB();
__HAL_RCC_PWR_CLK_DISABLE();
}
else
{
} else {
HAL_PWREx_DisableVddUSB();
}
@ -220,8 +210,7 @@ void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
{
USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
if ( hpcd->Init.speed != PCD_SPEED_FULL)
{
if(hpcd->Init.speed != PCD_SPEED_FULL) {
Error_Handler();
}
/* Set Speed. */
@ -248,8 +237,7 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData);
/* Enter in STOP mode. */
/* USER CODE BEGIN 2 */
if (hpcd->Init.low_power_enable)
{
if(hpcd->Init.low_power_enable) {
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
}
@ -271,8 +259,7 @@ void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
__HAL_PCD_UNGATE_PHYCLOCK(hpcd);
/* USER CODE BEGIN 3 */
if (hpcd->Init.low_power_enable)
{
if(hpcd->Init.low_power_enable) {
/* Reset SLEEPDEEP bit of Cortex System Control Register. */
SCB->SCR &= (uint32_t) ~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
SystemClockConfig_Resume();
@ -352,8 +339,7 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
* @param pdev: Device handle
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef* pdev) {
/* Init USB Ip. */
if(pdev->id == DEVICE_FS) {
/* Enable USB power on Pwrctrl CR2 register. */
@ -371,20 +357,21 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
{
if(HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK) {
Error_Handler();
}
#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
/* Register USB PCD CallBacks */
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback);
HAL_PCD_RegisterCallback(
&hpcd_USB_OTG_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback);
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback);
HAL_PCD_RegisterCallback(
&hpcd_USB_OTG_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback);
HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback);
HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback);
@ -403,8 +390,7 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
* @param pdev: Device handle
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef* pdev) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -435,8 +421,7 @@ USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
* @param pdev: Device handle
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef* pdev) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -467,8 +452,7 @@ USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
* @param pdev: Device handle
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef* pdev) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -502,8 +486,8 @@ USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
* @param ep_mps: Endpoint max packet size
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
{
USBD_StatusTypeDef
USBD_LL_OpenEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -535,8 +519,7 @@ USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uin
* @param ep_addr: Endpoint number
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -568,8 +551,7 @@ USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param ep_addr: Endpoint number
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -601,8 +583,7 @@ USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param ep_addr: Endpoint number
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -634,8 +615,7 @@ USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param ep_addr: Endpoint number
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -667,16 +647,12 @@ USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_add
* @param ep_addr: Endpoint number
* @retval Stall (1: Yes, 0: No)
*/
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
PCD_HandleTypeDef* hpcd = (PCD_HandleTypeDef*)pdev->pData;
if((ep_addr & 0x80) == 0x80)
{
if((ep_addr & 0x80) == 0x80) {
return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
}
else
{
} else {
return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
}
}
@ -687,8 +663,7 @@ uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param dev_addr: Device address
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
{
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef* pdev, uint8_t dev_addr) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -722,8 +697,8 @@ USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_a
* @param size: Data size
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
{
USBD_StatusTypeDef
USBD_LL_Transmit(USBD_HandleTypeDef* pdev, uint8_t ep_addr, uint8_t* pbuf, uint16_t size) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -757,8 +732,8 @@ USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, u
* @param size: Data size
* @retval USBD status
*/
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
{
USBD_StatusTypeDef
USBD_LL_PrepareReceive(USBD_HandleTypeDef* pdev, uint8_t ep_addr, uint8_t* pbuf, uint16_t size) {
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
@ -790,8 +765,7 @@ USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_a
* @param ep_addr: Endpoint number
* @retval Recived Data Size
*/
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef* pdev, uint8_t ep_addr) {
return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*)pdev->pData, ep_addr);
}
@ -801,13 +775,10 @@ uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
* @param msg: LPM message
* @retval None
*/
void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
{
switch (msg)
{
void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef* hpcd, PCD_LPM_MsgTypeDef msg) {
switch(msg) {
case PCD_LPM_L0_ACTIVE:
if (hpcd->Init.low_power_enable)
{
if(hpcd->Init.low_power_enable) {
SystemClockConfig_Resume();
/* Reset SLEEPDEEP bit of Cortex System Control Register. */
@ -822,8 +793,7 @@ void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
USBD_LL_Suspend(hpcd->pData);
/* Enter in STOP mode. */
if (hpcd->Init.low_power_enable)
{
if(hpcd->Init.low_power_enable) {
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
}
@ -836,8 +806,7 @@ void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
* @param Delay: Delay in ms
* @retval None
*/
void USBD_LL_Delay(uint32_t Delay)
{
void USBD_LL_Delay(uint32_t Delay) {
HAL_Delay(Delay);
}
@ -846,8 +815,7 @@ void USBD_LL_Delay(uint32_t Delay)
* @param size: Size of allocated memory
* @retval None
*/
void *USBD_static_malloc(uint32_t size)
{
void* USBD_static_malloc(uint32_t size) {
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */
return mem;
}
@ -857,9 +825,7 @@ void *USBD_static_malloc(uint32_t size)
* @param p: Pointer to allocated memory address
* @retval None
*/
void USBD_static_free(void *p)
{
void USBD_static_free(void* p) {
}
/* USER CODE BEGIN 5 */
@ -868,8 +834,7 @@ void USBD_static_free(void *p)
* enable HSI, PLL and select PLL as system clock source.
* @retval None
*/
static void SystemClockConfig_Resume(void)
{
static void SystemClockConfig_Resume(void) {
SystemClock_Config();
}
/* USER CODE END 5 */

View File

@ -110,7 +110,6 @@ static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len);
* @}
*/
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
* @brief Private functions declaration for FS.
* @{
@ -136,17 +135,16 @@ uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
* @{
*/
USBD_DescriptorsTypeDef FS_Desc =
{
USBD_FS_DeviceDescriptor
, USBD_FS_LangIDStrDescriptor
, USBD_FS_ManufacturerStrDescriptor
, USBD_FS_ProductStrDescriptor
, USBD_FS_SerialStrDescriptor
, USBD_FS_ConfigStrDescriptor
, USBD_FS_InterfaceStrDescriptor
USBD_DescriptorsTypeDef FS_Desc = {USBD_FS_DeviceDescriptor,
USBD_FS_LangIDStrDescriptor,
USBD_FS_ManufacturerStrDescriptor,
USBD_FS_ProductStrDescriptor,
USBD_FS_SerialStrDescriptor,
USBD_FS_ConfigStrDescriptor,
USBD_FS_InterfaceStrDescriptor
#if(USBD_LPM_ENABLED == 1)
, USBD_FS_USR_BOSDescriptor
,
USBD_FS_USR_BOSDescriptor
#endif /* (USBD_LPM_ENABLED == 1) */
};
@ -154,12 +152,12 @@ USBD_DescriptorsTypeDef FS_Desc =
#pragma data_alignment = 4
#endif /* defined ( __ICCARM__ ) */
/** USB standard device descriptor. */
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
{
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
0x12, /*bLength */
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
#if(USBD_LPM_ENABLED == 1)
0x01, /*bcdUSB */ /* changed to USB version 2.01
0x01,
/*bcdUSB */ /* changed to USB version 2.01
in order to support LPM L1 suspend
resume test of USBCV3.0*/
#else
@ -188,8 +186,7 @@ __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
#if defined(__ICCARM__) /* IAR Compiler */
#pragma data_alignment = 4
#endif /* defined ( __ICCARM__ ) */
__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
{
__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = {
0x5,
USB_DESC_TYPE_BOS,
0xC,
@ -202,8 +199,7 @@ __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
0x2, /* LPM capability bit set*/
0x0,
0x0,
0x0
};
0x0};
#endif /* (USBD_LPM_ENABLED == 1) */
/**
@ -220,13 +216,11 @@ __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
#endif /* defined ( __ICCARM__ ) */
/** USB lang indentifier descriptor. */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
{
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
USB_LEN_LANGID_STR_DESC,
USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING)
};
HIBYTE(USBD_LANGID_STRING)};
#if defined(__ICCARM__) /* IAR Compiler */
#pragma data_alignment = 4
@ -257,8 +251,7 @@ __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = {
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
*length = sizeof(USBD_FS_DeviceDesc);
return USBD_FS_DeviceDesc;
@ -270,8 +263,7 @@ uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
*length = sizeof(USBD_LangIDDesc);
return USBD_LangIDDesc;
@ -283,14 +275,10 @@ uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == 0)
{
uint8_t* USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
if(speed == 0) {
USBD_GetString((uint8_t*)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
}
else
{
} else {
USBD_GetString((uint8_t*)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
}
return USBD_StrDesc;
@ -302,8 +290,7 @@ uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
USBD_GetString((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
@ -315,8 +302,7 @@ uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *l
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
*length = USB_SIZ_STRING_SERIAL;
@ -335,14 +321,10 @@ uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == USBD_SPEED_HIGH)
{
uint8_t* USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
if(speed == USBD_SPEED_HIGH) {
USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
}
else
{
} else {
USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
}
return USBD_StrDesc;
@ -354,14 +336,10 @@ uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == 0)
{
uint8_t* USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
if(speed == 0) {
USBD_GetString((uint8_t*)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
}
else
{
} else {
USBD_GetString((uint8_t*)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
}
return USBD_StrDesc;
@ -374,8 +352,7 @@ uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
uint8_t* USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) {
UNUSED(speed);
*length = sizeof(USBD_FS_BOSDesc);
return (uint8_t*)USBD_FS_BOSDesc;
@ -387,8 +364,7 @@ uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* @param None
* @retval None
*/
static void Get_SerialNum(void)
{
static void Get_SerialNum(void) {
uint32_t deviceserial0, deviceserial1, deviceserial2;
deviceserial0 = *(uint32_t*)DEVICE_ID1;
@ -397,8 +373,7 @@ static void Get_SerialNum(void)
deviceserial0 += deviceserial2;
if (deviceserial0 != 0)
{
if(deviceserial0 != 0) {
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8);
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4);
}
@ -411,18 +386,13 @@ static void Get_SerialNum(void)
* @param len: buffer length
* @retval None
*/
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len)
{
static void IntToUnicode(uint32_t value, uint8_t* pbuf, uint8_t len) {
uint8_t idx = 0;
for (idx = 0; idx < len; idx++)
{
if (((value >> 28)) < 0xA)
{
for(idx = 0; idx < len; idx++) {
if(((value >> 28)) < 0xA) {
pbuf[2 * idx] = (value >> 28) + '0';
}
else
{
} else {
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
}

View File

@ -12,7 +12,6 @@ typedef uint32_t StackType_t;
typedef uint32_t StaticTask_t;
typedef pthread_t* TaskHandle_t;
typedef enum {
SemaphoreTypeMutex,
SemaphoreTypeCounting,
@ -30,48 +29,37 @@ typedef StaticQueue_t* QueueHandle_t;
#define portMAX_DELAY -1
typedef enum {
pdTRUE = 1,
pdFALSE = 0
} BaseType_t;
typedef enum { pdTRUE = 1, pdFALSE = 0 } BaseType_t;
typedef int32_t TickType_t;
#define tskIDLE_PRIORITY 0
TaskHandle_t xTaskCreateStatic(
TaskFunction_t pxTaskCode,
TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,
const char* const pcName,
const uint32_t ulStackDepth,
void* const pvParameters,
UBaseType_t uxPriority,
StackType_t* const puxStackBuffer,
StaticTask_t * const pxTaskBuffer
);
StaticTask_t* const pxTaskBuffer);
void vTaskDelete(TaskHandle_t xTask);
TaskHandle_t xTaskGetCurrentTaskHandle(void);
SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer);
bool task_equal(TaskHandle_t a, TaskHandle_t b);
QueueHandle_t xQueueCreateStatic(
UBaseType_t uxQueueLength,
QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
UBaseType_t uxItemSize,
uint8_t* pucQueueStorageBuffer,
StaticQueue_t* pxQueueBuffer
);
StaticQueue_t* pxQueueBuffer);
SemaphoreHandle_t xSemaphoreCreateCountingStatic(
UBaseType_t uxMaxCount,
SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount,
UBaseType_t uxInitialCount,
StaticSemaphore_t *pxSemaphoreBuffer
);
StaticSemaphore_t* pxSemaphoreBuffer);
BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait);
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore);
BaseType_t xQueueSend(
QueueHandle_t xQueue, const void * pvItemToQueue, TickType_t xTicksToWait
);
BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait);
BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait);

View File

@ -10,11 +10,7 @@ GPIO and HAL implementations
#include <stdbool.h>
#include "main.h"
typedef enum {
GpioModeInput,
GpioModeOutput,
GpioModeOpenDrain
} GpioMode;
typedef enum { GpioModeInput, GpioModeOutput, GpioModeOpenDrain } GpioMode;
typedef struct {
const char* port;
@ -42,10 +38,7 @@ inline bool app_gpio_read(GpioPin gpio) {
return false;
}
typedef enum {
GPIO_PIN_SET = 1,
GPIO_PIN_RESET = 0
} HAL_GPIO_PIN_STATE;
typedef enum { GPIO_PIN_SET = 1, GPIO_PIN_RESET = 0 } HAL_GPIO_PIN_STATE;
void HAL_GPIO_WritePin(const char* port, uint32_t pin, HAL_GPIO_PIN_STATE state);
@ -106,4 +99,5 @@ typedef const char* SPI_HandleTypeDef;
typedef uint32_t HAL_StatusTypeDef;
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef
HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t* pData, uint16_t Size, uint32_t Timeout);

View File

@ -5,12 +5,8 @@
#define HAL_MAX_DELAY INT_MAX
typedef uint32_t UART_HandleTypeDef;
uint16_t HAL_UART_Transmit(
UART_HandleTypeDef* handle,
uint8_t* bufer,
uint16_t size,
uint32_t wait_ms
);
uint16_t
HAL_UART_Transmit(UART_HandleTypeDef* handle, uint8_t* bufer, uint16_t size, uint32_t wait_ms);
typedef uint32_t TIM_HandleTypeDef;

View File

@ -10,7 +10,6 @@ GPIO and HAL implementations
void app_gpio_init(GpioPin gpio, GpioMode mode) {
if(gpio.pin != 0) {
switch(mode) {
case GpioModeInput:
printf("[GPIO] %s%d input\n", gpio.port, gpio.pin);
@ -44,7 +43,8 @@ void HAL_GPIO_WritePin(const char* port, uint32_t pin, HAL_GPIO_PIN_STATE state)
printf("[GPIO] set pin %s:%d = %d\n", port, pin, state);
}
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t *pData, uint16_t size, uint32_t Timeout) {
HAL_StatusTypeDef
HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t* pData, uint16_t size, uint32_t Timeout) {
printf("[SPI] write %d to %s: ", size, *hspi);
for(size_t i = 0; i < size; i++) {
printf("%02X ", pData[i]);

View File

@ -10,12 +10,8 @@ Dummy hal for local fw build
UART_HandleTypeDef DEBUG_UART = 0;
uint16_t HAL_UART_Transmit(
UART_HandleTypeDef* handle,
uint8_t* bufer,
uint16_t size,
uint32_t wait_ms
) {
uint16_t
HAL_UART_Transmit(UART_HandleTypeDef* handle, uint8_t* bufer, uint16_t size, uint32_t wait_ms) {
uint16_t res = write(1, (const char*)bufer, size);
return res;
}

View File

@ -30,15 +30,13 @@ void* pthread_wrapper(void* p) {
return NULL;
}
TaskHandle_t xTaskCreateStatic(
TaskFunction_t pxTaskCode,
TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,
const char* const pcName,
const uint32_t ulStackDepth,
void* const pvParameters,
UBaseType_t uxPriority,
StackType_t* const puxStackBuffer,
StaticTask_t * const pxTaskBuffer
) {
StaticTask_t* const pxTaskBuffer) {
TaskHandle_t thread = malloc(sizeof(TaskHandle_t));
PthreadTask* task = malloc(sizeof(PthreadTask));
@ -51,7 +49,6 @@ TaskHandle_t xTaskCreateStatic(
}
void vTaskDelete(TaskHandle_t xTask) {
if(xTask == NULL) {
// kill itself
pthread_exit(NULL);
@ -82,16 +79,12 @@ bool task_equal(TaskHandle_t a, TaskHandle_t b) {
return pthread_equal(*a, *b) != 0;
}
BaseType_t xQueueSend(
QueueHandle_t xQueue, const void * pvItemToQueue, TickType_t xTicksToWait
) {
BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait) {
// TODO: add implementation
return pdTRUE;
}
BaseType_t xQueueReceive(
QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait
) {
BaseType_t xQueueReceive(QueueHandle_t xQueue, void* pvBuffer, TickType_t xTicksToWait) {
// TODO: add implementation
osDelay(100);
@ -100,12 +93,10 @@ BaseType_t xQueueReceive(
static uint32_t queue_global_id = 0;
QueueHandle_t xQueueCreateStatic(
UBaseType_t uxQueueLength,
QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
UBaseType_t uxItemSize,
uint8_t* pucQueueStorageBuffer,
StaticQueue_t *pxQueueBuffer
) {
StaticQueue_t* pxQueueBuffer) {
// TODO: check this implementation
int* msgid = malloc(sizeof(int));
@ -117,11 +108,9 @@ QueueHandle_t xQueueCreateStatic(
return (QueueHandle_t)msgid;
}
SemaphoreHandle_t xSemaphoreCreateCountingStatic(
UBaseType_t uxMaxCount,
SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount,
UBaseType_t uxInitialCount,
StaticSemaphore_t* pxSemaphoreBuffer
) {
StaticSemaphore_t* pxSemaphoreBuffer) {
pxSemaphoreBuffer->type = SemaphoreTypeCounting;
pxSemaphoreBuffer->take_counter = 0;
pxSemaphoreBuffer->give_counter = 0;
@ -136,7 +125,6 @@ SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer)
return pxMutexBuffer;
}
BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait) {
if(xSemaphore == NULL) return pdFALSE;
@ -167,10 +155,8 @@ BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTic
TickType_t ticks = xTicksToWait;
while(
xSemaphore->take_counter != xSemaphore->give_counter
&& (ticks > 0 || xTicksToWait == portMAX_DELAY)
) {
while(xSemaphore->take_counter != xSemaphore->give_counter &&
(ticks > 0 || xTicksToWait == portMAX_DELAY)) {
osDelay(1);
ticks--;
}
@ -207,9 +193,7 @@ static void create_tls_keys() {
}
}
void* pvTaskGetThreadLocalStoragePointer(
TaskHandle_t xTaskToQuery, BaseType_t xIndex
) {
void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex) {
// Non-current task TLS access is not allowed
if(xTaskToQuery != NULL) {
return NULL;
@ -224,9 +208,7 @@ void* pvTaskGetThreadLocalStoragePointer(
return pthread_getspecific(tls_keys[xIndex]);
}
void vTaskSetThreadLocalStoragePointer(
TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue
) {
void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void* pvValue) {
// Non-current task TLS access is not allowed
if(xTaskToSet != NULL) {
return;

View File

@ -88,6 +88,12 @@ If you want to add some features or suggest some changes, do following steps:
* Your code is merged in master branch
5. If you can do only part of work, create PR with `WIP` label. Describe what you have already done and what remains to be done and other people can help you.
## Coding Style
Flipper Zero source code is formatted using clang-format for C code and rustfmt for rust. We use the [Kernel Code Style](https://www.kernel.org/doc/html/latest/process/coding-style.html) with minor changes, you can see the rules in .clang-format file. The Github CI tests will automatically check the code format and fail if the format is incorrect.
Also, you can check and fix format with syntax_check.sh script.
## Pull requests
1. Don't forget reference issues or other PR