FuriHal: UART refactoring (#3211)

* FuriHal: UART refactoring
* ApiSymbols: add furi_record_destroy
* FuriHal: cleanup serial API, add logging configuration in RTC
* FuriHal: hide private part in _i header. Toolbox: cleanup value index. SystemSettings: logging device and baudrate.
* FuriHal: RTC logging method documentation
* Synchronize API Symbols
* Furi: mark HEAP_PRINT_DEBUG as broken
* FuriHal: furi_hal_serial, add custom IRQ func
* Fix PR review issues
* FuriHal: UART add reception DMA (#3220)
* FuriHal: add DMA serial rx mode
* usb_uart_bridge: switch to working with DMA
* Sync api symbol versions
* FuriHal: update serial docs and api
* FuriHal: Selial added similar API for simple reception mode as with DMA
* FuriHal: Update API target H18
* API: ver API H7
* FuriHal: Serial error processing
* FuriHal: fix furi_hal_serial set baudrate
* Sync api symbols
* FuriHal: cleanup serial isr and various flag handling procedures
* FuriHal: cleanup and simplify serial API
* Debug: update UART Echo serial related flags
* FuriHal: update serial API symbols naming
* FuriHalSerial: various improvements and PR review fixes
* FuriHal: proper ISR function signatures

---------

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: SkorP <skorpionm@yandex.ru>
Co-authored-by: Skorpionm <85568270+Skorpionm@users.noreply.github.com>
This commit is contained in:
あく
2024-01-16 03:09:37 +04:00
committed by GitHub
co-authored by hedger SkorP Skorpionm
parent d73d007797
commit fc043da9c6
37 changed files with 1966 additions and 759 deletions
+37 -25
View File
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,50.1,,
Version,+,51.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
@@ -160,7 +160,6 @@ Header,+,targets/f18/furi_hal/furi_hal_spi_config.h,,
Header,+,targets/f18/furi_hal/furi_hal_target_hw.h,,
Header,+,targets/f7/furi_hal/furi_hal_bus.h,,
Header,+,targets/f7/furi_hal/furi_hal_clock.h,,
Header,+,targets/f7/furi_hal/furi_hal_console.h,,
Header,+,targets/f7/furi_hal/furi_hal_dma.h,,
Header,+,targets/f7/furi_hal/furi_hal_flash.h,,
Header,+,targets/f7/furi_hal/furi_hal_gpio.h,,
@@ -170,8 +169,11 @@ Header,+,targets/f7/furi_hal/furi_hal_idle_timer.h,,
Header,+,targets/f7/furi_hal/furi_hal_interrupt.h,,
Header,+,targets/f7/furi_hal/furi_hal_os.h,,
Header,+,targets/f7/furi_hal/furi_hal_pwm.h,,
Header,+,targets/f7/furi_hal/furi_hal_rtc.h,,
Header,+,targets/f7/furi_hal/furi_hal_serial.h,,
Header,+,targets/f7/furi_hal/furi_hal_serial_control.h,,
Header,+,targets/f7/furi_hal/furi_hal_serial_types.h,,
Header,+,targets/f7/furi_hal/furi_hal_spi_types.h,,
Header,+,targets/f7/furi_hal/furi_hal_uart.h,,
Header,+,targets/f7/furi_hal/furi_hal_usb_cdc.h,,
Header,+,targets/f7/platform_specific/intrinsic_export.h,,
Header,+,targets/f7/platform_specific/math_wrapper.h,,
@@ -190,7 +192,6 @@ Header,+,targets/furi_hal_include/furi_hal_mpu.h,,
Header,+,targets/furi_hal_include/furi_hal_power.h,,
Header,+,targets/furi_hal_include/furi_hal_random.h,,
Header,+,targets/furi_hal_include/furi_hal_region.h,,
Header,+,targets/furi_hal_include/furi_hal_rtc.h,,
Header,+,targets/furi_hal_include/furi_hal_sd.h,,
Header,+,targets/furi_hal_include/furi_hal_speaker.h,,
Header,+,targets/furi_hal_include/furi_hal_spi.h,,
@@ -1057,14 +1058,6 @@ Function,-,furi_hal_clock_switch_hse2hsi,void,
Function,-,furi_hal_clock_switch_hse2pll,_Bool,
Function,-,furi_hal_clock_switch_hsi2hse,void,
Function,-,furi_hal_clock_switch_pll2hse,_Bool,
Function,+,furi_hal_console_disable,void,
Function,+,furi_hal_console_enable,void,
Function,+,furi_hal_console_init,void,
Function,+,furi_hal_console_printf,void,"const char[], ..."
Function,+,furi_hal_console_puts,void,const char*
Function,+,furi_hal_console_set_tx_callback,void,"FuriHalConsoleTxCallback, void*"
Function,+,furi_hal_console_tx,void,"const uint8_t*, size_t"
Function,+,furi_hal_console_tx_with_new_line,void,"const uint8_t*, size_t"
Function,+,furi_hal_cortex_comp_enable,void,"FuriHalCortexComp, FuriHalCortexCompFunction, uint32_t, uint32_t, FuriHalCortexCompSize"
Function,+,furi_hal_cortex_comp_reset,void,FuriHalCortexComp
Function,+,furi_hal_cortex_delay_us,void,uint32_t
@@ -1239,6 +1232,8 @@ Function,+,furi_hal_rtc_get_heap_track_mode,FuriHalRtcHeapTrackMode,
Function,+,furi_hal_rtc_get_locale_dateformat,FuriHalRtcLocaleDateFormat,
Function,+,furi_hal_rtc_get_locale_timeformat,FuriHalRtcLocaleTimeFormat,
Function,+,furi_hal_rtc_get_locale_units,FuriHalRtcLocaleUnits,
Function,+,furi_hal_rtc_get_log_baud_rate,FuriHalRtcLogBaudRate,
Function,+,furi_hal_rtc_get_log_device,FuriHalRtcLogDevice,
Function,+,furi_hal_rtc_get_log_level,uint8_t,
Function,+,furi_hal_rtc_get_pin_fails,uint32_t,
Function,+,furi_hal_rtc_get_register,uint32_t,FuriHalRtcRegister
@@ -1257,6 +1252,8 @@ Function,+,furi_hal_rtc_set_heap_track_mode,void,FuriHalRtcHeapTrackMode
Function,+,furi_hal_rtc_set_locale_dateformat,void,FuriHalRtcLocaleDateFormat
Function,+,furi_hal_rtc_set_locale_timeformat,void,FuriHalRtcLocaleTimeFormat
Function,+,furi_hal_rtc_set_locale_units,void,FuriHalRtcLocaleUnits
Function,+,furi_hal_rtc_set_log_baud_rate,void,FuriHalRtcLogBaudRate
Function,+,furi_hal_rtc_set_log_device,void,FuriHalRtcLogDevice
Function,+,furi_hal_rtc_set_log_level,void,uint8_t
Function,+,furi_hal_rtc_set_pin_fails,void,uint32_t
Function,+,furi_hal_rtc_set_register,void,"FuriHalRtcRegister, uint32_t"
@@ -1271,6 +1268,26 @@ Function,+,furi_hal_sd_max_mount_retry_count,uint8_t,
Function,+,furi_hal_sd_presence_init,void,
Function,+,furi_hal_sd_read_blocks,FuriStatus,"uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_sd_write_blocks,FuriStatus,"const uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_serial_control_acquire,FuriHalSerialHandle*,FuriHalSerialId
Function,+,furi_hal_serial_control_deinit,void,
Function,+,furi_hal_serial_control_init,void,
Function,+,furi_hal_serial_control_release,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_control_resume,void,
Function,+,furi_hal_serial_control_set_logging_config,void,"FuriHalSerialId, uint32_t"
Function,+,furi_hal_serial_control_suspend,void,
Function,+,furi_hal_serial_deinit,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_dma_rx,size_t,"FuriHalSerialHandle*, uint8_t*, size_t"
Function,+,furi_hal_serial_dma_rx_start,void,"FuriHalSerialHandle*, FuriHalSerialDmaRxCallback, void*, _Bool"
Function,+,furi_hal_serial_dma_rx_stop,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_init,void,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_resume,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_async_rx,uint8_t,FuriHalSerialHandle*
Function,+,furi_hal_serial_async_rx_start,void,"FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool"
Function,+,furi_hal_serial_async_rx_stop,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_set_br,void,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_suspend,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_tx,void,"FuriHalSerialHandle*, const uint8_t*, size_t"
Function,+,furi_hal_serial_tx_wait_complete,void,FuriHalSerialHandle*
Function,+,furi_hal_speaker_acquire,_Bool,uint32_t
Function,-,furi_hal_speaker_deinit,void,
Function,-,furi_hal_speaker_init,void,
@@ -1294,13 +1311,6 @@ Function,-,furi_hal_spi_config_init_early,void,
Function,-,furi_hal_spi_dma_init,void,
Function,+,furi_hal_spi_release,void,FuriHalSpiBusHandle*
Function,+,furi_hal_switch,void,void*
Function,+,furi_hal_uart_deinit,void,FuriHalUartId
Function,+,furi_hal_uart_init,void,"FuriHalUartId, uint32_t"
Function,+,furi_hal_uart_resume,void,FuriHalUartId
Function,+,furi_hal_uart_set_br,void,"FuriHalUartId, uint32_t"
Function,+,furi_hal_uart_set_irq_cb,void,"FuriHalUartId, void (*)(UartIrqEvent, uint8_t, void*), void*"
Function,+,furi_hal_uart_suspend,void,FuriHalUartId
Function,+,furi_hal_uart_tx,void,"FuriHalUartId, uint8_t*, size_t"
Function,+,furi_hal_usb_disable,void,
Function,+,furi_hal_usb_enable,void,
Function,+,furi_hal_usb_get_config,FuriHalUsbInterface*,
@@ -1346,15 +1356,17 @@ Function,+,furi_kernel_is_running,_Bool,
Function,+,furi_kernel_lock,int32_t,
Function,+,furi_kernel_restore_lock,int32_t,int32_t
Function,+,furi_kernel_unlock,int32_t,
Function,+,furi_log_add_handler,_Bool,FuriLogHandler
Function,+,furi_log_get_level,FuriLogLevel,
Function,-,furi_log_init,void,
Function,+,furi_log_level_from_string,_Bool,"const char*, FuriLogLevel*"
Function,+,furi_log_level_to_string,_Bool,"FuriLogLevel, const char**"
Function,+,furi_log_print_format,void,"FuriLogLevel, const char*, const char*, ..."
Function,+,furi_log_print_raw_format,void,"FuriLogLevel, const char*, ..."
Function,+,furi_log_puts,void,const char*
Function,+,furi_log_remove_handler,_Bool,FuriLogHandler
Function,+,furi_log_set_level,void,FuriLogLevel
Function,-,furi_log_set_puts,void,FuriLogPuts
Function,-,furi_log_set_timestamp,void,FuriLogTimestamp
Function,+,furi_log_tx,void,"const uint8_t*, size_t"
Function,+,furi_message_queue_alloc,FuriMessageQueue*,"uint32_t, uint32_t"
Function,+,furi_message_queue_free,void,FuriMessageQueue*
Function,+,furi_message_queue_get,FuriStatus,"FuriMessageQueue*, void*, uint32_t"
@@ -2418,10 +2430,10 @@ Function,-,utoa,char*,"unsigned, char*, int"
Function,+,validator_is_file_alloc_init,ValidatorIsFile*,"const char*, const char*, const char*"
Function,+,validator_is_file_callback,_Bool,"const char*, FuriString*, void*"
Function,+,validator_is_file_free,void,ValidatorIsFile*
Function,+,value_index_bool,uint8_t,"const _Bool, const _Bool[], uint8_t"
Function,+,value_index_float,uint8_t,"const float, const float[], uint8_t"
Function,+,value_index_int32,uint8_t,"const int32_t, const int32_t[], uint8_t"
Function,+,value_index_uint32,uint8_t,"const uint32_t, const uint32_t[], uint8_t"
Function,+,value_index_bool,size_t,"const _Bool, const _Bool[], size_t"
Function,+,value_index_float,size_t,"const float, const float[], size_t"
Function,+,value_index_int32,size_t,"const int32_t, const int32_t[], size_t"
Function,+,value_index_uint32,size_t,"const uint32_t, const uint32_t[], size_t"
Function,+,variable_item_get_context,void*,VariableItem*
Function,+,variable_item_get_current_value_index,uint8_t,VariableItem*
Function,+,variable_item_list_add,VariableItem*,"VariableItemList*, const char*, uint8_t, VariableItemChangeCallback, void*"
1 entry status name type params
2 Version + 50.1 51.0
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
160 Header + targets/f18/furi_hal/furi_hal_target_hw.h
161 Header + targets/f7/furi_hal/furi_hal_bus.h
162 Header + targets/f7/furi_hal/furi_hal_clock.h
Header + targets/f7/furi_hal/furi_hal_console.h
163 Header + targets/f7/furi_hal/furi_hal_dma.h
164 Header + targets/f7/furi_hal/furi_hal_flash.h
165 Header + targets/f7/furi_hal/furi_hal_gpio.h
169 Header + targets/f7/furi_hal/furi_hal_interrupt.h
170 Header + targets/f7/furi_hal/furi_hal_os.h
171 Header + targets/f7/furi_hal/furi_hal_pwm.h
172 Header + targets/f7/furi_hal/furi_hal_rtc.h
173 Header + targets/f7/furi_hal/furi_hal_serial.h
174 Header + targets/f7/furi_hal/furi_hal_serial_control.h
175 Header + targets/f7/furi_hal/furi_hal_serial_types.h
176 Header + targets/f7/furi_hal/furi_hal_spi_types.h
Header + targets/f7/furi_hal/furi_hal_uart.h
177 Header + targets/f7/furi_hal/furi_hal_usb_cdc.h
178 Header + targets/f7/platform_specific/intrinsic_export.h
179 Header + targets/f7/platform_specific/math_wrapper.h
192 Header + targets/furi_hal_include/furi_hal_power.h
193 Header + targets/furi_hal_include/furi_hal_random.h
194 Header + targets/furi_hal_include/furi_hal_region.h
Header + targets/furi_hal_include/furi_hal_rtc.h
195 Header + targets/furi_hal_include/furi_hal_sd.h
196 Header + targets/furi_hal_include/furi_hal_speaker.h
197 Header + targets/furi_hal_include/furi_hal_spi.h
1058 Function - furi_hal_clock_switch_hse2pll _Bool
1059 Function - furi_hal_clock_switch_hsi2hse void
1060 Function - furi_hal_clock_switch_pll2hse _Bool
Function + furi_hal_console_disable void
Function + furi_hal_console_enable void
Function + furi_hal_console_init void
Function + furi_hal_console_printf void const char[], ...
Function + furi_hal_console_puts void const char*
Function + furi_hal_console_set_tx_callback void FuriHalConsoleTxCallback, void*
Function + furi_hal_console_tx void const uint8_t*, size_t
Function + furi_hal_console_tx_with_new_line void const uint8_t*, size_t
1061 Function + furi_hal_cortex_comp_enable void FuriHalCortexComp, FuriHalCortexCompFunction, uint32_t, uint32_t, FuriHalCortexCompSize
1062 Function + furi_hal_cortex_comp_reset void FuriHalCortexComp
1063 Function + furi_hal_cortex_delay_us void uint32_t
1232 Function + furi_hal_rtc_get_locale_dateformat FuriHalRtcLocaleDateFormat
1233 Function + furi_hal_rtc_get_locale_timeformat FuriHalRtcLocaleTimeFormat
1234 Function + furi_hal_rtc_get_locale_units FuriHalRtcLocaleUnits
1235 Function + furi_hal_rtc_get_log_baud_rate FuriHalRtcLogBaudRate
1236 Function + furi_hal_rtc_get_log_device FuriHalRtcLogDevice
1237 Function + furi_hal_rtc_get_log_level uint8_t
1238 Function + furi_hal_rtc_get_pin_fails uint32_t
1239 Function + furi_hal_rtc_get_register uint32_t FuriHalRtcRegister
1252 Function + furi_hal_rtc_set_locale_dateformat void FuriHalRtcLocaleDateFormat
1253 Function + furi_hal_rtc_set_locale_timeformat void FuriHalRtcLocaleTimeFormat
1254 Function + furi_hal_rtc_set_locale_units void FuriHalRtcLocaleUnits
1255 Function + furi_hal_rtc_set_log_baud_rate void FuriHalRtcLogBaudRate
1256 Function + furi_hal_rtc_set_log_device void FuriHalRtcLogDevice
1257 Function + furi_hal_rtc_set_log_level void uint8_t
1258 Function + furi_hal_rtc_set_pin_fails void uint32_t
1259 Function + furi_hal_rtc_set_register void FuriHalRtcRegister, uint32_t
1268 Function + furi_hal_sd_presence_init void
1269 Function + furi_hal_sd_read_blocks FuriStatus uint32_t*, uint32_t, uint32_t
1270 Function + furi_hal_sd_write_blocks FuriStatus const uint32_t*, uint32_t, uint32_t
1271 Function + furi_hal_serial_control_acquire FuriHalSerialHandle* FuriHalSerialId
1272 Function + furi_hal_serial_control_deinit void
1273 Function + furi_hal_serial_control_init void
1274 Function + furi_hal_serial_control_release void FuriHalSerialHandle*
1275 Function + furi_hal_serial_control_resume void
1276 Function + furi_hal_serial_control_set_logging_config void FuriHalSerialId, uint32_t
1277 Function + furi_hal_serial_control_suspend void
1278 Function + furi_hal_serial_deinit void FuriHalSerialHandle*
1279 Function + furi_hal_serial_dma_rx size_t FuriHalSerialHandle*, uint8_t*, size_t
1280 Function + furi_hal_serial_dma_rx_start void FuriHalSerialHandle*, FuriHalSerialDmaRxCallback, void*, _Bool
1281 Function + furi_hal_serial_dma_rx_stop void FuriHalSerialHandle*
1282 Function + furi_hal_serial_init void FuriHalSerialHandle*, uint32_t
1283 Function + furi_hal_serial_resume void FuriHalSerialHandle*
1284 Function + furi_hal_serial_async_rx uint8_t FuriHalSerialHandle*
1285 Function + furi_hal_serial_async_rx_start void FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool
1286 Function + furi_hal_serial_async_rx_stop void FuriHalSerialHandle*
1287 Function + furi_hal_serial_set_br void FuriHalSerialHandle*, uint32_t
1288 Function + furi_hal_serial_suspend void FuriHalSerialHandle*
1289 Function + furi_hal_serial_tx void FuriHalSerialHandle*, const uint8_t*, size_t
1290 Function + furi_hal_serial_tx_wait_complete void FuriHalSerialHandle*
1291 Function + furi_hal_speaker_acquire _Bool uint32_t
1292 Function - furi_hal_speaker_deinit void
1293 Function - furi_hal_speaker_init void
1311 Function - furi_hal_spi_dma_init void
1312 Function + furi_hal_spi_release void FuriHalSpiBusHandle*
1313 Function + furi_hal_switch void void*
Function + furi_hal_uart_deinit void FuriHalUartId
Function + furi_hal_uart_init void FuriHalUartId, uint32_t
Function + furi_hal_uart_resume void FuriHalUartId
Function + furi_hal_uart_set_br void FuriHalUartId, uint32_t
Function + furi_hal_uart_set_irq_cb void FuriHalUartId, void (*)(UartIrqEvent, uint8_t, void*), void*
Function + furi_hal_uart_suspend void FuriHalUartId
Function + furi_hal_uart_tx void FuriHalUartId, uint8_t*, size_t
1314 Function + furi_hal_usb_disable void
1315 Function + furi_hal_usb_enable void
1316 Function + furi_hal_usb_get_config FuriHalUsbInterface*
1356 Function + furi_kernel_lock int32_t
1357 Function + furi_kernel_restore_lock int32_t int32_t
1358 Function + furi_kernel_unlock int32_t
1359 Function + furi_log_add_handler _Bool FuriLogHandler
1360 Function + furi_log_get_level FuriLogLevel
1361 Function - furi_log_init void
1362 Function + furi_log_level_from_string _Bool const char*, FuriLogLevel*
1363 Function + furi_log_level_to_string _Bool FuriLogLevel, const char**
1364 Function + furi_log_print_format void FuriLogLevel, const char*, const char*, ...
1365 Function + furi_log_print_raw_format void FuriLogLevel, const char*, ...
1366 Function + furi_log_puts void const char*
1367 Function + furi_log_remove_handler _Bool FuriLogHandler
1368 Function + furi_log_set_level void FuriLogLevel
1369 Function - + furi_log_set_puts furi_log_tx void FuriLogPuts const uint8_t*, size_t
Function - furi_log_set_timestamp void FuriLogTimestamp
1370 Function + furi_message_queue_alloc FuriMessageQueue* uint32_t, uint32_t
1371 Function + furi_message_queue_free void FuriMessageQueue*
1372 Function + furi_message_queue_get FuriStatus FuriMessageQueue*, void*, uint32_t
2430 Function + validator_is_file_alloc_init ValidatorIsFile* const char*, const char*, const char*
2431 Function + validator_is_file_callback _Bool const char*, FuriString*, void*
2432 Function + validator_is_file_free void ValidatorIsFile*
2433 Function + value_index_bool uint8_t size_t const _Bool, const _Bool[], uint8_t const _Bool, const _Bool[], size_t
2434 Function + value_index_float uint8_t size_t const float, const float[], uint8_t const float, const float[], size_t
2435 Function + value_index_int32 uint8_t size_t const int32_t, const int32_t[], uint8_t const int32_t, const int32_t[], size_t
2436 Function + value_index_uint32 uint8_t size_t const uint32_t, const uint32_t[], uint8_t const uint32_t, const uint32_t[], size_t
2437 Function + variable_item_get_context void* VariableItem*
2438 Function + variable_item_get_current_value_index uint8_t VariableItem*
2439 Function + variable_item_list_add VariableItem* VariableItemList*, const char*, uint8_t, VariableItemChangeCallback, void*
+1 -1
View File
@@ -33,7 +33,7 @@ void furi_hal_init() {
furi_hal_mpu_init();
furi_hal_clock_init();
furi_hal_random_init();
furi_hal_console_init();
furi_hal_serial_control_init();
furi_hal_rtc_init();
furi_hal_interrupt_init();
furi_hal_flash_init();
+37 -25
View File
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,50.1,,
Version,+,51.0,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
@@ -221,7 +221,6 @@ Header,+,lib/toolbox/value_index.h,,
Header,+,lib/toolbox/version.h,,
Header,+,targets/f7/furi_hal/furi_hal_bus.h,,
Header,+,targets/f7/furi_hal/furi_hal_clock.h,,
Header,+,targets/f7/furi_hal/furi_hal_console.h,,
Header,+,targets/f7/furi_hal/furi_hal_dma.h,,
Header,+,targets/f7/furi_hal/furi_hal_flash.h,,
Header,+,targets/f7/furi_hal/furi_hal_gpio.h,,
@@ -234,11 +233,14 @@ Header,+,targets/f7/furi_hal/furi_hal_os.h,,
Header,+,targets/f7/furi_hal/furi_hal_pwm.h,,
Header,+,targets/f7/furi_hal/furi_hal_resources.h,,
Header,+,targets/f7/furi_hal/furi_hal_rfid.h,,
Header,+,targets/f7/furi_hal/furi_hal_rtc.h,,
Header,+,targets/f7/furi_hal/furi_hal_serial.h,,
Header,+,targets/f7/furi_hal/furi_hal_serial_control.h,,
Header,+,targets/f7/furi_hal/furi_hal_serial_types.h,,
Header,+,targets/f7/furi_hal/furi_hal_spi_config.h,,
Header,+,targets/f7/furi_hal/furi_hal_spi_types.h,,
Header,+,targets/f7/furi_hal/furi_hal_subghz.h,,
Header,+,targets/f7/furi_hal/furi_hal_target_hw.h,,
Header,+,targets/f7/furi_hal/furi_hal_uart.h,,
Header,+,targets/f7/furi_hal/furi_hal_usb_cdc.h,,
Header,+,targets/f7/platform_specific/intrinsic_export.h,,
Header,+,targets/f7/platform_specific/math_wrapper.h,,
@@ -259,7 +261,6 @@ Header,+,targets/furi_hal_include/furi_hal_nfc.h,,
Header,+,targets/furi_hal_include/furi_hal_power.h,,
Header,+,targets/furi_hal_include/furi_hal_random.h,,
Header,+,targets/furi_hal_include/furi_hal_region.h,,
Header,+,targets/furi_hal_include/furi_hal_rtc.h,,
Header,+,targets/furi_hal_include/furi_hal_sd.h,,
Header,+,targets/furi_hal_include/furi_hal_speaker.h,,
Header,+,targets/furi_hal_include/furi_hal_spi.h,,
@@ -1146,14 +1147,6 @@ Function,-,furi_hal_clock_switch_hse2hsi,void,
Function,-,furi_hal_clock_switch_hse2pll,_Bool,
Function,-,furi_hal_clock_switch_hsi2hse,void,
Function,-,furi_hal_clock_switch_pll2hse,_Bool,
Function,+,furi_hal_console_disable,void,
Function,+,furi_hal_console_enable,void,
Function,+,furi_hal_console_init,void,
Function,+,furi_hal_console_printf,void,"const char[], ..."
Function,+,furi_hal_console_puts,void,const char*
Function,+,furi_hal_console_set_tx_callback,void,"FuriHalConsoleTxCallback, void*"
Function,+,furi_hal_console_tx,void,"const uint8_t*, size_t"
Function,+,furi_hal_console_tx_with_new_line,void,"const uint8_t*, size_t"
Function,+,furi_hal_cortex_comp_enable,void,"FuriHalCortexComp, FuriHalCortexCompFunction, uint32_t, uint32_t, FuriHalCortexCompSize"
Function,+,furi_hal_cortex_comp_reset,void,FuriHalCortexComp
Function,+,furi_hal_cortex_delay_us,void,uint32_t
@@ -1405,6 +1398,8 @@ Function,+,furi_hal_rtc_get_heap_track_mode,FuriHalRtcHeapTrackMode,
Function,+,furi_hal_rtc_get_locale_dateformat,FuriHalRtcLocaleDateFormat,
Function,+,furi_hal_rtc_get_locale_timeformat,FuriHalRtcLocaleTimeFormat,
Function,+,furi_hal_rtc_get_locale_units,FuriHalRtcLocaleUnits,
Function,+,furi_hal_rtc_get_log_baud_rate,FuriHalRtcLogBaudRate,
Function,+,furi_hal_rtc_get_log_device,FuriHalRtcLogDevice,
Function,+,furi_hal_rtc_get_log_level,uint8_t,
Function,+,furi_hal_rtc_get_pin_fails,uint32_t,
Function,+,furi_hal_rtc_get_register,uint32_t,FuriHalRtcRegister
@@ -1423,6 +1418,8 @@ Function,+,furi_hal_rtc_set_heap_track_mode,void,FuriHalRtcHeapTrackMode
Function,+,furi_hal_rtc_set_locale_dateformat,void,FuriHalRtcLocaleDateFormat
Function,+,furi_hal_rtc_set_locale_timeformat,void,FuriHalRtcLocaleTimeFormat
Function,+,furi_hal_rtc_set_locale_units,void,FuriHalRtcLocaleUnits
Function,+,furi_hal_rtc_set_log_baud_rate,void,FuriHalRtcLogBaudRate
Function,+,furi_hal_rtc_set_log_device,void,FuriHalRtcLogDevice
Function,+,furi_hal_rtc_set_log_level,void,uint8_t
Function,+,furi_hal_rtc_set_pin_fails,void,uint32_t
Function,+,furi_hal_rtc_set_register,void,"FuriHalRtcRegister, uint32_t"
@@ -1437,6 +1434,26 @@ Function,+,furi_hal_sd_max_mount_retry_count,uint8_t,
Function,+,furi_hal_sd_presence_init,void,
Function,+,furi_hal_sd_read_blocks,FuriStatus,"uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_sd_write_blocks,FuriStatus,"const uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_serial_control_acquire,FuriHalSerialHandle*,FuriHalSerialId
Function,+,furi_hal_serial_control_deinit,void,
Function,+,furi_hal_serial_control_init,void,
Function,+,furi_hal_serial_control_release,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_control_resume,void,
Function,+,furi_hal_serial_control_set_logging_config,void,"FuriHalSerialId, uint32_t"
Function,+,furi_hal_serial_control_suspend,void,
Function,+,furi_hal_serial_deinit,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_dma_rx,size_t,"FuriHalSerialHandle*, uint8_t*, size_t"
Function,+,furi_hal_serial_dma_rx_start,void,"FuriHalSerialHandle*, FuriHalSerialDmaRxCallback, void*, _Bool"
Function,+,furi_hal_serial_dma_rx_stop,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_init,void,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_resume,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_async_rx,uint8_t,FuriHalSerialHandle*
Function,+,furi_hal_serial_async_rx_start,void,"FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool"
Function,+,furi_hal_serial_async_rx_stop,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_set_br,void,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_suspend,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_tx,void,"FuriHalSerialHandle*, const uint8_t*, size_t"
Function,+,furi_hal_serial_tx_wait_complete,void,FuriHalSerialHandle*
Function,+,furi_hal_speaker_acquire,_Bool,uint32_t
Function,-,furi_hal_speaker_deinit,void,
Function,-,furi_hal_speaker_init,void,
@@ -1490,13 +1507,6 @@ Function,+,furi_hal_subghz_stop_async_tx,void,
Function,+,furi_hal_subghz_tx,_Bool,
Function,+,furi_hal_subghz_write_packet,void,"const uint8_t*, uint8_t"
Function,+,furi_hal_switch,void,void*
Function,+,furi_hal_uart_deinit,void,FuriHalUartId
Function,+,furi_hal_uart_init,void,"FuriHalUartId, uint32_t"
Function,+,furi_hal_uart_resume,void,FuriHalUartId
Function,+,furi_hal_uart_set_br,void,"FuriHalUartId, uint32_t"
Function,+,furi_hal_uart_set_irq_cb,void,"FuriHalUartId, void (*)(UartIrqEvent, uint8_t, void*), void*"
Function,+,furi_hal_uart_suspend,void,FuriHalUartId
Function,+,furi_hal_uart_tx,void,"FuriHalUartId, uint8_t*, size_t"
Function,+,furi_hal_usb_disable,void,
Function,+,furi_hal_usb_enable,void,
Function,+,furi_hal_usb_get_config,FuriHalUsbInterface*,
@@ -1542,15 +1552,17 @@ Function,+,furi_kernel_is_running,_Bool,
Function,+,furi_kernel_lock,int32_t,
Function,+,furi_kernel_restore_lock,int32_t,int32_t
Function,+,furi_kernel_unlock,int32_t,
Function,+,furi_log_add_handler,_Bool,FuriLogHandler
Function,+,furi_log_get_level,FuriLogLevel,
Function,-,furi_log_init,void,
Function,+,furi_log_level_from_string,_Bool,"const char*, FuriLogLevel*"
Function,+,furi_log_level_to_string,_Bool,"FuriLogLevel, const char**"
Function,+,furi_log_print_format,void,"FuriLogLevel, const char*, const char*, ..."
Function,+,furi_log_print_raw_format,void,"FuriLogLevel, const char*, ..."
Function,+,furi_log_puts,void,const char*
Function,+,furi_log_remove_handler,_Bool,FuriLogHandler
Function,+,furi_log_set_level,void,FuriLogLevel
Function,-,furi_log_set_puts,void,FuriLogPuts
Function,-,furi_log_set_timestamp,void,FuriLogTimestamp
Function,+,furi_log_tx,void,"const uint8_t*, size_t"
Function,+,furi_message_queue_alloc,FuriMessageQueue*,"uint32_t, uint32_t"
Function,+,furi_message_queue_free,void,FuriMessageQueue*
Function,+,furi_message_queue_get,FuriStatus,"FuriMessageQueue*, void*, uint32_t"
@@ -3202,10 +3214,10 @@ Function,-,utoa,char*,"unsigned, char*, int"
Function,+,validator_is_file_alloc_init,ValidatorIsFile*,"const char*, const char*, const char*"
Function,+,validator_is_file_callback,_Bool,"const char*, FuriString*, void*"
Function,+,validator_is_file_free,void,ValidatorIsFile*
Function,+,value_index_bool,uint8_t,"const _Bool, const _Bool[], uint8_t"
Function,+,value_index_float,uint8_t,"const float, const float[], uint8_t"
Function,+,value_index_int32,uint8_t,"const int32_t, const int32_t[], uint8_t"
Function,+,value_index_uint32,uint8_t,"const uint32_t, const uint32_t[], uint8_t"
Function,+,value_index_bool,size_t,"const _Bool, const _Bool[], size_t"
Function,+,value_index_float,size_t,"const float, const float[], size_t"
Function,+,value_index_int32,size_t,"const int32_t, const int32_t[], size_t"
Function,+,value_index_uint32,size_t,"const uint32_t, const uint32_t[], size_t"
Function,+,variable_item_get_context,void*,VariableItem*
Function,+,variable_item_get_current_value_index,uint8_t,VariableItem*
Function,+,variable_item_list_add,VariableItem*,"VariableItemList*, const char*, uint8_t, VariableItemChangeCallback, void*"
1 entry status name type params
2 Version + 50.1 51.0
3 Header + applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h
4 Header + applications/services/bt/bt_service/bt.h
5 Header + applications/services/cli/cli.h
221 Header + lib/toolbox/version.h
222 Header + targets/f7/furi_hal/furi_hal_bus.h
223 Header + targets/f7/furi_hal/furi_hal_clock.h
Header + targets/f7/furi_hal/furi_hal_console.h
224 Header + targets/f7/furi_hal/furi_hal_dma.h
225 Header + targets/f7/furi_hal/furi_hal_flash.h
226 Header + targets/f7/furi_hal/furi_hal_gpio.h
233 Header + targets/f7/furi_hal/furi_hal_pwm.h
234 Header + targets/f7/furi_hal/furi_hal_resources.h
235 Header + targets/f7/furi_hal/furi_hal_rfid.h
236 Header + targets/f7/furi_hal/furi_hal_rtc.h
237 Header + targets/f7/furi_hal/furi_hal_serial.h
238 Header + targets/f7/furi_hal/furi_hal_serial_control.h
239 Header + targets/f7/furi_hal/furi_hal_serial_types.h
240 Header + targets/f7/furi_hal/furi_hal_spi_config.h
241 Header + targets/f7/furi_hal/furi_hal_spi_types.h
242 Header + targets/f7/furi_hal/furi_hal_subghz.h
243 Header + targets/f7/furi_hal/furi_hal_target_hw.h
Header + targets/f7/furi_hal/furi_hal_uart.h
244 Header + targets/f7/furi_hal/furi_hal_usb_cdc.h
245 Header + targets/f7/platform_specific/intrinsic_export.h
246 Header + targets/f7/platform_specific/math_wrapper.h
261 Header + targets/furi_hal_include/furi_hal_power.h
262 Header + targets/furi_hal_include/furi_hal_random.h
263 Header + targets/furi_hal_include/furi_hal_region.h
Header + targets/furi_hal_include/furi_hal_rtc.h
264 Header + targets/furi_hal_include/furi_hal_sd.h
265 Header + targets/furi_hal_include/furi_hal_speaker.h
266 Header + targets/furi_hal_include/furi_hal_spi.h
1147 Function - furi_hal_clock_switch_hse2pll _Bool
1148 Function - furi_hal_clock_switch_hsi2hse void
1149 Function - furi_hal_clock_switch_pll2hse _Bool
Function + furi_hal_console_disable void
Function + furi_hal_console_enable void
Function + furi_hal_console_init void
Function + furi_hal_console_printf void const char[], ...
Function + furi_hal_console_puts void const char*
Function + furi_hal_console_set_tx_callback void FuriHalConsoleTxCallback, void*
Function + furi_hal_console_tx void const uint8_t*, size_t
Function + furi_hal_console_tx_with_new_line void const uint8_t*, size_t
1150 Function + furi_hal_cortex_comp_enable void FuriHalCortexComp, FuriHalCortexCompFunction, uint32_t, uint32_t, FuriHalCortexCompSize
1151 Function + furi_hal_cortex_comp_reset void FuriHalCortexComp
1152 Function + furi_hal_cortex_delay_us void uint32_t
1398 Function + furi_hal_rtc_get_locale_dateformat FuriHalRtcLocaleDateFormat
1399 Function + furi_hal_rtc_get_locale_timeformat FuriHalRtcLocaleTimeFormat
1400 Function + furi_hal_rtc_get_locale_units FuriHalRtcLocaleUnits
1401 Function + furi_hal_rtc_get_log_baud_rate FuriHalRtcLogBaudRate
1402 Function + furi_hal_rtc_get_log_device FuriHalRtcLogDevice
1403 Function + furi_hal_rtc_get_log_level uint8_t
1404 Function + furi_hal_rtc_get_pin_fails uint32_t
1405 Function + furi_hal_rtc_get_register uint32_t FuriHalRtcRegister
1418 Function + furi_hal_rtc_set_locale_dateformat void FuriHalRtcLocaleDateFormat
1419 Function + furi_hal_rtc_set_locale_timeformat void FuriHalRtcLocaleTimeFormat
1420 Function + furi_hal_rtc_set_locale_units void FuriHalRtcLocaleUnits
1421 Function + furi_hal_rtc_set_log_baud_rate void FuriHalRtcLogBaudRate
1422 Function + furi_hal_rtc_set_log_device void FuriHalRtcLogDevice
1423 Function + furi_hal_rtc_set_log_level void uint8_t
1424 Function + furi_hal_rtc_set_pin_fails void uint32_t
1425 Function + furi_hal_rtc_set_register void FuriHalRtcRegister, uint32_t
1434 Function + furi_hal_sd_presence_init void
1435 Function + furi_hal_sd_read_blocks FuriStatus uint32_t*, uint32_t, uint32_t
1436 Function + furi_hal_sd_write_blocks FuriStatus const uint32_t*, uint32_t, uint32_t
1437 Function + furi_hal_serial_control_acquire FuriHalSerialHandle* FuriHalSerialId
1438 Function + furi_hal_serial_control_deinit void
1439 Function + furi_hal_serial_control_init void
1440 Function + furi_hal_serial_control_release void FuriHalSerialHandle*
1441 Function + furi_hal_serial_control_resume void
1442 Function + furi_hal_serial_control_set_logging_config void FuriHalSerialId, uint32_t
1443 Function + furi_hal_serial_control_suspend void
1444 Function + furi_hal_serial_deinit void FuriHalSerialHandle*
1445 Function + furi_hal_serial_dma_rx size_t FuriHalSerialHandle*, uint8_t*, size_t
1446 Function + furi_hal_serial_dma_rx_start void FuriHalSerialHandle*, FuriHalSerialDmaRxCallback, void*, _Bool
1447 Function + furi_hal_serial_dma_rx_stop void FuriHalSerialHandle*
1448 Function + furi_hal_serial_init void FuriHalSerialHandle*, uint32_t
1449 Function + furi_hal_serial_resume void FuriHalSerialHandle*
1450 Function + furi_hal_serial_async_rx uint8_t FuriHalSerialHandle*
1451 Function + furi_hal_serial_async_rx_start void FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool
1452 Function + furi_hal_serial_async_rx_stop void FuriHalSerialHandle*
1453 Function + furi_hal_serial_set_br void FuriHalSerialHandle*, uint32_t
1454 Function + furi_hal_serial_suspend void FuriHalSerialHandle*
1455 Function + furi_hal_serial_tx void FuriHalSerialHandle*, const uint8_t*, size_t
1456 Function + furi_hal_serial_tx_wait_complete void FuriHalSerialHandle*
1457 Function + furi_hal_speaker_acquire _Bool uint32_t
1458 Function - furi_hal_speaker_deinit void
1459 Function - furi_hal_speaker_init void
1507 Function + furi_hal_subghz_tx _Bool
1508 Function + furi_hal_subghz_write_packet void const uint8_t*, uint8_t
1509 Function + furi_hal_switch void void*
Function + furi_hal_uart_deinit void FuriHalUartId
Function + furi_hal_uart_init void FuriHalUartId, uint32_t
Function + furi_hal_uart_resume void FuriHalUartId
Function + furi_hal_uart_set_br void FuriHalUartId, uint32_t
Function + furi_hal_uart_set_irq_cb void FuriHalUartId, void (*)(UartIrqEvent, uint8_t, void*), void*
Function + furi_hal_uart_suspend void FuriHalUartId
Function + furi_hal_uart_tx void FuriHalUartId, uint8_t*, size_t
1510 Function + furi_hal_usb_disable void
1511 Function + furi_hal_usb_enable void
1512 Function + furi_hal_usb_get_config FuriHalUsbInterface*
1552 Function + furi_kernel_lock int32_t
1553 Function + furi_kernel_restore_lock int32_t int32_t
1554 Function + furi_kernel_unlock int32_t
1555 Function + furi_log_add_handler _Bool FuriLogHandler
1556 Function + furi_log_get_level FuriLogLevel
1557 Function - furi_log_init void
1558 Function + furi_log_level_from_string _Bool const char*, FuriLogLevel*
1559 Function + furi_log_level_to_string _Bool FuriLogLevel, const char**
1560 Function + furi_log_print_format void FuriLogLevel, const char*, const char*, ...
1561 Function + furi_log_print_raw_format void FuriLogLevel, const char*, ...
1562 Function + furi_log_puts void const char*
1563 Function + furi_log_remove_handler _Bool FuriLogHandler
1564 Function + furi_log_set_level void FuriLogLevel
1565 Function - + furi_log_set_puts furi_log_tx void FuriLogPuts const uint8_t*, size_t
Function - furi_log_set_timestamp void FuriLogTimestamp
1566 Function + furi_message_queue_alloc FuriMessageQueue* uint32_t, uint32_t
1567 Function + furi_message_queue_free void FuriMessageQueue*
1568 Function + furi_message_queue_get FuriStatus FuriMessageQueue*, void*, uint32_t
3214 Function + validator_is_file_alloc_init ValidatorIsFile* const char*, const char*, const char*
3215 Function + validator_is_file_callback _Bool const char*, FuriString*, void*
3216 Function + validator_is_file_free void ValidatorIsFile*
3217 Function + value_index_bool uint8_t size_t const _Bool, const _Bool[], uint8_t const _Bool, const _Bool[], size_t
3218 Function + value_index_float uint8_t size_t const float, const float[], uint8_t const float, const float[], size_t
3219 Function + value_index_int32 uint8_t size_t const int32_t, const int32_t[], uint8_t const int32_t, const int32_t[], size_t
3220 Function + value_index_uint32 uint8_t size_t const uint32_t, const uint32_t[], uint8_t const uint32_t, const uint32_t[], size_t
3221 Function + variable_item_get_context void* VariableItem*
3222 Function + variable_item_get_current_value_index uint8_t VariableItem*
3223 Function + variable_item_list_add VariableItem* VariableItemList*, const char*, uint8_t, VariableItemChangeCallback, void*
+1 -1
View File
@@ -33,7 +33,7 @@ void furi_hal_init() {
furi_hal_mpu_init();
furi_hal_clock_init();
furi_hal_random_init();
furi_hal_console_init();
furi_hal_serial_control_init();
furi_hal_rtc_init();
furi_hal_interrupt_init();
furi_hal_flash_init();
-99
View File
@@ -1,99 +0,0 @@
#include <furi_hal_console.h>
#include <furi_hal_uart.h>
#include <stdbool.h>
#include <stm32wbxx_ll_gpio.h>
#include <stm32wbxx_ll_usart.h>
#include <furi.h>
#define TAG "FuriHalConsole"
#ifdef HEAP_PRINT_DEBUG
#define CONSOLE_BAUDRATE 1843200
#else
#define CONSOLE_BAUDRATE 230400
#endif
typedef struct {
bool alive;
FuriHalConsoleTxCallback tx_callback;
void* tx_callback_context;
} FuriHalConsole;
FuriHalConsole furi_hal_console = {
.alive = false,
.tx_callback = NULL,
.tx_callback_context = NULL,
};
void furi_hal_console_init() {
furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
furi_hal_console.alive = true;
}
void furi_hal_console_enable() {
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
while(!LL_USART_IsActiveFlag_TC(USART1))
;
furi_hal_uart_set_br(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
furi_hal_console.alive = true;
}
void furi_hal_console_disable() {
while(!LL_USART_IsActiveFlag_TC(USART1))
;
furi_hal_console.alive = false;
}
void furi_hal_console_set_tx_callback(FuriHalConsoleTxCallback callback, void* context) {
FURI_CRITICAL_ENTER();
furi_hal_console.tx_callback = callback;
furi_hal_console.tx_callback_context = context;
FURI_CRITICAL_EXIT();
}
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
if(!furi_hal_console.alive) return;
FURI_CRITICAL_ENTER();
// Transmit data
if(furi_hal_console.tx_callback) {
furi_hal_console.tx_callback(buffer, buffer_size, furi_hal_console.tx_callback_context);
}
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
// Wait for TC flag to be raised for last char
while(!LL_USART_IsActiveFlag_TC(USART1))
;
FURI_CRITICAL_EXIT();
}
void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size) {
if(!furi_hal_console.alive) return;
FURI_CRITICAL_ENTER();
// Transmit data
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
// Transmit new line symbols
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)"\r\n", 2);
// Wait for TC flag to be raised for last char
while(!LL_USART_IsActiveFlag_TC(USART1))
;
FURI_CRITICAL_EXIT();
}
void furi_hal_console_printf(const char format[], ...) {
FuriString* string;
va_list args;
va_start(args, format);
string = furi_string_alloc_vprintf(format, args);
va_end(args);
furi_hal_console_tx((const uint8_t*)furi_string_get_cstr(string), furi_string_size(string));
furi_string_free(string);
}
void furi_hal_console_puts(const char* data) {
furi_hal_console_tx((const uint8_t*)data, strlen(data));
}
-37
View File
@@ -1,37 +0,0 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*FuriHalConsoleTxCallback)(const uint8_t* buffer, size_t size, void* context);
void furi_hal_console_init();
void furi_hal_console_enable();
void furi_hal_console_disable();
void furi_hal_console_set_tx_callback(FuriHalConsoleTxCallback callback, void* context);
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size);
void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size);
/**
* Printf-like plain uart interface
* @warning Will not work in ISR context
* @param format
* @param ...
*/
void furi_hal_console_printf(const char format[], ...) _ATTRIBUTE((__format__(__printf__, 1, 2)));
void furi_hal_console_puts(const char* data);
#ifdef __cplusplus
}
#endif
+14
View File
@@ -59,6 +59,12 @@ const IRQn_Type furi_hal_interrupt_irqn[FuriHalInterruptIdMax] = {
// LPTIMx
[FuriHalInterruptIdLpTim1] = LPTIM1_IRQn,
[FuriHalInterruptIdLpTim2] = LPTIM2_IRQn,
// UARTx
[FuriHalInterruptIdUart1] = USART1_IRQn,
// LPUARTx
[FuriHalInterruptIdLpUart1] = LPUART1_IRQn,
};
__attribute__((always_inline)) static inline void
@@ -329,3 +335,11 @@ void LPTIM1_IRQHandler() {
void LPTIM2_IRQHandler() {
furi_hal_interrupt_call(FuriHalInterruptIdLpTim2);
}
void USART1_IRQHandler(void) {
furi_hal_interrupt_call(FuriHalInterruptIdUart1);
}
void LPUART1_IRQHandler(void) {
furi_hal_interrupt_call(FuriHalInterruptIdLpUart1);
}
+6
View File
@@ -49,6 +49,12 @@ typedef enum {
FuriHalInterruptIdLpTim1,
FuriHalInterruptIdLpTim2,
//UARTx
FuriHalInterruptIdUart1,
//LPUARTx
FuriHalInterruptIdLpUart1,
// Service value
FuriHalInterruptIdMax,
} FuriHalInterruptId;
+3 -4
View File
@@ -1,6 +1,5 @@
#include <furi_hal_os.h>
#include <furi_hal_clock.h>
#include <furi_hal_console.h>
#include <furi_hal_power.h>
#include <furi_hal_gpio.h>
#include <furi_hal_resources.h>
@@ -208,8 +207,8 @@ void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
void vApplicationStackOverflowHook(TaskHandle_t xTask, char* pcTaskName) {
UNUSED(xTask);
furi_hal_console_puts("\r\n\r\n stack overflow in ");
furi_hal_console_puts(pcTaskName);
furi_hal_console_puts("\r\n\r\n");
furi_log_puts("\r\n\r\n stack overflow in ");
furi_log_puts(pcTaskName);
furi_log_puts("\r\n\r\n");
furi_crash("StackOverflow");
}
+3 -5
View File
@@ -3,7 +3,7 @@
#include <furi_hal_bt.h>
#include <furi_hal_vibro.h>
#include <furi_hal_resources.h>
#include <furi_hal_uart.h>
#include <furi_hal_serial_control.h>
#include <furi_hal_rtc.h>
#include <furi_hal_debug.h>
@@ -178,14 +178,12 @@ static inline void furi_hal_power_light_sleep() {
static inline void furi_hal_power_suspend_aux_periphs() {
// Disable USART
furi_hal_uart_suspend(FuriHalUartIdUSART1);
furi_hal_uart_suspend(FuriHalUartIdLPUART1);
furi_hal_serial_control_suspend();
}
static inline void furi_hal_power_resume_aux_periphs() {
// Re-enable USART
furi_hal_uart_resume(FuriHalUartIdUSART1);
furi_hal_uart_resume(FuriHalUartIdLPUART1);
furi_hal_serial_control_resume();
}
static inline void furi_hal_power_deep_sleep() {
+59 -1
View File
@@ -1,6 +1,7 @@
#include <furi_hal_rtc.h>
#include <furi_hal_light.h>
#include <furi_hal_debug.h>
#include <furi_hal_serial_control.h>
#include <stm32wbxx_ll_pwr.h>
#include <stm32wbxx_ll_bus.h>
@@ -34,7 +35,9 @@ typedef struct {
FuriHalRtcLocaleUnits locale_units : 1;
FuriHalRtcLocaleTimeFormat locale_timeformat : 1;
FuriHalRtcLocaleDateFormat locale_dateformat : 2;
uint8_t reserved : 6;
FuriHalRtcLogDevice log_device : 2;
FuriHalRtcLogBaudRate log_baud_rate : 3;
uint8_t reserved : 1;
} SystemReg;
_Static_assert(sizeof(SystemReg) == 4, "SystemReg size mismatch");
@@ -51,6 +54,24 @@ static const uint8_t furi_hal_rtc_days_per_month[2][FURI_HAL_RTC_MONTHS_COUNT] =
static const uint16_t furi_hal_rtc_days_per_year[] = {365, 366};
static const FuriHalSerialId furi_hal_rtc_log_devices[] = {
[FuriHalRtcLogDeviceUsart] = FuriHalSerialIdUsart,
[FuriHalRtcLogDeviceLpuart] = FuriHalSerialIdLpuart,
[FuriHalRtcLogDeviceReserved] = FuriHalSerialIdMax,
[FuriHalRtcLogDeviceNone] = FuriHalSerialIdMax,
};
static const uint32_t furi_hal_rtc_log_baud_rates[] = {
[FuriHalRtcLogBaudRate230400] = 230400,
[FuriHalRtcLogBaudRate9600] = 9600,
[FuriHalRtcLogBaudRate38400] = 38400,
[FuriHalRtcLogBaudRate57600] = 57600,
[FuriHalRtcLogBaudRate115200] = 115200,
[FuriHalRtcLogBaudRate460800] = 460800,
[FuriHalRtcLogBaudRate921600] = 921600,
[FuriHalRtcLogBaudRate1843200] = 1843200,
};
static void furi_hal_rtc_reset() {
LL_RCC_ForceBackupDomainReset();
LL_RCC_ReleaseBackupDomainReset();
@@ -153,6 +174,9 @@ void furi_hal_rtc_init() {
LL_RTC_Init(RTC, &RTC_InitStruct);
furi_log_set_level(furi_hal_rtc_get_log_level());
furi_hal_serial_control_set_logging_config(
furi_hal_rtc_log_devices[furi_hal_rtc_get_log_device()],
furi_hal_rtc_log_baud_rates[furi_hal_rtc_get_log_baud_rate()]);
FURI_LOG_I(TAG, "Init OK");
}
@@ -199,6 +223,40 @@ uint8_t furi_hal_rtc_get_log_level() {
return data->log_level;
}
void furi_hal_rtc_set_log_device(FuriHalRtcLogDevice device) {
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
SystemReg* data = (SystemReg*)&data_reg;
data->log_device = device;
furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg);
furi_hal_serial_control_set_logging_config(
furi_hal_rtc_log_devices[furi_hal_rtc_get_log_device()],
furi_hal_rtc_log_baud_rates[furi_hal_rtc_get_log_baud_rate()]);
}
FuriHalRtcLogDevice furi_hal_rtc_get_log_device() {
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
SystemReg* data = (SystemReg*)&data_reg;
return data->log_device;
}
void furi_hal_rtc_set_log_baud_rate(FuriHalRtcLogBaudRate baud_rate) {
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
SystemReg* data = (SystemReg*)&data_reg;
data->log_baud_rate = baud_rate;
furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg);
furi_hal_serial_control_set_logging_config(
furi_hal_rtc_log_devices[furi_hal_rtc_get_log_device()],
furi_hal_rtc_log_baud_rates[furi_hal_rtc_get_log_baud_rate()]);
}
FuriHalRtcLogBaudRate furi_hal_rtc_get_log_baud_rate() {
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
SystemReg* data = (SystemReg*)&data_reg;
return data->log_baud_rate;
}
void furi_hal_rtc_set_flag(FuriHalRtcFlag flag) {
uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem);
SystemReg* data = (SystemReg*)&data_reg;
@@ -64,32 +64,50 @@ typedef enum {
} FuriHalRtcRegister;
typedef enum {
FuriHalRtcLocaleUnitsMetric = 0, /**< Metric measurement units */
FuriHalRtcLocaleUnitsImperial = 1, /**< Imperial measurement units */
FuriHalRtcLocaleUnitsMetric = 0x0, /**< Metric measurement units */
FuriHalRtcLocaleUnitsImperial = 0x1, /**< Imperial measurement units */
} FuriHalRtcLocaleUnits;
typedef enum {
FuriHalRtcLocaleTimeFormat24h = 0, /**< 24-hour format */
FuriHalRtcLocaleTimeFormat12h = 1, /**< 12-hour format */
FuriHalRtcLocaleTimeFormat24h = 0x0, /**< 24-hour format */
FuriHalRtcLocaleTimeFormat12h = 0x1, /**< 12-hour format */
} FuriHalRtcLocaleTimeFormat;
typedef enum {
FuriHalRtcLocaleDateFormatDMY = 0, /**< Day/Month/Year */
FuriHalRtcLocaleDateFormatMDY = 1, /**< Month/Day/Year */
FuriHalRtcLocaleDateFormatYMD = 2, /**< Year/Month/Day */
FuriHalRtcLocaleDateFormatDMY = 0x0, /**< Day/Month/Year */
FuriHalRtcLocaleDateFormatMDY = 0x1, /**< Month/Day/Year */
FuriHalRtcLocaleDateFormatYMD = 0x2, /**< Year/Month/Day */
} FuriHalRtcLocaleDateFormat;
typedef enum {
FuriHalRtcLogDeviceUsart = 0x0, /**< Default: USART */
FuriHalRtcLogDeviceLpuart = 0x1, /**< Default: LPUART */
FuriHalRtcLogDeviceReserved = 0x2, /**< Reserved for future use */
FuriHalRtcLogDeviceNone = 0x3, /**< None, disable serial logging */
} FuriHalRtcLogDevice;
typedef enum {
FuriHalRtcLogBaudRate230400 = 0x0, /**< 230400 baud */
FuriHalRtcLogBaudRate9600 = 0x1, /**< 9600 baud */
FuriHalRtcLogBaudRate38400 = 0x2, /**< 38400 baud */
FuriHalRtcLogBaudRate57600 = 0x3, /**< 57600 baud */
FuriHalRtcLogBaudRate115200 = 0x4, /**< 115200 baud */
FuriHalRtcLogBaudRate460800 = 0x5, /**< 460800 baud */
FuriHalRtcLogBaudRate921600 = 0x6, /**< 921600 baud */
FuriHalRtcLogBaudRate1843200 = 0x7, /**< 1843200 baud */
} FuriHalRtcLogBaudRate;
/** Early initialization */
void furi_hal_rtc_init_early();
void furi_hal_rtc_init_early(void);
/** Early de-initialization */
void furi_hal_rtc_deinit_early();
void furi_hal_rtc_deinit_early(void);
/** Initialize RTC subsystem */
void furi_hal_rtc_init();
void furi_hal_rtc_init(void);
/** Force sync shadow registers */
void furi_hal_rtc_sync_shadow();
void furi_hal_rtc_sync_shadow(void);
/** Reset ALL RTC registers content */
void furi_hal_rtc_reset_registers();
@@ -119,7 +137,31 @@ void furi_hal_rtc_set_log_level(uint8_t level);
*
* @return The Log Level value
*/
uint8_t furi_hal_rtc_get_log_level();
uint8_t furi_hal_rtc_get_log_level(void);
/** Set logging device
*
* @param[in] device The device
*/
void furi_hal_rtc_set_log_device(FuriHalRtcLogDevice device);
/** Get logging device
*
* @return The furi hal rtc log device.
*/
FuriHalRtcLogDevice furi_hal_rtc_get_log_device(void);
/** Set logging baud rate
*
* @param[in] baud_rate The baud rate
*/
void furi_hal_rtc_set_log_baud_rate(FuriHalRtcLogBaudRate baud_rate);
/** Get logging baud rate
*
* @return The furi hal rtc log baud rate.
*/
FuriHalRtcLogBaudRate furi_hal_rtc_get_log_baud_rate(void);
/** Set RTC Flag
*
@@ -151,7 +193,7 @@ void furi_hal_rtc_set_boot_mode(FuriHalRtcBootMode mode);
*
* @return The RTC boot mode.
*/
FuriHalRtcBootMode furi_hal_rtc_get_boot_mode();
FuriHalRtcBootMode furi_hal_rtc_get_boot_mode(void);
/** Set Heap Track mode
*
@@ -163,7 +205,7 @@ void furi_hal_rtc_set_heap_track_mode(FuriHalRtcHeapTrackMode mode);
*
* @return The RTC heap track mode.
*/
FuriHalRtcHeapTrackMode furi_hal_rtc_get_heap_track_mode();
FuriHalRtcHeapTrackMode furi_hal_rtc_get_heap_track_mode(void);
/** Set locale units
*
@@ -175,7 +217,7 @@ void furi_hal_rtc_set_locale_units(FuriHalRtcLocaleUnits value);
*
* @return The RTC Locale Units.
*/
FuriHalRtcLocaleUnits furi_hal_rtc_get_locale_units();
FuriHalRtcLocaleUnits furi_hal_rtc_get_locale_units(void);
/** Set RTC Locale Time Format
*
@@ -187,7 +229,7 @@ void furi_hal_rtc_set_locale_timeformat(FuriHalRtcLocaleTimeFormat value);
*
* @return The RTC Locale Time Format.
*/
FuriHalRtcLocaleTimeFormat furi_hal_rtc_get_locale_timeformat();
FuriHalRtcLocaleTimeFormat furi_hal_rtc_get_locale_timeformat(void);
/** Set RTC Locale Date Format
*
@@ -199,7 +241,7 @@ void furi_hal_rtc_set_locale_dateformat(FuriHalRtcLocaleDateFormat value);
*
* @return The RTC Locale Date Format
*/
FuriHalRtcLocaleDateFormat furi_hal_rtc_get_locale_dateformat();
FuriHalRtcLocaleDateFormat furi_hal_rtc_get_locale_dateformat(void);
/** Set RTC Date Time
*
@@ -231,7 +273,7 @@ void furi_hal_rtc_set_fault_data(uint32_t value);
*
* @return RTC Fault Data value
*/
uint32_t furi_hal_rtc_get_fault_data();
uint32_t furi_hal_rtc_get_fault_data(void);
/** Set Pin Fails count
*
@@ -243,13 +285,13 @@ void furi_hal_rtc_set_pin_fails(uint32_t value);
*
* @return Pin Fails Count
*/
uint32_t furi_hal_rtc_get_pin_fails();
uint32_t furi_hal_rtc_get_pin_fails(void);
/** Get UNIX Timestamp
*
* @return Unix Timestamp in seconds from UNIX epoch start
*/
uint32_t furi_hal_rtc_get_timestamp();
uint32_t furi_hal_rtc_get_timestamp(void);
/** Convert DateTime to UNIX timestamp
*
+838
View File
@@ -0,0 +1,838 @@
#include <furi_hal_serial.h>
#include "furi_hal_serial_types_i.h"
#include <stdbool.h>
#include <stm32wbxx_ll_lpuart.h>
#include <stm32wbxx_ll_usart.h>
#include <stm32wbxx_ll_rcc.h>
#include <stm32wbxx_ll_dma.h>
#include <furi_hal_resources.h>
#include <furi_hal_interrupt.h>
#include <furi_hal_bus.h>
#include <furi.h>
#define FURI_HAL_SERIAL_USART_OVERSAMPLING LL_USART_OVERSAMPLING_16
#define FURI_HAL_SERIAL_USART_DMA_INSTANCE (DMA1)
#define FURI_HAL_SERIAL_USART_DMA_CHANNEL (LL_DMA_CHANNEL_6)
#define FURI_HAL_SERIAL_LPUART_DMA_INSTANCE (DMA1)
#define FURI_HAL_SERIAL_LPUART_DMA_CHANNEL (LL_DMA_CHANNEL_7)
typedef struct {
uint8_t* buffer_rx_ptr;
size_t buffer_rx_index_write;
size_t buffer_rx_index_read;
bool enabled;
FuriHalSerialHandle* handle;
FuriHalSerialAsyncRxCallback rx_byte_callback;
FuriHalSerialDmaRxCallback rx_dma_callback;
void* context;
} FuriHalSerial;
static FuriHalSerial furi_hal_serial[FuriHalSerialIdMax] = {0};
static size_t furi_hal_serial_dma_bytes_available(FuriHalSerialId ch);
static void furi_hal_serial_async_rx_configure(
FuriHalSerialHandle* handle,
FuriHalSerialAsyncRxCallback callback,
void* context);
static void furi_hal_serial_usart_irq_callback(void* context) {
UNUSED(context);
FuriHalSerialRxEvent event = 0;
// Notification flags
if(USART1->ISR & USART_ISR_RXNE_RXFNE) {
event |= FuriHalSerialRxEventData;
}
if(USART1->ISR & USART_ISR_IDLE) {
USART1->ICR = USART_ICR_IDLECF;
event |= FuriHalSerialRxEventIdle;
}
// Error flags
if(USART1->ISR & USART_ISR_ORE) {
USART1->ICR = USART_ICR_ORECF;
event |= FuriHalSerialRxEventOverrunError;
}
if(USART1->ISR & USART_ISR_NE) {
USART1->ICR = USART_ICR_NECF;
event |= FuriHalSerialRxEventNoiseError;
}
if(USART1->ISR & USART_ISR_FE) {
USART1->ICR = USART_ICR_FECF;
event |= FuriHalSerialRxEventFrameError;
}
if(USART1->ISR & USART_ISR_PE) {
USART1->ICR = USART_ICR_PECF;
event |= FuriHalSerialRxEventFrameError;
}
if(furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_ptr == NULL) {
if(furi_hal_serial[FuriHalSerialIdUsart].rx_byte_callback) {
furi_hal_serial[FuriHalSerialIdUsart].rx_byte_callback(
furi_hal_serial[FuriHalSerialIdUsart].handle,
event,
furi_hal_serial[FuriHalSerialIdUsart].context);
}
} else {
if(furi_hal_serial[FuriHalSerialIdUsart].rx_dma_callback) {
furi_hal_serial[FuriHalSerialIdUsart].rx_dma_callback(
furi_hal_serial[FuriHalSerialIdUsart].handle,
event,
furi_hal_serial_dma_bytes_available(FuriHalSerialIdUsart),
furi_hal_serial[FuriHalSerialIdUsart].context);
}
}
}
static void furi_hal_serial_usart_dma_rx_isr(void* context) {
UNUSED(context);
#if FURI_HAL_SERIAL_USART_DMA_CHANNEL == LL_DMA_CHANNEL_6
if(LL_DMA_IsActiveFlag_HT6(FURI_HAL_SERIAL_USART_DMA_INSTANCE)) {
LL_DMA_ClearFlag_HT6(FURI_HAL_SERIAL_USART_DMA_INSTANCE);
furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_index_write =
FURI_HAL_SERIAL_DMA_BUFFER_SIZE -
LL_DMA_GetDataLength(
FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
if((furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_index_read >
furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_index_write) ||
(furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_index_read <
FURI_HAL_SERIAL_DMA_BUFFER_SIZE / 4)) {
if(furi_hal_serial[FuriHalSerialIdUsart].rx_dma_callback) {
furi_hal_serial[FuriHalSerialIdUsart].rx_dma_callback(
furi_hal_serial[FuriHalSerialIdUsart].handle,
FuriHalSerialRxEventData,
furi_hal_serial_dma_bytes_available(FuriHalSerialIdUsart),
furi_hal_serial[FuriHalSerialIdUsart].context);
}
}
} else if(LL_DMA_IsActiveFlag_TC6(FURI_HAL_SERIAL_USART_DMA_INSTANCE)) {
LL_DMA_ClearFlag_TC6(FURI_HAL_SERIAL_USART_DMA_INSTANCE);
if(furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_index_read <
FURI_HAL_SERIAL_DMA_BUFFER_SIZE * 3 / 4) {
if(furi_hal_serial[FuriHalSerialIdUsart].rx_dma_callback) {
furi_hal_serial[FuriHalSerialIdUsart].rx_dma_callback(
furi_hal_serial[FuriHalSerialIdUsart].handle,
FuriHalSerialRxEventData,
furi_hal_serial_dma_bytes_available(FuriHalSerialIdUsart),
furi_hal_serial[FuriHalSerialIdUsart].context);
}
}
}
#else
#error Update this code. Would you kindly?
#endif
}
static void furi_hal_serial_usart_init_dma_rx(void) {
/* USART1_RX_DMA Init */
furi_check(furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_ptr == NULL);
furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_index_write = 0;
furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_index_read = 0;
furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_ptr = malloc(FURI_HAL_SERIAL_DMA_BUFFER_SIZE);
LL_DMA_SetMemoryAddress(
FURI_HAL_SERIAL_USART_DMA_INSTANCE,
FURI_HAL_SERIAL_USART_DMA_CHANNEL,
(uint32_t)furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_ptr);
LL_DMA_SetPeriphAddress(
FURI_HAL_SERIAL_USART_DMA_INSTANCE,
FURI_HAL_SERIAL_USART_DMA_CHANNEL,
(uint32_t) & (USART1->RDR));
LL_DMA_ConfigTransfer(
FURI_HAL_SERIAL_USART_DMA_INSTANCE,
FURI_HAL_SERIAL_USART_DMA_CHANNEL,
LL_DMA_DIRECTION_PERIPH_TO_MEMORY | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE |
LL_DMA_PRIORITY_HIGH);
LL_DMA_SetDataLength(
FURI_HAL_SERIAL_USART_DMA_INSTANCE,
FURI_HAL_SERIAL_USART_DMA_CHANNEL,
FURI_HAL_SERIAL_DMA_BUFFER_SIZE);
LL_DMA_SetPeriphRequest(
FURI_HAL_SERIAL_USART_DMA_INSTANCE,
FURI_HAL_SERIAL_USART_DMA_CHANNEL,
LL_DMAMUX_REQ_USART1_RX);
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch6, furi_hal_serial_usart_dma_rx_isr, NULL);
#if FURI_HAL_SERIAL_USART_DMA_CHANNEL == LL_DMA_CHANNEL_6
if(LL_DMA_IsActiveFlag_HT6(FURI_HAL_SERIAL_USART_DMA_INSTANCE))
LL_DMA_ClearFlag_HT6(FURI_HAL_SERIAL_USART_DMA_INSTANCE);
if(LL_DMA_IsActiveFlag_TC6(FURI_HAL_SERIAL_USART_DMA_INSTANCE))
LL_DMA_ClearFlag_TC6(FURI_HAL_SERIAL_USART_DMA_INSTANCE);
if(LL_DMA_IsActiveFlag_TE6(FURI_HAL_SERIAL_USART_DMA_INSTANCE))
LL_DMA_ClearFlag_TE6(FURI_HAL_SERIAL_USART_DMA_INSTANCE);
#else
#error Update this code. Would you kindly?
#endif
LL_DMA_EnableIT_TC(FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
LL_DMA_EnableIT_HT(FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
LL_DMA_EnableChannel(FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
LL_USART_EnableDMAReq_RX(USART1);
LL_USART_EnableIT_IDLE(USART1);
}
static void furi_hal_serial_usart_deinit_dma_rx(void) {
if(furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_ptr != NULL) {
LL_DMA_DisableChannel(
FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
LL_USART_DisableDMAReq_RX(USART1);
LL_USART_DisableIT_IDLE(USART1);
LL_DMA_DisableIT_TC(FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
LL_DMA_DisableIT_HT(FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
LL_DMA_ClearFlag_TC6(FURI_HAL_SERIAL_USART_DMA_INSTANCE);
LL_DMA_ClearFlag_HT6(FURI_HAL_SERIAL_USART_DMA_INSTANCE);
LL_DMA_DeInit(FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch6, NULL, NULL);
free(furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_ptr);
furi_hal_serial[FuriHalSerialIdUsart].buffer_rx_ptr = NULL;
}
}
static void furi_hal_serial_usart_init(FuriHalSerialHandle* handle, uint32_t baud) {
furi_hal_bus_enable(FuriHalBusUSART1);
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2);
furi_hal_gpio_init_ex(
&gpio_usart_tx,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn7USART1);
furi_hal_gpio_init_ex(
&gpio_usart_rx,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn7USART1);
LL_USART_InitTypeDef USART_InitStruct;
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
USART_InitStruct.BaudRate = baud;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = FURI_HAL_SERIAL_USART_OVERSAMPLING;
LL_USART_Init(USART1, &USART_InitStruct);
LL_USART_EnableFIFO(USART1);
LL_USART_ConfigAsyncMode(USART1);
LL_USART_Enable(USART1);
while(!LL_USART_IsActiveFlag_TEACK(USART1) || !LL_USART_IsActiveFlag_REACK(USART1))
;
furi_hal_serial_set_br(handle, baud);
LL_USART_DisableIT_ERROR(USART1);
furi_hal_serial[handle->id].enabled = true;
}
static void furi_hal_serial_lpuart_irq_callback(void* context) {
UNUSED(context);
FuriHalSerialRxEvent event = 0;
// Notification flags
if(LPUART1->ISR & USART_ISR_RXNE_RXFNE) {
event |= FuriHalSerialRxEventData;
}
if(LPUART1->ISR & USART_ISR_IDLE) {
LPUART1->ICR = USART_ICR_IDLECF;
event |= FuriHalSerialRxEventIdle;
}
// Error flags
if(LPUART1->ISR & USART_ISR_ORE) {
LPUART1->ICR = USART_ICR_ORECF;
event |= FuriHalSerialRxEventOverrunError;
}
if(LPUART1->ISR & USART_ISR_NE) {
LPUART1->ICR = USART_ICR_NECF;
event |= FuriHalSerialRxEventNoiseError;
}
if(LPUART1->ISR & USART_ISR_FE) {
LPUART1->ICR = USART_ICR_FECF;
event |= FuriHalSerialRxEventFrameError;
}
if(LPUART1->ISR & USART_ISR_PE) {
LPUART1->ICR = USART_ICR_PECF;
event |= FuriHalSerialRxEventFrameError;
}
if(furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_ptr == NULL) {
if(furi_hal_serial[FuriHalSerialIdLpuart].rx_byte_callback) {
furi_hal_serial[FuriHalSerialIdLpuart].rx_byte_callback(
furi_hal_serial[FuriHalSerialIdLpuart].handle,
event,
furi_hal_serial[FuriHalSerialIdLpuart].context);
}
} else {
if(furi_hal_serial[FuriHalSerialIdLpuart].rx_dma_callback) {
furi_hal_serial[FuriHalSerialIdLpuart].rx_dma_callback(
furi_hal_serial[FuriHalSerialIdLpuart].handle,
event,
furi_hal_serial_dma_bytes_available(FuriHalSerialIdLpuart),
furi_hal_serial[FuriHalSerialIdLpuart].context);
}
}
}
static void furi_hal_serial_lpuart_dma_rx_isr(void* context) {
UNUSED(context);
#if FURI_HAL_SERIAL_LPUART_DMA_CHANNEL == LL_DMA_CHANNEL_7
if(LL_DMA_IsActiveFlag_HT7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE)) {
LL_DMA_ClearFlag_HT7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE);
furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_index_write =
FURI_HAL_SERIAL_DMA_BUFFER_SIZE -
LL_DMA_GetDataLength(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
if((furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_index_read >
furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_index_write) ||
(furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_index_read <
FURI_HAL_SERIAL_DMA_BUFFER_SIZE / 4)) {
if(furi_hal_serial[FuriHalSerialIdLpuart].rx_dma_callback) {
furi_hal_serial[FuriHalSerialIdLpuart].rx_dma_callback(
furi_hal_serial[FuriHalSerialIdLpuart].handle,
FuriHalSerialRxEventData,
furi_hal_serial_dma_bytes_available(FuriHalSerialIdLpuart),
furi_hal_serial[FuriHalSerialIdLpuart].context);
}
}
} else if(LL_DMA_IsActiveFlag_TC7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE)) {
LL_DMA_ClearFlag_TC7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE);
if(furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_index_read <
FURI_HAL_SERIAL_DMA_BUFFER_SIZE * 3 / 4) {
if(furi_hal_serial[FuriHalSerialIdLpuart].rx_dma_callback) {
furi_hal_serial[FuriHalSerialIdLpuart].rx_dma_callback(
furi_hal_serial[FuriHalSerialIdLpuart].handle,
FuriHalSerialRxEventData,
furi_hal_serial_dma_bytes_available(FuriHalSerialIdLpuart),
furi_hal_serial[FuriHalSerialIdLpuart].context);
}
}
}
#else
#error Update this code. Would you kindly?
#endif
}
static void furi_hal_serial_lpuart_init_dma_rx(void) {
/* LPUART1_RX_DMA Init */
furi_check(furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_ptr == NULL);
furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_index_write = 0;
furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_index_read = 0;
furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_ptr = malloc(FURI_HAL_SERIAL_DMA_BUFFER_SIZE);
LL_DMA_SetMemoryAddress(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE,
FURI_HAL_SERIAL_LPUART_DMA_CHANNEL,
(uint32_t)furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_ptr);
LL_DMA_SetPeriphAddress(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE,
FURI_HAL_SERIAL_LPUART_DMA_CHANNEL,
(uint32_t) & (LPUART1->RDR));
LL_DMA_ConfigTransfer(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE,
FURI_HAL_SERIAL_LPUART_DMA_CHANNEL,
LL_DMA_DIRECTION_PERIPH_TO_MEMORY | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE |
LL_DMA_PRIORITY_HIGH);
LL_DMA_SetDataLength(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE,
FURI_HAL_SERIAL_LPUART_DMA_CHANNEL,
FURI_HAL_SERIAL_DMA_BUFFER_SIZE);
LL_DMA_SetPeriphRequest(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE,
FURI_HAL_SERIAL_LPUART_DMA_CHANNEL,
LL_DMAMUX_REQ_LPUART1_RX);
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch7, furi_hal_serial_lpuart_dma_rx_isr, NULL);
#if FURI_HAL_SERIAL_LPUART_DMA_CHANNEL == LL_DMA_CHANNEL_7
if(LL_DMA_IsActiveFlag_HT7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE))
LL_DMA_ClearFlag_HT7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE);
if(LL_DMA_IsActiveFlag_TC7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE))
LL_DMA_ClearFlag_TC7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE);
if(LL_DMA_IsActiveFlag_TE7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE))
LL_DMA_ClearFlag_TE7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE);
#else
#error Update this code. Would you kindly?
#endif
LL_DMA_EnableIT_TC(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
LL_DMA_EnableIT_HT(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
LL_DMA_EnableChannel(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
LL_USART_EnableDMAReq_RX(LPUART1);
LL_USART_EnableIT_IDLE(LPUART1);
}
static void furi_hal_serial_lpuart_deinit_dma_rx(void) {
if(furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_ptr != NULL) {
LL_DMA_DisableChannel(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
LL_USART_DisableDMAReq_RX(LPUART1);
LL_USART_DisableIT_IDLE(LPUART1);
LL_DMA_DisableIT_TC(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
LL_DMA_DisableIT_HT(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
LL_DMA_ClearFlag_TC7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE);
LL_DMA_ClearFlag_HT7(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE);
LL_DMA_DeInit(FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch7, NULL, NULL);
free(furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_ptr);
furi_hal_serial[FuriHalSerialIdLpuart].buffer_rx_ptr = NULL;
}
}
static void furi_hal_serial_lpuart_init(FuriHalSerialHandle* handle, uint32_t baud) {
furi_hal_bus_enable(FuriHalBusLPUART1);
LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1);
furi_hal_gpio_init_ex(
&gpio_ext_pc0,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn8LPUART1);
furi_hal_gpio_init_ex(
&gpio_ext_pc1,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn8LPUART1);
LL_LPUART_InitTypeDef LPUART_InitStruct;
LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1;
LPUART_InitStruct.BaudRate = baud;
LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B;
LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1;
LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE;
LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX;
LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE;
LL_LPUART_Init(LPUART1, &LPUART_InitStruct);
LL_LPUART_EnableFIFO(LPUART1);
LL_LPUART_Enable(LPUART1);
while(!LL_LPUART_IsActiveFlag_TEACK(LPUART1) || !LL_LPUART_IsActiveFlag_REACK(LPUART1))
;
furi_hal_serial_set_br(handle, baud);
LL_LPUART_DisableIT_ERROR(LPUART1);
furi_hal_serial[handle->id].enabled = true;
}
void furi_hal_serial_init(FuriHalSerialHandle* handle, uint32_t baud) {
furi_check(handle);
if(handle->id == FuriHalSerialIdLpuart) {
furi_hal_serial_lpuart_init(handle, baud);
} else if(handle->id == FuriHalSerialIdUsart) {
furi_hal_serial_usart_init(handle, baud);
}
}
static uint32_t furi_hal_serial_get_prescaler(FuriHalSerialHandle* handle, uint32_t baud) {
uint32_t uartclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE);
uint32_t divisor = (uartclk / baud);
uint32_t prescaler = 0;
if(handle->id == FuriHalSerialIdUsart) {
if(FURI_HAL_SERIAL_USART_OVERSAMPLING == LL_USART_OVERSAMPLING_16) {
divisor = (divisor / 16) >> 12;
} else {
divisor = (divisor / 8) >> 12;
}
if(divisor < 1) {
prescaler = LL_USART_PRESCALER_DIV1;
} else if(divisor < 2) {
prescaler = LL_USART_PRESCALER_DIV2;
} else if(divisor < 4) {
prescaler = LL_USART_PRESCALER_DIV4;
} else if(divisor < 6) {
prescaler = LL_USART_PRESCALER_DIV6;
} else if(divisor < 8) {
prescaler = LL_USART_PRESCALER_DIV8;
} else if(divisor < 10) {
prescaler = LL_USART_PRESCALER_DIV10;
} else if(divisor < 12) {
prescaler = LL_USART_PRESCALER_DIV12;
} else if(divisor < 16) {
prescaler = LL_USART_PRESCALER_DIV16;
} else if(divisor < 32) {
prescaler = LL_USART_PRESCALER_DIV32;
} else if(divisor < 64) {
prescaler = LL_USART_PRESCALER_DIV64;
} else if(divisor < 128) {
prescaler = LL_USART_PRESCALER_DIV128;
} else {
prescaler = LL_USART_PRESCALER_DIV256;
}
} else if(handle->id == FuriHalSerialIdLpuart) {
divisor >>= 12;
if(divisor < 1) {
prescaler = LL_LPUART_PRESCALER_DIV1;
} else if(divisor < 2) {
prescaler = LL_LPUART_PRESCALER_DIV2;
} else if(divisor < 4) {
prescaler = LL_LPUART_PRESCALER_DIV4;
} else if(divisor < 6) {
prescaler = LL_LPUART_PRESCALER_DIV6;
} else if(divisor < 8) {
prescaler = LL_LPUART_PRESCALER_DIV8;
} else if(divisor < 10) {
prescaler = LL_LPUART_PRESCALER_DIV10;
} else if(divisor < 12) {
prescaler = LL_LPUART_PRESCALER_DIV12;
} else if(divisor < 16) {
prescaler = LL_LPUART_PRESCALER_DIV16;
} else if(divisor < 32) {
prescaler = LL_LPUART_PRESCALER_DIV32;
} else if(divisor < 64) {
prescaler = LL_LPUART_PRESCALER_DIV64;
} else if(divisor < 128) {
prescaler = LL_LPUART_PRESCALER_DIV128;
} else {
prescaler = LL_LPUART_PRESCALER_DIV256;
}
}
return prescaler;
}
void furi_hal_serial_set_br(FuriHalSerialHandle* handle, uint32_t baud) {
furi_check(handle);
uint32_t prescaler = furi_hal_serial_get_prescaler(handle, baud);
if(handle->id == FuriHalSerialIdUsart) {
if(LL_USART_IsEnabled(USART1)) {
// Wait for transfer complete flag
while(!LL_USART_IsActiveFlag_TC(USART1))
;
LL_USART_Disable(USART1);
uint32_t uartclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE);
LL_USART_SetPrescaler(USART1, prescaler);
LL_USART_SetBaudRate(
USART1, uartclk, prescaler, FURI_HAL_SERIAL_USART_OVERSAMPLING, baud);
LL_USART_Enable(USART1);
}
} else if(handle->id == FuriHalSerialIdLpuart) {
if(LL_LPUART_IsEnabled(LPUART1)) {
// Wait for transfer complete flag
while(!LL_LPUART_IsActiveFlag_TC(LPUART1))
;
LL_LPUART_Disable(LPUART1);
uint32_t uartclk = LL_RCC_GetLPUARTClockFreq(LL_RCC_LPUART1_CLKSOURCE);
LL_LPUART_SetPrescaler(LPUART1, prescaler);
LL_LPUART_SetBaudRate(LPUART1, uartclk, prescaler, baud);
LL_LPUART_Enable(LPUART1);
}
}
}
void furi_hal_serial_deinit(FuriHalSerialHandle* handle) {
furi_check(handle);
furi_hal_serial_async_rx_configure(handle, NULL, NULL);
if(handle->id == FuriHalSerialIdUsart) {
if(furi_hal_bus_is_enabled(FuriHalBusUSART1)) {
furi_hal_bus_disable(FuriHalBusUSART1);
}
if(LL_USART_IsEnabled(USART1)) {
LL_USART_Disable(USART1);
}
furi_hal_serial_usart_deinit_dma_rx();
furi_hal_gpio_init(&gpio_usart_tx, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_usart_rx, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
} else if(handle->id == FuriHalSerialIdLpuart) {
if(furi_hal_bus_is_enabled(FuriHalBusLPUART1)) {
furi_hal_bus_disable(FuriHalBusLPUART1);
}
if(LL_LPUART_IsEnabled(LPUART1)) {
LL_LPUART_Disable(LPUART1);
}
furi_hal_serial_lpuart_deinit_dma_rx();
furi_hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pc1, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
} else {
furi_crash();
}
furi_hal_serial[handle->id].enabled = false;
}
void furi_hal_serial_suspend(FuriHalSerialHandle* handle) {
furi_check(handle);
if(handle->id == FuriHalSerialIdLpuart && LL_LPUART_IsEnabled(LPUART1)) {
LL_LPUART_Disable(LPUART1);
} else if(handle->id == FuriHalSerialIdUsart && LL_USART_IsEnabled(USART1)) {
LL_USART_Disable(USART1);
}
furi_hal_serial[handle->id].enabled = false;
}
void furi_hal_serial_resume(FuriHalSerialHandle* handle) {
furi_check(handle);
if(!furi_hal_serial[handle->id].enabled) {
if(handle->id == FuriHalSerialIdLpuart) {
LL_LPUART_Enable(LPUART1);
} else if(handle->id == FuriHalSerialIdUsart) {
LL_USART_Enable(USART1);
}
furi_hal_serial[handle->id].enabled = true;
}
}
void furi_hal_serial_tx(FuriHalSerialHandle* handle, const uint8_t* buffer, size_t buffer_size) {
furi_check(handle);
if(handle->id == FuriHalSerialIdUsart) {
if(LL_USART_IsEnabled(USART1) == 0) return;
while(buffer_size > 0) {
while(!LL_USART_IsActiveFlag_TXE(USART1))
;
LL_USART_TransmitData8(USART1, *buffer);
buffer++;
buffer_size--;
}
} else if(handle->id == FuriHalSerialIdLpuart) {
if(LL_LPUART_IsEnabled(LPUART1) == 0) return;
while(buffer_size > 0) {
while(!LL_LPUART_IsActiveFlag_TXE(LPUART1))
;
LL_LPUART_TransmitData8(LPUART1, *buffer);
buffer++;
buffer_size--;
}
}
}
void furi_hal_serial_tx_wait_complete(FuriHalSerialHandle* handle) {
furi_check(handle);
if(handle->id == FuriHalSerialIdUsart) {
if(LL_USART_IsEnabled(USART1) == 0) return;
while(!LL_USART_IsActiveFlag_TC(USART1))
;
} else if(handle->id == FuriHalSerialIdLpuart) {
if(LL_LPUART_IsEnabled(LPUART1) == 0) return;
while(!LL_LPUART_IsActiveFlag_TC(LPUART1))
;
}
}
static void furi_hal_serial_event_init(FuriHalSerialHandle* handle, bool report_errors) {
if(handle->id == FuriHalSerialIdUsart) {
LL_USART_EnableIT_IDLE(USART1);
} else if(handle->id == FuriHalSerialIdLpuart) {
LL_LPUART_EnableIT_IDLE(LPUART1);
}
if(report_errors) {
if(handle->id == FuriHalSerialIdUsart) {
LL_USART_EnableIT_ERROR(USART1);
} else if(handle->id == FuriHalSerialIdLpuart) {
LL_LPUART_EnableIT_ERROR(LPUART1);
}
}
}
static void furi_hal_serial_event_deinit(FuriHalSerialHandle* handle) {
if(handle->id == FuriHalSerialIdUsart) {
if(LL_USART_IsEnabledIT_IDLE(USART1)) LL_USART_DisableIT_IDLE(USART1);
if(LL_USART_IsEnabledIT_ERROR(USART1)) LL_USART_DisableIT_ERROR(USART1);
} else if(handle->id == FuriHalSerialIdLpuart) {
if(LL_LPUART_IsEnabledIT_IDLE(LPUART1)) LL_LPUART_DisableIT_IDLE(LPUART1);
if(LL_LPUART_IsEnabledIT_ERROR(LPUART1)) LL_LPUART_DisableIT_ERROR(LPUART1);
}
}
static void furi_hal_serial_async_rx_configure(
FuriHalSerialHandle* handle,
FuriHalSerialAsyncRxCallback callback,
void* context) {
if(handle->id == FuriHalSerialIdUsart) {
if(callback) {
furi_hal_serial_usart_deinit_dma_rx();
furi_hal_interrupt_set_isr(
FuriHalInterruptIdUart1, furi_hal_serial_usart_irq_callback, NULL);
LL_USART_EnableIT_RXNE_RXFNE(USART1);
} else {
furi_hal_interrupt_set_isr(FuriHalInterruptIdUart1, NULL, NULL);
furi_hal_serial_usart_deinit_dma_rx();
LL_USART_DisableIT_RXNE_RXFNE(USART1);
}
} else if(handle->id == FuriHalSerialIdLpuart) {
if(callback) {
furi_hal_serial_lpuart_deinit_dma_rx();
furi_hal_interrupt_set_isr(
FuriHalInterruptIdLpUart1, furi_hal_serial_lpuart_irq_callback, NULL);
LL_LPUART_EnableIT_RXNE_RXFNE(LPUART1);
} else {
furi_hal_interrupt_set_isr(FuriHalInterruptIdLpUart1, NULL, NULL);
furi_hal_serial_lpuart_deinit_dma_rx();
LL_LPUART_DisableIT_RXNE_RXFNE(LPUART1);
}
}
furi_hal_serial[handle->id].rx_byte_callback = callback;
furi_hal_serial[handle->id].handle = handle;
furi_hal_serial[handle->id].rx_dma_callback = NULL;
furi_hal_serial[handle->id].context = context;
}
void furi_hal_serial_async_rx_start(
FuriHalSerialHandle* handle,
FuriHalSerialAsyncRxCallback callback,
void* context,
bool report_errors) {
furi_check(handle);
furi_check(callback);
furi_hal_serial_event_init(handle, report_errors);
furi_hal_serial_async_rx_configure(handle, callback, context);
// Assign different functions to different UARTs
furi_check(
furi_hal_serial[FuriHalSerialIdUsart].rx_byte_callback !=
furi_hal_serial[FuriHalSerialIdLpuart].rx_byte_callback);
}
void furi_hal_serial_async_rx_stop(FuriHalSerialHandle* handle) {
furi_check(handle);
furi_hal_serial_event_deinit(handle);
furi_hal_serial_async_rx_configure(handle, NULL, NULL);
}
uint8_t furi_hal_serial_async_rx(FuriHalSerialHandle* handle) {
furi_check(FURI_IS_IRQ_MODE());
furi_assert(handle->id < FuriHalSerialIdMax);
if(handle->id == FuriHalSerialIdUsart) {
return LL_USART_ReceiveData8(USART1);
}
return LL_LPUART_ReceiveData8(LPUART1);
}
static size_t furi_hal_serial_dma_bytes_available(FuriHalSerialId ch) {
size_t dma_remain = 0;
if(ch == FuriHalSerialIdUsart) {
dma_remain = LL_DMA_GetDataLength(
FURI_HAL_SERIAL_USART_DMA_INSTANCE, FURI_HAL_SERIAL_USART_DMA_CHANNEL);
} else if(ch == FuriHalSerialIdLpuart) {
dma_remain = LL_DMA_GetDataLength(
FURI_HAL_SERIAL_LPUART_DMA_INSTANCE, FURI_HAL_SERIAL_LPUART_DMA_CHANNEL);
} else {
furi_crash();
}
furi_hal_serial[ch].buffer_rx_index_write = FURI_HAL_SERIAL_DMA_BUFFER_SIZE - dma_remain;
if(furi_hal_serial[ch].buffer_rx_index_write >= furi_hal_serial[ch].buffer_rx_index_read) {
return furi_hal_serial[ch].buffer_rx_index_write -
furi_hal_serial[ch].buffer_rx_index_read;
} else {
return FURI_HAL_SERIAL_DMA_BUFFER_SIZE - furi_hal_serial[ch].buffer_rx_index_read +
furi_hal_serial[ch].buffer_rx_index_write;
}
}
static uint8_t furi_hal_serial_dma_rx_read_byte(FuriHalSerialHandle* handle) {
uint8_t data = 0;
data =
furi_hal_serial[handle->id].buffer_rx_ptr[furi_hal_serial[handle->id].buffer_rx_index_read];
furi_hal_serial[handle->id].buffer_rx_index_read++;
if(furi_hal_serial[handle->id].buffer_rx_index_read >= FURI_HAL_SERIAL_DMA_BUFFER_SIZE) {
furi_hal_serial[handle->id].buffer_rx_index_read = 0;
}
return data;
}
size_t furi_hal_serial_dma_rx(FuriHalSerialHandle* handle, uint8_t* data, size_t len) {
furi_check(FURI_IS_IRQ_MODE());
furi_assert(furi_hal_serial[handle->id].buffer_rx_ptr != NULL);
size_t i = 0;
size_t available = furi_hal_serial_dma_bytes_available(handle->id);
if(available < len) {
len = available;
}
for(i = 0; i < len; i++) {
data[i] = furi_hal_serial_dma_rx_read_byte(handle);
}
return i;
}
static void furi_hal_serial_dma_configure(
FuriHalSerialHandle* handle,
FuriHalSerialDmaRxCallback callback,
void* context) {
furi_check(handle);
if(handle->id == FuriHalSerialIdUsart) {
if(callback) {
furi_hal_serial_usart_init_dma_rx();
furi_hal_interrupt_set_isr(
FuriHalInterruptIdUart1, furi_hal_serial_usart_irq_callback, NULL);
} else {
LL_USART_DisableIT_RXNE_RXFNE(USART1);
furi_hal_interrupt_set_isr(FuriHalInterruptIdUart1, NULL, NULL);
furi_hal_serial_usart_deinit_dma_rx();
}
} else if(handle->id == FuriHalSerialIdLpuart) {
if(callback) {
furi_hal_serial_lpuart_init_dma_rx();
furi_hal_interrupt_set_isr(
FuriHalInterruptIdLpUart1, furi_hal_serial_lpuart_irq_callback, NULL);
} else {
LL_LPUART_DisableIT_RXNE_RXFNE(LPUART1);
furi_hal_interrupt_set_isr(FuriHalInterruptIdLpUart1, NULL, NULL);
furi_hal_serial_lpuart_deinit_dma_rx();
}
}
furi_hal_serial[handle->id].rx_byte_callback = NULL;
furi_hal_serial[handle->id].handle = handle;
furi_hal_serial[handle->id].rx_dma_callback = callback;
furi_hal_serial[handle->id].context = context;
}
void furi_hal_serial_dma_rx_start(
FuriHalSerialHandle* handle,
FuriHalSerialDmaRxCallback callback,
void* context,
bool report_errors) {
furi_check(handle);
furi_check(callback);
furi_hal_serial_event_init(handle, report_errors);
furi_hal_serial_dma_configure(handle, callback, context);
// Assign different functions to different UARTs
furi_check(
furi_hal_serial[FuriHalSerialIdUsart].rx_dma_callback !=
furi_hal_serial[FuriHalSerialIdLpuart].rx_dma_callback);
}
void furi_hal_serial_dma_rx_stop(FuriHalSerialHandle* handle) {
furi_check(handle);
furi_hal_serial_event_deinit(handle);
furi_hal_serial_dma_configure(handle, NULL, NULL);
}
+189
View File
@@ -0,0 +1,189 @@
/**
* @file furi_hal_serial.h
*
* Serial HAL API
*/
#pragma once
#include <stddef.h>
#include <stdint.h>
#include "furi_hal_serial_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Initialize Serial
*
* Configures GPIO, configures and enables transceiver.
*
* @param handle Serial handle
* @param baud baud rate
*/
void furi_hal_serial_init(FuriHalSerialHandle* handle, uint32_t baud);
/** De-initialize Serial
*
* Configures GPIO to analog, clears callback and callback context, disables
* hardware
*
* @param handle Serial handle
*/
void furi_hal_serial_deinit(FuriHalSerialHandle* handle);
/** Suspend operation
*
* Suspend hardware, settings and callbacks are preserved
*
* @param handle Serial handle
*/
void furi_hal_serial_suspend(FuriHalSerialHandle* handle);
/** Resume operation
*
* Resumes hardware from suspended state
*
* @param handle Serial handle
*/
void furi_hal_serial_resume(FuriHalSerialHandle* handle);
/** Changes baud rate
*
* @param handle Serial handle
* @param baud baud rate
*/
void furi_hal_serial_set_br(FuriHalSerialHandle* handle, uint32_t baud);
/** Transmits data in semi-blocking mode
*
* Fills transmission pipe with data, returns as soon as all bytes from buffer
* are in the pipe.
*
* Real transmission will be completed later. Use
* `furi_hal_serial_tx_wait_complete` to wait for completion if you need it.
*
* @param handle Serial handle
* @param buffer data
* @param buffer_size data size (in bytes)
*/
void furi_hal_serial_tx(FuriHalSerialHandle* handle, const uint8_t* buffer, size_t buffer_size);
/** Wait until transmission is completed
*
* Ensures that all data has been sent.
*
* @param handle Serial handle
*/
void furi_hal_serial_tx_wait_complete(FuriHalSerialHandle* handle);
/** Serial RX events */
typedef enum {
FuriHalSerialRxEventData = (1 << 0), /**< Data: new data available */
FuriHalSerialRxEventIdle = (1 << 1), /**< Idle: bus idle detected */
FuriHalSerialRxEventFrameError = (1 << 2), /**< Framing Error: incorrect frame detected */
FuriHalSerialRxEventNoiseError = (1 << 3), /**< Noise Error: noise on the line detected */
FuriHalSerialRxEventOverrunError = (1 << 4), /**< Overrun Error: no space for received data */
} FuriHalSerialRxEvent;
/** Receive callback
*
* @warning Callback will be called in interrupt context, ensure thread
* safety on your side.
* @param handle Serial handle
* @param event FuriHalSerialRxEvent
* @param context Callback context provided earlier
*/
typedef void (*FuriHalSerialAsyncRxCallback)(
FuriHalSerialHandle* handle,
FuriHalSerialRxEvent event,
void* context);
/** Start and sets Serial Receive callback
*
* @warning Callback will be called in interrupt context, ensure thread
* safety on your side
*
* @param handle Serial handle
* @param callback callback pointer
* @param context callback context
* @param[in] report_errors report RX error
*/
void furi_hal_serial_async_rx_start(
FuriHalSerialHandle* handle,
FuriHalSerialAsyncRxCallback callback,
void* context,
bool report_errors);
/** Stop Serial Receive
*
* @param handle Serial handle
*/
void furi_hal_serial_async_rx_stop(FuriHalSerialHandle* handle);
/** Get data Serial receive
*
* @warning This function must be called only from the callback
* FuriHalSerialAsyncRxCallback
*
* @param handle Serial handle
*
* @return data
*/
uint8_t furi_hal_serial_async_rx(FuriHalSerialHandle* handle);
/* DMA based Serial API */
#define FURI_HAL_SERIAL_DMA_BUFFER_SIZE (256u)
/** Receive DMA callback
*
* @warning DMA Callback will be called in interrupt context, ensure thread
* safety on your side.
*
* @param handle Serial handle
* @param event FuriHalSerialDmaRxEvent
* @param data_len Received data
* @param context Callback context provided earlier
*/
typedef void (*FuriHalSerialDmaRxCallback)(
FuriHalSerialHandle* handle,
FuriHalSerialRxEvent event,
size_t data_len,
void* context);
/** Start and sets Serial event callback receive DMA
*
* @param handle Serial handle
* @param callback callback pointer
* @param context callback context
* @param[in] report_errors report RX error
*/
void furi_hal_serial_dma_rx_start(
FuriHalSerialHandle* handle,
FuriHalSerialDmaRxCallback callback,
void* context,
bool report_errors);
/** Stop Serial receive DMA
*
* @param handle Serial handle
*/
void furi_hal_serial_dma_rx_stop(FuriHalSerialHandle* handle);
/** Get data Serial receive DMA
*
* @warning This function must be called only from the callback
* FuriHalSerialDmaRxCallback
*
* @param handle Serial handle
* @param data pointer to data buffer
* @param len get data size (in bytes)
*
* @return size actual data receive (in bytes)
*/
size_t furi_hal_serial_dma_rx(FuriHalSerialHandle* handle, uint8_t* data, size_t len);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,233 @@
#include "furi_hal_serial_control.h"
#include "furi_hal_serial_types_i.h"
#include "furi_hal_serial.h"
#include <furi.h>
#include <toolbox/api_lock.h>
#define TAG "FuriHalSerialControl"
typedef enum {
FuriHalSerialControlMessageTypeStop,
FuriHalSerialControlMessageTypeSuspend,
FuriHalSerialControlMessageTypeResume,
FuriHalSerialControlMessageTypeAcquire,
FuriHalSerialControlMessageTypeRelease,
FuriHalSerialControlMessageTypeLogging,
} FuriHalSerialControlMessageType;
typedef struct {
FuriHalSerialControlMessageType type;
FuriApiLock api_lock;
void* input;
void* output;
} FuriHalSerialControlMessage;
typedef struct {
const FuriHalSerialId id;
const uint32_t baud_rate;
} FuriHalSerialControlMessageInputLogging;
typedef struct {
FuriHalSerialHandle handles[FuriHalSerialIdMax];
FuriMessageQueue* queue;
FuriThread* thread;
// Logging
FuriHalSerialId log_config_serial_id;
uint32_t log_config_serial_baud_rate;
FuriLogHandler log_handler;
FuriHalSerialHandle* log_serial;
} FuriHalSerialControl;
FuriHalSerialControl* furi_hal_serial_control = NULL;
static void furi_hal_serial_control_log_callback(const uint8_t* data, size_t size, void* context) {
FuriHalSerialHandle* handle = context;
furi_hal_serial_tx(handle, data, size);
}
static void furi_hal_serial_control_log_set_handle(FuriHalSerialHandle* handle) {
if(furi_hal_serial_control->log_serial) {
furi_log_remove_handler(furi_hal_serial_control->log_handler);
furi_hal_serial_deinit(furi_hal_serial_control->log_serial);
furi_hal_serial_control->log_serial = NULL;
}
if(handle) {
furi_hal_serial_control->log_serial = handle;
furi_hal_serial_init(
furi_hal_serial_control->log_serial,
furi_hal_serial_control->log_config_serial_baud_rate);
furi_hal_serial_control->log_handler.callback = furi_hal_serial_control_log_callback;
furi_hal_serial_control->log_handler.context = furi_hal_serial_control->log_serial;
furi_log_add_handler(furi_hal_serial_control->log_handler);
}
}
static int32_t furi_hal_serial_control_thread(void* args) {
UNUSED(args);
bool should_continue = true;
while(should_continue || furi_message_queue_get_count(furi_hal_serial_control->queue) > 0) {
FuriHalSerialControlMessage message = {0};
FuriStatus status =
furi_message_queue_get(furi_hal_serial_control->queue, &message, FuriWaitForever);
furi_check(status == FuriStatusOk);
if(message.type == FuriHalSerialControlMessageTypeStop) {
should_continue = false;
} else if(message.type == FuriHalSerialControlMessageTypeSuspend) {
for(size_t i = 0; i < FuriHalSerialIdMax; i++) {
furi_hal_serial_tx_wait_complete(&furi_hal_serial_control->handles[i]);
furi_hal_serial_suspend(&furi_hal_serial_control->handles[i]);
}
api_lock_unlock(message.api_lock);
} else if(message.type == FuriHalSerialControlMessageTypeResume) {
for(size_t i = 0; i < FuriHalSerialIdMax; i++) {
furi_hal_serial_resume(&furi_hal_serial_control->handles[i]);
}
api_lock_unlock(message.api_lock);
} else if(message.type == FuriHalSerialControlMessageTypeAcquire) {
FuriHalSerialId serial_id = *(FuriHalSerialId*)message.input;
if(furi_hal_serial_control->handles[serial_id].in_use) {
*(FuriHalSerialHandle**)message.output = NULL;
} else {
// Logging
if(furi_hal_serial_control->log_config_serial_id == serial_id) {
furi_hal_serial_control_log_set_handle(NULL);
}
// Return handle
furi_hal_serial_control->handles[serial_id].in_use = true;
*(FuriHalSerialHandle**)message.output =
&furi_hal_serial_control->handles[serial_id];
}
api_lock_unlock(message.api_lock);
} else if(message.type == FuriHalSerialControlMessageTypeRelease) {
FuriHalSerialHandle* handle = *(FuriHalSerialHandle**)message.input;
furi_assert(handle->in_use);
furi_hal_serial_deinit(handle);
handle->in_use = false;
// Return back logging
if(furi_hal_serial_control->log_config_serial_id == handle->id) {
furi_hal_serial_control_log_set_handle(handle);
}
api_lock_unlock(message.api_lock);
} else if(message.type == FuriHalSerialControlMessageTypeLogging) {
// Set new configuration
FuriHalSerialControlMessageInputLogging* message_input = message.input;
furi_hal_serial_control->log_config_serial_id = message_input->id;
furi_hal_serial_control->log_config_serial_baud_rate = message_input->baud_rate;
// Apply new configuration
FuriHalSerialHandle* handle = NULL;
if(furi_hal_serial_control->log_config_serial_id < FuriHalSerialIdMax) {
handle = &furi_hal_serial_control
->handles[furi_hal_serial_control->log_config_serial_id];
}
furi_hal_serial_control_log_set_handle(handle);
api_lock_unlock(message.api_lock);
} else {
furi_crash("Invalid parameter");
}
}
return 0;
}
void furi_hal_serial_control_init(void) {
furi_check(furi_hal_serial_control == NULL);
// Allocate resources
furi_hal_serial_control = malloc(sizeof(FuriHalSerialControl));
furi_hal_serial_control->handles[FuriHalSerialIdUsart].id = FuriHalSerialIdUsart;
furi_hal_serial_control->handles[FuriHalSerialIdLpuart].id = FuriHalSerialIdLpuart;
furi_hal_serial_control->queue =
furi_message_queue_alloc(8, sizeof(FuriHalSerialControlMessage));
furi_hal_serial_control->thread =
furi_thread_alloc_ex("SerialControlDriver", 512, furi_hal_serial_control_thread, NULL);
furi_thread_mark_as_service(furi_hal_serial_control->thread);
furi_thread_set_priority(furi_hal_serial_control->thread, FuriThreadPriorityHighest);
furi_hal_serial_control->log_config_serial_id = FuriHalSerialIdMax;
// Start control plane thread
furi_thread_start(furi_hal_serial_control->thread);
}
void furi_hal_serial_control_deinit(void) {
furi_check(furi_hal_serial_control);
// Stop control plane thread
FuriHalSerialControlMessage message;
message.type = FuriHalSerialControlMessageTypeStop;
furi_message_queue_put(furi_hal_serial_control->queue, &message, FuriWaitForever);
furi_thread_join(furi_hal_serial_control->thread);
// Release resources
furi_thread_free(furi_hal_serial_control->thread);
furi_message_queue_free(furi_hal_serial_control->queue);
free(furi_hal_serial_control);
}
void furi_hal_serial_control_suspend(void) {
furi_check(furi_hal_serial_control);
FuriHalSerialControlMessage message;
message.type = FuriHalSerialControlMessageTypeSuspend;
message.api_lock = api_lock_alloc_locked();
furi_message_queue_put(furi_hal_serial_control->queue, &message, FuriWaitForever);
api_lock_wait_unlock_and_free(message.api_lock);
}
void furi_hal_serial_control_resume(void) {
furi_check(furi_hal_serial_control);
FuriHalSerialControlMessage message;
message.type = FuriHalSerialControlMessageTypeResume;
message.api_lock = api_lock_alloc_locked();
furi_message_queue_put(furi_hal_serial_control->queue, &message, FuriWaitForever);
api_lock_wait_unlock_and_free(message.api_lock);
}
FuriHalSerialHandle* furi_hal_serial_control_acquire(FuriHalSerialId serial_id) {
furi_check(furi_hal_serial_control);
FuriHalSerialHandle* output = NULL;
FuriHalSerialControlMessage message;
message.type = FuriHalSerialControlMessageTypeAcquire;
message.api_lock = api_lock_alloc_locked();
message.input = &serial_id;
message.output = &output;
furi_message_queue_put(furi_hal_serial_control->queue, &message, FuriWaitForever);
api_lock_wait_unlock_and_free(message.api_lock);
return output;
}
void furi_hal_serial_control_release(FuriHalSerialHandle* handle) {
furi_check(furi_hal_serial_control);
furi_check(handle);
FuriHalSerialControlMessage message;
message.type = FuriHalSerialControlMessageTypeRelease;
message.api_lock = api_lock_alloc_locked();
message.input = &handle;
furi_message_queue_put(furi_hal_serial_control->queue, &message, FuriWaitForever);
api_lock_wait_unlock_and_free(message.api_lock);
}
void furi_hal_serial_control_set_logging_config(FuriHalSerialId serial_id, uint32_t baud_rate) {
furi_check(serial_id <= FuriHalSerialIdMax);
furi_check(baud_rate >= 9600 && baud_rate <= 4000000);
// Very special case of updater, where RTC initialized before kernel start
if(!furi_hal_serial_control) return;
FuriHalSerialControlMessageInputLogging message_input = {
.id = serial_id,
.baud_rate = baud_rate,
};
FuriHalSerialControlMessage message;
message.type = FuriHalSerialControlMessageTypeLogging;
message.api_lock = api_lock_alloc_locked();
message.input = &message_input;
furi_message_queue_put(furi_hal_serial_control->queue, &message, FuriWaitForever);
api_lock_wait_unlock_and_free(message.api_lock);
}
@@ -0,0 +1,46 @@
#pragma once
#include "furi_hal_serial_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Initialize Serial Control */
void furi_hal_serial_control_init(void);
/** De-Initialize Serial Control */
void furi_hal_serial_control_deinit(void);
/** Suspend All Serial Interfaces */
void furi_hal_serial_control_suspend(void);
/** Resume All Serial Interfaces */
void furi_hal_serial_control_resume(void);
/** Acquire Serial Interface Handler
*
* @param[in] serial_id The serial transceiver identifier
*
* @return The Serial Interface Handle or null if interfaces is in use
*/
FuriHalSerialHandle* furi_hal_serial_control_acquire(FuriHalSerialId serial_id);
/** Release Serial Interface Handler
*
* @param handle The handle
*/
void furi_hal_serial_control_release(FuriHalSerialHandle* handle);
/** Acquire Serial Interface Handler
*
* @param[in] serial_id The serial transceiver identifier. Use FuriHalSerialIdMax to disable logging.
* @param[in] baud_rate The baud rate
*
* @return The Serial Interface Handle or null if interfaces is in use
*/
void furi_hal_serial_control_set_logging_config(FuriHalSerialId serial_id, uint32_t baud_rate);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,15 @@
#pragma once
#include <furi.h>
/**
* UART channels
*/
typedef enum {
FuriHalSerialIdUsart,
FuriHalSerialIdLpuart,
FuriHalSerialIdMax,
} FuriHalSerialId;
typedef struct FuriHalSerialHandle FuriHalSerialHandle;
@@ -0,0 +1,8 @@
#pragma once
#include <furi_hal_serial_types.h>
struct FuriHalSerialHandle {
FuriHalSerialId id;
bool in_use;
};
-244
View File
@@ -1,244 +0,0 @@
#include <furi_hal_uart.h>
#include <stdbool.h>
#include <stm32wbxx_ll_lpuart.h>
#include <stm32wbxx_ll_usart.h>
#include <stm32wbxx_ll_rcc.h>
#include <furi_hal_resources.h>
#include <furi_hal_bus.h>
#include <furi.h>
static bool furi_hal_usart_prev_enabled[2];
static void (*irq_cb[2])(uint8_t ev, uint8_t data, void* context);
static void* irq_ctx[2];
static void furi_hal_usart_init(uint32_t baud) {
furi_hal_bus_enable(FuriHalBusUSART1);
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2);
furi_hal_gpio_init_ex(
&gpio_usart_tx,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn7USART1);
furi_hal_gpio_init_ex(
&gpio_usart_rx,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn7USART1);
LL_USART_InitTypeDef USART_InitStruct;
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
USART_InitStruct.BaudRate = baud;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
LL_USART_Init(USART1, &USART_InitStruct);
LL_USART_EnableFIFO(USART1);
LL_USART_ConfigAsyncMode(USART1);
LL_USART_Enable(USART1);
while(!LL_USART_IsActiveFlag_TEACK(USART1) || !LL_USART_IsActiveFlag_REACK(USART1))
;
LL_USART_DisableIT_ERROR(USART1);
NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
}
static void furi_hal_lpuart_init(uint32_t baud) {
furi_hal_bus_enable(FuriHalBusLPUART1);
LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1);
furi_hal_gpio_init_ex(
&gpio_ext_pc0,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn8LPUART1);
furi_hal_gpio_init_ex(
&gpio_ext_pc1,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn8LPUART1);
LL_LPUART_InitTypeDef LPUART_InitStruct;
LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1;
LPUART_InitStruct.BaudRate = 115200;
LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B;
LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1;
LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE;
LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX;
LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE;
LL_LPUART_Init(LPUART1, &LPUART_InitStruct);
LL_LPUART_EnableFIFO(LPUART1);
LL_LPUART_Enable(LPUART1);
while(!LL_LPUART_IsActiveFlag_TEACK(LPUART1) || !LL_LPUART_IsActiveFlag_REACK(LPUART1))
;
furi_hal_uart_set_br(FuriHalUartIdLPUART1, baud);
LL_LPUART_DisableIT_ERROR(LPUART1);
NVIC_SetPriority(LPUART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
}
void furi_hal_uart_init(FuriHalUartId ch, uint32_t baud) {
if(ch == FuriHalUartIdLPUART1) {
furi_hal_lpuart_init(baud);
} else if(ch == FuriHalUartIdUSART1) {
furi_hal_usart_init(baud);
}
}
void furi_hal_uart_set_br(FuriHalUartId ch, uint32_t baud) {
if(ch == FuriHalUartIdUSART1) {
if(LL_USART_IsEnabled(USART1)) {
// Wait for transfer complete flag
while(!LL_USART_IsActiveFlag_TC(USART1))
;
LL_USART_Disable(USART1);
uint32_t uartclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE);
LL_USART_SetBaudRate(
USART1, uartclk, LL_USART_PRESCALER_DIV1, LL_USART_OVERSAMPLING_16, baud);
LL_USART_Enable(USART1);
}
} else if(ch == FuriHalUartIdLPUART1) {
if(LL_LPUART_IsEnabled(LPUART1)) {
// Wait for transfer complete flag
while(!LL_LPUART_IsActiveFlag_TC(LPUART1))
;
LL_LPUART_Disable(LPUART1);
uint32_t uartclk = LL_RCC_GetLPUARTClockFreq(LL_RCC_LPUART1_CLKSOURCE);
if(uartclk / baud > 4095) {
LL_LPUART_SetPrescaler(LPUART1, LL_LPUART_PRESCALER_DIV32);
LL_LPUART_SetBaudRate(LPUART1, uartclk, LL_LPUART_PRESCALER_DIV32, baud);
} else {
LL_LPUART_SetPrescaler(LPUART1, LL_LPUART_PRESCALER_DIV1);
LL_LPUART_SetBaudRate(LPUART1, uartclk, LL_LPUART_PRESCALER_DIV1, baud);
}
LL_LPUART_Enable(LPUART1);
}
}
}
void furi_hal_uart_deinit(FuriHalUartId ch) {
furi_hal_uart_set_irq_cb(ch, NULL, NULL);
if(ch == FuriHalUartIdUSART1) {
if(furi_hal_bus_is_enabled(FuriHalBusUSART1)) {
furi_hal_bus_disable(FuriHalBusUSART1);
}
furi_hal_gpio_init(&gpio_usart_tx, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_usart_rx, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
} else if(ch == FuriHalUartIdLPUART1) {
if(furi_hal_bus_is_enabled(FuriHalBusLPUART1)) {
furi_hal_bus_disable(FuriHalBusLPUART1);
}
furi_hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pc1, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
}
void furi_hal_uart_suspend(FuriHalUartId channel) {
if(channel == FuriHalUartIdLPUART1 && LL_LPUART_IsEnabled(LPUART1)) {
LL_LPUART_Disable(LPUART1);
furi_hal_usart_prev_enabled[channel] = true;
} else if(channel == FuriHalUartIdUSART1 && LL_USART_IsEnabled(USART1)) {
LL_USART_Disable(USART1);
furi_hal_usart_prev_enabled[channel] = true;
}
}
void furi_hal_uart_resume(FuriHalUartId channel) {
if(!furi_hal_usart_prev_enabled[channel]) {
return;
} else if(channel == FuriHalUartIdLPUART1) {
LL_LPUART_Enable(LPUART1);
} else if(channel == FuriHalUartIdUSART1) {
LL_USART_Enable(USART1);
}
furi_hal_usart_prev_enabled[channel] = false;
}
void furi_hal_uart_tx(FuriHalUartId ch, uint8_t* buffer, size_t buffer_size) {
if(ch == FuriHalUartIdUSART1) {
if(LL_USART_IsEnabled(USART1) == 0) return;
while(buffer_size > 0) {
while(!LL_USART_IsActiveFlag_TXE(USART1))
;
LL_USART_TransmitData8(USART1, *buffer);
buffer++;
buffer_size--;
}
} else if(ch == FuriHalUartIdLPUART1) {
if(LL_LPUART_IsEnabled(LPUART1) == 0) return;
while(buffer_size > 0) {
while(!LL_LPUART_IsActiveFlag_TXE(LPUART1))
;
LL_LPUART_TransmitData8(LPUART1, *buffer);
buffer++;
buffer_size--;
}
}
}
void furi_hal_uart_set_irq_cb(
FuriHalUartId ch,
void (*cb)(UartIrqEvent ev, uint8_t data, void* ctx),
void* ctx) {
if(cb == NULL) {
if(ch == FuriHalUartIdUSART1) {
NVIC_DisableIRQ(USART1_IRQn);
LL_USART_DisableIT_RXNE_RXFNE(USART1);
} else if(ch == FuriHalUartIdLPUART1) {
NVIC_DisableIRQ(LPUART1_IRQn);
LL_LPUART_DisableIT_RXNE_RXFNE(LPUART1);
}
irq_cb[ch] = cb;
irq_ctx[ch] = ctx;
} else {
irq_ctx[ch] = ctx;
irq_cb[ch] = cb;
if(ch == FuriHalUartIdUSART1) {
NVIC_EnableIRQ(USART1_IRQn);
LL_USART_EnableIT_RXNE_RXFNE(USART1);
} else if(ch == FuriHalUartIdLPUART1) {
NVIC_EnableIRQ(LPUART1_IRQn);
LL_LPUART_EnableIT_RXNE_RXFNE(LPUART1);
}
}
}
void LPUART1_IRQHandler(void) {
if(LL_LPUART_IsActiveFlag_RXNE_RXFNE(LPUART1)) {
uint8_t data = LL_LPUART_ReceiveData8(LPUART1);
irq_cb[FuriHalUartIdLPUART1](UartIrqEventRXNE, data, irq_ctx[FuriHalUartIdLPUART1]);
} else if(LL_LPUART_IsActiveFlag_ORE(LPUART1)) {
LL_LPUART_ClearFlag_ORE(LPUART1);
}
}
void USART1_IRQHandler(void) {
if(LL_USART_IsActiveFlag_RXNE_RXFNE(USART1)) {
uint8_t data = LL_USART_ReceiveData8(USART1);
irq_cb[FuriHalUartIdUSART1](UartIrqEventRXNE, data, irq_ctx[FuriHalUartIdUSART1]);
} else if(LL_USART_IsActiveFlag_ORE(USART1)) {
LL_USART_ClearFlag_ORE(USART1);
}
}
-89
View File
@@ -1,89 +0,0 @@
/**
* @file furi_hal_uart.h
* @version 1.0
* @date 2021-11-19
*
* UART HAL api interface
*/
#pragma once
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* UART channels
*/
typedef enum {
FuriHalUartIdUSART1,
FuriHalUartIdLPUART1,
} FuriHalUartId;
/**
* UART events
*/
typedef enum {
UartIrqEventRXNE,
} UartIrqEvent;
/**
* Init UART
* Configures GPIO to UART function, сonfigures UART hardware, enables UART hardware
* @param channel UART channel
* @param baud baudrate
*/
void furi_hal_uart_init(FuriHalUartId channel, uint32_t baud);
/**
* Deinit UART
* Configures GPIO to analog, clears callback and callback context, disables UART hardware
* @param channel UART channel
*/
void furi_hal_uart_deinit(FuriHalUartId channel);
/**
* Suspend UART operation
* Disables UART hardware, settings and callbacks are preserved
* @param channel UART channel
*/
void furi_hal_uart_suspend(FuriHalUartId channel);
/**
* Resume UART operation
* Resumes UART hardware from suspended state
* @param channel UART channel
*/
void furi_hal_uart_resume(FuriHalUartId channel);
/**
* Changes UART baudrate
* @param channel UART channel
* @param baud baudrate
*/
void furi_hal_uart_set_br(FuriHalUartId channel, uint32_t baud);
/**
* Transmits data
* @param channel UART channel
* @param buffer data
* @param buffer_size data size (in bytes)
*/
void furi_hal_uart_tx(FuriHalUartId channel, uint8_t* buffer, size_t buffer_size);
/**
* Sets UART event callback
* @param channel UART channel
* @param callback callback pointer
* @param context callback context
*/
void furi_hal_uart_set_irq_cb(
FuriHalUartId channel,
void (*callback)(UartIrqEvent event, uint8_t data, void* context),
void* context);
#ifdef __cplusplus
}
#endif
+2 -2
View File
@@ -14,7 +14,6 @@ struct STOP_EXTERNING_ME {};
#include <furi_hal_clock.h>
#include <furi_hal_bus.h>
#include <furi_hal_crypto.h>
#include <furi_hal_console.h>
#include <furi_hal_debug.h>
#include <furi_hal_dma.h>
#include <furi_hal_os.h>
@@ -36,7 +35,8 @@ struct STOP_EXTERNING_ME {};
#include <furi_hal_usb.h>
#include <furi_hal_usb_hid.h>
#include <furi_hal_usb_ccid.h>
#include <furi_hal_uart.h>
#include <furi_hal_serial_control.h>
#include <furi_hal_serial.h>
#include <furi_hal_info.h>
#include <furi_hal_random.h>
#include <furi_hal_target_hw.h>