开始准备折腾外设了
看了几个库里面的例程
有点眼花缭乱
先折腾AD吧,查询方式
官方的例程很有意思
设置了一个缓冲,用以存储多次采集的数据
很贴合实际的一个例程
东改改西改改,直接把代码撸成了一个头文件
直接调用ROM_ADC_StartConversion和ROM_ADC_Handler
就能进行AD数据采集了:
ADC.h.txt
(7.44 KB, 下载次数: 3)
直接copy修改例程的,乱的很,大神勿喷
但是真的能直接操作外设吗?
LPCXpresso这个编译环境,或者说官方的设置比较牛x
写好驱动代码,直接编译,是会出错滴
- Invoking: MCU Linker
- arm-none-eabi-gcc -nostdlib -L"C:\Users\Liao\Documents\LPCXpresso_7.6.2_326\workspace\lpc_board_lpcxpresso_54102_m0\Debug" -L"C:\Users\Liao\Documents\LPCXpresso_7.6.2_326\workspace\lpc_chip_5410x_m0\Debug" -L"C:\Users\Liao\Documents\LPCXpresso_7.6.2_326\workspace\lpc_chip_5410x_m0\libs" -Xlinker -Map="pTest_slave.map" -Xlinker --gc-sections -mcpu=cortex-m0 -mthumb -T "pTest_slave_Debug.ld" -o "pTest_slave.axf" ./src/boot_multicore_slave.o ./src/cr_startup_lpc5410x-m0.o ./src/crp.o ./src/pTest_slave.o ./src/sysinit.o -llpc_board_lpcxpresso_54102_m0 -llpc_chip_5410x_m0 -lpower_m0 && arm-none-eabi-objcopy --target elf32-littlearm --verbose --strip-all --redefine-sym __vectors_start__=__vectors_start___core_m0slave --keep-symbol __vectors_start___core_m0slave --rename-section .text=".core_m0slave" --rename-section .data=".core_m0slave.data" "pTest_slave.axf" "pTest_slave.axf.o"
- c:/nxp/lpcxpresso_7.6.2_326/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(_deferredlazyseek.o): In function `__flsbuf':
- _deferredlazyseek.c:(.text.__flsbuf+0x88): undefined reference to `__sys_istty'
- c:/nxp/lpcxpresso_7.6.2_326/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(_writebuf.o): In function `_Cwritebuf':
- _writebuf.c:(.text._Cwritebuf+0x16): undefined reference to `__sys_flen'
- _writebuf.c:(.text._Cwritebuf+0x26): undefined reference to `__sys_seek'
- c:/nxp/lpcxpresso_7.6.2_326/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(alloc.o): In function `_Csys_alloc':
- alloc.c:(.text._Csys_alloc+0x12): undefined reference to `__sys_appexit'
- c:/nxp/lpcxpresso_7.6.2_326/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(fseek.o): In function `fseek':
- fseek.c:(.text.fseek+0x18): undefined reference to `__sys_istty'
- fseek.c:(.text.fseek+0x3c): undefined reference to `__sys_flen'
- collect2.exe: error: ld returned 1 exit status
- make: *** [pTest_slave.axf] Error 1
复制代码
从报错来看,似乎是编译链接有问题
找不到对应的库,导致出错
继续黑度娘,毛线都找不到一根
后来还是在NXP官网上找到相关的说明:
http://www.lpcware.com/content/faq/lpcxpresso/linker-undefined-reference
一堆鸟文,大概意思是
LPCXpresso其实是存在2个库的,Redlib和Newlib,各有none、nohost、semihost三种附加属性
默认都是none
如果出现
Undefined reference to 'xxx'
就得修改这些属性
在这里:
撸主选择Redlib(nohost),一切井然。
下面玩玩AD
设置了一个工作场景
M0去采集AD0(P1_0)的数据
一次采集8个,通过mailbox发给M4
M4接收后,求一个简单的算术平均(有兴趣可以去试试几何平均)
再将结果返回M0
M0判断结果是否大于2048,根据判断结果,点亮绿灯
M4同时systick闪烁蓝灯
上主要的代码吧
M0侧:
- void MAILBOX_IRQHandler(void)//判断M4返回的数据,并点亮LED
- {
- uint32_t *p = (uint32_t *)Chip_MBOX_GetValue(LPC_MBOX, myCoreBox);
- mutexTake();
- Board_UARTPutSTR("Core M0+ get the Result from M4,");
- if(*p>2048){Board_LED_Set(1,true);Board_UARTPutSTR("SET LED ON");}
- else{Board_LED_Set(1,false);Board_UARTPutSTR("SET LED OFF");}
- Board_UARTPutSTR("\r\n");
- Chip_MBOX_ClearValueBits(LPC_MBOX, myCoreBox, 0xFFFFFFFF);
- mutexGive();
- }
- int main(void) {
- SystemCoreClockUpdate();
- Board_Init();
- myCoreBox = MAILBOX_CM0PLUS;
- otherCoreBox = MAILBOX_CM4;
- Chip_MBOX_Init(LPC_MBOX);
- mutexGive();
- Board_UARTPutSTR("Core M0+ boot......\r\n");
- NVIC_EnableIRQ(MAILBOX_IRQn);
- SysTick_Config(SystemCoreClock/10);
- //ADC、ADCROM初始化
- if (adcrom_init()) {
- return 1;
- }
- if (adcrom_config()) {
- return 1;
- }
- volatile static int i = 0 ;
- while(1) {
- i++;
- }
- return 0 ;
- }
- void SysTick_Handler(void)//每次systick启动ADC转换,并发送M4
- {
- if (ROM_ADC_StartConversion(hADC, ADC_SEQ_A, &buff_A[0][0], NUM_SAMPLES_A * NUM_CHANNELS_A) != LPC_OK) {
- DEBUGSTR("ERROR: Starting conversion in SEQ_A\r\n");
- }
- if (ROM_ADC_Handler(hADC, ADC_EV_SEQ_A_POLL) == LPC_OK) {
- pBufA = buff_A;
- print_buf_A(NUM_SAMPLES_A);
- }
- mutexTake(); Chip_MBOX_SetValue(LPC_MBOX, otherCoreBox, (uint32_t) &buff_A);
- Chip_MBOX_ClearValueBits(LPC_MBOX, myCoreBox, 0xFFFFFFFF);
- mutexGive();
- }
复制代码
M4侧:
- void MAILBOX_IRQHandler(void)//mailbox中断中获取数据,并设置运算标志位
- {uint32_t *p = (uint32_t *)Chip_MBOX_GetValue(LPC_MBOX, myCoreBox);
- mutexTake();
- if(cflag == 0){
- cflag = 1;
- pBufA = p;
- uint16_t(*buf) = pBufA;
- // print_buf_A(NUM_SAMPLES_A * NUM_CHANNELS_A);
- Chip_MBOX_SetValue(LPC_MBOX, otherCoreBox, (uint32_t)&sdata);
- DEBUGOUT("Core M4 computed:",sdata);
- DEBUGOUT("%d\r\n",sdata);
- Chip_MBOX_ClearValueBits(LPC_MBOX, myCoreBox, 0xFFFFFFFF);
- }
- mutexGive();
- }
- uint16_t buf2average(void)//简单算术平均
- {
- unsigned char i;
- uint16_t(*buf) = pBufA;
- uint16_t average,sum;
- for(i=0;i<8;i++){
- sum=sum+buf[i];
- average=sum/8;
- }
- return average ;
- }
- int main(void) {
- SystemCoreClockUpdate();
- Board_Init();
- myCoreBox = MAILBOX_CM4;
- otherCoreBox = MAILBOX_CM0PLUS;
- Chip_MBOX_Init(LPC_MBOX);
- mutexGive();
- Board_UARTPutSTR("Core M4 boot......\r\n");
- NVIC_EnableIRQ(MAILBOX_IRQn);
- SysTick_Config(SystemCoreClock/50);
- Board_LED_Set(0, false);
- boot_multicore_slave();
- volatile static int i = 0 ;
- while(1) //循环中根据运算标志位来进行算术平均值计算
- {
- i++;
- if(cflag>=1){
- cflag = 0;
- sdata = (uint32_t)buf2average();
- }
- }
- return 0 ;
- }
- void SysTick_Handler(void)//5个systick翻转一次蓝灯
- {
- cnt_m4++;
- if(cnt_m4>=5)
- {
- cnt_m4 = 0;
- Board_LED_Toggle(2);
- }
- }
复制代码
上个GIF:
接下来开始折腾一些总线型的外设了