Blink f1 (#50)

* Fix target_f1 build

* restore build for F1 target

* change default LED pin state

* add real hw gif

Co-authored-by: Vadim Kaushan <admin@disasm.info>
This commit is contained in:
coreglitch 2020-08-26 14:43:18 +06:00 committed by GitHub
parent e7aa6caf0e
commit ab07bfb104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 134 additions and 62 deletions

View File

@ -2,9 +2,9 @@
#include "cmsis_os.h" #include "cmsis_os.h"
#include <string.h> #include <string.h>
#define DEBUG // TODO: this file contains printf, that not implemented on uC target
#ifdef DEBUG #ifdef FURI_DEBUG
#include <stdio.h> #include <stdio.h>
#endif #endif
@ -28,13 +28,13 @@ static FuriRecord* find_record(const char* name) {
} }
bool furi_create(const char* name, void* value, size_t size) { bool furi_create(const char* name, void* value, size_t size) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURI] creating %s record\n", name); printf("[FURI] creating %s record\n", name);
#endif #endif
if(current_buffer_idx >= MAX_RECORD_COUNT) { if(current_buffer_idx >= MAX_RECORD_COUNT) {
// max record count exceed // max record count exceed
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURI] max record count exceed\n"); printf("[FURI] max record count exceed\n");
#endif #endif
return NULL; return NULL;
@ -62,7 +62,7 @@ FuriRecordHandler furi_open(
FlipperRecordCallback value_callback, FlipperRecordCallback value_callback,
FlipperRecordStateCallback state_callback FlipperRecordStateCallback state_callback
) { ) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURI] opening %s record\n", name); printf("[FURI] opening %s record\n", name);
#endif #endif
@ -71,7 +71,7 @@ FuriRecordHandler furi_open(
if(record == NULL) { if(record == NULL) {
// cannot find record // cannot find record
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURI] cannot find record %s\n", name); printf("[FURI] cannot find record %s\n", name);
#endif #endif
@ -91,7 +91,7 @@ FuriRecordHandler furi_open(
if(subscriber == NULL) { if(subscriber == NULL) {
// cannot add subscriber (full) // cannot add subscriber (full)
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURI] cannot add subscriber (full)\n"); printf("[FURI] cannot add subscriber (full)\n");
#endif #endif
@ -123,7 +123,7 @@ FuriRecordHandler furi_open(
void furi_close(FuriRecordHandler* handler) { void furi_close(FuriRecordHandler* handler) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURI] closing %s record\n", handler->record->name); printf("[FURI] closing %s record\n", handler->record->name);
#endif #endif
@ -163,7 +163,7 @@ void furi_give(FuriRecordHandler* handler) {
} }
bool furi_read(FuriRecordHandler* handler, void* value, size_t size) { bool furi_read(FuriRecordHandler* handler, void* value, size_t size) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURI] read from %s\n", handler->record->name); printf("[FURI] read from %s\n", handler->record->name);
#endif #endif
@ -183,7 +183,7 @@ bool furi_read(FuriRecordHandler* handler, void* value, size_t size) {
} }
bool furi_write(FuriRecordHandler* handler, const void* value, size_t size) { bool furi_write(FuriRecordHandler* handler, const void* value, size_t size) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURI] write to %s\n", handler->record->name); printf("[FURI] write to %s\n", handler->record->name);
#endif #endif

View File

@ -1,9 +1,9 @@
#include "furi.h" #include "furi.h"
#include "cmsis_os.h" #include "cmsis_os.h"
#define DEBUG // TODO: this file contains printf, that not implemented on uC target
#ifdef DEBUG #ifdef FURI_DEBUG
#include <stdio.h> #include <stdio.h>
#endif #endif
@ -29,7 +29,7 @@ FuriApp* find_task(TaskHandle_t handler) {
} }
FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) { FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURIAC] start %s\n", name); printf("[FURIAC] start %s\n", name);
#endif #endif
@ -37,7 +37,7 @@ FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) {
if(current_buffer_idx >= MAX_TASK_COUNT) { if(current_buffer_idx >= MAX_TASK_COUNT) {
// max task count exceed // max task count exceed
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURIAC] max task count exceed\n"); printf("[FURIAC] max task count exceed\n");
#endif #endif
return NULL; return NULL;
@ -67,7 +67,7 @@ FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) {
} }
bool furiac_kill(FuriApp* app) { bool furiac_kill(FuriApp* app) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURIAC] kill %s\n", app->name); printf("[FURIAC] kill %s\n", app->name);
#endif #endif
@ -90,14 +90,14 @@ void furiac_exit(void* param) {
// run prev // run prev
if(current_task != NULL) { if(current_task != NULL) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURIAC] exit %s\n", current_task->name); printf("[FURIAC] exit %s\n", current_task->name);
#endif #endif
if(current_task->prev != NULL) { if(current_task->prev != NULL) {
furiac_start(current_task->prev, current_task->prev_name, param); furiac_start(current_task->prev, current_task->prev_name, param);
} else { } else {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURIAC] no prev\n"); printf("[FURIAC] no prev\n");
#endif #endif
} }
@ -116,12 +116,12 @@ void furiac_switch(FlipperApplication app, char* name, void* param) {
FuriApp* current_task = find_task(xTaskGetCurrentTaskHandle()); FuriApp* current_task = find_task(xTaskGetCurrentTaskHandle());
if(current_task == NULL) { if(current_task == NULL) {
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURIAC] no current task found\n"); printf("[FURIAC] no current task found\n");
#endif #endif
} }
#ifdef DEBUG #ifdef FURI_DEBUG
printf("[FURIAC] switch %s to %s\n", current_task->name, name); printf("[FURIAC] switch %s to %s\n", current_task->name, name);
#endif #endif

View File

@ -1,7 +1,7 @@
[PreviousGenFiles] [PreviousGenFiles]
HeaderPath=/home/aanper/project/flipperzero/fw/target_prod/Inc HeaderPath=/home/aanper/project/flipperzero/flipperzero-firmware-community/target_f1/Inc
HeaderFiles=FreeRTOSConfig.h;stm32l4xx_it.h;stm32l4xx_hal_conf.h;main.h;usb_device.h;usbd_conf.h;usbd_desc.h;usbd_cdc_if.h; HeaderFiles=FreeRTOSConfig.h;stm32l4xx_it.h;stm32l4xx_hal_conf.h;main.h;usb_device.h;usbd_conf.h;usbd_desc.h;usbd_cdc_if.h;
SourcePath=/home/aanper/project/flipperzero/fw/target_prod/Src SourcePath=/home/aanper/project/flipperzero/flipperzero-firmware-community/target_f1/Src
SourceFiles=freertos.c;stm32l4xx_it.c;stm32l4xx_hal_msp.c;main.c;usb_device.c;usbd_conf.c;usbd_desc.c;usbd_cdc_if.c; SourceFiles=freertos.c;stm32l4xx_it.c;stm32l4xx_hal_msp.c;main.c;usb_device.c;usbd_conf.c;usbd_desc.c;usbd_cdc_if.c;
[PreviousLibFiles] [PreviousLibFiles]

View File

@ -34,8 +34,14 @@ BUILD_DIR = build
###################################### ######################################
# source # source
###################################### ######################################
# C sources C_SOURCES =
C_SOURCES = \ CPP_SOURCES =
ASM_SOURCES =
C_DEFS =
# Target
C_SOURCES += \
Src/main.c \ Src/main.c \
Src/freertos.c \ Src/freertos.c \
Src/stm32l4xx_it.c \ Src/stm32l4xx_it.c \
@ -89,14 +95,44 @@ Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \ Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \
Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c
# ASM sources C_SOURCES += Src/flipper_hal.c
ASM_SOURCES = \
C_DEFS += \
-DUSE_HAL_DRIVER \
-DSTM32L476xx \
-DBUTON_INVERT=false \
-DDEBUG_UART=huart1
ASM_SOURCES += \
startup_stm32l476xx.s startup_stm32l476xx.s
CPP_SOURCES = ../app/app.cpp # Core
C_SOURCES += ../app/write.c CPP_SOURCES += ../core/app.cpp
C_SOURCES += Src/flipper_hal.c
C_SOURCES += ../core/debug.c
C_SOURCES += ../core/furi.c
C_SOURCES += ../core/furi_ac.c
# System applications
ifeq ($(TEST), 1)
C_SOURCES += ../applications/tests/furiac_test.c
C_SOURCES += ../applications/tests/furi_record_test.c
C_SOURCES += ../applications/tests/test_index.c
C_DEFS += -DTEST
endif
# Examples
ifeq ($(EXAMPLE_BLINK), 1)
C_SOURCES += ../applications/examples/blink.c
C_DEFS += -DEXAMPLE_BLINK
endif
# User application
# Add C_SOURCES +=, C_DEFS += or CPP_SOURCES += here
####################################### #######################################
# binaries # binaries
@ -139,13 +175,6 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# AS defines # AS defines
AS_DEFS = AS_DEFS =
# C defines
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32L476xx \
-DBUTON_INVERT=false \
-DDEBUG_UART=huart1
# AS includes # AS includes
AS_INCLUDES = \ AS_INCLUDES = \
@ -196,6 +225,11 @@ LDFLAGS = $(MCU) -specs=nano.specs -specs=nosys.specs -T$(LDSCRIPT) $(LIBDIR) $(
# default action: build all # default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
example_blink:
EXAMPLE_BLINK=1 make
test:
TEST=1 make
####################################### #######################################
# build the application # build the application

View File

@ -53,6 +53,8 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
#include <stdbool.h>
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "timers.h" #include "timers.h"
@ -1019,6 +1021,9 @@ osStatus osRecursiveMutexWait (osMutexId mutex_id, uint32_t millisec);
*/ */
uint32_t osSemaphoreGetCount(osSemaphoreId semaphore_id); uint32_t osSemaphoreGetCount(osSemaphoreId semaphore_id);
// FreeRTOS add-on
bool task_equal(TaskHandle_t a, TaskHandle_t b);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -25,6 +25,7 @@
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include <stdbool.h>
/* USER CODE END Includes */ /* USER CODE END Includes */
@ -105,6 +106,11 @@ void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, Stack
/* Private application code --------------------------------------------------*/ /* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */ /* USER CODE BEGIN Application */
bool task_equal(TaskHandle_t a, TaskHandle_t b) {
if(a == NULL || b == NULL) return false;
return a == b;
}
/* USER CODE END Application */ /* USER CODE END Application */

View File

@ -680,15 +680,20 @@ static void MX_GPIO_Init(void)
__HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */ /*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, DISPLAY_DI_Pin|LED_RED_Pin|CC1101_CS_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, DISPLAY_DI_Pin|CC1101_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */ /*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, LED_BLUE_Pin|DISPLAY_RST_Pin|IR_TX_Pin|LED_GREEN_Pin HAL_GPIO_WritePin(GPIOB, LED_BLUE_Pin|LED_GREEN_Pin, GPIO_PIN_SET);
|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 */ /*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, VIBRO_Pin|DISPLAY_CS_Pin, GPIO_PIN_RESET); 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 pins : PC13 PC0 PC1 PC9 */ /*Configure GPIO pins : PC13 PC0 PC1 PC9 */
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_9; GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
@ -757,7 +762,7 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Pin = LED_RED_Pin; GPIO_InitStruct.Pin = LED_RED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct); HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PD2 */ /*Configure GPIO pin : PD2 */

View File

@ -170,11 +170,12 @@ PA6.Locked=true
PA6.Signal=GPXTI6 PA6.Signal=GPXTI6
PA7.Locked=true PA7.Locked=true
PA7.Signal=GPIO_Analog PA7.Signal=GPIO_Analog
PA8.GPIOParameters=GPIO_Speed,GPIO_Label,GPIO_ModeDefaultOutputPP PA8.GPIOParameters=GPIO_Speed,PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
PA8.GPIO_Label=LED_RED PA8.GPIO_Label=LED_RED
PA8.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD PA8.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
PA8.GPIO_Speed=GPIO_SPEED_FREQ_HIGH PA8.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
PA8.Locked=true PA8.Locked=true
PA8.PinState=GPIO_PIN_SET
PA8.Signal=GPIO_Output PA8.Signal=GPIO_Output
PA9.Locked=true PA9.Locked=true
PA9.Mode=Asynchronous PA9.Mode=Asynchronous
@ -185,11 +186,12 @@ PB0.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING
PB0.GPIO_PuPd=GPIO_PULLDOWN PB0.GPIO_PuPd=GPIO_PULLDOWN
PB0.Locked=true PB0.Locked=true
PB0.Signal=GPXTI0 PB0.Signal=GPXTI0
PB1.GPIOParameters=GPIO_Speed,GPIO_Label,GPIO_ModeDefaultOutputPP PB1.GPIOParameters=GPIO_Speed,PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
PB1.GPIO_Label=LED_BLUE PB1.GPIO_Label=LED_BLUE
PB1.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD PB1.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
PB1.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM PB1.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
PB1.Locked=true PB1.Locked=true
PB1.PinState=GPIO_PIN_SET
PB1.Signal=GPIO_Output PB1.Signal=GPIO_Output
PB10.GPIOParameters=GPIO_Label PB10.GPIOParameters=GPIO_Label
PB10.GPIO_Label=DISPLAY_RST PB10.GPIO_Label=DISPLAY_RST
@ -206,11 +208,12 @@ PB13.GPIO_Label=RFID_OUT
PB13.Locked=true PB13.Locked=true
PB13.Mode=Output Compare1 CH1N PB13.Mode=Output Compare1 CH1N
PB13.Signal=TIM15_CH1N PB13.Signal=TIM15_CH1N
PB14.GPIOParameters=GPIO_Speed,GPIO_Label,GPIO_ModeDefaultOutputPP PB14.GPIOParameters=GPIO_Speed,PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
PB14.GPIO_Label=LED_GREEN PB14.GPIO_Label=LED_GREEN
PB14.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD PB14.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
PB14.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM PB14.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
PB14.Locked=true PB14.Locked=true
PB14.PinState=GPIO_PIN_SET
PB14.Signal=GPIO_Output PB14.Signal=GPIO_Output
PB15.GPIOParameters=GPIO_Label PB15.GPIOParameters=GPIO_Label
PB15.GPIO_Label=RFID_PULL PB15.GPIO_Label=RFID_PULL
@ -339,8 +342,8 @@ ProjectManager.MainLocation=Src
ProjectManager.NoMain=false ProjectManager.NoMain=false
ProjectManager.PreviousToolchain= ProjectManager.PreviousToolchain=
ProjectManager.ProjectBuild=false ProjectManager.ProjectBuild=false
ProjectManager.ProjectFileName=flipperzero_l476.ioc ProjectManager.ProjectFileName=flipperzero_f1.ioc
ProjectManager.ProjectName=flipperzero_l476 ProjectManager.ProjectName=flipperzero_f1
ProjectManager.StackSize=0x400 ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=Makefile ProjectManager.TargetToolchain=Makefile
ProjectManager.ToolChainLocation= ProjectManager.ToolChainLocation=

View File

@ -19,27 +19,25 @@ BUILD_DIR = build
###################################### ######################################
# source # source
###################################### ######################################
# C sources C_SOURCES =
C_SOURCES = \ CPP_SOURCES =
Src/main.c C_DEFS =
CPP_SOURCES = ../core/app.cpp # Target
# Core C_SOURCES += Src/main.c
C_SOURCES += ../core/debug.c
C_SOURCES += ../core/furi.c
C_SOURCES += ../core/furi_ac.c
C_SOURCES += Src/flipper_hal.c C_SOURCES += Src/flipper_hal.c
C_SOURCES += Src/lo_os.c C_SOURCES += Src/lo_os.c
C_SOURCES += Src/lo_hal.c C_SOURCES += Src/lo_hal.c
# C defines C_DEFS += -DFURI_DEBUG
C_DEFS = \ # Core
-DUSE_HAL_DRIVER \
-DSTM32L476xx \ CPP_SOURCES += ../core/app.cpp
-DBUTON_INVERT=false \
-DDEBUG_UART=huart1 C_SOURCES += ../core/debug.c
C_SOURCES += ../core/furi.c
C_SOURCES += ../core/furi_ac.c
# System applications # System applications
@ -50,13 +48,17 @@ C_SOURCES += ../applications/tests/test_index.c
C_DEFS += -DTEST C_DEFS += -DTEST
endif endif
# User application # Examples
ifeq ($(EXAMPLE_BLINK), 1) ifeq ($(EXAMPLE_BLINK), 1)
C_SOURCES += ../applications/examples/blink.c C_SOURCES += ../applications/examples/blink.c
C_DEFS += -DEXAMPLE_BLINK C_DEFS += -DEXAMPLE_BLINK
endif endif
# User application
# Add C_SOURCES +=, C_DEFS += or CPP_SOURCES += here
####################################### #######################################
# binaries # binaries
####################################### #######################################

View File

@ -82,3 +82,17 @@ Linux version has no LED or GPIO, but we can see debug messages how state of GPI
![](https://github.com/Flipper-Zero/flipperzero-firmware-community/raw/master/wiki_static/application_examples/example_blink.gif) ![](https://github.com/Flipper-Zero/flipperzero-firmware-community/raw/master/wiki_static/application_examples/example_blink.gif)
_You also run found source of this example in `applications/examples/blink.c` and run by `docker-compose exec dev make -C target_lo example_blink`_ _You also run found source of this example in `applications/examples/blink.c` and run by `docker-compose exec dev make -C target_lo example_blink`_
Build for Flipper (board F1):
`docker-compose exec dev make -C target_f1`
Upload to microcontroller:
`./target_f1/deploy.sh`
Blink!
![](https://github.com/Flipper-Zero/flipperzero-firmware-community/raw/master/wiki_static/application_examples/example_blink_hw.gif)
_You also compile by `docker-compose exec dev make -C target_f1 example_blink`_

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0901a507ea047af9945c27549dc1460d5552cfafcff27f646453d129030f23da
size 623188