Skip to content

Commit de5a67b

Browse files
committed
clean osal_freertos, update freertos examples to work with configSUPPORT_DYNAMIC_ALLOCATION only
note: for example to build with configSUPPORT_STATIC_ALLOCATION = 0, one of heap_n.c must be included in makefile/cmake
1 parent 52261ac commit de5a67b

File tree

8 files changed

+100
-65
lines changed

8 files changed

+100
-65
lines changed

examples/device/cdc_msc_freertos/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ SRC_C += \
2929
$(FREERTOS_SRC)/timers.c \
3030
$(subst ../../../,,$(wildcard ../../../$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)/*.c))
3131

32-
# Suppress FreeRTOS warnings
33-
CFLAGS += -Wno-error=cast-qual -Wno-error=redundant-decls
32+
# include heap manage if configSUPPORT_DYNAMIC_ALLOCATION = 1
33+
# SRC_C += $(FREERTOS_SRC)/portable/MemMang/heap_1.c
34+
# CFLAGS += -Wno-error=sign-compare
35+
36+
# Suppress FreeRTOSConfig.h warnings
37+
CFLAGS += -Wno-error=redundant-decls
38+
39+
# Suppress FreeRTOS source warnings
40+
CFLAGS += -Wno-error=cast-qual
3441

3542
# FreeRTOS (lto + Os) linker issue
3643
LDFLAGS += -Wl,--undefined=vTaskSwitchContext

examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
#define configTICK_RATE_HZ ( 1000 )
7070
#define configMAX_PRIORITIES ( 5 )
7171
#define configMINIMAL_STACK_SIZE ( 128 )
72-
#define configTOTAL_HEAP_SIZE ( 0*1024 ) // dynamic is not used
72+
#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 )
7373
#define configMAX_TASK_NAME_LEN 16
7474
#define configUSE_16_BIT_TICKS 0
7575
#define configIDLE_SHOULD_YIELD 1

examples/device/cdc_msc_freertos/src/main.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
5252
#endif
5353

54+
#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE
55+
5456
//--------------------------------------------------------------------+
5557
// MACRO CONSTANT TYPEDEF PROTYPES
5658
//--------------------------------------------------------------------+
@@ -66,19 +68,18 @@ enum {
6668
BLINK_SUSPENDED = 2500,
6769
};
6870

69-
// static timer
71+
// static timer & task
72+
#if configSUPPORT_STATIC_ALLOCATION
7073
StaticTimer_t blinky_tmdef;
71-
TimerHandle_t blinky_tm;
7274

73-
// static task
7475
StackType_t usb_device_stack[USBD_STACK_SIZE];
7576
StaticTask_t usb_device_taskdef;
7677

77-
// static task for cdc
78-
#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE
7978
StackType_t cdc_stack[CDC_STACK_SZIE];
8079
StaticTask_t cdc_taskdef;
80+
#endif
8181

82+
TimerHandle_t blinky_tm;
8283

8384
void led_blinky_cb(TimerHandle_t xTimer);
8485
void usb_device_task(void* param);
@@ -92,15 +93,22 @@ int main(void)
9293
{
9394
board_init();
9495

96+
#if configSUPPORT_STATIC_ALLOCATION
9597
// soft timer for blinky
9698
blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef);
97-
xTimerStart(blinky_tm, 0);
9899

99100
// Create a task for tinyusb device stack
100-
(void) xTaskCreateStatic( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
101+
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
101102

102103
// Create CDC task
103-
(void) xTaskCreateStatic( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
104+
xTaskCreateStatic(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
105+
#else
106+
blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb);
107+
xTaskCreate( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);
108+
xTaskCreate( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
109+
#endif
110+
111+
xTimerStart(blinky_tm, 0);
104112

105113
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
106114
#if !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)

examples/device/hid_composite_freertos/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ SRC_C += \
2828
$(FREERTOS_SRC)/timers.c \
2929
$(subst ../../../,,$(wildcard ../../../$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)/*.c))
3030

31-
# Suppress FreeRTOS warnings
32-
CFLAGS += -Wno-error=cast-qual -Wno-error=redundant-decls
31+
# include heap manage if configSUPPORT_DYNAMIC_ALLOCATION = 1
32+
# SRC_C += $(FREERTOS_SRC)/portable/MemMang/heap_1.c
33+
# CFLAGS += -Wno-error=sign-compare
34+
35+
# Suppress FreeRTOSConfig.h warnings
36+
CFLAGS += -Wno-error=redundant-decls
37+
38+
# Suppress FreeRTOS source warnings
39+
CFLAGS += -Wno-error=cast-qual
3340

3441
# FreeRTOS (lto + Os) linker issue
3542
LDFLAGS += -Wl,--undefined=vTaskSwitchContext

examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@
4646
#include "bsp/board_mcu.h"
4747

4848
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
49-
#error "ESP32-Sx should use IDF's FreeRTOSConfig.h"
49+
#error "ESP32-Sx should use IDF's FreeRTOSConfig.h"
5050
#endif
5151

52+
// TODO fix later
5253
#if CFG_TUSB_MCU == OPT_MCU_MM32F327X
53-
// TODO fix/remove later
5454
extern u32 SystemCoreClock;
5555
#else
56+
// FIXME cause redundant-decls warnings
5657
extern uint32_t SystemCoreClock;
5758
#endif
5859

@@ -68,7 +69,7 @@
6869
#define configTICK_RATE_HZ ( 1000 )
6970
#define configMAX_PRIORITIES ( 5 )
7071
#define configMINIMAL_STACK_SIZE ( 128 )
71-
#define configTOTAL_HEAP_SIZE ( 0*1024 ) // dynamic is not used
72+
#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 )
7273
#define configMAX_TASK_NAME_LEN 16
7374
#define configUSE_16_BIT_TICKS 0
7475
#define configIDLE_SHOULD_YIELD 1

examples/device/hid_composite_freertos/src/main.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
5454
#endif
5555

56+
#define HID_STACK_SZIE configMINIMAL_STACK_SIZE
57+
5658
//--------------------------------------------------------------------+
5759
// MACRO CONSTANT TYPEDEF PROTYPES
5860
//--------------------------------------------------------------------+
@@ -68,19 +70,18 @@ enum {
6870
BLINK_SUSPENDED = 2500,
6971
};
7072

71-
// static timer
73+
// static timer & task
74+
#if configSUPPORT_STATIC_ALLOCATION
7275
StaticTimer_t blinky_tmdef;
73-
TimerHandle_t blinky_tm;
7476

75-
// static task
7677
StackType_t usb_device_stack[USBD_STACK_SIZE];
7778
StaticTask_t usb_device_taskdef;
7879

79-
// static task for hid
80-
#define HID_STACK_SZIE configMINIMAL_STACK_SIZE
8180
StackType_t hid_stack[HID_STACK_SZIE];
8281
StaticTask_t hid_taskdef;
82+
#endif
8383

84+
TimerHandle_t blinky_tm;
8485

8586
void led_blinky_cb(TimerHandle_t xTimer);
8687
void usb_device_task(void* param);
@@ -94,15 +95,22 @@ int main(void)
9495
{
9596
board_init();
9697

98+
#if configSUPPORT_STATIC_ALLOCATION
9799
// soft timer for blinky
98100
blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef);
99-
xTimerStart(blinky_tm, 0);
100101

101102
// Create a task for tinyusb device stack
102-
(void) xTaskCreateStatic( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
103+
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
103104

104105
// Create HID task
105-
(void) xTaskCreateStatic( hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, hid_stack, &hid_taskdef);
106+
xTaskCreateStatic(hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, hid_stack, &hid_taskdef);
107+
#else
108+
blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb);
109+
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);
110+
xTaskCreate(hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
111+
#endif
112+
113+
xTimerStart(blinky_tm, 0);
106114

107115
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
108116
#if !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)

src/osal/osal_freertos.h

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@
3737
extern "C" {
3838
#endif
3939

40+
//--------------------------------------------------------------------+
41+
// MACRO CONSTANT TYPEDEF PROTYPES
42+
//--------------------------------------------------------------------+
43+
44+
#if configSUPPORT_STATIC_ALLOCATION
45+
typedef StaticSemaphore_t osal_semaphore_def_t;
46+
typedef StaticSemaphore_t osal_mutex_def_t;
47+
#else
48+
// not used therefore defined to smallest possible type to save space
49+
typedef uint8_t osal_semaphore_def_t;
50+
typedef uint8_t osal_mutex_def_t;
51+
#endif
52+
53+
typedef SemaphoreHandle_t osal_semaphore_t;
54+
typedef SemaphoreHandle_t osal_mutex_t;
55+
56+
// _int_set is not used with an RTOS
57+
#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
58+
static _type _name##_##buf[_depth];\
59+
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };
60+
61+
typedef struct
62+
{
63+
uint16_t depth;
64+
uint16_t item_sz;
65+
void* buf;
66+
#if configSUPPORT_STATIC_ALLOCATION
67+
StaticQueue_t sq;
68+
#endif
69+
}osal_queue_def_t;
70+
71+
typedef QueueHandle_t osal_queue_t;
72+
73+
//--------------------------------------------------------------------+
74+
// TASK API
75+
//--------------------------------------------------------------------+
76+
4077
TU_ATTR_ALWAYS_INLINE static inline uint32_t _osal_ms2tick(uint32_t msec)
4178
{
4279
if (msec == OSAL_TIMEOUT_WAIT_FOREVER) return portMAX_DELAY;
@@ -51,9 +88,6 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t _osal_ms2tick(uint32_t msec)
5188
return ticks;
5289
}
5390

54-
//--------------------------------------------------------------------+
55-
// TASK API
56-
//--------------------------------------------------------------------+
5791
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
5892
{
5993
vTaskDelay( pdMS_TO_TICKS(msec) );
@@ -62,19 +96,13 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
6296
//--------------------------------------------------------------------+
6397
// Semaphore API
6498
//--------------------------------------------------------------------+
65-
#if configSUPPORT_STATIC_ALLOCATION == 1
66-
typedef StaticSemaphore_t osal_semaphore_def_t;
67-
#else
68-
typedef SemaphoreHandle_t osal_semaphore_def_t;
69-
#endif
70-
typedef SemaphoreHandle_t osal_semaphore_t;
7199

72100
TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
73101
{
74-
#if configSUPPORT_STATIC_ALLOCATION == 1
102+
#if configSUPPORT_STATIC_ALLOCATION
75103
return xSemaphoreCreateBinaryStatic(semdef);
76104
#else
77-
(void)(semdef);
105+
(void) semdef;
78106
return xSemaphoreCreateBinary();
79107
#endif
80108
}
@@ -101,7 +129,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t se
101129
}
102130
}
103131

104-
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec)
132+
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
105133
{
106134
return xSemaphoreTake(sem_hdl, _osal_ms2tick(msec));
107135
}
@@ -114,25 +142,18 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t c
114142
//--------------------------------------------------------------------+
115143
// MUTEX API (priority inheritance)
116144
//--------------------------------------------------------------------+
117-
#if configSUPPORT_STATIC_ALLOCATION == 1
118-
typedef StaticSemaphore_t osal_mutex_def_t;
119-
#else
120-
typedef SemaphoreHandle_t osal_mutex_def_t;
121-
#endif
122-
typedef SemaphoreHandle_t osal_mutex_t;
123145

124146
TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
125147
{
126-
#if configSUPPORT_STATIC_ALLOCATION == 1
148+
#if configSUPPORT_STATIC_ALLOCATION
127149
return xSemaphoreCreateMutexStatic(mdef);
128150
#else
129-
(void)(mdef);
151+
(void) mdef;
130152
return xSemaphoreCreateMutex();
131153
#endif
132-
133154
}
134155

135-
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec)
156+
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec)
136157
{
137158
return osal_semaphore_wait(mutex_hdl, msec);
138159
}
@@ -146,26 +167,9 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
146167
// QUEUE API
147168
//--------------------------------------------------------------------+
148169

149-
// _int_set is not used with an RTOS
150-
#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
151-
static _type _name##_##buf[_depth];\
152-
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };
153-
154-
typedef struct
155-
{
156-
uint16_t depth;
157-
uint16_t item_sz;
158-
void* buf;
159-
#if configSUPPORT_STATIC_ALLOCATION == 1
160-
StaticQueue_t sq;
161-
#endif
162-
}osal_queue_def_t;
163-
164-
typedef QueueHandle_t osal_queue_t;
165-
166170
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
167171
{
168-
#if configSUPPORT_STATIC_ALLOCATION == 1
172+
#if configSUPPORT_STATIC_ALLOCATION
169173
return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
170174
#else
171175
return xQueueCreate(qdef->depth, qdef->item_sz);

src/portable/ehci/ehci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr)
193193
{
194194
// TODO check type for ISO iTD and siTD
195195
// TODO Suppress cast-align warning
196-
#pragma GCC diagnostic push
196+
#pragma GCC diagnostic push
197197
#pragma GCC diagnostic ignored "-Wcast-align"
198198
ehci_qhd_t* qhd = (ehci_qhd_t*) list_next(prev);
199199
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)