2017年6月11日 星期日

NANO100:Using data flash without the external 12M HZ crystal.

The data flash start address is set by register so it need a reset after update the address, but in default it will use  the external 12M HZ crystal.It's need to modify the CFOSC .



Modify the \SampleCode\StdDriver\FMC_RW set_data_flash_base() function

static int set_data_flash_base(uint32_t u32DFBA)
{
uint32_t au32Config[2];
if (FMC_ReadConfig(au32Config, 2) < 0) {
printf("\nRead User Config failed!\n");
return -1;
}
if ((!(au32Config[0] & 0x1)) && (au32Config[1] == u32DFBA))
return 0;
FMC_ENABLE_CFG_UPDATE();
au32Config[0] &= ~0x1;
au32Config[0] |= 0x1<<26; //Enable the HIRC
au32Config[1] = u32DFBA;
if (FMC_WriteConfig(au32Config, 2) < 0)
return -1;
printf("\nSet Data Flash base as 0x%x.\n", DATA_FLASH_TEST_BASE);
// Perform chip reset to make new User Config take effect
SYS->IPRST_CTL1 = SYS_IPRST_CTL1_CHIP_RST_Msk;
return 0;
}
view raw gistfile1.txt hosted with ❤ by GitHub


Ref:
     Nano100 Series Technical Reference Manual

NANO100:Enable printf use Nu-Link to send massage

1.Add #define DEBUG_ENABLE_SEMIHOST in Library\StdDriver\src\retarget.c .
 

2.Start Keil C IDE debug session and enable the View\Serial Windows\UART #1.


3. Now you can see the printf massage in Keil C IDE.

Ref:
   2. Semihosting

2017年6月7日 星期三

Octave: Modulation Sine Wave use PWM generate look up table for MCU DAC.

Input the target sample frequency ,sample bits and sample frequency.Generate the duty of PWM(percentage).
Code:
clc;
clear;
sample_bits = 12;#smaple bits
fs = 10000; #sample frequency
f = 60; #target frequency
amp= 2^(sample_bits-1);
t = 0:1/fs:1/f;
x = amp*(1+sin(2*pi*f*t));#avoid negative part
pwm_duty = x/(amp*2);
bar (pwm_duty);
view raw PWM_SINE.m hosted with ❤ by GitHub

Avoid the negative part cause normally MCU didn't have negative voltage output ability.







Ref:
    1.http://bugworkshop.blogspot.tw/2011/04/blog-post_12.html

Linux driver: How to enable dynamic debug at booting time for built-in driver.

 Dynamic debug is useful for debug driver, and can be enable by: 1. Mount debug fs #>mount -t debugfs none /sys/kernel/debug 2. Enable dy...