xiaoxiang781216 commented on code in PR #16687: URL: https://github.com/apache/nuttx/pull/16687#discussion_r2191461543
########## arch/avr/src/avr/Kconfig: ########## @@ -94,8 +110,76 @@ config AVR_HAS_MEMX_PTR pointers in arbitrary interaction with the kernel. Not all API functions have these qualifiers added to their parameters. +config AVR_HAS_FLMAP + bool "Use memory-mapped access to flash" + depends on AVR_BOARD_HAS_FLMAP && AVR_CHIP_HAS_FLMAP + ---help--- + Newer AVR chips - namely tinyAVR and AVR families - have (part of) + their program memory (flash) mapped into data memory address space. + The mapping is limited to 32kB window. + + With this option enabled, const variables are kept in the program + memory and no copy to RAM is done. Yet it is still possible to use + such variables in any interaction with the kernel as they are + visible in data memory address space. + + Note that this option only triggers some basic configuration + in the init function. It is the linker script of the board that needs + to ensure variables are placed correctly. + + Beware that FLMAP bits in NVMCTRL.CTRLB I/O register which select + the segment of program memory to be mapped may not be changed freely + by the application. If the application needs to change the mapping, + it may only do so while observing these rules: + + 1. No kernel function must be called until the original value + is restored. + + 2. Interrupts must be disabled for as long as the value is changed. + +endchoice # Const variable placement + +config AVR_FLMAP_RODATA_SIZE + int "Size of .rodata FLMAP section" + depends on AVR_HAS_FLMAP + default 4096 + ---help--- + Specify size of .rodata memory section, ie. the section that stores + const variables. This will be passed as a parameter to the linker + to be used by the board's linker script. + + Value must be divisible by 512 and no more than 32 kilobytes + is possible. + +config AVR_FLMAP_RODATA_OFFSET + int "Offset of .rodata FLMAP section" + depends on AVR_HAS_FLMAP + default 0 + ---help--- + Specify size of memory block between end of the .rodata section + (counting its full size as defined in AVR_FLMAP_RODATA_SIZE) + and the end of flash. + + This value is intended to leave the end of the flash unused, + presumably for the purpose of placing APPDATA section in there + (see the chip documentation for details about subdividing + the program flash to BOOT, APPCODE and APPDATA sections.) + + Note that this value is only passed to the linker to be used + by the linker script - the script then needs to place + the .rodata section accordingly. + + Value must be divisible by 512 and no more than 31 kilobytes + is possible. Sum of this value and AVR_FLMAP_RODATA_SIZE must + also not exceed 32kB. config AVR_HAS_RAMPZ bool +config AVR_BOARD_HAS_FLMAP Review Comment: `AVR_HAVE_BOARD_FLMAP` ########## arch/avr/src/avrdx/avrdx_head.S: ########## @@ -492,6 +492,57 @@ __start: out _SFR_IO_ADDR(SPH), r29 out _SFR_IO_ADDR(SPL), r28 + +#ifdef AVR_HAS_FLMAP + + /* Configure FLMAP bits in NVMCTRL.CTRLB in case this was software + * reset and they are not in default state. + * + * Don't care if the application actually changes the register. These + * bits are not under configuration protection (CCP) and runaway + * application can possibly change them. + */ + + ldi r26, lo8(NVMCTRL_CTRLB) + ldi r27, hi8(NVMCTRL_CTRLB) + ld r16, X + + /* Default value (on current chips anyway) uses all bits set to one. */ + +# if !defined(NVMCTRL_FLMAP_1_bm) + + /* Might be there won't be such (supported) device ever. */ + +# error Chips without FLMAP bit 1 are not supported + +# elif !defined(NVMCTRL_FLMAP_2_bm) + + /* Expected case */ + + ldi r17, NVMCTRL_FLMAP_0_bm | NVMCTRL_FLMAP_1_bm; + +# else + + /* Future device with more than 128kB RAM. The default is expected + * to be all bits set to one but it needs to be verified when + * support for such chip is added. Issue a warning. + */ + +# warning Support for more than 128kB flash was done blindly here + + ldi r17, NVMCTRL_FLMAP_0_bm | NVMCTRL_FLMAP_1_bm | NVMCTRL_FLMAP_2_bm; + +#endif Review Comment: `# endif` ########## arch/avr/src/avr/Kconfig: ########## @@ -94,8 +110,76 @@ config AVR_HAS_MEMX_PTR pointers in arbitrary interaction with the kernel. Not all API functions have these qualifiers added to their parameters. +config AVR_HAS_FLMAP + bool "Use memory-mapped access to flash" + depends on AVR_BOARD_HAS_FLMAP && AVR_CHIP_HAS_FLMAP + ---help--- + Newer AVR chips - namely tinyAVR and AVR families - have (part of) + their program memory (flash) mapped into data memory address space. + The mapping is limited to 32kB window. + + With this option enabled, const variables are kept in the program + memory and no copy to RAM is done. Yet it is still possible to use + such variables in any interaction with the kernel as they are + visible in data memory address space. + + Note that this option only triggers some basic configuration + in the init function. It is the linker script of the board that needs + to ensure variables are placed correctly. + + Beware that FLMAP bits in NVMCTRL.CTRLB I/O register which select + the segment of program memory to be mapped may not be changed freely + by the application. If the application needs to change the mapping, + it may only do so while observing these rules: + + 1. No kernel function must be called until the original value + is restored. + + 2. Interrupts must be disabled for as long as the value is changed. + +endchoice # Const variable placement + +config AVR_FLMAP_RODATA_SIZE + int "Size of .rodata FLMAP section" + depends on AVR_HAS_FLMAP + default 4096 + ---help--- + Specify size of .rodata memory section, ie. the section that stores + const variables. This will be passed as a parameter to the linker + to be used by the board's linker script. + + Value must be divisible by 512 and no more than 32 kilobytes + is possible. + +config AVR_FLMAP_RODATA_OFFSET + int "Offset of .rodata FLMAP section" + depends on AVR_HAS_FLMAP + default 0 + ---help--- + Specify size of memory block between end of the .rodata section + (counting its full size as defined in AVR_FLMAP_RODATA_SIZE) + and the end of flash. + + This value is intended to leave the end of the flash unused, + presumably for the purpose of placing APPDATA section in there + (see the chip documentation for details about subdividing + the program flash to BOOT, APPCODE and APPDATA sections.) + + Note that this value is only passed to the linker to be used + by the linker script - the script then needs to place + the .rodata section accordingly. + + Value must be divisible by 512 and no more than 31 kilobytes + is possible. Sum of this value and AVR_FLMAP_RODATA_SIZE must + also not exceed 32kB. config AVR_HAS_RAMPZ Review Comment: may be we need create a new patch to rename _HAS_ to _HAVE_ to align with ARCH_HAVE_xxx option ########## arch/avr/src/avr/Kconfig: ########## @@ -94,8 +110,76 @@ config AVR_HAS_MEMX_PTR pointers in arbitrary interaction with the kernel. Not all API functions have these qualifiers added to their parameters. +config AVR_HAS_FLMAP + bool "Use memory-mapped access to flash" + depends on AVR_BOARD_HAS_FLMAP && AVR_CHIP_HAS_FLMAP + ---help--- + Newer AVR chips - namely tinyAVR and AVR families - have (part of) + their program memory (flash) mapped into data memory address space. + The mapping is limited to 32kB window. + + With this option enabled, const variables are kept in the program + memory and no copy to RAM is done. Yet it is still possible to use + such variables in any interaction with the kernel as they are + visible in data memory address space. + + Note that this option only triggers some basic configuration + in the init function. It is the linker script of the board that needs + to ensure variables are placed correctly. + + Beware that FLMAP bits in NVMCTRL.CTRLB I/O register which select + the segment of program memory to be mapped may not be changed freely + by the application. If the application needs to change the mapping, + it may only do so while observing these rules: + + 1. No kernel function must be called until the original value + is restored. + + 2. Interrupts must be disabled for as long as the value is changed. + +endchoice # Const variable placement + +config AVR_FLMAP_RODATA_SIZE + int "Size of .rodata FLMAP section" + depends on AVR_HAS_FLMAP + default 4096 + ---help--- + Specify size of .rodata memory section, ie. the section that stores + const variables. This will be passed as a parameter to the linker + to be used by the board's linker script. + + Value must be divisible by 512 and no more than 32 kilobytes + is possible. + +config AVR_FLMAP_RODATA_OFFSET + int "Offset of .rodata FLMAP section" + depends on AVR_HAS_FLMAP + default 0 + ---help--- + Specify size of memory block between end of the .rodata section + (counting its full size as defined in AVR_FLMAP_RODATA_SIZE) + and the end of flash. + + This value is intended to leave the end of the flash unused, + presumably for the purpose of placing APPDATA section in there + (see the chip documentation for details about subdividing + the program flash to BOOT, APPCODE and APPDATA sections.) + + Note that this value is only passed to the linker to be used + by the linker script - the script then needs to place + the .rodata section accordingly. + + Value must be divisible by 512 and no more than 31 kilobytes + is possible. Sum of this value and AVR_FLMAP_RODATA_SIZE must + also not exceed 32kB. config AVR_HAS_RAMPZ bool +config AVR_BOARD_HAS_FLMAP + bool + +config AVR_CHIP_HAS_FLMAP Review Comment: AVR_HAVE_FLMAP ########## boards/Kconfig: ########## @@ -94,6 +94,7 @@ config ARCH_BOARD_AVRDX_BREADXAVR select ARCH_HAVE_LEDS select ARCH_HAVE_BUTTONS select ARCH_HAVE_IRQBUTTONS + select AVR_BOARD_HAS_FLMAP Review Comment: but this flag is AVR specific should contain AVR term in the config to avoid the confusion. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org