From 110a9efc3c9b18160b162f194d834083f66a478e Mon Sep 17 00:00:00 2001 From: Nikita Beletskii Date: Wed, 30 Sep 2020 02:18:30 +0300 Subject: [PATCH] [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 Co-authored-by: Vadim Kaushan --- .clang-format | 86 ++ .github/workflows/ci.yml | 6 + .gitignore | 1 - .../coreglitch_demo_0/coreglitch_demo_0.c | 12 +- applications/display-u8g2/display-u8g2.c | 142 +-- applications/examples/blink.c | 2 +- applications/examples/ipc.c | 26 +- applications/examples/u8g2_example.c | 6 +- applications/startup.h | 26 +- applications/tests/furi_record_test.c | 55 +- applications/tests/furiac_test.c | 4 +- applications/tests/test_index.c | 3 +- core-rs/flipper-core/build.rs | 6 +- core-rs/flipper-core/src/lib.rs | 8 +- core-rs/flipper-f1-sys/build.rs | 9 +- core-rs/flipper-f1-sys/src/lib.rs | 3 +- core/app.cpp | 14 +- core/flipper.h | 10 +- core/furi.c | 126 +- core/furi.h | 21 +- core/furi_ac.c | 63 +- core/log.c | 2 +- core/log.h | 2 +- core/tty_uart.c | 40 +- docker-compose.yml | 1 + docker/Dockerfile | 17 +- docker/syntax_check.sh | 43 + syntax_check.sh | 4 + target_f1/Inc/FreeRTOSConfig.h | 69 +- target_f1/Inc/flipper_hal.h | 9 +- target_f1/Inc/main.h | 29 +- target_f1/Inc/stm32l4xx_hal_conf.h | 179 +-- target_f1/Inc/stm32l4xx_it.h | 4 +- target_f1/Inc/usb_device.h | 2 +- target_f1/Inc/usbd_cdc_if.h | 6 +- target_f1/Inc/usbd_conf.h | 55 +- target_f1/Inc/usbd_desc.h | 14 +- target_f1/Src/flipper_hal.c | 25 +- target_f1/Src/freertos.c | 53 +- target_f1/Src/main.c | 1063 ++++++++--------- target_f1/Src/stm32l4xx_hal_msp.c | 644 +++++----- target_f1/Src/stm32l4xx_it.c | 262 ++-- target_f1/Src/system_stm32l4xx.c | 183 +-- target_f1/Src/usb_device.c | 47 +- target_f1/Src/usbd_cdc_if.c | 147 ++- target_f1/Src/usbd_conf.c | 967 ++++++++------- target_f1/Src/usbd_desc.c | 340 +++--- target_f2/Inc/FreeRTOSConfig.h | 69 +- target_f2/Inc/flipper_hal.h | 9 +- target_f2/Inc/main.h | 29 +- target_f2/Inc/stm32l4xx_hal_conf.h | 179 +-- target_f2/Inc/stm32l4xx_it.h | 4 +- target_f2/Inc/usb_device.h | 2 +- target_f2/Inc/usbd_cdc_if.h | 6 +- target_f2/Inc/usbd_conf.h | 55 +- target_f2/Inc/usbd_desc.h | 14 +- target_f2/Src/flipper_hal.c | 25 +- target_f2/Src/freertos.c | 53 +- target_f2/Src/main.c | 1022 ++++++++-------- target_f2/Src/stm32l4xx_hal_msp.c | 580 ++++----- target_f2/Src/stm32l4xx_it.c | 262 ++-- target_f2/Src/system_stm32l4xx.c | 183 +-- target_f2/Src/usb_device.c | 47 +- target_f2/Src/usbd_cdc_if.c | 147 ++- target_f2/Src/usbd_conf.c | 967 ++++++++------- target_f2/Src/usbd_desc.c | 340 +++--- target_lo/Inc/cmsis_os.h | 46 +- target_lo/Inc/flipper_hal.h | 14 +- target_lo/Inc/main.h | 8 +- target_lo/Src/flipper_hal.c | 18 +- target_lo/Src/lo_hal.c | 8 +- target_lo/Src/lo_os.c | 92 +- wiki/Contributing.md | 6 + 73 files changed, 4354 insertions(+), 4667 deletions(-) create mode 100644 .clang-format create mode 100755 docker/syntax_check.sh create mode 100755 syntax_check.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..aec6434e --- /dev/null +++ b/.clang-format @@ -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 \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3616d6bd..1bd8f4a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/.gitignore b/.gitignore index afb4d4df..7fd3badb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .idea/ -target_lo/build/ target_*/build/ bindings/ diff --git a/applications/coreglitch_demo_0/coreglitch_demo_0.c b/applications/coreglitch_demo_0/coreglitch_demo_0.c index ee682378..2b939b08 100644 --- a/applications/coreglitch_demo_0/coreglitch_demo_0.c +++ b/applications/coreglitch_demo_0/coreglitch_demo_0.c @@ -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,18 +31,17 @@ 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]; + float scale = scales[((cnt + note_idx) / 16) % 4]; float freq = notes[(note_idx + cnt / 2) % 8] * scale; - float width = 0.001 + 0.05 * (note_idx % (cnt/7 + 5)); + float width = 0.001 + 0.05 * (note_idx % (cnt / 7 + 5)); if(note_idx % 8 == 0) { freq = 0; @@ -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); diff --git a/applications/display-u8g2/display-u8g2.c b/applications/display-u8g2/display-u8g2.c index 02c8d447..b8293b8f 100644 --- a/applications/display-u8g2/display-u8g2.c +++ b/applications/display-u8g2/display-u8g2.c @@ -7,104 +7,107 @@ 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: - /* HAL initialization contains all what we need so we can skip this part. */ + //Initialize SPI peripheral + case U8X8_MSG_GPIO_AND_DELAY_INIT: + /* HAL initialization contains all what we need so we can skip this part. */ break; - //Function which implements a delay, arg_int contains the amount of ms - case U8X8_MSG_DELAY_MILLI: - osDelay(arg_int); + //Function which implements a delay, arg_int contains the amount of ms + case U8X8_MSG_DELAY_MILLI: + osDelay(arg_int); break; - //Function which delays 10us - case U8X8_MSG_DELAY_10MICRO: - delay_us(10); + //Function which delays 10us + case U8X8_MSG_DELAY_10MICRO: + delay_us(10); break; - //Function which delays 100ns - case U8X8_MSG_DELAY_100NANO: - asm("nop"); + //Function which delays 100ns + case U8X8_MSG_DELAY_100NANO: + asm("nop"); break; - // Function to define the logic level of the RESET line - case U8X8_MSG_GPIO_RESET: - #ifdef DEBUG - fuprintf(log, "[u8g2] rst %d\n", arg_int); - #endif + // Function to define the logic level of the RESET line + case U8X8_MSG_GPIO_RESET: +#ifdef DEBUG + fuprintf(log, "[u8g2] rst %d\n", arg_int); +#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); + // TODO change it to FuriRecord pin + HAL_GPIO_WritePin( + DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET); break; - default: - #ifdef DEBUG - fufuprintf(log, "[u8g2] unknown io %d\n", msg); - #endif + default: +#ifdef DEBUG + fufuprintf(log, "[u8g2] unknown io %d\n", msg); +#endif - return 0; //A message was received which is not implemented, return 0 to indicate an error + return 0; //A message was received which is not implemented, return 0 to indicate an error } return 1; // command processed successfully. } -static uint8_t u8x8_hw_spi_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr){ - switch (msg) { - case U8X8_MSG_BYTE_SEND: - #ifdef DEBUG - fuprintf(log, "[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]); - #endif +static uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { + switch(msg) { + case U8X8_MSG_BYTE_SEND: +#ifdef DEBUG + fuprintf(log, "[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]); +#endif - // TODO change it to FuriRecord SPI - HAL_SPI_Transmit(&hspi1, (uint8_t *)arg_ptr, arg_int, 10000); + // TODO change it to FuriRecord SPI + HAL_SPI_Transmit(&hspi1, (uint8_t*)arg_ptr, arg_int, 10000); break; - case U8X8_MSG_BYTE_SET_DC: - #ifdef DEBUG - fuprintf(log, "[u8g2] dc %d\n", arg_int); - #endif + case U8X8_MSG_BYTE_SET_DC: +#ifdef DEBUG + fuprintf(log, "[u8g2] dc %d\n", arg_int); +#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); + // TODO change it to FuriRecord pin + HAL_GPIO_WritePin( + DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET); break; - case U8X8_MSG_BYTE_INIT: - #ifdef DEBUG - fuprintf(log, "[u8g2] init\n"); - #endif + case U8X8_MSG_BYTE_INIT: +#ifdef DEBUG + fuprintf(log, "[u8g2] init\n"); +#endif - // TODO change it to FuriRecord pin - HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET); + // TODO change it to FuriRecord pin + HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET); break; - case U8X8_MSG_BYTE_START_TRANSFER: - #ifdef DEBUG - fuprintf(log, "[u8g2] start\n"); - #endif + case U8X8_MSG_BYTE_START_TRANSFER: +#ifdef DEBUG + fuprintf(log, "[u8g2] start\n"); +#endif - // TODO change it to FuriRecord pin - HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET); - asm("nop"); + // TODO change it to FuriRecord pin + HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET); + asm("nop"); break; - case U8X8_MSG_BYTE_END_TRANSFER: - #ifdef DEBUG - fuprintf(log, "[u8g2] end\n"); - #endif + case U8X8_MSG_BYTE_END_TRANSFER: +#ifdef DEBUG + fuprintf(log, "[u8g2] end\n"); +#endif - asm("nop"); - // TODO change it to FuriRecord pin - HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_SET); + asm("nop"); + // TODO change it to FuriRecord pin + HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_SET); break; - default: - #ifdef DEBUG - fuprintf(log, "[u8g2] unknown xfer %d\n", msg); - #endif + default: +#ifdef DEBUG + fuprintf(log, "[u8g2] unknown xfer %d\n", msg); +#endif - return 0; + return 0; } return 1; @@ -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"); diff --git a/applications/examples/blink.c b/applications/examples/blink.c index 244b54f7..d6d23bf2 100644 --- a/applications/examples/blink.c +++ b/applications/examples/blink.c @@ -3,7 +3,7 @@ void application_blink(void* p) { // create pin GpioPin led = {.pin = GPIO_PIN_8, .port = GPIOA}; - + // configure pin pinMode(led, GpioModeOpenDrain); diff --git a/applications/examples/ipc.c b/applications/examples/ipc.c index 5066fdd2..7860ad9e 100644 --- a/applications/examples/ipc.c +++ b/applications/examples/ipc.c @@ -25,7 +25,7 @@ static void handle_fb_change(const void* fb, size_t fb_size, void* raw_ctx) { static void print_fb(char* fb, FuriRecordSubscriber* log) { if(fb == NULL) return; - + /* draw framebuffer like this: +==========+ | | @@ -78,57 +78,53 @@ 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"); furiac_exit(NULL); } - #ifdef HW_DISPLAY +#ifdef HW_DISPLAY // on Flipper target -- open screen // draw border - #else +#else // on Local target -- print "blank screen" { void* fb = furi_take(fb_record); print_fb((char*)fb, log); furi_give(fb_record); } - #endif +#endif while(1) { // wait for event if(xSemaphoreTake(events, portMAX_DELAY) == pdTRUE) { fuprintf(log, "[display] get fb update\n\n"); - #ifdef HW_DISPLAY - // on Flipper target draw the screen - #else +#ifdef HW_DISPLAY +// on Flipper target draw the screen +#else // on local target just print { void* fb = furi_take(fb_record); print_fb((char*)fb, log); furi_give(fb_record); } - #endif +#endif } } } - // 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"); diff --git a/applications/examples/u8g2_example.c b/applications/examples/u8g2_example.c index 1df8bb0f..92b43447 100644 --- a/applications/examples/u8g2_example.c +++ b/applications/examples/u8g2_example.c @@ -6,11 +6,9 @@ void u8g2_example(void* p) { // TODO try open record and retry on timeout (needs FURI behaviour change) 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"); diff --git a/applications/startup.h b/applications/startup.h index ebabc9c8..aa1a0eba 100644 --- a/applications/startup.h +++ b/applications/startup.h @@ -23,25 +23,25 @@ void u8g2_example(void* p); void coreglitch_demo_0(void* p); const FlipperStartupApp FLIPPER_STARTUP[] = { - #ifndef TEST +#ifndef TEST {.app = display_u8g2, .name = "display_u8g2"}, {.app = u8g2_example, .name = "u8g2_example"}, - #endif +#endif - // {.app = coreglitch_demo_0, .name = "coreglitch_demo_0"}, - - #ifdef TEST +// {.app = coreglitch_demo_0, .name = "coreglitch_demo_0"}, + +#ifdef TEST {.app = flipper_test_app, .name = "test app"}, - #endif +#endif - #ifdef EXAMPLE_BLINK +#ifdef EXAMPLE_BLINK {.app = application_blink, .name = "blink"}, - #endif - #ifdef EXAMPLE_UART_WRITE +#endif +#ifdef EXAMPLE_UART_WRITE {.app = application_uart_write, .name = "uart write"}, - #endif - #ifdef EXAMPLE_IPC +#endif +#ifdef EXAMPLE_IPC {.app = application_ipc_display, .name = "ipc display"}, {.app = application_ipc_widget, .name = "ipc widget"}, - #endif -}; \ No newline at end of file +#endif +}; diff --git a/applications/tests/furi_record_test.c b/applications/tests/furi_record_test.c index 15991ba9..f59d5c62 100644 --- a/applications/tests/furi_record_test.c +++ b/applications/tests/furi_record_test.c @@ -29,10 +29,9 @@ bool test_furi_pipe_record(FuriRecordSubscriber* log) { return false; } - // 2. Open/subscribe to it - FuriRecordSubscriber* pipe_record = furi_open( - "test/pipe", false, false, pipe_record_cb, NULL, NULL - ); + // 2. Open/subscribe to it + 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; diff --git a/applications/tests/furiac_test.c b/applications/tests/furiac_test.c index 2c0f30cb..f9cdc201 100644 --- a/applications/tests/furiac_test.c +++ b/applications/tests/furiac_test.c @@ -78,7 +78,7 @@ typedef struct { void task_a(void*); void task_b(void*); -void task_a(void *p) { +void task_a(void* p) { // simply starts, add 'A' letter to sequence and switch // if sequence counter = 0, call task B, exit otherwise @@ -118,7 +118,7 @@ bool test_furi_ac_switch_exit(FuriRecordSubscriber* log) { furiac_start(task_a, "task A", (void*)&seq); // TODO how to check that all child task ends? - + delay(10); // wait while task do its work seq.sequence[seq.count] = '\0'; diff --git a/applications/tests/test_index.c b/applications/tests/test_index.c index 3b199164..96577ed6 100644 --- a/applications/tests/test_index.c +++ b/applications/tests/test_index.c @@ -15,7 +15,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log); void flipper_test_app(void* p) { FuriRecordSubscriber* log = get_default_log(); - + if(test_furi_ac_create_kill(log)) { fuprintf(log, "[TEST] test_furi_ac_create_kill PASSED\n"); } else { @@ -66,6 +66,5 @@ void flipper_test_app(void* p) { rust_uart_write(); - furiac_exit(NULL); } \ No newline at end of file diff --git a/core-rs/flipper-core/build.rs b/core-rs/flipper-core/build.rs index 2f36b8a9..70b94c1e 100644 --- a/core-rs/flipper-core/build.rs +++ b/core-rs/flipper-core/build.rs @@ -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)), ); -} \ No newline at end of file +} diff --git a/core-rs/flipper-core/src/lib.rs b/core-rs/flipper-core/src/lib.rs index 06eac65d..12d0c8a8 100644 --- a/core-rs/flipper-core/src/lib.rs +++ b/core-rs/flipper-core/src/lib.rs @@ -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; + } } } diff --git a/core-rs/flipper-f1-sys/build.rs b/core-rs/flipper-f1-sys/build.rs index 90409242..ecbd8923 100644 --- a/core-rs/flipper-f1-sys/build.rs +++ b/core-rs/flipper-f1-sys/build.rs @@ -54,7 +54,7 @@ impl BindingsGenerator { "Middlewares/ST/STM32_USB_Device_Library/Core/Inc", "Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc", ]; - + let stm32_sdk_includes = stm32_sdk_includes .iter() .map(|stm32_include| format!("{}/{}", self.clib_dir.to_string_lossy(), stm32_include)); @@ -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)) @@ -268,7 +263,7 @@ impl BindingsGenerator { bindings .write_to_file(result_path) .expect("Couldn't write bindings!"); - } + } } fn detect_gcc_inclide_dir() -> PathBuf { diff --git a/core-rs/flipper-f1-sys/src/lib.rs b/core-rs/flipper-f1-sys/src/lib.rs index 04bc768d..5916dcbe 100644 --- a/core-rs/flipper-f1-sys/src/lib.rs +++ b/core-rs/flipper-f1-sys/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] - #![allow(dead_code)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] @@ -17,4 +16,4 @@ pub mod cmsis_os { pub mod hal { include!(concat!(env!("OUT_DIR"), "/stm32_hal_bindings.rs")); include!(concat!(env!("OUT_DIR"), "/stm32_hal_statics.rs")); -} \ No newline at end of file +} diff --git a/core/app.cpp b/core/app.cpp index 807b3474..36b9de52 100644 --- a/core/app.cpp +++ b/core/app.cpp @@ -2,10 +2,10 @@ #include extern "C" { - #include "startup.h" - #include "furi.h" - #include "log.h" - #include "tty_uart.h" +#include "startup.h" +#include "furi.h" +#include "log.h" +#include "tty_uart.h" } extern "C" void app() { @@ -15,16 +15,16 @@ extern "C" void app() { fuprintf(log, "\n=== Welcome to Flipper Zero! ===\n\n"); // FURI startup - FuriApp* handlers[sizeof(FLIPPER_STARTUP)/sizeof(FLIPPER_STARTUP[0])]; + FuriApp* handlers[sizeof(FLIPPER_STARTUP) / sizeof(FLIPPER_STARTUP[0])]; - for(size_t i = 0; i < sizeof(FLIPPER_STARTUP)/sizeof(FLIPPER_STARTUP[0]); i++) { + for(size_t i = 0; i < sizeof(FLIPPER_STARTUP) / sizeof(FLIPPER_STARTUP[0]); i++) { handlers[i] = furiac_start(FLIPPER_STARTUP[i].app, FLIPPER_STARTUP[i].name, NULL); } bool is_alive = false; do { is_alive = false; - for(size_t i = 0; i < sizeof(FLIPPER_STARTUP)/sizeof(FLIPPER_STARTUP[0]); i++) { + for(size_t i = 0; i < sizeof(FLIPPER_STARTUP) / sizeof(FLIPPER_STARTUP[0]); i++) { if(handlers[i]->handler != NULL) { is_alive = true; } diff --git a/core/flipper.h b/core/flipper.h index 96776d28..b14210b2 100644 --- a/core/flipper.h +++ b/core/flipper.h @@ -4,11 +4,11 @@ extern "C" { #endif - #include "main.h" - #include "flipper_hal.h" - #include "cmsis_os.h" - #include "furi.h" - #include "log.h" +#include "main.h" +#include "flipper_hal.h" +#include "cmsis_os.h" +#include "furi.h" +#include "log.h" #ifdef __cplusplus } diff --git a/core/furi.c b/core/furi.c index 0f205c48..e85f5ba8 100644 --- a/core/furi.c +++ b/core/furi.c @@ -29,16 +29,16 @@ static FuriRecord* find_record(const char* name) { // TODO: change open-create to only open bool furi_create(const char* name, void* value, size_t size) { - #ifdef FURI_DEBUG - printf("[FURI] creating %s record\n", name); - #endif +#ifdef FURI_DEBUG + printf("[FURI] creating %s record\n", name); +#endif FuriRecord* record = find_record(name); if(record != NULL) { - #ifdef FURI_DEBUG - printf("[FURI] record already exist\n"); - #endif +#ifdef FURI_DEBUG + printf("[FURI] record already exist\n"); +#endif record->value = value; record->size = size; @@ -49,17 +49,16 @@ bool furi_create(const char* name, void* value, size_t size) { // record not exist, create new if(current_buffer_idx >= MAX_RECORD_COUNT) { - // max record count exceed - #ifdef FURI_DEBUG - printf("[FURI] create: max record count exceed\n"); - #endif +// max record count exceed +#ifdef FURI_DEBUG + printf("[FURI] create: max record count exceed\n"); +#endif return NULL; } 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,26 +73,24 @@ bool furi_create(const char* name, void* value, size_t size) { return true; } -FuriRecordSubscriber* furi_open( - const char* name, - bool solo, - bool no_mute, - FlipperRecordCallback value_callback, - FlipperRecordStateCallback state_callback, - void* ctx -) { - #ifdef FURI_DEBUG - printf("[FURI] opening %s record\n", name); - #endif +FuriRecordSubscriber* furi_open(const char* name, + bool solo, + bool no_mute, + FlipperRecordCallback value_callback, + FlipperRecordStateCallback state_callback, + void* ctx) { +#ifdef FURI_DEBUG + printf("[FURI] opening %s record\n", name); +#endif // get furi record by name FuriRecord* record = find_record(name); if(record == NULL) { - // cannot find record - #ifdef FURI_DEBUG - printf("[FURI] cannot find record %s\n", name); - #endif +// cannot find record +#ifdef FURI_DEBUG + printf("[FURI] cannot find record %s\n", name); +#endif // create record if not exist if(!furi_create(name, NULL, 0)) { @@ -118,11 +115,11 @@ FuriRecordSubscriber* furi_open( } if(subscriber == NULL) { - // cannot add subscriber (full) - #ifdef FURI_DEBUG - printf("[FURI] open: cannot add subscriber (full)\n"); - #endif - +// cannot add subscriber (full) +#ifdef FURI_DEBUG + printf("[FURI] open: cannot add subscriber (full)\n"); +#endif + return NULL; } @@ -147,19 +144,18 @@ FuriRecordSubscriber* furi_open( current_task->records[current_task->records_count] = record; current_task->records_count++; } else { - #ifdef FURI_DEBUG - printf("[FURI] open: no current task\n"); - #endif +#ifdef FURI_DEBUG + printf("[FURI] open: no current task\n"); +#endif } return subscriber; } - void furi_close(FuriRecordSubscriber* handler) { - #ifdef FURI_DEBUG - printf("[FURI] closing %s record\n", handler->record->name); - #endif +#ifdef FURI_DEBUG + printf("[FURI] closing %s record\n", handler->record->name); +#endif // deallocate subscriber handler->allocated = false; @@ -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); } } } @@ -193,7 +186,7 @@ static void furi_notify(FuriRecordSubscriber* handler, const void* value, size_t void* furi_take(FuriRecordSubscriber* handler) { if(handler == NULL || handler->record == NULL) return NULL; - if (xSemaphoreTake(handler->record->mutex, portMAX_DELAY) == pdTRUE) { + if(xSemaphoreTake(handler->record->mutex, portMAX_DELAY) == pdTRUE) { return handler->record->value; } else { return NULL; @@ -214,9 +207,9 @@ void furi_commit(FuriRecordSubscriber* handler) { } bool furi_read(FuriRecordSubscriber* handler, void* value, size_t size) { - #ifdef FURI_DEBUG - printf("[FURI] read from %s\n", handler->record->name); - #endif +#ifdef FURI_DEBUG + printf("[FURI] read from %s\n", handler->record->name); +#endif if(handler == NULL || handler->record == NULL || value == NULL) return false; @@ -234,41 +227,40 @@ bool furi_read(FuriRecordSubscriber* handler, void* value, size_t size) { } bool furi_write(FuriRecordSubscriber* handler, const void* value, size_t size) { - #ifdef FURI_DEBUG - printf("[FURI] write to %s\n", handler->record->name); - #endif +#ifdef FURI_DEBUG + printf("[FURI] write to %s\n", handler->record->name); +#endif 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); - #endif +#ifdef FURI_DEBUG + printf("[FURI] write: null param %x %x\n", + (uint32_t)(size_t)handler, + (uint32_t)(size_t)value); +#endif return false; } // check if closed if(!handler->allocated) { - #ifdef FURI_DEBUG - printf("[FURI] write: handler closed\n"); - #endif +#ifdef FURI_DEBUG + printf("[FURI] write: handler closed\n"); +#endif return false; } if(handler->record->value != NULL && size > handler->record->size) { - #ifdef FURI_DEBUG - printf("[FURI] write: wrong size %d\n", (uint32_t)size); - #endif +#ifdef FURI_DEBUG + printf("[FURI] write: wrong size %d\n", (uint32_t)size); +#endif return false; } // check mute - if( - handler->record->mute_counter != handler->mute_counter - && !handler->no_mute - ) { - #ifdef FURI_DEBUG - printf("[FURI] write: muted\n"); - #endif + if(handler->record->mute_counter != handler->mute_counter && !handler->no_mute) { +#ifdef FURI_DEBUG + printf("[FURI] write: muted\n"); +#endif return false; } diff --git a/core/furi.h b/core/furi.h index c66bad98..66aea585 100644 --- a/core/furi.h +++ b/core/furi.h @@ -8,10 +8,10 @@ #define MAX_RECORD_SUBSCRIBERS 8 /// application is just a function -typedef void(*FlipperApplication)(void*); +typedef void (*FlipperApplication)(void*); /// pointer to value callback function -typedef void(*FlipperRecordCallback)(const void*, size_t, void*); +typedef void (*FlipperRecordCallback)(const void*, size_t, void*); typedef enum { FlipperRecordStateMute, ///< record open and mute this handler @@ -20,7 +20,7 @@ typedef enum { } FlipperRecordState; /// pointer to state callback function -typedef void(*FlipperRecordStateCallback)(FlipperRecordState, void*); +typedef void (*FlipperRecordStateCallback)(FlipperRecordState, void*); struct _FuriRecord; @@ -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, - bool solo, - bool no_mute, - FlipperRecordCallback value_callback, - FlipperRecordStateCallback state_callback, - void* ctx -); +FuriRecordSubscriber* furi_open(const char* name, + bool solo, + bool no_mute, + FlipperRecordCallback value_callback, + FlipperRecordStateCallback state_callback, + void* ctx); /*! diff --git a/core/furi_ac.c b/core/furi_ac.c index 51678432..6ddbb142 100644 --- a/core/furi_ac.c +++ b/core/furi_ac.c @@ -29,30 +29,29 @@ FuriApp* find_task(TaskHandle_t handler) { } FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) { - #ifdef FURI_DEBUG - printf("[FURIAC] start %s\n", name); - #endif +#ifdef FURI_DEBUG + printf("[FURIAC] start %s\n", name); +#endif // TODO check first free item (.handler == NULL) and use it if(current_buffer_idx >= MAX_TASK_COUNT) { - // max task count exceed - #ifdef FURI_DEBUG - printf("[FURIAC] max task count exceed\n"); - #endif +// max task count exceed +#ifdef FURI_DEBUG + printf("[FURIAC] max task count exceed\n"); +#endif return NULL; } // create task on static stack memory - 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_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]); // save task task_buffer[current_buffer_idx].application = app; @@ -67,9 +66,9 @@ FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) { } bool furiac_kill(FuriApp* app) { - #ifdef FURI_DEBUG - printf("[FURIAC] kill %s\n", app->name); - #endif +#ifdef FURI_DEBUG + printf("[FURIAC] kill %s\n", app->name); +#endif // check handler if(app == NULL || app->handler == NULL) return false; @@ -90,16 +89,16 @@ void furiac_exit(void* param) { // run prev if(current_task != NULL) { - #ifdef FURI_DEBUG - printf("[FURIAC] exit %s\n", current_task->name); - #endif +#ifdef FURI_DEBUG + printf("[FURIAC] exit %s\n", current_task->name); +#endif if(current_task->prev != NULL) { furiac_start(current_task->prev, current_task->prev_name, param); } else { - #ifdef FURI_DEBUG - printf("[FURIAC] no prev\n"); - #endif +#ifdef FURI_DEBUG + printf("[FURIAC] no prev\n"); +#endif } // cleanup registry @@ -108,7 +107,7 @@ void furiac_exit(void* param) { } // kill itself - vTaskDelete(NULL); + vTaskDelete(NULL); } void furiac_switch(FlipperApplication app, char* name, void* param) { @@ -116,14 +115,14 @@ void furiac_switch(FlipperApplication app, char* name, void* param) { FuriApp* current_task = find_task(xTaskGetCurrentTaskHandle()); if(current_task == NULL) { - #ifdef FURI_DEBUG - printf("[FURIAC] no current task found\n"); - #endif +#ifdef FURI_DEBUG + printf("[FURIAC] no current task found\n"); +#endif } - #ifdef FURI_DEBUG - printf("[FURIAC] switch %s to %s\n", current_task->name, name); - #endif +#ifdef FURI_DEBUG + printf("[FURIAC] switch %s to %s\n", current_task->name, name); +#endif // run next FuriApp* next = furiac_start(app, name, param); diff --git a/core/log.c b/core/log.c index 1435bbec..3023528f 100644 --- a/core/log.c +++ b/core/log.c @@ -9,7 +9,7 @@ #define PRINT_STR_SIZE 64 -void fuprintf(FuriRecordSubscriber* f, const char * format, ...) { +void fuprintf(FuriRecordSubscriber* f, const char* format, ...) { char buffer[PRINT_STR_SIZE]; va_list args; diff --git a/core/log.h b/core/log.h index 9417ddaf..b8b80b01 100644 --- a/core/log.h +++ b/core/log.h @@ -3,4 +3,4 @@ #include "furi.h" FuriRecordSubscriber* get_default_log(); -void fuprintf(FuriRecordSubscriber* f, const char * format, ...); +void fuprintf(FuriRecordSubscriber* f, const char* format, ...); diff --git a/core/tty_uart.c b/core/tty_uart.c index e4e729d7..d70e3183 100644 --- a/core/tty_uart.c +++ b/core/tty_uart.c @@ -6,19 +6,19 @@ extern UART_HandleTypeDef DEBUG_UART; void handle_uart_write(const void* data, size_t size, void* ctx) { - HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)data, (uint16_t)size, HAL_MAX_DELAY); + HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)data, (uint16_t)size, HAL_MAX_DELAY); } -static ssize_t stdout_write(void *_cookie, const char *buf, size_t n) { - FuriRecordSubscriber *log = pvTaskGetThreadLocalStoragePointer(NULL, 0); - if (log == NULL) { +static ssize_t stdout_write(void* _cookie, const char* buf, size_t n) { + FuriRecordSubscriber* log = pvTaskGetThreadLocalStoragePointer(NULL, 0); + if(log == NULL) { log = furi_open("tty", false, false, NULL, NULL, NULL); - if (log == NULL) { + if(log == NULL) { return -1; } vTaskSetThreadLocalStoragePointer(NULL, 0, log); } - if (buf == 0) { + if(buf == 0) { /* * This means that we should flush internal buffers. Since we * don't we just return. (Remember, "handle" == -1 means that all @@ -33,22 +33,24 @@ static ssize_t stdout_write(void *_cookie, const char *buf, size_t n) { } bool register_tty_uart() { - if(!furi_create("tty", NULL, 0)) { - return false; - } + if(!furi_create("tty", NULL, 0)) { + return false; + } - if(furi_open("tty", false, false, handle_uart_write, NULL, NULL) == NULL) { - return false; - } + if(furi_open("tty", false, false, handle_uart_write, NULL, NULL) == NULL) { + return false; + } - FILE* fp = fopencookie(NULL, "w", (cookie_io_functions_t) { - .read = NULL, - .write = stdout_write, - .seek = NULL, - .close = NULL, - }); + FILE* fp = fopencookie(NULL, + "w", + (cookie_io_functions_t){ + .read = NULL, + .write = stdout_write, + .seek = NULL, + .close = NULL, + }); setvbuf(fp, NULL, _IONBF, 0); stdout = fp; - return true; + return true; } diff --git a/docker-compose.yml b/docker-compose.yml index 42aa5ac4..7ac6d569 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/docker/Dockerfile b/docker/Dockerfile index 127b323c..969bbded 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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"] diff --git a/docker/syntax_check.sh b/docker/syntax_check.sh new file mode 100755 index 00000000..43425bf7 --- /dev/null +++ b/docker/syntax_check.sh @@ -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 \ No newline at end of file diff --git a/syntax_check.sh b/syntax_check.sh new file mode 100755 index 00000000..4ad00e80 --- /dev/null +++ b/syntax_check.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +echo "RUN SYNTAX CHECK INSIDE CONTAINER" +docker-compose exec dev ./docker/syntax_check.sh diff --git a/target_f1/Inc/FreeRTOSConfig.h b/target_f1/Inc/FreeRTOSConfig.h index 085eb0c7..170cb7cc 100644 --- a/target_f1/Inc/FreeRTOSConfig.h +++ b/target_f1/Inc/FreeRTOSConfig.h @@ -25,7 +25,7 @@ * * 1 tab == 4 spaces! */ - /* USER CODE END Header */ +/* USER CODE END Header */ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H @@ -42,15 +42,15 @@ * See http://www.freertos.org/a00110.html *----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ +/* USER CODE BEGIN Includes */ /* Section where include file can be added */ -/* USER CODE END Includes */ +/* USER CODE END Includes */ /* Ensure definitions are only used by the compiler, and not by the assembler. */ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) - #include - extern uint32_t SystemCoreClock; - void xPortSysTickHandler(void); +#include +extern uint32_t SystemCoreClock; +void xPortSysTickHandler(void); #endif #define configUSE_PREEMPTION 1 #define configSUPPORT_STATIC_ALLOCATION 1 @@ -71,37 +71,37 @@ #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 1 /* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) /* Software timer definitions. */ -#define configUSE_TIMERS 1 -#define configTIMER_TASK_PRIORITY ( 2 ) -#define configTIMER_QUEUE_LENGTH 10 -#define configTIMER_TASK_STACK_DEPTH 256 +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (2) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH 256 /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 0 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 /* Cortex-M specific definitions. */ #ifdef __NVIC_PRIO_BITS - /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ - #define configPRIO_BITS __NVIC_PRIO_BITS +/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ +#define configPRIO_BITS __NVIC_PRIO_BITS #else - #define configPRIO_BITS 4 +#define configPRIO_BITS 4 #endif /* The lowest interrupt priority that can be used in a call to a "set priority" function. */ -#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 /* The highest interrupt priority that can be used by any interrupt service routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL @@ -111,29 +111,36 @@ 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 standard names. */ -#define vPortSVCHandler SVC_Handler +#define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick, to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ - + /* #define xPortSysTickHandler SysTick_Handler */ -/* USER CODE BEGIN Defines */ +/* USER CODE BEGIN Defines */ /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ -/* USER CODE END Defines */ +/* USER CODE END Defines */ #endif /* FREERTOS_CONFIG_H */ diff --git a/target_f1/Inc/flipper_hal.h b/target_f1/Inc/flipper_hal.h index aae9014b..02b8a1ad 100644 --- a/target_f1/Inc/flipper_hal.h +++ b/target_f1/Inc/flipper_hal.h @@ -9,11 +9,7 @@ GPIO and HAL implementations #include #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; diff --git a/target_f1/Inc/main.h b/target_f1/Inc/main.h index 93805470..5c76314b 100644 --- a/target_f1/Inc/main.h +++ b/target_f1/Inc/main.h @@ -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 */ @@ -55,14 +52,14 @@ typedef enum { /* USER CODE END EM */ -void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim); /* Exported functions prototypes ---------------------------------------------*/ void Error_Handler(void); /* USER CODE BEGIN EFP */ -void register_tim8_callback_ch2(void(*callback)(uint16_t ccr, TimerEvent tim_event)); +void register_tim8_callback_ch2(void (*callback)(uint16_t ccr, TimerEvent tim_event)); /* USER CODE END EFP */ @@ -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 */ diff --git a/target_f1/Inc/stm32l4xx_hal_conf.h b/target_f1/Inc/stm32l4xx_hal_conf.h index f8c241f2..75efea9b 100644 --- a/target_f1/Inc/stm32l4xx_hal_conf.h +++ b/target_f1/Inc/stm32l4xx_hal_conf.h @@ -30,14 +30,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32L4xx_HAL_CONF_H #define __STM32L4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -48,7 +48,7 @@ * @brief This is the list of modules to be used in the HAL driver */ -#define HAL_MODULE_ENABLED +#define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED /*#define HAL_CRYP_MODULE_ENABLED */ /*#define HAL_CAN_MODULE_ENABLED */ @@ -95,7 +95,7 @@ /*#define HAL_WWDG_MODULE_ENABLED */ /*#define HAL_EXTI_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED -#define HAL_EXTI_MODULE_ENABLED +#define HAL_EXTI_MODULE_ENABLED #define HAL_I2C_MODULE_ENABLED #define HAL_DMA_MODULE_ENABLED #define HAL_RCC_MODULE_ENABLED @@ -109,28 +109,28 @@ * This value is used by the RCC HAL module to compute the system frequency * (when HSE is used as system clock source, directly or through the PLL). */ -#if !defined (HSE_VALUE) - #define HSE_VALUE ((uint32_t)16000000U) /*!< Value of the External oscillator in Hz */ +#if !defined(HSE_VALUE) +#define HSE_VALUE ((uint32_t)16000000U) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ /** * @brief Internal Multiple Speed oscillator (MSI) default value. * This value is the default MSI range value after Reset. */ -#if !defined (MSI_VALUE) - #define MSI_VALUE ((uint32_t)4000000U) /*!< Value of the Internal oscillator in Hz*/ +#if !defined(MSI_VALUE) +#define MSI_VALUE ((uint32_t)4000000U) /*!< Value of the Internal oscillator in Hz*/ #endif /* MSI_VALUE */ /** * @brief Internal High Speed oscillator (HSI) value. * This value is used by the RCC HAL module to compute the system frequency * (when HSI is used as system clock source, directly or through the PLL). */ -#if !defined (HSI_VALUE) - #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ +#if !defined(HSI_VALUE) +#define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /** @@ -140,17 +140,18 @@ * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency * 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. +#if !defined(HSI48_VALUE) +#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 */ /** * @brief Internal Low Speed oscillator (LSI) value. */ -#if !defined (LSI_VALUE) - #define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz +#if !defined(LSI_VALUE) +#define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ @@ -158,12 +159,12 @@ * @brief External Low Speed oscillator (LSE) value. * This value is used by the UART, RTC HAL module to compute the system frequency */ -#if !defined (LSE_VALUE) - #define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External oscillator in Hz*/ +#if !defined(LSE_VALUE) +#define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External oscillator in Hz*/ #endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) - #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ /** @@ -171,8 +172,9 @@ * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source * frequency. */ -#if !defined (EXTERNAL_SAI1_CLOCK_VALUE) - #define EXTERNAL_SAI1_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/ +#if !defined(EXTERNAL_SAI1_CLOCK_VALUE) +#define EXTERNAL_SAI1_CLOCK_VALUE \ + ((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/ #endif /* EXTERNAL_SAI1_CLOCK_VALUE */ /** @@ -180,8 +182,9 @@ * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source * frequency. */ -#if !defined (EXTERNAL_SAI2_CLOCK_VALUE) - #define EXTERNAL_SAI2_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI2 External clock source in Hz*/ +#if !defined(EXTERNAL_SAI2_CLOCK_VALUE) +#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, @@ -190,14 +193,14 @@ /* ########################### System Configuration ######################### */ /** * @brief This is the HAL system configuration section - */ - -#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY ((uint32_t)15U) /*!< tick interrupt priority */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 1U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U + */ + +#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)15U) /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** @@ -213,7 +216,7 @@ * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** @@ -221,201 +224,201 @@ */ #ifdef HAL_RCC_MODULE_ENABLED - #include "stm32l4xx_hal_rcc.h" - #include "stm32l4xx_hal_rcc_ex.h" +#include "stm32l4xx_hal_rcc.h" +#include "stm32l4xx_hal_rcc_ex.h" #endif /* HAL_RCC_MODULE_ENABLED */ #ifdef HAL_EXTI_MODULE_ENABLED - #include "stm32l4xx_hal_exti.h" +#include "stm32l4xx_hal_exti.h" #endif /* HAL_EXTI_MODULE_ENABLED */ #ifdef HAL_GPIO_MODULE_ENABLED - #include "stm32l4xx_hal_gpio.h" +#include "stm32l4xx_hal_gpio.h" #endif /* HAL_GPIO_MODULE_ENABLED */ #ifdef HAL_DMA_MODULE_ENABLED - #include "stm32l4xx_hal_dma.h" - #include "stm32l4xx_hal_dma_ex.h" +#include "stm32l4xx_hal_dma.h" +#include "stm32l4xx_hal_dma_ex.h" #endif /* HAL_DMA_MODULE_ENABLED */ #ifdef HAL_DFSDM_MODULE_ENABLED - #include "stm32l4xx_hal_dfsdm.h" +#include "stm32l4xx_hal_dfsdm.h" #endif /* HAL_DFSDM_MODULE_ENABLED */ #ifdef HAL_CORTEX_MODULE_ENABLED - #include "stm32l4xx_hal_cortex.h" +#include "stm32l4xx_hal_cortex.h" #endif /* HAL_CORTEX_MODULE_ENABLED */ #ifdef HAL_ADC_MODULE_ENABLED - #include "stm32l4xx_hal_adc.h" +#include "stm32l4xx_hal_adc.h" #endif /* HAL_ADC_MODULE_ENABLED */ #ifdef HAL_CAN_MODULE_ENABLED - #include "stm32l4xx_hal_can.h" +#include "stm32l4xx_hal_can.h" #endif /* HAL_CAN_MODULE_ENABLED */ #ifdef HAL_COMP_MODULE_ENABLED - #include "stm32l4xx_hal_comp.h" +#include "stm32l4xx_hal_comp.h" #endif /* HAL_COMP_MODULE_ENABLED */ #ifdef HAL_CRC_MODULE_ENABLED - #include "stm32l4xx_hal_crc.h" +#include "stm32l4xx_hal_crc.h" #endif /* HAL_CRC_MODULE_ENABLED */ #ifdef HAL_CRYP_MODULE_ENABLED - #include "stm32l4xx_hal_cryp.h" +#include "stm32l4xx_hal_cryp.h" #endif /* HAL_CRYP_MODULE_ENABLED */ #ifdef HAL_DAC_MODULE_ENABLED - #include "stm32l4xx_hal_dac.h" +#include "stm32l4xx_hal_dac.h" #endif /* HAL_DAC_MODULE_ENABLED */ #ifdef HAL_DCMI_MODULE_ENABLED - #include "stm32l4xx_hal_dcmi.h" +#include "stm32l4xx_hal_dcmi.h" #endif /* HAL_DCMI_MODULE_ENABLED */ #ifdef HAL_DMA2D_MODULE_ENABLED - #include "stm32l4xx_hal_dma2d.h" +#include "stm32l4xx_hal_dma2d.h" #endif /* HAL_DMA2D_MODULE_ENABLED */ #ifdef HAL_DSI_MODULE_ENABLED - #include "stm32l4xx_hal_dsi.h" +#include "stm32l4xx_hal_dsi.h" #endif /* HAL_DSI_MODULE_ENABLED */ #ifdef HAL_FIREWALL_MODULE_ENABLED - #include "stm32l4xx_hal_firewall.h" +#include "stm32l4xx_hal_firewall.h" #endif /* HAL_FIREWALL_MODULE_ENABLED */ #ifdef HAL_FLASH_MODULE_ENABLED - #include "stm32l4xx_hal_flash.h" +#include "stm32l4xx_hal_flash.h" #endif /* HAL_FLASH_MODULE_ENABLED */ #ifdef HAL_HASH_MODULE_ENABLED - #include "stm32l4xx_hal_hash.h" +#include "stm32l4xx_hal_hash.h" #endif /* HAL_HASH_MODULE_ENABLED */ #ifdef HAL_SRAM_MODULE_ENABLED - #include "stm32l4xx_hal_sram.h" +#include "stm32l4xx_hal_sram.h" #endif /* HAL_SRAM_MODULE_ENABLED */ #ifdef HAL_MMC_MODULE_ENABLED - #include "stm32l4xx_hal_mmc.h" +#include "stm32l4xx_hal_mmc.h" #endif /* HAL_MMC_MODULE_ENABLED */ #ifdef HAL_NOR_MODULE_ENABLED - #include "stm32l4xx_hal_nor.h" +#include "stm32l4xx_hal_nor.h" #endif /* HAL_NOR_MODULE_ENABLED */ #ifdef HAL_NAND_MODULE_ENABLED - #include "stm32l4xx_hal_nand.h" +#include "stm32l4xx_hal_nand.h" #endif /* HAL_NAND_MODULE_ENABLED */ #ifdef HAL_I2C_MODULE_ENABLED - #include "stm32l4xx_hal_i2c.h" +#include "stm32l4xx_hal_i2c.h" #endif /* HAL_I2C_MODULE_ENABLED */ #ifdef HAL_IWDG_MODULE_ENABLED - #include "stm32l4xx_hal_iwdg.h" +#include "stm32l4xx_hal_iwdg.h" #endif /* HAL_IWDG_MODULE_ENABLED */ #ifdef HAL_LCD_MODULE_ENABLED - #include "stm32l4xx_hal_lcd.h" +#include "stm32l4xx_hal_lcd.h" #endif /* HAL_LCD_MODULE_ENABLED */ #ifdef HAL_LPTIM_MODULE_ENABLED - #include "stm32l4xx_hal_lptim.h" +#include "stm32l4xx_hal_lptim.h" #endif /* HAL_LPTIM_MODULE_ENABLED */ #ifdef HAL_LTDC_MODULE_ENABLED - #include "stm32l4xx_hal_ltdc.h" +#include "stm32l4xx_hal_ltdc.h" #endif /* HAL_LTDC_MODULE_ENABLED */ #ifdef HAL_OPAMP_MODULE_ENABLED - #include "stm32l4xx_hal_opamp.h" +#include "stm32l4xx_hal_opamp.h" #endif /* HAL_OPAMP_MODULE_ENABLED */ #ifdef HAL_OSPI_MODULE_ENABLED - #include "stm32l4xx_hal_ospi.h" +#include "stm32l4xx_hal_ospi.h" #endif /* HAL_OSPI_MODULE_ENABLED */ #ifdef HAL_PWR_MODULE_ENABLED - #include "stm32l4xx_hal_pwr.h" +#include "stm32l4xx_hal_pwr.h" #endif /* HAL_PWR_MODULE_ENABLED */ #ifdef HAL_QSPI_MODULE_ENABLED - #include "stm32l4xx_hal_qspi.h" +#include "stm32l4xx_hal_qspi.h" #endif /* HAL_QSPI_MODULE_ENABLED */ #ifdef HAL_RNG_MODULE_ENABLED - #include "stm32l4xx_hal_rng.h" +#include "stm32l4xx_hal_rng.h" #endif /* HAL_RNG_MODULE_ENABLED */ #ifdef HAL_RTC_MODULE_ENABLED - #include "stm32l4xx_hal_rtc.h" +#include "stm32l4xx_hal_rtc.h" #endif /* HAL_RTC_MODULE_ENABLED */ #ifdef HAL_SAI_MODULE_ENABLED - #include "stm32l4xx_hal_sai.h" +#include "stm32l4xx_hal_sai.h" #endif /* HAL_SAI_MODULE_ENABLED */ #ifdef HAL_SD_MODULE_ENABLED - #include "stm32l4xx_hal_sd.h" +#include "stm32l4xx_hal_sd.h" #endif /* HAL_SD_MODULE_ENABLED */ #ifdef HAL_SMBUS_MODULE_ENABLED - #include "stm32l4xx_hal_smbus.h" +#include "stm32l4xx_hal_smbus.h" #endif /* HAL_SMBUS_MODULE_ENABLED */ #ifdef HAL_SPI_MODULE_ENABLED - #include "stm32l4xx_hal_spi.h" +#include "stm32l4xx_hal_spi.h" #endif /* HAL_SPI_MODULE_ENABLED */ #ifdef HAL_SWPMI_MODULE_ENABLED - #include "stm32l4xx_hal_swpmi.h" +#include "stm32l4xx_hal_swpmi.h" #endif /* HAL_SWPMI_MODULE_ENABLED */ #ifdef HAL_TIM_MODULE_ENABLED - #include "stm32l4xx_hal_tim.h" +#include "stm32l4xx_hal_tim.h" #endif /* HAL_TIM_MODULE_ENABLED */ #ifdef HAL_TSC_MODULE_ENABLED - #include "stm32l4xx_hal_tsc.h" +#include "stm32l4xx_hal_tsc.h" #endif /* HAL_TSC_MODULE_ENABLED */ #ifdef HAL_UART_MODULE_ENABLED - #include "stm32l4xx_hal_uart.h" +#include "stm32l4xx_hal_uart.h" #endif /* HAL_UART_MODULE_ENABLED */ #ifdef HAL_USART_MODULE_ENABLED - #include "stm32l4xx_hal_usart.h" +#include "stm32l4xx_hal_usart.h" #endif /* HAL_USART_MODULE_ENABLED */ #ifdef HAL_IRDA_MODULE_ENABLED - #include "stm32l4xx_hal_irda.h" +#include "stm32l4xx_hal_irda.h" #endif /* HAL_IRDA_MODULE_ENABLED */ #ifdef HAL_SMARTCARD_MODULE_ENABLED - #include "stm32l4xx_hal_smartcard.h" +#include "stm32l4xx_hal_smartcard.h" #endif /* HAL_SMARTCARD_MODULE_ENABLED */ #ifdef HAL_WWDG_MODULE_ENABLED - #include "stm32l4xx_hal_wwdg.h" +#include "stm32l4xx_hal_wwdg.h" #endif /* HAL_WWDG_MODULE_ENABLED */ #ifdef HAL_PCD_MODULE_ENABLED - #include "stm32l4xx_hal_pcd.h" +#include "stm32l4xx_hal_pcd.h" #endif /* HAL_PCD_MODULE_ENABLED */ #ifdef HAL_HCD_MODULE_ENABLED - #include "stm32l4xx_hal_hcd.h" +#include "stm32l4xx_hal_hcd.h" #endif /* HAL_HCD_MODULE_ENABLED */ #ifdef HAL_GFXMMU_MODULE_ENABLED - #include "stm32l4xx_hal_gfxmmu.h" +#include "stm32l4xx_hal_gfxmmu.h" #endif /* HAL_GFXMMU_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function @@ -424,11 +427,11 @@ * If expr is true, it returns no value. * @retval None */ - #define assert_param(expr) ((expr) ? (void)0U : assert_failed((char *)__FILE__, __LINE__)) +#define assert_param(expr) ((expr) ? (void)0U : assert_failed((char*)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ - void assert_failed(char *file, uint32_t line); +void assert_failed(char* file, uint32_t line); #else - #define assert_param(expr) ((void)0U) +#define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus diff --git a/target_f1/Inc/stm32l4xx_it.h b/target_f1/Inc/stm32l4xx_it.h index ba58e4d3..6f944995 100644 --- a/target_f1/Inc/stm32l4xx_it.h +++ b/target_f1/Inc/stm32l4xx_it.h @@ -23,8 +23,8 @@ #define __STM32L4xx_IT_H #ifdef __cplusplus - extern "C" { -#endif +extern "C" { +#endif /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/target_f1/Inc/usb_device.h b/target_f1/Inc/usb_device.h index 8be16a01..95750c56 100644 --- a/target_f1/Inc/usb_device.h +++ b/target_f1/Inc/usb_device.h @@ -24,7 +24,7 @@ #define __USB_DEVICE__H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/target_f1/Inc/usbd_cdc_if.h b/target_f1/Inc/usbd_cdc_if.h index b941a817..4d92c7a5 100644 --- a/target_f1/Inc/usbd_cdc_if.h +++ b/target_f1/Inc/usbd_cdc_if.h @@ -24,7 +24,7 @@ #define __USBD_CDC_IF_H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -38,11 +38,11 @@ * @brief For Usb device. * @{ */ - + /** @defgroup USBD_CDC_IF USBD_CDC_IF * @brief Usb VCP device module * @{ - */ + */ /** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines * @brief Defines. diff --git a/target_f1/Inc/usbd_conf.h b/target_f1/Inc/usbd_conf.h index 27cd021b..05514d09 100644 --- a/target_f1/Inc/usbd_conf.h +++ b/target_f1/Inc/usbd_conf.h @@ -24,7 +24,7 @@ #define __USBD_CONF__H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -61,21 +61,21 @@ */ /*---------- -----------*/ -#define USBD_MAX_NUM_INTERFACES 1U +#define USBD_MAX_NUM_INTERFACES 1U /*---------- -----------*/ -#define USBD_MAX_NUM_CONFIGURATION 1U +#define USBD_MAX_NUM_CONFIGURATION 1U /*---------- -----------*/ -#define USBD_MAX_STR_DESC_SIZ 512U +#define USBD_MAX_STR_DESC_SIZ 512U /*---------- -----------*/ -#define USBD_DEBUG_LEVEL 0U +#define USBD_DEBUG_LEVEL 0U /*---------- -----------*/ -#define USBD_LPM_ENABLED 1U +#define USBD_LPM_ENABLED 1U /*---------- -----------*/ -#define USBD_SELF_POWERED 1U +#define USBD_SELF_POWERED 1U /****************************************/ /* #define for FS and HS identification */ -#define DEVICE_FS 0 +#define DEVICE_FS 0 /** * @} @@ -89,42 +89,45 @@ /* Memory management macros */ /** Alias for memory allocation. */ -#define USBD_malloc (uint32_t *)USBD_static_malloc +#define USBD_malloc (uint32_t*)USBD_static_malloc /** Alias for memory release. */ -#define USBD_free USBD_static_free +#define USBD_free USBD_static_free /** Alias for memory set. */ -#define USBD_memset /* Not used */ +#define USBD_memset /* Not used */ /** Alias for memory copy. */ -#define USBD_memcpy /* Not used */ +#define USBD_memcpy /* Not used */ /** Alias for delay. */ -#define USBD_Delay HAL_Delay +#define USBD_Delay HAL_Delay /* DEBUG macros */ -#if (USBD_DEBUG_LEVEL > 0) -#define USBD_UsrLog(...) printf(__VA_ARGS__);\ - printf("\n"); +#if(USBD_DEBUG_LEVEL > 0) +#define USBD_UsrLog(...) \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_UsrLog(...) #endif -#if (USBD_DEBUG_LEVEL > 1) +#if(USBD_DEBUG_LEVEL > 1) -#define USBD_ErrLog(...) printf("ERROR: ") ;\ - printf(__VA_ARGS__);\ - printf("\n"); +#define USBD_ErrLog(...) \ + printf("ERROR: "); \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_ErrLog(...) #endif -#if (USBD_DEBUG_LEVEL > 2) -#define USBD_DbgLog(...) printf("DEBUG : ") ;\ - printf(__VA_ARGS__);\ - printf("\n"); +#if(USBD_DEBUG_LEVEL > 2) +#define USBD_DbgLog(...) \ + printf("DEBUG : "); \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_DbgLog(...) #endif @@ -148,8 +151,8 @@ */ /* Exported functions -------------------------------------------------------*/ -void *USBD_static_malloc(uint32_t size); -void USBD_static_free(void *p); +void* USBD_static_malloc(uint32_t size); +void USBD_static_free(void* p); /** * @} diff --git a/target_f1/Inc/usbd_desc.h b/target_f1/Inc/usbd_desc.h index 9e0bb00d..c5bdfe75 100644 --- a/target_f1/Inc/usbd_desc.h +++ b/target_f1/Inc/usbd_desc.h @@ -17,13 +17,13 @@ * ****************************************************************************** */ -/* USER CODE END Header */ +/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_DESC__C__ #define __USBD_DESC__C__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -41,16 +41,16 @@ * @brief Usb device descriptors module. * @{ */ - + /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants * @brief Constants. * @{ */ -#define DEVICE_ID1 (UID_BASE) -#define DEVICE_ID2 (UID_BASE + 0x4) -#define DEVICE_ID3 (UID_BASE + 0x8) +#define DEVICE_ID1 (UID_BASE) +#define DEVICE_ID2 (UID_BASE + 0x4) +#define DEVICE_ID3 (UID_BASE + 0x8) -#define USB_SIZ_STRING_SERIAL 0x1A +#define USB_SIZ_STRING_SERIAL 0x1A /* USER CODE BEGIN EXPORTED_CONSTANTS */ diff --git a/target_f1/Src/flipper_hal.c b/target_f1/Src/flipper_hal.c index f1bccde1..ba9f4673 100644 --- a/target_f1/Src/flipper_hal.c +++ b/target_f1/Src/flipper_hal.c @@ -15,18 +15,18 @@ void app_gpio_init(GpioPin gpio, GpioMode mode) { GPIO_InitStruct.Pull = GPIO_NOPULL; switch(mode) { - case GpioModeInput: - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + case GpioModeInput: + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; break; - case GpioModeOutput: - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + case GpioModeOutput: + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; break; - case GpioModeOpenDrain: - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + case GpioModeOpenDrain: + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; break; } @@ -36,20 +36,21 @@ void app_gpio_init(GpioPin gpio, GpioMode mode) { // TODO delay from timer void delay_us(uint32_t time) { - time *= 11.8; + time *= 11.8; - while(time--) {} + while(time--) { + } } void pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) { tim->Init.CounterMode = TIM_COUNTERMODE_UP; - tim->Init.Period = (uint32_t)((SystemCoreClock/tim->Init.Prescaler)/freq); + tim->Init.Period = (uint32_t)((SystemCoreClock / tim->Init.Prescaler) / freq); tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; HAL_TIM_PWM_Init(tim); TIM_OC_InitTypeDef sConfigOC; - + sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = (uint16_t)(291 * value); sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; diff --git a/target_f1/Src/freertos.c b/target_f1/Src/freertos.c index b8fe8631..a62f690e 100644 --- a/target_f1/Src/freertos.c +++ b/target_f1/Src/freertos.c @@ -24,7 +24,7 @@ #include "main.h" /* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ +/* USER CODE BEGIN Includes */ #include /* USER CODE END Includes */ @@ -51,22 +51,25 @@ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ - + /* 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 ) -{ - /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set +__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 to block in any way (for example, call xQueueReceive() with a block time @@ -81,27 +84,29 @@ __weak void vApplicationIdleHook( void ) /* USER CODE BEGIN GET_IDLE_TASK_MEMORY */ static StaticTask_t xIdleTaskTCBBuffer; static StackType_t xIdleStack[configMINIMAL_STACK_SIZE]; - -void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) -{ - *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; - *ppxIdleTaskStackBuffer = &xIdleStack[0]; - *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; - /* place for user code */ -} + +void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer, + StackType_t** ppxIdleTaskStackBuffer, + uint32_t* pulIdleTaskStackSize) { + *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; + *ppxIdleTaskStackBuffer = &xIdleStack[0]; + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; + /* place for user code */ +} /* USER CODE END GET_IDLE_TASK_MEMORY */ /* USER CODE BEGIN GET_TIMER_TASK_MEMORY */ static StaticTask_t xTimerTaskTCBBuffer; static StackType_t xTimerStack[configTIMER_TASK_STACK_DEPTH]; - -void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) -{ - *ppxTimerTaskTCBBuffer = &xTimerTaskTCBBuffer; - *ppxTimerTaskStackBuffer = &xTimerStack[0]; - *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; - /* place for user code */ -} + +void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer, + StackType_t** ppxTimerTaskStackBuffer, + uint32_t* pulTimerTaskStackSize) { + *ppxTimerTaskTCBBuffer = &xTimerTaskTCBBuffer; + *ppxTimerTaskStackBuffer = &xTimerStack[0]; + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; + /* place for user code */ +} /* USER CODE END GET_TIMER_TASK_MEMORY */ /* Private application code --------------------------------------------------*/ @@ -111,7 +116,7 @@ bool task_equal(TaskHandle_t a, TaskHandle_t b) { return a == b; } - + /* USER CODE END Application */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/target_f1/Src/main.c b/target_f1/Src/main.c index ec16554f..9378d222 100644 --- a/target_f1/Src/main.c +++ b/target_f1/Src/main.c @@ -75,7 +75,7 @@ static void MX_TIM5_Init(void); static void MX_TIM15_Init(void); static void MX_USART1_UART_Init(void); static void MX_TIM8_Init(void); -void StartDefaultTask(void const * argument); +void StartDefaultTask(void const* argument); /* USER CODE BEGIN PFP */ @@ -90,145 +90,137 @@ void StartDefaultTask(void const * argument); * @brief The application entry point. * @retval int */ -int main(void) -{ - /* USER CODE BEGIN 1 */ +int main(void) { + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ - + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_SPI1_Init(); - MX_SPI3_Init(); - MX_ADC1_Init(); - MX_COMP1_Init(); - MX_DAC1_Init(); - MX_TIM5_Init(); - MX_TIM15_Init(); - MX_USART1_UART_Init(); - MX_TIM8_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_SPI1_Init(); + MX_SPI3_Init(); + MX_ADC1_Init(); + MX_COMP1_Init(); + MX_DAC1_Init(); + MX_TIM5_Init(); + MX_TIM15_Init(); + MX_USART1_UART_Init(); + MX_TIM8_Init(); + /* USER CODE BEGIN 2 */ - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* USER CODE BEGIN RTOS_MUTEX */ - /* add mutexes, ... */ - /* USER CODE END RTOS_MUTEX */ + /* USER CODE BEGIN RTOS_MUTEX */ + /* add mutexes, ... */ + /* USER CODE END RTOS_MUTEX */ - /* USER CODE BEGIN RTOS_SEMAPHORES */ - /* add semaphores, ... */ - /* USER CODE END RTOS_SEMAPHORES */ + /* USER CODE BEGIN RTOS_SEMAPHORES */ + /* add semaphores, ... */ + /* USER CODE END RTOS_SEMAPHORES */ - /* USER CODE BEGIN RTOS_TIMERS */ - /* start timers, add new ones, ... */ - /* USER CODE END RTOS_TIMERS */ + /* USER CODE BEGIN RTOS_TIMERS */ + /* start timers, add new ones, ... */ + /* USER CODE END RTOS_TIMERS */ - /* USER CODE BEGIN RTOS_QUEUES */ - /* add queues, ... */ - /* USER CODE END RTOS_QUEUES */ + /* USER CODE BEGIN RTOS_QUEUES */ + /* add queues, ... */ + /* USER CODE END RTOS_QUEUES */ - /* Create the thread(s) */ - /* definition and creation of defaultTask */ - osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 1024); - defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); + /* Create the thread(s) */ + /* definition and creation of defaultTask */ + osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 1024); + defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); - /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ - /* USER CODE END RTOS_THREADS */ + /* USER CODE BEGIN RTOS_THREADS */ + /* add threads, ... */ + /* USER CODE END RTOS_THREADS */ - /* Start scheduler */ - osKernelStart(); - - /* We should never get here as control is now taken by the scheduler */ + /* Start scheduler */ + osKernelStart(); - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - /* USER CODE END WHILE */ + /* We should never get here as control is now taken by the scheduler */ - /* USER CODE BEGIN 3 */ - } - /* USER CODE END 3 */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while(1) { + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + } + /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; +void SystemClock_Config(void) { + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - /** Initializes the CPU, AHB and APB busses clocks + /** Initializes the CPU, AHB and APB busses clocks */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 2; - RCC_OscInitStruct.PLL.PLLN = 16; - 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) - { - Error_Handler(); - } - /** Initializes the CPU, AHB and APB busses clocks + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 2; + RCC_OscInitStruct.PLL.PLLN = 16; + 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) { + 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.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + 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) - { - Error_Handler(); - } - 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; - PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE; - PeriphClkInit.PLLSAI1.PLLSAI1M = 2; - PeriphClkInit.PLLSAI1.PLLSAI1N = 12; - PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7; - 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) - { - Error_Handler(); - } - /** Configure the main internal regulator output voltage + 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.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2; + PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1; + PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE; + PeriphClkInit.PLLSAI1.PLLSAI1M = 2; + PeriphClkInit.PLLSAI1.PLLSAI1N = 12; + PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7; + 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) { + Error_Handler(); + } + /** Configure the main internal regulator output voltage */ - if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) - { - Error_Handler(); - } + if(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) { + Error_Handler(); + } } /** @@ -236,63 +228,57 @@ 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 BEGIN ADC1_Init 0 */ + /* USER CODE END ADC1_Init 0 */ - /* USER CODE END ADC1_Init 0 */ + ADC_MultiModeTypeDef multimode = {0}; + ADC_ChannelConfTypeDef sConfig = {0}; - ADC_MultiModeTypeDef multimode = {0}; - ADC_ChannelConfTypeDef sConfig = {0}; + /* USER CODE BEGIN ADC1_Init 1 */ - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - /** Common config + /* USER CODE END ADC1_Init 1 */ + /** Common config */ - hadc1.Instance = ADC1; - hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; - hadc1.Init.Resolution = ADC_RESOLUTION_12B; - hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; - hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; - hadc1.Init.LowPowerAutoWait = DISABLE; - hadc1.Init.ContinuousConvMode = DISABLE; - hadc1.Init.NbrOfConversion = 1; - hadc1.Init.DiscontinuousConvMode = DISABLE; - hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; - hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; - hadc1.Init.DMAContinuousRequests = DISABLE; - hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; - hadc1.Init.OversamplingMode = DISABLE; - if (HAL_ADC_Init(&hadc1) != HAL_OK) - { - Error_Handler(); - } - /** Configure the ADC multi-mode + hadc1.Instance = ADC1; + hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; + hadc1.Init.Resolution = ADC_RESOLUTION_12B; + hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; + hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + hadc1.Init.LowPowerAutoWait = DISABLE; + hadc1.Init.ContinuousConvMode = DISABLE; + hadc1.Init.NbrOfConversion = 1; + hadc1.Init.DiscontinuousConvMode = DISABLE; + hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc1.Init.DMAContinuousRequests = DISABLE; + hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; + hadc1.Init.OversamplingMode = DISABLE; + 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) - { - Error_Handler(); - } - /** Configure Regular Channel + multimode.Mode = ADC_MODE_INDEPENDENT; + if(HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) { + Error_Handler(); + } + /** Configure Regular Channel */ - sConfig.Channel = ADC_CHANNEL_4; - sConfig.Rank = ADC_REGULAR_RANK_1; - sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5; - sConfig.SingleDiff = ADC_SINGLE_ENDED; - sConfig.OffsetNumber = ADC_OFFSET_NONE; - sConfig.Offset = 0; - if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ + sConfig.Channel = ADC_CHANNEL_4; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5; + sConfig.SingleDiff = ADC_SINGLE_ENDED; + sConfig.OffsetNumber = ADC_OFFSET_NONE; + sConfig.Offset = 0; + if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN ADC1_Init 2 */ + /* USER CODE END ADC1_Init 2 */ } /** @@ -300,33 +286,29 @@ 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 BEGIN COMP1_Init 0 */ + /* USER CODE END COMP1_Init 0 */ - /* USER CODE END COMP1_Init 0 */ + /* USER CODE BEGIN COMP1_Init 1 */ - /* USER CODE BEGIN COMP1_Init 1 */ - - /* USER CODE END COMP1_Init 1 */ - hcomp1.Instance = COMP1; - hcomp1.Init.InvertingInput = COMP_INPUT_MINUS_DAC1_CH1; - hcomp1.Init.NonInvertingInput = COMP_INPUT_PLUS_IO1; - hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; - hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE; - hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN COMP1_Init 2 */ - - /* USER CODE END COMP1_Init 2 */ + /* USER CODE END COMP1_Init 1 */ + hcomp1.Instance = COMP1; + hcomp1.Init.InvertingInput = COMP_INPUT_MINUS_DAC1_CH1; + hcomp1.Init.NonInvertingInput = COMP_INPUT_PLUS_IO1; + hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; + hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE; + hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN COMP1_Init 2 */ + /* USER CODE END COMP1_Init 2 */ } /** @@ -334,40 +316,35 @@ 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 BEGIN DAC1_Init 0 */ + /* USER CODE END DAC1_Init 0 */ - /* USER CODE END DAC1_Init 0 */ + DAC_ChannelConfTypeDef sConfig = {0}; - DAC_ChannelConfTypeDef sConfig = {0}; + /* USER CODE BEGIN DAC1_Init 1 */ - /* USER CODE BEGIN DAC1_Init 1 */ - - /* USER CODE END DAC1_Init 1 */ - /** DAC Initialization + /* USER CODE END DAC1_Init 1 */ + /** DAC Initialization */ - hdac1.Instance = DAC1; - if (HAL_DAC_Init(&hdac1) != HAL_OK) - { - Error_Handler(); - } - /** DAC channel OUT1 config + hdac1.Instance = DAC1; + if(HAL_DAC_Init(&hdac1) != HAL_OK) { + Error_Handler(); + } + /** DAC channel OUT1 config */ - sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE; - sConfig.DAC_Trigger = DAC_TRIGGER_NONE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN DAC1_Init 2 */ - - /* USER CODE END DAC1_Init 2 */ + sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE; + sConfig.DAC_Trigger = DAC_TRIGGER_NONE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN DAC1_Init 2 */ + /* USER CODE END DAC1_Init 2 */ } /** @@ -375,39 +352,35 @@ 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 BEGIN SPI1_Init 0 */ + /* USER CODE END SPI1_Init 0 */ - /* USER CODE END SPI1_Init 0 */ + /* USER CODE BEGIN SPI1_Init 1 */ - /* USER CODE BEGIN SPI1_Init 1 */ - - /* USER CODE END SPI1_Init 1 */ - /* SPI1 parameter configuration*/ - hspi1.Instance = SPI1; - hspi1.Init.Mode = SPI_MODE_MASTER; - hspi1.Init.Direction = SPI_DIRECTION_2LINES; - hspi1.Init.DataSize = SPI_DATASIZE_8BIT; - hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi1.Init.NSS = SPI_NSS_SOFT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; - hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi1.Init.TIMode = SPI_TIMODE_DISABLE; - hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN SPI1_Init 2 */ - - /* USER CODE END SPI1_Init 2 */ + /* USER CODE END SPI1_Init 1 */ + /* SPI1 parameter configuration*/ + hspi1.Instance = SPI1; + hspi1.Init.Mode = SPI_MODE_MASTER; + hspi1.Init.Direction = SPI_DIRECTION_2LINES; + hspi1.Init.DataSize = SPI_DATASIZE_8BIT; + hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi1.Init.NSS = SPI_NSS_SOFT; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; + hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi1.Init.TIMode = SPI_TIMODE_DISABLE; + hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN SPI1_Init 2 */ + /* USER CODE END SPI1_Init 2 */ } /** @@ -415,39 +388,35 @@ 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 BEGIN SPI3_Init 0 */ + /* USER CODE END SPI3_Init 0 */ - /* USER CODE END SPI3_Init 0 */ + /* USER CODE BEGIN SPI3_Init 1 */ - /* USER CODE BEGIN SPI3_Init 1 */ - - /* USER CODE END SPI3_Init 1 */ - /* SPI3 parameter configuration*/ - hspi3.Instance = SPI3; - hspi3.Init.Mode = SPI_MODE_MASTER; - hspi3.Init.Direction = SPI_DIRECTION_2LINES; - hspi3.Init.DataSize = SPI_DATASIZE_8BIT; - hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi3.Init.NSS = SPI_NSS_SOFT; - hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; - hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi3.Init.TIMode = SPI_TIMODE_DISABLE; - hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN SPI3_Init 2 */ - - /* USER CODE END SPI3_Init 2 */ + /* USER CODE END SPI3_Init 1 */ + /* SPI3 parameter configuration*/ + hspi3.Instance = SPI3; + hspi3.Init.Mode = SPI_MODE_MASTER; + hspi3.Init.Direction = SPI_DIRECTION_2LINES; + hspi3.Init.DataSize = SPI_DATASIZE_8BIT; + hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi3.Init.NSS = SPI_NSS_SOFT; + hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; + hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi3.Init.TIMode = SPI_TIMODE_DISABLE; + hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN SPI3_Init 2 */ + /* USER CODE END SPI3_Init 2 */ } /** @@ -455,48 +424,42 @@ 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 BEGIN TIM5_Init 0 */ + /* USER CODE END TIM5_Init 0 */ - /* USER CODE END TIM5_Init 0 */ + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_OC_InitTypeDef sConfigOC = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_OC_InitTypeDef sConfigOC = {0}; + /* USER CODE BEGIN TIM5_Init 1 */ - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 500 - 1; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - 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) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ - - /* USER CODE END TIM5_Init 2 */ - HAL_TIM_MspPostInit(&htim5); + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 500 - 1; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + 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) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + HAL_TIM_MspPostInit(&htim5); } /** @@ -504,59 +467,51 @@ 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 BEGIN TIM8_Init 0 */ + /* USER CODE END TIM8_Init 0 */ - /* USER CODE END TIM8_Init 0 */ + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_IC_InitTypeDef sConfigIC = {0}; - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_IC_InitTypeDef sConfigIC = {0}; + /* USER CODE BEGIN TIM8_Init 1 */ - /* USER CODE BEGIN TIM8_Init 1 */ - - /* USER CODE END TIM8_Init 1 */ - htim8.Instance = TIM8; - htim8.Init.Prescaler = 64-1; - htim8.Init.CounterMode = TIM_COUNTERMODE_UP; - htim8.Init.Period = 32768-1; - 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) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - 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) - { - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM8_Init 2 */ - - /* USER CODE END TIM8_Init 2 */ + /* USER CODE END TIM8_Init 1 */ + htim8.Instance = TIM8; + htim8.Init.Prescaler = 64 - 1; + htim8.Init.CounterMode = TIM_COUNTERMODE_UP; + htim8.Init.Period = 32768 - 1; + 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) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if(HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + 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) { + 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) { + Error_Handler(); + } + /* USER CODE BEGIN TIM8_Init 2 */ + /* USER CODE END TIM8_Init 2 */ } /** @@ -564,68 +519,60 @@ 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 BEGIN TIM15_Init 0 */ + /* USER CODE END TIM15_Init 0 */ - /* USER CODE END TIM15_Init 0 */ + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_OC_InitTypeDef sConfigOC = {0}; + TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_OC_InitTypeDef sConfigOC = {0}; - TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; + /* USER CODE BEGIN TIM15_Init 1 */ - /* USER CODE BEGIN TIM15_Init 1 */ - - /* USER CODE END TIM15_Init 1 */ - htim15.Instance = TIM15; - htim15.Init.Prescaler = 0; - htim15.Init.CounterMode = TIM_COUNTERMODE_UP; - htim15.Init.Period = 0; - 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) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - sConfigOC.OCMode = TIM_OCMODE_TIMING; - sConfigOC.Pulse = 0; - sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; - 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) - { - Error_Handler(); - } - if (HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) - { - Error_Handler(); - } - sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; - sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; - sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; - sBreakDeadTimeConfig.DeadTime = 0; - sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; - sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; - sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; - 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); + /* USER CODE END TIM15_Init 1 */ + htim15.Instance = TIM15; + htim15.Init.Prescaler = 0; + htim15.Init.CounterMode = TIM_COUNTERMODE_UP; + htim15.Init.Period = 0; + 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) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if(HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + sConfigOC.OCMode = TIM_OCMODE_TIMING; + sConfigOC.Pulse = 0; + sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; + sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; + 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) { + Error_Handler(); + } + if(HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) { + Error_Handler(); + } + sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; + sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; + sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; + sBreakDeadTimeConfig.DeadTime = 0; + sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; + sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; + sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; + 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,34 +580,30 @@ 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 BEGIN USART1_Init 0 */ + /* USER CODE END USART1_Init 0 */ - /* USER CODE END USART1_Init 0 */ + /* USER CODE BEGIN USART1_Init 1 */ - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - huart1.Instance = USART1; - huart1.Init.BaudRate = 115200; - huart1.Init.WordLength = UART_WORDLENGTH_8B; - huart1.Init.StopBits = UART_STOPBITS_1; - huart1.Init.Parity = UART_PARITY_NONE; - huart1.Init.Mode = UART_MODE_TX_RX; - huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ + /* USER CODE END USART1_Init 1 */ + huart1.Instance = USART1; + huart1.Init.BaudRate = 115200; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN USART1_Init 2 */ + /* USER CODE END USART1_Init 2 */ } /** @@ -668,137 +611,135 @@ static void MX_USART1_UART_Init(void) * @param None * @retval None */ -static void MX_GPIO_Init(void) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; +static void MX_GPIO_Init(void) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOH_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOA, DISPLAY_DI_Pin|CC1101_CS_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOA, DISPLAY_DI_Pin | CC1101_CS_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, LED_BLUE_Pin|LED_GREEN_Pin, GPIO_PIN_SET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, LED_BLUE_Pin | LED_GREEN_Pin, GPIO_PIN_SET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, DISPLAY_RST_Pin|IR_TX_Pin|DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, DISPLAY_RST_Pin | IR_TX_Pin | DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, VIBRO_Pin|DISPLAY_CS_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOC, VIBRO_Pin | DISPLAY_CS_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET); - /*Configure GPIO pins : PC13 PC0 PC1 PC9 */ - GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_9; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + /*Configure GPIO pins : PC13 PC0 PC1 PC9 */ + GPIO_InitStruct.Pin = GPIO_PIN_13 | GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - /*Configure GPIO pin : CHRG_Pin */ - GPIO_InitStruct.Pin = CHRG_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(CHRG_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : CHRG_Pin */ + GPIO_InitStruct.Pin = CHRG_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLUP; + HAL_GPIO_Init(CHRG_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pins : BUTTON_DOWN_Pin BUTTON_BACK_Pin */ - GPIO_InitStruct.Pin = BUTTON_DOWN_Pin|BUTTON_BACK_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /*Configure GPIO pins : BUTTON_DOWN_Pin BUTTON_BACK_Pin */ + GPIO_InitStruct.Pin = BUTTON_DOWN_Pin | BUTTON_BACK_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /*Configure GPIO pins : DISPLAY_DI_Pin CC1101_CS_Pin */ - GPIO_InitStruct.Pin = DISPLAY_DI_Pin|CC1101_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /*Configure GPIO pins : DISPLAY_DI_Pin CC1101_CS_Pin */ + GPIO_InitStruct.Pin = DISPLAY_DI_Pin | CC1101_CS_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /*Configure GPIO pins : PA5 PA7 */ - GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /*Configure GPIO pins : PA5 PA7 */ + GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /*Configure GPIO pins : BUTTON_UP_Pin BUTTON_RIGHT_Pin BUTTON_OK_Pin */ - GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_RIGHT_Pin|BUTTON_OK_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pins : BUTTON_UP_Pin BUTTON_RIGHT_Pin BUTTON_OK_Pin */ + GPIO_InitStruct.Pin = BUTTON_UP_Pin | BUTTON_RIGHT_Pin | BUTTON_OK_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pins : LED_BLUE_Pin LED_GREEN_Pin */ - GPIO_InitStruct.Pin = LED_BLUE_Pin|LED_GREEN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pins : LED_BLUE_Pin LED_GREEN_Pin */ + GPIO_InitStruct.Pin = LED_BLUE_Pin | LED_GREEN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pins : PB2 PB12 */ - GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pins : PB2 PB12 */ + GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pins : DISPLAY_RST_Pin IR_TX_Pin DISPLAY_BACKLIGHT_Pin */ - GPIO_InitStruct.Pin = DISPLAY_RST_Pin|IR_TX_Pin|DISPLAY_BACKLIGHT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pins : DISPLAY_RST_Pin IR_TX_Pin DISPLAY_BACKLIGHT_Pin */ + GPIO_InitStruct.Pin = DISPLAY_RST_Pin | IR_TX_Pin | DISPLAY_BACKLIGHT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pins : VIBRO_Pin DISPLAY_CS_Pin */ - GPIO_InitStruct.Pin = VIBRO_Pin|DISPLAY_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + /*Configure GPIO pins : VIBRO_Pin DISPLAY_CS_Pin */ + GPIO_InitStruct.Pin = VIBRO_Pin | DISPLAY_CS_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - /*Configure GPIO pin : LED_RED_Pin */ - GPIO_InitStruct.Pin = LED_RED_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; - HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : LED_RED_Pin */ + GPIO_InitStruct.Pin = LED_RED_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pin : PD2 */ - GPIO_InitStruct.Pin = GPIO_PIN_2; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + /*Configure GPIO pin : PD2 */ + GPIO_InitStruct.Pin = GPIO_PIN_2; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - /*Configure GPIO pin : BUTTON_LEFT_Pin */ - GPIO_InitStruct.Pin = BUTTON_LEFT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - HAL_GPIO_Init(BUTTON_LEFT_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : BUTTON_LEFT_Pin */ + GPIO_InitStruct.Pin = BUTTON_LEFT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(BUTTON_LEFT_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pin : CC1101_G0_Pin */ - GPIO_InitStruct.Pin = CC1101_G0_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : CC1101_G0_Pin */ + GPIO_InitStruct.Pin = CC1101_G0_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct); - /* EXTI interrupt init*/ - HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI0_IRQn); + /* EXTI interrupt init*/ + HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI0_IRQn); - HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI1_IRQn); + HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI1_IRQn); - HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI2_IRQn); + HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI2_IRQn); - HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI4_IRQn); - - HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); + HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI4_IRQn); + HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); } /* USER CODE BEGIN 4 */ @@ -812,34 +753,31 @@ void app(); * @retval None */ /* USER CODE END Header_StartDefaultTask */ -void StartDefaultTask(void const * argument) -{ - /* init code for USB_DEVICE */ - MX_USB_DEVICE_Init(); - /* USER CODE BEGIN 5 */ - /* Infinite loop */ - app(); - - for(;;) - { - osDelay(1); - } - /* USER CODE END 5 */ +void StartDefaultTask(void const* argument) { + /* init code for USB_DEVICE */ + MX_USB_DEVICE_Init(); + /* USER CODE BEGIN 5 */ + /* Infinite loop */ + app(); + + for(;;) { + osDelay(1); + } + /* USER CODE END 5 */ } /** * @brief This function is executed in case of error occurrence. * @retval None */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ +void Error_Handler(void) { + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. @@ -847,12 +785,11 @@ void Error_Handler(void) * @param line: assert_param error line source number * @retval None */ -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, +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) */ - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/target_f1/Src/stm32l4xx_hal_msp.c b/target_f1/Src/stm32l4xx_hal_msp.c index caa08296..f1b5c1c2 100644 --- a/target_f1/Src/stm32l4xx_hal_msp.c +++ b/target_f1/Src/stm32l4xx_hal_msp.c @@ -32,7 +32,7 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN Define */ - + /* USER CODE END Define */ /* Private macro -------------------------------------------------------------*/ @@ -58,27 +58,26 @@ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ - -void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); - /** + +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim); +/** * Initializes the Global MSP. */ -void HAL_MspInit(void) -{ - /* USER CODE BEGIN MspInit 0 */ +void HAL_MspInit(void) { + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ - /* PendSV_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); + /* System interrupt init*/ + /* PendSV_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /** @@ -87,38 +86,35 @@ void HAL_MspInit(void) * @param hadc: ADC handle pointer * @retval None */ -void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hadc->Instance==ADC1) - { - /* USER CODE BEGIN ADC1_MspInit 0 */ +void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hadc->Instance == ADC1) { + /* USER CODE BEGIN ADC1_MspInit 0 */ - /* USER CODE END ADC1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_ADC_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**ADC1 GPIO Configuration + /* USER CODE END ADC1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_ADC_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**ADC1 GPIO Configuration PC3 ------> ADC1_IN4 PA0 ------> ADC1_IN5 */ - GPIO_InitStruct.Pin = BATT_V_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(BATT_V_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = BATT_V_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(BATT_V_GPIO_Port, &GPIO_InitStruct); - GPIO_InitStruct.Pin = IR_RX_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(IR_RX_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = IR_RX_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(IR_RX_GPIO_Port, &GPIO_InitStruct); - /* USER CODE BEGIN ADC1_MspInit 1 */ - - /* USER CODE END ADC1_MspInit 1 */ - } + /* USER CODE BEGIN ADC1_MspInit 1 */ + /* USER CODE END ADC1_MspInit 1 */ + } } /** @@ -127,29 +123,26 @@ 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) - { - /* USER CODE BEGIN ADC1_MspDeInit 0 */ +void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) { + if(hadc->Instance == ADC1) { + /* USER CODE BEGIN ADC1_MspDeInit 0 */ - /* USER CODE END ADC1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_ADC_CLK_DISABLE(); - - /**ADC1 GPIO Configuration + /* USER CODE END ADC1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_ADC_CLK_DISABLE(); + + /**ADC1 GPIO Configuration PC3 ------> ADC1_IN4 PA0 ------> ADC1_IN5 */ - HAL_GPIO_DeInit(BATT_V_GPIO_Port, BATT_V_Pin); + HAL_GPIO_DeInit(BATT_V_GPIO_Port, BATT_V_Pin); - HAL_GPIO_DeInit(IR_RX_GPIO_Port, IR_RX_Pin); + HAL_GPIO_DeInit(IR_RX_GPIO_Port, IR_RX_Pin); - /* USER CODE BEGIN ADC1_MspDeInit 1 */ - - /* USER CODE END ADC1_MspDeInit 1 */ - } + /* USER CODE BEGIN ADC1_MspDeInit 1 */ + /* USER CODE END ADC1_MspDeInit 1 */ + } } /** @@ -158,29 +151,26 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) * @param hcomp: COMP handle pointer * @retval None */ -void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hcomp->Instance==COMP1) - { - /* USER CODE BEGIN COMP1_MspInit 0 */ +void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hcomp->Instance == COMP1) { + /* USER CODE BEGIN COMP1_MspInit 0 */ - /* USER CODE END COMP1_MspInit 0 */ - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**COMP1 GPIO Configuration + /* USER CODE END COMP1_MspInit 0 */ + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**COMP1 GPIO Configuration PC5 ------> COMP1_INP */ - GPIO_InitStruct.Pin = RFID_RF_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = RFID_RF_IN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct); - /* USER CODE BEGIN COMP1_MspInit 1 */ - - /* USER CODE END COMP1_MspInit 1 */ - } + /* USER CODE BEGIN COMP1_MspInit 1 */ + /* USER CODE END COMP1_MspInit 1 */ + } } /** @@ -189,24 +179,21 @@ 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) - { - /* USER CODE BEGIN COMP1_MspDeInit 0 */ +void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp) { + if(hcomp->Instance == COMP1) { + /* USER CODE BEGIN COMP1_MspDeInit 0 */ - /* USER CODE END COMP1_MspDeInit 0 */ - - /**COMP1 GPIO Configuration + /* USER CODE END COMP1_MspDeInit 0 */ + + /**COMP1 GPIO Configuration PC5 ------> COMP1_INP */ - HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin); + HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin); - /* USER CODE BEGIN COMP1_MspDeInit 1 */ - - /* USER CODE END COMP1_MspDeInit 1 */ - } + /* USER CODE BEGIN COMP1_MspDeInit 1 */ + /* USER CODE END COMP1_MspDeInit 1 */ + } } /** @@ -215,31 +202,28 @@ void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp) * @param hdac: DAC handle pointer * @retval None */ -void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hdac->Instance==DAC1) - { - /* USER CODE BEGIN DAC1_MspInit 0 */ +void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hdac->Instance == DAC1) { + /* USER CODE BEGIN DAC1_MspInit 0 */ - /* USER CODE END DAC1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_DAC1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**DAC1 GPIO Configuration + /* USER CODE END DAC1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_DAC1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**DAC1 GPIO Configuration PA4 ------> DAC1_OUT1 */ - GPIO_InitStruct.Pin = RFID_REF_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(RFID_REF_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = RFID_REF_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(RFID_REF_GPIO_Port, &GPIO_InitStruct); - /* USER CODE BEGIN DAC1_MspInit 1 */ - - /* USER CODE END DAC1_MspInit 1 */ - } + /* USER CODE BEGIN DAC1_MspInit 1 */ + /* USER CODE END DAC1_MspInit 1 */ + } } /** @@ -248,26 +232,23 @@ 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) - { - /* USER CODE BEGIN DAC1_MspDeInit 0 */ +void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac) { + if(hdac->Instance == DAC1) { + /* USER CODE BEGIN DAC1_MspDeInit 0 */ - /* USER CODE END DAC1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_DAC1_CLK_DISABLE(); - - /**DAC1 GPIO Configuration + /* USER CODE END DAC1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_DAC1_CLK_DISABLE(); + + /**DAC1 GPIO Configuration PA4 ------> DAC1_OUT1 */ - HAL_GPIO_DeInit(RFID_REF_GPIO_Port, RFID_REF_Pin); + HAL_GPIO_DeInit(RFID_REF_GPIO_Port, RFID_REF_Pin); - /* USER CODE BEGIN DAC1_MspDeInit 1 */ - - /* USER CODE END DAC1_MspDeInit 1 */ - } + /* USER CODE BEGIN DAC1_MspDeInit 1 */ + /* USER CODE END DAC1_MspDeInit 1 */ + } } /** @@ -276,59 +257,54 @@ void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac) * @param hspi: SPI handle pointer * @retval None */ -void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hspi->Instance==SPI1) - { - /* USER CODE BEGIN SPI1_MspInit 0 */ +void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hspi->Instance == SPI1) { + /* USER CODE BEGIN SPI1_MspInit 0 */ - /* USER CODE END SPI1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_SPI1_CLK_ENABLE(); - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**SPI1 GPIO Configuration + /* USER CODE END SPI1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_SPI1_CLK_ENABLE(); + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**SPI1 GPIO Configuration PB3 (JTDO-TRACESWO) ------> SPI1_SCK PB5 ------> SPI1_MOSI */ - GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_5; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_3 | GPIO_PIN_5; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /* USER CODE BEGIN SPI1_MspInit 1 */ + /* USER CODE BEGIN SPI1_MspInit 1 */ - /* USER CODE END SPI1_MspInit 1 */ - } - else if(hspi->Instance==SPI3) - { - /* USER CODE BEGIN SPI3_MspInit 0 */ + /* USER CODE END SPI1_MspInit 1 */ + } else if(hspi->Instance == SPI3) { + /* USER CODE BEGIN SPI3_MspInit 0 */ - /* USER CODE END SPI3_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_SPI3_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**SPI3 GPIO Configuration + /* USER CODE END SPI3_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_SPI3_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**SPI3 GPIO Configuration PC10 ------> SPI3_SCK PC11 ------> SPI3_MISO PC12 ------> SPI3_MOSI */ - GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - /* USER CODE BEGIN SPI3_MspInit 1 */ - - /* USER CODE END SPI3_MspInit 1 */ - } + /* USER CODE BEGIN SPI3_MspInit 1 */ + /* USER CODE END SPI3_MspInit 1 */ + } } /** @@ -337,46 +313,41 @@ 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) - { - /* USER CODE BEGIN SPI1_MspDeInit 0 */ +void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) { + if(hspi->Instance == SPI1) { + /* USER CODE BEGIN SPI1_MspDeInit 0 */ - /* USER CODE END SPI1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI1_CLK_DISABLE(); - - /**SPI1 GPIO Configuration + /* USER CODE END SPI1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI1_CLK_DISABLE(); + + /**SPI1 GPIO Configuration PB3 (JTDO-TRACESWO) ------> SPI1_SCK PB5 ------> SPI1_MOSI */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_5); + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3 | GPIO_PIN_5); - /* USER CODE BEGIN SPI1_MspDeInit 1 */ + /* USER CODE BEGIN SPI1_MspDeInit 1 */ - /* USER CODE END SPI1_MspDeInit 1 */ - } - else if(hspi->Instance==SPI3) - { - /* USER CODE BEGIN SPI3_MspDeInit 0 */ + /* USER CODE END SPI1_MspDeInit 1 */ + } else if(hspi->Instance == SPI3) { + /* USER CODE BEGIN SPI3_MspDeInit 0 */ - /* USER CODE END SPI3_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI3_CLK_DISABLE(); - - /**SPI3 GPIO Configuration + /* USER CODE END SPI3_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI3_CLK_DISABLE(); + + /**SPI3 GPIO Configuration PC10 ------> SPI3_SCK PC11 ------> SPI3_MISO PC12 ------> SPI3_MOSI */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12); - /* USER CODE BEGIN SPI3_MspDeInit 1 */ - - /* USER CODE END SPI3_MspDeInit 1 */ - } + /* USER CODE BEGIN SPI3_MspDeInit 1 */ + /* USER CODE END SPI3_MspDeInit 1 */ + } } /** @@ -385,20 +356,17 @@ 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) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ +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 */ - /* Peripheral clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); - /* USER CODE BEGIN TIM5_MspInit 1 */ - - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE BEGIN TIM5_MspInit 1 */ + /* USER CODE END TIM5_MspInit 1 */ + } } /** @@ -407,36 +375,33 @@ 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) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(htim_base->Instance==TIM8) - { - /* USER CODE BEGIN TIM8_MspInit 0 */ +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(htim_base->Instance == TIM8) { + /* USER CODE BEGIN TIM8_MspInit 0 */ - /* USER CODE END TIM8_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_TIM8_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**TIM8 GPIO Configuration + /* USER CODE END TIM8_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM8_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**TIM8 GPIO Configuration PC7 ------> TIM8_CH2 */ - GPIO_InitStruct.Pin = iButton_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; - GPIO_InitStruct.Alternate = GPIO_AF3_TIM8; - HAL_GPIO_Init(iButton_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = iButton_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + GPIO_InitStruct.Alternate = GPIO_AF3_TIM8; + HAL_GPIO_Init(iButton_GPIO_Port, &GPIO_InitStruct); - /* TIM8 interrupt Init */ - HAL_NVIC_SetPriority(TIM8_CC_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(TIM8_CC_IRQn); - /* USER CODE BEGIN TIM8_MspInit 1 */ - - /* USER CODE END TIM8_MspInit 1 */ - } + /* TIM8 interrupt Init */ + HAL_NVIC_SetPriority(TIM8_CC_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(TIM8_CC_IRQn); + /* USER CODE BEGIN TIM8_MspInit 1 */ + /* USER CODE END TIM8_MspInit 1 */ + } } /** @@ -445,68 +410,60 @@ 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) - { - /* USER CODE BEGIN TIM15_MspInit 0 */ +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 */ - /* Peripheral clock enable */ - __HAL_RCC_TIM15_CLK_ENABLE(); - /* USER CODE BEGIN TIM15_MspInit 1 */ - - /* USER CODE END TIM15_MspInit 1 */ - } + /* USER CODE END TIM15_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM15_CLK_ENABLE(); + /* USER CODE BEGIN TIM15_MspInit 1 */ + /* USER CODE END TIM15_MspInit 1 */ + } } -void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(htim->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspPostInit 0 */ +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(htim->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspPostInit 0 */ - /* USER CODE END TIM5_MspPostInit 0 */ - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**TIM5 GPIO Configuration + /* USER CODE END TIM5_MspPostInit 0 */ + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**TIM5 GPIO Configuration PA3 ------> TIM5_CH4 */ - GPIO_InitStruct.Pin = SPEAKER_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF2_TIM5; - HAL_GPIO_Init(SPEAKER_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = SPEAKER_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF2_TIM5; + HAL_GPIO_Init(SPEAKER_GPIO_Port, &GPIO_InitStruct); - /* USER CODE BEGIN TIM5_MspPostInit 1 */ + /* USER CODE BEGIN TIM5_MspPostInit 1 */ - /* USER CODE END TIM5_MspPostInit 1 */ - } - else if(htim->Instance==TIM15) - { - /* USER CODE BEGIN TIM15_MspPostInit 0 */ + /* USER CODE END TIM5_MspPostInit 1 */ + } else if(htim->Instance == TIM15) { + /* USER CODE BEGIN TIM15_MspPostInit 0 */ - /* USER CODE END TIM15_MspPostInit 0 */ - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**TIM15 GPIO Configuration + /* USER CODE END TIM15_MspPostInit 0 */ + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**TIM15 GPIO Configuration PB13 ------> TIM15_CH1N PB15 ------> TIM15_CH2 */ - GPIO_InitStruct.Pin = RFID_OUT_Pin|RFID_PULL_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF14_TIM15; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + GPIO_InitStruct.Pin = RFID_OUT_Pin | RFID_PULL_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF14_TIM15; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /* USER CODE BEGIN TIM15_MspPostInit 1 */ - - /* USER CODE END TIM15_MspPostInit 1 */ - } + /* USER CODE BEGIN TIM15_MspPostInit 1 */ + /* USER CODE END TIM15_MspPostInit 1 */ + } } /** * @brief TIM_PWM MSP De-Initialization @@ -514,20 +471,17 @@ 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) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ +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 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ - - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* USER CODE END TIM5_MspDeInit 1 */ + } } /** @@ -536,28 +490,25 @@ 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) - { - /* USER CODE BEGIN TIM8_MspDeInit 0 */ +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 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM8_CLK_DISABLE(); - - /**TIM8 GPIO Configuration + /* USER CODE END TIM8_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM8_CLK_DISABLE(); + + /**TIM8 GPIO Configuration PC7 ------> TIM8_CH2 */ - HAL_GPIO_DeInit(iButton_GPIO_Port, iButton_Pin); + HAL_GPIO_DeInit(iButton_GPIO_Port, iButton_Pin); - /* TIM8 interrupt DeInit */ - HAL_NVIC_DisableIRQ(TIM8_CC_IRQn); - /* USER CODE BEGIN TIM8_MspDeInit 1 */ - - /* USER CODE END TIM8_MspDeInit 1 */ - } + /* TIM8 interrupt DeInit */ + HAL_NVIC_DisableIRQ(TIM8_CC_IRQn); + /* USER CODE BEGIN TIM8_MspDeInit 1 */ + /* USER CODE END TIM8_MspDeInit 1 */ + } } /** @@ -566,20 +517,17 @@ 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) - { - /* USER CODE BEGIN TIM15_MspDeInit 0 */ +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 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM15_CLK_DISABLE(); - /* USER CODE BEGIN TIM15_MspDeInit 1 */ - - /* USER CODE END TIM15_MspDeInit 1 */ - } + /* USER CODE END TIM15_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM15_CLK_DISABLE(); + /* USER CODE BEGIN TIM15_MspDeInit 1 */ + /* USER CODE END TIM15_MspDeInit 1 */ + } } /** @@ -588,34 +536,31 @@ void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc) * @param huart: UART handle pointer * @retval None */ -void HAL_UART_MspInit(UART_HandleTypeDef* huart) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(huart->Instance==USART1) - { - /* USER CODE BEGIN USART1_MspInit 0 */ +void HAL_UART_MspInit(UART_HandleTypeDef* huart) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(huart->Instance == USART1) { + /* USER CODE BEGIN USART1_MspInit 0 */ - /* USER CODE END USART1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_USART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USART1 GPIO Configuration + /* USER CODE END USART1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_USART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ - GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF7_USART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF7_USART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /* USER CODE BEGIN USART1_MspInit 1 */ - - /* USER CODE END USART1_MspInit 1 */ - } + /* USER CODE BEGIN USART1_MspInit 1 */ + /* USER CODE END USART1_MspInit 1 */ + } } /** @@ -624,27 +569,24 @@ 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) - { - /* USER CODE BEGIN USART1_MspDeInit 0 */ +void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) { + if(huart->Instance == USART1) { + /* USER CODE BEGIN USART1_MspDeInit 0 */ - /* USER CODE END USART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USART1_CLK_DISABLE(); - - /**USART1 GPIO Configuration + /* USER CODE END USART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART1_CLK_DISABLE(); + + /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9 | GPIO_PIN_10); - /* USER CODE BEGIN USART1_MspDeInit 1 */ - - /* USER CODE END USART1_MspDeInit 1 */ - } + /* USER CODE BEGIN USART1_MspDeInit 1 */ + /* USER CODE END USART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ diff --git a/target_f1/Src/stm32l4xx_it.c b/target_f1/Src/stm32l4xx_it.c index 86a73024..6f86a1a7 100644 --- a/target_f1/Src/stm32l4xx_it.c +++ b/target_f1/Src/stm32l4xx_it.c @@ -34,7 +34,7 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ - + /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ @@ -65,114 +65,102 @@ extern TIM_HandleTypeDef htim8; /* USER CODE END EV */ /******************************************************************************/ -/* Cortex-M4 Processor Interruption and Exception Handlers */ +/* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** * @brief This function handles Non maskable interrupt. */ -void NMI_Handler(void) -{ - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ +void NMI_Handler(void) { + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** * @brief This function handles Hard fault interrupt. */ -void HardFault_Handler(void) -{ - /* USER CODE BEGIN HardFault_IRQn 0 */ +void HardFault_Handler(void) { + /* USER CODE BEGIN HardFault_IRQn 0 */ - /* USER CODE END HardFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_HardFault_IRQn 0 */ - /* USER CODE END W1_HardFault_IRQn 0 */ - } + /* USER CODE END HardFault_IRQn 0 */ + while(1) { + /* USER CODE BEGIN W1_HardFault_IRQn 0 */ + /* USER CODE END W1_HardFault_IRQn 0 */ + } } /** * @brief This function handles Memory management fault. */ -void MemManage_Handler(void) -{ - /* USER CODE BEGIN MemoryManagement_IRQn 0 */ +void MemManage_Handler(void) { + /* USER CODE BEGIN MemoryManagement_IRQn 0 */ - /* USER CODE END MemoryManagement_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ - /* USER CODE END W1_MemoryManagement_IRQn 0 */ - } + /* USER CODE END MemoryManagement_IRQn 0 */ + while(1) { + /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ + /* USER CODE END W1_MemoryManagement_IRQn 0 */ + } } /** * @brief This function handles Prefetch fault, memory access fault. */ -void BusFault_Handler(void) -{ - /* USER CODE BEGIN BusFault_IRQn 0 */ +void BusFault_Handler(void) { + /* USER CODE BEGIN BusFault_IRQn 0 */ - /* USER CODE END BusFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_BusFault_IRQn 0 */ - /* USER CODE END W1_BusFault_IRQn 0 */ - } + /* USER CODE END BusFault_IRQn 0 */ + while(1) { + /* USER CODE BEGIN W1_BusFault_IRQn 0 */ + /* USER CODE END W1_BusFault_IRQn 0 */ + } } /** * @brief This function handles Undefined instruction or illegal state. */ -void UsageFault_Handler(void) -{ - /* USER CODE BEGIN UsageFault_IRQn 0 */ +void UsageFault_Handler(void) { + /* USER CODE BEGIN UsageFault_IRQn 0 */ - /* USER CODE END UsageFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ - /* USER CODE END W1_UsageFault_IRQn 0 */ - } + /* USER CODE END UsageFault_IRQn 0 */ + while(1) { + /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ + /* USER CODE END W1_UsageFault_IRQn 0 */ + } } /** * @brief This function handles Debug monitor. */ -void DebugMon_Handler(void) -{ - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ +void DebugMon_Handler(void) { + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** * @brief This function handles System tick timer. */ -void SysTick_Handler(void) -{ - /* USER CODE BEGIN SysTick_IRQn 0 */ +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) - { + /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); +#if(INCLUDE_xTaskGetSchedulerState == 1) + if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { #endif /* INCLUDE_xTaskGetSchedulerState */ - xPortSysTickHandler(); -#if (INCLUDE_xTaskGetSchedulerState == 1 ) - } + xPortSysTickHandler(); +#if(INCLUDE_xTaskGetSchedulerState == 1) + } #endif /* INCLUDE_xTaskGetSchedulerState */ - /* USER CODE BEGIN SysTick_IRQn 1 */ + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -185,115 +173,105 @@ void SysTick_Handler(void) /** * @brief This function handles EXTI line0 interrupt. */ -void EXTI0_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI0_IRQn 0 */ +void EXTI0_IRQHandler(void) { + /* USER CODE BEGIN EXTI0_IRQn 0 */ - /* USER CODE END EXTI0_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); - /* USER CODE BEGIN EXTI0_IRQn 1 */ + /* USER CODE END EXTI0_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); + /* USER CODE BEGIN EXTI0_IRQn 1 */ - /* USER CODE END EXTI0_IRQn 1 */ + /* USER CODE END EXTI0_IRQn 1 */ } /** * @brief This function handles EXTI line1 interrupt. */ -void EXTI1_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI1_IRQn 0 */ +void EXTI1_IRQHandler(void) { + /* USER CODE BEGIN EXTI1_IRQn 0 */ - /* USER CODE END EXTI1_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1); - /* USER CODE BEGIN EXTI1_IRQn 1 */ + /* USER CODE END EXTI1_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1); + /* USER CODE BEGIN EXTI1_IRQn 1 */ - /* USER CODE END EXTI1_IRQn 1 */ + /* USER CODE END EXTI1_IRQn 1 */ } /** * @brief This function handles EXTI line2 interrupt. */ -void EXTI2_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI2_IRQn 0 */ +void EXTI2_IRQHandler(void) { + /* USER CODE BEGIN EXTI2_IRQn 0 */ - /* USER CODE END EXTI2_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); - /* USER CODE BEGIN EXTI2_IRQn 1 */ + /* USER CODE END EXTI2_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); + /* USER CODE BEGIN EXTI2_IRQn 1 */ - /* USER CODE END EXTI2_IRQn 1 */ + /* USER CODE END EXTI2_IRQn 1 */ } /** * @brief This function handles EXTI line4 interrupt. */ -void EXTI4_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI4_IRQn 0 */ +void EXTI4_IRQHandler(void) { + /* USER CODE BEGIN EXTI4_IRQn 0 */ - /* USER CODE END EXTI4_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4); - /* USER CODE BEGIN EXTI4_IRQn 1 */ + /* USER CODE END EXTI4_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4); + /* USER CODE BEGIN EXTI4_IRQn 1 */ - /* USER CODE END EXTI4_IRQn 1 */ + /* USER CODE END EXTI4_IRQn 1 */ } /** * @brief This function handles EXTI line[9:5] interrupts. */ -void EXTI9_5_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI9_5_IRQn 0 */ +void EXTI9_5_IRQHandler(void) { + /* USER CODE BEGIN EXTI9_5_IRQn 0 */ - /* USER CODE END EXTI9_5_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6); - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8); - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9); - /* USER CODE BEGIN EXTI9_5_IRQn 1 */ + /* USER CODE END EXTI9_5_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6); + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8); + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9); + /* USER CODE BEGIN EXTI9_5_IRQn 1 */ - /* USER CODE END EXTI9_5_IRQn 1 */ + /* USER CODE END EXTI9_5_IRQn 1 */ } -void(*tim8_callback_ch2)(uint16_t ccr, TimerEvent tim_event); +void (*tim8_callback_ch2)(uint16_t ccr, TimerEvent tim_event); -void register_tim8_callback_ch2(void(*callback)(uint16_t ccr, TimerEvent tim_event)) { - tim8_callback_ch2 = callback; +void register_tim8_callback_ch2(void (*callback)(uint16_t ccr, TimerEvent tim_event)) { + tim8_callback_ch2 = callback; } /** * @brief This function handles TIM8 capture compare interrupt. */ -void TIM8_CC_IRQHandler(void) -{ - /* USER CODE BEGIN TIM8_CC_IRQn 0 */ +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) - { - __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) - { -/* + /* 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) { + __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 (USE_HAL_TIM_REGISTER_CALLBACKS == 1) htim->IC_CaptureCallback(htim); #else HAL_TIM_IC_CaptureCallback(htim); #endif */ - if(tim8_callback_ch2 != NULL) { - tim8_callback_ch2(htim8.Instance->CCR2, TimerEventInputCapture); - } - } - /* Output compare event */ - else - { - if(tim8_callback_ch2 != NULL) { - tim8_callback_ch2(0, TimerEventEndOfPulse); - } -/* + if(tim8_callback_ch2 != NULL) { + tim8_callback_ch2(htim8.Instance->CCR2, TimerEventInputCapture); + } + } + /* Output compare event */ + else { + if(tim8_callback_ch2 != NULL) { + tim8_callback_ch2(0, TimerEventEndOfPulse); + } + /* #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) htim->OC_DelayElapsedCallback(htim); htim->PWM_PulseFinishedCallback(htim); @@ -302,31 +280,29 @@ void TIM8_CC_IRQHandler(void) HAL_TIM_PWM_PulseFinishedCallback(htim); #endif */ - } - htim8.Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; + } + htim8.Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; + } } - } + /* USER CODE END TIM8_CC_IRQn 0 */ + // HAL_TIM_IRQHandler(&htim8); + /* USER CODE BEGIN TIM8_CC_IRQn 1 */ - /* USER CODE END TIM8_CC_IRQn 0 */ - // HAL_TIM_IRQHandler(&htim8); - /* USER CODE BEGIN TIM8_CC_IRQn 1 */ - - /* USER CODE END TIM8_CC_IRQn 1 */ + /* USER CODE END TIM8_CC_IRQn 1 */ } /** * @brief This function handles USB OTG FS global interrupt. */ -void OTG_FS_IRQHandler(void) -{ - /* USER CODE BEGIN OTG_FS_IRQn 0 */ +void OTG_FS_IRQHandler(void) { + /* USER CODE BEGIN OTG_FS_IRQn 0 */ - /* USER CODE END OTG_FS_IRQn 0 */ - HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS); - /* USER CODE BEGIN OTG_FS_IRQn 1 */ + /* USER CODE END OTG_FS_IRQn 0 */ + HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS); + /* USER CODE BEGIN OTG_FS_IRQn 1 */ - /* USER CODE END OTG_FS_IRQn 1 */ + /* USER CODE END OTG_FS_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/target_f1/Src/system_stm32l4xx.c b/target_f1/Src/system_stm32l4xx.c index 1db59ec9..a16bf4c7 100644 --- a/target_f1/Src/system_stm32l4xx.c +++ b/target_f1/Src/system_stm32l4xx.c @@ -91,16 +91,16 @@ #include "stm32l4xx.h" -#if !defined (HSE_VALUE) - #define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */ +#if !defined(HSE_VALUE) +#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ -#if !defined (MSI_VALUE) - #define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/ +#if !defined(MSI_VALUE) +#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/ #endif /* MSI_VALUE */ -#if !defined (HSI_VALUE) - #define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ +#if !defined(HSI_VALUE) +#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /** @@ -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. */ /******************************************************************************/ /** @@ -141,7 +142,7 @@ /** @addtogroup STM32L4xx_System_Private_Variables * @{ */ - /* The SystemCoreClock variable is updated in three ways: +/* The SystemCoreClock variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency @@ -149,12 +150,22 @@ is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ - uint32_t SystemCoreClock = 4000000U; +uint32_t SystemCoreClock = 4000000U; - 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 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}; /** * @} */ @@ -177,37 +188,36 @@ * @retval None */ -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 */ - #endif +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 */ +#endif - /* Reset the RCC clock configuration to the default reset state ------------*/ - /* Set MSION bit */ - RCC->CR |= RCC_CR_MSION; + /* Reset the RCC clock configuration to the default reset state ------------*/ + /* Set MSION bit */ + RCC->CR |= RCC_CR_MSION; - /* Reset CFGR register */ - RCC->CFGR = 0x00000000U; + /* Reset CFGR register */ + RCC->CFGR = 0x00000000U; - /* Reset HSEON, CSSON , HSION, and PLLON bits */ - RCC->CR &= 0xEAF6FFFFU; + /* Reset HSEON, CSSON , HSION, and PLLON bits */ + RCC->CR &= 0xEAF6FFFFU; - /* Reset PLLCFGR register */ - RCC->PLLCFGR = 0x00001000U; + /* Reset PLLCFGR register */ + RCC->PLLCFGR = 0x00001000U; - /* Reset HSEBYP bit */ - RCC->CR &= 0xFFFBFFFFU; + /* Reset HSEBYP bit */ + RCC->CR &= 0xFFFBFFFFU; - /* Disable all interrupts */ - RCC->CIER = 0x00000000U; + /* Disable all interrupts */ + RCC->CIER = 0x00000000U; - /* Configure the Vector Table location add offset address ------------------*/ + /* Configure the Vector Table location add offset address ------------------*/ #ifdef VECT_TAB_SRAM - SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ + SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ #else - SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ + SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ #endif } @@ -253,75 +263,68 @@ void SystemInit(void) * @param None * @retval None */ -void SystemCoreClockUpdate(void) -{ - uint32_t tmp = 0U, msirange = 0U, pllvco = 0U, pllr = 2U, pllsource = 0U, pllm = 2U; +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 */ - msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U; - } - else - { /* MSIRANGE from RCC_CR applies */ - msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U; - } - /*MSI frequency range in HZ*/ - msirange = MSIRangeTable[msirange]; + /* Get MSI Range frequency--------------------------------------------------*/ + 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 */ + msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U; + } + /*MSI frequency range in HZ*/ + msirange = MSIRangeTable[msirange]; - /* Get SYSCLK source -------------------------------------------------------*/ - switch (RCC->CFGR & RCC_CFGR_SWS) - { - case 0x00: /* MSI used as system clock source */ - SystemCoreClock = msirange; - break; + /* Get SYSCLK source -------------------------------------------------------*/ + switch(RCC->CFGR & RCC_CFGR_SWS) { + case 0x00: /* MSI used as system clock source */ + SystemCoreClock = msirange; + break; - case 0x04: /* HSI used as system clock source */ - SystemCoreClock = HSI_VALUE; - break; + case 0x04: /* HSI used as system clock source */ + SystemCoreClock = HSI_VALUE; + break; - case 0x08: /* HSE used as system clock source */ - SystemCoreClock = HSE_VALUE; - break; + case 0x08: /* HSE used as system clock source */ + SystemCoreClock = HSE_VALUE; + break; - case 0x0C: /* PLL used as system clock source */ - /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN + case 0x0C: /* PLL used as system clock source */ + /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN SYSCLK = PLL_VCO / PLLR */ - pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); - pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U ; + pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); + pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U; - switch (pllsource) - { - case 0x02: /* HSI used as PLL clock source */ - pllvco = (HSI_VALUE / pllm); - break; + switch(pllsource) { + case 0x02: /* HSI used as PLL clock source */ + pllvco = (HSI_VALUE / pllm); + break; - case 0x03: /* HSE used as PLL clock source */ - pllvco = (HSE_VALUE / pllm); - break; + case 0x03: /* HSE used as PLL clock source */ + pllvco = (HSE_VALUE / pllm); + break; - default: /* MSI used as PLL clock source */ - pllvco = (msirange / pllm); - break; - } - pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U); - pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U; - SystemCoreClock = pllvco/pllr; - break; + default: /* MSI used as PLL clock source */ + pllvco = (msirange / pllm); + break; + } + pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U); + pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U; + SystemCoreClock = pllvco / pllr; + break; default: - SystemCoreClock = msirange; - break; - } - /* Compute HCLK clock frequency --------------------------------------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; - /* HCLK clock frequency */ - SystemCoreClock >>= tmp; + SystemCoreClock = msirange; + break; + } + /* Compute HCLK clock frequency --------------------------------------------*/ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; } - /** * @} */ diff --git a/target_f1/Src/usb_device.c b/target_f1/Src/usb_device.c index d34e67a1..3f9b99ee 100644 --- a/target_f1/Src/usb_device.c +++ b/target_f1/Src/usb_device.c @@ -63,32 +63,27 @@ extern USBD_DescriptorsTypeDef FS_Desc; * Init USB device Library, add supported class and start the library * @retval None */ -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) - { - Error_Handler(); - } - if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) - { - Error_Handler(); - } - if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) - { - Error_Handler(); - } - if (USBD_Start(&hUsbDeviceFS) != USBD_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ - - /* USER CODE END USB_DEVICE_Init_PostTreatment */ +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) { + Error_Handler(); + } + if(USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { + Error_Handler(); + } + if(USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { + Error_Handler(); + } + if(USBD_Start(&hUsbDeviceFS) != USBD_OK) { + Error_Handler(); + } + /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ + + /* USER CODE END USB_DEVICE_Init_PostTreatment */ } /** diff --git a/target_f1/Src/usbd_cdc_if.c b/target_f1/Src/usbd_cdc_if.c index 88144eab..0e2bdf65 100644 --- a/target_f1/Src/usbd_cdc_if.c +++ b/target_f1/Src/usbd_cdc_if.c @@ -65,8 +65,8 @@ /* USER CODE BEGIN PRIVATE_DEFINES */ /* Define size for the receive and transmit buffer over CDC */ /* It's up to user to redefine and/or remove those define */ -#define APP_RX_DATA_SIZE 2048 -#define APP_TX_DATA_SIZE 2048 +#define APP_RX_DATA_SIZE 2048 +#define APP_TX_DATA_SIZE 2048 /* USER CODE END PRIVATE_DEFINES */ /** @@ -129,7 +129,7 @@ extern USBD_HandleTypeDef hUsbDeviceFS; static int8_t CDC_Init_FS(void); static int8_t CDC_DeInit_FS(void); static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); -static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); +static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t* Len); /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ @@ -139,38 +139,33 @@ static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); * @} */ -USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = -{ - CDC_Init_FS, - CDC_DeInit_FS, - CDC_Control_FS, - CDC_Receive_FS -}; +USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = {CDC_Init_FS, + CDC_DeInit_FS, + CDC_Control_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) -{ - /* USER CODE BEGIN 3 */ - /* Set Application Buffers */ - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); - return (USBD_OK); - /* USER CODE END 3 */ +static int8_t CDC_Init_FS(void) { + /* USER CODE BEGIN 3 */ + /* Set Application Buffers */ + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); + USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); + return (USBD_OK); + /* USER CODE END 3 */ } /** * @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) -{ - /* USER CODE BEGIN 4 */ - return (USBD_OK); - /* USER CODE END 4 */ +static int8_t CDC_DeInit_FS(void) { + /* USER CODE BEGIN 4 */ + return (USBD_OK); + /* USER CODE END 4 */ } /** @@ -180,70 +175,68 @@ 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) -{ - /* USER CODE BEGIN 5 */ - switch(cmd) - { +static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) { + /* USER CODE BEGIN 5 */ + switch(cmd) { case CDC_SEND_ENCAPSULATED_COMMAND: - break; + break; case CDC_GET_ENCAPSULATED_RESPONSE: - break; + break; case CDC_SET_COMM_FEATURE: - break; + break; case CDC_GET_COMM_FEATURE: - break; + break; case CDC_CLEAR_COMM_FEATURE: - break; + break; - /*******************************************************************************/ - /* Line Coding Structure */ - /*-----------------------------------------------------------------------------*/ - /* Offset | Field | Size | Value | Description */ - /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ - /* 4 | bCharFormat | 1 | Number | Stop bits */ - /* 0 - 1 Stop bit */ - /* 1 - 1.5 Stop bits */ - /* 2 - 2 Stop bits */ - /* 5 | bParityType | 1 | Number | Parity */ - /* 0 - None */ - /* 1 - Odd */ - /* 2 - Even */ - /* 3 - Mark */ - /* 4 - Space */ - /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ - /*******************************************************************************/ + /*******************************************************************************/ + /* Line Coding Structure */ + /*-----------------------------------------------------------------------------*/ + /* Offset | Field | Size | Value | Description */ + /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ + /* 4 | bCharFormat | 1 | Number | Stop bits */ + /* 0 - 1 Stop bit */ + /* 1 - 1.5 Stop bits */ + /* 2 - 2 Stop bits */ + /* 5 | bParityType | 1 | Number | Parity */ + /* 0 - None */ + /* 1 - Odd */ + /* 2 - Even */ + /* 3 - Mark */ + /* 4 - Space */ + /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ + /*******************************************************************************/ case CDC_SET_LINE_CODING: - break; + break; case CDC_GET_LINE_CODING: - break; + break; case CDC_SET_CONTROL_LINE_STATE: - break; + break; case CDC_SEND_BREAK: - break; + break; - default: - break; - } + default: + break; + } - return (USBD_OK); - /* USER CODE END 5 */ + return (USBD_OK); + /* USER CODE END 5 */ } /** @@ -260,13 +253,12 @@ 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) -{ - /* USER CODE BEGIN 6 */ - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); - USBD_CDC_ReceivePacket(&hUsbDeviceFS); - return (USBD_OK); - /* USER CODE END 6 */ +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); + return (USBD_OK); + /* USER CODE END 6 */ } /** @@ -280,18 +272,17 @@ 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 result = USBD_OK; - /* USER CODE BEGIN 7 */ - USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; - if (hcdc->TxState != 0){ - return USBD_BUSY; - } - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); - result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); - /* USER CODE END 7 */ - return result; +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; + if(hcdc->TxState != 0) { + return USBD_BUSY; + } + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); + result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); + /* USER CODE END 7 */ + return result; } /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ diff --git a/target_f1/Src/usbd_conf.c b/target_f1/Src/usbd_conf.c index 077d3ac3..1d63512d 100644 --- a/target_f1/Src/usbd_conf.c +++ b/target_f1/Src/usbd_conf.c @@ -47,7 +47,7 @@ void Error_Handler(void); /* USER CODE END 0 */ /* Exported function prototypes ----------------------------------------------*/ -extern USBD_StatusTypeDef USBD_LL_BatteryCharging(USBD_HandleTypeDef *pdev); +extern USBD_StatusTypeDef USBD_LL_BatteryCharging(USBD_HandleTypeDef* pdev); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ @@ -67,86 +67,76 @@ extern void SystemClock_Config(void); *******************************************************************************/ /* MSP Init */ -void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(pcdHandle->Instance==USB_OTG_FS) - { - /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(pcdHandle->Instance == USB_OTG_FS) { + /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ - /* USER CODE END USB_OTG_FS_MspInit 0 */ - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USB_OTG_FS GPIO Configuration + /* USER CODE END USB_OTG_FS_MspInit 0 */ + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USB_OTG_FS GPIO Configuration PA11 ------> USB_OTG_FS_DM PA12 ------> USB_OTG_FS_DP */ - GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /* Peripheral clock enable */ - __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + /* Peripheral clock enable */ + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); - /* Enable VDDUSB */ - if(__HAL_RCC_PWR_IS_CLK_DISABLED()) - { - __HAL_RCC_PWR_CLK_ENABLE(); - HAL_PWREx_EnableVddUSB(); - __HAL_RCC_PWR_CLK_DISABLE(); + /* Enable VDDUSB */ + if(__HAL_RCC_PWR_IS_CLK_DISABLED()) { + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_PWREx_EnableVddUSB(); + __HAL_RCC_PWR_CLK_DISABLE(); + } else { + HAL_PWREx_EnableVddUSB(); + } + + /* Peripheral interrupt init */ + HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(OTG_FS_IRQn); + /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ + + /* USER CODE END USB_OTG_FS_MspInit 1 */ } - else - { - HAL_PWREx_EnableVddUSB(); - } - - /* Peripheral interrupt init */ - HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(OTG_FS_IRQn); - /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ - - /* USER CODE END USB_OTG_FS_MspInit 1 */ - } } -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) -{ - if(pcdHandle->Instance==USB_OTG_FS) - { - /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */ +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 */ - /* Peripheral clock disable */ - __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); - - /**USB_OTG_FS GPIO Configuration + /* USER CODE END USB_OTG_FS_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); + + /**USB_OTG_FS GPIO Configuration PA11 ------> USB_OTG_FS_DM PA12 ------> USB_OTG_FS_DP */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11 | GPIO_PIN_12); - /* Disable VDDUSB */ - if(__HAL_RCC_PWR_IS_CLK_DISABLED()) - { - __HAL_RCC_PWR_CLK_ENABLE(); - HAL_PWREx_DisableVddUSB(); - __HAL_RCC_PWR_CLK_DISABLE(); + /* Disable VDDUSB */ + if(__HAL_RCC_PWR_IS_CLK_DISABLED()) { + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_PWREx_DisableVddUSB(); + __HAL_RCC_PWR_CLK_DISABLE(); + } else { + HAL_PWREx_DisableVddUSB(); + } + + /* Peripheral interrupt Deinit*/ + HAL_NVIC_DisableIRQ(OTG_FS_IRQn); + + /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ + + /* USER CODE END USB_OTG_FS_MspDeInit 1 */ } - else - { - HAL_PWREx_DisableVddUSB(); - } - - /* Peripheral interrupt Deinit*/ - HAL_NVIC_DisableIRQ(OTG_FS_IRQn); - - /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ - - /* USER CODE END USB_OTG_FS_MspDeInit 1 */ - } } /** @@ -154,13 +144,13 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SetupStageCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); + USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t*)hpcd->Setup); } /** @@ -169,13 +159,13 @@ void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) * @param epnum: Endpoint number * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DataOutStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); + USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); } /** @@ -184,13 +174,13 @@ void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) * @param epnum: Endpoint number * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DataInStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); + USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); } /** @@ -198,13 +188,13 @@ void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SOFCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SOFCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); + USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); } /** @@ -212,23 +202,22 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ResetCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ResetCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_SpeedTypeDef speed = USBD_SPEED_FULL; +{ + USBD_SpeedTypeDef speed = USBD_SPEED_FULL; - if ( hpcd->Init.speed != PCD_SPEED_FULL) - { - Error_Handler(); - } + if(hpcd->Init.speed != PCD_SPEED_FULL) { + Error_Handler(); + } /* Set Speed. */ - USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); + USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); - /* Reset Device. */ - USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); + /* Reset Device. */ + USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); } /** @@ -237,23 +226,22 @@ void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SuspendCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SuspendCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - __HAL_PCD_GATE_PHYCLOCK(hpcd); - /* Inform USB library that core enters in suspend Mode. */ - USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); - /* Enter in STOP mode. */ - /* USER CODE BEGIN 2 */ - 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)); - } - /* USER CODE END 2 */ + __HAL_PCD_GATE_PHYCLOCK(hpcd); + /* Inform USB library that core enters in suspend Mode. */ + USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); + /* Enter in STOP mode. */ + /* USER CODE BEGIN 2 */ + 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)); + } + /* USER CODE END 2 */ } /** @@ -262,23 +250,22 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ResumeCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ResumeCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - __HAL_PCD_UNGATE_PHYCLOCK(hpcd); + __HAL_PCD_UNGATE_PHYCLOCK(hpcd); - /* USER CODE BEGIN 3 */ - 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(); - } - /* USER CODE END 3 */ - USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN 3 */ + 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(); + } + /* USER CODE END 3 */ + USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); } /** @@ -287,13 +274,13 @@ void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) * @param epnum: Endpoint number * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); + USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); } /** @@ -302,13 +289,13 @@ void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) * @param epnum: Endpoint number * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); + USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); } /** @@ -316,15 +303,15 @@ void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ConnectCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ConnectCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - // TODO send UsbConnect event to FURI + // TODO send UsbConnect event to FURI - USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); + USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); } /** @@ -332,15 +319,15 @@ void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DisconnectCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - // TODO send UsbDisconnect event to FURI + // TODO send UsbDisconnect event to FURI - USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); + USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); } /******************************************************************************* @@ -352,50 +339,50 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) * @param pdev: Device handle * @retval USBD status */ -USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) -{ - /* Init USB Ip. */ - if (pdev->id == DEVICE_FS) { - /* Enable USB power on Pwrctrl CR2 register. */ - /* Link the driver to the stack. */ - hpcd_USB_OTG_FS.pData = pdev; - pdev->pData = &hpcd_USB_OTG_FS; - - hpcd_USB_OTG_FS.Instance = USB_OTG_FS; - hpcd_USB_OTG_FS.Init.dev_endpoints = 6; - hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE; - hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE; - hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE; - 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) - { - Error_Handler( ); - } +USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef* pdev) { + /* Init USB Ip. */ + if(pdev->id == DEVICE_FS) { + /* Enable USB power on Pwrctrl CR2 register. */ + /* Link the driver to the stack. */ + hpcd_USB_OTG_FS.pData = pdev; + pdev->pData = &hpcd_USB_OTG_FS; -#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_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); + hpcd_USB_OTG_FS.Instance = USB_OTG_FS; + hpcd_USB_OTG_FS.Init.dev_endpoints = 6; + hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED; + hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE; + hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE; + hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE; + 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) { + Error_Handler(); + } - HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback); - HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback); - HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOOUTIncompleteCallback); - HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOINIncompleteCallback); +#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_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_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback); + HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback); + HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOOUTIncompleteCallback); + HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOINIncompleteCallback); #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ - HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80); - HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40); - HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80); - } - return USBD_OK; + HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80); + HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40); + HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80); + } + return USBD_OK; } /** @@ -403,31 +390,30 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) * @param pdev: Device handle * @retval USBD status */ -USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_DeInit(pdev->pData); + hal_status = HAL_PCD_DeInit(pdev->pData); - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -435,31 +421,30 @@ USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) * @param pdev: Device handle * @retval USBD status */ -USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_Start(pdev->pData); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_Start(pdev->pData); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -467,31 +452,30 @@ USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) * @param pdev: Device handle * @retval USBD status */ -USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_Stop(pdev->pData); + hal_status = HAL_PCD_Stop(pdev->pData); - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -502,31 +486,31 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +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; - hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); + hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -535,31 +519,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -568,31 +551,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -601,31 +583,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_SetStall(pdev->pData, 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; - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -634,31 +615,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -667,18 +647,14 @@ 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) -{ - PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; - - if((ep_addr & 0x80) == 0x80) - { - return hpcd->IN_ep[ep_addr & 0x7F].is_stall; - } - else - { - return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; - } +uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + PCD_HandleTypeDef* hpcd = (PCD_HandleTypeDef*)pdev->pData; + + if((ep_addr & 0x80) == 0x80) { + return hpcd->IN_ep[ep_addr & 0x7F].is_stall; + } else { + return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; + } } /** @@ -687,31 +663,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef* pdev, uint8_t dev_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -722,31 +697,31 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +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; - hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -757,31 +732,31 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +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; - hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -790,9 +765,8 @@ 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) -{ - return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, 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,34 +775,30 @@ 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) - { - case PCD_LPM_L0_ACTIVE: - if (hpcd->Init.low_power_enable) - { - SystemClockConfig_Resume(); - - /* Reset SLEEPDEEP bit of Cortex System Control Register. */ - SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); +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) { + SystemClockConfig_Resume(); + + /* Reset SLEEPDEEP bit of Cortex System Control Register. */ + SCB->SCR &= (uint32_t) ~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + } + __HAL_PCD_UNGATE_PHYCLOCK(hpcd); + USBD_LL_Resume(hpcd->pData); + break; + + case PCD_LPM_L1_ACTIVE: + __HAL_PCD_GATE_PHYCLOCK(hpcd); + USBD_LL_Suspend(hpcd->pData); + + /* Enter in STOP mode. */ + 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)); + } + break; } - __HAL_PCD_UNGATE_PHYCLOCK(hpcd); - USBD_LL_Resume(hpcd->pData); - break; - - case PCD_LPM_L1_ACTIVE: - __HAL_PCD_GATE_PHYCLOCK(hpcd); - USBD_LL_Suspend(hpcd->pData); - - /* Enter in STOP mode. */ - 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)); - } - break; - } } /** @@ -836,9 +806,8 @@ 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) -{ - HAL_Delay(Delay); +void USBD_LL_Delay(uint32_t Delay) { + HAL_Delay(Delay); } /** @@ -846,10 +815,9 @@ void USBD_LL_Delay(uint32_t Delay) * @param size: Size of allocated memory * @retval None */ -void *USBD_static_malloc(uint32_t size) -{ - static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ - return mem; +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,9 +834,8 @@ void USBD_static_free(void *p) * enable HSI, PLL and select PLL as system clock source. * @retval None */ -static void SystemClockConfig_Resume(void) -{ - SystemClock_Config(); +static void SystemClockConfig_Resume(void) { + SystemClock_Config(); } /* USER CODE END 5 */ diff --git a/target_f1/Src/usbd_desc.c b/target_f1/Src/usbd_desc.c index e40828ab..a57103a1 100644 --- a/target_f1/Src/usbd_desc.c +++ b/target_f1/Src/usbd_desc.c @@ -63,15 +63,15 @@ * @{ */ -#define USBD_VID 1155 -#define USBD_LANGID_STRING 1033 -#define USBD_MANUFACTURER_STRING "STMicroelectronics" -#define USBD_PID_FS 22336 -#define USBD_PRODUCT_STRING_FS "Flipper Zero Virtual ComPort" -#define USBD_CONFIGURATION_STRING_FS "CDC Config" -#define USBD_INTERFACE_STRING_FS "CDC Interface" +#define USBD_VID 1155 +#define USBD_LANGID_STRING 1033 +#define USBD_MANUFACTURER_STRING "STMicroelectronics" +#define USBD_PID_FS 22336 +#define USBD_PRODUCT_STRING_FS "Flipper Zero Virtual ComPort" +#define USBD_CONFIGURATION_STRING_FS "CDC Config" +#define USBD_INTERFACE_STRING_FS "CDC Interface" -#define USB_SIZ_BOS_DESC 0x0C +#define USB_SIZ_BOS_DESC 0x0C /* USER CODE BEGIN PRIVATE_DEFINES */ @@ -97,34 +97,33 @@ /** * @} */ - + /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes * @brief Private functions declaration. * @{ */ - + static void Get_SerialNum(void); -static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); - +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. * @{ */ -uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -#if (USBD_LPM_ENABLED == 1) -uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t* USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +#if(USBD_LPM_ENABLED == 1) +uint8_t* USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); #endif /* (USBD_LPM_ENABLED == 1) */ /** @@ -136,74 +135,71 @@ 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 -#if (USBD_LPM_ENABLED == 1) -, USBD_FS_USR_BOSDescriptor +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 #endif /* (USBD_LPM_ENABLED == 1) */ }; -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /** USB standard device descriptor. */ -__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 +__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 in order to support LPM L1 suspend resume test of USBCV3.0*/ #else - 0x00, /*bcdUSB */ + 0x00, /*bcdUSB */ #endif /* (USBD_LPM_ENABLED == 1) */ - 0x02, - 0x02, /*bDeviceClass*/ - 0x02, /*bDeviceSubClass*/ - 0x00, /*bDeviceProtocol*/ - USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ - LOBYTE(USBD_VID), /*idVendor*/ - HIBYTE(USBD_VID), /*idVendor*/ - LOBYTE(USBD_PID_FS), /*idProduct*/ - HIBYTE(USBD_PID_FS), /*idProduct*/ - 0x00, /*bcdDevice rel. 2.00*/ - 0x02, - USBD_IDX_MFC_STR, /*Index of manufacturer string*/ - USBD_IDX_PRODUCT_STR, /*Index of product string*/ - USBD_IDX_SERIAL_STR, /*Index of serial number string*/ - USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ + 0x02, + 0x02, /*bDeviceClass*/ + 0x02, /*bDeviceSubClass*/ + 0x00, /*bDeviceProtocol*/ + USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ + LOBYTE(USBD_VID), /*idVendor*/ + HIBYTE(USBD_VID), /*idVendor*/ + LOBYTE(USBD_PID_FS), /*idProduct*/ + HIBYTE(USBD_PID_FS), /*idProduct*/ + 0x00, /*bcdDevice rel. 2.00*/ + 0x02, + USBD_IDX_MFC_STR, /*Index of manufacturer string*/ + USBD_IDX_PRODUCT_STR, /*Index of product string*/ + USBD_IDX_SERIAL_STR, /*Index of serial number string*/ + USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ }; /* USB_DeviceDescriptor */ /** BOS descriptor. */ -#if (USBD_LPM_ENABLED == 1) -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if(USBD_LPM_ENABLED == 1) +#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 = -{ - 0x5, - USB_DESC_TYPE_BOS, - 0xC, - 0x0, - 0x1, /* 1 device capability*/ - /* device capability*/ - 0x7, - USB_DEVICE_CAPABITY_TYPE, - 0x2, - 0x2, /* LPM capability bit set*/ - 0x0, - 0x0, - 0x0 -}; +__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = { + 0x5, + USB_DESC_TYPE_BOS, + 0xC, + 0x0, + 0x1, /* 1 device capability*/ + /* device capability*/ + 0x7, + USB_DEVICE_CAPABITY_TYPE, + 0x2, + 0x2, /* LPM capability bit set*/ + 0x0, + 0x0, + 0x0}; #endif /* (USBD_LPM_ENABLED == 1) */ /** @@ -215,31 +211,29 @@ __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = * @{ */ -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /** USB lang indentifier descriptor. */ -__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) -}; +__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)}; -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /* Internal string descriptor. */ __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /*!< IAR Compiler */ +#pragma data_alignment = 4 #endif __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { - USB_SIZ_STRING_SERIAL, - USB_DESC_TYPE_STRING, + USB_SIZ_STRING_SERIAL, + USB_DESC_TYPE_STRING, }; /** @@ -257,11 +251,10 @@ __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) -{ - UNUSED(speed); - *length = sizeof(USBD_FS_DeviceDesc); - return USBD_FS_DeviceDesc; +uint8_t* USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { + UNUSED(speed); + *length = sizeof(USBD_FS_DeviceDesc); + return USBD_FS_DeviceDesc; } /** @@ -270,11 +263,10 @@ 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) -{ - UNUSED(speed); - *length = sizeof(USBD_LangIDDesc); - return USBD_LangIDDesc; +uint8_t* USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { + UNUSED(speed); + *length = sizeof(USBD_LangIDDesc); + return USBD_LangIDDesc; } /** @@ -283,17 +275,13 @@ 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) - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; +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 { + USBD_GetString((uint8_t*)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; } /** @@ -302,11 +290,10 @@ 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) -{ - UNUSED(speed); - USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); - return USBD_StrDesc; +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,18 +302,17 @@ 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) -{ - UNUSED(speed); - *length = USB_SIZ_STRING_SERIAL; +uint8_t* USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { + UNUSED(speed); + *length = USB_SIZ_STRING_SERIAL; - /* Update the serial number string descriptor with the data from the unique + /* Update the serial number string descriptor with the data from the unique * ID */ - Get_SerialNum(); - /* USER CODE BEGIN USBD_FS_SerialStrDescriptor */ - - /* USER CODE END USBD_FS_SerialStrDescriptor */ - return (uint8_t *) USBD_StringSerial; + Get_SerialNum(); + /* USER CODE BEGIN USBD_FS_SerialStrDescriptor */ + + /* USER CODE END USBD_FS_SerialStrDescriptor */ + return (uint8_t*)USBD_StringSerial; } /** @@ -335,17 +321,13 @@ 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) - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; +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 { + USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; } /** @@ -354,31 +336,26 @@ 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) - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; +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 { + USBD_GetString((uint8_t*)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; } -#if (USBD_LPM_ENABLED == 1) +#if(USBD_LPM_ENABLED == 1) /** * @brief Return the BOS descriptor * @param speed : Current device speed * @param length : Pointer to data length variable * @retval Pointer to descriptor buffer */ -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; +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; } #endif /* (USBD_LPM_ENABLED == 1) */ @@ -387,21 +364,19 @@ uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) * @param None * @retval None */ -static void Get_SerialNum(void) -{ - uint32_t deviceserial0, deviceserial1, deviceserial2; +static void Get_SerialNum(void) { + uint32_t deviceserial0, deviceserial1, deviceserial2; - deviceserial0 = *(uint32_t *) DEVICE_ID1; - deviceserial1 = *(uint32_t *) DEVICE_ID2; - deviceserial2 = *(uint32_t *) DEVICE_ID3; + deviceserial0 = *(uint32_t*)DEVICE_ID1; + deviceserial1 = *(uint32_t*)DEVICE_ID2; + deviceserial2 = *(uint32_t*)DEVICE_ID3; - deviceserial0 += deviceserial2; + deviceserial0 += deviceserial2; - if (deviceserial0 != 0) - { - IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); - IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); - } + if(deviceserial0 != 0) { + IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); + IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); + } } /** @@ -411,25 +386,20 @@ static void Get_SerialNum(void) * @param len: buffer length * @retval None */ -static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) -{ - uint8_t idx = 0; +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) - { - pbuf[2 * idx] = (value >> 28) + '0'; + for(idx = 0; idx < len; idx++) { + if(((value >> 28)) < 0xA) { + pbuf[2 * idx] = (value >> 28) + '0'; + } else { + pbuf[2 * idx] = (value >> 28) + 'A' - 10; + } + + value = value << 4; + + pbuf[2 * idx + 1] = 0; } - else - { - pbuf[2 * idx] = (value >> 28) + 'A' - 10; - } - - value = value << 4; - - pbuf[2 * idx + 1] = 0; - } } /** * @} diff --git a/target_f2/Inc/FreeRTOSConfig.h b/target_f2/Inc/FreeRTOSConfig.h index 085eb0c7..170cb7cc 100644 --- a/target_f2/Inc/FreeRTOSConfig.h +++ b/target_f2/Inc/FreeRTOSConfig.h @@ -25,7 +25,7 @@ * * 1 tab == 4 spaces! */ - /* USER CODE END Header */ +/* USER CODE END Header */ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H @@ -42,15 +42,15 @@ * See http://www.freertos.org/a00110.html *----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ +/* USER CODE BEGIN Includes */ /* Section where include file can be added */ -/* USER CODE END Includes */ +/* USER CODE END Includes */ /* Ensure definitions are only used by the compiler, and not by the assembler. */ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) - #include - extern uint32_t SystemCoreClock; - void xPortSysTickHandler(void); +#include +extern uint32_t SystemCoreClock; +void xPortSysTickHandler(void); #endif #define configUSE_PREEMPTION 1 #define configSUPPORT_STATIC_ALLOCATION 1 @@ -71,37 +71,37 @@ #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 1 /* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) /* Software timer definitions. */ -#define configUSE_TIMERS 1 -#define configTIMER_TASK_PRIORITY ( 2 ) -#define configTIMER_QUEUE_LENGTH 10 -#define configTIMER_TASK_STACK_DEPTH 256 +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (2) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH 256 /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 0 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 /* Cortex-M specific definitions. */ #ifdef __NVIC_PRIO_BITS - /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ - #define configPRIO_BITS __NVIC_PRIO_BITS +/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ +#define configPRIO_BITS __NVIC_PRIO_BITS #else - #define configPRIO_BITS 4 +#define configPRIO_BITS 4 #endif /* The lowest interrupt priority that can be used in a call to a "set priority" function. */ -#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 /* The highest interrupt priority that can be used by any interrupt service routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL @@ -111,29 +111,36 @@ 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 standard names. */ -#define vPortSVCHandler SVC_Handler +#define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick, to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ - + /* #define xPortSysTickHandler SysTick_Handler */ -/* USER CODE BEGIN Defines */ +/* USER CODE BEGIN Defines */ /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ -/* USER CODE END Defines */ +/* USER CODE END Defines */ #endif /* FREERTOS_CONFIG_H */ diff --git a/target_f2/Inc/flipper_hal.h b/target_f2/Inc/flipper_hal.h index aae9014b..02b8a1ad 100644 --- a/target_f2/Inc/flipper_hal.h +++ b/target_f2/Inc/flipper_hal.h @@ -9,11 +9,7 @@ GPIO and HAL implementations #include #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; diff --git a/target_f2/Inc/main.h b/target_f2/Inc/main.h index fd0e04d6..735552a5 100644 --- a/target_f2/Inc/main.h +++ b/target_f2/Inc/main.h @@ -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 */ @@ -55,14 +52,14 @@ typedef enum { /* USER CODE END EM */ -void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim); /* Exported functions prototypes ---------------------------------------------*/ void Error_Handler(void); /* USER CODE BEGIN EFP */ -void register_tim8_callback_ch2(void(*callback)(uint16_t ccr, TimerEvent tim_event)); +void register_tim8_callback_ch2(void (*callback)(uint16_t ccr, TimerEvent tim_event)); /* USER CODE END EFP */ @@ -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 */ diff --git a/target_f2/Inc/stm32l4xx_hal_conf.h b/target_f2/Inc/stm32l4xx_hal_conf.h index e2e03c4e..b3d31693 100644 --- a/target_f2/Inc/stm32l4xx_hal_conf.h +++ b/target_f2/Inc/stm32l4xx_hal_conf.h @@ -30,14 +30,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** - */ + */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32L4xx_HAL_CONF_H #define __STM32L4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -48,7 +48,7 @@ * @brief This is the list of modules to be used in the HAL driver */ -#define HAL_MODULE_ENABLED +#define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED /*#define HAL_CRYP_MODULE_ENABLED */ /*#define HAL_CAN_MODULE_ENABLED */ @@ -95,7 +95,7 @@ /*#define HAL_WWDG_MODULE_ENABLED */ /*#define HAL_EXTI_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED -#define HAL_EXTI_MODULE_ENABLED +#define HAL_EXTI_MODULE_ENABLED #define HAL_I2C_MODULE_ENABLED #define HAL_DMA_MODULE_ENABLED #define HAL_RCC_MODULE_ENABLED @@ -109,28 +109,28 @@ * This value is used by the RCC HAL module to compute the system frequency * (when HSE is used as system clock source, directly or through the PLL). */ -#if !defined (HSE_VALUE) - #define HSE_VALUE ((uint32_t)16000000U) /*!< Value of the External oscillator in Hz */ +#if !defined(HSE_VALUE) +#define HSE_VALUE ((uint32_t)16000000U) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ /** * @brief Internal Multiple Speed oscillator (MSI) default value. * This value is the default MSI range value after Reset. */ -#if !defined (MSI_VALUE) - #define MSI_VALUE ((uint32_t)4000000U) /*!< Value of the Internal oscillator in Hz*/ +#if !defined(MSI_VALUE) +#define MSI_VALUE ((uint32_t)4000000U) /*!< Value of the Internal oscillator in Hz*/ #endif /* MSI_VALUE */ /** * @brief Internal High Speed oscillator (HSI) value. * This value is used by the RCC HAL module to compute the system frequency * (when HSI is used as system clock source, directly or through the PLL). */ -#if !defined (HSI_VALUE) - #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ +#if !defined(HSI_VALUE) +#define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /** @@ -140,17 +140,18 @@ * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency * 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. +#if !defined(HSI48_VALUE) +#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 */ /** * @brief Internal Low Speed oscillator (LSI) value. */ -#if !defined (LSI_VALUE) - #define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz +#if !defined(LSI_VALUE) +#define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ @@ -158,12 +159,12 @@ * @brief External Low Speed oscillator (LSE) value. * This value is used by the UART, RTC HAL module to compute the system frequency */ -#if !defined (LSE_VALUE) - #define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External oscillator in Hz*/ +#if !defined(LSE_VALUE) +#define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External oscillator in Hz*/ #endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) - #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ /** @@ -171,8 +172,9 @@ * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source * frequency. */ -#if !defined (EXTERNAL_SAI1_CLOCK_VALUE) - #define EXTERNAL_SAI1_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/ +#if !defined(EXTERNAL_SAI1_CLOCK_VALUE) +#define EXTERNAL_SAI1_CLOCK_VALUE \ + ((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/ #endif /* EXTERNAL_SAI1_CLOCK_VALUE */ /** @@ -180,8 +182,9 @@ * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source * frequency. */ -#if !defined (EXTERNAL_SAI2_CLOCK_VALUE) - #define EXTERNAL_SAI2_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI2 External clock source in Hz*/ +#if !defined(EXTERNAL_SAI2_CLOCK_VALUE) +#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, @@ -190,14 +193,14 @@ /* ########################### System Configuration ######################### */ /** * @brief This is the HAL system configuration section - */ - -#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY ((uint32_t)15U) /*!< tick interrupt priority */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 1U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U + */ + +#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)15U) /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** @@ -213,7 +216,7 @@ * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** @@ -221,201 +224,201 @@ */ #ifdef HAL_RCC_MODULE_ENABLED - #include "stm32l4xx_hal_rcc.h" - #include "stm32l4xx_hal_rcc_ex.h" +#include "stm32l4xx_hal_rcc.h" +#include "stm32l4xx_hal_rcc_ex.h" #endif /* HAL_RCC_MODULE_ENABLED */ #ifdef HAL_EXTI_MODULE_ENABLED - #include "stm32l4xx_hal_exti.h" +#include "stm32l4xx_hal_exti.h" #endif /* HAL_EXTI_MODULE_ENABLED */ #ifdef HAL_GPIO_MODULE_ENABLED - #include "stm32l4xx_hal_gpio.h" +#include "stm32l4xx_hal_gpio.h" #endif /* HAL_GPIO_MODULE_ENABLED */ #ifdef HAL_DMA_MODULE_ENABLED - #include "stm32l4xx_hal_dma.h" - #include "stm32l4xx_hal_dma_ex.h" +#include "stm32l4xx_hal_dma.h" +#include "stm32l4xx_hal_dma_ex.h" #endif /* HAL_DMA_MODULE_ENABLED */ #ifdef HAL_DFSDM_MODULE_ENABLED - #include "stm32l4xx_hal_dfsdm.h" +#include "stm32l4xx_hal_dfsdm.h" #endif /* HAL_DFSDM_MODULE_ENABLED */ #ifdef HAL_CORTEX_MODULE_ENABLED - #include "stm32l4xx_hal_cortex.h" +#include "stm32l4xx_hal_cortex.h" #endif /* HAL_CORTEX_MODULE_ENABLED */ #ifdef HAL_ADC_MODULE_ENABLED - #include "stm32l4xx_hal_adc.h" +#include "stm32l4xx_hal_adc.h" #endif /* HAL_ADC_MODULE_ENABLED */ #ifdef HAL_CAN_MODULE_ENABLED - #include "stm32l4xx_hal_can.h" +#include "stm32l4xx_hal_can.h" #endif /* HAL_CAN_MODULE_ENABLED */ #ifdef HAL_COMP_MODULE_ENABLED - #include "stm32l4xx_hal_comp.h" +#include "stm32l4xx_hal_comp.h" #endif /* HAL_COMP_MODULE_ENABLED */ #ifdef HAL_CRC_MODULE_ENABLED - #include "stm32l4xx_hal_crc.h" +#include "stm32l4xx_hal_crc.h" #endif /* HAL_CRC_MODULE_ENABLED */ #ifdef HAL_CRYP_MODULE_ENABLED - #include "stm32l4xx_hal_cryp.h" +#include "stm32l4xx_hal_cryp.h" #endif /* HAL_CRYP_MODULE_ENABLED */ #ifdef HAL_DAC_MODULE_ENABLED - #include "stm32l4xx_hal_dac.h" +#include "stm32l4xx_hal_dac.h" #endif /* HAL_DAC_MODULE_ENABLED */ #ifdef HAL_DCMI_MODULE_ENABLED - #include "stm32l4xx_hal_dcmi.h" +#include "stm32l4xx_hal_dcmi.h" #endif /* HAL_DCMI_MODULE_ENABLED */ #ifdef HAL_DMA2D_MODULE_ENABLED - #include "stm32l4xx_hal_dma2d.h" +#include "stm32l4xx_hal_dma2d.h" #endif /* HAL_DMA2D_MODULE_ENABLED */ #ifdef HAL_DSI_MODULE_ENABLED - #include "stm32l4xx_hal_dsi.h" +#include "stm32l4xx_hal_dsi.h" #endif /* HAL_DSI_MODULE_ENABLED */ #ifdef HAL_FIREWALL_MODULE_ENABLED - #include "stm32l4xx_hal_firewall.h" +#include "stm32l4xx_hal_firewall.h" #endif /* HAL_FIREWALL_MODULE_ENABLED */ #ifdef HAL_FLASH_MODULE_ENABLED - #include "stm32l4xx_hal_flash.h" +#include "stm32l4xx_hal_flash.h" #endif /* HAL_FLASH_MODULE_ENABLED */ #ifdef HAL_HASH_MODULE_ENABLED - #include "stm32l4xx_hal_hash.h" +#include "stm32l4xx_hal_hash.h" #endif /* HAL_HASH_MODULE_ENABLED */ #ifdef HAL_SRAM_MODULE_ENABLED - #include "stm32l4xx_hal_sram.h" +#include "stm32l4xx_hal_sram.h" #endif /* HAL_SRAM_MODULE_ENABLED */ #ifdef HAL_MMC_MODULE_ENABLED - #include "stm32l4xx_hal_mmc.h" +#include "stm32l4xx_hal_mmc.h" #endif /* HAL_MMC_MODULE_ENABLED */ #ifdef HAL_NOR_MODULE_ENABLED - #include "stm32l4xx_hal_nor.h" +#include "stm32l4xx_hal_nor.h" #endif /* HAL_NOR_MODULE_ENABLED */ #ifdef HAL_NAND_MODULE_ENABLED - #include "stm32l4xx_hal_nand.h" +#include "stm32l4xx_hal_nand.h" #endif /* HAL_NAND_MODULE_ENABLED */ #ifdef HAL_I2C_MODULE_ENABLED - #include "stm32l4xx_hal_i2c.h" +#include "stm32l4xx_hal_i2c.h" #endif /* HAL_I2C_MODULE_ENABLED */ #ifdef HAL_IWDG_MODULE_ENABLED - #include "stm32l4xx_hal_iwdg.h" +#include "stm32l4xx_hal_iwdg.h" #endif /* HAL_IWDG_MODULE_ENABLED */ #ifdef HAL_LCD_MODULE_ENABLED - #include "stm32l4xx_hal_lcd.h" +#include "stm32l4xx_hal_lcd.h" #endif /* HAL_LCD_MODULE_ENABLED */ #ifdef HAL_LPTIM_MODULE_ENABLED - #include "stm32l4xx_hal_lptim.h" +#include "stm32l4xx_hal_lptim.h" #endif /* HAL_LPTIM_MODULE_ENABLED */ #ifdef HAL_LTDC_MODULE_ENABLED - #include "stm32l4xx_hal_ltdc.h" +#include "stm32l4xx_hal_ltdc.h" #endif /* HAL_LTDC_MODULE_ENABLED */ #ifdef HAL_OPAMP_MODULE_ENABLED - #include "stm32l4xx_hal_opamp.h" +#include "stm32l4xx_hal_opamp.h" #endif /* HAL_OPAMP_MODULE_ENABLED */ #ifdef HAL_OSPI_MODULE_ENABLED - #include "stm32l4xx_hal_ospi.h" +#include "stm32l4xx_hal_ospi.h" #endif /* HAL_OSPI_MODULE_ENABLED */ #ifdef HAL_PWR_MODULE_ENABLED - #include "stm32l4xx_hal_pwr.h" +#include "stm32l4xx_hal_pwr.h" #endif /* HAL_PWR_MODULE_ENABLED */ #ifdef HAL_QSPI_MODULE_ENABLED - #include "stm32l4xx_hal_qspi.h" +#include "stm32l4xx_hal_qspi.h" #endif /* HAL_QSPI_MODULE_ENABLED */ #ifdef HAL_RNG_MODULE_ENABLED - #include "stm32l4xx_hal_rng.h" +#include "stm32l4xx_hal_rng.h" #endif /* HAL_RNG_MODULE_ENABLED */ #ifdef HAL_RTC_MODULE_ENABLED - #include "stm32l4xx_hal_rtc.h" +#include "stm32l4xx_hal_rtc.h" #endif /* HAL_RTC_MODULE_ENABLED */ #ifdef HAL_SAI_MODULE_ENABLED - #include "stm32l4xx_hal_sai.h" +#include "stm32l4xx_hal_sai.h" #endif /* HAL_SAI_MODULE_ENABLED */ #ifdef HAL_SD_MODULE_ENABLED - #include "stm32l4xx_hal_sd.h" +#include "stm32l4xx_hal_sd.h" #endif /* HAL_SD_MODULE_ENABLED */ #ifdef HAL_SMBUS_MODULE_ENABLED - #include "stm32l4xx_hal_smbus.h" +#include "stm32l4xx_hal_smbus.h" #endif /* HAL_SMBUS_MODULE_ENABLED */ #ifdef HAL_SPI_MODULE_ENABLED - #include "stm32l4xx_hal_spi.h" +#include "stm32l4xx_hal_spi.h" #endif /* HAL_SPI_MODULE_ENABLED */ #ifdef HAL_SWPMI_MODULE_ENABLED - #include "stm32l4xx_hal_swpmi.h" +#include "stm32l4xx_hal_swpmi.h" #endif /* HAL_SWPMI_MODULE_ENABLED */ #ifdef HAL_TIM_MODULE_ENABLED - #include "stm32l4xx_hal_tim.h" +#include "stm32l4xx_hal_tim.h" #endif /* HAL_TIM_MODULE_ENABLED */ #ifdef HAL_TSC_MODULE_ENABLED - #include "stm32l4xx_hal_tsc.h" +#include "stm32l4xx_hal_tsc.h" #endif /* HAL_TSC_MODULE_ENABLED */ #ifdef HAL_UART_MODULE_ENABLED - #include "stm32l4xx_hal_uart.h" +#include "stm32l4xx_hal_uart.h" #endif /* HAL_UART_MODULE_ENABLED */ #ifdef HAL_USART_MODULE_ENABLED - #include "stm32l4xx_hal_usart.h" +#include "stm32l4xx_hal_usart.h" #endif /* HAL_USART_MODULE_ENABLED */ #ifdef HAL_IRDA_MODULE_ENABLED - #include "stm32l4xx_hal_irda.h" +#include "stm32l4xx_hal_irda.h" #endif /* HAL_IRDA_MODULE_ENABLED */ #ifdef HAL_SMARTCARD_MODULE_ENABLED - #include "stm32l4xx_hal_smartcard.h" +#include "stm32l4xx_hal_smartcard.h" #endif /* HAL_SMARTCARD_MODULE_ENABLED */ #ifdef HAL_WWDG_MODULE_ENABLED - #include "stm32l4xx_hal_wwdg.h" +#include "stm32l4xx_hal_wwdg.h" #endif /* HAL_WWDG_MODULE_ENABLED */ #ifdef HAL_PCD_MODULE_ENABLED - #include "stm32l4xx_hal_pcd.h" +#include "stm32l4xx_hal_pcd.h" #endif /* HAL_PCD_MODULE_ENABLED */ #ifdef HAL_HCD_MODULE_ENABLED - #include "stm32l4xx_hal_hcd.h" +#include "stm32l4xx_hal_hcd.h" #endif /* HAL_HCD_MODULE_ENABLED */ #ifdef HAL_GFXMMU_MODULE_ENABLED - #include "stm32l4xx_hal_gfxmmu.h" +#include "stm32l4xx_hal_gfxmmu.h" #endif /* HAL_GFXMMU_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function @@ -424,11 +427,11 @@ * If expr is true, it returns no value. * @retval None */ - #define assert_param(expr) ((expr) ? (void)0U : assert_failed((char *)__FILE__, __LINE__)) +#define assert_param(expr) ((expr) ? (void)0U : assert_failed((char*)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ - void assert_failed(char *file, uint32_t line); +void assert_failed(char* file, uint32_t line); #else - #define assert_param(expr) ((void)0U) +#define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus diff --git a/target_f2/Inc/stm32l4xx_it.h b/target_f2/Inc/stm32l4xx_it.h index ba58e4d3..6f944995 100644 --- a/target_f2/Inc/stm32l4xx_it.h +++ b/target_f2/Inc/stm32l4xx_it.h @@ -23,8 +23,8 @@ #define __STM32L4xx_IT_H #ifdef __cplusplus - extern "C" { -#endif +extern "C" { +#endif /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/target_f2/Inc/usb_device.h b/target_f2/Inc/usb_device.h index 8be16a01..95750c56 100644 --- a/target_f2/Inc/usb_device.h +++ b/target_f2/Inc/usb_device.h @@ -24,7 +24,7 @@ #define __USB_DEVICE__H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/target_f2/Inc/usbd_cdc_if.h b/target_f2/Inc/usbd_cdc_if.h index b941a817..4d92c7a5 100644 --- a/target_f2/Inc/usbd_cdc_if.h +++ b/target_f2/Inc/usbd_cdc_if.h @@ -24,7 +24,7 @@ #define __USBD_CDC_IF_H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -38,11 +38,11 @@ * @brief For Usb device. * @{ */ - + /** @defgroup USBD_CDC_IF USBD_CDC_IF * @brief Usb VCP device module * @{ - */ + */ /** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines * @brief Defines. diff --git a/target_f2/Inc/usbd_conf.h b/target_f2/Inc/usbd_conf.h index f43bcde7..86e3a038 100644 --- a/target_f2/Inc/usbd_conf.h +++ b/target_f2/Inc/usbd_conf.h @@ -24,7 +24,7 @@ #define __USBD_CONF__H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -64,21 +64,21 @@ */ /*---------- -----------*/ -#define USBD_MAX_NUM_INTERFACES 1U +#define USBD_MAX_NUM_INTERFACES 1U /*---------- -----------*/ -#define USBD_MAX_NUM_CONFIGURATION 1U +#define USBD_MAX_NUM_CONFIGURATION 1U /*---------- -----------*/ -#define USBD_MAX_STR_DESC_SIZ 512U +#define USBD_MAX_STR_DESC_SIZ 512U /*---------- -----------*/ -#define USBD_DEBUG_LEVEL 0U +#define USBD_DEBUG_LEVEL 0U /*---------- -----------*/ -#define USBD_LPM_ENABLED 1U +#define USBD_LPM_ENABLED 1U /*---------- -----------*/ -#define USBD_SELF_POWERED 1U +#define USBD_SELF_POWERED 1U /****************************************/ /* #define for FS and HS identification */ -#define DEVICE_FS 0 +#define DEVICE_FS 0 /** * @} @@ -92,42 +92,45 @@ /* Memory management macros */ /** Alias for memory allocation. */ -#define USBD_malloc (uint32_t *)USBD_static_malloc +#define USBD_malloc (uint32_t*)USBD_static_malloc /** Alias for memory release. */ -#define USBD_free USBD_static_free +#define USBD_free USBD_static_free /** Alias for memory set. */ -#define USBD_memset /* Not used */ +#define USBD_memset /* Not used */ /** Alias for memory copy. */ -#define USBD_memcpy /* Not used */ +#define USBD_memcpy /* Not used */ /** Alias for delay. */ -#define USBD_Delay HAL_Delay +#define USBD_Delay HAL_Delay /* DEBUG macros */ -#if (USBD_DEBUG_LEVEL > 0) -#define USBD_UsrLog(...) printf(__VA_ARGS__);\ - printf("\n"); +#if(USBD_DEBUG_LEVEL > 0) +#define USBD_UsrLog(...) \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_UsrLog(...) #endif -#if (USBD_DEBUG_LEVEL > 1) +#if(USBD_DEBUG_LEVEL > 1) -#define USBD_ErrLog(...) printf("ERROR: ") ;\ - printf(__VA_ARGS__);\ - printf("\n"); +#define USBD_ErrLog(...) \ + printf("ERROR: "); \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_ErrLog(...) #endif -#if (USBD_DEBUG_LEVEL > 2) -#define USBD_DbgLog(...) printf("DEBUG : ") ;\ - printf(__VA_ARGS__);\ - printf("\n"); +#if(USBD_DEBUG_LEVEL > 2) +#define USBD_DbgLog(...) \ + printf("DEBUG : "); \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_DbgLog(...) #endif @@ -151,8 +154,8 @@ */ /* Exported functions -------------------------------------------------------*/ -void *USBD_static_malloc(uint32_t size); -void USBD_static_free(void *p); +void* USBD_static_malloc(uint32_t size); +void USBD_static_free(void* p); /** * @} diff --git a/target_f2/Inc/usbd_desc.h b/target_f2/Inc/usbd_desc.h index 9e0bb00d..c5bdfe75 100644 --- a/target_f2/Inc/usbd_desc.h +++ b/target_f2/Inc/usbd_desc.h @@ -17,13 +17,13 @@ * ****************************************************************************** */ -/* USER CODE END Header */ +/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_DESC__C__ #define __USBD_DESC__C__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -41,16 +41,16 @@ * @brief Usb device descriptors module. * @{ */ - + /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants * @brief Constants. * @{ */ -#define DEVICE_ID1 (UID_BASE) -#define DEVICE_ID2 (UID_BASE + 0x4) -#define DEVICE_ID3 (UID_BASE + 0x8) +#define DEVICE_ID1 (UID_BASE) +#define DEVICE_ID2 (UID_BASE + 0x4) +#define DEVICE_ID3 (UID_BASE + 0x8) -#define USB_SIZ_STRING_SERIAL 0x1A +#define USB_SIZ_STRING_SERIAL 0x1A /* USER CODE BEGIN EXPORTED_CONSTANTS */ diff --git a/target_f2/Src/flipper_hal.c b/target_f2/Src/flipper_hal.c index f1bccde1..ba9f4673 100644 --- a/target_f2/Src/flipper_hal.c +++ b/target_f2/Src/flipper_hal.c @@ -15,18 +15,18 @@ void app_gpio_init(GpioPin gpio, GpioMode mode) { GPIO_InitStruct.Pull = GPIO_NOPULL; switch(mode) { - case GpioModeInput: - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + case GpioModeInput: + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; break; - case GpioModeOutput: - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + case GpioModeOutput: + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; break; - case GpioModeOpenDrain: - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + case GpioModeOpenDrain: + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; break; } @@ -36,20 +36,21 @@ void app_gpio_init(GpioPin gpio, GpioMode mode) { // TODO delay from timer void delay_us(uint32_t time) { - time *= 11.8; + time *= 11.8; - while(time--) {} + while(time--) { + } } void pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) { tim->Init.CounterMode = TIM_COUNTERMODE_UP; - tim->Init.Period = (uint32_t)((SystemCoreClock/tim->Init.Prescaler)/freq); + tim->Init.Period = (uint32_t)((SystemCoreClock / tim->Init.Prescaler) / freq); tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; HAL_TIM_PWM_Init(tim); TIM_OC_InitTypeDef sConfigOC; - + sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = (uint16_t)(291 * value); sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; diff --git a/target_f2/Src/freertos.c b/target_f2/Src/freertos.c index b8fe8631..a62f690e 100644 --- a/target_f2/Src/freertos.c +++ b/target_f2/Src/freertos.c @@ -24,7 +24,7 @@ #include "main.h" /* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ +/* USER CODE BEGIN Includes */ #include /* USER CODE END Includes */ @@ -51,22 +51,25 @@ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ - + /* 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 ) -{ - /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set +__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 to block in any way (for example, call xQueueReceive() with a block time @@ -81,27 +84,29 @@ __weak void vApplicationIdleHook( void ) /* USER CODE BEGIN GET_IDLE_TASK_MEMORY */ static StaticTask_t xIdleTaskTCBBuffer; static StackType_t xIdleStack[configMINIMAL_STACK_SIZE]; - -void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) -{ - *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; - *ppxIdleTaskStackBuffer = &xIdleStack[0]; - *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; - /* place for user code */ -} + +void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer, + StackType_t** ppxIdleTaskStackBuffer, + uint32_t* pulIdleTaskStackSize) { + *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; + *ppxIdleTaskStackBuffer = &xIdleStack[0]; + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; + /* place for user code */ +} /* USER CODE END GET_IDLE_TASK_MEMORY */ /* USER CODE BEGIN GET_TIMER_TASK_MEMORY */ static StaticTask_t xTimerTaskTCBBuffer; static StackType_t xTimerStack[configTIMER_TASK_STACK_DEPTH]; - -void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) -{ - *ppxTimerTaskTCBBuffer = &xTimerTaskTCBBuffer; - *ppxTimerTaskStackBuffer = &xTimerStack[0]; - *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; - /* place for user code */ -} + +void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer, + StackType_t** ppxTimerTaskStackBuffer, + uint32_t* pulTimerTaskStackSize) { + *ppxTimerTaskTCBBuffer = &xTimerTaskTCBBuffer; + *ppxTimerTaskStackBuffer = &xTimerStack[0]; + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; + /* place for user code */ +} /* USER CODE END GET_TIMER_TASK_MEMORY */ /* Private application code --------------------------------------------------*/ @@ -111,7 +116,7 @@ bool task_equal(TaskHandle_t a, TaskHandle_t b) { return a == b; } - + /* USER CODE END Application */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/target_f2/Src/main.c b/target_f2/Src/main.c index 043247c9..ce711c15 100644 --- a/target_f2/Src/main.c +++ b/target_f2/Src/main.c @@ -72,7 +72,7 @@ static void MX_TIM5_Init(void); static void MX_TIM15_Init(void); static void MX_USART1_UART_Init(void); static void MX_TIM8_Init(void); -void StartDefaultTask(void const * argument); +void StartDefaultTask(void const* argument); /* USER CODE BEGIN PFP */ @@ -87,144 +87,136 @@ void StartDefaultTask(void const * argument); * @brief The application entry point. * @retval int */ -int main(void) -{ - /* USER CODE BEGIN 1 */ +int main(void) { + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ - + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_SPI1_Init(); - MX_SPI3_Init(); - MX_ADC1_Init(); - MX_COMP1_Init(); - MX_TIM5_Init(); - MX_TIM15_Init(); - MX_USART1_UART_Init(); - MX_TIM8_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_SPI1_Init(); + MX_SPI3_Init(); + MX_ADC1_Init(); + MX_COMP1_Init(); + MX_TIM5_Init(); + MX_TIM15_Init(); + MX_USART1_UART_Init(); + MX_TIM8_Init(); + /* USER CODE BEGIN 2 */ - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* USER CODE BEGIN RTOS_MUTEX */ - /* add mutexes, ... */ - /* USER CODE END RTOS_MUTEX */ + /* USER CODE BEGIN RTOS_MUTEX */ + /* add mutexes, ... */ + /* USER CODE END RTOS_MUTEX */ - /* USER CODE BEGIN RTOS_SEMAPHORES */ - /* add semaphores, ... */ - /* USER CODE END RTOS_SEMAPHORES */ + /* USER CODE BEGIN RTOS_SEMAPHORES */ + /* add semaphores, ... */ + /* USER CODE END RTOS_SEMAPHORES */ - /* USER CODE BEGIN RTOS_TIMERS */ - /* start timers, add new ones, ... */ - /* USER CODE END RTOS_TIMERS */ + /* USER CODE BEGIN RTOS_TIMERS */ + /* start timers, add new ones, ... */ + /* USER CODE END RTOS_TIMERS */ - /* USER CODE BEGIN RTOS_QUEUES */ - /* add queues, ... */ - /* USER CODE END RTOS_QUEUES */ + /* USER CODE BEGIN RTOS_QUEUES */ + /* add queues, ... */ + /* USER CODE END RTOS_QUEUES */ - /* Create the thread(s) */ - /* definition and creation of defaultTask */ - osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 1024); - defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); + /* Create the thread(s) */ + /* definition and creation of defaultTask */ + osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 1024); + defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); - /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ - /* USER CODE END RTOS_THREADS */ + /* USER CODE BEGIN RTOS_THREADS */ + /* add threads, ... */ + /* USER CODE END RTOS_THREADS */ - /* Start scheduler */ - osKernelStart(); - - /* We should never get here as control is now taken by the scheduler */ + /* Start scheduler */ + osKernelStart(); - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - /* USER CODE END WHILE */ + /* We should never get here as control is now taken by the scheduler */ - /* USER CODE BEGIN 3 */ - } - /* USER CODE END 3 */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while(1) { + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + } + /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; +void SystemClock_Config(void) { + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - /** Initializes the CPU, AHB and APB busses clocks + /** Initializes the CPU, AHB and APB busses clocks */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 2; - RCC_OscInitStruct.PLL.PLLN = 16; - 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) - { - Error_Handler(); - } - /** Initializes the CPU, AHB and APB busses clocks + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 2; + RCC_OscInitStruct.PLL.PLLN = 16; + 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) { + 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.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + 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) - { - Error_Handler(); - } - 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; - PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE; - PeriphClkInit.PLLSAI1.PLLSAI1M = 2; - PeriphClkInit.PLLSAI1.PLLSAI1N = 12; - PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7; - 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) - { - Error_Handler(); - } - /** Configure the main internal regulator output voltage + 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.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2; + PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1; + PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE; + PeriphClkInit.PLLSAI1.PLLSAI1M = 2; + PeriphClkInit.PLLSAI1.PLLSAI1N = 12; + PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7; + 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) { + Error_Handler(); + } + /** Configure the main internal regulator output voltage */ - if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) - { - Error_Handler(); - } + if(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) { + Error_Handler(); + } } /** @@ -232,63 +224,57 @@ 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 BEGIN ADC1_Init 0 */ + /* USER CODE END ADC1_Init 0 */ - /* USER CODE END ADC1_Init 0 */ + ADC_MultiModeTypeDef multimode = {0}; + ADC_ChannelConfTypeDef sConfig = {0}; - ADC_MultiModeTypeDef multimode = {0}; - ADC_ChannelConfTypeDef sConfig = {0}; + /* USER CODE BEGIN ADC1_Init 1 */ - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - /** Common config + /* USER CODE END ADC1_Init 1 */ + /** Common config */ - hadc1.Instance = ADC1; - hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; - hadc1.Init.Resolution = ADC_RESOLUTION_12B; - hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; - hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; - hadc1.Init.LowPowerAutoWait = DISABLE; - hadc1.Init.ContinuousConvMode = DISABLE; - hadc1.Init.NbrOfConversion = 1; - hadc1.Init.DiscontinuousConvMode = DISABLE; - hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; - hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; - hadc1.Init.DMAContinuousRequests = DISABLE; - hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; - hadc1.Init.OversamplingMode = DISABLE; - if (HAL_ADC_Init(&hadc1) != HAL_OK) - { - Error_Handler(); - } - /** Configure the ADC multi-mode + hadc1.Instance = ADC1; + hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; + hadc1.Init.Resolution = ADC_RESOLUTION_12B; + hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; + hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + hadc1.Init.LowPowerAutoWait = DISABLE; + hadc1.Init.ContinuousConvMode = DISABLE; + hadc1.Init.NbrOfConversion = 1; + hadc1.Init.DiscontinuousConvMode = DISABLE; + hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc1.Init.DMAContinuousRequests = DISABLE; + hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; + hadc1.Init.OversamplingMode = DISABLE; + 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) - { - Error_Handler(); - } - /** Configure Regular Channel + multimode.Mode = ADC_MODE_INDEPENDENT; + if(HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) { + Error_Handler(); + } + /** Configure Regular Channel */ - sConfig.Channel = ADC_CHANNEL_4; - sConfig.Rank = ADC_REGULAR_RANK_1; - sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5; - sConfig.SingleDiff = ADC_SINGLE_ENDED; - sConfig.OffsetNumber = ADC_OFFSET_NONE; - sConfig.Offset = 0; - if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ + sConfig.Channel = ADC_CHANNEL_4; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5; + sConfig.SingleDiff = ADC_SINGLE_ENDED; + sConfig.OffsetNumber = ADC_OFFSET_NONE; + sConfig.Offset = 0; + if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN ADC1_Init 2 */ + /* USER CODE END ADC1_Init 2 */ } /** @@ -296,33 +282,29 @@ 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 BEGIN COMP1_Init 0 */ + /* USER CODE END COMP1_Init 0 */ - /* USER CODE END COMP1_Init 0 */ + /* USER CODE BEGIN COMP1_Init 1 */ - /* USER CODE BEGIN COMP1_Init 1 */ - - /* USER CODE END COMP1_Init 1 */ - hcomp1.Instance = COMP1; - hcomp1.Init.InvertingInput = COMP_INPUT_MINUS_1_2VREFINT; - hcomp1.Init.NonInvertingInput = COMP_INPUT_PLUS_IO1; - hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; - hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE; - hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN COMP1_Init 2 */ - - /* USER CODE END COMP1_Init 2 */ + /* USER CODE END COMP1_Init 1 */ + hcomp1.Instance = COMP1; + hcomp1.Init.InvertingInput = COMP_INPUT_MINUS_1_2VREFINT; + hcomp1.Init.NonInvertingInput = COMP_INPUT_PLUS_IO1; + hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; + hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE; + hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN COMP1_Init 2 */ + /* USER CODE END COMP1_Init 2 */ } /** @@ -330,39 +312,35 @@ 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 BEGIN SPI1_Init 0 */ + /* USER CODE END SPI1_Init 0 */ - /* USER CODE END SPI1_Init 0 */ + /* USER CODE BEGIN SPI1_Init 1 */ - /* USER CODE BEGIN SPI1_Init 1 */ - - /* USER CODE END SPI1_Init 1 */ - /* SPI1 parameter configuration*/ - hspi1.Instance = SPI1; - hspi1.Init.Mode = SPI_MODE_MASTER; - hspi1.Init.Direction = SPI_DIRECTION_2LINES; - hspi1.Init.DataSize = SPI_DATASIZE_8BIT; - hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi1.Init.NSS = SPI_NSS_SOFT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; - hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi1.Init.TIMode = SPI_TIMODE_DISABLE; - hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN SPI1_Init 2 */ - - /* USER CODE END SPI1_Init 2 */ + /* USER CODE END SPI1_Init 1 */ + /* SPI1 parameter configuration*/ + hspi1.Instance = SPI1; + hspi1.Init.Mode = SPI_MODE_MASTER; + hspi1.Init.Direction = SPI_DIRECTION_2LINES; + hspi1.Init.DataSize = SPI_DATASIZE_8BIT; + hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi1.Init.NSS = SPI_NSS_SOFT; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; + hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi1.Init.TIMode = SPI_TIMODE_DISABLE; + hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN SPI1_Init 2 */ + /* USER CODE END SPI1_Init 2 */ } /** @@ -370,39 +348,35 @@ 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 BEGIN SPI3_Init 0 */ + /* USER CODE END SPI3_Init 0 */ - /* USER CODE END SPI3_Init 0 */ + /* USER CODE BEGIN SPI3_Init 1 */ - /* USER CODE BEGIN SPI3_Init 1 */ - - /* USER CODE END SPI3_Init 1 */ - /* SPI3 parameter configuration*/ - hspi3.Instance = SPI3; - hspi3.Init.Mode = SPI_MODE_MASTER; - hspi3.Init.Direction = SPI_DIRECTION_2LINES; - hspi3.Init.DataSize = SPI_DATASIZE_8BIT; - hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi3.Init.NSS = SPI_NSS_SOFT; - hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; - hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi3.Init.TIMode = SPI_TIMODE_DISABLE; - hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN SPI3_Init 2 */ - - /* USER CODE END SPI3_Init 2 */ + /* USER CODE END SPI3_Init 1 */ + /* SPI3 parameter configuration*/ + hspi3.Instance = SPI3; + hspi3.Init.Mode = SPI_MODE_MASTER; + hspi3.Init.Direction = SPI_DIRECTION_2LINES; + hspi3.Init.DataSize = SPI_DATASIZE_8BIT; + hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi3.Init.NSS = SPI_NSS_SOFT; + hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; + hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi3.Init.TIMode = SPI_TIMODE_DISABLE; + hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN SPI3_Init 2 */ + /* USER CODE END SPI3_Init 2 */ } /** @@ -410,48 +384,42 @@ 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 BEGIN TIM5_Init 0 */ + /* USER CODE END TIM5_Init 0 */ - /* USER CODE END TIM5_Init 0 */ + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_OC_InitTypeDef sConfigOC = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_OC_InitTypeDef sConfigOC = {0}; + /* USER CODE BEGIN TIM5_Init 1 */ - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 500 - 1; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - 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) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ - - /* USER CODE END TIM5_Init 2 */ - HAL_TIM_MspPostInit(&htim5); + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 500 - 1; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + 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) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + HAL_TIM_MspPostInit(&htim5); } /** @@ -459,59 +427,51 @@ 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 BEGIN TIM8_Init 0 */ + /* USER CODE END TIM8_Init 0 */ - /* USER CODE END TIM8_Init 0 */ + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_IC_InitTypeDef sConfigIC = {0}; - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_IC_InitTypeDef sConfigIC = {0}; + /* USER CODE BEGIN TIM8_Init 1 */ - /* USER CODE BEGIN TIM8_Init 1 */ - - /* USER CODE END TIM8_Init 1 */ - htim8.Instance = TIM8; - htim8.Init.Prescaler = 64-1; - htim8.Init.CounterMode = TIM_COUNTERMODE_UP; - htim8.Init.Period = 32768-1; - 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) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - 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) - { - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM8_Init 2 */ - - /* USER CODE END TIM8_Init 2 */ + /* USER CODE END TIM8_Init 1 */ + htim8.Instance = TIM8; + htim8.Init.Prescaler = 64 - 1; + htim8.Init.CounterMode = TIM_COUNTERMODE_UP; + htim8.Init.Period = 32768 - 1; + 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) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if(HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + 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) { + 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) { + Error_Handler(); + } + /* USER CODE BEGIN TIM8_Init 2 */ + /* USER CODE END TIM8_Init 2 */ } /** @@ -519,68 +479,60 @@ 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 BEGIN TIM15_Init 0 */ + /* USER CODE END TIM15_Init 0 */ - /* USER CODE END TIM15_Init 0 */ + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_OC_InitTypeDef sConfigOC = {0}; + TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_OC_InitTypeDef sConfigOC = {0}; - TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; + /* USER CODE BEGIN TIM15_Init 1 */ - /* USER CODE BEGIN TIM15_Init 1 */ - - /* USER CODE END TIM15_Init 1 */ - htim15.Instance = TIM15; - htim15.Init.Prescaler = 0; - htim15.Init.CounterMode = TIM_COUNTERMODE_UP; - htim15.Init.Period = 0; - 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) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - sConfigOC.OCMode = TIM_OCMODE_TIMING; - sConfigOC.Pulse = 0; - sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; - 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) - { - Error_Handler(); - } - if (HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) - { - Error_Handler(); - } - sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; - sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; - sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; - sBreakDeadTimeConfig.DeadTime = 0; - sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; - sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; - sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; - 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); + /* USER CODE END TIM15_Init 1 */ + htim15.Instance = TIM15; + htim15.Init.Prescaler = 0; + htim15.Init.CounterMode = TIM_COUNTERMODE_UP; + htim15.Init.Period = 0; + 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) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if(HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + sConfigOC.OCMode = TIM_OCMODE_TIMING; + sConfigOC.Pulse = 0; + sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; + sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; + 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) { + Error_Handler(); + } + if(HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) { + Error_Handler(); + } + sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; + sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; + sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; + sBreakDeadTimeConfig.DeadTime = 0; + sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; + sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; + sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; + 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,34 +540,30 @@ 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 BEGIN USART1_Init 0 */ + /* USER CODE END USART1_Init 0 */ - /* USER CODE END USART1_Init 0 */ + /* USER CODE BEGIN USART1_Init 1 */ - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - huart1.Instance = USART1; - huart1.Init.BaudRate = 115200; - huart1.Init.WordLength = UART_WORDLENGTH_8B; - huart1.Init.StopBits = UART_STOPBITS_1; - huart1.Init.Parity = UART_PARITY_NONE; - huart1.Init.Mode = UART_MODE_TX_RX; - huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - 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) - { - Error_Handler(); - } - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ + /* USER CODE END USART1_Init 1 */ + huart1.Instance = USART1; + huart1.Init.BaudRate = 115200; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + 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) { + Error_Handler(); + } + /* USER CODE BEGIN USART1_Init 2 */ + /* USER CODE END USART1_Init 2 */ } /** @@ -623,143 +571,141 @@ static void MX_USART1_UART_Init(void) * @param None * @retval None */ -static void MX_GPIO_Init(void) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; +static void MX_GPIO_Init(void) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOH_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOA, DISPLAY_DI_Pin|CC1101_CS_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOA, DISPLAY_DI_Pin | CC1101_CS_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, NFC_CS_Pin|VIBRO_Pin|DISPLAY_CS_Pin|SD_CS_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOC, NFC_CS_Pin | VIBRO_Pin | DISPLAY_CS_Pin | SD_CS_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, LED_BLUE_Pin|LED_GREEN_Pin, GPIO_PIN_SET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, LED_BLUE_Pin | LED_GREEN_Pin, GPIO_PIN_SET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, DISPLAY_RST_Pin|IR_TX_Pin|DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, DISPLAY_RST_Pin | IR_TX_Pin | DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET); - /*Configure GPIO pin : BUTTON_BACK_Pin */ - GPIO_InitStruct.Pin = BUTTON_BACK_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : BUTTON_BACK_Pin */ + GPIO_InitStruct.Pin = BUTTON_BACK_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pins : PC0 PC1 */ - GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + /*Configure GPIO pins : PC0 PC1 */ + GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - /*Configure GPIO pin : CHRG_Pin */ - GPIO_InitStruct.Pin = CHRG_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(CHRG_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : CHRG_Pin */ + GPIO_InitStruct.Pin = CHRG_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLUP; + HAL_GPIO_Init(CHRG_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pin : BUTTON_DOWN_Pin */ - GPIO_InitStruct.Pin = BUTTON_DOWN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - HAL_GPIO_Init(BUTTON_DOWN_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : BUTTON_DOWN_Pin */ + GPIO_InitStruct.Pin = BUTTON_DOWN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(BUTTON_DOWN_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pins : DISPLAY_DI_Pin CC1101_CS_Pin */ - GPIO_InitStruct.Pin = DISPLAY_DI_Pin|CC1101_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /*Configure GPIO pins : DISPLAY_DI_Pin CC1101_CS_Pin */ + GPIO_InitStruct.Pin = DISPLAY_DI_Pin | CC1101_CS_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /*Configure GPIO pins : PA4 PA5 PA6 PA7 */ - GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /*Configure GPIO pins : PA4 PA5 PA6 PA7 */ + GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /*Configure GPIO pins : NFC_CS_Pin VIBRO_Pin DISPLAY_CS_Pin SD_CS_Pin */ - GPIO_InitStruct.Pin = NFC_CS_Pin|VIBRO_Pin|DISPLAY_CS_Pin|SD_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + /*Configure GPIO pins : NFC_CS_Pin VIBRO_Pin DISPLAY_CS_Pin SD_CS_Pin */ + GPIO_InitStruct.Pin = NFC_CS_Pin | VIBRO_Pin | DISPLAY_CS_Pin | SD_CS_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - /*Configure GPIO pins : BUTTON_UP_Pin BUTTON_RIGHT_Pin BUTTON_OK_Pin */ - GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_RIGHT_Pin|BUTTON_OK_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pins : BUTTON_UP_Pin BUTTON_RIGHT_Pin BUTTON_OK_Pin */ + GPIO_InitStruct.Pin = BUTTON_UP_Pin | BUTTON_RIGHT_Pin | BUTTON_OK_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pins : LED_BLUE_Pin LED_GREEN_Pin */ - GPIO_InitStruct.Pin = LED_BLUE_Pin|LED_GREEN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pins : LED_BLUE_Pin LED_GREEN_Pin */ + GPIO_InitStruct.Pin = LED_BLUE_Pin | LED_GREEN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pins : PB2 PB12 */ - GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pins : PB2 PB12 */ + GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pins : DISPLAY_RST_Pin IR_TX_Pin DISPLAY_BACKLIGHT_Pin */ - GPIO_InitStruct.Pin = DISPLAY_RST_Pin|IR_TX_Pin|DISPLAY_BACKLIGHT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pins : DISPLAY_RST_Pin IR_TX_Pin DISPLAY_BACKLIGHT_Pin */ + GPIO_InitStruct.Pin = DISPLAY_RST_Pin | IR_TX_Pin | DISPLAY_BACKLIGHT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pin : LED_RED_Pin */ - GPIO_InitStruct.Pin = LED_RED_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : LED_RED_Pin */ + GPIO_InitStruct.Pin = LED_RED_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pin : PD2 */ - GPIO_InitStruct.Pin = GPIO_PIN_2; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + /*Configure GPIO pin : PD2 */ + GPIO_InitStruct.Pin = GPIO_PIN_2; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - /*Configure GPIO pin : BUTTON_LEFT_Pin */ - GPIO_InitStruct.Pin = BUTTON_LEFT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - HAL_GPIO_Init(BUTTON_LEFT_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : BUTTON_LEFT_Pin */ + GPIO_InitStruct.Pin = BUTTON_LEFT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(BUTTON_LEFT_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pin : CC1101_G0_Pin */ - GPIO_InitStruct.Pin = CC1101_G0_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : CC1101_G0_Pin */ + GPIO_InitStruct.Pin = CC1101_G0_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct); - /* EXTI interrupt init*/ - HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI0_IRQn); + /* EXTI interrupt init*/ + HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI0_IRQn); - HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI1_IRQn); + HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI1_IRQn); - HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI2_IRQn); + HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI2_IRQn); - HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI4_IRQn); - - HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); + HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI4_IRQn); + HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); } /* USER CODE BEGIN 4 */ @@ -773,34 +719,31 @@ void app(); * @retval None */ /* USER CODE END Header_StartDefaultTask */ -void StartDefaultTask(void const * argument) -{ - /* init code for USB_DEVICE */ - MX_USB_DEVICE_Init(); - /* USER CODE BEGIN 5 */ - /* Infinite loop */ - app(); - - for(;;) - { - osDelay(1); - } - /* USER CODE END 5 */ +void StartDefaultTask(void const* argument) { + /* init code for USB_DEVICE */ + MX_USB_DEVICE_Init(); + /* USER CODE BEGIN 5 */ + /* Infinite loop */ + app(); + + for(;;) { + osDelay(1); + } + /* USER CODE END 5 */ } /** * @brief This function is executed in case of error occurrence. * @retval None */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ +void Error_Handler(void) { + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. @@ -808,12 +751,11 @@ void Error_Handler(void) * @param line: assert_param error line source number * @retval None */ -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, +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) */ - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/target_f2/Src/stm32l4xx_hal_msp.c b/target_f2/Src/stm32l4xx_hal_msp.c index 310cd309..86f8aa9e 100644 --- a/target_f2/Src/stm32l4xx_hal_msp.c +++ b/target_f2/Src/stm32l4xx_hal_msp.c @@ -32,7 +32,7 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN Define */ - + /* USER CODE END Define */ /* Private macro -------------------------------------------------------------*/ @@ -58,27 +58,26 @@ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ - -void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); - /** + +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim); +/** * Initializes the Global MSP. */ -void HAL_MspInit(void) -{ - /* USER CODE BEGIN MspInit 0 */ +void HAL_MspInit(void) { + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ - /* PendSV_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); + /* System interrupt init*/ + /* PendSV_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /** @@ -87,38 +86,35 @@ void HAL_MspInit(void) * @param hadc: ADC handle pointer * @retval None */ -void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hadc->Instance==ADC1) - { - /* USER CODE BEGIN ADC1_MspInit 0 */ +void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hadc->Instance == ADC1) { + /* USER CODE BEGIN ADC1_MspInit 0 */ - /* USER CODE END ADC1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_ADC_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**ADC1 GPIO Configuration + /* USER CODE END ADC1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_ADC_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**ADC1 GPIO Configuration PC3 ------> ADC1_IN4 PA0 ------> ADC1_IN5 */ - GPIO_InitStruct.Pin = BATT_V_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(BATT_V_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = BATT_V_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(BATT_V_GPIO_Port, &GPIO_InitStruct); - GPIO_InitStruct.Pin = IR_RX_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(IR_RX_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = IR_RX_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(IR_RX_GPIO_Port, &GPIO_InitStruct); - /* USER CODE BEGIN ADC1_MspInit 1 */ - - /* USER CODE END ADC1_MspInit 1 */ - } + /* USER CODE BEGIN ADC1_MspInit 1 */ + /* USER CODE END ADC1_MspInit 1 */ + } } /** @@ -127,29 +123,26 @@ 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) - { - /* USER CODE BEGIN ADC1_MspDeInit 0 */ +void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) { + if(hadc->Instance == ADC1) { + /* USER CODE BEGIN ADC1_MspDeInit 0 */ - /* USER CODE END ADC1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_ADC_CLK_DISABLE(); - - /**ADC1 GPIO Configuration + /* USER CODE END ADC1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_ADC_CLK_DISABLE(); + + /**ADC1 GPIO Configuration PC3 ------> ADC1_IN4 PA0 ------> ADC1_IN5 */ - HAL_GPIO_DeInit(BATT_V_GPIO_Port, BATT_V_Pin); + HAL_GPIO_DeInit(BATT_V_GPIO_Port, BATT_V_Pin); - HAL_GPIO_DeInit(IR_RX_GPIO_Port, IR_RX_Pin); + HAL_GPIO_DeInit(IR_RX_GPIO_Port, IR_RX_Pin); - /* USER CODE BEGIN ADC1_MspDeInit 1 */ - - /* USER CODE END ADC1_MspDeInit 1 */ - } + /* USER CODE BEGIN ADC1_MspDeInit 1 */ + /* USER CODE END ADC1_MspDeInit 1 */ + } } /** @@ -158,29 +151,26 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) * @param hcomp: COMP handle pointer * @retval None */ -void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hcomp->Instance==COMP1) - { - /* USER CODE BEGIN COMP1_MspInit 0 */ +void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hcomp->Instance == COMP1) { + /* USER CODE BEGIN COMP1_MspInit 0 */ - /* USER CODE END COMP1_MspInit 0 */ - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**COMP1 GPIO Configuration + /* USER CODE END COMP1_MspInit 0 */ + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**COMP1 GPIO Configuration PC5 ------> COMP1_INP */ - GPIO_InitStruct.Pin = RFID_RF_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = RFID_RF_IN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct); - /* USER CODE BEGIN COMP1_MspInit 1 */ - - /* USER CODE END COMP1_MspInit 1 */ - } + /* USER CODE BEGIN COMP1_MspInit 1 */ + /* USER CODE END COMP1_MspInit 1 */ + } } /** @@ -189,24 +179,21 @@ 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) - { - /* USER CODE BEGIN COMP1_MspDeInit 0 */ +void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp) { + if(hcomp->Instance == COMP1) { + /* USER CODE BEGIN COMP1_MspDeInit 0 */ - /* USER CODE END COMP1_MspDeInit 0 */ - - /**COMP1 GPIO Configuration + /* USER CODE END COMP1_MspDeInit 0 */ + + /**COMP1 GPIO Configuration PC5 ------> COMP1_INP */ - HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin); + HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin); - /* USER CODE BEGIN COMP1_MspDeInit 1 */ - - /* USER CODE END COMP1_MspDeInit 1 */ - } + /* USER CODE BEGIN COMP1_MspDeInit 1 */ + /* USER CODE END COMP1_MspDeInit 1 */ + } } /** @@ -215,59 +202,54 @@ void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp) * @param hspi: SPI handle pointer * @retval None */ -void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hspi->Instance==SPI1) - { - /* USER CODE BEGIN SPI1_MspInit 0 */ +void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hspi->Instance == SPI1) { + /* USER CODE BEGIN SPI1_MspInit 0 */ - /* USER CODE END SPI1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_SPI1_CLK_ENABLE(); - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**SPI1 GPIO Configuration + /* USER CODE END SPI1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_SPI1_CLK_ENABLE(); + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**SPI1 GPIO Configuration PB3 (JTDO-TRACESWO) ------> SPI1_SCK PB5 ------> SPI1_MOSI */ - GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_5; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_3 | GPIO_PIN_5; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /* USER CODE BEGIN SPI1_MspInit 1 */ + /* USER CODE BEGIN SPI1_MspInit 1 */ - /* USER CODE END SPI1_MspInit 1 */ - } - else if(hspi->Instance==SPI3) - { - /* USER CODE BEGIN SPI3_MspInit 0 */ + /* USER CODE END SPI1_MspInit 1 */ + } else if(hspi->Instance == SPI3) { + /* USER CODE BEGIN SPI3_MspInit 0 */ - /* USER CODE END SPI3_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_SPI3_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**SPI3 GPIO Configuration + /* USER CODE END SPI3_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_SPI3_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**SPI3 GPIO Configuration PC10 ------> SPI3_SCK PC11 ------> SPI3_MISO PC12 ------> SPI3_MOSI */ - GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - /* USER CODE BEGIN SPI3_MspInit 1 */ - - /* USER CODE END SPI3_MspInit 1 */ - } + /* USER CODE BEGIN SPI3_MspInit 1 */ + /* USER CODE END SPI3_MspInit 1 */ + } } /** @@ -276,46 +258,41 @@ 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) - { - /* USER CODE BEGIN SPI1_MspDeInit 0 */ +void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) { + if(hspi->Instance == SPI1) { + /* USER CODE BEGIN SPI1_MspDeInit 0 */ - /* USER CODE END SPI1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI1_CLK_DISABLE(); - - /**SPI1 GPIO Configuration + /* USER CODE END SPI1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI1_CLK_DISABLE(); + + /**SPI1 GPIO Configuration PB3 (JTDO-TRACESWO) ------> SPI1_SCK PB5 ------> SPI1_MOSI */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_5); + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3 | GPIO_PIN_5); - /* USER CODE BEGIN SPI1_MspDeInit 1 */ + /* USER CODE BEGIN SPI1_MspDeInit 1 */ - /* USER CODE END SPI1_MspDeInit 1 */ - } - else if(hspi->Instance==SPI3) - { - /* USER CODE BEGIN SPI3_MspDeInit 0 */ + /* USER CODE END SPI1_MspDeInit 1 */ + } else if(hspi->Instance == SPI3) { + /* USER CODE BEGIN SPI3_MspDeInit 0 */ - /* USER CODE END SPI3_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI3_CLK_DISABLE(); - - /**SPI3 GPIO Configuration + /* USER CODE END SPI3_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI3_CLK_DISABLE(); + + /**SPI3 GPIO Configuration PC10 ------> SPI3_SCK PC11 ------> SPI3_MISO PC12 ------> SPI3_MOSI */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12); - /* USER CODE BEGIN SPI3_MspDeInit 1 */ - - /* USER CODE END SPI3_MspDeInit 1 */ - } + /* USER CODE BEGIN SPI3_MspDeInit 1 */ + /* USER CODE END SPI3_MspDeInit 1 */ + } } /** @@ -324,20 +301,17 @@ 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) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ +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 */ - /* Peripheral clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); - /* USER CODE BEGIN TIM5_MspInit 1 */ - - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE BEGIN TIM5_MspInit 1 */ + /* USER CODE END TIM5_MspInit 1 */ + } } /** @@ -346,36 +320,33 @@ 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) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(htim_base->Instance==TIM8) - { - /* USER CODE BEGIN TIM8_MspInit 0 */ +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(htim_base->Instance == TIM8) { + /* USER CODE BEGIN TIM8_MspInit 0 */ - /* USER CODE END TIM8_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_TIM8_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**TIM8 GPIO Configuration + /* USER CODE END TIM8_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM8_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**TIM8 GPIO Configuration PC7 ------> TIM8_CH2 */ - GPIO_InitStruct.Pin = iButton_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; - GPIO_InitStruct.Alternate = GPIO_AF3_TIM8; - HAL_GPIO_Init(iButton_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = iButton_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + GPIO_InitStruct.Alternate = GPIO_AF3_TIM8; + HAL_GPIO_Init(iButton_GPIO_Port, &GPIO_InitStruct); - /* TIM8 interrupt Init */ - HAL_NVIC_SetPriority(TIM8_CC_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(TIM8_CC_IRQn); - /* USER CODE BEGIN TIM8_MspInit 1 */ - - /* USER CODE END TIM8_MspInit 1 */ - } + /* TIM8 interrupt Init */ + HAL_NVIC_SetPriority(TIM8_CC_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(TIM8_CC_IRQn); + /* USER CODE BEGIN TIM8_MspInit 1 */ + /* USER CODE END TIM8_MspInit 1 */ + } } /** @@ -384,68 +355,60 @@ 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) - { - /* USER CODE BEGIN TIM15_MspInit 0 */ +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 */ - /* Peripheral clock enable */ - __HAL_RCC_TIM15_CLK_ENABLE(); - /* USER CODE BEGIN TIM15_MspInit 1 */ - - /* USER CODE END TIM15_MspInit 1 */ - } + /* USER CODE END TIM15_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM15_CLK_ENABLE(); + /* USER CODE BEGIN TIM15_MspInit 1 */ + /* USER CODE END TIM15_MspInit 1 */ + } } -void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(htim->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspPostInit 0 */ +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(htim->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspPostInit 0 */ - /* USER CODE END TIM5_MspPostInit 0 */ - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**TIM5 GPIO Configuration + /* USER CODE END TIM5_MspPostInit 0 */ + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**TIM5 GPIO Configuration PA3 ------> TIM5_CH4 */ - GPIO_InitStruct.Pin = SPEAKER_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF2_TIM5; - HAL_GPIO_Init(SPEAKER_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = SPEAKER_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF2_TIM5; + HAL_GPIO_Init(SPEAKER_GPIO_Port, &GPIO_InitStruct); - /* USER CODE BEGIN TIM5_MspPostInit 1 */ + /* USER CODE BEGIN TIM5_MspPostInit 1 */ - /* USER CODE END TIM5_MspPostInit 1 */ - } - else if(htim->Instance==TIM15) - { - /* USER CODE BEGIN TIM15_MspPostInit 0 */ + /* USER CODE END TIM5_MspPostInit 1 */ + } else if(htim->Instance == TIM15) { + /* USER CODE BEGIN TIM15_MspPostInit 0 */ - /* USER CODE END TIM15_MspPostInit 0 */ - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**TIM15 GPIO Configuration + /* USER CODE END TIM15_MspPostInit 0 */ + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**TIM15 GPIO Configuration PB13 ------> TIM15_CH1N PB15 ------> TIM15_CH2 */ - GPIO_InitStruct.Pin = RFID_OUT_Pin|RFID_PULL_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF14_TIM15; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + GPIO_InitStruct.Pin = RFID_OUT_Pin | RFID_PULL_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF14_TIM15; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /* USER CODE BEGIN TIM15_MspPostInit 1 */ - - /* USER CODE END TIM15_MspPostInit 1 */ - } + /* USER CODE BEGIN TIM15_MspPostInit 1 */ + /* USER CODE END TIM15_MspPostInit 1 */ + } } /** * @brief TIM_PWM MSP De-Initialization @@ -453,20 +416,17 @@ 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) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ +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 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ - - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* USER CODE END TIM5_MspDeInit 1 */ + } } /** @@ -475,28 +435,25 @@ 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) - { - /* USER CODE BEGIN TIM8_MspDeInit 0 */ +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 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM8_CLK_DISABLE(); - - /**TIM8 GPIO Configuration + /* USER CODE END TIM8_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM8_CLK_DISABLE(); + + /**TIM8 GPIO Configuration PC7 ------> TIM8_CH2 */ - HAL_GPIO_DeInit(iButton_GPIO_Port, iButton_Pin); + HAL_GPIO_DeInit(iButton_GPIO_Port, iButton_Pin); - /* TIM8 interrupt DeInit */ - HAL_NVIC_DisableIRQ(TIM8_CC_IRQn); - /* USER CODE BEGIN TIM8_MspDeInit 1 */ - - /* USER CODE END TIM8_MspDeInit 1 */ - } + /* TIM8 interrupt DeInit */ + HAL_NVIC_DisableIRQ(TIM8_CC_IRQn); + /* USER CODE BEGIN TIM8_MspDeInit 1 */ + /* USER CODE END TIM8_MspDeInit 1 */ + } } /** @@ -505,20 +462,17 @@ 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) - { - /* USER CODE BEGIN TIM15_MspDeInit 0 */ +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 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM15_CLK_DISABLE(); - /* USER CODE BEGIN TIM15_MspDeInit 1 */ - - /* USER CODE END TIM15_MspDeInit 1 */ - } + /* USER CODE END TIM15_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM15_CLK_DISABLE(); + /* USER CODE BEGIN TIM15_MspDeInit 1 */ + /* USER CODE END TIM15_MspDeInit 1 */ + } } /** @@ -527,34 +481,31 @@ void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc) * @param huart: UART handle pointer * @retval None */ -void HAL_UART_MspInit(UART_HandleTypeDef* huart) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(huart->Instance==USART1) - { - /* USER CODE BEGIN USART1_MspInit 0 */ +void HAL_UART_MspInit(UART_HandleTypeDef* huart) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(huart->Instance == USART1) { + /* USER CODE BEGIN USART1_MspInit 0 */ - /* USER CODE END USART1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_USART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USART1 GPIO Configuration + /* USER CODE END USART1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_USART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ - GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF7_USART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF7_USART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /* USER CODE BEGIN USART1_MspInit 1 */ - - /* USER CODE END USART1_MspInit 1 */ - } + /* USER CODE BEGIN USART1_MspInit 1 */ + /* USER CODE END USART1_MspInit 1 */ + } } /** @@ -563,27 +514,24 @@ 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) - { - /* USER CODE BEGIN USART1_MspDeInit 0 */ +void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) { + if(huart->Instance == USART1) { + /* USER CODE BEGIN USART1_MspDeInit 0 */ - /* USER CODE END USART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USART1_CLK_DISABLE(); - - /**USART1 GPIO Configuration + /* USER CODE END USART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART1_CLK_DISABLE(); + + /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9 | GPIO_PIN_10); - /* USER CODE BEGIN USART1_MspDeInit 1 */ - - /* USER CODE END USART1_MspDeInit 1 */ - } + /* USER CODE BEGIN USART1_MspDeInit 1 */ + /* USER CODE END USART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ diff --git a/target_f2/Src/stm32l4xx_it.c b/target_f2/Src/stm32l4xx_it.c index 86a73024..6f86a1a7 100644 --- a/target_f2/Src/stm32l4xx_it.c +++ b/target_f2/Src/stm32l4xx_it.c @@ -34,7 +34,7 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ - + /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ @@ -65,114 +65,102 @@ extern TIM_HandleTypeDef htim8; /* USER CODE END EV */ /******************************************************************************/ -/* Cortex-M4 Processor Interruption and Exception Handlers */ +/* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** * @brief This function handles Non maskable interrupt. */ -void NMI_Handler(void) -{ - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ +void NMI_Handler(void) { + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** * @brief This function handles Hard fault interrupt. */ -void HardFault_Handler(void) -{ - /* USER CODE BEGIN HardFault_IRQn 0 */ +void HardFault_Handler(void) { + /* USER CODE BEGIN HardFault_IRQn 0 */ - /* USER CODE END HardFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_HardFault_IRQn 0 */ - /* USER CODE END W1_HardFault_IRQn 0 */ - } + /* USER CODE END HardFault_IRQn 0 */ + while(1) { + /* USER CODE BEGIN W1_HardFault_IRQn 0 */ + /* USER CODE END W1_HardFault_IRQn 0 */ + } } /** * @brief This function handles Memory management fault. */ -void MemManage_Handler(void) -{ - /* USER CODE BEGIN MemoryManagement_IRQn 0 */ +void MemManage_Handler(void) { + /* USER CODE BEGIN MemoryManagement_IRQn 0 */ - /* USER CODE END MemoryManagement_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ - /* USER CODE END W1_MemoryManagement_IRQn 0 */ - } + /* USER CODE END MemoryManagement_IRQn 0 */ + while(1) { + /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ + /* USER CODE END W1_MemoryManagement_IRQn 0 */ + } } /** * @brief This function handles Prefetch fault, memory access fault. */ -void BusFault_Handler(void) -{ - /* USER CODE BEGIN BusFault_IRQn 0 */ +void BusFault_Handler(void) { + /* USER CODE BEGIN BusFault_IRQn 0 */ - /* USER CODE END BusFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_BusFault_IRQn 0 */ - /* USER CODE END W1_BusFault_IRQn 0 */ - } + /* USER CODE END BusFault_IRQn 0 */ + while(1) { + /* USER CODE BEGIN W1_BusFault_IRQn 0 */ + /* USER CODE END W1_BusFault_IRQn 0 */ + } } /** * @brief This function handles Undefined instruction or illegal state. */ -void UsageFault_Handler(void) -{ - /* USER CODE BEGIN UsageFault_IRQn 0 */ +void UsageFault_Handler(void) { + /* USER CODE BEGIN UsageFault_IRQn 0 */ - /* USER CODE END UsageFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ - /* USER CODE END W1_UsageFault_IRQn 0 */ - } + /* USER CODE END UsageFault_IRQn 0 */ + while(1) { + /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ + /* USER CODE END W1_UsageFault_IRQn 0 */ + } } /** * @brief This function handles Debug monitor. */ -void DebugMon_Handler(void) -{ - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ +void DebugMon_Handler(void) { + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** * @brief This function handles System tick timer. */ -void SysTick_Handler(void) -{ - /* USER CODE BEGIN SysTick_IRQn 0 */ +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) - { + /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); +#if(INCLUDE_xTaskGetSchedulerState == 1) + if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { #endif /* INCLUDE_xTaskGetSchedulerState */ - xPortSysTickHandler(); -#if (INCLUDE_xTaskGetSchedulerState == 1 ) - } + xPortSysTickHandler(); +#if(INCLUDE_xTaskGetSchedulerState == 1) + } #endif /* INCLUDE_xTaskGetSchedulerState */ - /* USER CODE BEGIN SysTick_IRQn 1 */ + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -185,115 +173,105 @@ void SysTick_Handler(void) /** * @brief This function handles EXTI line0 interrupt. */ -void EXTI0_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI0_IRQn 0 */ +void EXTI0_IRQHandler(void) { + /* USER CODE BEGIN EXTI0_IRQn 0 */ - /* USER CODE END EXTI0_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); - /* USER CODE BEGIN EXTI0_IRQn 1 */ + /* USER CODE END EXTI0_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); + /* USER CODE BEGIN EXTI0_IRQn 1 */ - /* USER CODE END EXTI0_IRQn 1 */ + /* USER CODE END EXTI0_IRQn 1 */ } /** * @brief This function handles EXTI line1 interrupt. */ -void EXTI1_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI1_IRQn 0 */ +void EXTI1_IRQHandler(void) { + /* USER CODE BEGIN EXTI1_IRQn 0 */ - /* USER CODE END EXTI1_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1); - /* USER CODE BEGIN EXTI1_IRQn 1 */ + /* USER CODE END EXTI1_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1); + /* USER CODE BEGIN EXTI1_IRQn 1 */ - /* USER CODE END EXTI1_IRQn 1 */ + /* USER CODE END EXTI1_IRQn 1 */ } /** * @brief This function handles EXTI line2 interrupt. */ -void EXTI2_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI2_IRQn 0 */ +void EXTI2_IRQHandler(void) { + /* USER CODE BEGIN EXTI2_IRQn 0 */ - /* USER CODE END EXTI2_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); - /* USER CODE BEGIN EXTI2_IRQn 1 */ + /* USER CODE END EXTI2_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); + /* USER CODE BEGIN EXTI2_IRQn 1 */ - /* USER CODE END EXTI2_IRQn 1 */ + /* USER CODE END EXTI2_IRQn 1 */ } /** * @brief This function handles EXTI line4 interrupt. */ -void EXTI4_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI4_IRQn 0 */ +void EXTI4_IRQHandler(void) { + /* USER CODE BEGIN EXTI4_IRQn 0 */ - /* USER CODE END EXTI4_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4); - /* USER CODE BEGIN EXTI4_IRQn 1 */ + /* USER CODE END EXTI4_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4); + /* USER CODE BEGIN EXTI4_IRQn 1 */ - /* USER CODE END EXTI4_IRQn 1 */ + /* USER CODE END EXTI4_IRQn 1 */ } /** * @brief This function handles EXTI line[9:5] interrupts. */ -void EXTI9_5_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI9_5_IRQn 0 */ +void EXTI9_5_IRQHandler(void) { + /* USER CODE BEGIN EXTI9_5_IRQn 0 */ - /* USER CODE END EXTI9_5_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6); - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8); - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9); - /* USER CODE BEGIN EXTI9_5_IRQn 1 */ + /* USER CODE END EXTI9_5_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6); + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8); + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9); + /* USER CODE BEGIN EXTI9_5_IRQn 1 */ - /* USER CODE END EXTI9_5_IRQn 1 */ + /* USER CODE END EXTI9_5_IRQn 1 */ } -void(*tim8_callback_ch2)(uint16_t ccr, TimerEvent tim_event); +void (*tim8_callback_ch2)(uint16_t ccr, TimerEvent tim_event); -void register_tim8_callback_ch2(void(*callback)(uint16_t ccr, TimerEvent tim_event)) { - tim8_callback_ch2 = callback; +void register_tim8_callback_ch2(void (*callback)(uint16_t ccr, TimerEvent tim_event)) { + tim8_callback_ch2 = callback; } /** * @brief This function handles TIM8 capture compare interrupt. */ -void TIM8_CC_IRQHandler(void) -{ - /* USER CODE BEGIN TIM8_CC_IRQn 0 */ +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) - { - __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) - { -/* + /* 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) { + __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 (USE_HAL_TIM_REGISTER_CALLBACKS == 1) htim->IC_CaptureCallback(htim); #else HAL_TIM_IC_CaptureCallback(htim); #endif */ - if(tim8_callback_ch2 != NULL) { - tim8_callback_ch2(htim8.Instance->CCR2, TimerEventInputCapture); - } - } - /* Output compare event */ - else - { - if(tim8_callback_ch2 != NULL) { - tim8_callback_ch2(0, TimerEventEndOfPulse); - } -/* + if(tim8_callback_ch2 != NULL) { + tim8_callback_ch2(htim8.Instance->CCR2, TimerEventInputCapture); + } + } + /* Output compare event */ + else { + if(tim8_callback_ch2 != NULL) { + tim8_callback_ch2(0, TimerEventEndOfPulse); + } + /* #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) htim->OC_DelayElapsedCallback(htim); htim->PWM_PulseFinishedCallback(htim); @@ -302,31 +280,29 @@ void TIM8_CC_IRQHandler(void) HAL_TIM_PWM_PulseFinishedCallback(htim); #endif */ - } - htim8.Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; + } + htim8.Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; + } } - } + /* USER CODE END TIM8_CC_IRQn 0 */ + // HAL_TIM_IRQHandler(&htim8); + /* USER CODE BEGIN TIM8_CC_IRQn 1 */ - /* USER CODE END TIM8_CC_IRQn 0 */ - // HAL_TIM_IRQHandler(&htim8); - /* USER CODE BEGIN TIM8_CC_IRQn 1 */ - - /* USER CODE END TIM8_CC_IRQn 1 */ + /* USER CODE END TIM8_CC_IRQn 1 */ } /** * @brief This function handles USB OTG FS global interrupt. */ -void OTG_FS_IRQHandler(void) -{ - /* USER CODE BEGIN OTG_FS_IRQn 0 */ +void OTG_FS_IRQHandler(void) { + /* USER CODE BEGIN OTG_FS_IRQn 0 */ - /* USER CODE END OTG_FS_IRQn 0 */ - HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS); - /* USER CODE BEGIN OTG_FS_IRQn 1 */ + /* USER CODE END OTG_FS_IRQn 0 */ + HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS); + /* USER CODE BEGIN OTG_FS_IRQn 1 */ - /* USER CODE END OTG_FS_IRQn 1 */ + /* USER CODE END OTG_FS_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/target_f2/Src/system_stm32l4xx.c b/target_f2/Src/system_stm32l4xx.c index 1db59ec9..a16bf4c7 100644 --- a/target_f2/Src/system_stm32l4xx.c +++ b/target_f2/Src/system_stm32l4xx.c @@ -91,16 +91,16 @@ #include "stm32l4xx.h" -#if !defined (HSE_VALUE) - #define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */ +#if !defined(HSE_VALUE) +#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ -#if !defined (MSI_VALUE) - #define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/ +#if !defined(MSI_VALUE) +#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/ #endif /* MSI_VALUE */ -#if !defined (HSI_VALUE) - #define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ +#if !defined(HSI_VALUE) +#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /** @@ -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. */ /******************************************************************************/ /** @@ -141,7 +142,7 @@ /** @addtogroup STM32L4xx_System_Private_Variables * @{ */ - /* The SystemCoreClock variable is updated in three ways: +/* The SystemCoreClock variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency @@ -149,12 +150,22 @@ is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ - uint32_t SystemCoreClock = 4000000U; +uint32_t SystemCoreClock = 4000000U; - 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 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}; /** * @} */ @@ -177,37 +188,36 @@ * @retval None */ -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 */ - #endif +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 */ +#endif - /* Reset the RCC clock configuration to the default reset state ------------*/ - /* Set MSION bit */ - RCC->CR |= RCC_CR_MSION; + /* Reset the RCC clock configuration to the default reset state ------------*/ + /* Set MSION bit */ + RCC->CR |= RCC_CR_MSION; - /* Reset CFGR register */ - RCC->CFGR = 0x00000000U; + /* Reset CFGR register */ + RCC->CFGR = 0x00000000U; - /* Reset HSEON, CSSON , HSION, and PLLON bits */ - RCC->CR &= 0xEAF6FFFFU; + /* Reset HSEON, CSSON , HSION, and PLLON bits */ + RCC->CR &= 0xEAF6FFFFU; - /* Reset PLLCFGR register */ - RCC->PLLCFGR = 0x00001000U; + /* Reset PLLCFGR register */ + RCC->PLLCFGR = 0x00001000U; - /* Reset HSEBYP bit */ - RCC->CR &= 0xFFFBFFFFU; + /* Reset HSEBYP bit */ + RCC->CR &= 0xFFFBFFFFU; - /* Disable all interrupts */ - RCC->CIER = 0x00000000U; + /* Disable all interrupts */ + RCC->CIER = 0x00000000U; - /* Configure the Vector Table location add offset address ------------------*/ + /* Configure the Vector Table location add offset address ------------------*/ #ifdef VECT_TAB_SRAM - SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ + SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ #else - SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ + SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ #endif } @@ -253,75 +263,68 @@ void SystemInit(void) * @param None * @retval None */ -void SystemCoreClockUpdate(void) -{ - uint32_t tmp = 0U, msirange = 0U, pllvco = 0U, pllr = 2U, pllsource = 0U, pllm = 2U; +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 */ - msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U; - } - else - { /* MSIRANGE from RCC_CR applies */ - msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U; - } - /*MSI frequency range in HZ*/ - msirange = MSIRangeTable[msirange]; + /* Get MSI Range frequency--------------------------------------------------*/ + 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 */ + msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U; + } + /*MSI frequency range in HZ*/ + msirange = MSIRangeTable[msirange]; - /* Get SYSCLK source -------------------------------------------------------*/ - switch (RCC->CFGR & RCC_CFGR_SWS) - { - case 0x00: /* MSI used as system clock source */ - SystemCoreClock = msirange; - break; + /* Get SYSCLK source -------------------------------------------------------*/ + switch(RCC->CFGR & RCC_CFGR_SWS) { + case 0x00: /* MSI used as system clock source */ + SystemCoreClock = msirange; + break; - case 0x04: /* HSI used as system clock source */ - SystemCoreClock = HSI_VALUE; - break; + case 0x04: /* HSI used as system clock source */ + SystemCoreClock = HSI_VALUE; + break; - case 0x08: /* HSE used as system clock source */ - SystemCoreClock = HSE_VALUE; - break; + case 0x08: /* HSE used as system clock source */ + SystemCoreClock = HSE_VALUE; + break; - case 0x0C: /* PLL used as system clock source */ - /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN + case 0x0C: /* PLL used as system clock source */ + /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN SYSCLK = PLL_VCO / PLLR */ - pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); - pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U ; + pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); + pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U; - switch (pllsource) - { - case 0x02: /* HSI used as PLL clock source */ - pllvco = (HSI_VALUE / pllm); - break; + switch(pllsource) { + case 0x02: /* HSI used as PLL clock source */ + pllvco = (HSI_VALUE / pllm); + break; - case 0x03: /* HSE used as PLL clock source */ - pllvco = (HSE_VALUE / pllm); - break; + case 0x03: /* HSE used as PLL clock source */ + pllvco = (HSE_VALUE / pllm); + break; - default: /* MSI used as PLL clock source */ - pllvco = (msirange / pllm); - break; - } - pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U); - pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U; - SystemCoreClock = pllvco/pllr; - break; + default: /* MSI used as PLL clock source */ + pllvco = (msirange / pllm); + break; + } + pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U); + pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U; + SystemCoreClock = pllvco / pllr; + break; default: - SystemCoreClock = msirange; - break; - } - /* Compute HCLK clock frequency --------------------------------------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; - /* HCLK clock frequency */ - SystemCoreClock >>= tmp; + SystemCoreClock = msirange; + break; + } + /* Compute HCLK clock frequency --------------------------------------------*/ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; } - /** * @} */ diff --git a/target_f2/Src/usb_device.c b/target_f2/Src/usb_device.c index d34e67a1..3f9b99ee 100644 --- a/target_f2/Src/usb_device.c +++ b/target_f2/Src/usb_device.c @@ -63,32 +63,27 @@ extern USBD_DescriptorsTypeDef FS_Desc; * Init USB device Library, add supported class and start the library * @retval None */ -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) - { - Error_Handler(); - } - if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) - { - Error_Handler(); - } - if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) - { - Error_Handler(); - } - if (USBD_Start(&hUsbDeviceFS) != USBD_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ - - /* USER CODE END USB_DEVICE_Init_PostTreatment */ +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) { + Error_Handler(); + } + if(USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { + Error_Handler(); + } + if(USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { + Error_Handler(); + } + if(USBD_Start(&hUsbDeviceFS) != USBD_OK) { + Error_Handler(); + } + /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ + + /* USER CODE END USB_DEVICE_Init_PostTreatment */ } /** diff --git a/target_f2/Src/usbd_cdc_if.c b/target_f2/Src/usbd_cdc_if.c index 88144eab..0e2bdf65 100644 --- a/target_f2/Src/usbd_cdc_if.c +++ b/target_f2/Src/usbd_cdc_if.c @@ -65,8 +65,8 @@ /* USER CODE BEGIN PRIVATE_DEFINES */ /* Define size for the receive and transmit buffer over CDC */ /* It's up to user to redefine and/or remove those define */ -#define APP_RX_DATA_SIZE 2048 -#define APP_TX_DATA_SIZE 2048 +#define APP_RX_DATA_SIZE 2048 +#define APP_TX_DATA_SIZE 2048 /* USER CODE END PRIVATE_DEFINES */ /** @@ -129,7 +129,7 @@ extern USBD_HandleTypeDef hUsbDeviceFS; static int8_t CDC_Init_FS(void); static int8_t CDC_DeInit_FS(void); static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); -static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); +static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t* Len); /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ @@ -139,38 +139,33 @@ static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); * @} */ -USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = -{ - CDC_Init_FS, - CDC_DeInit_FS, - CDC_Control_FS, - CDC_Receive_FS -}; +USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = {CDC_Init_FS, + CDC_DeInit_FS, + CDC_Control_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) -{ - /* USER CODE BEGIN 3 */ - /* Set Application Buffers */ - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); - return (USBD_OK); - /* USER CODE END 3 */ +static int8_t CDC_Init_FS(void) { + /* USER CODE BEGIN 3 */ + /* Set Application Buffers */ + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); + USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); + return (USBD_OK); + /* USER CODE END 3 */ } /** * @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) -{ - /* USER CODE BEGIN 4 */ - return (USBD_OK); - /* USER CODE END 4 */ +static int8_t CDC_DeInit_FS(void) { + /* USER CODE BEGIN 4 */ + return (USBD_OK); + /* USER CODE END 4 */ } /** @@ -180,70 +175,68 @@ 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) -{ - /* USER CODE BEGIN 5 */ - switch(cmd) - { +static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) { + /* USER CODE BEGIN 5 */ + switch(cmd) { case CDC_SEND_ENCAPSULATED_COMMAND: - break; + break; case CDC_GET_ENCAPSULATED_RESPONSE: - break; + break; case CDC_SET_COMM_FEATURE: - break; + break; case CDC_GET_COMM_FEATURE: - break; + break; case CDC_CLEAR_COMM_FEATURE: - break; + break; - /*******************************************************************************/ - /* Line Coding Structure */ - /*-----------------------------------------------------------------------------*/ - /* Offset | Field | Size | Value | Description */ - /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ - /* 4 | bCharFormat | 1 | Number | Stop bits */ - /* 0 - 1 Stop bit */ - /* 1 - 1.5 Stop bits */ - /* 2 - 2 Stop bits */ - /* 5 | bParityType | 1 | Number | Parity */ - /* 0 - None */ - /* 1 - Odd */ - /* 2 - Even */ - /* 3 - Mark */ - /* 4 - Space */ - /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ - /*******************************************************************************/ + /*******************************************************************************/ + /* Line Coding Structure */ + /*-----------------------------------------------------------------------------*/ + /* Offset | Field | Size | Value | Description */ + /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ + /* 4 | bCharFormat | 1 | Number | Stop bits */ + /* 0 - 1 Stop bit */ + /* 1 - 1.5 Stop bits */ + /* 2 - 2 Stop bits */ + /* 5 | bParityType | 1 | Number | Parity */ + /* 0 - None */ + /* 1 - Odd */ + /* 2 - Even */ + /* 3 - Mark */ + /* 4 - Space */ + /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ + /*******************************************************************************/ case CDC_SET_LINE_CODING: - break; + break; case CDC_GET_LINE_CODING: - break; + break; case CDC_SET_CONTROL_LINE_STATE: - break; + break; case CDC_SEND_BREAK: - break; + break; - default: - break; - } + default: + break; + } - return (USBD_OK); - /* USER CODE END 5 */ + return (USBD_OK); + /* USER CODE END 5 */ } /** @@ -260,13 +253,12 @@ 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) -{ - /* USER CODE BEGIN 6 */ - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); - USBD_CDC_ReceivePacket(&hUsbDeviceFS); - return (USBD_OK); - /* USER CODE END 6 */ +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); + return (USBD_OK); + /* USER CODE END 6 */ } /** @@ -280,18 +272,17 @@ 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 result = USBD_OK; - /* USER CODE BEGIN 7 */ - USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; - if (hcdc->TxState != 0){ - return USBD_BUSY; - } - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); - result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); - /* USER CODE END 7 */ - return result; +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; + if(hcdc->TxState != 0) { + return USBD_BUSY; + } + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); + result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); + /* USER CODE END 7 */ + return result; } /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ diff --git a/target_f2/Src/usbd_conf.c b/target_f2/Src/usbd_conf.c index 077d3ac3..1d63512d 100644 --- a/target_f2/Src/usbd_conf.c +++ b/target_f2/Src/usbd_conf.c @@ -47,7 +47,7 @@ void Error_Handler(void); /* USER CODE END 0 */ /* Exported function prototypes ----------------------------------------------*/ -extern USBD_StatusTypeDef USBD_LL_BatteryCharging(USBD_HandleTypeDef *pdev); +extern USBD_StatusTypeDef USBD_LL_BatteryCharging(USBD_HandleTypeDef* pdev); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ @@ -67,86 +67,76 @@ extern void SystemClock_Config(void); *******************************************************************************/ /* MSP Init */ -void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(pcdHandle->Instance==USB_OTG_FS) - { - /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(pcdHandle->Instance == USB_OTG_FS) { + /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ - /* USER CODE END USB_OTG_FS_MspInit 0 */ - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USB_OTG_FS GPIO Configuration + /* USER CODE END USB_OTG_FS_MspInit 0 */ + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USB_OTG_FS GPIO Configuration PA11 ------> USB_OTG_FS_DM PA12 ------> USB_OTG_FS_DP */ - GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /* Peripheral clock enable */ - __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + /* Peripheral clock enable */ + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); - /* Enable VDDUSB */ - if(__HAL_RCC_PWR_IS_CLK_DISABLED()) - { - __HAL_RCC_PWR_CLK_ENABLE(); - HAL_PWREx_EnableVddUSB(); - __HAL_RCC_PWR_CLK_DISABLE(); + /* Enable VDDUSB */ + if(__HAL_RCC_PWR_IS_CLK_DISABLED()) { + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_PWREx_EnableVddUSB(); + __HAL_RCC_PWR_CLK_DISABLE(); + } else { + HAL_PWREx_EnableVddUSB(); + } + + /* Peripheral interrupt init */ + HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(OTG_FS_IRQn); + /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ + + /* USER CODE END USB_OTG_FS_MspInit 1 */ } - else - { - HAL_PWREx_EnableVddUSB(); - } - - /* Peripheral interrupt init */ - HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(OTG_FS_IRQn); - /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ - - /* USER CODE END USB_OTG_FS_MspInit 1 */ - } } -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) -{ - if(pcdHandle->Instance==USB_OTG_FS) - { - /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */ +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 */ - /* Peripheral clock disable */ - __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); - - /**USB_OTG_FS GPIO Configuration + /* USER CODE END USB_OTG_FS_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); + + /**USB_OTG_FS GPIO Configuration PA11 ------> USB_OTG_FS_DM PA12 ------> USB_OTG_FS_DP */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11 | GPIO_PIN_12); - /* Disable VDDUSB */ - if(__HAL_RCC_PWR_IS_CLK_DISABLED()) - { - __HAL_RCC_PWR_CLK_ENABLE(); - HAL_PWREx_DisableVddUSB(); - __HAL_RCC_PWR_CLK_DISABLE(); + /* Disable VDDUSB */ + if(__HAL_RCC_PWR_IS_CLK_DISABLED()) { + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_PWREx_DisableVddUSB(); + __HAL_RCC_PWR_CLK_DISABLE(); + } else { + HAL_PWREx_DisableVddUSB(); + } + + /* Peripheral interrupt Deinit*/ + HAL_NVIC_DisableIRQ(OTG_FS_IRQn); + + /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ + + /* USER CODE END USB_OTG_FS_MspDeInit 1 */ } - else - { - HAL_PWREx_DisableVddUSB(); - } - - /* Peripheral interrupt Deinit*/ - HAL_NVIC_DisableIRQ(OTG_FS_IRQn); - - /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ - - /* USER CODE END USB_OTG_FS_MspDeInit 1 */ - } } /** @@ -154,13 +144,13 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SetupStageCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); + USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t*)hpcd->Setup); } /** @@ -169,13 +159,13 @@ void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) * @param epnum: Endpoint number * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DataOutStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); + USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); } /** @@ -184,13 +174,13 @@ void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) * @param epnum: Endpoint number * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DataInStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); + USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); } /** @@ -198,13 +188,13 @@ void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SOFCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SOFCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); + USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); } /** @@ -212,23 +202,22 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ResetCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ResetCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_SpeedTypeDef speed = USBD_SPEED_FULL; +{ + USBD_SpeedTypeDef speed = USBD_SPEED_FULL; - if ( hpcd->Init.speed != PCD_SPEED_FULL) - { - Error_Handler(); - } + if(hpcd->Init.speed != PCD_SPEED_FULL) { + Error_Handler(); + } /* Set Speed. */ - USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); + USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); - /* Reset Device. */ - USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); + /* Reset Device. */ + USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); } /** @@ -237,23 +226,22 @@ void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SuspendCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SuspendCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - __HAL_PCD_GATE_PHYCLOCK(hpcd); - /* Inform USB library that core enters in suspend Mode. */ - USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); - /* Enter in STOP mode. */ - /* USER CODE BEGIN 2 */ - 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)); - } - /* USER CODE END 2 */ + __HAL_PCD_GATE_PHYCLOCK(hpcd); + /* Inform USB library that core enters in suspend Mode. */ + USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); + /* Enter in STOP mode. */ + /* USER CODE BEGIN 2 */ + 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)); + } + /* USER CODE END 2 */ } /** @@ -262,23 +250,22 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ResumeCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ResumeCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - __HAL_PCD_UNGATE_PHYCLOCK(hpcd); + __HAL_PCD_UNGATE_PHYCLOCK(hpcd); - /* USER CODE BEGIN 3 */ - 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(); - } - /* USER CODE END 3 */ - USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN 3 */ + 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(); + } + /* USER CODE END 3 */ + USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); } /** @@ -287,13 +274,13 @@ void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) * @param epnum: Endpoint number * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); + USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); } /** @@ -302,13 +289,13 @@ void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) * @param epnum: Endpoint number * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); + USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); } /** @@ -316,15 +303,15 @@ void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ConnectCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ConnectCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - // TODO send UsbConnect event to FURI + // TODO send UsbConnect event to FURI - USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); + USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); } /** @@ -332,15 +319,15 @@ void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) * @param hpcd: PCD handle * @retval None */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DisconnectCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - // TODO send UsbDisconnect event to FURI + // TODO send UsbDisconnect event to FURI - USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); + USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); } /******************************************************************************* @@ -352,50 +339,50 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) * @param pdev: Device handle * @retval USBD status */ -USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) -{ - /* Init USB Ip. */ - if (pdev->id == DEVICE_FS) { - /* Enable USB power on Pwrctrl CR2 register. */ - /* Link the driver to the stack. */ - hpcd_USB_OTG_FS.pData = pdev; - pdev->pData = &hpcd_USB_OTG_FS; - - hpcd_USB_OTG_FS.Instance = USB_OTG_FS; - hpcd_USB_OTG_FS.Init.dev_endpoints = 6; - hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE; - hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE; - hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE; - 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) - { - Error_Handler( ); - } +USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef* pdev) { + /* Init USB Ip. */ + if(pdev->id == DEVICE_FS) { + /* Enable USB power on Pwrctrl CR2 register. */ + /* Link the driver to the stack. */ + hpcd_USB_OTG_FS.pData = pdev; + pdev->pData = &hpcd_USB_OTG_FS; -#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_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); + hpcd_USB_OTG_FS.Instance = USB_OTG_FS; + hpcd_USB_OTG_FS.Init.dev_endpoints = 6; + hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED; + hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE; + hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE; + hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE; + 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) { + Error_Handler(); + } - HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback); - HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback); - HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOOUTIncompleteCallback); - HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOINIncompleteCallback); +#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_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_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback); + HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback); + HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOOUTIncompleteCallback); + HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOINIncompleteCallback); #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ - HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80); - HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40); - HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80); - } - return USBD_OK; + HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80); + HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40); + HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80); + } + return USBD_OK; } /** @@ -403,31 +390,30 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) * @param pdev: Device handle * @retval USBD status */ -USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_DeInit(pdev->pData); + hal_status = HAL_PCD_DeInit(pdev->pData); - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -435,31 +421,30 @@ USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) * @param pdev: Device handle * @retval USBD status */ -USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_Start(pdev->pData); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_Start(pdev->pData); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -467,31 +452,30 @@ USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) * @param pdev: Device handle * @retval USBD status */ -USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_Stop(pdev->pData); + hal_status = HAL_PCD_Stop(pdev->pData); - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -502,31 +486,31 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +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; - hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); + hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -535,31 +519,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -568,31 +551,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -601,31 +583,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_SetStall(pdev->pData, 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; - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -634,31 +615,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -667,18 +647,14 @@ 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) -{ - PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; - - if((ep_addr & 0x80) == 0x80) - { - return hpcd->IN_ep[ep_addr & 0x7F].is_stall; - } - else - { - return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; - } +uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + PCD_HandleTypeDef* hpcd = (PCD_HandleTypeDef*)pdev->pData; + + if((ep_addr & 0x80) == 0x80) { + return hpcd->IN_ep[ep_addr & 0x7F].is_stall; + } else { + return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; + } } /** @@ -687,31 +663,30 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; +USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef* pdev, uint8_t dev_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -722,31 +697,31 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +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; - hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -757,31 +732,31 @@ 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) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; +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; - hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); - - switch (hal_status) { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); + + switch(hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } /** @@ -790,9 +765,8 @@ 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) -{ - return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, 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,34 +775,30 @@ 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) - { - case PCD_LPM_L0_ACTIVE: - if (hpcd->Init.low_power_enable) - { - SystemClockConfig_Resume(); - - /* Reset SLEEPDEEP bit of Cortex System Control Register. */ - SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); +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) { + SystemClockConfig_Resume(); + + /* Reset SLEEPDEEP bit of Cortex System Control Register. */ + SCB->SCR &= (uint32_t) ~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + } + __HAL_PCD_UNGATE_PHYCLOCK(hpcd); + USBD_LL_Resume(hpcd->pData); + break; + + case PCD_LPM_L1_ACTIVE: + __HAL_PCD_GATE_PHYCLOCK(hpcd); + USBD_LL_Suspend(hpcd->pData); + + /* Enter in STOP mode. */ + 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)); + } + break; } - __HAL_PCD_UNGATE_PHYCLOCK(hpcd); - USBD_LL_Resume(hpcd->pData); - break; - - case PCD_LPM_L1_ACTIVE: - __HAL_PCD_GATE_PHYCLOCK(hpcd); - USBD_LL_Suspend(hpcd->pData); - - /* Enter in STOP mode. */ - 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)); - } - break; - } } /** @@ -836,9 +806,8 @@ 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) -{ - HAL_Delay(Delay); +void USBD_LL_Delay(uint32_t Delay) { + HAL_Delay(Delay); } /** @@ -846,10 +815,9 @@ void USBD_LL_Delay(uint32_t Delay) * @param size: Size of allocated memory * @retval None */ -void *USBD_static_malloc(uint32_t size) -{ - static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ - return mem; +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,9 +834,8 @@ void USBD_static_free(void *p) * enable HSI, PLL and select PLL as system clock source. * @retval None */ -static void SystemClockConfig_Resume(void) -{ - SystemClock_Config(); +static void SystemClockConfig_Resume(void) { + SystemClock_Config(); } /* USER CODE END 5 */ diff --git a/target_f2/Src/usbd_desc.c b/target_f2/Src/usbd_desc.c index e40828ab..a57103a1 100644 --- a/target_f2/Src/usbd_desc.c +++ b/target_f2/Src/usbd_desc.c @@ -63,15 +63,15 @@ * @{ */ -#define USBD_VID 1155 -#define USBD_LANGID_STRING 1033 -#define USBD_MANUFACTURER_STRING "STMicroelectronics" -#define USBD_PID_FS 22336 -#define USBD_PRODUCT_STRING_FS "Flipper Zero Virtual ComPort" -#define USBD_CONFIGURATION_STRING_FS "CDC Config" -#define USBD_INTERFACE_STRING_FS "CDC Interface" +#define USBD_VID 1155 +#define USBD_LANGID_STRING 1033 +#define USBD_MANUFACTURER_STRING "STMicroelectronics" +#define USBD_PID_FS 22336 +#define USBD_PRODUCT_STRING_FS "Flipper Zero Virtual ComPort" +#define USBD_CONFIGURATION_STRING_FS "CDC Config" +#define USBD_INTERFACE_STRING_FS "CDC Interface" -#define USB_SIZ_BOS_DESC 0x0C +#define USB_SIZ_BOS_DESC 0x0C /* USER CODE BEGIN PRIVATE_DEFINES */ @@ -97,34 +97,33 @@ /** * @} */ - + /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes * @brief Private functions declaration. * @{ */ - + static void Get_SerialNum(void); -static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); - +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. * @{ */ -uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -#if (USBD_LPM_ENABLED == 1) -uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t* USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +#if(USBD_LPM_ENABLED == 1) +uint8_t* USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); #endif /* (USBD_LPM_ENABLED == 1) */ /** @@ -136,74 +135,71 @@ 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 -#if (USBD_LPM_ENABLED == 1) -, USBD_FS_USR_BOSDescriptor +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 #endif /* (USBD_LPM_ENABLED == 1) */ }; -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /** USB standard device descriptor. */ -__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 +__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 in order to support LPM L1 suspend resume test of USBCV3.0*/ #else - 0x00, /*bcdUSB */ + 0x00, /*bcdUSB */ #endif /* (USBD_LPM_ENABLED == 1) */ - 0x02, - 0x02, /*bDeviceClass*/ - 0x02, /*bDeviceSubClass*/ - 0x00, /*bDeviceProtocol*/ - USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ - LOBYTE(USBD_VID), /*idVendor*/ - HIBYTE(USBD_VID), /*idVendor*/ - LOBYTE(USBD_PID_FS), /*idProduct*/ - HIBYTE(USBD_PID_FS), /*idProduct*/ - 0x00, /*bcdDevice rel. 2.00*/ - 0x02, - USBD_IDX_MFC_STR, /*Index of manufacturer string*/ - USBD_IDX_PRODUCT_STR, /*Index of product string*/ - USBD_IDX_SERIAL_STR, /*Index of serial number string*/ - USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ + 0x02, + 0x02, /*bDeviceClass*/ + 0x02, /*bDeviceSubClass*/ + 0x00, /*bDeviceProtocol*/ + USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ + LOBYTE(USBD_VID), /*idVendor*/ + HIBYTE(USBD_VID), /*idVendor*/ + LOBYTE(USBD_PID_FS), /*idProduct*/ + HIBYTE(USBD_PID_FS), /*idProduct*/ + 0x00, /*bcdDevice rel. 2.00*/ + 0x02, + USBD_IDX_MFC_STR, /*Index of manufacturer string*/ + USBD_IDX_PRODUCT_STR, /*Index of product string*/ + USBD_IDX_SERIAL_STR, /*Index of serial number string*/ + USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ }; /* USB_DeviceDescriptor */ /** BOS descriptor. */ -#if (USBD_LPM_ENABLED == 1) -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if(USBD_LPM_ENABLED == 1) +#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 = -{ - 0x5, - USB_DESC_TYPE_BOS, - 0xC, - 0x0, - 0x1, /* 1 device capability*/ - /* device capability*/ - 0x7, - USB_DEVICE_CAPABITY_TYPE, - 0x2, - 0x2, /* LPM capability bit set*/ - 0x0, - 0x0, - 0x0 -}; +__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = { + 0x5, + USB_DESC_TYPE_BOS, + 0xC, + 0x0, + 0x1, /* 1 device capability*/ + /* device capability*/ + 0x7, + USB_DEVICE_CAPABITY_TYPE, + 0x2, + 0x2, /* LPM capability bit set*/ + 0x0, + 0x0, + 0x0}; #endif /* (USBD_LPM_ENABLED == 1) */ /** @@ -215,31 +211,29 @@ __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = * @{ */ -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /** USB lang indentifier descriptor. */ -__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) -}; +__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)}; -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /* Internal string descriptor. */ __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /*!< IAR Compiler */ +#pragma data_alignment = 4 #endif __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { - USB_SIZ_STRING_SERIAL, - USB_DESC_TYPE_STRING, + USB_SIZ_STRING_SERIAL, + USB_DESC_TYPE_STRING, }; /** @@ -257,11 +251,10 @@ __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) -{ - UNUSED(speed); - *length = sizeof(USBD_FS_DeviceDesc); - return USBD_FS_DeviceDesc; +uint8_t* USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { + UNUSED(speed); + *length = sizeof(USBD_FS_DeviceDesc); + return USBD_FS_DeviceDesc; } /** @@ -270,11 +263,10 @@ 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) -{ - UNUSED(speed); - *length = sizeof(USBD_LangIDDesc); - return USBD_LangIDDesc; +uint8_t* USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { + UNUSED(speed); + *length = sizeof(USBD_LangIDDesc); + return USBD_LangIDDesc; } /** @@ -283,17 +275,13 @@ 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) - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; +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 { + USBD_GetString((uint8_t*)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; } /** @@ -302,11 +290,10 @@ 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) -{ - UNUSED(speed); - USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); - return USBD_StrDesc; +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,18 +302,17 @@ 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) -{ - UNUSED(speed); - *length = USB_SIZ_STRING_SERIAL; +uint8_t* USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { + UNUSED(speed); + *length = USB_SIZ_STRING_SERIAL; - /* Update the serial number string descriptor with the data from the unique + /* Update the serial number string descriptor with the data from the unique * ID */ - Get_SerialNum(); - /* USER CODE BEGIN USBD_FS_SerialStrDescriptor */ - - /* USER CODE END USBD_FS_SerialStrDescriptor */ - return (uint8_t *) USBD_StringSerial; + Get_SerialNum(); + /* USER CODE BEGIN USBD_FS_SerialStrDescriptor */ + + /* USER CODE END USBD_FS_SerialStrDescriptor */ + return (uint8_t*)USBD_StringSerial; } /** @@ -335,17 +321,13 @@ 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) - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; +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 { + USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; } /** @@ -354,31 +336,26 @@ 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) - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); - } - return USBD_StrDesc; +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 { + USBD_GetString((uint8_t*)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); + } + return USBD_StrDesc; } -#if (USBD_LPM_ENABLED == 1) +#if(USBD_LPM_ENABLED == 1) /** * @brief Return the BOS descriptor * @param speed : Current device speed * @param length : Pointer to data length variable * @retval Pointer to descriptor buffer */ -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; +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; } #endif /* (USBD_LPM_ENABLED == 1) */ @@ -387,21 +364,19 @@ uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) * @param None * @retval None */ -static void Get_SerialNum(void) -{ - uint32_t deviceserial0, deviceserial1, deviceserial2; +static void Get_SerialNum(void) { + uint32_t deviceserial0, deviceserial1, deviceserial2; - deviceserial0 = *(uint32_t *) DEVICE_ID1; - deviceserial1 = *(uint32_t *) DEVICE_ID2; - deviceserial2 = *(uint32_t *) DEVICE_ID3; + deviceserial0 = *(uint32_t*)DEVICE_ID1; + deviceserial1 = *(uint32_t*)DEVICE_ID2; + deviceserial2 = *(uint32_t*)DEVICE_ID3; - deviceserial0 += deviceserial2; + deviceserial0 += deviceserial2; - if (deviceserial0 != 0) - { - IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); - IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); - } + if(deviceserial0 != 0) { + IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); + IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); + } } /** @@ -411,25 +386,20 @@ static void Get_SerialNum(void) * @param len: buffer length * @retval None */ -static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) -{ - uint8_t idx = 0; +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) - { - pbuf[2 * idx] = (value >> 28) + '0'; + for(idx = 0; idx < len; idx++) { + if(((value >> 28)) < 0xA) { + pbuf[2 * idx] = (value >> 28) + '0'; + } else { + pbuf[2 * idx] = (value >> 28) + 'A' - 10; + } + + value = value << 4; + + pbuf[2 * idx + 1] = 0; } - else - { - pbuf[2 * idx] = (value >> 28) + 'A' - 10; - } - - value = value << 4; - - pbuf[2 * idx + 1] = 0; - } } /** * @} diff --git a/target_lo/Inc/cmsis_os.h b/target_lo/Inc/cmsis_os.h index 985e0e8b..a53462fb 100644 --- a/target_lo/Inc/cmsis_os.h +++ b/target_lo/Inc/cmsis_os.h @@ -6,13 +6,12 @@ void osDelay(uint32_t ms); // some FreeRTOS types -typedef void(*TaskFunction_t)(void*); +typedef void (*TaskFunction_t)(void*); typedef size_t UBaseType_t; 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, - const char * const pcName, - const uint32_t ulStackDepth, - void * const pvParameters, - UBaseType_t uxPriority, - StackType_t * const puxStackBuffer, - StaticTask_t * const pxTaskBuffer -); +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); 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, - UBaseType_t uxItemSize, - uint8_t* pucQueueStorageBuffer, - StaticQueue_t* pxQueueBuffer -); +QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength, + UBaseType_t uxItemSize, + uint8_t* pucQueueStorageBuffer, + StaticQueue_t* pxQueueBuffer); -SemaphoreHandle_t xSemaphoreCreateCountingStatic( - UBaseType_t uxMaxCount, - UBaseType_t uxInitialCount, - StaticSemaphore_t *pxSemaphoreBuffer -); +SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount, + UBaseType_t uxInitialCount, + 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); diff --git a/target_lo/Inc/flipper_hal.h b/target_lo/Inc/flipper_hal.h index 979d86d9..e844ee22 100644 --- a/target_lo/Inc/flipper_hal.h +++ b/target_lo/Inc/flipper_hal.h @@ -10,11 +10,7 @@ GPIO and HAL implementations #include #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); \ No newline at end of file +HAL_StatusTypeDef +HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t* pData, uint16_t Size, uint32_t Timeout); \ No newline at end of file diff --git a/target_lo/Inc/main.h b/target_lo/Inc/main.h index ee095608..e169e63d 100644 --- a/target_lo/Inc/main.h +++ b/target_lo/Inc/main.h @@ -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; diff --git a/target_lo/Src/flipper_hal.c b/target_lo/Src/flipper_hal.c index 324f8d66..a121bb43 100644 --- a/target_lo/Src/flipper_hal.c +++ b/target_lo/Src/flipper_hal.c @@ -10,18 +10,17 @@ 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); + case GpioModeInput: + printf("[GPIO] %s%d input\n", gpio.port, gpio.pin); break; - case GpioModeOutput: - printf("[GPIO] %s%d push pull\n", gpio.port, gpio.pin); + case GpioModeOutput: + printf("[GPIO] %s%d push pull\n", gpio.port, gpio.pin); break; - case GpioModeOpenDrain: - printf("[GPIO] %s%d open drain\n", gpio.port, gpio.pin); + case GpioModeOpenDrain: + printf("[GPIO] %s%d open drain\n", gpio.port, gpio.pin); break; } @@ -44,13 +43,14 @@ 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]); } printf("\n"); - + return 0; } diff --git a/target_lo/Src/lo_hal.c b/target_lo/Src/lo_hal.c index a72b7e9e..843f5c80 100644 --- a/target_lo/Src/lo_hal.c +++ b/target_lo/Src/lo_hal.c @@ -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; } \ No newline at end of file diff --git a/target_lo/Src/lo_os.c b/target_lo/Src/lo_os.c index 14d79f0a..2ada054c 100644 --- a/target_lo/Src/lo_os.c +++ b/target_lo/Src/lo_os.c @@ -16,7 +16,7 @@ void osDelay(uint32_t ms) { // temporary struct to pass function ptr and param to wrapper typedef struct { TaskFunction_t func; - void * param; + void* param; } PthreadTask; void* pthread_wrapper(void* p) { @@ -24,21 +24,19 @@ void* pthread_wrapper(void* p) { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0x00); PthreadTask* task = (PthreadTask*)p; - + task->func(task->param); return NULL; } -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 -) { +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) { TaskHandle_t thread = malloc(sizeof(TaskHandle_t)); PthreadTask* task = malloc(sizeof(PthreadTask)); @@ -51,14 +49,13 @@ TaskHandle_t xTaskCreateStatic( } void vTaskDelete(TaskHandle_t xTask) { - if(xTask == NULL) { // kill itself pthread_exit(NULL); } // maybe thread already join - if (pthread_kill(*xTask, 0) == ESRCH) return; + if(pthread_kill(*xTask, 0) == ESRCH) return; // send thread_child signal to stop it сигнал, который ее завершает pthread_cancel(*xTask); @@ -78,20 +75,16 @@ TaskHandle_t xTaskGetCurrentTaskHandle(void) { bool task_equal(TaskHandle_t a, TaskHandle_t b) { if(a == NULL || b == NULL) return false; - + 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, - UBaseType_t uxItemSize, - uint8_t* pucQueueStorageBuffer, - StaticQueue_t *pxQueueBuffer -) { +QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength, + UBaseType_t uxItemSize, + uint8_t* pucQueueStorageBuffer, + 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, - UBaseType_t uxInitialCount, - StaticSemaphore_t* pxSemaphoreBuffer -) { +SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount, + UBaseType_t uxInitialCount, + StaticSemaphore_t* pxSemaphoreBuffer) { pxSemaphoreBuffer->type = SemaphoreTypeCounting; pxSemaphoreBuffer->take_counter = 0; pxSemaphoreBuffer->give_counter = 0; @@ -136,24 +125,23 @@ SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer) return pxMutexBuffer; } - BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait) { if(xSemaphore == NULL) return pdFALSE; - if (xSemaphore->type == SemaphoreTypeMutex) { - if (xTicksToWait == portMAX_DELAY) { - if (pthread_mutex_lock(&xSemaphore->mutex) == 0) { + if(xSemaphore->type == SemaphoreTypeMutex) { + if(xTicksToWait == portMAX_DELAY) { + if(pthread_mutex_lock(&xSemaphore->mutex) == 0) { return pdTRUE; } else { return pdFALSE; } } else { TickType_t ticks = xTicksToWait; - while (ticks >= 0) { - if (pthread_mutex_trylock(&xSemaphore->mutex) == 0) { + while(ticks >= 0) { + if(pthread_mutex_trylock(&xSemaphore->mutex) == 0) { return pdTRUE; } - if (ticks > 0) { + if(ticks > 0) { osDelay(1); } ticks--; @@ -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--; } @@ -183,8 +169,8 @@ BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTic BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore) { if(xSemaphore == NULL) return pdFALSE; - if (xSemaphore->type == SemaphoreTypeMutex) { - if (pthread_mutex_unlock(&xSemaphore->mutex) == 0) { + if(xSemaphore->type == SemaphoreTypeMutex) { + if(pthread_mutex_unlock(&xSemaphore->mutex) == 0) { return pdTRUE; } else { return pdFALSE; @@ -202,20 +188,18 @@ static pthread_key_t tls_keys[TLS_ITEM_COUNT]; static pthread_once_t tls_keys_once = PTHREAD_ONCE_INIT; static void create_tls_keys() { - for (size_t i = 0; i < TLS_ITEM_COUNT; i++) { + for(size_t i = 0; i < TLS_ITEM_COUNT; i++) { pthread_key_create(&tls_keys[i], NULL); } } -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) { + if(xTaskToQuery != NULL) { return NULL; } - if (xIndex >= TLS_ITEM_COUNT) { + if(xIndex >= TLS_ITEM_COUNT) { return NULL; } @@ -224,15 +208,13 @@ 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) { + if(xTaskToSet != NULL) { return; } - if (xIndex >= TLS_ITEM_COUNT) { + if(xIndex >= TLS_ITEM_COUNT) { return; } diff --git a/wiki/Contributing.md b/wiki/Contributing.md index 866a8539..57608325 100644 --- a/wiki/Contributing.md +++ b/wiki/Contributing.md @@ -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