One crazy SAMD21G MCU – I2C/RESET issues (custom PCB design) - Page 1
Forum section: electronics / projects

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 02, 2019, 07:09:07 pm
content: Howdy,I have custom PCB design with SAMD21G and 2 separate I2C (feather M0 bootloader).I wrote code to scan both I2C lanes and uploaded to MCU – second I2C port (that I created) scan finds chips just find, but no devices on 1st I2C port (there are 3 devices with different addresses on that port). I also used default I2C scanner code that scans only default I2C port – same result, no devices.And here is the interesting part – If I connect another I2C device with its own pullups – ALL devices just appears in the scan until I disconnect it and they disappear again. You may say it's pullups, well, just keep reading....I have another SAMD21G bare breakout board with only necessary components, if I jumpwire it to the same I2C lanes (with pullups only on custom PCB) and scan – it detects those devices just fine (with no additional I2C device and no extra pullups). Pullups on that line works fine, I used 10K resistors pull to 3,3V.Also that SAMD21G on the PCB doen't react to RESET going low (internally pulled up), at least computer doesn't make USB connect/disconnect sound (other SAMD21G break out board do).I'm thinking this is cos of one of two things:1. some SAMD21G pins are pulled up/down by the PCB design that shouldn't be and messes with reset2. I did an oopsie on PCB design – one chip (on 2nd I2C port that works) uses interrupt pin, and I missed that this chip sends 5V instead of 3,3, so that MCU got 5V. After realizing this I disconnected that pin and tested – that interrupt pin on MCU seems to work fine still.Eventually I will solder jump wires and connect pin by pin to breakout board to find out what is the issue, but as you can imagine it's very tedious task, so I just posting my issues in hope to get some ideas before I do that. Sadly I just can't change MCU – I don't have hot air station.I little update: I figure I'll try to add another I2C device (with no pullups on it this time, pullups only on PCB), and "bad" MCU on the chip sees it, but this time it detects only that chip, it doesn't detects other 3 chips on the PCB. I tried again another I2C device with its own pullups – all chips gets detected. WTH...Cheers

author: ataradov
author_rank: Super Contributor
timestamp: October 02, 2019, 09:05:52 pm
content: Without looking at the actual I2C signals with a scope it would be impossible to tell what is going on exactly.Same for reset. Check that the line actually goes low. I'm not really sure what you can really do to make it not go low short of connecting the reset pin directly to the supply voltage.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 03, 2019, 12:30:53 am
content: It's actually 2nd version of this PCB, on a first version this I2C works fine (no changes between V1 and V2 in this I2C). And reset pin is connected only to testing pad so I could manually reset MCU if needed. I'm using Adafruit bootloader, so to enter programming mode I have to double tap reset pin, and with minimum config breakout of SAMD21G this works just fine, but with custom PCB I have to disconnect and reconnect power, then double tap reset pin, only then it enters programming mode. I think easiest way would be to populate another PCB and test it after soldering every component until I found the problem.I have logic analyzer, will poke around tomorrow.

author: ataradov
author_rank: Super Contributor
timestamp: October 03, 2019, 01:10:30 am
content: Is it possible that some code changes reset to be a regular GPIO pin? May be by accident?

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 03, 2019, 02:16:46 am
content: Quote from: ataradov on October 03, 2019, 01:10:30 amI didn't mess with the fuses myself, but now as you mentioned – Atmel Studio could change them while burning bootloader. Tho I burned same bootloader to both SAMD chips so both chips reset should be messed up. Maybe that bootloader looks at specific pins states while IC powers on and sets something accordingly...Anyway, thank you, that was a good hint – I'll burn Arduino Zero bootloader and check I2C and reset pin.Update on the progress tomorrow

author: ataradov
author_rank: Super Contributor
timestamp: October 03, 2019, 02:18:22 am
content: Pins are not configured though the fuses. Even regular code can change the pin function in run-time.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 03, 2019, 03:14:03 am
content: According todatasheetReset pin do not have Port or Port pin number, so I'm pretty sure it's not possible to make Reset pin as a regular pin via code. Code I uploaded is very simple, it's very unlikely I changed something that I shouldn't.

author: ataradov
author_rank: Super Contributor
timestamp: October 03, 2019, 03:17:19 am
content: My bad. It is a dedicated pin indeed on this device. I guess they though that there are enough I/O pins already.In that case only looking at the board with a scope/logic analyzer may reveal something useful.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 03, 2019, 08:27:22 pm
content: I think my board is possessed...After some time when plugging USB all I got is "device not recognized", I nuked that MCU and changed with new one, same, now I know for sure pins are messing stuff up. Will solder another PCB component by component and test on every step.Also I noticed my Pfets are not working properly, I usedSQ3985EV, added 3.3V pullups on Gates, 5V on Source, Drain should be 0v with pullups, but no, it's 5VPCB design and schematic looks correct...P.S. burning Arduino Zero bootloader did not helped, Reset pin still seems to brick MCU instead of resetting it.

author: maginnovision
author_rank: Super Contributor
timestamp: October 03, 2019, 09:06:58 pm
content: Quote from: 3dgeo on October 03, 2019, 08:27:22 pmDid you want help? I haven't seen schematic, board layout, code, or pictures of anything.

author: Kasper
author_rank: Frequent Contributor
timestamp: October 03, 2019, 09:16:39 pm
content: Quote from: 3dgeo on October 03, 2019, 08:27:22 pmOn front page of your PMOS datasheet:If Vgs = -1.8V then Rds = 0.3ohmsFor your description:Vgs = Vg - VsVgs = 3.3V - 5VVgs = -1.7VRds ~ 0.3ohmsSounds like your PMOS circuit is working. Just not how you expected. Generally gate voltage should be as high as source voltage to ~fully turn off PMOS.When switching PMOS with low voltage MCU it can help to connect NPN or NMOS between MCU and PMOS.

author: Kasper
author_rank: Frequent Contributor
timestamp: October 03, 2019, 09:21:50 pm
content: Quote from: 3dgeo on October 02, 2019, 07:09:07 pmThis video might help with this:EEVblog #831 - Power A Micro With No Power Pin!YouTube · EEVblogDec 17, 2015

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 04, 2019, 09:00:37 pm
content: Quote from: Kasper on October 03, 2019, 09:16:39 pmThank you for explanation, I'm not that familiar with Pfets.Quote from: Kasper on October 03, 2019, 09:21:50 pmI encountered issue in the video with 74 logic, this is not the case. I should clear it out – pulling Reset to ground seems to crash MCU, it stops responding (at least serial com to PC stops).I build two more PCBs with minimum components – first one had 5V to 3.3V step down, it worked at the beginning, but then it just stopped, I can't even get it recognized with Atmel Ice. Also I notices that Voltage sometimes goes down to 0 on USB 5V rail on that board, so I figured it's regulator (MCP1700 SOT-23). So I just made another PCB with no regulator, it as well not recognized with Atmel Ice (it's not the Ice cos it still detects my first PCB just fine).I didn't post the schematic and PCB layout cos I wasn't near my workstation were I can prepare this info.But I guess I'll have to do it now cos even cursing and threatening at this PCB doesn't seems to work.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 05, 2019, 06:38:33 pm
content: OK, I'm back with the schematic, at least part of it that I'm having issues.By making image below I realized that I'm using12pFcrystal caps (C52,C53) instead of 15pF, can this be a problem?Crystal I'm usingis 32.768KHz +-10ppm, 12.5pF.Also I think I found my problem with the I2C – I'm using MCU IO pin PA21 to reset 3 ICs (NOT THE MCU) on the same I2C bus I'm having problem with. I actually made some tests before to make sure this pin works properly, it seems at that time that it's fine. This PA21 pin name seemed very familiar tho but I didn't know why. I think that SAM-BA bootloader uses it for some sort of data representation LED, I assume it's the same with Arduino core, so MCU toggling that pin. Me adding another I2C device with its own pullups reduced resistance and that line didn't get to 0v or wasn't long enough on 0V to reset those chips, that's why all IC showed up on the scan script, but If I added another chip without its own pullups only that chip gets detected cos other chips are in Reset constantly – now that's an interesting issue.... I think I'm lucky to figure this one outI'm guessing Reset issues I'm having is also related to my PCB pin configuration.To fix Pfets I'll probably will addULN2003darlington array, it got 7 drivers, 7 drivers I need. If anyone have better idea – let me know.Now I need to find out why my other PCBs with minimum config doesn't work, crystal/caps? But Atmel Ice should be able to detect those with no crystal at all... I really doubt I fried chips while soldering, ESD maybe?I removed GND copper fills, so please ignore GND:

author: ataradov
author_rank: Super Contributor
timestamp: October 05, 2019, 06:43:23 pm
content: Crystals are not likely to be the problem.I don't know anything about SAM-BA or Arduino bootloaders, so can't help you here.Again scope or logic analyzer will answer those questions.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 05, 2019, 07:19:26 pm
content: What bootloader do you know/use?I think eventually I will have to write my own, if I manage to beat that steep learning curve that is...

author: ataradov
author_rank: Super Contributor
timestamp: October 05, 2019, 07:25:11 pm
content: I write my own. There is no real learning curve. Bootloaders are easy unless you want to make them complicated.Here is example of a USB HID bootloaderhttps://github.com/ataradov/bootloadersAttached is a simple UART bootloader for SAM D21.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 05, 2019, 08:13:13 pm
content: I'm very grateful, Alex, thank you for your help (this is not the first time you are helping).I actually tried to find info on this topic, and your name came up, so I know you are THE MAN on these things, and I know it's easy for you but definitely not for me. Tho I'm getting there, slowly, maybe a bit frustrated at the time but I'm movingWhat do you mean by "USB HID bootloader"? Why I should need HID on bootloader? As far as I understand HID should be enabled when main program runs, or I'm wrong?My end goal is this:"firmware" on MCU is running as normal, it gets serial command that there is a need for firmware update, "firmware" changes "firmware update is active" "fuse" and resets MCU.Bootloader starts and stays in bootloader mode if "firmware update is active" (I still don't know how it should be done, I found other uses flash memory location to read/write this state, in my circuit there is external I2C EEPROM that can be used for this purpose as well).Bootloader should be able to receive commands/data via USB (serial com) and update "firmware", deactivate "firmware update is active" and reset itself or reset itself if commend received to do so via serial com."Firmware" should be able to emulate HID keyboard and use serial port at the same time (same USB).For me it's a huge goal to do this without Arduino existing libraries...How much a bootloader like this could cost? 3-4-5 figures?

author: ataradov
author_rank: Super Contributor
timestamp: October 05, 2019, 08:20:25 pm
content: HID is the easiest way to make a device work 9n all OSes without drivers.What you are describing is exactly what my HID bootloader is doing.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 05, 2019, 08:51:01 pm
content: But this will not work with Ardino IDE I'm guessing?As I said – I don't know how to make HID keyboard without Arduino libraries, it's too big of a gap to jump, at least for now.Tho I would like to know what is the best IDE for ARM developing in general? I have Atmel studio, but will it work with STM32?When I migrate I want to have one IDE (industry standard) for all ARM chips.Also, is there some sort of "starter code" generator for SAMD chips like STcube for STM chips?Sorry if I'm asking stupid things, I'm in uncharted waters here

author: ataradov
author_rank: Super Contributor
timestamp: October 05, 2019, 09:00:08 pm
content: No, none of my stuff would work with Arduino.AS will not work with STM32. Something Eclipse-based will be your only option for a full-featured IDE. But I have no idea how easy it is to setup nowadays, I have never used IDEs.https://start.atmel.comis a starter code generator. If you want less bloat, you can have a look at my starter projectshttps://github.com/ataradov/mcu-starter-projects

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 05, 2019, 09:25:37 pm
content: Wow, that's cool, I didn't knew I could get example codes so easilyI found USB composite right a way, this is awesome, you should lead with thislinknext timeThis is exiting, now I can think about migrating from ArduinoThanks again, Alex!

author: ataradov
author_rank: Super Contributor
timestamp: October 05, 2019, 09:28:03 pm
content: If you want to see an actually easy to understand VCP implementation, then I have one too -https://github.com/ataradov/vcp

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 05, 2019, 09:40:51 pm
content: Thanks, I'll take a look.For now I need working USB composite lib that I can modify, I need "send key press" function and "send serial" function or similarI hope this example I found will give me that.You wrote you never used IDE, how you code than? What tools do you use for that?

author: ataradov
author_rank: Super Contributor
timestamp: October 05, 2019, 09:54:23 pm
content: Quote from: 3dgeo on October 05, 2019, 09:40:51 pmHere is another example of a composite device HID/VCP -https://github.com/ataradov/free-dap/tree/master/platform/samd11_vcp. It does not implement actual HID devices. HID is just used as a driverless way to communicate with devices.Quote from: 3dgeo on October 05, 2019, 09:40:51 pmText editor and makefiles.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 05, 2019, 10:36:34 pm
content: Hm, I still don't understand how to upload to SAMD21 via USB when bootloader is already programmed, any tips on that?

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 05, 2019, 11:13:46 pm
content: This is Arduino USB Composite example:Code:#include "Keyboard.h"void setup(){Serial.begin(9600);Keyboard.begin();}void loop(){if (Serial.available() > 0){char inChar = Serial.read();Keyboard.write(inChar + 1);}}and this is Atmels example:Code:#include "atmel_start.h"#include "atmel_start_pins.h"#define CDC_EN (CONF_USB_COMPOSITE_CDC_ECHO_DEMO && CONF_USB_COMPOSITE_CDC_ACM_EN)#define MOUSE_EN (CONF_USB_COMPOSITE_HID_MOUSE_DEMO && CONF_USB_COMPOSITE_HID_MOUSE_EN)#define KEYBOARD_EN (CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO && CONF_USB_COMPOSITE_HID_KEYBOARD_EN)#define MSC_EN (CONF_USB_COMPOSITE_MSC_LUN_DEMO && CONF_USB_COMPOSITE_MSC_EN)#if CDC_ENstatic uint32_t cdc_demo_buf[64 / 4];#endif#if MSC_EN#if CONF_USB_MSC_LUN0_ENABLEstatic uint32_t msc_ramdisk_buf[CONF_USB_MSC_LUN0_CAPACITY * 1024 / 4];#define msc_ramdisk_buf NULL#endif#if CONF_USB_MSC_LUN1_ENABLEstatic uint32_t msc_diskcache_buf[CONF_USB_MSC_LUN_BUF_SECTORS * 512 / 4];#define msc_diskcache_buf NULL#endif#endifint main(void){atmel_start_init();/* Do function or app specific initialize */#if CDC_ENcdcdf_acm_demo_init((uint8_t *)cdc_demo_buf);#endif#if KEYBOARD_EN || MOUSE_ENhiddf_demo_init(BUTTON1, BUTTON2, BUTTON3);#endif#if MSC_ENmscdf_demo_init((uint8_t *)msc_ramdisk_buf, (uint8_t *)msc_diskcache_buf);#endif/* Start the composite device */composite_device_start();/* Main loop */while (1) {#if MSC_ENmscdf_demo_task();#endif}}What I'm suppose to do with this crap? Where is " Keyboard.write(); " and " Serial.println(); " equivalents?Anyway, back to the topic, I need to solve Reset and board issues...

author: ataradov
author_rank: Super Contributor
timestamp: October 05, 2019, 11:48:45 pm
content: Quote from: 3dgeo on October 05, 2019, 10:36:34 pmThat depends on the type of bootloader. Mine comes with a command like tool.

author: ataradov
author_rank: Super Contributor
timestamp: October 05, 2019, 11:50:53 pm
content: Quote from: 3dgeo on October 05, 2019, 11:13:46 pmWelcome to the grown up programming world. Where you actually have to do programming. If you want think to be easy, stick with Arduino. But when it becomes too limited, you will have to make a switch.Also, don't make a mistake thinking that manufacturer supplied code is good. It is not. But it works, and that's how much you can ask of it, really.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 06, 2019, 01:37:18 am
content: Quote from: ataradov on October 05, 2019, 11:50:53 pmWell, you are advanced programmer so you should know that it is nothing to do with "doing actual programming" – this example is simply not optimized for use of itself as a library.Cos of minimum configuration issues I'm having with SAMD21 + I have to add extra chip for driving 5V Pfet I'm considering going back to STM32f103.It's over 2 times cheaper + no extra chip due to 5V tolerant IO, it's also 1/3 faster (I need speed). As most likely I will have to role up my own bootloader/USB composite lib anyway I think this is a logical decision (I picked SAMD21 cos I hoped to avoid "real programming").Bummer, what a waste, I was quite invested in SAMD21 (money and time wise). Oh well, I might get back to SAMD

author: 3dgeo
author_rank: Frequent Contributor
timestamp: October 06, 2019, 06:37:11 pm
content: After connecting VDDANA to 3.3V now instead of no devices I'm getting this:Code:Scanning...I2C device found at address 0x01 !I2C device found at address 0x02 !I2C device found at address 0x03 !I2C device found at address 0x04 !I2C device found at address 0x05 !I2C device found at address 0x06 !I2C device found at address 0x07 !I2C device found at address 0x08 !I2C device found at address 0x09 !I2C device found at address 0x0A !I2C device found at address 0x0B !I2C device found at address 0x0C !I2C device found at address 0x0D !I2C device found at address 0x0E !I2C device found at address 0x0F !I2C device found at address 0x10 !I2C device found at address 0x11 !I2C device found at address 0x12 !I2C device found at address 0x13 !I2C device found at address 0x14 !I2C device found at address 0x15 !I2C device found at address 0x16 !I2C device found at address 0x17 !I2C device found at address 0x18 !I2C device found at address 0x19 !I2C device found at address 0x1A !I2C device found at address 0x1B !I2C device found at address 0x1C !I2C device found at address 0x1D !I2C device found at address 0x1E !I2C device found at address 0x1F !I2C device found at address 0x20 !I2C device found at address 0x21 !I2C device found at address 0x22 !I2C device found at address 0x23 !I2C device found at address 0x24 !I2C device found at address 0x25 !I2C device found at address 0x26 !I2C device found at address 0x27 !I2C device found at address 0x28 !I2C device found at address 0x29 !I2C device found at address 0x2A !I2C device found at address 0x2B !I2C device found at address 0x2C !I2C device found at address 0x2D !I2C device found at address 0x2E !I2C device found at address 0x2F !I2C device found at address 0x30 !I2C device found at address 0x31 !I2C device found at address 0x32 !I2C device found at address 0x33 !I2C device found at address 0x34 !I2C device found at address 0x35 !I2C device found at address 0x36 !I2C device found at address 0x37 !I2C device found at address 0x38 !I2C device found at address 0x39 !I2C device found at address 0x3A !I2C device found at address 0x3B !I2C device found at address 0x3C !I2C device found at address 0x3D !I2C device found at address 0x3E !I2C device found at address 0x3F !I2C device found at address 0x40 !I2C device found at address 0x41 !I2C device found at address 0x42 !I2C device found at address 0x43 !I2C device found at address 0x44 !I2C device found at address 0x45 !I2C device found at address 0x46 !I2C device found at address 0x47 !I2C device found at address 0x48 !I2C device found at address 0x49 !I2C device found at address 0x4A !I2C device found at address 0x4B !I2C device found at address 0x4C !I2C device found at address 0x4D !I2C device found at address 0x4E !I2C device found at address 0x4F !I2C device found at address 0x50 !I2C device found at address 0x51 !I2C device found at address 0x52 !I2C device found at address 0x53 !I2C device found at address 0x54 !I2C device found at address 0x55 !I2C device found at address 0x56 !I2C device found at address 0x57 !I2C device found at address 0x58 !I2C device found at address 0x59 !I2C device found at address 0x5A !I2C device found at address 0x5B !I2C device found at address 0x5C !I2C device found at address 0x5D !I2C device found at address 0x5E !I2C device found at address 0x5F !I2C device found at address 0x60 !I2C device found at address 0x61 !I2C device found at address 0x62 !I2C device found at address 0x63 !I2C device found at address 0x64 !I2C device found at address 0x65 !I2C device found at address 0x66 !I2C device found at address 0x67 !I2C device found at address 0x68 !I2C device found at address 0x69 !I2C device found at address 0x6A !I2C device found at address 0x6B !I2C device found at address 0x6C !I2C device found at address 0x6D !I2C device found at address 0x6E !I2C device found at address 0x6F !I2C device found at address 0x70 !I2C device found at address 0x71 !I2C device found at address 0x72 !I2C device found at address 0x73 !I2C device found at address 0x74 !I2C device found at address 0x75 !I2C device found at address 0x76 !I2C device found at address 0x77 !I2C device found at address 0x78 !I2C device found at address 0x79 !I2C device found at address 0x7A !I2C device found at address 0x7B !I2C device found at address 0x7C !I2C device found at address 0x7D !I2C device found at address 0x7E !doneTroll board...