Difference between revisions of "Microcontrollers-nxp"
Jump to navigation
Jump to search
m (adding first note references on how to program dual-core microcontrollers.) |
m (adding excerpt copy and pasted of example assembly code to run on M0 core of dual core uc.) |
||
| Line 14: | Line 14: | ||
* https://community.arm.com/developer/ip-products/processors/f/cortex-a-forum/4105/how-to-build-an-application-for-dual-core-m4-m0-mcu/18010 | * https://community.arm.com/developer/ip-products/processors/f/cortex-a-forum/4105/how-to-build-an-application-for-dual-core-m4-m0-mcu/18010 | ||
| + | Not sure how useful this code example will be, it is posted in or around 2014. Hard to read on the NXP forum due to some funky formatting: | ||
| + | <pre> | ||
| + | ;/* File: example.s */ | ||
| + | .syntax unified /* this makes the assembler automatically generate IT instructions for you */ | ||
| + | |||
| + | .cpu cortex-m0 /* this selects the cortex-m0 architecture and helps you avoid using cortex-m3/cortex-m4 instructions */ | ||
| + | |||
| + | .text /* this makes sure the code goes into the .text section */ | ||
| + | |||
| + | .global m0vectors | ||
| + | |||
| + | .word 0x20004000 /* this defines the initial stack pointer for the Cortex-M0 */ | ||
| + | |||
| + | .word m0reset /* the reset exception vector */ | ||
| + | |||
| + | /* here you should place your other exception vectors. There are too many to include in this example */ | ||
| + | |||
| + | .global m0test /* this exports the symbol m0test, so you can reference it from for instance C */ | ||
| + | |||
| + | .func m0test,m0test /* this names the symbol m0test as a function (for the debug-info) */ | ||
| + | |||
| + | .type m0test,%function /* this tells the assembler (and linker) what kind of symbol we're generating */ | ||
| + | |||
| + | .thumb_func /* this is necessary if pointers use the symbol */ | ||
| + | |||
| + | .align /* this makes sure the code is positioned on a 16-bit boundary */ | ||
| + | |||
| + | m0test: /* this defines the actual symbol */ | ||
| + | |||
| + | ldr r0,=0x01234567 /* example code, load a value into r0 */ | ||
| + | |||
| + | bx lr /* return to the calling function */ | ||
| + | |||
| + | m0reset: | ||
| + | |||
| + | bl m0test /* this is the startup-code, call our function */ | ||
| + | |||
| + | lockup: wfi /* sleep the CPU; it'll wake up if an interrupt occurs */ | ||
| + | |||
| + | b lockup /* go back to sleep */ | ||
| + | |||
| + | .size m0test, . - m0test /* this tells the linker how big this function is, so it can correctly exclude it if it's unused */ | ||
| + | |||
| + | .endfunc /* this marks the end of the function (for the debug-info) */ | ||
| + | |||
| + | You can then refer to the code from your C file... | ||
| + | |||
| + | /* File: main.c */ | ||
| + | |||
| + | #include <ipc_queue.h> | ||
| + | |||
| + | /* Note: you don't need argc and argv on a microcontroller. */ | ||
| + | |||
| + | int main(int argc, const char *argv[]) | ||
| + | |||
| + | { | ||
| + | |||
| + | IPC_haltSlave(); | ||
| + | |||
| + | SET_SLAVE_SHADOWREG(m0vectors); | ||
| + | |||
| + | IPC_startSlave(); | ||
| + | |||
| + | while(1) | ||
| + | |||
| + | { | ||
| + | |||
| + | asm volatile("wfi"); | ||
| + | |||
| + | } | ||
| + | |||
| + | return(0); | ||
| + | |||
| + | } | ||
| + | </pre> | ||
<center> | <center> | ||
[[#top|- - - top - - -]] | [[#top|- - - top - - -]] | ||
</center> | </center> | ||
Revision as of 19:28, 9 July 2021
Microcontrollers de NXP, starting with a NXP's Line Card:
2021-07-08
And an article at Wikipedia:
How to program dual-core microcontrollers:
Not sure how useful this code example will be, it is posted in or around 2014. Hard to read on the NXP forum due to some funky formatting:
;/* File: example.s */
.syntax unified /* this makes the assembler automatically generate IT instructions for you */
.cpu cortex-m0 /* this selects the cortex-m0 architecture and helps you avoid using cortex-m3/cortex-m4 instructions */
.text /* this makes sure the code goes into the .text section */
.global m0vectors
.word 0x20004000 /* this defines the initial stack pointer for the Cortex-M0 */
.word m0reset /* the reset exception vector */
/* here you should place your other exception vectors. There are too many to include in this example */
.global m0test /* this exports the symbol m0test, so you can reference it from for instance C */
.func m0test,m0test /* this names the symbol m0test as a function (for the debug-info) */
.type m0test,%function /* this tells the assembler (and linker) what kind of symbol we're generating */
.thumb_func /* this is necessary if pointers use the symbol */
.align /* this makes sure the code is positioned on a 16-bit boundary */
m0test: /* this defines the actual symbol */
ldr r0,=0x01234567 /* example code, load a value into r0 */
bx lr /* return to the calling function */
m0reset:
bl m0test /* this is the startup-code, call our function */
lockup: wfi /* sleep the CPU; it'll wake up if an interrupt occurs */
b lockup /* go back to sleep */
.size m0test, . - m0test /* this tells the linker how big this function is, so it can correctly exclude it if it's unused */
.endfunc /* this marks the end of the function (for the debug-info) */
You can then refer to the code from your C file...
/* File: main.c */
#include <ipc_queue.h>
/* Note: you don't need argc and argv on a microcontroller. */
int main(int argc, const char *argv[])
{
IPC_haltSlave();
SET_SLAVE_SHADOWREG(m0vectors);
IPC_startSlave();
while(1)
{
asm volatile("wfi");
}
return(0);
}