Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to ChibiOS 17.6.3 #2025

Open
wants to merge 43 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7f71a65
RTOS: Remove ChibiOS 2.6.6
glowtape Jan 5, 2018
463e649
RTOS: Add ChibiOS 17.6.3
glowtape Jan 5, 2018
e16f726
ChibiOS F0,F1,F3,F4: Don't use CMSIS supplied with ChibiOS.
glowtape Jan 5, 2018
ce03587
ChibiOS,stm32_registry: Prevent redefinition of STM32F40_41xxx
glowtape Jan 5, 2018
3c568ca
ChibiOS: Clear CCM RAM, too, when BSS init is desired.
glowtape Jan 5, 2018
713caec
ChibiOS,HAL,F446: New ChibiOS suddenly has issues with HSECLK being a…
glowtape Jan 6, 2018
cea64dd
pios_mutex: Rename types and calls, update unlocking next mutex metho…
glowtape Jan 5, 2018
6f7456d
pios_queue: Rename types and calls for new ChibiOS.
glowtape Jan 5, 2018
8e38a0c
pios_semaphore: Rename types and calls for new ChibiOS.
glowtape Jan 5, 2018
99abbf1
pios_thread: Rename types and calls for new ChibiOS.
glowtape Jan 5, 2018
4261424
pios_usb: New ChibiOS HAL remaps the USB IRQ depending on the F3 type.
glowtape Jan 6, 2018
8b13690
pios: Updated ChibiOS configuration headers (chconf.h, halconf.h)
glowtape Jan 5, 2018
10c7be0
loadable: MemManageVector got renamed to MemManage_Handler in new Chi…
glowtape Jan 5, 2018
8bed3a6
all targets: Makefile changes, introduce $STM32_SUBTYPE, make non-F4 …
glowtape Jan 5, 2018
53ff02e
all targets: Don't reset ADEFS that might have been defined in an inc…
glowtape Jan 5, 2018
21d07d7
F4: Update ChibiOS library.mk makefile
glowtape Jan 5, 2018
a5ed161
F4: Added sections for ChibiOS 17 to linker scripts. Renamed ResetHan…
glowtape Jan 5, 2018
d757e00
F4: Fix linker script lookup. Specify some startup defines.
glowtape Jan 5, 2018
2383793
F4: Add the STM32_SUBTYPE stuff and fixed linker script lookup to boo…
glowtape Jan 5, 2018
332b34d
F3: Update ChibiOS library.mk makefile
glowtape Jan 5, 2018
7f5aec7
F3: Added sections for ChibiOS 17 to linker scripts. Renamed ResetHan…
glowtape Jan 5, 2018
8a7fe22
F3: Specify some startup defines.
glowtape Jan 5, 2018
f043f65
F3: Redirect ChibiOS to project own CMSIS
glowtape Jan 6, 2018
a55c893
sprf3e: Adapt to new USB IRQ handling, disable diagnostics for memory…
glowtape Jan 6, 2018
6dd7b2d
lux: Adapt to new USB IRQ handling.
glowtape Jan 6, 2018
d112bd8
omnibusf3: Adapt to new USB IRQ handling.
glowtape Jan 6, 2018
52a082c
pikoblx: Adapt to new USB IRQ handling.
glowtape Jan 6, 2018
2966618
dtfc: Adapt to new USB IRQ handling.
glowtape Jan 6, 2018
c4cfaf0
sparky: Adapt to new USB IRQ handling, axed two modules to save flash…
glowtape Jan 6, 2018
402f588
F1: Update ChibiOS references in makefile
glowtape Jan 6, 2018
40e1eed
F1: Added sections for ChibiOS 17 to linker scripts. Renamed ResetHan…
glowtape Jan 6, 2018
ec60584
F1,ChibiOS,stm32_registry: Stop it from whining about platform flags.
glowtape Jan 6, 2018
5a8600c
F1: Redirect ChibiOS to project own CMSIS
glowtape Jan 6, 2018
00a02b8
pipxtreme: Updated chconf.h and mcuconf.h, resolve variable conflict …
glowtape Jan 6, 2018
3467596
pios_thread: Forgot to rename a #define.
glowtape Apr 15, 2018
98de70b
chconf: Probably ought to put defines in right order. (fixup)
glowtape Apr 15, 2018
3eb5fa9
pios_thread: Fix SNAFU, ticks_total was our own field. (fixup)
glowtape Apr 15, 2018
b4e69d0
pios_heap: Use memcore with ChibiOS for standard heap.
glowtape Apr 15, 2018
30d977f
pios_thread: Use ChibiOS' allocator for aligned alloc. Store stack lo…
glowtape Apr 15, 2018
31298ca
F4: Change heap stuff for memcore (fixup).
glowtape Apr 15, 2018
1d90679
F3: Change heap stuff for memcore (fixup).
glowtape Apr 16, 2018
330d942
F1: Change heap stuff for memcore (fixup).
glowtape Apr 16, 2018
69fad6a
chibios: Default MSP init to on.
glowtape Apr 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
/* Module pre-compile time settings. */
/*===========================================================================*/

/* dRonin: This if fixed upstream apparently, remove on upgrade to 18.x. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can never be fixed because we will always have old bootloaders around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the CRT0_FORCE_MSP_INIT thing. It's not set at all in this ChibiOS release. It's been set to TRUE by default in 18.x.

/**
* @brief MSP register initialization.
* @details MSP is initialized to point to the proper main process tack.
*/
#if !defined(CRT0_FORCE_MSP_INIT) || defined(__DOXYGEN__)
#define CRT0_FORCE_MSP_INIT TRUE
#endif

/**
* @brief VTOR special register initialization.
* @details VTOR is initialized to point to the vectors table.
Expand Down
26 changes: 25 additions & 1 deletion flight/PiOS/Common/pios_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#include <stdint.h> /* uintptr_t */
#include <stdbool.h> /* bool */

#if defined(PIOS_INCLUDE_CHIBIOS)
#if !defined(CH_CFG_USE_MEMCORE) || CH_CFG_USE_MEMCORE != TRUE
#error "pios_heap: Need to use memcore with ChibiOS."
#endif
#endif

#define DEBUG_MALLOC_FAILURES 0
static volatile bool malloc_failed_flag = false;
static void malloc_failed_hook(void)
Expand All @@ -53,6 +59,8 @@ bool PIOS_heap_malloc_failed_p(void)
#include "pios_thread.h"
#endif

#if !defined(PIOS_INCLUDE_CHIBIOS) || defined(PIOS_INCLUDE_FASTHEAP)

struct pios_heap {
const uintptr_t start_addr;
uintptr_t end_addr;
Expand Down Expand Up @@ -103,6 +111,10 @@ static size_t simple_get_free_bytes(struct pios_heap *heap)
return heap->end_addr - heap->free_addr;
}

#endif

#if !defined(PIOS_INCLUDE_CHIBIOS)

static void simple_extend_heap(struct pios_heap *heap, size_t bytes)
{
heap->end_addr += bytes;
Expand All @@ -119,12 +131,16 @@ static struct pios_heap pios_standard_heap = {
.end_addr = (const uintptr_t)&_eheap,
.free_addr = (uintptr_t)&_sheap,
};

#endif

void * pvPortMalloc(size_t size) __attribute__((alias ("PIOS_malloc"), weak));
void * PIOS_malloc(size_t size)
{
#if defined(PIOS_INCLUDE_CHIBIOS)
void *buf = chCoreAlloc(size);
#else
void *buf = simple_malloc(&pios_standard_heap, size);
#endif

if (buf == NULL)
malloc_failed_hook();
Expand Down Expand Up @@ -178,8 +194,10 @@ void PIOS_free(void * buf)
return simple_free(&pios_nodma_heap, buf);
#endif /* PIOS_INCLUDE_FASTHEAP */

#if !defined(PIOS_INCLUDE_CHIBIOS)
if (is_ptr_in_heap_p(&pios_standard_heap, buf))
return simple_free(&pios_standard_heap, buf);
#endif
}

size_t xPortGetFreeHeapSize(void) __attribute__((alias ("PIOS_heap_get_free_size")));
Expand All @@ -189,7 +207,11 @@ size_t PIOS_heap_get_free_size(void)
PIOS_Thread_Scheduler_Suspend();
#endif /* PIOS_INCLUDE_RTOS */

#if defined(PIOS_INCLUDE_CHIBIOS)
size_t free_bytes = chCoreGetStatusX();
#else
size_t free_bytes = simple_get_free_bytes(&pios_standard_heap);
#endif

#if defined(PIOS_INCLUDE_RTOS)
PIOS_Thread_Scheduler_Resume();
Expand Down Expand Up @@ -236,7 +258,9 @@ void PIOS_heap_increase_size(size_t bytes)
PIOS_Thread_Scheduler_Suspend();
#endif /* PIOS_INCLUDE_RTOS */

#if !defined(PIOS_INCLUDE_CHIBIOS)
simple_extend_heap(&pios_standard_heap, bytes);
#endif

#if defined(PIOS_INCLUDE_RTOS)
PIOS_Thread_Scheduler_Resume();
Expand Down
40 changes: 16 additions & 24 deletions flight/PiOS/Common/pios_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
#error "pios_thread.c requires PIOS_INCLUDE_CHIBIOS"
#endif

#if !defined(CH_CFG_USE_MEMCORE) || CH_CFG_USE_MEMCORE != TRUE
#error "pios_thread: Need to use memcore with ChibiOS."
#endif

#if defined(PIOS_INCLUDE_CHIBIOS)
struct pios_thread
{
thread_t *threadp;
uint32_t *stack;
};

#define CVT_MS2ST(msec) ((systime_t)(((((uint32_t)(msec)) * ((uint64_t)CH_CFG_ST_FREQUENCY) - 1UL) / 1000UL) + 1UL))
Expand All @@ -49,26 +54,6 @@ static uint32_t ceil_size(uint32_t size)
size = size + (a - size % a);
return size;
}
/**
* ChibiOS stack expects alignment (both start and end)
* to 8 byte boundaries. This makes sure to allocate enough
* memory and return an address that has the requested size
* or more with these constraints.
*/
static uint8_t * align8_alloc(uint32_t size)
{
// round size up to at nearest multiple of 8 + 4 bytes to guarantee
// sufficient size within. This is because PIOS_malloc only guarantees
// uintptr_t alignment which is 4 bytes.
size = size + sizeof(uintptr_t);
uint8_t *wap = PIOS_malloc(size);

// shift start point to nearest 8 byte boundary.
uint32_t pad = ((uint32_t) wap) % sizeof(stkalign_t);
wap = wap + pad;

return wap;
}

/**
* @brief Creates a handle for the current thread.
Expand All @@ -83,6 +68,9 @@ struct pios_thread *PIOS_Thread_WrapCurrentThread(const char *namep)

if (thread) {
thread->threadp = chThdGetSelfX();

extern uint32_t __main_thread_stack_base__;
thread->stack = &__main_thread_stack_base__;
#if CH_CFG_USE_REGISTRY
thread->threadp->name = namep;
#endif /* CH_USE_REGISTRY */
Expand Down Expand Up @@ -122,7 +110,7 @@ struct pios_thread *PIOS_Thread_Create(void (*fp)(void *), const char *namep, si

// Use special functions to ensure ChibiOS stack requirements
stack_bytes = ceil_size(stack_bytes);
uint8_t *wap = align8_alloc(stack_bytes);
uint8_t *wap = chCoreAllocAligned(stack_bytes, PORT_STACK_ALIGN);
if (wap == NULL)
{
PIOS_free(thread);
Expand All @@ -141,6 +129,10 @@ struct pios_thread *PIOS_Thread_Create(void (*fp)(void *), const char *namep, si
thread->threadp->name = namep;
#endif /* CH_CFG_USE_REGISTRY */

/* Newer ChibiOS versions store the thread struct at the bottom of the stack allocation
instead of the top. */
thread->stack = (uint32_t*)wap;

return thread;
}

Expand Down Expand Up @@ -255,7 +247,7 @@ bool PIOS_Thread_Period_Elapsed(const uint32_t prev_systime, const uint32_t incr
uint32_t PIOS_Thread_Get_Stack_Usage(struct pios_thread *threadp)
{
#if CH_DBG_FILL_THREADS
uint32_t *stack = (uint32_t*)((size_t)threadp->threadp + sizeof(*threadp->threadp));
uint32_t *stack = threadp->stack;
uint32_t *stklimit = stack;
while (*stack ==
((CH_DBG_STACK_FILL_VALUE << 24) |
Expand All @@ -282,8 +274,8 @@ uint32_t PIOS_Thread_Get_Stack_Usage(struct pios_thread *threadp)
{
chSysLock();

uint32_t result = threadp->threadp->time;
threadp->threadp->time = 0;
uint32_t result = threadp->threadp->ticks_total;
threadp->threadp->ticks_total = 0;

chSysUnlock();

Expand Down
2 changes: 1 addition & 1 deletion flight/PiOS/STM32/inc/chconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@
/*
Backwards compat for dRonin
*/
#define halGetCounterValue() hal_lld_get_counter_value()
#define hal_lld_get_counter_value() DWT->CYCCNT
#define halGetCounterValue() hal_lld_get_counter_value()

// typedef uint32_t halrtcnt_t;

Expand Down
4 changes: 2 additions & 2 deletions flight/PiOS/STM32F10x/sections_chibios.ld
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ SECTIONS
PROVIDE(end = .);
_end = .;

__heap_base__ = .;
__heap_end__ = __ram_end__;
__heap_base__ = _sheap;
__heap_end__ = _eheap;
4 changes: 2 additions & 2 deletions flight/PiOS/STM32F30x/sections_chibios.ld
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@ SECTIONS
PROVIDE(end = .);
_end = .;

__heap_base__ = .;
__heap_end__ = __ram_end__;
__heap_base__ = _sheap;
__heap_end__ = _eheap;
4 changes: 2 additions & 2 deletions flight/PiOS/STM32F4xx/sections_chibios.ld
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@ SECTIONS
PROVIDE(end = .);
_end = .;

__heap_base__ = .;
__heap_end__ = __ram_end__;
__heap_base__ = _sheap;
__heap_end__ = _eheap;