Skip to content

Instantly share code, notes, and snippets.

@f-steff
Last active September 16, 2025 08:54
Show Gist options
  • Save f-steff/a827ec3ed53253082bfad7dc698e2cdf to your computer and use it in GitHub Desktop.
Save f-steff/a827ec3ed53253082bfad7dc698e2cdf to your computer and use it in GitHub Desktop.
Renesas CC-RX compiler 3.07+ hack to implement weak functions

Renesas CC-RX compiler 3.07 hack to implement weak functions

Typical weak function implementations

Normally weak functions are implemented using either function attributes or pragmas, like this

Function declaration attributes

uint16_t __attribute__((weak)) getValue(void){ ... };
uint16_t getValue(void) __attribute__((weak)){ ... };

Pragma statements

#pragma weak getValue
uint16_t getValue(){ ... };

Renesas CC-RX implementation

Unfortunately the CC-RX compiler do not yet implement support for weak functions, but since version 3.07, the assembler have supported weak symbols. By mixing c and assembly code, it's possible to archive a weak function option:

HAL implementation with weak functions

hal/myFunctions.h

#include <stdint.h>

uint16_t getValue();

hal/weak_functions.s

.SECTION P,CODE

.WEAK    _getValue

.END

hal/weak_function_impl.c

#include <hal/myFunctions.h>

uint16_t getValue(){
	return 0;
}

Main project - overrides the weak function.

actual_function_impl.c

#include <hal/myFunctions.h>

uint16_t getValue(){
	return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment