Browse Source

clean up for porting - move platform specific stuff into outer project

Ondřej Hruška 1 year ago
parent
commit
20639b77a6
Signed by: Ondřej Hruška <ondra@ondrovo.com> GPG key ID: 2C5FD5035250423D

+ 6 - 28
FreeRTOSConfig.h View File

@@ -90,6 +90,7 @@
90 90
 #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
91 91
     #include <stdint.h>
92 92
     #include "main.h"
93
+    #include "plat_config.h"
93 94
     #include "plat_compat.h"
94 95
 extern uint32_t SystemCoreClock;
95 96
 #endif
@@ -134,34 +135,11 @@ to exclude the API function. */
134 135
 
135 136
 ///* Cortex-M specific definitions. */
136 137
 
137
-#if defined(GEX_PLAT_F103_BLUEPILL) || defined(GEX_PLAT_F303_DISCOVERY) \
138
-    || defined(GEX_PLAT_F407_DISCOVERY)
139
-    // This is for F103+
140
-
141
-    /* The lowest interrupt priority that can be used in a call to a "set priority"
142
-    function. */
143
-    #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   15
144
-
145
-    #define configPRIO_BITS         4
146
-
147
-    /* The highest interrupt priority that can be used by any interrupt service
148
-    routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
149
-    INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
150
-    PRIORITY THAN THIS! (higher priorities are lower numeric values. */
151
-    #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
152
-
153
-    #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
154
-#elif defined(STM32F072xB)
155
-    // This is for F072
156
-    #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   3
157
-    #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 1
158
-
159
-    #define configPRIO_BITS         2
160
-
161
-    #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
162
-#else
163
-    #error "BAD PLATFORM!!"
164
-#endif
138
+// These are defined in plat_compat.h:
139
+#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY  PLAT_FREERTOS_LOWEST_INTERRUPT_PRIORITY
140
+#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY  PLAT_FREERTOS_MAX_SYSCALL_INTERRUPT_PRIORITY
141
+#define configPRIO_BITS  PLAT_FREERTOS_PRIO_BITS
142
+#define configUSE_PORT_OPTIMISED_TASK_SELECTION  PLAT_FREERTOS_USE_PORT_OPTIMISED_TASK_SELECTION
165 143
 
166 144
 /* Interrupt priorities used by the kernel port layer itself.  These are generic
167 145
 to all Cortex-M ports, and do not rely on any particular library functions. */

+ 7 - 6
USB/usbd_conf.c View File

@@ -84,13 +84,14 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
84 84
     __HAL_RCC_USB_CLK_ENABLE();
85 85
 
86 86
     /* Peripheral interrupt init */
87
-#if GEX_PLAT_F103_BLUEPILL
87
+    // TODO convert this to feature flags if possible - avoid tying to particular platforms
88
+#if GEX_PLAT_F103
88 89
     HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 5, 0);
89 90
     HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
90
-#elif STM32F072xB
91
+#elif GEX_PLAT_F072
91 92
     HAL_NVIC_SetPriority(USB_IRQn, 3, 0);
92 93
     HAL_NVIC_EnableIRQ(USB_IRQn);
93
-#elif GEX_PLAT_F303_DISCOVERY
94
+#elif GEX_PLAT_F303
94 95
     // Pins need to be configured here
95 96
 
96 97
     /**USB GPIO Configuration
@@ -149,11 +150,11 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
149 150
     __HAL_RCC_USB_CLK_DISABLE();
150 151
 
151 152
     /* Peripheral interrupt Deinit*/
152
-#if GEX_PLAT_F103_BLUEPILL
153
+#if GEX_PLAT_F103
153 154
     HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
154
-#elif STM32F072xB
155
+#elif GEX_PLAT_F072
155 156
     HAL_NVIC_DisableIRQ(USB_IRQn);
156
-#elif GEX_PLAT_F303_DISCOVERY
157
+#elif GEX_PLAT_F303
157 158
     HAL_NVIC_DisableIRQ(USB_LP_CAN_RX0_IRQn);
158 159
 #else
159 160
   #error "BAD PLATFORM"

+ 3 - 3
comm/event_reports.h View File

@@ -2,8 +2,8 @@
2 2
 // Created by MightyPork on 2018/01/27.
3 3
 //
4 4
 
5
-#ifndef GEX_F072_EVENT_REPORTS_H
6
-#define GEX_F072_EVENT_REPORTS_H
5
+#ifndef GEX_CORE_EVENT_REPORTS_H
6
+#define GEX_CORE_EVENT_REPORTS_H
7 7
 
8 8
 #ifndef GEX_MESSAGES_H
9 9
 #error "Include messages.h instead!"
@@ -31,4 +31,4 @@ void EventReport_Data(const uint8_t *buff, uint16_t len);
31 31
 void EventReport_PB(PayloadBuilder *pb);
32 32
 void EventReport_End(void);
33 33
 
34
-#endif //GEX_F072_EVENT_REPORTS_H
34
+#endif //GEX_CORE_EVENT_REPORTS_H

+ 3 - 1
comm/iface_nordic.c View File

@@ -2,6 +2,9 @@
2 2
 // Created by MightyPork on 2018/04/06.
3 3
 //
4 4
 
5
+#include "platform.h"
6
+#if SUPPORT_NRF
7
+
5 8
 #include "iface_nordic.h"
6 9
 #include "nrf_pins.h"
7 10
 #include "resources.h"
@@ -11,7 +14,6 @@
11 14
 #include "system_settings.h"
12 15
 #include "utils/hexdump.h"
13 16
 
14
-#if SUPPORT_NRF
15 17
 
16 18
 extern osSemaphoreId semVcomTxReadyHandle;
17 19
 

+ 3 - 4
comm/iface_nordic.h View File

@@ -2,11 +2,10 @@
2 2
 // Created by MightyPork on 2018/04/06.
3 3
 //
4 4
 
5
-#ifndef GEX_F072_IFACE_NORDIC_H
6
-#define GEX_F072_IFACE_NORDIC_H
5
+#ifndef GEX_CORE_IFACE_NORDIC_H
6
+#define GEX_CORE_IFACE_NORDIC_H
7 7
 
8 8
 #include "platform.h"
9
-
10 9
 #if SUPPORT_NRF
11 10
 
12 11
 void iface_nordic_claim_resources(void);
@@ -21,4 +20,4 @@ void iface_nordic_transmit(const uint8_t *buff, uint32_t len);
21 20
 
22 21
 #endif // SUPPORT_NRF
23 22
 
24
-#endif //GEX_F072_IFACE_NORDIC_H
23
+#endif //GEX_CORE_IFACE_NORDIC_H

+ 3 - 3
comm/iface_uart.h View File

@@ -2,8 +2,8 @@
2 2
 // Created by MightyPork on 2018/04/06.
3 3
 //
4 4
 
5
-#ifndef GEX_F072_IFACE_UART_H
6
-#define GEX_F072_IFACE_UART_H
5
+#ifndef GEX_CORE_IFACE_UART_H
6
+#define GEX_CORE_IFACE_UART_H
7 7
 
8 8
 #include "platform.h"
9 9
 
@@ -17,4 +17,4 @@ void iface_uart_claim_resources(void);
17 17
 
18 18
 void iface_uart_transmit(const uint8_t *buff, uint32_t len);
19 19
 
20
-#endif //GEX_F072_IFACE_UART_H
20
+#endif //GEX_CORE_IFACE_UART_H

+ 3 - 3
comm/iface_usb.h View File

@@ -2,8 +2,8 @@
2 2
 // Created by MightyPork on 2018/04/06.
3 3
 //
4 4
 
5
-#ifndef GEX_F072_IFACE_USB_H
6
-#define GEX_F072_IFACE_USB_H
5
+#ifndef GEX_CORE_IFACE_USB_H
6
+#define GEX_CORE_IFACE_USB_H
7 7
 
8 8
 #include "platform.h"
9 9
 
@@ -17,4 +17,4 @@ bool iface_usb_ready(void);
17 17
  */
18 18
 void iface_usb_transmit(const uint8_t *buff, uint32_t len);
19 19
 
20
-#endif //GEX_F072_IFACE_USB_H
20
+#endif //GEX_CORE_IFACE_USB_H

+ 3 - 3
comm/interfaces.h View File

@@ -2,8 +2,8 @@
2 2
 // Created by MightyPork on 2018/03/23.
3 3
 //
4 4
 
5
-#ifndef GEX_F072_COM_INTERFACES_H
6
-#define GEX_F072_COM_INTERFACES_H
5
+#ifndef GEX_CORE_COM_INTERFACES_H
6
+#define GEX_CORE_COM_INTERFACES_H
7 7
 
8 8
 #include "platform.h"
9 9
 
@@ -34,4 +34,4 @@ void com_release_resources_for_alt_transfers(void);
34 34
 /** Flush the rx buffer */
35 35
 void com_iface_flush_buffer(void);
36 36
 
37
-#endif //GEX_F072_COM_INTERFACES_H
37
+#endif //GEX_CORE_COM_INTERFACES_H

+ 3 - 3
comm/msg_bulkread.h View File

@@ -4,8 +4,8 @@
4 4
 // Bulk read (providing data for bulk read by the PC)
5 5
 //
6 6
 
7
-#ifndef GEX_F072_MSG_BULKREAD_H
8
-#define GEX_F072_MSG_BULKREAD_H
7
+#ifndef GEX_CORE_MSG_BULKREAD_H
8
+#define GEX_CORE_MSG_BULKREAD_H
9 9
 
10 10
 #ifndef GEX_MESSAGES_H
11 11
 #error "Include messages.h instead!"
@@ -45,4 +45,4 @@ struct bulk_read {
45 45
 void bulkread_start(TinyFrame *tf, BulkRead *bulk);
46 46
 
47 47
 
48
-#endif //GEX_F072_MSG_BULKREAD_H
48
+#endif //GEX_CORE_MSG_BULKREAD_H

+ 3 - 3
comm/msg_bulkwrite.h View File

@@ -4,8 +4,8 @@
4 4
 // Bulk write (receiving bulk write from the PC)
5 5
 //
6 6
 
7
-#ifndef GEX_F072_MSG_BULKWRITE_H
8
-#define GEX_F072_MSG_BULKWRITE_H
7
+#ifndef GEX_CORE_MSG_BULKWRITE_H
8
+#define GEX_CORE_MSG_BULKWRITE_H
9 9
 
10 10
 #ifndef GEX_MESSAGES_H
11 11
 #error "Include messages.h instead!"
@@ -44,4 +44,4 @@ struct bulk_write {
44 44
 void bulkwrite_start(TinyFrame *tf, BulkWrite *bulk);
45 45
 
46 46
 
47
-#endif //GEX_F072_MSG_BULKWRITE_H
47
+#endif //GEX_CORE_MSG_BULKWRITE_H

+ 3 - 3
comm/msg_responses.h View File

@@ -4,8 +4,8 @@
4 4
 // Routines for sending TinyFrame responses.
5 5
 //
6 6
 
7
-#ifndef GEX_F072_MSG_RESPONSES_H
8
-#define GEX_F072_MSG_RESPONSES_H
7
+#ifndef GEX_CORE_MSG_RESPONSES_H
8
+#define GEX_CORE_MSG_RESPONSES_H
9 9
 
10 10
 #ifndef GEX_MESSAGES_H
11 11
 #error "Include messages.h instead!"
@@ -109,4 +109,4 @@ void com_respond_u16(TF_ID frame_id, uint16_t d);
109 109
  */
110 110
 void com_respond_u32(TF_ID frame_id, uint32_t d);
111 111
 
112
-#endif //GEX_F072_MSG_RESPONSES_H
112
+#endif //GEX_CORE_MSG_RESPONSES_H

+ 4 - 0
comm/nrf.c View File

@@ -3,6 +3,8 @@
3 3
 //
4 4
 
5 5
 #include "platform.h"
6
+#if SUPPORT_NRF
7
+
6 8
 #include "nrf.h"
7 9
 
8 10
 /**
@@ -545,3 +547,5 @@ bool NRF_Init(uint8_t pSpeed)
545 547
 
546 548
     return true;
547 549
 }
550
+
551
+#endif

+ 3 - 5
comm/nrf.h View File

@@ -15,11 +15,9 @@
15 15
  *
16 16
  */
17 17
 
18
-
19
-#ifndef NORDIC_H_
20
-#define NORDIC_H_
21
-
22 18
 #include "platform.h"
19
+#if SUPPORT_NRF
20
+
23 21
 #include "resources.h"
24 22
 #include "nrf_pins.h"
25 23
 
@@ -160,6 +158,6 @@ void NRF_EnablePipe(uint8_t pipenum);
160 158
  */
161 159
 void NRF_DisablePipe(uint8_t pipenum);
162 160
 
163
-#endif /* NORDIC_H_ */
161
+#endif // SUPPORT_NRF
164 162
 
165 163
 #endif //GEX_NRF_NRF_H

+ 0 - 75
comm/nrf_pins.h View File

@@ -1,75 +0,0 @@
1
-//
2
-// Created by MightyPork on 2018/04/06.
3
-//
4
-
5
-#ifndef GEX_F072_NRF_PINS_H
6
-#define GEX_F072_NRF_PINS_H
7
-
8
-#include "platform.h"
9
-
10
-#if defined(GEX_PLAT_F072_DISCOVERY) || defined(GEX_PLAT_F072_HUB)
11
-
12
-    // This config was used only for development when NRF was enabled for those platforms. It is normally disabled.
13
-    #define NRF_SPI            SPI1
14
-    #define NRF_R_SPI          R_SPI1
15
-
16
-    #define NRF_IRQ_Pin        LL_GPIO_PIN_10
17
-    #define NRF_IRQ_GPIO_Port  GPIOB
18
-    #define NRF_R_IRQ          R_PB10
19
-    #define NRF_EXTI_LINENUM   10
20
-    #define NRF_SYSCFG_EXTI_PORT LL_SYSCFG_EXTI_PORTB
21
-
22
-    #define NRF_NSS_Pin        LL_GPIO_PIN_11
23
-    #define NRF_NSS_GPIO_Port  GPIOB
24
-    #define NRF_R_NSS          R_PB11
25
-
26
-    #define NRF_CE_Pin         LL_GPIO_PIN_12
27
-    #define NRF_CE_GPIO_Port   GPIOB
28
-    #define NRF_R_CE           R_PB12
29
-
30
-    #define NRF_RST_Pin        LL_GPIO_PIN_13
31
-    #define NRF_RST_GPIO_Port  GPIOB
32
-    #define NRF_R_RST          R_PB13
33
-
34
-    #define NRF_R_SCK          R_PA5
35
-    #define NRF_SCK_AF         LL_GPIO_AF_0
36
-    #define NRF_R_MISO         R_PA6
37
-    #define NRF_MISO_AF        LL_GPIO_AF_0
38
-    #define NRF_R_MOSI         R_PA7
39
-    #define NRF_MOSI_AF        LL_GPIO_AF_0
40
-
41
-#elif defined(GEX_PLAT_F072_ZERO)
42
-
43
-    #define NRF_SPI            SPI2
44
-    #define NRF_R_SPI          R_SPI2
45
-
46
-    #define NRF_IRQ_Pin        LL_GPIO_PIN_15
47
-    #define NRF_IRQ_GPIO_Port  GPIOC
48
-    #define NRF_R_IRQ          R_PC15
49
-    #define NRF_EXTI_LINENUM   15
50
-    #define NRF_SYSCFG_EXTI_PORT LL_SYSCFG_EXTI_PORTC
51
-
52
-    #define NRF_NSS_Pin        LL_GPIO_PIN_13
53
-    #define NRF_NSS_GPIO_Port  GPIOC
54
-    #define NRF_R_NSS          R_PC13
55
-
56
-    #define NRF_CE_Pin         LL_GPIO_PIN_14
57
-    #define NRF_CE_GPIO_Port   GPIOC
58
-    #define NRF_R_CE           R_PC14
59
-
60
-    #define NRF_RST_Pin        LL_GPIO_PIN_12
61
-    #define NRF_RST_GPIO_Port  GPIOC
62
-    #define NRF_R_RST          R_PC12
63
-
64
-    #define NRF_R_SCK          R_PB13
65
-    #define NRF_SCK_AF         LL_GPIO_AF_0
66
-    #define NRF_R_MISO         R_PC2
67
-    #define NRF_MISO_AF        LL_GPIO_AF_1
68
-    #define NRF_R_MOSI         R_PC3
69
-    #define NRF_MOSI_AF        LL_GPIO_AF_1
70
-
71
-#else
72
-    #error "Missing NRF config for this platform."
73
-#endif
74
-
75
-#endif //GEX_F072_NRF_PINS_H

+ 3 - 3
framework/rsc_enum.h View File

@@ -4,8 +4,8 @@
4 4
 // Enum of all defined resources
5 5
 //
6 6
 
7
-#ifndef GEX_F072_RSC_ENUM_H
8
-#define GEX_F072_RSC_ENUM_H
7
+#ifndef GEX_CORE_RSC_ENUM_H
8
+#define GEX_CORE_RSC_ENUM_H
9 9
 
10 10
 // X macro: Resource name,
11 11
 #define XX_RESOURCES \
@@ -132,4 +132,4 @@ static inline void rscmap_free(ResourceMap *rscmap, Resource rsc)
132 132
 #define RSC_CLAIM(rscmap, rsc)   rscmap_claim(&rscmap, (rsc))
133 133
 #define RSC_FREE(rscmap, rsc)    rscmap_free(&rscmap, (rsc))
134 134
 
135
-#endif //GEX_F072_RSC_ENUM_H
135
+#endif //GEX_CORE_RSC_ENUM_H

+ 2 - 1
framework/settings.c View File

@@ -110,7 +110,7 @@ void settings_save(void)
110 110
         erase.Banks = FLASH_BANK_1; // TODO ?????
111 111
 #endif
112 112
 
113
-#if defined(GEX_PLAT_F407_DISCOVERY)
113
+#if GEX_PLAT_F407
114 114
         // specialty for F4 with too much flash
115 115
         erase.NbSectors = 1;
116 116
         erase.Sector = SETTINGS_FLASH_SECTOR;
@@ -122,6 +122,7 @@ void settings_save(void)
122 122
         erase.PageAddress = SETTINGS_FLASH_ADDR;
123 123
         erase.TypeErase = FLASH_TYPEERASE_PAGES;
124 124
 #endif
125
+
125 126
         uint32_t pgerror = 0;
126 127
         hst = HAL_FLASHEx_Erase(&erase, &pgerror);
127 128
         assert_param(pgerror == 0xFFFFFFFFU);

+ 2 - 1
gex.mk View File

@@ -83,7 +83,8 @@ GEX_C_FILES = \
83 83
     GexCore/USB/STM32_USB_Device_Library/Class/MSC_CDC/usbd_msc_cdc.c \
84 84
     GexCore/USB/STM32_USB_Device_Library/Core/Src/usbd_core.c \
85 85
     GexCore/USB/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \
86
-    GexCore/USB/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
86
+    GexCore/USB/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \
87
+    Src/platform_resources.c
87 88
 
88 89
 GEX_C_INCLUDES = \
89 90
     -IGexUnits \

+ 3 - 3
platform/cfg_utils.h View File

@@ -2,8 +2,8 @@
2 2
 // Created by MightyPork on 2018/02/23.
3 3
 //
4 4
 
5
-#ifndef GEX_F072_CFG_UTILS_H
6
-#define GEX_F072_CFG_UTILS_H
5
+#ifndef GEX_CORE_CFG_UTILS_H
6
+#define GEX_CORE_CFG_UTILS_H
7 7
 
8 8
 #include "platform.h"
9 9
 #include "rsc_enum.h"
@@ -162,4 +162,4 @@ static inline int32_t cfg_i32_parse(const char *value, bool *suc)
162 162
     return (int32_t) avr_atoi(value);
163 163
 }
164 164
 
165
-#endif //GEX_F072_CFG_UTILS_H
165
+#endif //GEX_CORE_CFG_UTILS_H

+ 0 - 43
platform/debug_uart.c View File

@@ -5,54 +5,11 @@
5 5
 #include "platform.h"
6 6
 #include "framework/resources.h"
7 7
 #include "debug_uart.h"
8
-#include "plat_compat.h"
9 8
 #include "hw_utils.h"
10 9
 #include "framework/system_settings.h"
11 10
 
12 11
 #if USE_DEBUG_UART
13 12
 
14
-#define DEBUG_USART_BAUD 115200
15
-
16
-#if GEX_PLAT_F072_DISCOVERY || GEX_PLAT_F072_HUB || GEX_PLAT_F072_ZERO
17
-
18
-    #define DEBUG_USART USART1
19
-    #define DEBUG_USART_RSC R_USART1
20
-    #define DEBUG_USART_PORT 'A'
21
-    #define DEBUG_USART_PIN  9
22
-    #define DEBUG_USART_AF  1
23
-    #define DEBUG_USART_PCLK PLAT_APB1_HZ
24
-
25
-#elif GEX_PLAT_F103_BLUEPILL
26
-
27
-    #define DEBUG_USART USART2
28
-    #define DEBUG_USART_RSC R_USART2
29
-    #define DEBUG_USART_PORT 'A'
30
-    #define DEBUG_USART_PIN  2
31
-    #define DEBUG_USART_PCLK PLAT_APB1_HZ
32
-
33
-#elif GEX_PLAT_F303_DISCOVERY
34
-
35
-    #define DEBUG_USART USART3
36
-    #define DEBUG_USART_RSC R_USART3
37
-    #define DEBUG_USART_PORT 'D'
38
-    #define DEBUG_USART_PIN  8
39
-    #define DEBUG_USART_AF  7
40
-    #define DEBUG_USART_PCLK PLAT_APB1_HZ
41
-
42
-#elif GEX_PLAT_F407_DISCOVERY
43
-
44
-    #define DEBUG_USART USART2
45
-    #define DEBUG_USART_RSC R_USART2
46
-    #define DEBUG_USART_PORT 'A'
47
-    #define DEBUG_USART_PIN  2
48
-    #define DEBUG_USART_AF  7
49
-    #define DEBUG_USART_PCLK PLAT_APB1_HZ
50
-
51
-#else
52
-    #error "BAD PLATFORM!"
53
-#endif
54
-
55
-
56 13
 static bool debug_uart_inited = false;
57 14
 static bool debug_uart_preinited = false;
58 15
 

+ 3 - 3
platform/irq_dispatcher.h View File

@@ -4,8 +4,8 @@
4 4
 // Provides a trampoline system for redirecting IRQ calls to assigned callbacks.
5 5
 //
6 6
 
7
-#ifndef GEX_F072_IRQ_DISPATCHER_H
8
-#define GEX_F072_IRQ_DISPATCHER_H
7
+#ifndef GEX_CORE_IRQ_DISPATCHER_H
8
+#define GEX_CORE_IRQ_DISPATCHER_H
9 9
 
10 10
 // Dummy peripherals for use with the
11 11
 extern void * const EXTIS[16];
@@ -42,4 +42,4 @@ void irqd_attach(void *periph, IrqCallback callback, void *data);
42 42
  */
43 43
 void* irqd_detach(void *periph, IrqCallback callback);
44 44
 
45
-#endif //GEX_F072_IRQ_DISPATCHER_H
45
+#endif //GEX_CORE_IRQ_DISPATCHER_H

+ 3 - 3
platform/ll_extension.h View File

@@ -2,8 +2,8 @@
2 2
 // Created by MightyPork on 2018/02/04.
3 3
 //
4 4
 
5
-#ifndef GEX_F072_LL_EXTENSION_H
6
-#define GEX_F072_LL_EXTENSION_H
5
+#ifndef GEX_CORE_LL_EXTENSION_H
6
+#define GEX_CORE_LL_EXTENSION_H
7 7
 
8 8
 #include "platform.h"
9 9
 
@@ -57,4 +57,4 @@ static inline void LL_DMA_ClearFlags(DMA_TypeDef *DMAx, uint8_t channel)
57 57
 }
58 58
 
59 59
 
60
-#endif //GEX_F072_LL_EXTENSION_H
60
+#endif //GEX_CORE_LL_EXTENSION_H

+ 0 - 2
platform/lock_jumper.h View File

@@ -7,8 +7,6 @@
7 7
 #ifndef GEX_LOCK_JUMPER_H
8 8
 #define GEX_LOCK_JUMPER_H
9 9
 
10
-#include "plat_compat.h"
11
-
12 10
 /**
13 11
  * Init the lock jumper subsystem
14 12
  */

+ 64 - 0
platform/plat_config.h View File

@@ -0,0 +1,64 @@
1
+//
2
+// Created by MightyPork on 2018/07/07.
3
+//
4
+
5
+#ifndef GEX_CORE_PLAT_CONFIG_H
6
+#define GEX_CORE_PLAT_CONFIG_H
7
+
8
+#define VFS_DRIVE_NAME "GEX"
9
+
10
+// -------- Priorities -------------
11
+#define TSK_MAIN_PRIO osPriorityNormal
12
+#define TSK_JOBS_PRIO osPriorityHigh
13
+#define TSK_TIMERS_PRIO 4 // this must be in the 0-7 range
14
+
15
+// -------- Static buffers ---------
16
+// USB / VFS task stack size
17
+#if DISABLE_MSC
18
+#define TSK_STACK_MAIN      100 // without MSC the stack usage is significantly lower
19
+#else
20
+#define TSK_STACK_MAIN      160
21
+#endif
22
+
23
+// 180 is normally enough if not doing extensive debug logging
24
+#define TSK_STACK_MSG       220 // TF message handler task stack size (all unit commands run on this thread)
25
+#define TSK_STACK_IDLE    64 //configMINIMAL_STACK_SIZE
26
+#define TSK_STACK_TIMERS  64 //configTIMER_TASK_STACK_DEPTH
27
+
28
+#define PLAT_HEAP_SIZE 4096
29
+
30
+
31
+
32
+#define BULK_READ_BUF_LEN 256   // Buffer for TF bulk reads
33
+#define UNIT_TMP_LEN      256   // Buffer for internal unit operations
34
+
35
+#define FLASH_SAVE_BUF_LEN  128 // Malloc'd buffer for saving to flash
36
+
37
+#define MSG_QUE_SLOT_SIZE 64 // FIXME this should be possible to lower, but there's some bug with bulk transfer / INI parser
38
+#define RX_QUE_CAPACITY    16 // TinyFrame rx queue size (64 bytes each)
39
+
40
+#define TF_MAX_PAYLOAD_RX 512 // TF max Rx payload
41
+#define TF_SENDBUF_LEN    512 // TF transmit buffer (can be less than a full frame)
42
+
43
+#define TF_MAX_ID_LST   4 // Frame ID listener count
44
+#define TF_MAX_TYPE_LST 6 // Frame Type listener count
45
+#define TF_MAX_GEN_LST  1 // Generic listener count
46
+
47
+#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)
48
+#define MSC_MEDIA_PACKET       512 // Mass storage sector size (packet)
49
+
50
+#define INI_KEY_MAX    20 // Ini parser key buffer
51
+#define INI_VALUE_MAX  30 // Ini parser value buffer
52
+
53
+// -------- Stack buffers ----------
54
+#define DBG_BUF_LEN      100 // Size of the snprintf buffer for debug messages
55
+#define ERR_MSG_STR_LEN  64 // Error message buffer size
56
+#define IWBUFFER_LEN     80 // Ini writer buffer for sprintf
57
+
58
+// -------- Timeouts ------------
59
+#define TF_PARSER_TIMEOUT_TICKS 100 // Timeout for receiving & parsing a frame
60
+#define BULK_LST_TIMEOUT_MS     2000 // timeout for the bulk transaction to expire
61
+#define MSG_QUE_POST_TIMEOUT    200 // Time to post to the messages / jobs queue
62
+
63
+
64
+#endif //GEX_CORE_PLAT_CONFIG_H

+ 6 - 208
platform/platform.c View File

@@ -12,6 +12,8 @@
12 12
 
13 13
 #include "units_manifest.h"
14 14
 
15
+extern uint32_t plat_init_resources2(void);
16
+
15 17
 // TODO split this and the plat_compat files to per-platform ones stored in the platform project
16 18
 
17 19
 void plat_init_resources(void)
@@ -26,217 +28,16 @@ void plat_init_resources(void)
26 28
     hw_periph_clock_enable(DMA2);
27 29
 #endif
28 30
 
29
-    // --- Common unit drivers ---
30
-
31
-    #if HAVE_TEST_UNIT
32
-        ureg_add_type(&UNIT_TEST);
33
-    #endif
34
-
35 31
     // EXTI are always available
36 32
     rsc_free_range(NULL, R_EXTI0, R_EXTI15);
37 33
 
38 34
     // --- platform specific resource releases and claims ---
39 35
 
40
-#if defined(GEX_PLAT_F103_BLUEPILL)
41
-    // Platform STM32F103C8T6 Bluepill ($4 board from eBay)
42
-
43
-    // Units supported by the platform (known to work correctly)
44
-
45
-    // free all present resources
46
-    {
47
-        rsc_free_range(NULL, R_ADC1, R_ADC2);
48
-        rsc_free_range(NULL, R_I2C1, R_I2C2);
49
-        rsc_free_range(NULL, R_SPI1, R_SPI2);
50
-        rsc_free_range(NULL, R_TIM1, R_TIM4);
51
-        rsc_free_range(NULL, R_USART1, R_USART3);
52
-        rsc_free_range(NULL, R_PA0, R_PA15);
53
-        rsc_free_range(NULL, R_PB0, R_PB15);
54
-        rsc_free_range(NULL, R_PC13, R_PC15);
55
-        rsc_free_range(NULL, R_PD0, R_PD1);
56
-    }
57
-
58
-    // Claim resources not available due to board layout or internal usage
59
-    {
60
-        // HAL timebase
61
-        rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1);
62
-        // HSE crystal
63
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PD0);
64
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PD1);
65
-        // SWD
66
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
67
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
68
-        // USB
69
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
70
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
71
-        // BOOT pin(s)
72
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1
73
-    }
74
-#elif defined(STM32F072xB)
75
-    // Platform STM32F073RBT
76
-
77
-    // Additional GPIO ports
78
-    __HAL_RCC_GPIOF_CLK_ENABLE();
79
-
80 36
     // Units supported by the platform (known to work correctly)
81 37
     // - this is a macro created in the Makefile, registering all enabled units
82
-    UNITS_REGISTER_CMD
83
-
84
-    // Free all present resources
85
-    {
86
-        rsc_free(NULL, R_ADC1);
87
-//        rsc_free(NULL, R_CAN1);
88
-//        rsc_free_range(NULL, R_COMP1, R_COMP2);
89
-        rsc_free(NULL, R_DAC1);
90
-//        rsc_free(NULL, R_HDMI_CEC);
91
-        rsc_free(NULL, R_TSC);
92
-        rsc_free_range(NULL, R_I2C1, R_I2C2);
93
-//        rsc_free_range(NULL, R_I2S1, R_I2S2);
94
-        rsc_free_range(NULL, R_SPI1, R_SPI2);
95
-        rsc_free_range(NULL, R_TIM1, R_TIM3);
96
-        rsc_free_range(NULL, R_TIM6, R_TIM7);
97
-        rsc_free_range(NULL, R_TIM14, R_TIM17);
98
-        rsc_free_range(NULL, R_USART1, R_USART4);
99
-        rsc_free_range(NULL, R_DMA1_1, R_DMA1_7);
100
-
101
-        rsc_free_range(NULL, R_PA0, R_PA15);
102
-        rsc_free_range(NULL, R_PB0, R_PB15);
103
-        rsc_free_range(NULL, R_PC0, R_PC15);
104
-        rsc_free(NULL, R_PD2);
105
-        rsc_free_range(NULL, R_PF0, R_PF1);
106
-    }
107
-
108
-    // Claim resources not available due to board layout or internal usage
109
-    {
110
-        // HAL timebase
111
-        rv |= rsc_claim(&UNIT_SYSTEM, R_TIM17);
112
-        // HSE crystal
113
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PF0);
114
-
115
-        #if PLAT_FULL_XTAL
116
-            rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode
117
-        #endif
118
-
119
-        // SWD
120
-//        rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
121
-//        rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
122
-        // USB
123
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
124
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
125
-
126
-        #if defined(GEX_PLAT_F072_ZERO)
127
-            // unconnected pins
128
-            rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC0, R_PC1);
129
-            rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC4, R_PC9);
130
-        #endif
131
-    }
132
-#elif defined(GEX_PLAT_F303_DISCOVERY)
133
-    // Platform STM32F303VCT
134
-
135
-    // Additional GPIO ports
136
-    __HAL_RCC_GPIOF_CLK_ENABLE();
137
-
138
-    // Units supported by the platform (known to work correctly)
139
-    // ureg_add_type(&UNIT_XYZ);
140
-
141
-    // Free all present resources
142
-    {
143
-        rsc_free_range(NULL, R_ADC1, R_ADC4);
144
-//        rsc_free(NULL, R_CAN1);
145
-//        rsc_free_range(NULL, R_COMP1, R_COMP7);
146
-//        rsc_free(NULL, R_HDMI_CEC);
147
-        rsc_free(NULL, R_DAC1);
148
-        rsc_free_range(NULL, R_I2C1, R_I2C2);
149
-        rsc_free_range(NULL, R_I2S2, R_I2S3);
150
-//        rsc_free_range(NULL, R_OPAMP1, R_OPAMP4);
151
-        rsc_free_range(NULL, R_SPI1, R_SPI3);
152
-        rsc_free_range(NULL, R_TIM1, R_TIM4);
153
-        rsc_free_range(NULL, R_TIM6, R_TIM8);
154
-        rsc_free_range(NULL, R_TIM15, R_TIM17);
155
-        rsc_free(NULL, R_TSC);
156
-        rsc_free_range(NULL, R_USART1, R_USART5);
157
-
158
-        rsc_free_range(NULL, R_PA0, R_PA15);
159
-        rsc_free_range(NULL, R_PB0, R_PB15);
160
-        rsc_free_range(NULL, R_PC0, R_PC15);
161
-        rsc_free_range(NULL, R_PD0, R_PD15);
162
-        rsc_free_range(NULL, R_PE0, R_PE15);
163
-
164
-        rsc_free_range(NULL, R_PF0, R_PF2);
165
-        rsc_free(NULL, R_PF4);
166
-        rsc_free_range(NULL, R_PF9, R_PF10);
167
-    }
168
-
169
-    // Claim resources not available due to board layout or internal usage
170
-    {
171
-        // HAL timebase
172
-        rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1);
173
-        // HSE crystal
174
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PF0);
175
-        //rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode
176
-        // SWD
177
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
178
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
179
-        // USB
180
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
181
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
182
-        // BOOT pin(s)
183
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1
184
-    }
185
-#elif defined(GEX_PLAT_F407_DISCOVERY)
186
-    // Platform STM32F407VGT
187
-
188
-    // Additional GPIO ports
189
-    __HAL_RCC_GPIOF_CLK_ENABLE();
190
-
191
-    // Units supported by the platform (known to work correctly)
192
-    // ureg_add_type(&UNIT_XYZ);
193
-
194
-    // Free all present resources
195
-    {
196
-        rsc_free_range(NULL, R_ADC1, R_ADC3);
197
-//        rsc_free_range(NULL, R_CAN1, R_CAN2);
198
-//        rsc_free_range(NULL, R_COMP1, R_COMP7);
199
-        rsc_free(NULL, R_DAC1);
200
-//        rsc_free(NULL, R_DCMI);
201
-//        rsc_free(NULL, R_ETH);
202
-//        rsc_free(NULL, R_FSMC);
203
-        rsc_free_range(NULL, R_I2C1, R_I2C3);
204
-        rsc_free_range(NULL, R_I2S2, R_I2S3);
205
-//        rsc_free(NULL, R_SDIO);
206
-        rsc_free_range(NULL, R_SPI1, R_SPI3);
207
-        rsc_free_range(NULL, R_TIM1, R_TIM14);
208
-        rsc_free_range(NULL, R_USART1, R_USART3);
209
-        rsc_free(NULL, R_USART6);
210
-
211
-        rsc_free_range(NULL, R_PA0, R_PA15);
212
-        rsc_free_range(NULL, R_PB0, R_PB15);
213
-        rsc_free_range(NULL, R_PC0, R_PC15);
214
-        rsc_free_range(NULL, R_PD0, R_PD15);
215
-        rsc_free_range(NULL, R_PE0, R_PE15);
216
-        // also has 2 PH pins
217
-
218
-        // F407 appears to have fewer GPIOs than F303?
219
-    }
220
-
221
-    // Claim resources not available due to board layout or internal usage
222
-    {
223
-        // HAL timebase
224
-        rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1);
225
-        // HSE crystal
226
-        // H0 and H1
227
-        // SWD
228
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
229
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
230
-        // USB
231
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
232
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
233
-        // BOOT pin(s)
234
-        rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1
235
-    }
236
-#else
237
-    #error "BAD PLATFORM!"
238
-#endif
38
+    UNITS_REGISTER_CMD;
239 39
 
40
+    rv = plat_init_resources2();
240 41
     assert_param(rv == 0);
241 42
 }
242 43
 
@@ -250,13 +51,10 @@ void plat_usb_reconnect(void)
250 51
 {
251 52
     if (gActiveComport != COMPORT_USB) return;
252 53
 
253
-    // TODO add better reset methods available on different chips
254
-
54
+    // TODO add other reset methods available on different chips (e.g. externam FET)
255 55
     USBD_LL_Reset(&hUsbDeviceFS);
256 56
 
257
-#if defined(GEX_PLAT_F103_BLUEPILL)
258
-    // F103 doesn't have pull-up control
259
-#else
57
+#if PLAT_USB_PU_CTL
260 58
     HAL_PCD_DevDisconnect(&hpcd_USB_FS);
261 59
     osDelay(100);
262 60
     HAL_PCD_DevConnect(&hpcd_USB_FS);

+ 7 - 0
platform/platform.h View File

@@ -17,8 +17,15 @@
17 17
 
18 18
 // FreeRTOS includes
19 19
 #include <cmsis_os.h>
20
+// platform-independent GEX config
21
+#include "plat_config.h"
20 22
 // platform-specific stuff (includes stm32 driver headers)
21 23
 #include "plat_compat.h"
24
+
25
+#define PLAT_AHB_HZ (PLAT_AHB_MHZ*1000000)
26
+#define PLAT_APB1_HZ (PLAT_APB1_MHZ*1000000)
27
+#define PLAT_APB2_HZ (PLAT_APB2_MHZ*1000000)
28
+
22 29
 // assert_param, trap...
23 30
 #include "stm32_assert.h"
24 31
 // inIRQ etc

+ 3 - 3
platform/timebase.h View File

@@ -8,8 +8,8 @@
8 8
 // and interrupts.
9 9
 //
10 10
 
11
-#ifndef GEX_F072_TIMEBASE_H
12
-#define GEX_F072_TIMEBASE_H
11
+#ifndef GEX_CORE_TIMEBASE_H
12
+#define GEX_CORE_TIMEBASE_H
13 13
 
14 14
 #include "platform.h"
15 15
 
@@ -58,4 +58,4 @@ static inline uint32_t PTIM_MicroDelayAlign(void)
58 58
     return res;
59 59
 }
60 60
 
61
-#endif //GEX_F072_TIMEBASE_H
61
+#endif //GEX_CORE_TIMEBASE_H

+ 3 - 3
platform/watchdog.h View File

@@ -2,8 +2,8 @@
2 2
 // Created by MightyPork on 2018/02/27.
3 3
 //
4 4
 
5
-#ifndef GEX_F072_WATCHDOG_H
6
-#define GEX_F072_WATCHDOG_H
5
+#ifndef GEX_CORE_WATCHDOG_H
6
+#define GEX_CORE_WATCHDOG_H
7 7
 
8 8
 /**
9 9
  * Initialize the application watchdog
@@ -29,4 +29,4 @@ void wd_resume(void);
29 29
  */
30 30
 void wd_restart(void);
31 31
 
32
-#endif //GEX_F072_WATCHDOG_H
32
+#endif //GEX_CORE_WATCHDOG_H

+ 3 - 3
tasks/task_msg.h View File

@@ -5,8 +5,8 @@
5 5
 // and TinyFrame message handling
6 6
 //
7 7
 
8
-#ifndef GEX_F072_TASK_MSG_H
9
-#define GEX_F072_TASK_MSG_H
8
+#ifndef GEX_CORE_TASK_MSG_H
9
+#define GEX_CORE_TASK_MSG_H
10 10
 
11 11
 #include "platform.h"
12 12
 #include "sched_queue.h"
@@ -39,4 +39,4 @@ void rxQuePostMsg(uint8_t *buf, uint32_t len);
39 39
 extern volatile uint32_t msgQueHighWaterMark;
40 40
 #endif
41 41
 
42
-#endif //GEX_F072_TASK_MSG_H
42
+#endif //GEX_CORE_TASK_MSG_H

+ 41 - 0
template/nrf_pins.h.txt View File

@@ -0,0 +1,41 @@
1
+//
2
+// Definition of nRF24L01+ pin mappings for the platform
3
+// This file may be omitted if SUPPORT_NRF is not set in plat_compat.h
4
+// See rsc_enum.h for the R_ resource constants
5
+//
6
+
7
+#ifndef GEX_NRF_PINS_H
8
+#define GEX_NRF_PINS_H
9
+
10
+#include "platform.h"
11
+#include "rsc_enum.h"
12
+
13
+#define NRF_SPI            SPI2
14
+#define NRF_R_SPI          R_SPI2
15
+
16
+#define NRF_IRQ_Pin        LL_GPIO_PIN_15
17
+#define NRF_IRQ_GPIO_Port  GPIOC
18
+#define NRF_R_IRQ          R_PC15
19
+#define NRF_EXTI_LINENUM   15
20
+#define NRF_SYSCFG_EXTI_PORT LL_SYSCFG_EXTI_PORTC
21
+
22
+#define NRF_NSS_Pin        LL_GPIO_PIN_13
23
+#define NRF_NSS_GPIO_Port  GPIOC
24
+#define NRF_R_NSS          R_PC13
25
+
26
+#define NRF_CE_Pin         LL_GPIO_PIN_14
27
+#define NRF_CE_GPIO_Port   GPIOC
28
+#define NRF_R_CE           R_PC14
29
+
30
+#define NRF_RST_Pin        LL_GPIO_PIN_12
31
+#define NRF_RST_GPIO_Port  GPIOC
32
+#define NRF_R_RST          R_PC12
33
+
34
+#define NRF_R_SCK          R_PB13
35
+#define NRF_SCK_AF         LL_GPIO_AF_0
36
+#define NRF_R_MISO         R_PC2
37
+#define NRF_MISO_AF        LL_GPIO_AF_1
38
+#define NRF_R_MOSI         R_PC3
39
+#define NRF_MOSI_AF        LL_GPIO_AF_1
40
+
41
+#endif //GEX_NRF_PINS_H

+ 28 - 0
template/old/FreeRTOSConfig.plat.txt View File

@@ -0,0 +1,28 @@
1
+#if defined(GEX_PLAT_F103_BLUEPILL) || defined(GEX_PLAT_F303_DISCOVERY) \
2
+    || defined(GEX_PLAT_F407_DISCOVERY)
3
+    // This is for F103+
4
+
5
+    /* The lowest interrupt priority that can be used in a call to a "set priority"
6
+    function. */
7
+    #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   15
8
+
9
+    #define configPRIO_BITS         4
10
+
11
+    /* The highest interrupt priority that can be used by any interrupt service
12
+    routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
13
+    INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
14
+    PRIORITY THAN THIS! (higher priorities are lower numeric values. */
15
+    #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
16
+
17
+    #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
18
+#elif defined(STM32F072xB)
19
+    // This is for F072
20
+    #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   3
21
+    #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 1
22
+
23
+    #define configPRIO_BITS         2
24
+
25
+    #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
26
+#else
27
+    #error "BAD PLATFORM!!"
28
+#endif

+ 41 - 0
template/old/debug_uart.h.txt View File

@@ -0,0 +1,41 @@
1
+
2
+#define DEBUG_USART_BAUD 115200
3
+
4
+#if GEX_PLAT_F072
5
+
6
+    #define DEBUG_USART USART1
7
+    #define DEBUG_USART_RSC R_USART1
8
+    #define DEBUG_USART_PORT 'A'
9
+    #define DEBUG_USART_PIN  9
10
+    #define DEBUG_USART_AF  1
11
+    #define DEBUG_USART_PCLK PLAT_APB1_HZ
12
+
13
+#elif GEX_PLAT_F103
14
+
15
+    #define DEBUG_USART USART2
16
+    #define DEBUG_USART_RSC R_USART2
17
+    #define DEBUG_USART_PORT 'A'
18
+    #define DEBUG_USART_PIN  2
19
+    #define DEBUG_USART_PCLK PLAT_APB1_HZ
20
+
21
+#elif GEX_PLAT_F303
22
+
23
+    #define DEBUG_USART USART3
24
+    #define DEBUG_USART_RSC R_USART3
25
+    #define DEBUG_USART_PORT 'D'
26
+    #define DEBUG_USART_PIN  8
27
+    #define DEBUG_USART_AF  7
28
+    #define DEBUG_USART_PCLK PLAT_APB1_HZ
29
+
30
+#elif GEX_PLAT_F407
31
+
32
+    #define DEBUG_USART USART2
33
+    #define DEBUG_USART_RSC R_USART2
34
+    #define DEBUG_USART_PORT 'A'
35
+    #define DEBUG_USART_PIN  2
36
+    #define DEBUG_USART_AF  7
37
+    #define DEBUG_USART_PCLK PLAT_APB1_HZ
38
+
39
+#else
40
+    #error "BAD PLATFORM!"
41
+#endif

platform/plat_compat.h → template/old/plat_compat.h.txt View File

@@ -5,75 +5,6 @@
5 5
 #ifndef GEX_PLAT_COMPAT_H
6 6
 #define GEX_PLAT_COMPAT_H
7 7
 
8
-#define VFS_DRIVE_NAME "GEX"
9
-
10
-// -------- Priorities -------------
11
-#define TSK_MAIN_PRIO osPriorityNormal
12
-#define TSK_JOBS_PRIO osPriorityHigh
13
-#define TSK_TIMERS_PRIO 4 // this must be in the 0-7 range
14
-
15
-// -------- Static buffers ---------
16
-// USB / VFS task stack size
17
-#if DISABLE_MSC
18
- #define TSK_STACK_MAIN      100 // without MSC the stack usage is significantly lower
19
-#else
20
- #define TSK_STACK_MAIN      160
21
-#endif
22
-
23
-// 180 is normally enough if not doing extensive debug logging
24
-#define TSK_STACK_MSG       220 // TF message handler task stack size (all unit commands run on this thread)
25
-#define TSK_STACK_IDLE    64 //configMINIMAL_STACK_SIZE
26
-#define TSK_STACK_TIMERS  64 //configTIMER_TASK_STACK_DEPTH
27
-
28
-#define PLAT_HEAP_SIZE 4096
29
-
30
-
31
-
32
-#define BULK_READ_BUF_LEN 256   // Buffer for TF bulk reads
33
-#define UNIT_TMP_LEN      256   // Buffer for internal unit operations
34
-
35
-#define FLASH_SAVE_BUF_LEN  128 // Malloc'd buffer for saving to flash
36
-
37
-#define MSG_QUE_SLOT_SIZE 64 // FIXME this should be possible to lower, but there's some bug with bulk transfer / INI parser
38
-#define RX_QUE_CAPACITY    16 // TinyFrame rx queue size (64 bytes each)
39
-
40
-#define TF_MAX_PAYLOAD_RX 512 // TF max Rx payload
41
-#define TF_SENDBUF_LEN    512 // TF transmit buffer (can be less than a full frame)
42
-
43
-#define TF_MAX_ID_LST   4 // Frame ID listener count
44
-#define TF_MAX_TYPE_LST 6 // Frame Type listener count
45
-#define TF_MAX_GEN_LST  1 // Generic listener count
46
-
47
-#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)
48
-#define MSC_MEDIA_PACKET       512 // Mass storage sector size (packet)
49
-
50
-#define INI_KEY_MAX    20 // Ini parser key buffer
51
-#define INI_VALUE_MAX  30 // Ini parser value buffer
52
-
53
-// -------- Stack buffers ----------
54
-#define DBG_BUF_LEN      100 // Size of the snprintf buffer for debug messages
55
-#define ERR_MSG_STR_LEN  64 // Error message buffer size
56
-#define IWBUFFER_LEN     80 // Ini writer buffer for sprintf
57
-
58
-// -------- Timeouts ------------
59
-#define TF_PARSER_TIMEOUT_TICKS 100 // Timeout for receiving & parsing a frame
60
-#define BULK_LST_TIMEOUT_MS     2000 // timeout for the bulk transaction to expire
61
-#define MSG_QUE_POST_TIMEOUT    200 // Time to post to the messages / jobs queue
62
-
63
-// -------- Platform specific includes and defines ---------
64
-
65
-/// Feature flags:
66
-// PLAT_FLASHBANKS - has the Banks field on the Flash config struct
67
-// PLAT_NO_FLOATING_INPUTS - can't have digital inputs with no pull resistor
68
-// PLAT_USB_PHYCLOCK - requires special config of phy clock for USB
69
-// PLAT_USB_OTGFS - uses the USB OTG IP, needs different config code
70
-// PLAT_LOCK_BTN - use a lock button instead of a lock jumper (push to toggle)
71
-// PLAT_LOCK_1CLOSED - lock jumper is active (closed / button pressed) in logical 1
72
-// PLAT_NO_AFNUM - legacy platform without numbered AF alternatives
73
-// PLAT_FULL_XTAL - use two-wire xtal attachment
74
-
75
-// SUPPORT_NRF
76
-
77 8
 #if defined(GEX_PLAT_F103_BLUEPILL)
78 9
 
79 10
     // platform name for the version string

+ 194 - 0
template/old/plat_init.c.txt View File

@@ -0,0 +1,194 @@
1
+
2
+#if defined(GEX_PLAT_F103_BLUEPILL)
3
+    // Platform STM32F103C8T6 Bluepill ($4 board from eBay)
4
+
5
+    // Units supported by the platform (known to work correctly)
6
+
7
+    // free all present resources
8
+    {
9
+        rsc_free_range(NULL, R_ADC1, R_ADC2);
10
+        rsc_free_range(NULL, R_I2C1, R_I2C2);
11
+        rsc_free_range(NULL, R_SPI1, R_SPI2);
12
+        rsc_free_range(NULL, R_TIM1, R_TIM4);
13
+        rsc_free_range(NULL, R_USART1, R_USART3);
14
+        rsc_free_range(NULL, R_PA0, R_PA15);
15
+        rsc_free_range(NULL, R_PB0, R_PB15);
16
+        rsc_free_range(NULL, R_PC13, R_PC15);
17
+        rsc_free_range(NULL, R_PD0, R_PD1);
18
+    }
19
+
20
+    // Claim resources not available due to board layout or internal usage
21
+    {
22
+        // HAL timebase
23
+        rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1);
24
+        // HSE crystal
25
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PD0);
26
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PD1);
27
+        // SWD
28
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
29
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
30
+        // USB
31
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
32
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
33
+        // BOOT pin(s)
34
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1
35
+    }
36
+#elif defined(STM32F072xB)
37
+    // Platform STM32F073RBT
38
+
39
+
40
+    // Free all present resources
41
+    {
42
+        rsc_free(NULL, R_ADC1);
43
+//        rsc_free(NULL, R_CAN1);
44
+//        rsc_free_range(NULL, R_COMP1, R_COMP2);
45
+        rsc_free(NULL, R_DAC1);
46
+//        rsc_free(NULL, R_HDMI_CEC);
47
+        rsc_free(NULL, R_TSC);
48
+        rsc_free_range(NULL, R_I2C1, R_I2C2);
49
+//        rsc_free_range(NULL, R_I2S1, R_I2S2);
50
+        rsc_free_range(NULL, R_SPI1, R_SPI2);
51
+        rsc_free_range(NULL, R_TIM1, R_TIM3);
52
+        rsc_free_range(NULL, R_TIM6, R_TIM7);
53
+        rsc_free_range(NULL, R_TIM14, R_TIM17);
54
+        rsc_free_range(NULL, R_USART1, R_USART4);
55
+        rsc_free_range(NULL, R_DMA1_1, R_DMA1_7);
56
+
57
+        rsc_free_range(NULL, R_PA0, R_PA15);
58
+        rsc_free_range(NULL, R_PB0, R_PB15);
59
+        rsc_free_range(NULL, R_PC0, R_PC15);
60
+        rsc_free(NULL, R_PD2);
61
+        rsc_free_range(NULL, R_PF0, R_PF1);
62
+    }
63
+
64
+    // Claim resources not available due to board layout or internal usage
65
+    {
66
+        // HAL timebase
67
+        rv |= rsc_claim(&UNIT_SYSTEM, R_TIM17);
68
+        // HSE crystal
69
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PF0);
70
+
71
+        #if PLAT_FULL_XTAL
72
+            rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode
73
+        #endif
74
+
75
+        // SWD
76
+//        rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
77
+//        rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
78
+        // USB
79
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
80
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
81
+
82
+        #if defined(GEX_PLAT_F072_ZERO)
83
+            // unconnected pins
84
+            rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC0, R_PC1);
85
+            rv |= rsc_claim_range(&UNIT_PLATFORM, R_PC4, R_PC9);
86
+        #endif
87
+    }
88
+#elif defined(GEX_PLAT_F303_DISCOVERY)
89
+    // Platform STM32F303VCT
90
+
91
+    // Additional GPIO ports
92
+    __HAL_RCC_GPIOF_CLK_ENABLE();
93
+
94
+    // Units supported by the platform (known to work correctly)
95
+    // ureg_add_type(&UNIT_XYZ);
96
+
97
+    // Free all present resources
98
+    {
99
+        rsc_free_range(NULL, R_ADC1, R_ADC4);
100
+//        rsc_free(NULL, R_CAN1);
101
+//        rsc_free_range(NULL, R_COMP1, R_COMP7);
102
+//        rsc_free(NULL, R_HDMI_CEC);
103
+        rsc_free(NULL, R_DAC1);
104
+        rsc_free_range(NULL, R_I2C1, R_I2C2);
105
+        rsc_free_range(NULL, R_I2S2, R_I2S3);
106
+//        rsc_free_range(NULL, R_OPAMP1, R_OPAMP4);
107
+        rsc_free_range(NULL, R_SPI1, R_SPI3);
108
+        rsc_free_range(NULL, R_TIM1, R_TIM4);
109
+        rsc_free_range(NULL, R_TIM6, R_TIM8);
110
+        rsc_free_range(NULL, R_TIM15, R_TIM17);
111
+        rsc_free(NULL, R_TSC);
112
+        rsc_free_range(NULL, R_USART1, R_USART5);
113
+
114
+        rsc_free_range(NULL, R_PA0, R_PA15);
115
+        rsc_free_range(NULL, R_PB0, R_PB15);
116
+        rsc_free_range(NULL, R_PC0, R_PC15);
117
+        rsc_free_range(NULL, R_PD0, R_PD15);
118
+        rsc_free_range(NULL, R_PE0, R_PE15);
119
+
120
+        rsc_free_range(NULL, R_PF0, R_PF2);
121
+        rsc_free(NULL, R_PF4);
122
+        rsc_free_range(NULL, R_PF9, R_PF10);
123
+    }
124
+
125
+    // Claim resources not available due to board layout or internal usage
126
+    {
127
+        // HAL timebase
128
+        rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1);
129
+        // HSE crystal
130
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PF0);
131
+        //rv |= rsc_claim(&UNIT_SYSTEM, R_PF1); // - not used in BYPASS mode
132
+        // SWD
133
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
134
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
135
+        // USB
136
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
137
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
138
+        // BOOT pin(s)
139
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1
140
+    }
141
+#elif defined(GEX_PLAT_F407_DISCOVERY)
142
+    // Platform STM32F407VGT
143
+
144
+    // Additional GPIO ports
145
+    __HAL_RCC_GPIOF_CLK_ENABLE();
146
+
147
+    // Units supported by the platform (known to work correctly)
148
+    // ureg_add_type(&UNIT_XYZ);
149
+
150
+    // Free all present resources
151
+    {
152
+        rsc_free_range(NULL, R_ADC1, R_ADC3);
153
+//        rsc_free_range(NULL, R_CAN1, R_CAN2);
154
+//        rsc_free_range(NULL, R_COMP1, R_COMP7);
155
+        rsc_free(NULL, R_DAC1);
156
+//        rsc_free(NULL, R_DCMI);
157
+//        rsc_free(NULL, R_ETH);
158
+//        rsc_free(NULL, R_FSMC);
159
+        rsc_free_range(NULL, R_I2C1, R_I2C3);
160
+        rsc_free_range(NULL, R_I2S2, R_I2S3);
161
+//        rsc_free(NULL, R_SDIO);
162
+        rsc_free_range(NULL, R_SPI1, R_SPI3);
163
+        rsc_free_range(NULL, R_TIM1, R_TIM14);
164
+        rsc_free_range(NULL, R_USART1, R_USART3);
165
+        rsc_free(NULL, R_USART6);
166
+
167
+        rsc_free_range(NULL, R_PA0, R_PA15);
168
+        rsc_free_range(NULL, R_PB0, R_PB15);
169
+        rsc_free_range(NULL, R_PC0, R_PC15);
170
+        rsc_free_range(NULL, R_PD0, R_PD15);
171
+        rsc_free_range(NULL, R_PE0, R_PE15);
172
+        // also has 2 PH pins
173
+
174
+        // F407 appears to have fewer GPIOs than F303?
175
+    }
176
+
177
+    // Claim resources not available due to board layout or internal usage
178
+    {
179
+        // HAL timebase
180
+        rv |= rsc_claim(&UNIT_SYSTEM, R_TIM1);
181
+        // HSE crystal
182
+        // H0 and H1
183
+        // SWD
184
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA13);
185
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA14);
186
+        // USB
187
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA11);
188
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PA12);
189
+        // BOOT pin(s)
190
+        rv |= rsc_claim(&UNIT_SYSTEM, R_PB2); // BOOT1
191
+    }
192
+#else
193
+    #error "BAD PLATFORM!"
194
+#endif

+ 46 - 0
template/plat_compat.h.txt View File

@@ -0,0 +1,46 @@
1
+#ifndef GEX_PLAT_COMPAT_H
2
+#define GEX_PLAT_COMPAT_H
3
+
4
+// string identifying the GEX board
5
+#define GEX_PLATFORM "Discovery-XYZ"
6
+#define GEX_PLAT_XYZ 1 // only with the MCU name
7
+
8
+// GEX_PLAT_XYZ_BOARD is defined in build.mk to identify particular board layout
9
+
10
+#define PLAT_AHB_MHZ  72
11
+#define PLAT_APB1_MHZ 36
12
+
13
+#include ... // all useful from the peripheral library (HAL / LL)
14
+
15
+// in bytes
16
+#define FLASH_SIZE (128*1024)
17
+// in bytes
18
+#define SETTINGS_BLOCK_SIZE (2*1024)
19
+// address where the settings block starts
20
+#define SETTINGS_FLASH_ADDR (0x08000000 + FLASH_SIZE - SETTINGS_BLOCK_SIZE)
21
+
22
+#define PORTS_COUNT       5   // number of available GPIO ports A,B,C,D,E,F...
23
+#define LOCK_JUMPER_PORT 'A'
24
+#define LOCK_JUMPER_PIN   2
25
+
26
+#define STATUS_LED_PORT 'A'
27
+#define STATUS_LED_PIN  15
28
+
29
+// Feature flags:
30
+#define PLAT_FLASHBANKS   0        // has the Banks field on the Flash config struct
31
+#define PLAT_NO_FLOATING_INPUTS 0  // can't have digital inputs with no pull resistor
32
+#define PLAT_USB_PHYCLOCK 0        // requires special config of phy clock for USB
33
+#define PLAT_USB_OTGFS    0        // uses the USB OTG IP, needs different config code
34
+#define PLAT_LOCK_BTN     1        // use a lock button instead of a lock jumper (push to toggle)
35
+#define PLAT_LOCK_1CLOSED 1        // lock jumper is active (closed / button pressed) in logical 1
36
+#define PLAT_NO_AFNUM     0        // legacy platform without numbered AF alternatives
37
+#define PLAT_FULL_XTAL    1        // use two-wire xtal attachment
38
+#define PLAT_USB_PU_CTL   1        // platform has USB pullup control
39
+
40
+// FreeRTOS config
41
+#define PLAT_FREERTOS_LOWEST_INTERRUPT_PRIORITY          3
42
+#define PLAT_FREERTOS_MAX_SYSCALL_INTERRUPT_PRIORITY     1
43
+#define PLAT_FREERTOS_PRIO_BITS                          2
44
+#define PLAT_FREERTOS_USE_PORT_OPTIMISED_TASK_SELECTION  0
45
+
46
+#endif //GEX_PLAT_COMPAT_H

BIN
template/template_unit.zip View File