From 20639b77a615eac5538941972f47fed717949e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 7 Jul 2018 23:02:58 +0200 Subject: [PATCH] clean up for porting - move platform specific stuff into outer project --- FreeRTOSConfig.h | 34 +-- USB/usbd_conf.c | 13 +- comm/event_reports.h | 6 +- comm/iface_nordic.c | 4 +- comm/iface_nordic.h | 7 +- comm/iface_uart.h | 6 +- comm/iface_usb.h | 6 +- comm/interfaces.h | 6 +- comm/msg_bulkread.h | 6 +- comm/msg_bulkwrite.h | 6 +- comm/msg_responses.h | 6 +- comm/nrf.c | 4 + comm/nrf.h | 8 +- comm/nrf_pins.h | 75 ------ framework/rsc_enum.h | 6 +- framework/settings.c | 3 +- gex.mk | 3 +- platform/cfg_utils.h | 6 +- platform/debug_uart.c | 43 ---- platform/irq_dispatcher.h | 6 +- platform/ll_extension.h | 6 +- platform/lock_jumper.h | 2 - platform/plat_config.h | 64 ++++++ platform/platform.c | 214 +----------------- platform/platform.h | 7 + platform/timebase.h | 6 +- platform/watchdog.h | 6 +- tasks/task_msg.h | 6 +- template/nrf_pins.h.txt | 41 ++++ template/old/FreeRTOSConfig.plat.txt | 28 +++ template/old/debug_uart.h.txt | 41 ++++ .../old/plat_compat.h.txt | 69 ------ template/old/plat_init.c.txt | 194 ++++++++++++++++ template/plat_compat.h.txt | 46 ++++ template/template_unit.zip | Bin 0 -> 4028 bytes 35 files changed, 499 insertions(+), 485 deletions(-) delete mode 100644 comm/nrf_pins.h create mode 100644 platform/plat_config.h create mode 100644 template/nrf_pins.h.txt create mode 100644 template/old/FreeRTOSConfig.plat.txt create mode 100644 template/old/debug_uart.h.txt rename platform/plat_compat.h => template/old/plat_compat.h.txt (73%) create mode 100644 template/old/plat_init.c.txt create mode 100644 template/plat_compat.h.txt create mode 100644 template/template_unit.zip diff --git a/FreeRTOSConfig.h b/FreeRTOSConfig.h index bbb8c9c..f626c15 100644 --- a/FreeRTOSConfig.h +++ b/FreeRTOSConfig.h @@ -90,6 +90,7 @@ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) #include #include "main.h" + #include "plat_config.h" #include "plat_compat.h" extern uint32_t SystemCoreClock; #endif @@ -134,34 +135,11 @@ to exclude the API function. */ ///* Cortex-M specific definitions. */ -#if defined(GEX_PLAT_F103_BLUEPILL) || defined(GEX_PLAT_F303_DISCOVERY) \ - || defined(GEX_PLAT_F407_DISCOVERY) - // This is for F103+ - - /* The lowest interrupt priority that can be used in a call to a "set priority" - function. */ - #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 - - #define configPRIO_BITS 4 - - /* The highest interrupt priority that can be used by any interrupt service - routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL - INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER - PRIORITY THAN THIS! (higher priorities are lower numeric values. */ - #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 - - #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 -#elif defined(STM32F072xB) - // This is for F072 - #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 3 - #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 1 - - #define configPRIO_BITS 2 - - #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 -#else - #error "BAD PLATFORM!!" -#endif +// These are defined in plat_compat.h: +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY PLAT_FREERTOS_LOWEST_INTERRUPT_PRIORITY +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY PLAT_FREERTOS_MAX_SYSCALL_INTERRUPT_PRIORITY +#define configPRIO_BITS PLAT_FREERTOS_PRIO_BITS +#define configUSE_PORT_OPTIMISED_TASK_SELECTION PLAT_FREERTOS_USE_PORT_OPTIMISED_TASK_SELECTION /* Interrupt priorities used by the kernel port layer itself. These are generic to all Cortex-M ports, and do not rely on any particular library functions. */ diff --git a/USB/usbd_conf.c b/USB/usbd_conf.c index 25fd096..11a2618 100644 --- a/USB/usbd_conf.c +++ b/USB/usbd_conf.c @@ -84,13 +84,14 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) __HAL_RCC_USB_CLK_ENABLE(); /* Peripheral interrupt init */ -#if GEX_PLAT_F103_BLUEPILL + // TODO convert this to feature flags if possible - avoid tying to particular platforms +#if GEX_PLAT_F103 HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); -#elif STM32F072xB +#elif GEX_PLAT_F072 HAL_NVIC_SetPriority(USB_IRQn, 3, 0); HAL_NVIC_EnableIRQ(USB_IRQn); -#elif GEX_PLAT_F303_DISCOVERY +#elif GEX_PLAT_F303 // Pins need to be configured here /**USB GPIO Configuration @@ -149,11 +150,11 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) __HAL_RCC_USB_CLK_DISABLE(); /* Peripheral interrupt Deinit*/ -#if GEX_PLAT_F103_BLUEPILL +#if GEX_PLAT_F103 HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); -#elif STM32F072xB +#elif GEX_PLAT_F072 HAL_NVIC_DisableIRQ(USB_IRQn); -#elif GEX_PLAT_F303_DISCOVERY +#elif GEX_PLAT_F303 HAL_NVIC_DisableIRQ(USB_LP_CAN_RX0_IRQn); #else #error "BAD PLATFORM" diff --git a/comm/event_reports.h b/comm/event_reports.h index 05f57c1..8d10ac1 100644 --- a/comm/event_reports.h +++ b/comm/event_reports.h @@ -2,8 +2,8 @@ // Created by MightyPork on 2018/01/27. // -#ifndef GEX_F072_EVENT_REPORTS_H -#define GEX_F072_EVENT_REPORTS_H +#ifndef GEX_CORE_EVENT_REPORTS_H +#define GEX_CORE_EVENT_REPORTS_H #ifndef GEX_MESSAGES_H #error "Include messages.h instead!" @@ -31,4 +31,4 @@ void EventReport_Data(const uint8_t *buff, uint16_t len); void EventReport_PB(PayloadBuilder *pb); void EventReport_End(void); -#endif //GEX_F072_EVENT_REPORTS_H +#endif //GEX_CORE_EVENT_REPORTS_H diff --git a/comm/iface_nordic.c b/comm/iface_nordic.c index d73bac7..bf0e403 100644 --- a/comm/iface_nordic.c +++ b/comm/iface_nordic.c @@ -2,6 +2,9 @@ // Created by MightyPork on 2018/04/06. // +#include "platform.h" +#if SUPPORT_NRF + #include "iface_nordic.h" #include "nrf_pins.h" #include "resources.h" @@ -11,7 +14,6 @@ #include "system_settings.h" #include "utils/hexdump.h" -#if SUPPORT_NRF extern osSemaphoreId semVcomTxReadyHandle; diff --git a/comm/iface_nordic.h b/comm/iface_nordic.h index 1e09d6f..1b128c1 100644 --- a/comm/iface_nordic.h +++ b/comm/iface_nordic.h @@ -2,11 +2,10 @@ // Created by MightyPork on 2018/04/06. // -#ifndef GEX_F072_IFACE_NORDIC_H -#define GEX_F072_IFACE_NORDIC_H +#ifndef GEX_CORE_IFACE_NORDIC_H +#define GEX_CORE_IFACE_NORDIC_H #include "platform.h" - #if SUPPORT_NRF void iface_nordic_claim_resources(void); @@ -21,4 +20,4 @@ void iface_nordic_transmit(const uint8_t *buff, uint32_t len); #endif // SUPPORT_NRF -#endif //GEX_F072_IFACE_NORDIC_H +#endif //GEX_CORE_IFACE_NORDIC_H diff --git a/comm/iface_uart.h b/comm/iface_uart.h index 71b6c3f..c98c150 100644 --- a/comm/iface_uart.h +++ b/comm/iface_uart.h @@ -2,8 +2,8 @@ // Created by MightyPork on 2018/04/06. // -#ifndef GEX_F072_IFACE_UART_H -#define GEX_F072_IFACE_UART_H +#ifndef GEX_CORE_IFACE_UART_H +#define GEX_CORE_IFACE_UART_H #include "platform.h" @@ -17,4 +17,4 @@ void iface_uart_claim_resources(void); void iface_uart_transmit(const uint8_t *buff, uint32_t len); -#endif //GEX_F072_IFACE_UART_H +#endif //GEX_CORE_IFACE_UART_H diff --git a/comm/iface_usb.h b/comm/iface_usb.h index d83f370..459e4ce 100644 --- a/comm/iface_usb.h +++ b/comm/iface_usb.h @@ -2,8 +2,8 @@ // Created by MightyPork on 2018/04/06. // -#ifndef GEX_F072_IFACE_USB_H -#define GEX_F072_IFACE_USB_H +#ifndef GEX_CORE_IFACE_USB_H +#define GEX_CORE_IFACE_USB_H #include "platform.h" @@ -17,4 +17,4 @@ bool iface_usb_ready(void); */ void iface_usb_transmit(const uint8_t *buff, uint32_t len); -#endif //GEX_F072_IFACE_USB_H +#endif //GEX_CORE_IFACE_USB_H diff --git a/comm/interfaces.h b/comm/interfaces.h index fe56abe..3038f1a 100644 --- a/comm/interfaces.h +++ b/comm/interfaces.h @@ -2,8 +2,8 @@ // Created by MightyPork on 2018/03/23. // -#ifndef GEX_F072_COM_INTERFACES_H -#define GEX_F072_COM_INTERFACES_H +#ifndef GEX_CORE_COM_INTERFACES_H +#define GEX_CORE_COM_INTERFACES_H #include "platform.h" @@ -34,4 +34,4 @@ void com_release_resources_for_alt_transfers(void); /** Flush the rx buffer */ void com_iface_flush_buffer(void); -#endif //GEX_F072_COM_INTERFACES_H +#endif //GEX_CORE_COM_INTERFACES_H diff --git a/comm/msg_bulkread.h b/comm/msg_bulkread.h index d8ca9ee..62dfc8c 100644 --- a/comm/msg_bulkread.h +++ b/comm/msg_bulkread.h @@ -4,8 +4,8 @@ // Bulk read (providing data for bulk read by the PC) // -#ifndef GEX_F072_MSG_BULKREAD_H -#define GEX_F072_MSG_BULKREAD_H +#ifndef GEX_CORE_MSG_BULKREAD_H +#define GEX_CORE_MSG_BULKREAD_H #ifndef GEX_MESSAGES_H #error "Include messages.h instead!" @@ -45,4 +45,4 @@ struct bulk_read { void bulkread_start(TinyFrame *tf, BulkRead *bulk); -#endif //GEX_F072_MSG_BULKREAD_H +#endif //GEX_CORE_MSG_BULKREAD_H diff --git a/comm/msg_bulkwrite.h b/comm/msg_bulkwrite.h index 3e5715e..1f242ce 100644 --- a/comm/msg_bulkwrite.h +++ b/comm/msg_bulkwrite.h @@ -4,8 +4,8 @@ // Bulk write (receiving bulk write from the PC) // -#ifndef GEX_F072_MSG_BULKWRITE_H -#define GEX_F072_MSG_BULKWRITE_H +#ifndef GEX_CORE_MSG_BULKWRITE_H +#define GEX_CORE_MSG_BULKWRITE_H #ifndef GEX_MESSAGES_H #error "Include messages.h instead!" @@ -44,4 +44,4 @@ struct bulk_write { void bulkwrite_start(TinyFrame *tf, BulkWrite *bulk); -#endif //GEX_F072_MSG_BULKWRITE_H +#endif //GEX_CORE_MSG_BULKWRITE_H diff --git a/comm/msg_responses.h b/comm/msg_responses.h index 0145c32..f4cbbdd 100644 --- a/comm/msg_responses.h +++ b/comm/msg_responses.h @@ -4,8 +4,8 @@ // Routines for sending TinyFrame responses. // -#ifndef GEX_F072_MSG_RESPONSES_H -#define GEX_F072_MSG_RESPONSES_H +#ifndef GEX_CORE_MSG_RESPONSES_H +#define GEX_CORE_MSG_RESPONSES_H #ifndef GEX_MESSAGES_H #error "Include messages.h instead!" @@ -109,4 +109,4 @@ void com_respond_u16(TF_ID frame_id, uint16_t d); */ void com_respond_u32(TF_ID frame_id, uint32_t d); -#endif //GEX_F072_MSG_RESPONSES_H +#endif //GEX_CORE_MSG_RESPONSES_H diff --git a/comm/nrf.c b/comm/nrf.c index 00a7768..551faae 100644 --- a/comm/nrf.c +++ b/comm/nrf.c @@ -3,6 +3,8 @@ // #include "platform.h" +#if SUPPORT_NRF + #include "nrf.h" /** @@ -545,3 +547,5 @@ bool NRF_Init(uint8_t pSpeed) return true; } + +#endif diff --git a/comm/nrf.h b/comm/nrf.h index 2256c39..e1b8524 100644 --- a/comm/nrf.h +++ b/comm/nrf.h @@ -15,11 +15,9 @@ * */ - -#ifndef NORDIC_H_ -#define NORDIC_H_ - #include "platform.h" +#if SUPPORT_NRF + #include "resources.h" #include "nrf_pins.h" @@ -160,6 +158,6 @@ void NRF_EnablePipe(uint8_t pipenum); */ void NRF_DisablePipe(uint8_t pipenum); -#endif /* NORDIC_H_ */ +#endif // SUPPORT_NRF #endif //GEX_NRF_NRF_H diff --git a/comm/nrf_pins.h b/comm/nrf_pins.h deleted file mode 100644 index f1702da..0000000 --- a/comm/nrf_pins.h +++ /dev/null @@ -1,75 +0,0 @@ -// -// Created by MightyPork on 2018/04/06. -// - -#ifndef GEX_F072_NRF_PINS_H -#define GEX_F072_NRF_PINS_H - -#include "platform.h" - -#if defined(GEX_PLAT_F072_DISCOVERY) || defined(GEX_PLAT_F072_HUB) - - // This config was used only for development when NRF was enabled for those platforms. It is normally disabled. - #define NRF_SPI SPI1 - #define NRF_R_SPI R_SPI1 - - #define NRF_IRQ_Pin LL_GPIO_PIN_10 - #define NRF_IRQ_GPIO_Port GPIOB - #define NRF_R_IRQ R_PB10 - #define NRF_EXTI_LINENUM 10 - #define NRF_SYSCFG_EXTI_PORT LL_SYSCFG_EXTI_PORTB - - #define NRF_NSS_Pin LL_GPIO_PIN_11 - #define NRF_NSS_GPIO_Port GPIOB - #define NRF_R_NSS R_PB11 - - #define NRF_CE_Pin LL_GPIO_PIN_12 - #define NRF_CE_GPIO_Port GPIOB - #define NRF_R_CE R_PB12 - - #define NRF_RST_Pin LL_GPIO_PIN_13 - #define NRF_RST_GPIO_Port GPIOB - #define NRF_R_RST R_PB13 - - #define NRF_R_SCK R_PA5 - #define NRF_SCK_AF LL_GPIO_AF_0 - #define NRF_R_MISO R_PA6 - #define NRF_MISO_AF LL_GPIO_AF_0 - #define NRF_R_MOSI R_PA7 - #define NRF_MOSI_AF LL_GPIO_AF_0 - -#elif defined(GEX_PLAT_F072_ZERO) - - #define NRF_SPI SPI2 - #define NRF_R_SPI R_SPI2 - - #define NRF_IRQ_Pin LL_GPIO_PIN_15 - #define NRF_IRQ_GPIO_Port GPIOC - #define NRF_R_IRQ R_PC15 - #define NRF_EXTI_LINENUM 15 - #define NRF_SYSCFG_EXTI_PORT LL_SYSCFG_EXTI_PORTC - - #define NRF_NSS_Pin LL_GPIO_PIN_13 - #define NRF_NSS_GPIO_Port GPIOC - #define NRF_R_NSS R_PC13 - - #define NRF_CE_Pin LL_GPIO_PIN_14 - #define NRF_CE_GPIO_Port GPIOC - #define NRF_R_CE R_PC14 - - #define NRF_RST_Pin LL_GPIO_PIN_12 - #define NRF_RST_GPIO_Port GPIOC - #define NRF_R_RST R_PC12 - - #define NRF_R_SCK R_PB13 - #define NRF_SCK_AF LL_GPIO_AF_0 - #define NRF_R_MISO R_PC2 - #define NRF_MISO_AF LL_GPIO_AF_1 - #define NRF_R_MOSI R_PC3 - #define NRF_MOSI_AF LL_GPIO_AF_1 - -#else - #error "Missing NRF config for this platform." -#endif - -#endif //GEX_F072_NRF_PINS_H diff --git a/framework/rsc_enum.h b/framework/rsc_enum.h index fdb21ea..3348437 100644 --- a/framework/rsc_enum.h +++ b/framework/rsc_enum.h @@ -4,8 +4,8 @@ // Enum of all defined resources // -#ifndef GEX_F072_RSC_ENUM_H -#define GEX_F072_RSC_ENUM_H +#ifndef GEX_CORE_RSC_ENUM_H +#define GEX_CORE_RSC_ENUM_H // X macro: Resource name, #define XX_RESOURCES \ @@ -132,4 +132,4 @@ static inline void rscmap_free(ResourceMap *rscmap, Resource rsc) #define RSC_CLAIM(rscmap, rsc) rscmap_claim(&rscmap, (rsc)) #define RSC_FREE(rscmap, rsc) rscmap_free(&rscmap, (rsc)) -#endif //GEX_F072_RSC_ENUM_H +#endif //GEX_CORE_RSC_ENUM_H diff --git a/framework/settings.c b/framework/settings.c index 5abd366..2141f9f 100644 --- a/framework/settings.c +++ b/framework/settings.c @@ -110,7 +110,7 @@ void settings_save(void) erase.Banks = FLASH_BANK_1; // TODO ????? #endif -#if defined(GEX_PLAT_F407_DISCOVERY) +#if GEX_PLAT_F407 // specialty for F4 with too much flash erase.NbSectors = 1; erase.Sector = SETTINGS_FLASH_SECTOR; @@ -122,6 +122,7 @@ void settings_save(void) erase.PageAddress = SETTINGS_FLASH_ADDR; erase.TypeErase = FLASH_TYPEERASE_PAGES; #endif + uint32_t pgerror = 0; hst = HAL_FLASHEx_Erase(&erase, &pgerror); assert_param(pgerror == 0xFFFFFFFFU); diff --git a/gex.mk b/gex.mk index b788611..9076656 100644 --- a/gex.mk +++ b/gex.mk @@ -83,7 +83,8 @@ GEX_C_FILES = \ GexCore/USB/STM32_USB_Device_Library/Class/MSC_CDC/usbd_msc_cdc.c \ GexCore/USB/STM32_USB_Device_Library/Core/Src/usbd_core.c \ GexCore/USB/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \ - GexCore/USB/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c + GexCore/USB/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \ + Src/platform_resources.c GEX_C_INCLUDES = \ -IGexUnits \ diff --git a/platform/cfg_utils.h b/platform/cfg_utils.h index de34c19..9496a06 100644 --- a/platform/cfg_utils.h +++ b/platform/cfg_utils.h @@ -2,8 +2,8 @@ // Created by MightyPork on 2018/02/23. // -#ifndef GEX_F072_CFG_UTILS_H -#define GEX_F072_CFG_UTILS_H +#ifndef GEX_CORE_CFG_UTILS_H +#define GEX_CORE_CFG_UTILS_H #include "platform.h" #include "rsc_enum.h" @@ -162,4 +162,4 @@ static inline int32_t cfg_i32_parse(const char *value, bool *suc) return (int32_t) avr_atoi(value); } -#endif //GEX_F072_CFG_UTILS_H +#endif //GEX_CORE_CFG_UTILS_H diff --git a/platform/debug_uart.c b/platform/debug_uart.c index d0a3ef4..186fde8 100644 --- a/platform/debug_uart.c +++ b/platform/debug_uart.c @@ -5,54 +5,11 @@ #include "platform.h" #include "framework/resources.h" #include "debug_uart.h" -#include "plat_compat.h" #include "hw_utils.h" #include "framework/system_settings.h" #if USE_DEBUG_UART -#define DEBUG_USART_BAUD 115200 - -#if GEX_PLAT_F072_DISCOVERY || GEX_PLAT_F072_HUB || GEX_PLAT_F072_ZERO - - #define DEBUG_USART USART1 - #define DEBUG_USART_RSC R_USART1 - #define DEBUG_USART_PORT 'A' - #define DEBUG_USART_PIN 9 - #define DEBUG_USART_AF 1 - #define DEBUG_USART_PCLK PLAT_APB1_HZ - -#elif GEX_PLAT_F103_BLUEPILL - - #define DEBUG_USART USART2 - #define DEBUG_USART_RSC R_USART2 - #define DEBUG_USART_PORT 'A' - #define DEBUG_USART_PIN 2 - #define DEBUG_USART_PCLK PLAT_APB1_HZ - -#elif GEX_PLAT_F303_DISCOVERY - - #define DEBUG_USART USART3 - #define DEBUG_USART_RSC R_USART3 - #define DEBUG_USART_PORT 'D' - #define DEBUG_USART_PIN 8 - #define DEBUG_USART_AF 7 - #define DEBUG_USART_PCLK PLAT_APB1_HZ - -#elif GEX_PLAT_F407_DISCOVERY - - #define DEBUG_USART USART2 - #define DEBUG_USART_RSC R_USART2 - #define DEBUG_USART_PORT 'A' - #define DEBUG_USART_PIN 2 - #define DEBUG_USART_AF 7 - #define DEBUG_USART_PCLK PLAT_APB1_HZ - -#else - #error "BAD PLATFORM!" -#endif - - static bool debug_uart_inited = false; static bool debug_uart_preinited = false; diff --git a/platform/irq_dispatcher.h b/platform/irq_dispatcher.h index 9a6ebc0..d2ee0d1 100644 --- a/platform/irq_dispatcher.h +++ b/platform/irq_dispatcher.h @@ -4,8 +4,8 @@ // Provides a trampoline system for redirecting IRQ calls to assigned callbacks. // -#ifndef GEX_F072_IRQ_DISPATCHER_H -#define GEX_F072_IRQ_DISPATCHER_H +#ifndef GEX_CORE_IRQ_DISPATCHER_H +#define GEX_CORE_IRQ_DISPATCHER_H // Dummy peripherals for use with the extern void * const EXTIS[16]; @@ -42,4 +42,4 @@ void irqd_attach(void *periph, IrqCallback callback, void *data); */ void* irqd_detach(void *periph, IrqCallback callback); -#endif //GEX_F072_IRQ_DISPATCHER_H +#endif //GEX_CORE_IRQ_DISPATCHER_H diff --git a/platform/ll_extension.h b/platform/ll_extension.h index 6f0b384..be23b67 100644 --- a/platform/ll_extension.h +++ b/platform/ll_extension.h @@ -2,8 +2,8 @@ // Created by MightyPork on 2018/02/04. // -#ifndef GEX_F072_LL_EXTENSION_H -#define GEX_F072_LL_EXTENSION_H +#ifndef GEX_CORE_LL_EXTENSION_H +#define GEX_CORE_LL_EXTENSION_H #include "platform.h" @@ -57,4 +57,4 @@ static inline void LL_DMA_ClearFlags(DMA_TypeDef *DMAx, uint8_t channel) } -#endif //GEX_F072_LL_EXTENSION_H +#endif //GEX_CORE_LL_EXTENSION_H diff --git a/platform/lock_jumper.h b/platform/lock_jumper.h index cc4b5c4..3e5fe92 100644 --- a/platform/lock_jumper.h +++ b/platform/lock_jumper.h @@ -7,8 +7,6 @@ #ifndef GEX_LOCK_JUMPER_H #define GEX_LOCK_JUMPER_H -#include "plat_compat.h" - /** * Init the lock jumper subsystem */ diff --git a/platform/plat_config.h b/platform/plat_config.h new file mode 100644 index 0000000..fda597e --- /dev/null +++ b/platform/plat_config.h @@ -0,0 +1,64 @@ +// +// Created by MightyPork on 2018/07/07. +// + +#ifndef GEX_CORE_PLAT_CONFIG_H +#define GEX_CORE_PLAT_CONFIG_H + +#define VFS_DRIVE_NAME "GEX" + +// -------- Priorities ------------- +#define TSK_MAIN_PRIO osPriorityNormal +#define TSK_JOBS_PRIO osPriorityHigh +#define TSK_TIMERS_PRIO 4 // this must be in the 0-7 range + +// -------- Static buffers --------- +// USB / VFS task stack size +#if DISABLE_MSC +#define TSK_STACK_MAIN 100 // without MSC the stack usage is significantly lower +#else +#define TSK_STACK_MAIN 160 +#endif + +// 180 is normally enough if not doing extensive debug logging +#define TSK_STACK_MSG 220 // TF message handler task stack size (all unit commands run on this thread) +#define TSK_STACK_IDLE 64 //configMINIMAL_STACK_SIZE +#define TSK_STACK_TIMERS 64 //configTIMER_TASK_STACK_DEPTH + +#define PLAT_HEAP_SIZE 4096 + + + +#define BULK_READ_BUF_LEN 256 // Buffer for TF bulk reads +#define UNIT_TMP_LEN 256 // Buffer for internal unit operations + +#define FLASH_SAVE_BUF_LEN 128 // Malloc'd buffer for saving to flash + +#define MSG_QUE_SLOT_SIZE 64 // FIXME this should be possible to lower, but there's some bug with bulk transfer / INI parser +#define RX_QUE_CAPACITY 16 // TinyFrame rx queue size (64 bytes each) + +#define TF_MAX_PAYLOAD_RX 512 // TF max Rx payload +#define TF_SENDBUF_LEN 512 // TF transmit buffer (can be less than a full frame) + +#define TF_MAX_ID_LST 4 // Frame ID listener count +#define TF_MAX_TYPE_LST 6 // Frame Type listener count +#define TF_MAX_GEN_LST 1 // Generic listener count + +#define USBD_MAX_STR_DESC_SIZ 64 // Descriptor conversion buffer (used for converting ASCII to UTF-16, must be 2x the size of the longest descriptor) +#define MSC_MEDIA_PACKET 512 // Mass storage sector size (packet) + +#define INI_KEY_MAX 20 // Ini parser key buffer +#define INI_VALUE_MAX 30 // Ini parser value buffer + +// -------- Stack buffers ---------- +#define DBG_BUF_LEN 100 // Size of the snprintf buffer for debug messages +#define ERR_MSG_STR_LEN 64 // Error message buffer size +#define IWBUFFER_LEN 80 // Ini writer buffer for sprintf + +// -------- Timeouts ------------ +#define TF_PARSER_TIMEOUT_TICKS 100 // Timeout for receiving & parsing a frame +#define BULK_LST_TIMEOUT_MS 2000 // timeout for the bulk transaction to expire +#define MSG_QUE_POST_TIMEOUT 200 // Time to post to the messages / jobs queue + + +#endif //GEX_CORE_PLAT_CONFIG_H diff --git a/platform/platform.c b/platform/platform.c index 8b5a791..f6291be 100644 --- a/platform/platform.c +++ b/platform/platform.c @@ -12,6 +12,8 @@ #include "units_manifest.h" +extern uint32_t plat_init_resources2(void); + // TODO split this and the plat_compat files to per-platform ones stored in the platform project void plat_init_resources(void) @@ -26,217 +28,16 @@ void plat_init_resources(void) hw_periph_clock_enable(DMA2); #endif - // --- Common unit drivers --- - - #if HAVE_TEST_UNIT - ureg_add_type(&UNIT_TEST); - #endif - // EXTI are always available rsc_free_range(NULL, R_EXTI0, R_EXTI15); // --- platform specific resource releases and claims --- -#if defined(GEX_PLAT_F103_BLUEPILL) - // Platform STM32F103C8T6 Bluepill ($4 board from eBay) - - // Units supported by the platform (known to work correctly) - - // free all present resources - { - rsc_free_range(NULL, R_ADC1, R_ADC2); - rsc_free_range(NULL, R_I2C1, R_I2C2); - rsc_free_range(NULL, R_SPI1, R_SPI2); - rsc_free_range(NULL, R_TIM1, R_TIM4); - rsc_free_range(NULL, R_USART1, R_USART3); - rsc_free_range(NULL, R_PA0, R_PA15); - rsc_free_range(NULL, R_PB0, R_PB15); - rsc_free_range(NULL, R_PC13, R_PC15); - rsc_free_range(NULL, R_PD0, R_PD1); - } - - // Claim resources not available due to board layout or internal usage - { - // HAL timebase - rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1); - // HSE crystal - rv |= rsc_claim(&UNIT_SYSTEM, R_PD0); - rv |= rsc_claim(&UNIT_SYSTEM, R_PD1); - // SWD - rv |= rsc_claim(&UNIT_SYSTEM, R_PA13); - rv |= rsc_claim(&UNIT_SYSTEM, R_PA14); - // USB - rv |= rsc_claim(&UNIT_SYSTEM, R_PA11); - rv |= rsc_claim(&UNIT_SYSTEM, R_PA12); - // BOOT pin(s) - rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1 - } -#elif defined(STM32F072xB) - // Platform STM32F073RBT - - // Additional GPIO ports - __HAL_RCC_GPIOF_CLK_ENABLE(); - // Units supported by the platform (known to work correctly) // - this is a macro created in the Makefile, registering all enabled units - UNITS_REGISTER_CMD - - // Free all present resources - { - rsc_free(NULL, R_ADC1); -// rsc_free(NULL, R_CAN1); -// rsc_free_range(NULL, R_COMP1, R_COMP2); - rsc_free(NULL, R_DAC1); -// rsc_free(NULL, R_HDMI_CEC); - rsc_free(NULL, R_TSC); - rsc_free_range(NULL, R_I2C1, R_I2C2); -// rsc_free_range(NULL, R_I2S1, R_I2S2); - rsc_free_range(NULL, R_SPI1, R_SPI2); - rsc_free_range(NULL, R_TIM1, R_TIM3); - rsc_free_range(NULL, R_TIM6, R_TIM7); - rsc_free_range(NULL, R_TIM14, R_TIM17); - rsc_free_range(NULL, R_USART1, R_USART4); - rsc_free_range(NULL, R_DMA1_1, R_DMA1_7); - - rsc_free_range(NULL, R_PA0, R_PA15); - rsc_free_range(NULL, R_PB0, R_PB15); - rsc_free_range(NULL, R_PC0, R_PC15); - rsc_free(NULL, R_PD2); - rsc_free_range(NULL, R_PF0, R_PF1); - } - - // Claim resources not available due to board layout or internal usage - { - // HAL timebase - rv |= rsc_claim(&UNIT_SYSTEM, R_TIM17); - // HSE crystal - rv |= rsc_claim(&UNIT_SYSTEM, R_PF0); - - #if PLAT_FULL_XTAL - rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode - #endif - - // SWD -// rv |= rsc_claim(&UNIT_SYSTEM, R_PA13); -// rv |= rsc_claim(&UNIT_SYSTEM, R_PA14); - // USB - rv |= rsc_claim(&UNIT_SYSTEM, R_PA11); - rv |= rsc_claim(&UNIT_SYSTEM, R_PA12); - - #if defined(GEX_PLAT_F072_ZERO) - // unconnected pins - rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC0, R_PC1); - rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC4, R_PC9); - #endif - } -#elif defined(GEX_PLAT_F303_DISCOVERY) - // Platform STM32F303VCT - - // Additional GPIO ports - __HAL_RCC_GPIOF_CLK_ENABLE(); - - // Units supported by the platform (known to work correctly) - // ureg_add_type(&UNIT_XYZ); - - // Free all present resources - { - rsc_free_range(NULL, R_ADC1, R_ADC4); -// rsc_free(NULL, R_CAN1); -// rsc_free_range(NULL, R_COMP1, R_COMP7); -// rsc_free(NULL, R_HDMI_CEC); - rsc_free(NULL, R_DAC1); - rsc_free_range(NULL, R_I2C1, R_I2C2); - rsc_free_range(NULL, R_I2S2, R_I2S3); -// rsc_free_range(NULL, R_OPAMP1, R_OPAMP4); - rsc_free_range(NULL, R_SPI1, R_SPI3); - rsc_free_range(NULL, R_TIM1, R_TIM4); - rsc_free_range(NULL, R_TIM6, R_TIM8); - rsc_free_range(NULL, R_TIM15, R_TIM17); - rsc_free(NULL, R_TSC); - rsc_free_range(NULL, R_USART1, R_USART5); - - rsc_free_range(NULL, R_PA0, R_PA15); - rsc_free_range(NULL, R_PB0, R_PB15); - rsc_free_range(NULL, R_PC0, R_PC15); - rsc_free_range(NULL, R_PD0, R_PD15); - rsc_free_range(NULL, R_PE0, R_PE15); - - rsc_free_range(NULL, R_PF0, R_PF2); - rsc_free(NULL, R_PF4); - rsc_free_range(NULL, R_PF9, R_PF10); - } - - // Claim resources not available due to board layout or internal usage - { - // HAL timebase - rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1); - // HSE crystal - rv |= rsc_claim(&UNIT_SYSTEM, R_PF0); - //rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode - // SWD - rv |= rsc_claim(&UNIT_SYSTEM, R_PA13); - rv |= rsc_claim(&UNIT_SYSTEM, R_PA14); - // USB - rv |= rsc_claim(&UNIT_SYSTEM, R_PA11); - rv |= rsc_claim(&UNIT_SYSTEM, R_PA12); - // BOOT pin(s) - rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1 - } -#elif defined(GEX_PLAT_F407_DISCOVERY) - // Platform STM32F407VGT - - // Additional GPIO ports - __HAL_RCC_GPIOF_CLK_ENABLE(); - - // Units supported by the platform (known to work correctly) - // ureg_add_type(&UNIT_XYZ); - - // Free all present resources - { - rsc_free_range(NULL, R_ADC1, R_ADC3); -// rsc_free_range(NULL, R_CAN1, R_CAN2); -// rsc_free_range(NULL, R_COMP1, R_COMP7); - rsc_free(NULL, R_DAC1); -// rsc_free(NULL, R_DCMI); -// rsc_free(NULL, R_ETH); -// rsc_free(NULL, R_FSMC); - rsc_free_range(NULL, R_I2C1, R_I2C3); - rsc_free_range(NULL, R_I2S2, R_I2S3); -// rsc_free(NULL, R_SDIO); - rsc_free_range(NULL, R_SPI1, R_SPI3); - rsc_free_range(NULL, R_TIM1, R_TIM14); - rsc_free_range(NULL, R_USART1, R_USART3); - rsc_free(NULL, R_USART6); - - rsc_free_range(NULL, R_PA0, R_PA15); - rsc_free_range(NULL, R_PB0, R_PB15); - rsc_free_range(NULL, R_PC0, R_PC15); - rsc_free_range(NULL, R_PD0, R_PD15); - rsc_free_range(NULL, R_PE0, R_PE15); - // also has 2 PH pins - - // F407 appears to have fewer GPIOs than F303? - } - - // Claim resources not available due to board layout or internal usage - { - // HAL timebase - rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1); - // HSE crystal - // H0 and H1 - // SWD - rv |= rsc_claim(&UNIT_SYSTEM, R_PA13); - rv |= rsc_claim(&UNIT_SYSTEM, R_PA14); - // USB - rv |= rsc_claim(&UNIT_SYSTEM, R_PA11); - rv |= rsc_claim(&UNIT_SYSTEM, R_PA12); - // BOOT pin(s) - rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1 - } -#else - #error "BAD PLATFORM!" -#endif + UNITS_REGISTER_CMD; + rv = plat_init_resources2(); assert_param(rv == 0); } @@ -250,13 +51,10 @@ void plat_usb_reconnect(void) { if (gActiveComport != COMPORT_USB) return; - // TODO add better reset methods available on different chips - + // TODO add other reset methods available on different chips (e.g. externam FET) USBD_LL_Reset(&hUsbDeviceFS); -#if defined(GEX_PLAT_F103_BLUEPILL) - // F103 doesn't have pull-up control -#else +#if PLAT_USB_PU_CTL HAL_PCD_DevDisconnect(&hpcd_USB_FS); osDelay(100); HAL_PCD_DevConnect(&hpcd_USB_FS); diff --git a/platform/platform.h b/platform/platform.h index b704719..31d42f0 100644 --- a/platform/platform.h +++ b/platform/platform.h @@ -17,8 +17,15 @@ // FreeRTOS includes #include +// platform-independent GEX config +#include "plat_config.h" // platform-specific stuff (includes stm32 driver headers) #include "plat_compat.h" + +#define PLAT_AHB_HZ (PLAT_AHB_MHZ*1000000) +#define PLAT_APB1_HZ (PLAT_APB1_MHZ*1000000) +#define PLAT_APB2_HZ (PLAT_APB2_MHZ*1000000) + // assert_param, trap... #include "stm32_assert.h" // inIRQ etc diff --git a/platform/timebase.h b/platform/timebase.h index 255e154..38500f8 100644 --- a/platform/timebase.h +++ b/platform/timebase.h @@ -8,8 +8,8 @@ // and interrupts. // -#ifndef GEX_F072_TIMEBASE_H -#define GEX_F072_TIMEBASE_H +#ifndef GEX_CORE_TIMEBASE_H +#define GEX_CORE_TIMEBASE_H #include "platform.h" @@ -58,4 +58,4 @@ static inline uint32_t PTIM_MicroDelayAlign(void) return res; } -#endif //GEX_F072_TIMEBASE_H +#endif //GEX_CORE_TIMEBASE_H diff --git a/platform/watchdog.h b/platform/watchdog.h index 8927dfa..717f907 100644 --- a/platform/watchdog.h +++ b/platform/watchdog.h @@ -2,8 +2,8 @@ // Created by MightyPork on 2018/02/27. // -#ifndef GEX_F072_WATCHDOG_H -#define GEX_F072_WATCHDOG_H +#ifndef GEX_CORE_WATCHDOG_H +#define GEX_CORE_WATCHDOG_H /** * Initialize the application watchdog @@ -29,4 +29,4 @@ void wd_resume(void); */ void wd_restart(void); -#endif //GEX_F072_WATCHDOG_H +#endif //GEX_CORE_WATCHDOG_H diff --git a/tasks/task_msg.h b/tasks/task_msg.h index f0a9990..74d0026 100644 --- a/tasks/task_msg.h +++ b/tasks/task_msg.h @@ -5,8 +5,8 @@ // and TinyFrame message handling // -#ifndef GEX_F072_TASK_MSG_H -#define GEX_F072_TASK_MSG_H +#ifndef GEX_CORE_TASK_MSG_H +#define GEX_CORE_TASK_MSG_H #include "platform.h" #include "sched_queue.h" @@ -39,4 +39,4 @@ void rxQuePostMsg(uint8_t *buf, uint32_t len); extern volatile uint32_t msgQueHighWaterMark; #endif -#endif //GEX_F072_TASK_MSG_H +#endif //GEX_CORE_TASK_MSG_H diff --git a/template/nrf_pins.h.txt b/template/nrf_pins.h.txt new file mode 100644 index 0000000..f25136c --- /dev/null +++ b/template/nrf_pins.h.txt @@ -0,0 +1,41 @@ +// +// Definition of nRF24L01+ pin mappings for the platform +// This file may be omitted if SUPPORT_NRF is not set in plat_compat.h +// See rsc_enum.h for the R_ resource constants +// + +#ifndef GEX_NRF_PINS_H +#define GEX_NRF_PINS_H + +#include "platform.h" +#include "rsc_enum.h" + +#define NRF_SPI SPI2 +#define NRF_R_SPI R_SPI2 + +#define NRF_IRQ_Pin LL_GPIO_PIN_15 +#define NRF_IRQ_GPIO_Port GPIOC +#define NRF_R_IRQ R_PC15 +#define NRF_EXTI_LINENUM 15 +#define NRF_SYSCFG_EXTI_PORT LL_SYSCFG_EXTI_PORTC + +#define NRF_NSS_Pin LL_GPIO_PIN_13 +#define NRF_NSS_GPIO_Port GPIOC +#define NRF_R_NSS R_PC13 + +#define NRF_CE_Pin LL_GPIO_PIN_14 +#define NRF_CE_GPIO_Port GPIOC +#define NRF_R_CE R_PC14 + +#define NRF_RST_Pin LL_GPIO_PIN_12 +#define NRF_RST_GPIO_Port GPIOC +#define NRF_R_RST R_PC12 + +#define NRF_R_SCK R_PB13 +#define NRF_SCK_AF LL_GPIO_AF_0 +#define NRF_R_MISO R_PC2 +#define NRF_MISO_AF LL_GPIO_AF_1 +#define NRF_R_MOSI R_PC3 +#define NRF_MOSI_AF LL_GPIO_AF_1 + +#endif //GEX_NRF_PINS_H diff --git a/template/old/FreeRTOSConfig.plat.txt b/template/old/FreeRTOSConfig.plat.txt new file mode 100644 index 0000000..c600bf5 --- /dev/null +++ b/template/old/FreeRTOSConfig.plat.txt @@ -0,0 +1,28 @@ +#if defined(GEX_PLAT_F103_BLUEPILL) || defined(GEX_PLAT_F303_DISCOVERY) \ + || defined(GEX_PLAT_F407_DISCOVERY) + // This is for F103+ + + /* The lowest interrupt priority that can be used in a call to a "set priority" + function. */ + #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 + + #define configPRIO_BITS 4 + + /* The highest interrupt priority that can be used by any interrupt service + routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL + INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER + PRIORITY THAN THIS! (higher priorities are lower numeric values. */ + #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 +#elif defined(STM32F072xB) + // This is for F072 + #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 3 + #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 1 + + #define configPRIO_BITS 2 + + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#else + #error "BAD PLATFORM!!" +#endif diff --git a/template/old/debug_uart.h.txt b/template/old/debug_uart.h.txt new file mode 100644 index 0000000..3710d50 --- /dev/null +++ b/template/old/debug_uart.h.txt @@ -0,0 +1,41 @@ + +#define DEBUG_USART_BAUD 115200 + +#if GEX_PLAT_F072 + + #define DEBUG_USART USART1 + #define DEBUG_USART_RSC R_USART1 + #define DEBUG_USART_PORT 'A' + #define DEBUG_USART_PIN 9 + #define DEBUG_USART_AF 1 + #define DEBUG_USART_PCLK PLAT_APB1_HZ + +#elif GEX_PLAT_F103 + + #define DEBUG_USART USART2 + #define DEBUG_USART_RSC R_USART2 + #define DEBUG_USART_PORT 'A' + #define DEBUG_USART_PIN 2 + #define DEBUG_USART_PCLK PLAT_APB1_HZ + +#elif GEX_PLAT_F303 + + #define DEBUG_USART USART3 + #define DEBUG_USART_RSC R_USART3 + #define DEBUG_USART_PORT 'D' + #define DEBUG_USART_PIN 8 + #define DEBUG_USART_AF 7 + #define DEBUG_USART_PCLK PLAT_APB1_HZ + +#elif GEX_PLAT_F407 + + #define DEBUG_USART USART2 + #define DEBUG_USART_RSC R_USART2 + #define DEBUG_USART_PORT 'A' + #define DEBUG_USART_PIN 2 + #define DEBUG_USART_AF 7 + #define DEBUG_USART_PCLK PLAT_APB1_HZ + +#else + #error "BAD PLATFORM!" +#endif diff --git a/platform/plat_compat.h b/template/old/plat_compat.h.txt similarity index 73% rename from platform/plat_compat.h rename to template/old/plat_compat.h.txt index aeb44f7..7e85322 100644 --- a/platform/plat_compat.h +++ b/template/old/plat_compat.h.txt @@ -5,75 +5,6 @@ #ifndef GEX_PLAT_COMPAT_H #define GEX_PLAT_COMPAT_H -#define VFS_DRIVE_NAME "GEX" - -// -------- Priorities ------------- -#define TSK_MAIN_PRIO osPriorityNormal -#define TSK_JOBS_PRIO osPriorityHigh -#define TSK_TIMERS_PRIO 4 // this must be in the 0-7 range - -// -------- Static buffers --------- -// USB / VFS task stack size -#if DISABLE_MSC - #define TSK_STACK_MAIN 100 // without MSC the stack usage is significantly lower -#else - #define TSK_STACK_MAIN 160 -#endif - -// 180 is normally enough if not doing extensive debug logging -#define TSK_STACK_MSG 220 // TF message handler task stack size (all unit commands run on this thread) -#define TSK_STACK_IDLE 64 //configMINIMAL_STACK_SIZE -#define TSK_STACK_TIMERS 64 //configTIMER_TASK_STACK_DEPTH - -#define PLAT_HEAP_SIZE 4096 - - - -#define BULK_READ_BUF_LEN 256 // Buffer for TF bulk reads -#define UNIT_TMP_LEN 256 // Buffer for internal unit operations - -#define FLASH_SAVE_BUF_LEN 128 // Malloc'd buffer for saving to flash - -#define MSG_QUE_SLOT_SIZE 64 // FIXME this should be possible to lower, but there's some bug with bulk transfer / INI parser -#define RX_QUE_CAPACITY 16 // TinyFrame rx queue size (64 bytes each) - -#define TF_MAX_PAYLOAD_RX 512 // TF max Rx payload -#define TF_SENDBUF_LEN 512 // TF transmit buffer (can be less than a full frame) - -#define TF_MAX_ID_LST 4 // Frame ID listener count -#define TF_MAX_TYPE_LST 6 // Frame Type listener count -#define TF_MAX_GEN_LST 1 // Generic listener count - -#define USBD_MAX_STR_DESC_SIZ 64 // Descriptor conversion buffer (used for converting ASCII to UTF-16, must be 2x the size of the longest descriptor) -#define MSC_MEDIA_PACKET 512 // Mass storage sector size (packet) - -#define INI_KEY_MAX 20 // Ini parser key buffer -#define INI_VALUE_MAX 30 // Ini parser value buffer - -// -------- Stack buffers ---------- -#define DBG_BUF_LEN 100 // Size of the snprintf buffer for debug messages -#define ERR_MSG_STR_LEN 64 // Error message buffer size -#define IWBUFFER_LEN 80 // Ini writer buffer for sprintf - -// -------- Timeouts ------------ -#define TF_PARSER_TIMEOUT_TICKS 100 // Timeout for receiving & parsing a frame -#define BULK_LST_TIMEOUT_MS 2000 // timeout for the bulk transaction to expire -#define MSG_QUE_POST_TIMEOUT 200 // Time to post to the messages / jobs queue - -// -------- Platform specific includes and defines --------- - -/// Feature flags: -// PLAT_FLASHBANKS - has the Banks field on the Flash config struct -// PLAT_NO_FLOATING_INPUTS - can't have digital inputs with no pull resistor -// PLAT_USB_PHYCLOCK - requires special config of phy clock for USB -// PLAT_USB_OTGFS - uses the USB OTG IP, needs different config code -// PLAT_LOCK_BTN - use a lock button instead of a lock jumper (push to toggle) -// PLAT_LOCK_1CLOSED - lock jumper is active (closed / button pressed) in logical 1 -// PLAT_NO_AFNUM - legacy platform without numbered AF alternatives -// PLAT_FULL_XTAL - use two-wire xtal attachment - -// SUPPORT_NRF - #if defined(GEX_PLAT_F103_BLUEPILL) // platform name for the version string diff --git a/template/old/plat_init.c.txt b/template/old/plat_init.c.txt new file mode 100644 index 0000000..751fb21 --- /dev/null +++ b/template/old/plat_init.c.txt @@ -0,0 +1,194 @@ + +#if defined(GEX_PLAT_F103_BLUEPILL) + // Platform STM32F103C8T6 Bluepill ($4 board from eBay) + + // Units supported by the platform (known to work correctly) + + // free all present resources + { + rsc_free_range(NULL, R_ADC1, R_ADC2); + rsc_free_range(NULL, R_I2C1, R_I2C2); + rsc_free_range(NULL, R_SPI1, R_SPI2); + rsc_free_range(NULL, R_TIM1, R_TIM4); + rsc_free_range(NULL, R_USART1, R_USART3); + rsc_free_range(NULL, R_PA0, R_PA15); + rsc_free_range(NULL, R_PB0, R_PB15); + rsc_free_range(NULL, R_PC13, R_PC15); + rsc_free_range(NULL, R_PD0, R_PD1); + } + + // Claim resources not available due to board layout or internal usage + { + // HAL timebase + rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1); + // HSE crystal + rv |= rsc_claim(&UNIT_SYSTEM, R_PD0); + rv |= rsc_claim(&UNIT_SYSTEM, R_PD1); + // SWD + rv |= rsc_claim(&UNIT_SYSTEM, R_PA13); + rv |= rsc_claim(&UNIT_SYSTEM, R_PA14); + // USB + rv |= rsc_claim(&UNIT_SYSTEM, R_PA11); + rv |= rsc_claim(&UNIT_SYSTEM, R_PA12); + // BOOT pin(s) + rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1 + } +#elif defined(STM32F072xB) + // Platform STM32F073RBT + + + // Free all present resources + { + rsc_free(NULL, R_ADC1); +// rsc_free(NULL, R_CAN1); +// rsc_free_range(NULL, R_COMP1, R_COMP2); + rsc_free(NULL, R_DAC1); +// rsc_free(NULL, R_HDMI_CEC); + rsc_free(NULL, R_TSC); + rsc_free_range(NULL, R_I2C1, R_I2C2); +// rsc_free_range(NULL, R_I2S1, R_I2S2); + rsc_free_range(NULL, R_SPI1, R_SPI2); + rsc_free_range(NULL, R_TIM1, R_TIM3); + rsc_free_range(NULL, R_TIM6, R_TIM7); + rsc_free_range(NULL, R_TIM14, R_TIM17); + rsc_free_range(NULL, R_USART1, R_USART4); + rsc_free_range(NULL, R_DMA1_1, R_DMA1_7); + + rsc_free_range(NULL, R_PA0, R_PA15); + rsc_free_range(NULL, R_PB0, R_PB15); + rsc_free_range(NULL, R_PC0, R_PC15); + rsc_free(NULL, R_PD2); + rsc_free_range(NULL, R_PF0, R_PF1); + } + + // Claim resources not available due to board layout or internal usage + { + // HAL timebase + rv |= rsc_claim(&UNIT_SYSTEM, R_TIM17); + // HSE crystal + rv |= rsc_claim(&UNIT_SYSTEM, R_PF0); + + #if PLAT_FULL_XTAL + rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode + #endif + + // SWD +// rv |= rsc_claim(&UNIT_SYSTEM, R_PA13); +// rv |= rsc_claim(&UNIT_SYSTEM, R_PA14); + // USB + rv |= rsc_claim(&UNIT_SYSTEM, R_PA11); + rv |= rsc_claim(&UNIT_SYSTEM, R_PA12); + + #if defined(GEX_PLAT_F072_ZERO) + // unconnected pins + rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC0, R_PC1); + rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC4, R_PC9); + #endif + } +#elif defined(GEX_PLAT_F303_DISCOVERY) + // Platform STM32F303VCT + + // Additional GPIO ports + __HAL_RCC_GPIOF_CLK_ENABLE(); + + // Units supported by the platform (known to work correctly) + // ureg_add_type(&UNIT_XYZ); + + // Free all present resources + { + rsc_free_range(NULL, R_ADC1, R_ADC4); +// rsc_free(NULL, R_CAN1); +// rsc_free_range(NULL, R_COMP1, R_COMP7); +// rsc_free(NULL, R_HDMI_CEC); + rsc_free(NULL, R_DAC1); + rsc_free_range(NULL, R_I2C1, R_I2C2); + rsc_free_range(NULL, R_I2S2, R_I2S3); +// rsc_free_range(NULL, R_OPAMP1, R_OPAMP4); + rsc_free_range(NULL, R_SPI1, R_SPI3); + rsc_free_range(NULL, R_TIM1, R_TIM4); + rsc_free_range(NULL, R_TIM6, R_TIM8); + rsc_free_range(NULL, R_TIM15, R_TIM17); + rsc_free(NULL, R_TSC); + rsc_free_range(NULL, R_USART1, R_USART5); + + rsc_free_range(NULL, R_PA0, R_PA15); + rsc_free_range(NULL, R_PB0, R_PB15); + rsc_free_range(NULL, R_PC0, R_PC15); + rsc_free_range(NULL, R_PD0, R_PD15); + rsc_free_range(NULL, R_PE0, R_PE15); + + rsc_free_range(NULL, R_PF0, R_PF2); + rsc_free(NULL, R_PF4); + rsc_free_range(NULL, R_PF9, R_PF10); + } + + // Claim resources not available due to board layout or internal usage + { + // HAL timebase + rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1); + // HSE crystal + rv |= rsc_claim(&UNIT_SYSTEM, R_PF0); + //rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode + // SWD + rv |= rsc_claim(&UNIT_SYSTEM, R_PA13); + rv |= rsc_claim(&UNIT_SYSTEM, R_PA14); + // USB + rv |= rsc_claim(&UNIT_SYSTEM, R_PA11); + rv |= rsc_claim(&UNIT_SYSTEM, R_PA12); + // BOOT pin(s) + rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1 + } +#elif defined(GEX_PLAT_F407_DISCOVERY) + // Platform STM32F407VGT + + // Additional GPIO ports + __HAL_RCC_GPIOF_CLK_ENABLE(); + + // Units supported by the platform (known to work correctly) + // ureg_add_type(&UNIT_XYZ); + + // Free all present resources + { + rsc_free_range(NULL, R_ADC1, R_ADC3); +// rsc_free_range(NULL, R_CAN1, R_CAN2); +// rsc_free_range(NULL, R_COMP1, R_COMP7); + rsc_free(NULL, R_DAC1); +// rsc_free(NULL, R_DCMI); +// rsc_free(NULL, R_ETH); +// rsc_free(NULL, R_FSMC); + rsc_free_range(NULL, R_I2C1, R_I2C3); + rsc_free_range(NULL, R_I2S2, R_I2S3); +// rsc_free(NULL, R_SDIO); + rsc_free_range(NULL, R_SPI1, R_SPI3); + rsc_free_range(NULL, R_TIM1, R_TIM14); + rsc_free_range(NULL, R_USART1, R_USART3); + rsc_free(NULL, R_USART6); + + rsc_free_range(NULL, R_PA0, R_PA15); + rsc_free_range(NULL, R_PB0, R_PB15); + rsc_free_range(NULL, R_PC0, R_PC15); + rsc_free_range(NULL, R_PD0, R_PD15); + rsc_free_range(NULL, R_PE0, R_PE15); + // also has 2 PH pins + + // F407 appears to have fewer GPIOs than F303? + } + + // Claim resources not available due to board layout or internal usage + { + // HAL timebase + rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1); + // HSE crystal + // H0 and H1 + // SWD + rv |= rsc_claim(&UNIT_SYSTEM, R_PA13); + rv |= rsc_claim(&UNIT_SYSTEM, R_PA14); + // USB + rv |= rsc_claim(&UNIT_SYSTEM, R_PA11); + rv |= rsc_claim(&UNIT_SYSTEM, R_PA12); + // BOOT pin(s) + rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1 + } +#else + #error "BAD PLATFORM!" +#endif diff --git a/template/plat_compat.h.txt b/template/plat_compat.h.txt new file mode 100644 index 0000000..2e4e222 --- /dev/null +++ b/template/plat_compat.h.txt @@ -0,0 +1,46 @@ +#ifndef GEX_PLAT_COMPAT_H +#define GEX_PLAT_COMPAT_H + +// string identifying the GEX board +#define GEX_PLATFORM "Discovery-XYZ" +#define GEX_PLAT_XYZ 1 // only with the MCU name + +// GEX_PLAT_XYZ_BOARD is defined in build.mk to identify particular board layout + +#define PLAT_AHB_MHZ 72 +#define PLAT_APB1_MHZ 36 + +#include ... // all useful from the peripheral library (HAL / LL) + +// in bytes +#define FLASH_SIZE (128*1024) +// in bytes +#define SETTINGS_BLOCK_SIZE (2*1024) +// address where the settings block starts +#define SETTINGS_FLASH_ADDR (0x08000000 + FLASH_SIZE - SETTINGS_BLOCK_SIZE) + +#define PORTS_COUNT 5 // number of available GPIO ports A,B,C,D,E,F... +#define LOCK_JUMPER_PORT 'A' +#define LOCK_JUMPER_PIN 2 + +#define STATUS_LED_PORT 'A' +#define STATUS_LED_PIN 15 + +// Feature flags: +#define PLAT_FLASHBANKS 0 // has the Banks field on the Flash config struct +#define PLAT_NO_FLOATING_INPUTS 0 // can't have digital inputs with no pull resistor +#define PLAT_USB_PHYCLOCK 0 // requires special config of phy clock for USB +#define PLAT_USB_OTGFS 0 // uses the USB OTG IP, needs different config code +#define PLAT_LOCK_BTN 1 // use a lock button instead of a lock jumper (push to toggle) +#define PLAT_LOCK_1CLOSED 1 // lock jumper is active (closed / button pressed) in logical 1 +#define PLAT_NO_AFNUM 0 // legacy platform without numbered AF alternatives +#define PLAT_FULL_XTAL 1 // use two-wire xtal attachment +#define PLAT_USB_PU_CTL 1 // platform has USB pullup control + +// FreeRTOS config +#define PLAT_FREERTOS_LOWEST_INTERRUPT_PRIORITY 3 +#define PLAT_FREERTOS_MAX_SYSCALL_INTERRUPT_PRIORITY 1 +#define PLAT_FREERTOS_PRIO_BITS 2 +#define PLAT_FREERTOS_USE_PORT_OPTIMISED_TASK_SELECTION 0 + +#endif //GEX_PLAT_COMPAT_H diff --git a/template/template_unit.zip b/template/template_unit.zip new file mode 100644 index 0000000000000000000000000000000000000000..b63157bc0b7705dd8024fd171e5f41f2f3354caa GIT binary patch literal 4028 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 literal 0 HcmV?d00001